blob: 26075e95b1bad786db8ff7b0e8504521fe8f3d68 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * File...........: linux/drivers/s390/block/dasd_ioctl.c
3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4 * Horst Hummel <Horst.Hummel@de.ibm.com>
5 * Carsten Otte <Cotte@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
9 *
10 * i/o controls for the dasd driver.
11 */
Stefan Haberlandfc19f382009-03-26 15:23:49 +010012
13#define KMSG_COMPONENT "dasd"
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/interrupt.h>
16#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 Weinhuber8e09f212008-01-26 14:11:23 +010045 struct dasd_block *block = bdev->bd_disk->private_data;
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 Weinhuber8e09f212008-01-26 14:11:23 +010050 dasd_enable_device(block->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 /* Formatting the dasd device can change the capacity. */
Arjan van de Venc039e312006-03-23 03:00:28 -080052 mutex_lock(&bdev->bd_mutex);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010053 i_size_write(bdev->bd_inode, (loff_t)get_capacity(block->gdp) << 9);
Arjan van de Venc039e312006-03-23 03:00:28 -080054 mutex_unlock(&bdev->bd_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return 0;
56}
57
58/*
59 * Disable device.
60 * Used by dasdfmt. Disable I/O operations but allow ioctls.
61 */
62static int
Christoph Hellwig13c62042006-03-24 03:15:19 -080063dasd_ioctl_disable(struct block_device *bdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010065 struct dasd_block *block = bdev->bd_disk->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 if (!capable(CAP_SYS_ADMIN))
68 return -EACCES;
Christoph Hellwig13c62042006-03-24 03:15:19 -080069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 /*
71 * Man this is sick. We don't do a real disable but only downgrade
72 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
73 * BIODASDDISABLE to disable accesses to the device via the block
74 * device layer but it still wants to do i/o on the device by
75 * using the BIODASDFMT ioctl. Therefore the correct state for the
76 * device is DASD_STATE_BASIC that allows to do basic i/o.
77 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010078 dasd_set_target_state(block->base, DASD_STATE_BASIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /*
80 * Set i_size to zero, since read, write, etc. check against this
81 * value.
82 */
Arjan van de Venc039e312006-03-23 03:00:28 -080083 mutex_lock(&bdev->bd_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 i_size_write(bdev->bd_inode, 0);
Arjan van de Venc039e312006-03-23 03:00:28 -080085 mutex_unlock(&bdev->bd_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return 0;
87}
88
89/*
90 * Quiesce device.
91 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010092static int dasd_ioctl_quiesce(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 unsigned long flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010095 struct dasd_device *base;
Horst Hummel138c0142006-06-29 14:58:12 +020096
Stefan Weinhuber8e09f212008-01-26 14:11:23 +010097 base = block->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (!capable (CAP_SYS_ADMIN))
99 return -EACCES;
Horst Hummel138c0142006-06-29 14:58:12 +0200100
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200101 pr_info("%s: The DASD has been put in the quiesce "
102 "state\n", dev_name(&base->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100103 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100104 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100105 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return 0;
107}
108
109
110/*
Stefan Haberlandfc19f382009-03-26 15:23:49 +0100111 * Resume device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100113static int dasd_ioctl_resume(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 unsigned long flags;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100116 struct dasd_device *base;
Horst Hummel138c0142006-06-29 14:58:12 +0200117
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100118 base = block->base;
Horst Hummel138c0142006-06-29 14:58:12 +0200119 if (!capable (CAP_SYS_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return -EACCES;
121
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200122 pr_info("%s: I/O operations have been resumed "
123 "on the DASD\n", dev_name(&base->cdev->dev));
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100124 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
Stefan Weinhubereb6e1992009-12-07 12:51:51 +0100125 dasd_device_remove_stop_bits(base, DASD_STOPPED_QUIESCE);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100126 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
Horst Hummel138c0142006-06-29 14:58:12 +0200127
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100128 dasd_schedule_block_bh(block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return 0;
130}
131
132/*
133 * performs formatting of _device_ according to _fdata_
134 * Note: The discipline's format_function is assumed to deliver formatting
135 * commands to format a single unit of the device. In terms of the ECKD
136 * devices this means CCWs are generated to format a single track.
137 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100138static int dasd_format(struct dasd_block *block, struct format_data_t *fdata)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
140 struct dasd_ccw_req *cqr;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100141 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 int rc;
143
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100144 base = block->base;
145 if (base->discipline->format_device == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return -EPERM;
147
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100148 if (base->state != DASD_STATE_BASIC) {
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200149 pr_warning("%s: The DASD cannot be formatted while it is "
150 "enabled\n", dev_name(&base->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 return -EBUSY;
152 }
153
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100154 DBF_DEV_EVENT(DBF_NOTICE, base,
Stefan Weinhuberb44b0ab32009-03-26 15:23:47 +0100155 "formatting units %u to %u (%u B blocks) flags %u",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 fdata->start_unit,
157 fdata->stop_unit, fdata->blksize, fdata->intensity);
158
159 /* Since dasdfmt keeps the device open after it was disabled,
160 * there still exists an inode for this device.
161 * We must update i_blkbits, otherwise we might get errors when
162 * enabling the device later.
163 */
164 if (fdata->start_unit == 0) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100165 struct block_device *bdev = bdget_disk(block->gdp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 bdev->bd_inode->i_blkbits = blksize_bits(fdata->blksize);
167 bdput(bdev);
168 }
169
170 while (fdata->start_unit <= fdata->stop_unit) {
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100171 cqr = base->discipline->format_device(base, fdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 if (IS_ERR(cqr))
173 return PTR_ERR(cqr);
174 rc = dasd_sleep_on_interruptible(cqr);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100175 dasd_sfree_request(cqr, cqr->memdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if (rc) {
177 if (rc != -ERESTARTSYS)
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200178 pr_err("%s: Formatting unit %d failed with "
179 "rc=%d\n", dev_name(&base->cdev->dev),
180 fdata->start_unit, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return rc;
182 }
183 fdata->start_unit++;
184 }
185 return 0;
186}
187
188/*
189 * Format device.
190 */
191static int
Christoph Hellwig13c62042006-03-24 03:15:19 -0800192dasd_ioctl_format(struct block_device *bdev, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100194 struct dasd_block *block = bdev->bd_disk->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 struct format_data_t fdata;
196
197 if (!capable(CAP_SYS_ADMIN))
198 return -EACCES;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800199 if (!argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 return -EINVAL;
Horst Hummelf24acd42005-05-01 08:58:59 -0700201
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100202 if (block->base->features & DASD_FEATURE_READONLY ||
203 test_bit(DASD_FLAG_DEVICE_RO, &block->base->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return -EROFS;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800205 if (copy_from_user(&fdata, argp, sizeof(struct format_data_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return -EFAULT;
207 if (bdev != bdev->bd_contains) {
Stefan Haberlandca99dab2009-09-11 10:28:30 +0200208 pr_warning("%s: The specified DASD is a partition and cannot "
209 "be formatted\n",
210 dev_name(&block->base->cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return -EINVAL;
212 }
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100213 return dasd_format(block, &fdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
216#ifdef CONFIG_DASD_PROFILE
217/*
218 * Reset device profile information
219 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100220static int dasd_ioctl_reset_profile(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100222 memset(&block->profile, 0, sizeof(struct dasd_profile_info_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return 0;
224}
225
226/*
227 * Return device profile information
228 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100229static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Horst Hummel9a7af282006-01-06 00:19:14 -0800231 if (dasd_profile_level == DASD_PROFILE_OFF)
232 return -EIO;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100233 if (copy_to_user(argp, &block->profile,
234 sizeof(struct dasd_profile_info_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 return -EFAULT;
236 return 0;
237}
238#else
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100239static int dasd_ioctl_reset_profile(struct dasd_block *block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
241 return -ENOSYS;
242}
243
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100244static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 return -ENOSYS;
247}
248#endif
249
250/*
251 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
252 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100253static int dasd_ioctl_information(struct dasd_block *block,
254 unsigned int cmd, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 struct dasd_information2_t *dasd_info;
257 unsigned long flags;
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700258 int rc;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100259 struct dasd_device *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 struct ccw_device *cdev;
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200261 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100263 base = block->base;
Stefan Haberland294001a2010-01-27 10:12:35 +0100264 if (!base->discipline || !base->discipline->fill_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return -EINVAL;
266
Horst Hummel554a8262006-03-24 03:15:24 -0800267 dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 if (dasd_info == NULL)
269 return -ENOMEM;
270
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100271 rc = base->discipline->fill_info(base, dasd_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (rc) {
273 kfree(dasd_info);
274 return rc;
275 }
276
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100277 cdev = base->cdev;
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200278 ccw_device_get_id(cdev, &dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Cornelia Huck9a92fe42007-05-10 15:45:42 +0200280 dasd_info->devno = dev_id.devno;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100281 dasd_info->schid = _ccw_device_get_subchannel_number(base->cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 dasd_info->cu_type = cdev->id.cu_type;
283 dasd_info->cu_model = cdev->id.cu_model;
284 dasd_info->dev_type = cdev->id.dev_type;
285 dasd_info->dev_model = cdev->id.dev_model;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100286 dasd_info->status = base->state;
Horst Hummel57467192006-02-01 03:06:36 -0800287 /*
288 * The open_count is increased for every opener, that includes
289 * the blkdev_get in dasd_scan_partitions.
290 * This must be hidden from user-space.
291 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100292 dasd_info->open_count = atomic_read(&block->open_count);
293 if (!block->bdev)
Horst Hummel57467192006-02-01 03:06:36 -0800294 dasd_info->open_count++;
Horst Hummel138c0142006-06-29 14:58:12 +0200295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 /*
297 * check if device is really formatted
298 * LDL / CDL was returned by 'fill_info'
299 */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100300 if ((base->state < DASD_STATE_READY) ||
301 (dasd_check_blocksize(block->bp_block)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 dasd_info->format = DASD_FORMAT_NONE;
Horst Hummelf24acd42005-05-01 08:58:59 -0700303
Horst Hummelc6eb7b72005-09-03 15:57:58 -0700304 dasd_info->features |=
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100305 ((base->features & DASD_FEATURE_READONLY) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Stefan Haberland294001a2010-01-27 10:12:35 +0100307 memcpy(dasd_info->type, base->discipline->name, 4);
Horst Hummel554a8262006-03-24 03:15:24 -0800308
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100309 if (block->request_queue->request_fn) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 struct list_head *l;
311#ifdef DASD_EXTENDED_PROFILING
312 {
313 struct list_head *l;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100314 spin_lock_irqsave(&block->lock, flags);
315 list_for_each(l, &block->request_queue->queue_head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 dasd_info->req_queue_len++;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100317 spin_unlock_irqrestore(&block->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 }
319#endif /* DASD_EXTENDED_PROFILING */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100320 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
321 list_for_each(l, &base->ccw_queue)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 dasd_info->chanq_len++;
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100323 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 flags);
325 }
326
327 rc = 0;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800328 if (copy_to_user(argp, dasd_info,
329 ((cmd == (unsigned int) BIODASDINFO2) ?
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100330 sizeof(struct dasd_information2_t) :
331 sizeof(struct dasd_information_t))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 rc = -EFAULT;
333 kfree(dasd_info);
334 return rc;
335}
336
337/*
338 * Set read only
339 */
340static int
Christoph Hellwig13c62042006-03-24 03:15:19 -0800341dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100343 struct dasd_block *block = bdev->bd_disk->private_data;
Christoph Hellwig13c62042006-03-24 03:15:19 -0800344 int intval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 if (!capable(CAP_SYS_ADMIN))
347 return -EACCES;
348 if (bdev != bdev->bd_contains)
349 // ro setting is not allowed for partitions
350 return -EINVAL;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200351 if (get_user(intval, (int __user *)argp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return -EFAULT;
Stefan Weinhuber33b62a32010-03-08 12:26:24 +0100353 if (!intval && test_bit(DASD_FLAG_DEVICE_RO, &block->base->flags))
354 return -EROFS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 set_disk_ro(bdev->bd_disk, intval);
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100356 return dasd_set_feature(block->base->cdev, DASD_FEATURE_READONLY, intval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100359static int dasd_ioctl_readall_cmb(struct dasd_block *block, unsigned int cmd,
Heiko Carstens88034862010-01-13 20:44:29 +0100360 struct cmbdata __user *argp)
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800361{
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800362 size_t size = _IOC_SIZE(cmd);
363 struct cmbdata data;
364 int ret;
365
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100366 ret = cmf_readall(block->base->cdev, &data);
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800367 if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp))))
368 return -EFAULT;
369 return ret;
370}
371
Arnd Bergmanncfdb00a2010-05-31 22:38:40 +0200372int dasd_ioctl(struct block_device *bdev, fmode_t mode,
373 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100375 struct dasd_block *block = bdev->bd_disk->private_data;
Heiko Carstens88034862010-01-13 20:44:29 +0100376 void __user *argp;
377
378 if (is_compat_task())
379 argp = compat_ptr(arg);
380 else
381 argp = (void __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100383 if (!block)
Christoph Hellwig13c62042006-03-24 03:15:19 -0800384 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Christoph Hellwig13c62042006-03-24 03:15:19 -0800386 if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) {
387 PRINT_DEBUG("empty data ptr");
388 return -EINVAL;
389 }
390
391 switch (cmd) {
392 case BIODASDDISABLE:
393 return dasd_ioctl_disable(bdev);
394 case BIODASDENABLE:
395 return dasd_ioctl_enable(bdev);
396 case BIODASDQUIESCE:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100397 return dasd_ioctl_quiesce(block);
Christoph Hellwig13c62042006-03-24 03:15:19 -0800398 case BIODASDRESUME:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100399 return dasd_ioctl_resume(block);
Christoph Hellwig13c62042006-03-24 03:15:19 -0800400 case BIODASDFMT:
401 return dasd_ioctl_format(bdev, argp);
402 case BIODASDINFO:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100403 return dasd_ioctl_information(block, cmd, argp);
Christoph Hellwig13c62042006-03-24 03:15:19 -0800404 case BIODASDINFO2:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100405 return dasd_ioctl_information(block, cmd, argp);
Christoph Hellwig13c62042006-03-24 03:15:19 -0800406 case BIODASDPRRD:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100407 return dasd_ioctl_read_profile(block, argp);
Christoph Hellwig13c62042006-03-24 03:15:19 -0800408 case BIODASDPRRST:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100409 return dasd_ioctl_reset_profile(block);
Christoph Hellwig13c62042006-03-24 03:15:19 -0800410 case BLKROSET:
411 return dasd_ioctl_set_ro(bdev, argp);
412 case DASDAPIVER:
413 return dasd_ioctl_api_version(argp);
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800414 case BIODASDCMFENABLE:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100415 return enable_cmf(block->base->cdev);
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800416 case BIODASDCMFDISABLE:
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100417 return disable_cmf(block->base->cdev);
Christoph Hellwig8b2eb662006-03-24 03:15:21 -0800418 case BIODASDREADALLCMB:
Heiko Carstens88034862010-01-13 20:44:29 +0100419 return dasd_ioctl_readall_cmb(block, cmd, argp);
Christoph Hellwig13c62042006-03-24 03:15:19 -0800420 default:
Christoph Hellwig1107ccf2006-03-24 03:15:20 -0800421 /* if the discipline has an ioctl method try it. */
Stefan Weinhuber8e09f212008-01-26 14:11:23 +0100422 if (block->base->discipline->ioctl) {
423 int rval = block->base->discipline->ioctl(block, cmd, argp);
Christoph Hellwig1107ccf2006-03-24 03:15:20 -0800424 if (rval != -ENOIOCTLCMD)
425 return rval;
426 }
427
Christoph Hellwig13c62042006-03-24 03:15:19 -0800428 return -EINVAL;
429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}