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_eh.h>
54 #include <scsi/scsi_host.h>
55 #include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
56 #include <scsi/scsi_request.h>
58 #include "scsi_logging.h"
62 MODULE_PARM(xa_test
, "i"); /* see sr_ioctl.c */
68 #define SR_TIMEOUT (30 * HZ)
69 #define SR_CAPABILITIES \
70 (CDC_CLOSE_TRAY|CDC_OPEN_TRAY|CDC_LOCK|CDC_SELECT_SPEED| \
71 CDC_SELECT_DISC|CDC_MULTI_SESSION|CDC_MCN|CDC_MEDIA_CHANGED| \
72 CDC_PLAY_AUDIO|CDC_RESET|CDC_IOCTLS|CDC_DRIVE_STATUS| \
73 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
74 CDC_MRW|CDC_MRW_W|CDC_RAM)
76 static int sr_probe(struct device
*);
77 static int sr_remove(struct device
*);
78 static int sr_init_command(struct scsi_cmnd
*);
80 static struct scsi_driver sr_template
= {
87 .init_command
= sr_init_command
,
90 static unsigned long sr_index_bits
[SR_DISKS
/ BITS_PER_LONG
];
91 static spinlock_t sr_index_lock
= SPIN_LOCK_UNLOCKED
;
93 /* This semaphore is used to mediate the 0->1 reference get in the
94 * face of object destruction (i.e. we can't allow a get on an
95 * object after last put) */
96 static DECLARE_MUTEX(sr_ref_sem
);
98 static int sr_open(struct cdrom_device_info
*, int);
99 static void sr_release(struct cdrom_device_info
*);
101 static void get_sectorsize(struct scsi_cd
*);
102 static void get_capabilities(struct scsi_cd
*);
104 static int sr_media_change(struct cdrom_device_info
*, int);
105 static int sr_packet(struct cdrom_device_info
*, struct packet_command
*);
107 static struct cdrom_device_ops sr_dops
= {
109 .release
= sr_release
,
110 .drive_status
= sr_drive_status
,
111 .media_changed
= sr_media_change
,
112 .tray_move
= sr_tray_move
,
113 .lock_door
= sr_lock_door
,
114 .select_speed
= sr_select_speed
,
115 .get_last_session
= sr_get_last_session
,
116 .get_mcn
= sr_get_mcn
,
118 .audio_ioctl
= sr_audio_ioctl
,
119 .dev_ioctl
= sr_dev_ioctl
,
120 .capability
= SR_CAPABILITIES
,
121 .generic_packet
= sr_packet
,
124 static void sr_kref_release(struct kref
*kref
);
126 static inline struct scsi_cd
*scsi_cd(struct gendisk
*disk
)
128 return container_of(disk
->private_data
, struct scsi_cd
, driver
);
132 * The get and put routines for the struct scsi_cd. Note this entity
133 * has a scsi_device pointer and owns a reference to this.
135 static inline struct scsi_cd
*scsi_cd_get(struct gendisk
*disk
)
137 struct scsi_cd
*cd
= NULL
;
140 if (disk
->private_data
== NULL
)
144 if (scsi_device_get(cd
->device
))
149 kref_put(&cd
->kref
, sr_kref_release
);
156 static inline void scsi_cd_put(struct scsi_cd
*cd
)
159 scsi_device_put(cd
->device
);
160 kref_put(&cd
->kref
, sr_kref_release
);
165 * This function checks to see if the media has been changed in the
166 * CDROM drive. It is possible that we have already sensed a change,
167 * or the drive may have sensed one and not yet reported it. We must
168 * be ready for either case. This function always reports the current
169 * value of the changed bit. If flag is 0, then the changed bit is reset.
170 * This function could be done as an ioctl, but we would need to have
171 * an inode for that to work, and we do not always have one.
174 int sr_media_change(struct cdrom_device_info
*cdi
, int slot
)
176 struct scsi_cd
*cd
= cdi
->handle
;
179 if (CDSL_CURRENT
!= slot
) {
180 /* no changer support */
184 retval
= scsi_test_unit_ready(cd
->device
, SR_TIMEOUT
, MAX_RETRIES
);
186 /* Unable to test, unit probably not ready. This usually
187 * means there is no disc in the drive. Mark as changed,
188 * and we will figure it out later once the drive is
189 * available again. */
190 cd
->device
->changed
= 1;
191 return 1; /* This will force a flush, if called from
192 * check_disk_change */
195 retval
= cd
->device
->changed
;
196 cd
->device
->changed
= 0;
197 /* If the disk changed, the capacity will now be different,
198 * so we force a re-read of this information */
200 /* check multisession offset etc */
204 * If the disk changed, the capacity will now be different,
205 * so we force a re-read of this information
206 * Force 2048 for the sector size so that filesystems won't
207 * be trying to use something that is too small if the disc
210 cd
->needs_sector_size
= 1;
211 cd
->device
->sector_size
= 2048;
217 * rw_intr is the interrupt routine for the device driver.
219 * It will be notified on the end of a SCSI read / write, and will take on
220 * of several actions based on success or failure.
222 static void rw_intr(struct scsi_cmnd
* SCpnt
)
224 int result
= SCpnt
->result
;
225 int this_count
= SCpnt
->bufflen
;
226 int good_bytes
= (result
== 0 ? this_count
: 0);
227 int block_sectors
= 0;
229 struct scsi_cd
*cd
= scsi_cd(SCpnt
->request
->rq_disk
);
232 printk("sr.c done: %x\n", result
);
236 * Handle MEDIUM ERRORs or VOLUME OVERFLOWs that indicate partial
237 * success. Since this is a relatively rare error condition, no
238 * care is taken to avoid unnecessary additional work such as
239 * memcpy's that could be avoided.
241 if (driver_byte(result
) != 0 && /* An error occurred */
242 (SCpnt
->sense_buffer
[0] & 0x7f) == 0x70) { /* Sense current */
243 switch (SCpnt
->sense_buffer
[2]) {
245 case VOLUME_OVERFLOW
:
246 case ILLEGAL_REQUEST
:
247 if (!(SCpnt
->sense_buffer
[0] & 0x90))
249 if (!blk_fs_request(SCpnt
->request
))
251 error_sector
= (SCpnt
->sense_buffer
[3] << 24) |
252 (SCpnt
->sense_buffer
[4] << 16) |
253 (SCpnt
->sense_buffer
[5] << 8) |
254 SCpnt
->sense_buffer
[6];
255 if (SCpnt
->request
->bio
!= NULL
)
257 bio_sectors(SCpnt
->request
->bio
);
258 if (block_sectors
< 4)
260 if (cd
->device
->sector_size
== 2048)
262 error_sector
&= ~(block_sectors
- 1);
263 good_bytes
= (error_sector
- SCpnt
->request
->sector
) << 9;
264 if (good_bytes
< 0 || good_bytes
>= this_count
)
267 * The SCSI specification allows for the value
268 * returned by READ CAPACITY to be up to 75 2K
269 * sectors past the last readable block.
270 * Therefore, if we hit a medium error within the
271 * last 75 2K sectors, we decrease the saved size
274 if (error_sector
< get_capacity(cd
->disk
) &&
275 cd
->capacity
- error_sector
< 4 * 75)
276 set_capacity(cd
->disk
, error_sector
);
279 case RECOVERED_ERROR
:
282 * An error occured, but it recovered. Inform the
283 * user, but make sure that it's not treated as a
286 scsi_print_sense("sr", SCpnt
);
288 SCpnt
->sense_buffer
[0] = 0x0;
289 good_bytes
= this_count
;
298 * This calls the generic completion function, now that we know
299 * how many actual sectors finished, and how many sectors we need
300 * to say have failed.
302 scsi_io_completion(SCpnt
, good_bytes
, block_sectors
<< 9);
305 static int sr_init_command(struct scsi_cmnd
* SCpnt
)
307 int block
=0, this_count
, s_size
, timeout
= SR_TIMEOUT
;
308 struct scsi_cd
*cd
= scsi_cd(SCpnt
->request
->rq_disk
);
310 SCSI_LOG_HLQUEUE(1, printk("Doing sr request, dev = %s, block = %d\n",
311 cd
->disk
->disk_name
, block
));
313 if (!cd
->device
|| !scsi_device_online(cd
->device
)) {
314 SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n",
315 SCpnt
->request
->nr_sectors
));
316 SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt
));
320 if (cd
->device
->changed
) {
322 * quietly refuse to do anything to a changed disc until the
323 * changed bit has been reset
329 * these are already setup, just copy cdb basically
331 if (SCpnt
->request
->flags
& REQ_BLOCK_PC
) {
332 struct request
*rq
= SCpnt
->request
;
334 if (sizeof(rq
->cmd
) > sizeof(SCpnt
->cmnd
))
337 memcpy(SCpnt
->cmnd
, rq
->cmd
, sizeof(SCpnt
->cmnd
));
339 SCpnt
->sc_data_direction
= DMA_NONE
;
340 else if (rq_data_dir(rq
) == WRITE
)
341 SCpnt
->sc_data_direction
= DMA_TO_DEVICE
;
343 SCpnt
->sc_data_direction
= DMA_FROM_DEVICE
;
345 this_count
= rq
->data_len
;
347 timeout
= rq
->timeout
;
349 SCpnt
->transfersize
= rq
->data_len
;
353 if (!(SCpnt
->request
->flags
& REQ_CMD
)) {
354 blk_dump_rq_flags(SCpnt
->request
, "sr unsup command");
359 * we do lazy blocksize switching (when reading XA sectors,
360 * see CDROMREADMODE2 ioctl)
362 s_size
= cd
->device
->sector_size
;
365 sr_set_blocklength(cd
, 2048);
367 printk("sr: can't switch blocksize: in interrupt\n");
370 if (s_size
!= 512 && s_size
!= 1024 && s_size
!= 2048) {
371 printk("sr: bad sector size %d\n", s_size
);
375 if (rq_data_dir(SCpnt
->request
) == WRITE
) {
376 if (!cd
->device
->writeable
)
378 SCpnt
->cmnd
[0] = WRITE_10
;
379 SCpnt
->sc_data_direction
= DMA_TO_DEVICE
;
380 cd
->cdi
.media_written
= 1;
381 } else if (rq_data_dir(SCpnt
->request
) == READ
) {
382 SCpnt
->cmnd
[0] = READ_10
;
383 SCpnt
->sc_data_direction
= DMA_FROM_DEVICE
;
385 blk_dump_rq_flags(SCpnt
->request
, "Unknown sr command");
390 struct scatterlist
*sg
= SCpnt
->request_buffer
;
392 for (i
= 0; i
< SCpnt
->use_sg
; i
++)
393 size
+= sg
[i
].length
;
395 if (size
!= SCpnt
->request_bufflen
&& SCpnt
->use_sg
) {
396 printk(KERN_ERR
"sr: mismatch count %d, bytes %d\n",
397 size
, SCpnt
->request_bufflen
);
398 if (SCpnt
->request_bufflen
> size
)
399 SCpnt
->request_bufflen
= SCpnt
->bufflen
= size
;
404 * request doesn't start on hw block boundary, add scatter pads
406 if (((unsigned int)SCpnt
->request
->sector
% (s_size
>> 9)) ||
407 (SCpnt
->request_bufflen
% s_size
)) {
408 printk("sr: unaligned transfer\n");
412 this_count
= (SCpnt
->request_bufflen
>> 9) / (s_size
>> 9);
415 SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n",
417 (rq_data_dir(SCpnt
->request
) == WRITE
) ?
418 "writing" : "reading",
419 this_count
, SCpnt
->request
->nr_sectors
));
422 block
= (unsigned int)SCpnt
->request
->sector
/ (s_size
>> 9);
424 if (this_count
> 0xffff) {
426 SCpnt
->request_bufflen
= SCpnt
->bufflen
=
430 SCpnt
->cmnd
[2] = (unsigned char) (block
>> 24) & 0xff;
431 SCpnt
->cmnd
[3] = (unsigned char) (block
>> 16) & 0xff;
432 SCpnt
->cmnd
[4] = (unsigned char) (block
>> 8) & 0xff;
433 SCpnt
->cmnd
[5] = (unsigned char) block
& 0xff;
434 SCpnt
->cmnd
[6] = SCpnt
->cmnd
[9] = 0;
435 SCpnt
->cmnd
[7] = (unsigned char) (this_count
>> 8) & 0xff;
436 SCpnt
->cmnd
[8] = (unsigned char) this_count
& 0xff;
439 * We shouldn't disconnect in the middle of a sector, so with a dumb
440 * host adapter, it's safe to assume that we can at least transfer
441 * this many bytes between each connect / disconnect.
443 SCpnt
->transfersize
= cd
->device
->sector_size
;
444 SCpnt
->underflow
= this_count
<< 9;
447 SCpnt
->allowed
= MAX_RETRIES
;
448 SCpnt
->timeout_per_command
= timeout
;
451 * This is the completion routine we use. This is matched in terms
452 * of capability to this function.
454 SCpnt
->done
= rw_intr
;
457 * This indicates that the command is ready from our end to be
463 static int sr_block_open(struct inode
*inode
, struct file
*file
)
465 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
466 struct scsi_cd
*cd
= scsi_cd(inode
->i_bdev
->bd_disk
);
469 if(!(cd
= scsi_cd_get(disk
)))
472 if((ret
= cdrom_open(&cd
->cdi
, inode
, file
)) != 0)
478 static int sr_block_release(struct inode
*inode
, struct file
*file
)
481 struct scsi_cd
*cd
= scsi_cd(inode
->i_bdev
->bd_disk
);
482 ret
= cdrom_release(&cd
->cdi
, file
);
491 static int sr_block_ioctl(struct inode
*inode
, struct file
*file
, unsigned cmd
,
494 struct scsi_cd
*cd
= scsi_cd(inode
->i_bdev
->bd_disk
);
495 struct scsi_device
*sdev
= cd
->device
;
498 * Send SCSI addressing ioctls directly to mid level, send other
499 * ioctls to cdrom/block level.
502 case SCSI_IOCTL_GET_IDLUN
:
503 case SCSI_IOCTL_GET_BUS_NUMBER
:
504 return scsi_ioctl(sdev
, cmd
, (void __user
*)arg
);
506 return cdrom_ioctl(file
, &cd
->cdi
, inode
, cmd
, arg
);
509 static int sr_block_media_changed(struct gendisk
*disk
)
511 struct scsi_cd
*cd
= scsi_cd(disk
);
512 return cdrom_media_changed(&cd
->cdi
);
515 struct block_device_operations sr_bdops
=
517 .owner
= THIS_MODULE
,
518 .open
= sr_block_open
,
519 .release
= sr_block_release
,
520 .ioctl
= sr_block_ioctl
,
521 .media_changed
= sr_block_media_changed
,
524 static int sr_open(struct cdrom_device_info
*cdi
, int purpose
)
526 struct scsi_cd
*cd
= cdi
->handle
;
527 struct scsi_device
*sdev
= cd
->device
;
531 * If the device is in error recovery, wait until it is done.
532 * If the device is offline, then disallow any access to it.
535 if (!scsi_block_when_processing_errors(sdev
))
539 * If this device did not have media in the drive at boot time, then
540 * we would have been unable to get the sector size. Check to see if
541 * this is the case, and try again.
543 if (cd
->needs_sector_size
)
552 static void sr_release(struct cdrom_device_info
*cdi
)
554 struct scsi_cd
*cd
= cdi
->handle
;
556 if (cd
->device
->sector_size
> 2048)
557 sr_set_blocklength(cd
, 2048);
561 static int sr_probe(struct device
*dev
)
563 struct scsi_device
*sdev
= to_scsi_device(dev
);
564 struct gendisk
*disk
;
569 if (sdev
->type
!= TYPE_ROM
&& sdev
->type
!= TYPE_WORM
)
573 cd
= kmalloc(sizeof(*cd
), GFP_KERNEL
);
576 memset(cd
, 0, sizeof(*cd
));
578 kref_init(&cd
->kref
);
580 disk
= alloc_disk(1);
584 spin_lock(&sr_index_lock
);
585 minor
= find_first_zero_bit(sr_index_bits
, SR_DISKS
);
586 if (minor
== SR_DISKS
) {
587 spin_unlock(&sr_index_lock
);
591 __set_bit(minor
, sr_index_bits
);
592 spin_unlock(&sr_index_lock
);
594 disk
->major
= SCSI_CDROM_MAJOR
;
595 disk
->first_minor
= minor
;
596 sprintf(disk
->disk_name
, "sr%d", minor
);
597 disk
->fops
= &sr_bdops
;
598 disk
->flags
= GENHD_FL_CD
;
602 cd
->driver
= &sr_template
;
604 cd
->capacity
= 0x1fffff;
605 cd
->needs_sector_size
= 1;
606 cd
->device
->changed
= 1; /* force recheck CD type */
608 cd
->readcd_known
= 0;
611 cd
->cdi
.ops
= &sr_dops
;
614 cd
->cdi
.capacity
= 1;
615 sprintf(cd
->cdi
.name
, "sr%d", minor
);
617 sdev
->sector_size
= 2048; /* A guess, just in case */
619 /* FIXME: need to handle a get_capabilities failure properly ?? */
620 get_capabilities(cd
);
623 snprintf(disk
->devfs_name
, sizeof(disk
->devfs_name
),
624 "%s/cd", sdev
->devfs_name
);
625 disk
->driverfs_dev
= &sdev
->sdev_gendev
;
626 set_capacity(disk
, cd
->capacity
);
627 disk
->private_data
= &cd
->driver
;
628 disk
->queue
= sdev
->request_queue
;
631 if (register_cdrom(&cd
->cdi
))
634 dev_set_drvdata(dev
, cd
);
635 disk
->flags
|= GENHD_FL_REMOVABLE
;
639 "Attached scsi CD-ROM %s at scsi%d, channel %d, id %d, lun %d\n",
640 cd
->cdi
.name
, sdev
->host
->host_no
, sdev
->channel
,
641 sdev
->id
, sdev
->lun
);
653 static void get_sectorsize(struct scsi_cd
*cd
)
655 unsigned char cmd
[10];
656 unsigned char *buffer
;
657 int the_result
, retries
= 3;
659 struct scsi_request
*SRpnt
= NULL
;
660 request_queue_t
*queue
;
662 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
665 SRpnt
= scsi_allocate_request(cd
->device
, GFP_KERNEL
);
670 cmd
[0] = READ_CAPACITY
;
671 memset((void *) &cmd
[1], 0, 9);
672 /* Mark as really busy */
673 SRpnt
->sr_request
->rq_status
= RQ_SCSI_BUSY
;
674 SRpnt
->sr_cmd_len
= 0;
676 memset(buffer
, 0, 8);
678 /* Do the command and wait.. */
679 SRpnt
->sr_data_direction
= DMA_FROM_DEVICE
;
680 scsi_wait_req(SRpnt
, (void *) cmd
, (void *) buffer
,
681 8, SR_TIMEOUT
, MAX_RETRIES
);
683 the_result
= SRpnt
->sr_result
;
686 } while (the_result
&& retries
);
689 scsi_release_request(SRpnt
);
693 cd
->capacity
= 0x1fffff;
694 sector_size
= 2048; /* A guess, just in case */
695 cd
->needs_sector_size
= 1;
698 if (cdrom_get_last_written(&cd
->cdi
,
701 cd
->capacity
= 1 + ((buffer
[0] << 24) |
705 sector_size
= (buffer
[4] << 24) |
706 (buffer
[5] << 16) | (buffer
[6] << 8) | buffer
[7];
707 switch (sector_size
) {
709 * HP 4020i CD-Recorder reports 2340 byte sectors
710 * Philips CD-Writers report 2352 byte sectors
712 * Use 2k sectors for them..
725 printk("%s: unsupported sector size %d.\n",
726 cd
->cdi
.name
, sector_size
);
728 cd
->needs_sector_size
= 1;
731 cd
->device
->sector_size
= sector_size
;
734 * Add this so that we have the ability to correctly gauge
735 * what the device is capable of.
737 cd
->needs_sector_size
= 0;
738 set_capacity(cd
->disk
, cd
->capacity
);
741 queue
= cd
->device
->request_queue
;
742 blk_queue_hardsect_size(queue
, sector_size
);
748 cd
->capacity
= 0x1fffff;
749 sector_size
= 2048; /* A guess, just in case */
750 cd
->needs_sector_size
= 1;
752 scsi_release_request(SRpnt
);
756 static void get_capabilities(struct scsi_cd
*cd
)
758 unsigned char *buffer
;
759 struct scsi_mode_data data
;
760 struct scsi_request
*SRpnt
;
761 unsigned char cmd
[MAX_COMMAND_SIZE
];
762 unsigned int the_result
;
765 static char *loadmech
[] =
777 /* allocate a request for the TEST_UNIT_READY */
778 SRpnt
= scsi_allocate_request(cd
->device
, GFP_KERNEL
);
780 printk(KERN_WARNING
"(get_capabilities:) Request allocation "
785 /* allocate transfer buffer */
786 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
788 printk(KERN_ERR
"sr: out of memory.\n");
789 scsi_release_request(SRpnt
);
793 /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION
794 * conditions are gone, or a timeout happens
798 memset((void *)cmd
, 0, MAX_COMMAND_SIZE
);
799 cmd
[0] = TEST_UNIT_READY
;
801 SRpnt
->sr_cmd_len
= 0;
802 SRpnt
->sr_sense_buffer
[0] = 0;
803 SRpnt
->sr_sense_buffer
[2] = 0;
804 SRpnt
->sr_data_direction
= DMA_NONE
;
806 scsi_wait_req (SRpnt
, (void *) cmd
, buffer
,
807 0, SR_TIMEOUT
, MAX_RETRIES
);
809 the_result
= SRpnt
->sr_result
;
811 } while (retries
< 5 &&
812 (!scsi_status_is_good(the_result
) ||
813 ((driver_byte(the_result
) & DRIVER_SENSE
) &&
814 SRpnt
->sr_sense_buffer
[2] == UNIT_ATTENTION
)));
816 /* ask for mode page 0x2a */
817 rc
= scsi_mode_sense(cd
->device
, 0, 0x2a, buffer
, 128,
818 SR_TIMEOUT
, 3, &data
);
820 if (!scsi_status_is_good(rc
)) {
821 /* failed, drive doesn't have capabilities mode page */
823 cd
->cdi
.mask
|= (CDC_CD_R
| CDC_CD_RW
| CDC_DVD_R
|
824 CDC_DVD
| CDC_DVD_RAM
|
825 CDC_SELECT_DISC
| CDC_SELECT_SPEED
);
826 scsi_release_request(SRpnt
);
828 printk("%s: scsi-1 drive\n", cd
->cdi
.name
);
832 n
= data
.header_length
+ data
.block_descriptor_length
;
833 cd
->cdi
.speed
= ((buffer
[n
+ 8] << 8) + buffer
[n
+ 9]) / 176;
834 cd
->readcd_known
= 1;
835 cd
->readcd_cdda
= buffer
[n
+ 5] & 0x01;
836 /* print some capability bits */
837 printk("%s: scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n", cd
->cdi
.name
,
838 ((buffer
[n
+ 14] << 8) + buffer
[n
+ 15]) / 176,
840 buffer
[n
+ 3] & 0x01 ? "writer " : "", /* CD Writer */
841 buffer
[n
+ 3] & 0x20 ? "dvd-ram " : "",
842 buffer
[n
+ 2] & 0x02 ? "cd/rw " : "", /* can read rewriteable */
843 buffer
[n
+ 4] & 0x20 ? "xa/form2 " : "", /* can read xa/from2 */
844 buffer
[n
+ 5] & 0x01 ? "cdda " : "", /* can read audio data */
845 loadmech
[buffer
[n
+ 6] >> 5]);
846 if ((buffer
[n
+ 6] >> 5) == 0)
847 /* caddy drives can't close tray... */
848 cd
->cdi
.mask
|= CDC_CLOSE_TRAY
;
849 if ((buffer
[n
+ 2] & 0x8) == 0)
850 /* not a DVD drive */
851 cd
->cdi
.mask
|= CDC_DVD
;
852 if ((buffer
[n
+ 3] & 0x20) == 0)
853 /* can't write DVD-RAM media */
854 cd
->cdi
.mask
|= CDC_DVD_RAM
;
855 if ((buffer
[n
+ 3] & 0x10) == 0)
856 /* can't write DVD-R media */
857 cd
->cdi
.mask
|= CDC_DVD_R
;
858 if ((buffer
[n
+ 3] & 0x2) == 0)
859 /* can't write CD-RW media */
860 cd
->cdi
.mask
|= CDC_CD_RW
;
861 if ((buffer
[n
+ 3] & 0x1) == 0)
862 /* can't write CD-R media */
863 cd
->cdi
.mask
|= CDC_CD_R
;
864 if ((buffer
[n
+ 6] & 0x8) == 0)
866 cd
->cdi
.mask
|= CDC_OPEN_TRAY
;
868 if ((buffer
[n
+ 6] >> 5) == mechtype_individual_changer
||
869 (buffer
[n
+ 6] >> 5) == mechtype_cartridge_changer
)
871 cdrom_number_of_slots(&cd
->cdi
);
872 if (cd
->cdi
.capacity
<= 1)
874 cd
->cdi
.mask
|= CDC_SELECT_DISC
;
875 /*else I don't think it can close its tray
876 cd->cdi.mask |= CDC_CLOSE_TRAY; */
879 * if DVD-RAM, MRW-W or CD-RW, we are randomly writable
881 if ((cd
->cdi
.mask
& (CDC_DVD_RAM
| CDC_MRW_W
| CDC_RAM
| CDC_CD_RW
)) !=
882 (CDC_DVD_RAM
| CDC_MRW_W
| CDC_RAM
| CDC_CD_RW
)) {
883 cd
->device
->writeable
= 1;
886 scsi_release_request(SRpnt
);
891 * sr_packet() is the entry point for the generic commands generated
892 * by the Uniform CD-ROM layer.
894 static int sr_packet(struct cdrom_device_info
*cdi
,
895 struct packet_command
*cgc
)
897 if (cgc
->timeout
<= 0)
898 cgc
->timeout
= IOCTL_TIMEOUT
;
900 sr_do_ioctl(cdi
->handle
, cgc
);
906 * sr_kref_release - Called to free the scsi_cd structure
907 * @kref: pointer to embedded kref
909 * sr_ref_sem must be held entering this routine. Because it is
910 * called on last put, you should always use the scsi_cd_get()
911 * scsi_cd_put() helpers which manipulate the semaphore directly
912 * and never do a direct kref_put().
914 static void sr_kref_release(struct kref
*kref
)
916 struct scsi_cd
*cd
= container_of(kref
, struct scsi_cd
, kref
);
917 struct gendisk
*disk
= cd
->disk
;
919 spin_lock(&sr_index_lock
);
920 clear_bit(disk
->first_minor
, sr_index_bits
);
921 spin_unlock(&sr_index_lock
);
923 unregister_cdrom(&cd
->cdi
);
925 disk
->private_data
= NULL
;
932 static int sr_remove(struct device
*dev
)
934 struct scsi_cd
*cd
= dev_get_drvdata(dev
);
936 del_gendisk(cd
->disk
);
939 kref_put(&cd
->kref
, sr_kref_release
);
945 static int __init
init_sr(void)
949 rc
= register_blkdev(SCSI_CDROM_MAJOR
, "sr");
952 return scsi_register_driver(&sr_template
.gendrv
);
955 static void __exit
exit_sr(void)
957 scsi_unregister_driver(&sr_template
.gendrv
);
958 unregister_blkdev(SCSI_CDROM_MAJOR
, "sr");
961 module_init(init_sr
);
962 module_exit(exit_sr
);
963 MODULE_LICENSE("GPL");