3 * vendor-specific code for SCSI CD-ROM's goes here.
5 * This is needed becauce most of the new features (multisession and
6 * the like) are too new to be included into the SCSI-II standard (to
7 * be exact: there is'nt anything in my draft copy).
9 * Aug 1997: Ha! Got a SCSI-3 cdrom spec across my fingers. SCSI-3 does
10 * multisession using the READ TOC command (like SONY).
12 * Rearranged stuff here: SCSI-3 is included allways, support
13 * for NEC/TOSHIBA/HP commands is optional.
15 * Gerd Knorr <kraxel@cs.tu-berlin.de>
17 * --------------------------------------------------------------------------
19 * support for XA/multisession-CD's
21 * - NEC: Detection and support of multisession CD's.
23 * - TOSHIBA: Detection and support of multisession CD's.
24 * Some XA-Sector tweaking, required for older drives.
26 * - SONY: Detection and support of multisession CD's.
27 * added by Thomas Quinot <thomas@cuivre.freenix.fr>
29 * - PIONEER, HITACHI, PLEXTOR, MATSHITA, TEAC, PHILIPS: known to
30 * work with SONY (SCSI3 now) code.
32 * - HP: Much like SONY, but a little different... (Thomas)
33 * HP-Writers only ??? Maybe other CD-Writers work with this too ?
34 * HP 6020 writers now supported.
37 #include <linux/cdrom.h>
38 #include <linux/errno.h>
39 #include <linux/string.h>
40 #include <linux/bcd.h>
41 #include <linux/blkdev.h>
43 #include <scsi/scsi.h>
44 #include <scsi/scsi_cmnd.h>
45 #include <scsi/scsi_device.h>
46 #include <scsi/scsi_host.h>
47 #include <scsi/scsi_ioctl.h>
55 /* here are some constants to sort the vendors into groups */
57 #define VENDOR_SCSI3 1 /* default: scsi-3 mmc */
60 #define VENDOR_TOSHIBA 3
61 #define VENDOR_WRITER 4 /* pre-scsi3 writers */
63 #define VENDOR_TIMEOUT 30*HZ
65 void sr_vendor_init(Scsi_CD
*cd
)
67 #ifndef CONFIG_BLK_DEV_SR_VENDOR
68 cd
->vendor
= VENDOR_SCSI3
;
70 const char *vendor
= cd
->device
->vendor
;
71 const char *model
= cd
->device
->model
;
74 cd
->vendor
= VENDOR_SCSI3
;
76 /* this is true for scsi3/mmc drives - no more checks */
79 if (cd
->device
->type
== TYPE_WORM
) {
80 cd
->vendor
= VENDOR_WRITER
;
82 } else if (!strncmp(vendor
, "NEC", 3)) {
83 cd
->vendor
= VENDOR_NEC
;
84 if (!strncmp(model
, "CD-ROM DRIVE:25", 15) ||
85 !strncmp(model
, "CD-ROM DRIVE:36", 15) ||
86 !strncmp(model
, "CD-ROM DRIVE:83", 15) ||
87 !strncmp(model
, "CD-ROM DRIVE:84 ", 16)
89 /* my NEC 3x returns the read-raw data if a read-raw
90 is followed by a read for the same sector - aeb */
91 || !strncmp(model
, "CD-ROM DRIVE:500", 16)
94 /* these can't handle multisession, may hang */
95 cd
->cdi
.mask
|= CDC_MULTI_SESSION
;
97 } else if (!strncmp(vendor
, "TOSHIBA", 7)) {
98 cd
->vendor
= VENDOR_TOSHIBA
;
105 /* small handy function for switching block length using MODE SELECT,
106 * used by sr_read_sector() */
108 int sr_set_blocklength(Scsi_CD
*cd
, int blocklength
)
110 unsigned char *buffer
; /* the buffer for the ioctl */
111 struct packet_command cgc
;
112 struct ccs_modesel_head
*modesel
;
115 #ifdef CONFIG_BLK_DEV_SR_VENDOR
116 if (cd
->vendor
== VENDOR_TOSHIBA
)
117 density
= (blocklength
> 2048) ? 0x81 : 0x83;
120 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
125 printk("%s: MODE SELECT 0x%x/%d\n", cd
->cdi
.name
, density
, blocklength
);
127 memset(&cgc
, 0, sizeof(struct packet_command
));
128 cgc
.cmd
[0] = MODE_SELECT
;
129 cgc
.cmd
[1] = (1 << 4);
131 modesel
= (struct ccs_modesel_head
*) buffer
;
132 memset(modesel
, 0, sizeof(*modesel
));
133 modesel
->block_desc_length
= 0x08;
134 modesel
->density
= density
;
135 modesel
->block_length_med
= (blocklength
>> 8) & 0xff;
136 modesel
->block_length_lo
= blocklength
& 0xff;
138 cgc
.buflen
= sizeof(*modesel
);
139 cgc
.data_direction
= DMA_TO_DEVICE
;
140 cgc
.timeout
= VENDOR_TIMEOUT
;
141 if (0 == (rc
= sr_do_ioctl(cd
, &cgc
))) {
142 cd
->device
->sector_size
= blocklength
;
146 printk("%s: switching blocklength to %d bytes failed\n",
147 cd
->cdi
.name
, blocklength
);
153 /* This function gets called after a media change. Checks if the CD is
154 multisession, asks for offset etc. */
156 int sr_cd_check(struct cdrom_device_info
*cdi
)
158 Scsi_CD
*cd
= cdi
->handle
;
159 unsigned long sector
;
160 unsigned char *buffer
; /* the buffer for the ioctl */
161 struct packet_command cgc
;
164 if (cd
->cdi
.mask
& CDC_MULTI_SESSION
)
167 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
171 sector
= 0; /* the multisession sector offset goes here */
172 no_multi
= 0; /* flag: the drive can't handle multisession */
175 memset(&cgc
, 0, sizeof(struct packet_command
));
177 switch (cd
->vendor
) {
180 cgc
.cmd
[0] = READ_TOC
;
186 cgc
.data_direction
= DMA_FROM_DEVICE
;
187 cgc
.timeout
= VENDOR_TIMEOUT
;
188 rc
= sr_do_ioctl(cd
, &cgc
);
191 if ((buffer
[0] << 8) + buffer
[1] < 0x0a) {
192 printk(KERN_INFO
"%s: Hmm, seems the drive "
193 "doesn't support multisession CD's\n", cd
->cdi
.name
);
197 sector
= buffer
[11] + (buffer
[10] << 8) +
198 (buffer
[9] << 16) + (buffer
[8] << 24);
199 if (buffer
[6] <= 1) {
200 /* ignore sector offsets from first track */
205 #ifdef CONFIG_BLK_DEV_SR_VENDOR
207 unsigned long min
, sec
, frame
;
214 cgc
.data_direction
= DMA_FROM_DEVICE
;
215 cgc
.timeout
= VENDOR_TIMEOUT
;
216 rc
= sr_do_ioctl(cd
, &cgc
);
219 if (buffer
[14] != 0 && buffer
[14] != 0xb0) {
220 printk(KERN_INFO
"%s: Hmm, seems the cdrom "
221 "doesn't support multisession CD's\n",
226 min
= BCD2BIN(buffer
[15]);
227 sec
= BCD2BIN(buffer
[16]);
228 frame
= BCD2BIN(buffer
[17]);
229 sector
= min
* CD_SECS
* CD_FRAMES
+ sec
* CD_FRAMES
+ frame
;
233 case VENDOR_TOSHIBA
:{
234 unsigned long min
, sec
, frame
;
236 /* we request some disc information (is it a XA-CD ?,
237 * where starts the last session ?) */
243 cgc
.data_direction
= DMA_FROM_DEVICE
;
244 cgc
.timeout
= VENDOR_TIMEOUT
;
245 rc
= sr_do_ioctl(cd
, &cgc
);
247 printk(KERN_INFO
"%s: Hmm, seems the drive "
248 "doesn't support multisession CD's\n",
255 min
= BCD2BIN(buffer
[1]);
256 sec
= BCD2BIN(buffer
[2]);
257 frame
= BCD2BIN(buffer
[3]);
258 sector
= min
* CD_SECS
* CD_FRAMES
+ sec
* CD_FRAMES
+ frame
;
260 sector
-= CD_MSF_OFFSET
;
261 sr_set_blocklength(cd
, 2048);
266 cgc
.cmd
[0] = READ_TOC
;
272 cgc
.data_direction
= DMA_FROM_DEVICE
;
273 cgc
.timeout
= VENDOR_TIMEOUT
;
274 rc
= sr_do_ioctl(cd
, &cgc
);
278 if ((rc
= buffer
[2]) == 0) {
280 "%s: No finished session\n", cd
->cdi
.name
);
283 cgc
.cmd
[0] = READ_TOC
; /* Read TOC */
284 cgc
.cmd
[6] = rc
& 0x7f; /* number of last session */
290 cgc
.data_direction
= DMA_FROM_DEVICE
;
291 cgc
.timeout
= VENDOR_TIMEOUT
;
292 rc
= sr_do_ioctl(cd
, &cgc
);
296 sector
= buffer
[11] + (buffer
[10] << 8) +
297 (buffer
[9] << 16) + (buffer
[8] << 24);
299 #endif /* CONFIG_BLK_DEV_SR_VENDOR */
302 /* should not happen */
304 "%s: unknown vendor code (%i), not initialized ?\n",
305 cd
->cdi
.name
, cd
->vendor
);
310 cd
->ms_offset
= sector
;
312 if (CDS_AUDIO
!= sr_disk_status(cdi
) && 1 == sr_is_xa(cd
))
315 if (2048 != cd
->device
->sector_size
) {
316 sr_set_blocklength(cd
, 2048);
319 cdi
->mask
|= CDC_MULTI_SESSION
;
323 printk(KERN_DEBUG
"%s: multisession offset=%lu\n",
324 cd
->cdi
.name
, sector
);