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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  sr.c Copyright (C) 1992 David Giller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *           Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  adapted from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *      sd.c Copyright (C) 1992 Drew Eckhardt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *      Linux scsi disk driver by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *              Drew Eckhardt <drew@colorado.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *	Modified by Eric Youngdale ericy@andante.org to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *	add scatter-gather, multiple outstanding request, and other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *	enhancements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *      Modified by Eric Youngdale eric@andante.org to support loadable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *      low-level scsi drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *      Modified by Thomas Quinot thomas@melchior.cuivre.fdn.fr to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *      provide auto-eject.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *      Modified by Gerd Knorr <kraxel@cs.tu-berlin.de> to support the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *      generic cdrom interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *      Modified by Jens Axboe <axboe@suse.de> - Uniform sr_packet()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *      interface, capabilities probe additions, ioctl cleanups, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *	Modified by Richard Gooch <rgooch@atnf.csiro.au> to support devfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *	Modified by Jens Axboe <axboe@suse.de> - support DVD-RAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *	transparently and lose the GHOST hack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *	Modified by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *	check resource allocation in sr_init and some cleanups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/cdrom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/blk-pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <scsi/scsi_dbg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <scsi/scsi_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include <scsi/scsi_ioctl.h>	/* For the door lock/unlock commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include "scsi_logging.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include "sr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) MODULE_DESCRIPTION("SCSI cdrom (sr) driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_CDROM_MAJOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) MODULE_ALIAS_SCSI_DEVICE(TYPE_ROM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #define SR_DISKS	256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define SR_CAPABILITIES \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	(CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	 CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	 CDC_PLAY_AUDIO|CDC_RESET|CDC_DRIVE_STATUS| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	 CDC_MRW|CDC_MRW_W|CDC_RAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) static int sr_probe(struct device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) static int sr_remove(struct device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) static int sr_done(struct scsi_cmnd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) static int sr_runtime_suspend(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) static const struct dev_pm_ops sr_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	.runtime_suspend	= sr_runtime_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) static struct scsi_driver sr_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	.gendrv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		.name   	= "sr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 		.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 		.probe		= sr_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 		.remove		= sr_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		.pm		= &sr_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	.init_command		= sr_init_command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	.done			= sr_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) static DEFINE_SPINLOCK(sr_index_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) /* This semaphore is used to mediate the 0->1 reference get in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  * face of object destruction (i.e. we can't allow a get on an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * object after last put) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) static DEFINE_MUTEX(sr_ref_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static int sr_open(struct cdrom_device_info *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static void sr_release(struct cdrom_device_info *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) static void get_sectorsize(struct scsi_cd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) static void get_capabilities(struct scsi_cd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static unsigned int sr_check_events(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 				    unsigned int clearing, int slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) static int sr_packet(struct cdrom_device_info *, struct packet_command *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static const struct cdrom_device_ops sr_dops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	.open			= sr_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	.release	 	= sr_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	.drive_status	 	= sr_drive_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	.check_events		= sr_check_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	.tray_move		= sr_tray_move,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	.lock_door		= sr_lock_door,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	.select_speed		= sr_select_speed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	.get_last_session	= sr_get_last_session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	.get_mcn		= sr_get_mcn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	.reset			= sr_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	.audio_ioctl		= sr_audio_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	.capability		= SR_CAPABILITIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	.generic_packet		= sr_packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static void sr_kref_release(struct kref *kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static inline struct scsi_cd *scsi_cd(struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	return container_of(disk->private_data, struct scsi_cd, driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static int sr_runtime_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	struct scsi_cd *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	if (!cd)	/* E.g.: runtime suspend following sr_remove() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	if (cd->media_present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  * The get and put routines for the struct scsi_cd.  Note this entity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)  * has a scsi_device pointer and owns a reference to this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	struct scsi_cd *cd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	mutex_lock(&sr_ref_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	if (disk->private_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	cd = scsi_cd(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	kref_get(&cd->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	if (scsi_device_get(cd->device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		kref_put(&cd->kref, sr_kref_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		cd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	mutex_unlock(&sr_ref_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	return cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) static void scsi_cd_put(struct scsi_cd *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	struct scsi_device *sdev = cd->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	mutex_lock(&sr_ref_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	kref_put(&cd->kref, sr_kref_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	scsi_device_put(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	mutex_unlock(&sr_ref_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) static unsigned int sr_get_events(struct scsi_device *sdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	u8 buf[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	u8 cmd[] = { GET_EVENT_STATUS_NOTIFICATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		     1,			/* polled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		     0, 0,		/* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		     1 << 4,		/* notification class: media */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		     0, 0,		/* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		     0, sizeof(buf),	/* allocation length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		     0,			/* control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	struct event_header *eh = (void *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	struct media_event_desc *med = (void *)(buf + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	struct scsi_sense_hdr sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, sizeof(buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 				  &sshdr, SR_TIMEOUT, MAX_RETRIES, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	if (scsi_sense_valid(&sshdr) && sshdr.sense_key == UNIT_ATTENTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		return DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	if (result || be16_to_cpu(eh->data_len) < sizeof(*med))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	if (eh->nea || eh->notification_class != 0x4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	if (med->media_event_code == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		return DISK_EVENT_EJECT_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	else if (med->media_event_code == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		return DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	else if (med->media_event_code == 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		return DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229)  * This function checks to see if the media has been changed or eject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230)  * button has been pressed.  It is possible that we have already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231)  * sensed a change, or the drive may have sensed one and not yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232)  * reported it.  The past events are accumulated in sdev->changed and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233)  * returned together with the current state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) static unsigned int sr_check_events(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 				    unsigned int clearing, int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	struct scsi_cd *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	bool last_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	struct scsi_sense_hdr sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	unsigned int events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	/* no changer support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	if (CDSL_CURRENT != slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	events = sr_get_events(cd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	cd->get_event_changed |= events & DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	 * If earlier GET_EVENT_STATUS_NOTIFICATION and TUR did not agree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	 * for several times in a row.  We rely on TUR only for this likely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	 * broken device, to prevent generating incorrect media changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	 * events for every open().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	if (cd->ignore_get_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		events &= ~DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		goto do_tur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	 * GET_EVENT_STATUS_NOTIFICATION is enough unless MEDIA_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	 * is being cleared.  Note that there are devices which hang
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	 * if asked to execute TUR repeatedly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	if (cd->device->changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		events |= DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		cd->device->changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		cd->tur_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	if (!(clearing & DISK_EVENT_MEDIA_CHANGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		return events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) do_tur:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	/* let's see whether the media is there with TUR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	last_present = cd->media_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	ret = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	 * Media is considered to be present if TUR succeeds or fails with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	 * sense data indicating something other than media-not-present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	 * (ASC 0x3a).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	cd->media_present = scsi_status_is_good(ret) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		(scsi_sense_valid(&sshdr) && sshdr.asc != 0x3a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	if (last_present != cd->media_present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		cd->device->changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	if (cd->device->changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 		events |= DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		cd->device->changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		cd->tur_changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	if (cd->ignore_get_event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		return events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	if (!cd->tur_changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		if (cd->get_event_changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 			if (cd->tur_mismatch++ > 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 				sr_printk(KERN_WARNING, cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 					  "GET_EVENT and TUR disagree continuously, suppress GET_EVENT events\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 				cd->ignore_get_event = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			cd->tur_mismatch = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	cd->tur_changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	cd->get_event_changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	return events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319)  * sr_done is the interrupt routine for the device driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321)  * It will be notified on the end of a SCSI read / write, and will take one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322)  * of several actions based on success or failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) static int sr_done(struct scsi_cmnd *SCpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	int result = SCpnt->result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	int this_count = scsi_bufflen(SCpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	int good_bytes = (result == 0 ? this_count : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	int block_sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	long error_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	scmd_printk(KERN_INFO, SCpnt, "done: %x\n", result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	 * Handle MEDIUM ERRORs or VOLUME OVERFLOWs that indicate partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	 * success.  Since this is a relatively rare error condition, no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	 * care is taken to avoid unnecessary additional work such as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	 * memcpy's that could be avoided.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	if (driver_byte(result) != 0 &&		/* An error occurred */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	    (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		switch (SCpnt->sense_buffer[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		case MEDIUM_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		case VOLUME_OVERFLOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		case ILLEGAL_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			if (!(SCpnt->sense_buffer[0] & 0x90))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 			error_sector =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 				get_unaligned_be32(&SCpnt->sense_buffer[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			if (SCpnt->request->bio != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 				block_sectors =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 					bio_sectors(SCpnt->request->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			if (block_sectors < 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 				block_sectors = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 			if (cd->device->sector_size == 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 				error_sector <<= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			error_sector &= ~(block_sectors - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 			good_bytes = (error_sector -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 				      blk_rq_pos(SCpnt->request)) << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			if (good_bytes < 0 || good_bytes >= this_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 				good_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			 * The SCSI specification allows for the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			 * returned by READ CAPACITY to be up to 75 2K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			 * sectors past the last readable block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			 * Therefore, if we hit a medium error within the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			 * last 75 2K sectors, we decrease the saved size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			 * value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			if (error_sector < get_capacity(cd->disk) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 			    cd->capacity - error_sector < 4 * 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 				set_capacity(cd->disk, error_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		case RECOVERED_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			good_bytes = this_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	return good_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	int block = 0, this_count, s_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	struct scsi_cd *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	struct request *rq = SCpnt->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	blk_status_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	ret = scsi_alloc_sgtables(SCpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	if (ret != BLK_STS_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	cd = scsi_cd(rq->rq_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	SCSI_LOG_HLQUEUE(1, scmd_printk(KERN_INFO, SCpnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		"Doing sr request, block = %d\n", block));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (!cd->device || !scsi_device_online(cd->device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			"Finishing %u sectors\n", blk_rq_sectors(rq)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			"Retry with 0x%p\n", SCpnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	if (cd->device->changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		 * quietly refuse to do anything to a changed disc until the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		 * changed bit has been reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	 * we do lazy blocksize switching (when reading XA sectors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	 * see CDROMREADMODE2 ioctl) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	s_size = cd->device->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	if (s_size > 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		if (!in_interrupt())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 			sr_set_blocklength(cd, 2048);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 			scmd_printk(KERN_INFO, SCpnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 				    "can't switch blocksize: in interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	if (s_size != 512 && s_size != 1024 && s_size != 2048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		scmd_printk(KERN_ERR, SCpnt, "bad sector size %d\n", s_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	switch (req_op(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	case REQ_OP_WRITE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		if (!cd->writeable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		SCpnt->cmnd[0] = WRITE_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		cd->cdi.media_written = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	case REQ_OP_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		SCpnt->cmnd[0] = READ_10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		blk_dump_rq_flags(rq, "Unknown sr command");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		int i, size = 0, sg_count = scsi_sg_count(SCpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		scsi_for_each_sg(SCpnt, sg, sg_count, i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			size += sg->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		if (size != scsi_bufflen(SCpnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 			scmd_printk(KERN_ERR, SCpnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 				"mismatch count %d, bytes %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 				size, scsi_bufflen(SCpnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			if (scsi_bufflen(SCpnt) > size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 				SCpnt->sdb.length = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	 * request doesn't start on hw block boundary, add scatter pads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	if (((unsigned int)blk_rq_pos(rq) % (s_size >> 9)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	    (scsi_bufflen(SCpnt) % s_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	this_count = (scsi_bufflen(SCpnt) >> 9) / (s_size >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 					"%s %d/%u 512 byte blocks.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 					(rq_data_dir(rq) == WRITE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 					"writing" : "reading",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 					this_count, blk_rq_sectors(rq)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	SCpnt->cmnd[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	block = (unsigned int)blk_rq_pos(rq) / (s_size >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	if (this_count > 0xffff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		this_count = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		SCpnt->sdb.length = this_count * s_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	put_unaligned_be32(block, &SCpnt->cmnd[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	put_unaligned_be16(this_count, &SCpnt->cmnd[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	 * We shouldn't disconnect in the middle of a sector, so with a dumb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	 * host adapter, it's safe to assume that we can at least transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	 * this many bytes between each connect / disconnect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	SCpnt->transfersize = cd->device->sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	SCpnt->underflow = this_count << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	SCpnt->allowed = MAX_RETRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	SCpnt->cmd_len = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	 * This indicates that the command is ready from our end to be queued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	return BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	scsi_free_sgtables(SCpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	return BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) static void sr_revalidate_disk(struct scsi_cd *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	struct scsi_sense_hdr sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	/* if the unit is not ready, nothing more to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	if (scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	sr_cd_check(&cd->cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	get_sectorsize(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) static int sr_block_open(struct block_device *bdev, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	struct scsi_cd *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	struct scsi_device *sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	int ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	cd = scsi_cd_get(bdev->bd_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	if (!cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	sdev = cd->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	scsi_autopm_get_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	if (bdev_check_media_change(bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		sr_revalidate_disk(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	mutex_lock(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	ret = cdrom_open(&cd->cdi, bdev, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	mutex_unlock(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	scsi_autopm_put_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		scsi_cd_put(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) static void sr_block_release(struct gendisk *disk, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	struct scsi_cd *cd = scsi_cd(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	mutex_lock(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	cdrom_release(&cd->cdi, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	mutex_unlock(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	scsi_cd_put(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 			  unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	struct scsi_cd *cd = scsi_cd(bdev->bd_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	struct scsi_device *sdev = cd->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	void __user *argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	mutex_lock(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	ret = scsi_ioctl_block_when_processing_errors(sdev, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			(mode & FMODE_NDELAY) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	scsi_autopm_get_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	 * Send SCSI addressing ioctls directly to mid level, send other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	 * ioctls to cdrom/block level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	case SCSI_IOCTL_GET_IDLUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	case SCSI_IOCTL_GET_BUS_NUMBER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		ret = scsi_ioctl(sdev, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	if (ret != -ENOSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	ret = scsi_ioctl(sdev, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	scsi_autopm_put_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	mutex_unlock(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			  unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	struct scsi_cd *cd = scsi_cd(bdev->bd_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	struct scsi_device *sdev = cd->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	void __user *argp = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	mutex_lock(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	ret = scsi_ioctl_block_when_processing_errors(sdev, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			(mode & FMODE_NDELAY) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	scsi_autopm_get_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	 * Send SCSI addressing ioctls directly to mid level, send other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	 * ioctls to cdrom/block level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	case SCSI_IOCTL_GET_IDLUN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	case SCSI_IOCTL_GET_BUS_NUMBER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		ret = scsi_compat_ioctl(sdev, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, (unsigned long)argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	if (ret != -ENOSYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	ret = scsi_compat_ioctl(sdev, cmd, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	scsi_autopm_put_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	mutex_unlock(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) static unsigned int sr_block_check_events(struct gendisk *disk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 					  unsigned int clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	unsigned int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	struct scsi_cd *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	cd = scsi_cd_get(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (!cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	if (!atomic_read(&cd->device->disk_events_disable_depth))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		ret = cdrom_check_events(&cd->cdi, clearing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	scsi_cd_put(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) static const struct block_device_operations sr_bdops =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	.open		= sr_block_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	.release	= sr_block_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	.ioctl		= sr_block_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	.compat_ioctl	= sr_block_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	.check_events	= sr_block_check_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) static int sr_open(struct cdrom_device_info *cdi, int purpose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	struct scsi_cd *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	struct scsi_device *sdev = cd->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	 * If the device is in error recovery, wait until it is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	 * If the device is offline, then disallow any access to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	retval = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	if (!scsi_block_when_processing_errors(sdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		goto error_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) error_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	return retval;	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) static void sr_release(struct cdrom_device_info *cdi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	struct scsi_cd *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	if (cd->device->sector_size > 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		sr_set_blocklength(cd, 2048);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) static int sr_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	struct scsi_device *sdev = to_scsi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	struct gendisk *disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	struct scsi_cd *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	int minor, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	scsi_autopm_get_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	error = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	cd = kzalloc(sizeof(*cd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (!cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	kref_init(&cd->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	disk = alloc_disk(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	if (!disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		goto fail_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	mutex_init(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	spin_lock(&sr_index_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	if (minor == SR_DISKS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		spin_unlock(&sr_index_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		error = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		goto fail_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	__set_bit(minor, sr_index_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	spin_unlock(&sr_index_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	disk->major = SCSI_CDROM_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	disk->first_minor = minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	sprintf(disk->disk_name, "sr%d", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	disk->fops = &sr_bdops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	disk->flags = GENHD_FL_CD | GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	cd->device = sdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	cd->disk = disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	cd->driver = &sr_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	cd->disk = disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	cd->capacity = 0x1fffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	cd->device->changed = 1;	/* force recheck CD type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	cd->media_present = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	cd->use = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	cd->readcd_known = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	cd->readcd_cdda = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	cd->cdi.ops = &sr_dops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	cd->cdi.handle = cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	cd->cdi.mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	cd->cdi.capacity = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	sprintf(cd->cdi.name, "sr%d", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	sdev->sector_size = 2048;	/* A guess, just in case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	/* FIXME: need to handle a get_capabilities failure properly ?? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	get_capabilities(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	sr_vendor_init(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	set_capacity(disk, cd->capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	disk->private_data = &cd->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	disk->queue = sdev->request_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	if (register_cdrom(disk, &cd->cdi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		goto fail_minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	 * Initialize block layer runtime PM stuffs before the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	 * periodic event checking request gets started in add_disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	blk_pm_runtime_init(sdev->request_queue, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	dev_set_drvdata(dev, cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	disk->flags |= GENHD_FL_REMOVABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	sr_revalidate_disk(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	device_add_disk(&sdev->sdev_gendev, disk, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	sdev_printk(KERN_DEBUG, sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		    "Attached scsi CD-ROM %s\n", cd->cdi.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	scsi_autopm_put_device(cd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) fail_minor:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	spin_lock(&sr_index_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	clear_bit(minor, sr_index_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	spin_unlock(&sr_index_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) fail_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	put_disk(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	mutex_destroy(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) fail_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	kfree(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	scsi_autopm_put_device(sdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) static void get_sectorsize(struct scsi_cd *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	unsigned char cmd[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	unsigned char buffer[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	int the_result, retries = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	int sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	struct request_queue *queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		cmd[0] = READ_CAPACITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		memset((void *) &cmd[1], 0, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		memset(buffer, 0, sizeof(buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		/* Do the command and wait.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 					      buffer, sizeof(buffer), NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 					      SR_TIMEOUT, MAX_RETRIES, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		retries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	} while (the_result && retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	if (the_result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		cd->capacity = 0x1fffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		sector_size = 2048;	/* A guess, just in case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		long last_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 		cd->capacity = 1 + get_unaligned_be32(&buffer[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		 * READ_CAPACITY doesn't return the correct size on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		 * certain UDF media.  If last_written is larger, use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		 * it instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		 * http://bugzilla.kernel.org/show_bug.cgi?id=9668
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		if (!cdrom_get_last_written(&cd->cdi, &last_written))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 			cd->capacity = max_t(long, cd->capacity, last_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		sector_size = get_unaligned_be32(&buffer[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		switch (sector_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 			 * HP 4020i CD-Recorder reports 2340 byte sectors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 			 * Philips CD-Writers report 2352 byte sectors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 			 * Use 2k sectors for them..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		case 2340:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		case 2352:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 			sector_size = 2048;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		case 2048:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 			cd->capacity *= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		case 512:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 			sr_printk(KERN_INFO, cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 				  "unsupported sector size %d.", sector_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 			cd->capacity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		cd->device->sector_size = sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		 * Add this so that we have the ability to correctly gauge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		 * what the device is capable of.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		set_capacity(cd->disk, cd->capacity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	queue = cd->device->request_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	blk_queue_logical_block_size(queue, sector_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) static void get_capabilities(struct scsi_cd *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	unsigned char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	struct scsi_mode_data data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	struct scsi_sense_hdr sshdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	unsigned int ms_len = 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	int rc, n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	static const char *loadmech[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		"caddy",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		"tray",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		"pop-up",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		"changer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		"cartridge changer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	/* allocate transfer buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	buffer = kmalloc(512, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		sr_printk(KERN_ERR, cd, "out of memory.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	/* eat unit attentions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	/* ask for mode page 0x2a */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, ms_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 			     SR_TIMEOUT, 3, &data, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	if (rc < 0 || data.length > ms_len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	    data.header_length + data.block_descriptor_length > data.length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		/* failed, drive doesn't have capabilities mode page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		cd->cdi.speed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 				 CDC_DVD | CDC_DVD_RAM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 				 CDC_SELECT_DISC | CDC_SELECT_SPEED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 				 CDC_MRW | CDC_MRW_W | CDC_RAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 		sr_printk(KERN_INFO, cd, "scsi-1 drive");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	n = data.header_length + data.block_descriptor_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	cd->cdi.speed = get_unaligned_be16(&buffer[n + 8]) / 176;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	cd->readcd_known = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	cd->readcd_cdda = buffer[n + 5] & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	/* print some capability bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	sr_printk(KERN_INFO, cd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		  "scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		  get_unaligned_be16(&buffer[n + 14]) / 176,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		  cd->cdi.speed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		  buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		  buffer[n + 3] & 0x20 ? "dvd-ram " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		  buffer[n + 2] & 0x02 ? "cd/rw " : "", /* can read rewriteable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		  buffer[n + 4] & 0x20 ? "xa/form2 " : "",	/* can read xa/from2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		  buffer[n + 5] & 0x01 ? "cdda " : "", /* can read audio data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		  loadmech[buffer[n + 6] >> 5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	if ((buffer[n + 6] >> 5) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		/* caddy drives can't close tray... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		cd->cdi.mask |= CDC_CLOSE_TRAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	if ((buffer[n + 2] & 0x8) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		/* not a DVD drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		cd->cdi.mask |= CDC_DVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	if ((buffer[n + 3] & 0x20) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		/* can't write DVD-RAM media */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		cd->cdi.mask |= CDC_DVD_RAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	if ((buffer[n + 3] & 0x10) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		/* can't write DVD-R media */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		cd->cdi.mask |= CDC_DVD_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	if ((buffer[n + 3] & 0x2) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		/* can't write CD-RW media */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		cd->cdi.mask |= CDC_CD_RW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	if ((buffer[n + 3] & 0x1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		/* can't write CD-R media */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		cd->cdi.mask |= CDC_CD_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	if ((buffer[n + 6] & 0x8) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		/* can't eject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		cd->cdi.mask |= CDC_OPEN_TRAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	if ((buffer[n + 6] >> 5) == mechtype_individual_changer ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	    (buffer[n + 6] >> 5) == mechtype_cartridge_changer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		cd->cdi.capacity =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		    cdrom_number_of_slots(&cd->cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	if (cd->cdi.capacity <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		/* not a changer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		cd->cdi.mask |= CDC_SELECT_DISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	/*else    I don't think it can close its tray
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		cd->cdi.mask |= CDC_CLOSE_TRAY; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	 * if DVD-RAM, MRW-W or CD-RW, we are randomly writable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		cd->writeable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)  * sr_packet() is the entry point for the generic commands generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)  * by the Uniform CD-ROM layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) static int sr_packet(struct cdrom_device_info *cdi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		struct packet_command *cgc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	struct scsi_cd *cd = cdi->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	struct scsi_device *sdev = cd->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	if (cgc->cmd[0] == GPCMD_READ_DISC_INFO && sdev->no_read_disc_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		return -EDRIVE_CANT_DO_THIS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	if (cgc->timeout <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		cgc->timeout = IOCTL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	sr_do_ioctl(cd, cgc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	return cgc->stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)  *	sr_kref_release - Called to free the scsi_cd structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)  *	@kref: pointer to embedded kref
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)  *	sr_ref_mutex must be held entering this routine.  Because it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)  *	called on last put, you should always use the scsi_cd_get()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)  *	scsi_cd_put() helpers which manipulate the semaphore directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)  *	and never do a direct kref_put().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) static void sr_kref_release(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	struct scsi_cd *cd = container_of(kref, struct scsi_cd, kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	struct gendisk *disk = cd->disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	spin_lock(&sr_index_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	clear_bit(MINOR(disk_devt(disk)), sr_index_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	spin_unlock(&sr_index_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	unregister_cdrom(&cd->cdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	disk->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	put_disk(disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	mutex_destroy(&cd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	kfree(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) static int sr_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	struct scsi_cd *cd = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	scsi_autopm_get_device(cd->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	del_gendisk(cd->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	dev_set_drvdata(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	mutex_lock(&sr_ref_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	kref_put(&cd->kref, sr_kref_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	mutex_unlock(&sr_ref_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) static int __init init_sr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	rc = register_blkdev(SCSI_CDROM_MAJOR, "sr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	rc = scsi_register_driver(&sr_template.gendrv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) static void __exit exit_sr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	scsi_unregister_driver(&sr_template.gendrv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) module_init(init_sr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) module_exit(exit_sr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) MODULE_LICENSE("GPL");