2 * 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>
7 * Copyright IBM Corp. 1999, 2001
9 * i/o controls for the dasd driver.
12 #define KMSG_COMPONENT "dasd"
14 #include <linux/interrupt.h>
15 #include <linux/compat.h>
16 #include <linux/major.h>
18 #include <linux/blkpg.h>
19 #include <linux/slab.h>
20 #include <asm/compat.h>
21 #include <asm/ccwdev.h>
22 #include <asm/schid.h>
24 #include <asm/uaccess.h>
27 #define PRINTK_HEADER "dasd_ioctl:"
33 dasd_ioctl_api_version(void __user *argp)
35 int ver = DASD_API_VERSION;
36 return put_user(ver, (int __user *)argp);
41 * used by dasdfmt after BIODASDDISABLE to retrigger blocksize detection
44 dasd_ioctl_enable(struct block_device *bdev)
46 struct dasd_device *base;
48 if (!capable(CAP_SYS_ADMIN))
51 base = dasd_device_from_gendisk(bdev->bd_disk);
55 dasd_enable_device(base);
56 /* Formatting the dasd device can change the capacity. */
57 mutex_lock(&bdev->bd_mutex);
58 i_size_write(bdev->bd_inode,
59 (loff_t)get_capacity(base->block->gdp) << 9);
60 mutex_unlock(&bdev->bd_mutex);
61 dasd_put_device(base);
67 * Used by dasdfmt. Disable I/O operations but allow ioctls.
70 dasd_ioctl_disable(struct block_device *bdev)
72 struct dasd_device *base;
74 if (!capable(CAP_SYS_ADMIN))
77 base = dasd_device_from_gendisk(bdev->bd_disk);
81 * Man this is sick. We don't do a real disable but only downgrade
82 * the device to DASD_STATE_BASIC. The reason is that dasdfmt uses
83 * BIODASDDISABLE to disable accesses to the device via the block
84 * device layer but it still wants to do i/o on the device by
85 * using the BIODASDFMT ioctl. Therefore the correct state for the
86 * device is DASD_STATE_BASIC that allows to do basic i/o.
88 dasd_set_target_state(base, DASD_STATE_BASIC);
90 * Set i_size to zero, since read, write, etc. check against this
93 mutex_lock(&bdev->bd_mutex);
94 i_size_write(bdev->bd_inode, 0);
95 mutex_unlock(&bdev->bd_mutex);
96 dasd_put_device(base);
103 static int dasd_ioctl_quiesce(struct dasd_block *block)
106 struct dasd_device *base;
109 if (!capable (CAP_SYS_ADMIN))
112 pr_info("%s: The DASD has been put in the quiesce "
113 "state\n", dev_name(&base->cdev->dev));
114 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
115 dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
116 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
124 static int dasd_ioctl_resume(struct dasd_block *block)
127 struct dasd_device *base;
130 if (!capable (CAP_SYS_ADMIN))
133 pr_info("%s: I/O operations have been resumed "
134 "on the DASD\n", dev_name(&base->cdev->dev));
135 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
136 dasd_device_remove_stop_bits(base, DASD_STOPPED_QUIESCE);
137 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev), flags);
139 dasd_schedule_block_bh(block);
144 * performs formatting of _device_ according to _fdata_
145 * Note: The discipline's format_function is assumed to deliver formatting
146 * commands to format multiple units of the device. In terms of the ECKD
147 * devices this means CCWs are generated to format multiple tracks.
150 dasd_format(struct dasd_block *block, struct format_data_t *fdata)
152 struct dasd_device *base;
156 if (base->discipline->format_device == NULL)
159 if (base->state != DASD_STATE_BASIC) {
160 pr_warn("%s: The DASD cannot be formatted while it is enabled\n",
161 dev_name(&base->cdev->dev));
165 DBF_DEV_EVENT(DBF_NOTICE, base,
166 "formatting units %u to %u (%u B blocks) flags %u",
168 fdata->stop_unit, fdata->blksize, fdata->intensity);
170 /* Since dasdfmt keeps the device open after it was disabled,
171 * there still exists an inode for this device.
172 * We must update i_blkbits, otherwise we might get errors when
173 * enabling the device later.
175 if (fdata->start_unit == 0) {
176 struct block_device *bdev = bdget_disk(block->gdp, 0);
177 bdev->bd_inode->i_blkbits = blksize_bits(fdata->blksize);
181 rc = base->discipline->format_device(base, fdata);
192 dasd_ioctl_format(struct block_device *bdev, void __user *argp)
194 struct dasd_device *base;
195 struct format_data_t fdata;
198 if (!capable(CAP_SYS_ADMIN))
202 base = dasd_device_from_gendisk(bdev->bd_disk);
205 if (base->features & DASD_FEATURE_READONLY ||
206 test_bit(DASD_FLAG_DEVICE_RO, &base->flags)) {
207 dasd_put_device(base);
210 if (copy_from_user(&fdata, argp, sizeof(struct format_data_t))) {
211 dasd_put_device(base);
214 if (bdev != bdev->bd_contains) {
215 pr_warning("%s: The specified DASD is a partition and cannot "
217 dev_name(&base->cdev->dev));
218 dasd_put_device(base);
221 rc = dasd_format(base->block, &fdata);
222 dasd_put_device(base);
226 #ifdef CONFIG_DASD_PROFILE
228 * Reset device profile information
230 static int dasd_ioctl_reset_profile(struct dasd_block *block)
232 dasd_profile_reset(&block->profile);
237 * Return device profile information
239 static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
241 struct dasd_profile_info_t *data;
244 data = kmalloc(sizeof(*data), GFP_KERNEL);
248 spin_lock_bh(&block->profile.lock);
249 if (block->profile.data) {
250 data->dasd_io_reqs = block->profile.data->dasd_io_reqs;
251 data->dasd_io_sects = block->profile.data->dasd_io_sects;
252 memcpy(data->dasd_io_secs, block->profile.data->dasd_io_secs,
253 sizeof(data->dasd_io_secs));
254 memcpy(data->dasd_io_times, block->profile.data->dasd_io_times,
255 sizeof(data->dasd_io_times));
256 memcpy(data->dasd_io_timps, block->profile.data->dasd_io_timps,
257 sizeof(data->dasd_io_timps));
258 memcpy(data->dasd_io_time1, block->profile.data->dasd_io_time1,
259 sizeof(data->dasd_io_time1));
260 memcpy(data->dasd_io_time2, block->profile.data->dasd_io_time2,
261 sizeof(data->dasd_io_time2));
262 memcpy(data->dasd_io_time2ps,
263 block->profile.data->dasd_io_time2ps,
264 sizeof(data->dasd_io_time2ps));
265 memcpy(data->dasd_io_time3, block->profile.data->dasd_io_time3,
266 sizeof(data->dasd_io_time3));
267 memcpy(data->dasd_io_nr_req,
268 block->profile.data->dasd_io_nr_req,
269 sizeof(data->dasd_io_nr_req));
270 spin_unlock_bh(&block->profile.lock);
272 spin_unlock_bh(&block->profile.lock);
276 if (copy_to_user(argp, data, sizeof(*data)))
283 static int dasd_ioctl_reset_profile(struct dasd_block *block)
288 static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp)
295 * Return dasd information. Used for BIODASDINFO and BIODASDINFO2.
297 static int dasd_ioctl_information(struct dasd_block *block,
298 unsigned int cmd, void __user *argp)
300 struct dasd_information2_t *dasd_info;
301 struct subchannel_id sch_id;
302 struct ccw_dev_id dev_id;
303 struct dasd_device *base;
304 struct ccw_device *cdev;
309 if (!base->discipline || !base->discipline->fill_info)
312 dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
313 if (dasd_info == NULL)
316 rc = base->discipline->fill_info(base, dasd_info);
323 ccw_device_get_id(cdev, &dev_id);
324 ccw_device_get_schid(cdev, &sch_id);
326 dasd_info->devno = dev_id.devno;
327 dasd_info->schid = sch_id.sch_no;
328 dasd_info->cu_type = cdev->id.cu_type;
329 dasd_info->cu_model = cdev->id.cu_model;
330 dasd_info->dev_type = cdev->id.dev_type;
331 dasd_info->dev_model = cdev->id.dev_model;
332 dasd_info->status = base->state;
334 * The open_count is increased for every opener, that includes
335 * the blkdev_get in dasd_scan_partitions.
336 * This must be hidden from user-space.
338 dasd_info->open_count = atomic_read(&block->open_count);
340 dasd_info->open_count++;
343 * check if device is really formatted
344 * LDL / CDL was returned by 'fill_info'
346 if ((base->state < DASD_STATE_READY) ||
347 (dasd_check_blocksize(block->bp_block)))
348 dasd_info->format = DASD_FORMAT_NONE;
350 dasd_info->features |=
351 ((base->features & DASD_FEATURE_READONLY) != 0);
353 memcpy(dasd_info->type, base->discipline->name, 4);
355 if (block->request_queue->request_fn) {
357 #ifdef DASD_EXTENDED_PROFILING
360 spin_lock_irqsave(&block->lock, flags);
361 list_for_each(l, &block->request_queue->queue_head)
362 dasd_info->req_queue_len++;
363 spin_unlock_irqrestore(&block->lock, flags);
365 #endif /* DASD_EXTENDED_PROFILING */
366 spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
367 list_for_each(l, &base->ccw_queue)
368 dasd_info->chanq_len++;
369 spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
374 if (copy_to_user(argp, dasd_info,
375 ((cmd == (unsigned int) BIODASDINFO2) ?
376 sizeof(struct dasd_information2_t) :
377 sizeof(struct dasd_information_t))))
387 dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
389 struct dasd_device *base;
392 if (!capable(CAP_SYS_ADMIN))
394 if (bdev != bdev->bd_contains)
395 // ro setting is not allowed for partitions
397 if (get_user(intval, (int __user *)argp))
399 base = dasd_device_from_gendisk(bdev->bd_disk);
402 if (!intval && test_bit(DASD_FLAG_DEVICE_RO, &base->flags)) {
403 dasd_put_device(base);
406 set_disk_ro(bdev->bd_disk, intval);
407 rc = dasd_set_feature(base->cdev, DASD_FEATURE_READONLY, intval);
408 dasd_put_device(base);
412 static int dasd_ioctl_readall_cmb(struct dasd_block *block, unsigned int cmd,
413 struct cmbdata __user *argp)
415 size_t size = _IOC_SIZE(cmd);
419 ret = cmf_readall(block->base->cdev, &data);
420 if (!ret && copy_to_user(argp, &data, min(size, sizeof(*argp))))
425 int dasd_ioctl(struct block_device *bdev, fmode_t mode,
426 unsigned int cmd, unsigned long arg)
428 struct dasd_block *block;
429 struct dasd_device *base;
433 if (is_compat_task())
434 argp = compat_ptr(arg);
436 argp = (void __user *)arg;
438 if ((_IOC_DIR(cmd) != _IOC_NONE) && !arg) {
439 PRINT_DEBUG("empty data ptr");
443 base = dasd_device_from_gendisk(bdev->bd_disk);
450 rc = dasd_ioctl_disable(bdev);
453 rc = dasd_ioctl_enable(bdev);
456 rc = dasd_ioctl_quiesce(block);
459 rc = dasd_ioctl_resume(block);
462 rc = dasd_ioctl_format(bdev, argp);
465 rc = dasd_ioctl_information(block, cmd, argp);
468 rc = dasd_ioctl_information(block, cmd, argp);
471 rc = dasd_ioctl_read_profile(block, argp);
474 rc = dasd_ioctl_reset_profile(block);
477 rc = dasd_ioctl_set_ro(bdev, argp);
480 rc = dasd_ioctl_api_version(argp);
482 case BIODASDCMFENABLE:
483 rc = enable_cmf(base->cdev);
485 case BIODASDCMFDISABLE:
486 rc = disable_cmf(base->cdev);
488 case BIODASDREADALLCMB:
489 rc = dasd_ioctl_readall_cmb(block, cmd, argp);
492 /* if the discipline has an ioctl method try it. */
494 if (base->discipline->ioctl)
495 rc = base->discipline->ioctl(block, cmd, argp);
497 dasd_put_device(base);