Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *		    Horst Hummel <Horst.Hummel@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *		    Carsten Otte <Cotte@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *		    Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Bugreports.to..: <Linux390@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright IBM Corp. 1999, 2001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * gendisk related functions for the dasd driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define KMSG_COMPONENT "dasd"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/blkpg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /* This is ugly... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define PRINTK_HEADER "dasd_gendisk:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "dasd_int.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * Allocate and register gendisk structure for device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) int dasd_gendisk_alloc(struct dasd_block *block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct gendisk *gdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct dasd_device *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	/* Make sure the minor for this device exists. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	base = block->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (base->devindex >= DASD_PER_MAJOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	gdp = alloc_disk(1 << DASD_PARTN_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (!gdp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* Initialize gendisk structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	gdp->major = DASD_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	gdp->first_minor = base->devindex << DASD_PARTN_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	gdp->fops = &dasd_device_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 * Set device name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 *   dasda - dasdz : 26 devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 *   dasdaa - dasdzz : 676 devices, added up = 702
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 *   dasdaaa - dasdzzz : 17576 devices, added up = 18278
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 *   dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	len = sprintf(gdp->disk_name, "dasd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (base->devindex > 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		if (base->devindex > 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			if (base->devindex > 18277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			        len += sprintf(gdp->disk_name + len, "%c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 					       'a'+(((base->devindex-18278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 						     /17576)%26));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			len += sprintf(gdp->disk_name + len, "%c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				       'a'+(((base->devindex-702)/676)%26));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		len += sprintf(gdp->disk_name + len, "%c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			       'a'+(((base->devindex-26)/26)%26));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	len += sprintf(gdp->disk_name + len, "%c", 'a'+(base->devindex%26));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (base->features & DASD_FEATURE_READONLY ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	    test_bit(DASD_FLAG_DEVICE_RO, &base->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		set_disk_ro(gdp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	dasd_add_link_to_gendisk(gdp, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	gdp->queue = block->request_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	block->gdp = gdp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	set_capacity(block->gdp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	device_add_disk(&base->cdev->dev, block->gdp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * Unregister and free gendisk structure for device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) void dasd_gendisk_free(struct dasd_block *block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (block->gdp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		del_gendisk(block->gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		block->gdp->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		put_disk(block->gdp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		block->gdp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * Trigger a partition detection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) int dasd_scan_partitions(struct dasd_block *block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct block_device *bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	bdev = blkdev_get_by_dev(disk_devt(block->gdp), FMODE_READ, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (IS_ERR(bdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		DBF_DEV_EVENT(DBF_ERR, block->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			      "scan partitions error, blkdev_get returned %ld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			      PTR_ERR(bdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	mutex_lock(&bdev->bd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	rc = bdev_disk_changed(bdev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	mutex_unlock(&bdev->bd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		DBF_DEV_EVENT(DBF_ERR, block->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				"scan partitions error, rc %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * Since the matching blkdev_put call to the blkdev_get in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * this function is not called before dasd_destroy_partitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * the offline open_count limit needs to be increased from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 * 0 to 1. This is done by setting device->bdev (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * dasd_generic_set_offline). As long as the partition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 * detection is running no offline should be allowed. That
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 * is why the assignment to device->bdev is done AFTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * the BLKRRPART ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	block->bdev = bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * Remove all inodes in the system for a device, delete the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * partitions and make device unusable by setting its size to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) void dasd_destroy_partitions(struct dasd_block *block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct block_device *bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 * Get the bdev pointer from the device structure and clear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	 * device->bdev to lower the offline open_count limit again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	bdev = block->bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	block->bdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	mutex_lock(&bdev->bd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	blk_drop_partitions(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	mutex_unlock(&bdev->bd_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	blkdev_put(bdev, FMODE_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	set_capacity(block->gdp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int dasd_gendisk_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	/* Register to static dasd major 94 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	rc = register_blkdev(DASD_MAJOR, "dasd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		pr_warn("Registering the device driver with major number %d failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			DASD_MAJOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) void dasd_gendisk_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	unregister_blkdev(DASD_MAJOR, "dasd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }