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 <linux/mutex.h>
48 #include <asm/uaccess.h>
50 #include <scsi/scsi.h>
51 #include <scsi/scsi_dbg.h>
52 #include <scsi/scsi_device.h>
53 #include <scsi/scsi_driver.h>
54 #include <scsi/scsi_cmnd.h>
55 #include <scsi/scsi_eh.h>
56 #include <scsi/scsi_host.h>
57 #include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
59 #include "scsi_logging.h"
63 MODULE_DESCRIPTION("SCSI cdrom (sr) driver");
64 MODULE_LICENSE("GPL");
65 MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_CDROM_MAJOR);
70 #define SR_TIMEOUT (30 * HZ)
71 #define SR_CAPABILITIES \
72 (CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
73 CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
74 CDC_PLAY_AUDIO|CDC_RESET|CDC_IOCTLS|CDC_DRIVE_STATUS| \
75 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
76 CDC_MRW|CDC_MRW_W|CDC_RAM)
78 static int sr_probe(struct device *);
79 static int sr_remove(struct device *);
80 static int sr_init_command(struct scsi_cmnd *);
82 static struct scsi_driver sr_template = {
89 .init_command = sr_init_command,
92 static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
93 static DEFINE_SPINLOCK(sr_index_lock);
95 /* This semaphore is used to mediate the 0->1 reference get in the
96 * face of object destruction (i.e. we can't allow a get on an
97 * object after last put) */
98 static DEFINE_MUTEX(sr_ref_mutex);
100 static int sr_open(struct cdrom_device_info *, int);
101 static void sr_release(struct cdrom_device_info *);
103 static void get_sectorsize(struct scsi_cd *);
104 static void get_capabilities(struct scsi_cd *);
106 static int sr_media_change(struct cdrom_device_info *, int);
107 static int sr_packet(struct cdrom_device_info *, struct packet_command *);
109 static struct cdrom_device_ops sr_dops = {
111 .release = sr_release,
112 .drive_status = sr_drive_status,
113 .media_changed = sr_media_change,
114 .tray_move = sr_tray_move,
115 .lock_door = sr_lock_door,
116 .select_speed = sr_select_speed,
117 .get_last_session = sr_get_last_session,
118 .get_mcn = sr_get_mcn,
120 .audio_ioctl = sr_audio_ioctl,
121 .dev_ioctl = sr_dev_ioctl,
122 .capability = SR_CAPABILITIES,
123 .generic_packet = sr_packet,
126 static void sr_kref_release(struct kref *kref);
128 static inline struct scsi_cd *scsi_cd(struct gendisk *disk)
130 return container_of(disk->private_data, struct scsi_cd, driver);
134 * The get and put routines for the struct scsi_cd. Note this entity
135 * has a scsi_device pointer and owns a reference to this.
137 static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk)
139 struct scsi_cd *cd = NULL;
141 mutex_lock(&sr_ref_mutex);
142 if (disk->private_data == NULL)
146 if (scsi_device_get(cd->device))
151 kref_put(&cd->kref, sr_kref_release);
154 mutex_unlock(&sr_ref_mutex);
158 static void scsi_cd_put(struct scsi_cd *cd)
160 struct scsi_device *sdev = cd->device;
162 mutex_lock(&sr_ref_mutex);
163 kref_put(&cd->kref, sr_kref_release);
164 scsi_device_put(sdev);
165 mutex_unlock(&sr_ref_mutex);
169 * This function checks to see if the media has been changed in the
170 * CDROM drive. It is possible that we have already sensed a change,
171 * or the drive may have sensed one and not yet reported it. We must
172 * be ready for either case. This function always reports the current
173 * value of the changed bit. If flag is 0, then the changed bit is reset.
174 * This function could be done as an ioctl, but we would need to have
175 * an inode for that to work, and we do not always have one.
178 int sr_media_change(struct cdrom_device_info *cdi, int slot)
180 struct scsi_cd *cd = cdi->handle;
183 if (CDSL_CURRENT != slot) {
184 /* no changer support */
188 retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES);
190 /* Unable to test, unit probably not ready. This usually
191 * means there is no disc in the drive. Mark as changed,
192 * and we will figure it out later once the drive is
193 * available again. */
194 cd->device->changed = 1;
195 return 1; /* This will force a flush, if called from
196 * check_disk_change */
199 retval = cd->device->changed;
200 cd->device->changed = 0;
201 /* If the disk changed, the capacity will now be different,
202 * so we force a re-read of this information */
204 /* check multisession offset etc */
213 * rw_intr is the interrupt routine for the device driver.
215 * It will be notified on the end of a SCSI read / write, and will take on
216 * of several actions based on success or failure.
218 static void rw_intr(struct scsi_cmnd * SCpnt)
220 int result = SCpnt->result;
221 int this_count = SCpnt->bufflen;
222 int good_bytes = (result == 0 ? this_count : 0);
223 int block_sectors = 0;
225 struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
228 printk("sr.c done: %x\n", result);
232 * Handle MEDIUM ERRORs or VOLUME OVERFLOWs that indicate partial
233 * success. Since this is a relatively rare error condition, no
234 * care is taken to avoid unnecessary additional work such as
235 * memcpy's that could be avoided.
237 if (driver_byte(result) != 0 && /* An error occurred */
238 (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */
239 switch (SCpnt->sense_buffer[2]) {
241 case VOLUME_OVERFLOW:
242 case ILLEGAL_REQUEST:
243 if (!(SCpnt->sense_buffer[0] & 0x90))
245 error_sector = (SCpnt->sense_buffer[3] << 24) |
246 (SCpnt->sense_buffer[4] << 16) |
247 (SCpnt->sense_buffer[5] << 8) |
248 SCpnt->sense_buffer[6];
249 if (SCpnt->request->bio != NULL)
251 bio_sectors(SCpnt->request->bio);
252 if (block_sectors < 4)
254 if (cd->device->sector_size == 2048)
256 error_sector &= ~(block_sectors - 1);
257 good_bytes = (error_sector - SCpnt->request->sector) << 9;
258 if (good_bytes < 0 || good_bytes >= this_count)
261 * The SCSI specification allows for the value
262 * returned by READ CAPACITY to be up to 75 2K
263 * sectors past the last readable block.
264 * Therefore, if we hit a medium error within the
265 * last 75 2K sectors, we decrease the saved size
268 if (error_sector < get_capacity(cd->disk) &&
269 cd->capacity - error_sector < 4 * 75)
270 set_capacity(cd->disk, error_sector);
273 case RECOVERED_ERROR:
276 * An error occured, but it recovered. Inform the
277 * user, but make sure that it's not treated as a
280 scsi_print_sense("sr", SCpnt);
282 SCpnt->sense_buffer[0] = 0x0;
283 good_bytes = this_count;
292 * This calls the generic completion function, now that we know
293 * how many actual sectors finished, and how many sectors we need
294 * to say have failed.
296 scsi_io_completion(SCpnt, good_bytes, block_sectors << 9);
299 static int sr_init_command(struct scsi_cmnd * SCpnt)
301 int block=0, this_count, s_size, timeout = SR_TIMEOUT;
302 struct scsi_cd *cd = scsi_cd(SCpnt->request->rq_disk);
304 SCSI_LOG_HLQUEUE(1, printk("Doing sr request, dev = %s, block = %d\n",
305 cd->disk->disk_name, block));
307 if (!cd->device || !scsi_device_online(cd->device)) {
308 SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n",
309 SCpnt->request->nr_sectors));
310 SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));
314 if (cd->device->changed) {
316 * quietly refuse to do anything to a changed disc until the
317 * changed bit has been reset
323 * we do lazy blocksize switching (when reading XA sectors,
324 * see CDROMREADMODE2 ioctl)
326 s_size = cd->device->sector_size;
329 sr_set_blocklength(cd, 2048);
331 printk("sr: can't switch blocksize: in interrupt\n");
334 if (s_size != 512 && s_size != 1024 && s_size != 2048) {
335 scmd_printk(KERN_ERR, SCpnt, "bad sector size %d\n", s_size);
339 if (rq_data_dir(SCpnt->request) == WRITE) {
340 if (!cd->device->writeable)
342 SCpnt->cmnd[0] = WRITE_10;
343 SCpnt->sc_data_direction = DMA_TO_DEVICE;
344 cd->cdi.media_written = 1;
345 } else if (rq_data_dir(SCpnt->request) == READ) {
346 SCpnt->cmnd[0] = READ_10;
347 SCpnt->sc_data_direction = DMA_FROM_DEVICE;
349 blk_dump_rq_flags(SCpnt->request, "Unknown sr command");
354 struct scatterlist *sg = SCpnt->request_buffer;
356 for (i = 0; i < SCpnt->use_sg; i++)
357 size += sg[i].length;
359 if (size != SCpnt->request_bufflen && SCpnt->use_sg) {
360 scmd_printk(KERN_ERR, SCpnt,
361 "mismatch count %d, bytes %d\n",
362 size, SCpnt->request_bufflen);
363 if (SCpnt->request_bufflen > size)
364 SCpnt->request_bufflen = SCpnt->bufflen = size;
369 * request doesn't start on hw block boundary, add scatter pads
371 if (((unsigned int)SCpnt->request->sector % (s_size >> 9)) ||
372 (SCpnt->request_bufflen % s_size)) {
373 scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n");
377 this_count = (SCpnt->request_bufflen >> 9) / (s_size >> 9);
380 SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n",
382 (rq_data_dir(SCpnt->request) == WRITE) ?
383 "writing" : "reading",
384 this_count, SCpnt->request->nr_sectors));
387 block = (unsigned int)SCpnt->request->sector / (s_size >> 9);
389 if (this_count > 0xffff) {
391 SCpnt->request_bufflen = SCpnt->bufflen =
395 SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;
396 SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
397 SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
398 SCpnt->cmnd[5] = (unsigned char) block & 0xff;
399 SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0;
400 SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
401 SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
404 * We shouldn't disconnect in the middle of a sector, so with a dumb
405 * host adapter, it's safe to assume that we can at least transfer
406 * this many bytes between each connect / disconnect.
408 SCpnt->transfersize = cd->device->sector_size;
409 SCpnt->underflow = this_count << 9;
410 SCpnt->allowed = MAX_RETRIES;
411 SCpnt->timeout_per_command = timeout;
414 * This is the completion routine we use. This is matched in terms
415 * of capability to this function.
417 SCpnt->done = rw_intr;
420 * This indicates that the command is ready from our end to be
426 static int sr_block_open(struct inode *inode, struct file *file)
428 struct gendisk *disk = inode->i_bdev->bd_disk;
432 if(!(cd = scsi_cd_get(disk)))
435 if((ret = cdrom_open(&cd->cdi, inode, file)) != 0)
441 static int sr_block_release(struct inode *inode, struct file *file)
444 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
445 ret = cdrom_release(&cd->cdi, file);
454 static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
457 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk);
458 struct scsi_device *sdev = cd->device;
461 * Send SCSI addressing ioctls directly to mid level, send other
462 * ioctls to cdrom/block level.
465 case SCSI_IOCTL_GET_IDLUN:
466 case SCSI_IOCTL_GET_BUS_NUMBER:
467 return scsi_ioctl(sdev, cmd, (void __user *)arg);
469 return cdrom_ioctl(file, &cd->cdi, inode, cmd, arg);
472 static int sr_block_media_changed(struct gendisk *disk)
474 struct scsi_cd *cd = scsi_cd(disk);
475 return cdrom_media_changed(&cd->cdi);
478 static struct block_device_operations sr_bdops =
480 .owner = THIS_MODULE,
481 .open = sr_block_open,
482 .release = sr_block_release,
483 .ioctl = sr_block_ioctl,
484 .media_changed = sr_block_media_changed,
486 * No compat_ioctl for now because sr_block_ioctl never
487 * seems to pass arbitary ioctls down to host drivers.
491 static int sr_open(struct cdrom_device_info *cdi, int purpose)
493 struct scsi_cd *cd = cdi->handle;
494 struct scsi_device *sdev = cd->device;
498 * If the device is in error recovery, wait until it is done.
499 * If the device is offline, then disallow any access to it.
502 if (!scsi_block_when_processing_errors(sdev))
511 static void sr_release(struct cdrom_device_info *cdi)
513 struct scsi_cd *cd = cdi->handle;
515 if (cd->device->sector_size > 2048)
516 sr_set_blocklength(cd, 2048);
520 static int sr_probe(struct device *dev)
522 struct scsi_device *sdev = to_scsi_device(dev);
523 struct gendisk *disk;
528 if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
532 cd = kzalloc(sizeof(*cd), GFP_KERNEL);
536 kref_init(&cd->kref);
538 disk = alloc_disk(1);
542 spin_lock(&sr_index_lock);
543 minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
544 if (minor == SR_DISKS) {
545 spin_unlock(&sr_index_lock);
549 __set_bit(minor, sr_index_bits);
550 spin_unlock(&sr_index_lock);
552 disk->major = SCSI_CDROM_MAJOR;
553 disk->first_minor = minor;
554 sprintf(disk->disk_name, "sr%d", minor);
555 disk->fops = &sr_bdops;
556 disk->flags = GENHD_FL_CD;
560 cd->driver = &sr_template;
562 cd->capacity = 0x1fffff;
563 cd->device->changed = 1; /* force recheck CD type */
565 cd->readcd_known = 0;
568 cd->cdi.ops = &sr_dops;
571 cd->cdi.capacity = 1;
572 sprintf(cd->cdi.name, "sr%d", minor);
574 sdev->sector_size = 2048; /* A guess, just in case */
576 /* FIXME: need to handle a get_capabilities failure properly ?? */
577 get_capabilities(cd);
580 disk->driverfs_dev = &sdev->sdev_gendev;
581 set_capacity(disk, cd->capacity);
582 disk->private_data = &cd->driver;
583 disk->queue = sdev->request_queue;
586 if (register_cdrom(&cd->cdi))
589 dev_set_drvdata(dev, cd);
590 disk->flags |= GENHD_FL_REMOVABLE;
593 sdev_printk(KERN_DEBUG, sdev,
594 "Attached scsi CD-ROM %s\n", cd->cdi.name);
606 static void get_sectorsize(struct scsi_cd *cd)
608 unsigned char cmd[10];
609 unsigned char *buffer;
610 int the_result, retries = 3;
612 request_queue_t *queue;
614 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
619 cmd[0] = READ_CAPACITY;
620 memset((void *) &cmd[1], 0, 9);
621 memset(buffer, 0, 8);
623 /* Do the command and wait.. */
624 the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
625 buffer, 8, NULL, SR_TIMEOUT,
630 } while (the_result && retries);
634 cd->capacity = 0x1fffff;
635 sector_size = 2048; /* A guess, just in case */
638 if (cdrom_get_last_written(&cd->cdi,
641 cd->capacity = 1 + ((buffer[0] << 24) |
645 sector_size = (buffer[4] << 24) |
646 (buffer[5] << 16) | (buffer[6] << 8) | buffer[7];
647 switch (sector_size) {
649 * HP 4020i CD-Recorder reports 2340 byte sectors
650 * Philips CD-Writers report 2352 byte sectors
652 * Use 2k sectors for them..
665 printk("%s: unsupported sector size %d.\n",
666 cd->cdi.name, sector_size);
670 cd->device->sector_size = sector_size;
673 * Add this so that we have the ability to correctly gauge
674 * what the device is capable of.
676 set_capacity(cd->disk, cd->capacity);
679 queue = cd->device->request_queue;
680 blk_queue_hardsect_size(queue, sector_size);
686 cd->capacity = 0x1fffff;
687 cd->device->sector_size = 2048; /* A guess, just in case */
691 static void get_capabilities(struct scsi_cd *cd)
693 unsigned char *buffer;
694 struct scsi_mode_data data;
695 unsigned char cmd[MAX_COMMAND_SIZE];
696 struct scsi_sense_hdr sshdr;
697 unsigned int the_result;
700 static const char *loadmech[] =
713 /* allocate transfer buffer */
714 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
716 printk(KERN_ERR "sr: out of memory.\n");
720 /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION
721 * conditions are gone, or a timeout happens
725 memset((void *)cmd, 0, MAX_COMMAND_SIZE);
726 cmd[0] = TEST_UNIT_READY;
728 the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL,
729 0, &sshdr, SR_TIMEOUT,
733 } while (retries < 5 &&
734 (!scsi_status_is_good(the_result) ||
735 (scsi_sense_valid(&sshdr) &&
736 sshdr.sense_key == UNIT_ATTENTION)));
738 /* ask for mode page 0x2a */
739 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
740 SR_TIMEOUT, 3, &data, NULL);
742 if (!scsi_status_is_good(rc)) {
743 /* failed, drive doesn't have capabilities mode page */
745 cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
746 CDC_DVD | CDC_DVD_RAM |
747 CDC_SELECT_DISC | CDC_SELECT_SPEED |
748 CDC_MRW | CDC_MRW_W | CDC_RAM);
750 printk("%s: scsi-1 drive\n", cd->cdi.name);
754 n = data.header_length + data.block_descriptor_length;
755 cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176;
756 cd->readcd_known = 1;
757 cd->readcd_cdda = buffer[n + 5] & 0x01;
758 /* print some capability bits */
759 printk("%s: scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n", cd->cdi.name,
760 ((buffer[n + 14] << 8) + buffer[n + 15]) / 176,
762 buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */
763 buffer[n + 3] & 0x20 ? "dvd-ram " : "",
764 buffer[n + 2] & 0x02 ? "cd/rw " : "", /* can read rewriteable */
765 buffer[n + 4] & 0x20 ? "xa/form2 " : "", /* can read xa/from2 */
766 buffer[n + 5] & 0x01 ? "cdda " : "", /* can read audio data */
767 loadmech[buffer[n + 6] >> 5]);
768 if ((buffer[n + 6] >> 5) == 0)
769 /* caddy drives can't close tray... */
770 cd->cdi.mask |= CDC_CLOSE_TRAY;
771 if ((buffer[n + 2] & 0x8) == 0)
772 /* not a DVD drive */
773 cd->cdi.mask |= CDC_DVD;
774 if ((buffer[n + 3] & 0x20) == 0)
775 /* can't write DVD-RAM media */
776 cd->cdi.mask |= CDC_DVD_RAM;
777 if ((buffer[n + 3] & 0x10) == 0)
778 /* can't write DVD-R media */
779 cd->cdi.mask |= CDC_DVD_R;
780 if ((buffer[n + 3] & 0x2) == 0)
781 /* can't write CD-RW media */
782 cd->cdi.mask |= CDC_CD_RW;
783 if ((buffer[n + 3] & 0x1) == 0)
784 /* can't write CD-R media */
785 cd->cdi.mask |= CDC_CD_R;
786 if ((buffer[n + 6] & 0x8) == 0)
788 cd->cdi.mask |= CDC_OPEN_TRAY;
790 if ((buffer[n + 6] >> 5) == mechtype_individual_changer ||
791 (buffer[n + 6] >> 5) == mechtype_cartridge_changer)
793 cdrom_number_of_slots(&cd->cdi);
794 if (cd->cdi.capacity <= 1)
796 cd->cdi.mask |= CDC_SELECT_DISC;
797 /*else I don't think it can close its tray
798 cd->cdi.mask |= CDC_CLOSE_TRAY; */
801 * if DVD-RAM, MRW-W or CD-RW, we are randomly writable
803 if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
804 (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
805 cd->device->writeable = 1;
812 * sr_packet() is the entry point for the generic commands generated
813 * by the Uniform CD-ROM layer.
815 static int sr_packet(struct cdrom_device_info *cdi,
816 struct packet_command *cgc)
818 if (cgc->timeout <= 0)
819 cgc->timeout = IOCTL_TIMEOUT;
821 sr_do_ioctl(cdi->handle, cgc);
827 * sr_kref_release - Called to free the scsi_cd structure
828 * @kref: pointer to embedded kref
830 * sr_ref_mutex must be held entering this routine. Because it is
831 * called on last put, you should always use the scsi_cd_get()
832 * scsi_cd_put() helpers which manipulate the semaphore directly
833 * and never do a direct kref_put().
835 static void sr_kref_release(struct kref *kref)
837 struct scsi_cd *cd = container_of(kref, struct scsi_cd, kref);
838 struct gendisk *disk = cd->disk;
840 spin_lock(&sr_index_lock);
841 clear_bit(disk->first_minor, sr_index_bits);
842 spin_unlock(&sr_index_lock);
844 unregister_cdrom(&cd->cdi);
846 disk->private_data = NULL;
853 static int sr_remove(struct device *dev)
855 struct scsi_cd *cd = dev_get_drvdata(dev);
857 del_gendisk(cd->disk);
859 mutex_lock(&sr_ref_mutex);
860 kref_put(&cd->kref, sr_kref_release);
861 mutex_unlock(&sr_ref_mutex);
866 static int __init init_sr(void)
870 rc = register_blkdev(SCSI_CDROM_MAJOR, "sr");
873 return scsi_register_driver(&sr_template.gendrv);
876 static void __exit exit_sr(void)
878 scsi_unregister_driver(&sr_template.gendrv);
879 unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
882 module_init(init_sr);
883 module_exit(exit_sr);
884 MODULE_LICENSE("GPL");