1 // SPDX-License-Identifier: GPL-2.0
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 * Copyright IBM Corp. 1999, 2001
10 * gendisk related functions for the dasd driver.
14 #define KMSG_COMPONENT "dasd"
16 #include <linux/interrupt.h>
17 #include <linux/major.h>
19 #include <linux/blkpg.h>
21 #include <linux/uaccess.h>
24 #define PRINTK_HEADER "dasd_gendisk:"
28 static unsigned int queue_depth = 32;
29 static unsigned int nr_hw_queues = 4;
31 module_param(queue_depth, uint, 0444);
32 MODULE_PARM_DESC(queue_depth, "Default queue depth for new DASD devices");
34 module_param(nr_hw_queues, uint, 0444);
35 MODULE_PARM_DESC(nr_hw_queues, "Default number of hardware queues for new DASD devices");
38 * Allocate and register gendisk structure for device.
40 int dasd_gendisk_alloc(struct dasd_block *block)
43 struct dasd_device *base;
46 /* Make sure the minor for this device exists. */
48 if (base->devindex >= DASD_PER_MAJOR)
51 block->tag_set.ops = &dasd_mq_ops;
52 block->tag_set.cmd_size = sizeof(struct dasd_ccw_req);
53 block->tag_set.nr_hw_queues = nr_hw_queues;
54 block->tag_set.queue_depth = queue_depth;
55 block->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
56 block->tag_set.numa_node = NUMA_NO_NODE;
57 rc = blk_mq_alloc_tag_set(&block->tag_set);
61 gdp = blk_mq_alloc_disk(&block->tag_set, block);
63 blk_mq_free_tag_set(&block->tag_set);
67 /* Initialize gendisk structure. */
68 gdp->major = DASD_MAJOR;
69 gdp->first_minor = base->devindex << DASD_PARTN_BITS;
70 gdp->minors = 1 << DASD_PARTN_BITS;
71 gdp->fops = &dasd_device_operations;
75 * dasda - dasdz : 26 devices
76 * dasdaa - dasdzz : 676 devices, added up = 702
77 * dasdaaa - dasdzzz : 17576 devices, added up = 18278
78 * dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
80 len = sprintf(gdp->disk_name, "dasd");
81 if (base->devindex > 25) {
82 if (base->devindex > 701) {
83 if (base->devindex > 18277)
84 len += sprintf(gdp->disk_name + len, "%c",
85 'a'+(((base->devindex-18278)
87 len += sprintf(gdp->disk_name + len, "%c",
88 'a'+(((base->devindex-702)/676)%26));
90 len += sprintf(gdp->disk_name + len, "%c",
91 'a'+(((base->devindex-26)/26)%26));
93 len += sprintf(gdp->disk_name + len, "%c", 'a'+(base->devindex%26));
95 if (base->features & DASD_FEATURE_READONLY ||
96 test_bit(DASD_FLAG_DEVICE_RO, &base->flags))
98 dasd_add_link_to_gendisk(gdp, base);
100 set_capacity(block->gdp, 0);
102 rc = device_add_disk(&base->cdev->dev, block->gdp, NULL);
104 dasd_gendisk_free(block);
112 * Unregister and free gendisk structure for device.
114 void dasd_gendisk_free(struct dasd_block *block)
117 del_gendisk(block->gdp);
118 block->gdp->private_data = NULL;
119 put_disk(block->gdp);
121 blk_mq_free_tag_set(&block->tag_set);
126 * Trigger a partition detection.
128 int dasd_scan_partitions(struct dasd_block *block)
130 struct block_device *bdev;
133 bdev = blkdev_get_by_dev(disk_devt(block->gdp), FMODE_READ, NULL);
135 DBF_DEV_EVENT(DBF_ERR, block->base,
136 "scan partitions error, blkdev_get returned %ld",
141 mutex_lock(&block->gdp->open_mutex);
142 rc = bdev_disk_changed(block->gdp, false);
143 mutex_unlock(&block->gdp->open_mutex);
145 DBF_DEV_EVENT(DBF_ERR, block->base,
146 "scan partitions error, rc %d", rc);
149 * Since the matching blkdev_put call to the blkdev_get in
150 * this function is not called before dasd_destroy_partitions
151 * the offline open_count limit needs to be increased from
152 * 0 to 1. This is done by setting device->bdev (see
153 * dasd_generic_set_offline). As long as the partition
154 * detection is running no offline should be allowed. That
155 * is why the assignment to device->bdev is done AFTER
156 * the BLKRRPART ioctl.
163 * Remove all inodes in the system for a device, delete the
164 * partitions and make device unusable by setting its size to zero.
166 void dasd_destroy_partitions(struct dasd_block *block)
168 struct block_device *bdev;
171 * Get the bdev pointer from the device structure and clear
172 * device->bdev to lower the offline open_count limit again.
177 mutex_lock(&bdev->bd_disk->open_mutex);
178 bdev_disk_changed(bdev->bd_disk, true);
179 mutex_unlock(&bdev->bd_disk->open_mutex);
181 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
182 blkdev_put(bdev, FMODE_READ);
185 int dasd_gendisk_init(void)
189 /* Register to static dasd major 94 */
190 rc = register_blkdev(DASD_MAJOR, "dasd");
192 pr_warn("Registering the device driver with major number %d failed\n",
199 void dasd_gendisk_exit(void)
201 unregister_blkdev(DASD_MAJOR, "dasd");