blob: cceae70279f6407d96f7249f02939de53405ea03 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
3 * Horst Hummel <Horst.Hummel@de.ibm.com>
4 * Carsten Otte <Cotte@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02007 * Copyright IBM Corp. 1999, 2001
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * i/o controls for the dasd driver.
10 */
Stefan Haberlandfc19f382009-03-26 15:23:49 +010011
12#define KMSG_COMPONENT "dasd"
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/interrupt.h>
Heiko Carstens048cd4e2012-02-27 10:01:52 +010015#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/major.h>
17#include <linux/fs.h>
18#include <linux/blkpg.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Heiko Carstens88034862010-01-13 20:44:29 +010020#include <asm/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/ccwdev.h>
Christoph Hellwig8b2eb662006-03-24 03:15:21 -080022#include <asm/cmb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/uaccess.h>
24
25/* This is ugly... */
26#define PRINTK_HEADER "dasd_ioctl:"
27
28#include "dasd_int.h"
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static int
Christoph Hellwig13c62042006-03-24 03:15:19 -080032dasd_ioctl_api_version(void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 int ver = DASD_API_VERSION;
Bastian Blankb5029622006-03-24 03:15:32 -080035 return put_user(ver, (int __user *)argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
38/*
39 * Enable device.
40 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
41 */
42static int
Christoph Hellwig13c62042006-03-24 03:15:19 -080043dasd_ioctl_enable(struct block_device *bdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Stefan Weinhuber65f8da42011-04-20 10:15:30 +020045 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 if (!capable(CAP_SYS_ADMIN))
48 return -EACCES;
Christoph Hellwig13c62042006-03-24 03:15:19 -080049
Stefan Weinhuber65f8da42011-04-20 10:15:30 +020050 base = dasd_device_from_gendisk(bdev->bd_disk);
51 if (!base)
52 return -ENODEV;
53
54 dasd_enable_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 /* Formatting the dasd device can change the capacity. */
Arjan van de Venc039e312006-03-23 03:00:28 -080056 mutex_lock(&bdev->bd_mutex);
Stefan Weinhuber65f8da42011-04-20 10:15:30 +020057 i_size_write(bdev->bd_inode,
58 (loff_t)get_capacity(base->block->gdp) << 9);
Arjan van de Venc039e312006-03-23 03:00:28 -080059 mutex_unlock(&bdev->bd_mutex);
Stefan Weinhuber65f8da42011-04-20 10:15:30 +020060 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return 0;
62}
63
64/*
65 * Disable device.
66 * Used by dasdfmt. Disable I/O operations but allow ioctls.
67 */
68static int
Christoph Hellwig13c62042006-03-24 03:15:19 -080069dasd_ioctl_disable(struct block_device *bdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Stefan Weinhuber65f8da42011-04-20 10:15:30 +020071 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 if (!capable(CAP_SYS_ADMIN))
74 return -EACCES;
Christoph Hellwig13c62042006-03-24 03:15:19 -080075
Stefan Weinhuber65f8da42011-04-20 10:15:30 +020076 base = dasd_device_from_gendisk(bdev->bd_disk);
77 if (!base)
78 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /*
80 * Man this is sick. We don't do a real disable but only downgrade
81 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
82 * BIODASDDISABLE to disable accesses to the device via the block
83 * device layer but it still wants to do i/o on the device by
84 * using the BIODASDFMT ioctl. Therefore the correct state for the
85 * device is DASD_STATE_BASIC that allows to do basic i/o.
86 */
Stefan Weinhuber65f8da42011-04-20 10:15:30 +020087 dasd_set_target_state(base, DASD_STATE_BASIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /*
89 * Set i_size to zero, since read, write, etc. check against this
90 * value.
91 */
Arjan van de Venc039e312006-03-23 03:00:28 -080092 mutex_lock(&bdev->bd_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 i_size_write(bdev->bd_inode, 0);
Arjan van de Venc039e312006-03-23 03:00:28 -080094 mutex_unlock(&bdev->bd_mutex);
Stefan Weinhuber65f8da42011-04-20 10:15:30 +020095 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return 0;
97}
98
99/*
100 * Quiesce device.
101 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100102static int dasd_ioctl_quiesce(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 unsigned long flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100105 struct dasd_device *base;
Horst Hummel138c0142006-06-29 14:58:12 +0200106
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100107 base = block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 if (!capable (CAP_SYS_ADMIN))
109 return -EACCES;
Horst Hummel138c0142006-06-29 14:58:12 +0200110
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200111 pr_info("%s: The DASD has been put in the quiesce "
112 "state\n", dev_name(&base->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100113 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100114 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100115 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return 0;
117}
118
119
120/*
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100121 * Resume device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100123static int dasd_ioctl_resume(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 unsigned long flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100126 struct dasd_device *base;
Horst Hummel138c0142006-06-29 14:58:12 +0200127
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100128 base = block->base;
Horst Hummel138c0142006-06-29 14:58:12 +0200129 if (!capable (CAP_SYS_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return -EACCES;
131
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200132 pr_info("%s: I/O operations have been resumed "
133 "on the DASD\n", dev_name(&base->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100134 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100135 dasd_device_remove_stop_bits(base, DASD_STOPPED_QUIESCE);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100136 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
Horst Hummel138c0142006-06-29 14:58:12 +0200137
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100138 dasd_schedule_block_bh(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return 0;
140}
141
142/*
143 * performs formatting of _device_ according to _fdata_
144 * Note: The discipline's format_function is assumed to deliver formatting
145 * commands to format a single unit of the device. In terms of the ECKD
146 * devices this means CCWs are generated to format a single track.
147 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100148static int dasd_format(struct dasd_block *block, struct format_data_t *fdata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 struct dasd_ccw_req *cqr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100151 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 int rc;
153
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100154 base = block->base;
155 if (base->discipline->format_device == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return -EPERM;
157
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100158 if (base->state != DASD_STATE_BASIC) {
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200159 pr_warning("%s: The DASD cannot be formatted while it is "
160 "enabled\n", dev_name(&base->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return -EBUSY;
162 }
163
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100164 DBF_DEV_EVENT(DBF_NOTICE, base,
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100165 "formatting units %u to %u (%u B blocks) flags %u",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 fdata->start_unit,
167 fdata->stop_unit, fdata->blksize, fdata->intensity);
168
169 /* Since dasdfmt keeps the device open after it was disabled,
170 * there still exists an inode for this device.
171 * We must update i_blkbits, otherwise we might get errors when
172 * enabling the device later.
173 */
174 if (fdata->start_unit == 0) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100175 struct block_device *bdev = bdget_disk(block->gdp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 bdev->bd_inode->i_blkbits = blksize_bits(fdata->blksize);
177 bdput(bdev);
178 }
179
180 while (fdata->start_unit <= fdata->stop_unit) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100181 cqr = base->discipline->format_device(base, fdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 if (IS_ERR(cqr))
183 return PTR_ERR(cqr);
184 rc = dasd_sleep_on_interruptible(cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100185 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 if (rc) {
187 if (rc != -ERESTARTSYS)
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200188 pr_err("%s: Formatting unit %d failed with "
189 "rc=%d\n", dev_name(&base->cdev->dev),
190 fdata->start_unit, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return rc;
192 }
193 fdata->start_unit++;
194 }
195 return 0;
196}
197
198/*
199 * Format device.
200 */
201static int
Christoph Hellwig13c62042006-03-24 03:15:19 -0800202dasd_ioctl_format(struct block_device *bdev, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200204 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 struct format_data_t fdata;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200206 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 if (!capable(CAP_SYS_ADMIN))
209 return -EACCES;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800210 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return -EINVAL;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200212 base = dasd_device_from_gendisk(bdev->bd_disk);
213 if (!base)
214 return -ENODEV;
215 if (base->features & DASD_FEATURE_READONLY ||
216 test_bit(DASD_FLAG_DEVICE_RO, &base->flags)) {
217 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return -EROFS;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200219 }
220 if (copy_from_user(&fdata, argp, sizeof(struct format_data_t))) {
221 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return -EFAULT;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (bdev != bdev->bd_contains) {
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200225 pr_warning("%s: The specified DASD is a partition and cannot "
226 "be formatted\n",
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200227 dev_name(&base->cdev->dev));
228 dasd_put_device(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return -EINVAL;
230 }
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200231 rc = dasd_format(base->block, &fdata);
232 dasd_put_device(base);
233 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
236#ifdef CONFIG_DASD_PROFILE
237/*
238 * Reset device profile information
239 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100240static int dasd_ioctl_reset_profile(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200242 dasd_profile_reset(&block->profile);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 return 0;
244}
245
246/*
247 * Return device profile information
248 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100249static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200251 struct dasd_profile_info_t *data;
Julia Lawallba465d82011-08-24 17:15:10 +0200252 int rc = 0;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200253
254 data = kmalloc(sizeof(*data), GFP_KERNEL);
255 if (!data)
256 return -ENOMEM;
257
258 spin_lock_bh(&block->profile.lock);
259 if (block->profile.data) {
260 data->dasd_io_reqs = block->profile.data->dasd_io_reqs;
261 data->dasd_io_sects = block->profile.data->dasd_io_sects;
262 memcpy(data->dasd_io_secs, block->profile.data->dasd_io_secs,
263 sizeof(data->dasd_io_secs));
264 memcpy(data->dasd_io_times, block->profile.data->dasd_io_times,
265 sizeof(data->dasd_io_times));
266 memcpy(data->dasd_io_timps, block->profile.data->dasd_io_timps,
267 sizeof(data->dasd_io_timps));
268 memcpy(data->dasd_io_time1, block->profile.data->dasd_io_time1,
269 sizeof(data->dasd_io_time1));
270 memcpy(data->dasd_io_time2, block->profile.data->dasd_io_time2,
271 sizeof(data->dasd_io_time2));
272 memcpy(data->dasd_io_time2ps,
273 block->profile.data->dasd_io_time2ps,
274 sizeof(data->dasd_io_time2ps));
275 memcpy(data->dasd_io_time3, block->profile.data->dasd_io_time3,
276 sizeof(data->dasd_io_time3));
277 memcpy(data->dasd_io_nr_req,
278 block->profile.data->dasd_io_nr_req,
279 sizeof(data->dasd_io_nr_req));
280 spin_unlock_bh(&block->profile.lock);
281 } else {
282 spin_unlock_bh(&block->profile.lock);
Julia Lawallba465d82011-08-24 17:15:10 +0200283 rc = -EIO;
284 goto out;
Stefan Weinhuber4fa52aa2011-07-24 10:48:32 +0200285 }
286 if (copy_to_user(argp, data, sizeof(*data)))
Julia Lawallba465d82011-08-24 17:15:10 +0200287 rc = -EFAULT;
288out:
289 kfree(data);
290 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292#else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100293static int dasd_ioctl_reset_profile(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 return -ENOSYS;
296}
297
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100298static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 return -ENOSYS;
301}
302#endif
303
304/*
305 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
306 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100307static int dasd_ioctl_information(struct dasd_block *block,
308 unsigned int cmd, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 struct dasd_information2_t *dasd_info;
311 unsigned long flags;
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700312 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100313 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct ccw_device *cdev;
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200315 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100317 base = block->base;
Stefan Haberland294001a2010-01-27 10:12:35 +0100318 if (!base->discipline || !base->discipline->fill_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return -EINVAL;
320
Horst Hummel554a8262006-03-24 03:15:24 -0800321 dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (dasd_info == NULL)
323 return -ENOMEM;
324
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100325 rc = base->discipline->fill_info(base, dasd_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 if (rc) {
327 kfree(dasd_info);
328 return rc;
329 }
330
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100331 cdev = base->cdev;
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200332 ccw_device_get_id(cdev, &dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200334 dasd_info->devno = dev_id.devno;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100335 dasd_info->schid = _ccw_device_get_subchannel_number(base->cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 dasd_info->cu_type = cdev->id.cu_type;
337 dasd_info->cu_model = cdev->id.cu_model;
338 dasd_info->dev_type = cdev->id.dev_type;
339 dasd_info->dev_model = cdev->id.dev_model;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100340 dasd_info->status = base->state;
Horst Hummel57467192006-02-01 03:06:36 -0800341 /*
342 * The open_count is increased for every opener, that includes
343 * the blkdev_get in dasd_scan_partitions.
344 * This must be hidden from user-space.
345 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100346 dasd_info->open_count = atomic_read(&block->open_count);
347 if (!block->bdev)
Horst Hummel57467192006-02-01 03:06:36 -0800348 dasd_info->open_count++;
Horst Hummel138c0142006-06-29 14:58:12 +0200349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 /*
351 * check if device is really formatted
352 * LDL / CDL was returned by 'fill_info'
353 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100354 if ((base->state < DASD_STATE_READY) ||
355 (dasd_check_blocksize(block->bp_block)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 dasd_info->format = DASD_FORMAT_NONE;
Horst Hummelf24acd42005-05-01 08:58:59 -0700357
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700358 dasd_info->features |=
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100359 ((base->features & DASD_FEATURE_READONLY) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Stefan Haberland294001a2010-01-27 10:12:35 +0100361 memcpy(dasd_info->type, base->discipline->name, 4);
Horst Hummel554a8262006-03-24 03:15:24 -0800362
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100363 if (block->request_queue->request_fn) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 struct list_head *l;
365#ifdef DASD_EXTENDED_PROFILING
366 {
367 struct list_head *l;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100368 spin_lock_irqsave(&block->lock, flags);
369 list_for_each(l, &block->request_queue->queue_head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 dasd_info->req_queue_len++;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100371 spin_unlock_irqrestore(&block->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
373#endif /* DASD_EXTENDED_PROFILING */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100374 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
375 list_for_each(l, &base->ccw_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 dasd_info->chanq_len++;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100377 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 flags);
379 }
380
381 rc = 0;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800382 if (copy_to_user(argp, dasd_info,
383 ((cmd == (unsigned int) BIODASDINFO2) ?
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100384 sizeof(struct dasd_information2_t) :
385 sizeof(struct dasd_information_t))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 rc = -EFAULT;
387 kfree(dasd_info);
388 return rc;
389}
390
391/*
392 * Set read only
393 */
394static int
Christoph Hellwig13c62042006-03-24 03:15:19 -0800395dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200397 struct dasd_device *base;
398 int intval, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 if (!capable(CAP_SYS_ADMIN))
401 return -EACCES;
402 if (bdev != bdev->bd_contains)
403 // ro setting is not allowed for partitions
404 return -EINVAL;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200405 if (get_user(intval, (int __user *)argp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return -EFAULT;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200407 base = dasd_device_from_gendisk(bdev->bd_disk);
408 if (!base)
409 return -ENODEV;
410 if (!intval && test_bit(DASD_FLAG_DEVICE_RO, &base->flags)) {
411 dasd_put_device(base);
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100412 return -EROFS;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 set_disk_ro(bdev->bd_disk, intval);
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200415 rc = dasd_set_feature(base->cdev, DASD_FEATURE_READONLY, intval);
416 dasd_put_device(base);
417 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100420static int dasd_ioctl_readall_cmb(struct dasd_block *block, unsigned int cmd,
Heiko Carstens88034862010-01-13 20:44:29 +0100421 struct cmbdata __user *argp)
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800422{
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800423 size_t size = _IOC_SIZE(cmd);
424 struct cmbdata data;
425 int ret;
426
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100427 ret = cmf_readall(block->base->cdev, &data);
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800428 if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp))))
429 return -EFAULT;
430 return ret;
431}
432
Arnd Bergmanncfdb00a2010-05-31 22:38:40 +0200433int dasd_ioctl(struct block_device *bdev, fmode_t mode,
434 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200436 struct dasd_block *block;
437 struct dasd_device *base;
Heiko Carstens88034862010-01-13 20:44:29 +0100438 void __user *argp;
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200439 int rc;
Heiko Carstens88034862010-01-13 20:44:29 +0100440
441 if (is_compat_task())
442 argp = compat_ptr(arg);
443 else
444 argp = (void __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Christoph Hellwig13c62042006-03-24 03:15:19 -0800446 if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) {
447 PRINT_DEBUG("empty data ptr");
448 return -EINVAL;
449 }
450
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200451 base = dasd_device_from_gendisk(bdev->bd_disk);
452 if (!base)
453 return -ENODEV;
454 block = base->block;
455 rc = 0;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800456 switch (cmd) {
457 case BIODASDDISABLE:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200458 rc = dasd_ioctl_disable(bdev);
459 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800460 case BIODASDENABLE:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200461 rc = dasd_ioctl_enable(bdev);
462 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800463 case BIODASDQUIESCE:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200464 rc = dasd_ioctl_quiesce(block);
465 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800466 case BIODASDRESUME:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200467 rc = dasd_ioctl_resume(block);
468 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800469 case BIODASDFMT:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200470 rc = dasd_ioctl_format(bdev, argp);
471 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800472 case BIODASDINFO:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200473 rc = dasd_ioctl_information(block, cmd, argp);
474 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800475 case BIODASDINFO2:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200476 rc = dasd_ioctl_information(block, cmd, argp);
477 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800478 case BIODASDPRRD:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200479 rc = dasd_ioctl_read_profile(block, argp);
480 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800481 case BIODASDPRRST:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200482 rc = dasd_ioctl_reset_profile(block);
483 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800484 case BLKROSET:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200485 rc = dasd_ioctl_set_ro(bdev, argp);
486 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800487 case DASDAPIVER:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200488 rc = dasd_ioctl_api_version(argp);
489 break;
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800490 case BIODASDCMFENABLE:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200491 rc = enable_cmf(base->cdev);
492 break;
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800493 case BIODASDCMFDISABLE:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200494 rc = disable_cmf(base->cdev);
495 break;
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800496 case BIODASDREADALLCMB:
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200497 rc = dasd_ioctl_readall_cmb(block, cmd, argp);
498 break;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800499 default:
Christoph Hellwig1107ccf2006-03-24 03:15:20 -0800500 /* if the discipline has an ioctl method try it. */
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200501 if (base->discipline->ioctl) {
502 rc = base->discipline->ioctl(block, cmd, argp);
503 if (rc == -ENOIOCTLCMD)
504 rc = -EINVAL;
505 } else
506 rc = -EINVAL;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800507 }
Stefan Weinhuber65f8da42011-04-20 10:15:30 +0200508 dasd_put_device(base);
509 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}