2 * sr.c Copyright (C) 1992 David Giller
3 * Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
6 * sd.c Copyright (C) 1992 Drew Eckhardt
7 * Linux scsi disk driver by
8 * Drew Eckhardt <drew@colorado.edu>
10 * Modified by Eric Youngdale ericy@andante.org to
11 * add scatter-gather, multiple outstanding request, and other
14 * Modified by Eric Youngdale eric@andante.org to support loadable
15 * low-level scsi drivers.
17 * Modified by Thomas Quinot thomas@melchior.cuivre.fdn.fr to
20 * Modified by Gerd Knorr <kraxel@cs.tu-berlin.de> to support the
21 * generic cdrom interface
23 * Modified by Jens Axboe <axboe@suse.de> - Uniform sr_packet()
24 * interface, capabilities probe additions, ioctl cleanups, etc.
26 * Modified by Richard Gooch <rgooch@atnf.csiro.au> to support devfs
28 * Modified by Jens Axboe <axboe@suse.de> - support DVD-RAM
29 * transparently and lose the GHOST hack
31 * Modified by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
32 * check resource allocation in sr_init and some cleanups
35 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
40 #include <linux/bio.h>
41 #include <linux/string.h>
42 #include <linux/errno.h>
43 #include <linux/cdrom.h>
44 #include <linux/interrupt.h>
45 #include <linux/init.h>
46 #include <linux/blkdev.h>
47 #include <asm/uaccess.h>
49 #include <scsi/scsi.h>
50 #include <scsi/scsi_dbg.h>
51 #include <scsi/scsi_device.h>
52 #include <scsi/scsi_driver.h>
53 #include <scsi/scsi_cmnd.h>
54 #include <scsi/scsi_eh.h>
55 #include <scsi/scsi_host.h>
56 #include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
58 #include "scsi_logging.h"
65 #define SR_TIMEOUT (30 * HZ)
66 #define SR_CAPABILITIES \
67 (CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
68 CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
69 CDC_PLAY_AUDIO|CDC_RESET|CDC_IOCTLS|CDC_DRIVE_STATUS| \
70 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
71 CDC_MRW|CDC_MRW_W|CDC_RAM)
73 static int sr_probe(struct device *);
74 static int sr_remove(struct device *);
75 static int sr_init_command(struct scsi_cmnd *);
77 static struct scsi_driver sr_template = {
84 .init_command = sr_init_command,
87 static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
88 static DEFINE_SPINLOCK(sr_index_lock);
90 /* This semaphore is used to mediate the 0->1 reference get in the
91 * face of object destruction (i.e. we can't allow a get on an
92 * object after last put) */
93 static DECLARE_MUTEX(sr_ref_sem);
95 static int sr_open(struct cdrom_device_info *, int);
96 static void sr_release(struct cdrom_device_info *);
98 static void get_sectorsize(struct scsi_cd *);
99 static void get_capabilities(struct scsi_cd *);
101 static int sr_media_change(struct cdrom_device_info *, int);
102 static int sr_packet(struct cdrom_device_info *, struct packet_command *);
104 static struct cdrom_device_ops sr_dops = {
106 .release = sr_release,
107 .drive_status = sr_drive_status,
108 .media_changed = sr_media_change,
109 .tray_move = sr_tray_move,
110 .lock_door = sr_lock_door,
111 .select_speed = sr_select_speed,
112 .get_last_session = sr_get_last_session,
113 .get_mcn = sr_get_mcn,
115 .audio_ioctl = sr_audio_ioctl,
116 .dev_ioctl = sr_dev_ioctl,
117 .capability = SR_CAPABILITIES,
118 .generic_packet = sr_packet,
121 static void sr_kref_release(struct kref *kref);
123 static inline struct scsi_cd *scsi_cd(struct gendisk *disk)
125 return container_of(disk->private_data, struct scsi_cd, driver);
129 * The get and put routines for the struct scsi_cd. Note this entity
130 * has a scsi_device pointer and owns a reference to this.
132 static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
134 struct scsi_cd *cd = NULL;
137 if (disk->private_data == NULL)
141 if (scsi_device_get(cd->device))
146 kref_put(&cd->kref, sr_kref_release);
153 static inline void scsi_cd_put(struct scsi_cd *cd)
155 struct scsi_device *sdev = cd->device;
158 kref_put(&cd->kref, sr_kref_release);
159 scsi_device_put(sdev);
164 * This function checks to see if the media has been changed in the
165 * CDROM drive. It is possible that we have already sensed a change,
166 * or the drive may have sensed one and not yet reported it. We must
167 * be ready for either case. This function always reports the current
168 * value of the changed bit. If flag is 0, then the changed bit is reset.
169 * This function could be done as an ioctl, but we would need to have
170 * an inode for that to work, and we do not always have one.
173 int sr_media_change(struct cdrom_device_info *cdi, int slot)
175 struct scsi_cd *cd = cdi->handle;
178 if (CDSL_CURRENT != slot) {
179 /* no changer support */
183 retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES);
185 /* Unable to test, unit probably not ready. This usually
186 * means there is no disc in the drive. Mark as changed,
187 * and we will figure it out later once the drive is
188 * available again. */
189 cd->device->changed = 1;
190 return 1; /* This will force a flush, if called from
191 * check_disk_change */
194 retval = cd->device->changed;
195 cd->device->changed = 0;
196 /* If the disk changed, the capacity will now be different,
197 * so we force a re-read of this information */
199 /* check multisession offset etc */
208 * rw_intr is the interrupt routine for the device driver.
210 * It will be notified on the end of a SCSI read / write, and will take on
211 * of several actions based on success or failure.
213 static void rw_intr(struct scsi_cmnd * SCpnt)
215 int result = SCpnt->result;
216 int this_count = SCpnt->bufflen;
217 int good_bytes = (result == 0 ? this_count : 0);
218 int block_sectors = 0;
220 struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
223 printk("sr.c done: %x\n", result);
227 * Handle MEDIUM ERRORs or VOLUME OVERFLOWs that indicate partial
228 * success. Since this is a relatively rare error condition, no
229 * care is taken to avoid unnecessary additional work such as
230 * memcpy's that could be avoided.
232 if (driver_byte(result) != 0 && /* An error occurred */
233 (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */
234 switch (SCpnt->sense_buffer[2]) {
236 case VOLUME_OVERFLOW:
237 case ILLEGAL_REQUEST:
238 if (!(SCpnt->sense_buffer[0] & 0x90))
240 if (!blk_fs_request(SCpnt->request))
242 error_sector = (SCpnt->sense_buffer[3] << 24) |
243 (SCpnt->sense_buffer[4] << 16) |
244 (SCpnt->sense_buffer[5] << 8) |
245 SCpnt->sense_buffer[6];
246 if (SCpnt->request->bio != NULL)
248 bio_sectors(SCpnt->request->bio);
249 if (block_sectors < 4)
251 if (cd->device->sector_size == 2048)
253 error_sector &= ~(block_sectors - 1);
254 good_bytes = (error_sector - SCpnt->request->sector) << 9;
255 if (good_bytes < 0 || good_bytes >= this_count)
258 * The SCSI specification allows for the value
259 * returned by READ CAPACITY to be up to 75 2K
260 * sectors past the last readable block.
261 * Therefore, if we hit a medium error within the
262 * last 75 2K sectors, we decrease the saved size
265 if (error_sector < get_capacity(cd->disk) &&
266 cd->capacity - error_sector < 4 * 75)
267 set_capacity(cd->disk, error_sector);
270 case RECOVERED_ERROR:
273 * An error occured, but it recovered. Inform the
274 * user, but make sure that it's not treated as a
277 scsi_print_sense("sr", SCpnt);
279 SCpnt->sense_buffer[0] = 0x0;
280 good_bytes = this_count;
289 * This calls the generic completion function, now that we know
290 * how many actual sectors finished, and how many sectors we need
291 * to say have failed.
293 scsi_io_completion(SCpnt, good_bytes, block_sectors << 9);
296 static int sr_init_command(struct scsi_cmnd * SCpnt)
298 int block=0, this_count, s_size, timeout = SR_TIMEOUT;
299 struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
301 SCSI_LOG_HLQUEUE(1, printk("Doing sr request, dev = %s, block = %d\n",
302 cd->disk->disk_name, block));
304 if (!cd->device || !scsi_device_online(cd->device)) {
305 SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n",
306 SCpnt->request->nr_sectors));
307 SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));
311 if (cd->device->changed) {
313 * quietly refuse to do anything to a changed disc until the
314 * changed bit has been reset
320 * these are already setup, just copy cdb basically
322 if (SCpnt->request->flags & REQ_BLOCK_PC) {
323 struct request *rq = SCpnt->request;
325 if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))
328 memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));
329 SCpnt->cmd_len = rq->cmd_len;
331 SCpnt->sc_data_direction = DMA_NONE;
332 else if (rq_data_dir(rq) == WRITE)
333 SCpnt->sc_data_direction = DMA_TO_DEVICE;
335 SCpnt->sc_data_direction = DMA_FROM_DEVICE;
337 this_count = rq->data_len;
339 timeout = rq->timeout;
341 SCpnt->transfersize = rq->data_len;
345 if (!(SCpnt->request->flags & REQ_CMD)) {
346 blk_dump_rq_flags(SCpnt->request, "sr unsup command");
351 * we do lazy blocksize switching (when reading XA sectors,
352 * see CDROMREADMODE2 ioctl)
354 s_size = cd->device->sector_size;
357 sr_set_blocklength(cd, 2048);
359 printk("sr: can't switch blocksize: in interrupt\n");
362 if (s_size != 512 && s_size != 1024 && s_size != 2048) {
363 printk("sr: bad sector size %d\n", s_size);
367 if (rq_data_dir(SCpnt->request) == WRITE) {
368 if (!cd->device->writeable)
370 SCpnt->cmnd[0] = WRITE_10;
371 SCpnt->sc_data_direction = DMA_TO_DEVICE;
372 cd->cdi.media_written = 1;
373 } else if (rq_data_dir(SCpnt->request) == READ) {
374 SCpnt->cmnd[0] = READ_10;
375 SCpnt->sc_data_direction = DMA_FROM_DEVICE;
377 blk_dump_rq_flags(SCpnt->request, "Unknown sr command");
382 struct scatterlist *sg = SCpnt->request_buffer;
384 for (i = 0; i < SCpnt->use_sg; i++)
385 size += sg[i].length;
387 if (size != SCpnt->request_bufflen && SCpnt->use_sg) {
388 printk(KERN_ERR "sr: mismatch count %d, bytes %d\n",
389 size, SCpnt->request_bufflen);
390 if (SCpnt->request_bufflen > size)
391 SCpnt->request_bufflen = SCpnt->bufflen = size;
396 * request doesn't start on hw block boundary, add scatter pads
398 if (((unsigned int)SCpnt->request->sector % (s_size >> 9)) ||
399 (SCpnt->request_bufflen % s_size)) {
400 printk("sr: unaligned transfer\n");
404 this_count = (SCpnt->request_bufflen >> 9) / (s_size >> 9);
407 SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n",
409 (rq_data_dir(SCpnt->request) == WRITE) ?
410 "writing" : "reading",
411 this_count, SCpnt->request->nr_sectors));
414 block = (unsigned int)SCpnt->request->sector / (s_size >> 9);
416 if (this_count > 0xffff) {
418 SCpnt->request_bufflen = SCpnt->bufflen =
422 SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;
423 SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
424 SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
425 SCpnt->cmnd[5] = (unsigned char) block & 0xff;
426 SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
427 SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
428 SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
431 * We shouldn't disconnect in the middle of a sector, so with a dumb
432 * host adapter, it's safe to assume that we can at least transfer
433 * this many bytes between each connect / disconnect.
435 SCpnt->transfersize = cd->device->sector_size;
436 SCpnt->underflow = this_count << 9;
439 SCpnt->allowed = MAX_RETRIES;
440 SCpnt->timeout_per_command = timeout;
443 * This is the completion routine we use. This is matched in terms
444 * of capability to this function.
446 SCpnt->done = rw_intr;
449 * This indicates that the command is ready from our end to be
455 static int sr_block_open(struct inode *inode, struct file *file)
457 struct gendisk *disk = inode->i_bdev->bd_disk;
458 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
461 if(!(cd = scsi_cd_get(disk)))
464 if((ret = cdrom_open(&cd->cdi, inode, file)) != 0)
470 static int sr_block_release(struct inode *inode, struct file *file)
473 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
474 ret = cdrom_release(&cd->cdi, file);
483 static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
486 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
487 struct scsi_device *sdev = cd->device;
490 * Send SCSI addressing ioctls directly to mid level, send other
491 * ioctls to cdrom/block level.
494 case SCSI_IOCTL_GET_IDLUN:
495 case SCSI_IOCTL_GET_BUS_NUMBER:
496 return scsi_ioctl(sdev, cmd, (void __user *)arg);
498 return cdrom_ioctl(file, &cd->cdi, inode, cmd, arg);
501 static int sr_block_media_changed(struct gendisk *disk)
503 struct scsi_cd *cd = scsi_cd(disk);
504 return cdrom_media_changed(&cd->cdi);
507 static struct block_device_operations sr_bdops =
509 .owner = THIS_MODULE,
510 .open = sr_block_open,
511 .release = sr_block_release,
512 .ioctl = sr_block_ioctl,
513 .media_changed = sr_block_media_changed,
515 * No compat_ioctl for now because sr_block_ioctl never
516 * seems to pass arbitary ioctls down to host drivers.
520 static int sr_open(struct cdrom_device_info *cdi, int purpose)
522 struct scsi_cd *cd = cdi->handle;
523 struct scsi_device *sdev = cd->device;
527 * If the device is in error recovery, wait until it is done.
528 * If the device is offline, then disallow any access to it.
531 if (!scsi_block_when_processing_errors(sdev))
540 static void sr_release(struct cdrom_device_info *cdi)
542 struct scsi_cd *cd = cdi->handle;
544 if (cd->device->sector_size > 2048)
545 sr_set_blocklength(cd, 2048);
549 static int sr_probe(struct device *dev)
551 struct scsi_device *sdev = to_scsi_device(dev);
552 struct gendisk *disk;
557 if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
561 cd = kmalloc(sizeof(*cd), GFP_KERNEL);
564 memset(cd, 0, sizeof(*cd));
566 kref_init(&cd->kref);
568 disk = alloc_disk(1);
572 spin_lock(&sr_index_lock);
573 minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
574 if (minor == SR_DISKS) {
575 spin_unlock(&sr_index_lock);
579 __set_bit(minor, sr_index_bits);
580 spin_unlock(&sr_index_lock);
582 disk->major = SCSI_CDROM_MAJOR;
583 disk->first_minor = minor;
584 sprintf(disk->disk_name, "sr%d", minor);
585 disk->fops = &sr_bdops;
586 disk->flags = GENHD_FL_CD;
590 cd->driver = &sr_template;
592 cd->capacity = 0x1fffff;
593 cd->device->changed = 1; /* force recheck CD type */
595 cd->readcd_known = 0;
598 cd->cdi.ops = &sr_dops;
601 cd->cdi.capacity = 1;
602 sprintf(cd->cdi.name, "sr%d", minor);
604 sdev->sector_size = 2048; /* A guess, just in case */
606 /* FIXME: need to handle a get_capabilities failure properly ?? */
607 get_capabilities(cd);
610 snprintf(disk->devfs_name, sizeof(disk->devfs_name),
611 "%s/cd", sdev->devfs_name);
612 disk->driverfs_dev = &sdev->sdev_gendev;
613 set_capacity(disk, cd->capacity);
614 disk->private_data = &cd->driver;
615 disk->queue = sdev->request_queue;
618 if (register_cdrom(&cd->cdi))
621 dev_set_drvdata(dev, cd);
622 disk->flags |= GENHD_FL_REMOVABLE;
626 "Attached scsi CD-ROM %s at scsi%d, channel %d, id %d, lun %d\n",
627 cd->cdi.name, sdev->host->host_no, sdev->channel,
628 sdev->id, sdev->lun);
640 static void get_sectorsize(struct scsi_cd *cd)
642 unsigned char cmd[10];
643 unsigned char *buffer;
644 int the_result, retries = 3;
646 request_queue_t *queue;
648 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
653 cmd[0] = READ_CAPACITY;
654 memset((void *) &cmd[1], 0, 9);
655 memset(buffer, 0, 8);
657 /* Do the command and wait.. */
658 the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
659 buffer, 8, NULL, SR_TIMEOUT,
664 } while (the_result && retries);
668 cd->capacity = 0x1fffff;
669 sector_size = 2048; /* A guess, just in case */
672 if (cdrom_get_last_written(&cd->cdi,
675 cd->capacity = 1 + ((buffer[0] << 24) |
679 sector_size = (buffer[4] << 24) |
680 (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
681 switch (sector_size) {
683 * HP 4020i CD-Recorder reports 2340 byte sectors
684 * Philips CD-Writers report 2352 byte sectors
686 * Use 2k sectors for them..
699 printk("%s: unsupported sector size %d.\n",
700 cd->cdi.name, sector_size);
704 cd->device->sector_size = sector_size;
707 * Add this so that we have the ability to correctly gauge
708 * what the device is capable of.
710 set_capacity(cd->disk, cd->capacity);
713 queue = cd->device->request_queue;
714 blk_queue_hardsect_size(queue, sector_size);
720 cd->capacity = 0x1fffff;
721 cd->device->sector_size = 2048; /* A guess, just in case */
725 static void get_capabilities(struct scsi_cd *cd)
727 unsigned char *buffer;
728 struct scsi_mode_data data;
729 unsigned char cmd[MAX_COMMAND_SIZE];
730 struct scsi_sense_hdr sshdr;
731 unsigned int the_result;
734 static char *loadmech[] =
747 /* allocate transfer buffer */
748 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
750 printk(KERN_ERR "sr: out of memory.\n");
754 /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION
755 * conditions are gone, or a timeout happens
759 memset((void *)cmd, 0, MAX_COMMAND_SIZE);
760 cmd[0] = TEST_UNIT_READY;
762 the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL,
763 0, &sshdr, SR_TIMEOUT,
767 } while (retries < 5 &&
768 (!scsi_status_is_good(the_result) ||
769 (scsi_sense_valid(&sshdr) &&
770 sshdr.sense_key == UNIT_ATTENTION)));
772 /* ask for mode page 0x2a */
773 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
774 SR_TIMEOUT, 3, &data, NULL);
776 if (!scsi_status_is_good(rc)) {
777 /* failed, drive doesn't have capabilities mode page */
779 cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
780 CDC_DVD | CDC_DVD_RAM |
781 CDC_SELECT_DISC | CDC_SELECT_SPEED);
783 printk("%s: scsi-1 drive\n", cd->cdi.name);
787 n = data.header_length + data.block_descriptor_length;
788 cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
789 cd->readcd_known = 1;
790 cd->readcd_cdda = buffer[n + 5] & 0x01;
791 /* print some capability bits */
792 printk("%s: scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n", cd->cdi.name,
793 ((buffer[n + 14] << 8) + buffer[n + 15]) / 176,
795 buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */
796 buffer[n + 3] & 0x20 ? "dvd-ram " : "",
797 buffer[n + 2] & 0x02 ? "cd/rw " : "", /* can read rewriteable */
798 buffer[n + 4] & 0x20 ? "xa/form2 " : "", /* can read xa/from2 */
799 buffer[n + 5] & 0x01 ? "cdda " : "", /* can read audio data */
800 loadmech[buffer[n + 6] >> 5]);
801 if ((buffer[n + 6] >> 5) == 0)
802 /* caddy drives can't close tray... */
803 cd->cdi.mask |= CDC_CLOSE_TRAY;
804 if ((buffer[n + 2] & 0x8) == 0)
805 /* not a DVD drive */
806 cd->cdi.mask |= CDC_DVD;
807 if ((buffer[n + 3] & 0x20) == 0)
808 /* can't write DVD-RAM media */
809 cd->cdi.mask |= CDC_DVD_RAM;
810 if ((buffer[n + 3] & 0x10) == 0)
811 /* can't write DVD-R media */
812 cd->cdi.mask |= CDC_DVD_R;
813 if ((buffer[n + 3] & 0x2) == 0)
814 /* can't write CD-RW media */
815 cd->cdi.mask |= CDC_CD_RW;
816 if ((buffer[n + 3] & 0x1) == 0)
817 /* can't write CD-R media */
818 cd->cdi.mask |= CDC_CD_R;
819 if ((buffer[n + 6] & 0x8) == 0)
821 cd->cdi.mask |= CDC_OPEN_TRAY;
823 if ((buffer[n + 6] >> 5) == mechtype_individual_changer ||
824 (buffer[n + 6] >> 5) == mechtype_cartridge_changer)
826 cdrom_number_of_slots(&cd->cdi);
827 if (cd->cdi.capacity <= 1)
829 cd->cdi.mask |= CDC_SELECT_DISC;
830 /*else I don't think it can close its tray
831 cd->cdi.mask |= CDC_CLOSE_TRAY; */
834 * if DVD-RAM, MRW-W or CD-RW, we are randomly writable
836 if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
837 (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
838 cd->device->writeable = 1;
845 * sr_packet() is the entry point for the generic commands generated
846 * by the Uniform CD-ROM layer.
848 static int sr_packet(struct cdrom_device_info *cdi,
849 struct packet_command *cgc)
851 if (cgc->timeout <= 0)
852 cgc->timeout = IOCTL_TIMEOUT;
854 sr_do_ioctl(cdi->handle, cgc);
860 * sr_kref_release - Called to free the scsi_cd structure
861 * @kref: pointer to embedded kref
863 * sr_ref_sem must be held entering this routine. Because it is
864 * called on last put, you should always use the scsi_cd_get()
865 * scsi_cd_put() helpers which manipulate the semaphore directly
866 * and never do a direct kref_put().
868 static void sr_kref_release(struct kref *kref)
870 struct scsi_cd *cd = container_of(kref, struct scsi_cd, kref);
871 struct gendisk *disk = cd->disk;
873 spin_lock(&sr_index_lock);
874 clear_bit(disk->first_minor, sr_index_bits);
875 spin_unlock(&sr_index_lock);
877 unregister_cdrom(&cd->cdi);
879 disk->private_data = NULL;
886 static int sr_remove(struct device *dev)
888 struct scsi_cd *cd = dev_get_drvdata(dev);
890 del_gendisk(cd->disk);
893 kref_put(&cd->kref, sr_kref_release);
899 static int __init init_sr(void)
903 rc = register_blkdev(SCSI_CDROM_MAJOR, "sr");
906 return scsi_register_driver(&sr_template.gendrv);
909 static void __exit exit_sr(void)
911 scsi_unregister_driver(&sr_template.gendrv);
912 unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
915 module_init(init_sr);
916 module_exit(exit_sr);
917 MODULE_LICENSE("GPL");