1 // SPDX-License-Identifier: GPL-2.0
4 * vendor-specific code for SCSI CD-ROM's goes here.
6 * This is needed becauce most of the new features (multisession and
7 * the like) are too new to be included into the SCSI-II standard (to
8 * be exact: there is'nt anything in my draft copy).
10 * Aug 1997: Ha! Got a SCSI-3 cdrom spec across my fingers. SCSI-3 does
11 * multisession using the READ TOC command (like SONY).
13 * Rearranged stuff here: SCSI-3 is included allways, support
14 * for NEC/TOSHIBA/HP commands is optional.
16 * Gerd Knorr <kraxel@cs.tu-berlin.de>
18 * --------------------------------------------------------------------------
20 * support for XA/multisession-CD's
22 * - NEC: Detection and support of multisession CD's.
24 * - TOSHIBA: Detection and support of multisession CD's.
25 * Some XA-Sector tweaking, required for older drives.
27 * - SONY: Detection and support of multisession CD's.
28 * added by Thomas Quinot <thomas@cuivre.freenix.fr>
30 * - PIONEER, HITACHI, PLEXTOR, MATSHITA, TEAC, PHILIPS: known to
31 * work with SONY (SCSI3 now) code.
33 * - HP: Much like SONY, but a little different... (Thomas)
34 * HP-Writers only ??? Maybe other CD-Writers work with this too ?
35 * HP 6020 writers now supported.
38 #include <linux/cdrom.h>
39 #include <linux/errno.h>
40 #include <linux/string.h>
41 #include <linux/bcd.h>
42 #include <linux/blkdev.h>
43 #include <linux/slab.h>
45 #include <scsi/scsi.h>
46 #include <scsi/scsi_cmnd.h>
47 #include <scsi/scsi_device.h>
48 #include <scsi/scsi_host.h>
49 #include <scsi/scsi_ioctl.h>
57 /* here are some constants to sort the vendors into groups */
59 #define VENDOR_SCSI3 1 /* default: scsi-3 mmc */
62 #define VENDOR_TOSHIBA 3
63 #define VENDOR_WRITER 4 /* pre-scsi3 writers */
65 #define VENDOR_TIMEOUT 30*HZ
67 void sr_vendor_init(Scsi_CD
*cd
)
69 #ifndef CONFIG_BLK_DEV_SR_VENDOR
70 cd
->vendor
= VENDOR_SCSI3
;
72 const char *vendor
= cd
->device
->vendor
;
73 const char *model
= cd
->device
->model
;
76 cd
->vendor
= VENDOR_SCSI3
;
78 /* this is true for scsi3/mmc drives - no more checks */
81 if (cd
->device
->type
== TYPE_WORM
) {
82 cd
->vendor
= VENDOR_WRITER
;
84 } else if (!strncmp(vendor
, "NEC", 3)) {
85 cd
->vendor
= VENDOR_NEC
;
86 if (!strncmp(model
, "CD-ROM DRIVE:25", 15) ||
87 !strncmp(model
, "CD-ROM DRIVE:36", 15) ||
88 !strncmp(model
, "CD-ROM DRIVE:83", 15) ||
89 !strncmp(model
, "CD-ROM DRIVE:84 ", 16)
91 /* my NEC 3x returns the read-raw data if a read-raw
92 is followed by a read for the same sector - aeb */
93 || !strncmp(model
, "CD-ROM DRIVE:500", 16)
96 /* these can't handle multisession, may hang */
97 cd
->cdi
.mask
|= CDC_MULTI_SESSION
;
99 } else if (!strncmp(vendor
, "TOSHIBA", 7)) {
100 cd
->vendor
= VENDOR_TOSHIBA
;
107 /* small handy function for switching block length using MODE SELECT,
108 * used by sr_read_sector() */
110 int sr_set_blocklength(Scsi_CD
*cd
, int blocklength
)
112 unsigned char *buffer
; /* the buffer for the ioctl */
113 struct packet_command cgc
;
114 struct ccs_modesel_head
*modesel
;
117 #ifdef CONFIG_BLK_DEV_SR_VENDOR
118 if (cd
->vendor
== VENDOR_TOSHIBA
)
119 density
= (blocklength
> 2048) ? 0x81 : 0x83;
122 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
127 sr_printk(KERN_INFO
, cd
, "MODE SELECT 0x%x/%d\n", density
, blocklength
);
129 memset(&cgc
, 0, sizeof(struct packet_command
));
130 cgc
.cmd
[0] = MODE_SELECT
;
131 cgc
.cmd
[1] = (1 << 4);
133 modesel
= (struct ccs_modesel_head
*) buffer
;
134 memset(modesel
, 0, sizeof(*modesel
));
135 modesel
->block_desc_length
= 0x08;
136 modesel
->density
= density
;
137 modesel
->block_length_med
= (blocklength
>> 8) & 0xff;
138 modesel
->block_length_lo
= blocklength
& 0xff;
140 cgc
.buflen
= sizeof(*modesel
);
141 cgc
.data_direction
= DMA_TO_DEVICE
;
142 cgc
.timeout
= VENDOR_TIMEOUT
;
143 if (0 == (rc
= sr_do_ioctl(cd
, &cgc
))) {
144 cd
->device
->sector_size
= blocklength
;
148 sr_printk(KERN_INFO
, cd
,
149 "switching blocklength to %d bytes failed\n",
156 /* This function gets called after a media change. Checks if the CD is
157 multisession, asks for offset etc. */
159 int sr_cd_check(struct cdrom_device_info
*cdi
)
161 Scsi_CD
*cd
= cdi
->handle
;
162 unsigned long sector
;
163 unsigned char *buffer
; /* the buffer for the ioctl */
164 struct packet_command cgc
;
167 if (cd
->cdi
.mask
& CDC_MULTI_SESSION
)
170 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
174 sector
= 0; /* the multisession sector offset goes here */
175 no_multi
= 0; /* flag: the drive can't handle multisession */
178 memset(&cgc
, 0, sizeof(struct packet_command
));
180 switch (cd
->vendor
) {
183 cgc
.cmd
[0] = READ_TOC
;
189 cgc
.data_direction
= DMA_FROM_DEVICE
;
190 cgc
.timeout
= VENDOR_TIMEOUT
;
191 rc
= sr_do_ioctl(cd
, &cgc
);
194 if ((buffer
[0] << 8) + buffer
[1] < 0x0a) {
195 sr_printk(KERN_INFO
, cd
, "Hmm, seems the drive "
196 "doesn't support multisession CD's\n");
200 sector
= buffer
[11] + (buffer
[10] << 8) +
201 (buffer
[9] << 16) + (buffer
[8] << 24);
202 if (buffer
[6] <= 1) {
203 /* ignore sector offsets from first track */
208 #ifdef CONFIG_BLK_DEV_SR_VENDOR
210 unsigned long min
, sec
, frame
;
217 cgc
.data_direction
= DMA_FROM_DEVICE
;
218 cgc
.timeout
= VENDOR_TIMEOUT
;
219 rc
= sr_do_ioctl(cd
, &cgc
);
222 if (buffer
[14] != 0 && buffer
[14] != 0xb0) {
223 sr_printk(KERN_INFO
, cd
, "Hmm, seems the cdrom "
224 "doesn't support multisession CD's\n");
229 min
= bcd2bin(buffer
[15]);
230 sec
= bcd2bin(buffer
[16]);
231 frame
= bcd2bin(buffer
[17]);
232 sector
= min
* CD_SECS
* CD_FRAMES
+ sec
* CD_FRAMES
+ frame
;
236 case VENDOR_TOSHIBA
:{
237 unsigned long min
, sec
, frame
;
239 /* we request some disc information (is it a XA-CD ?,
240 * where starts the last session ?) */
246 cgc
.data_direction
= DMA_FROM_DEVICE
;
247 cgc
.timeout
= VENDOR_TIMEOUT
;
248 rc
= sr_do_ioctl(cd
, &cgc
);
250 sr_printk(KERN_INFO
, cd
, "Hmm, seems the drive "
251 "doesn't support multisession CD's\n");
257 min
= bcd2bin(buffer
[1]);
258 sec
= bcd2bin(buffer
[2]);
259 frame
= bcd2bin(buffer
[3]);
260 sector
= min
* CD_SECS
* CD_FRAMES
+ sec
* CD_FRAMES
+ frame
;
262 sector
-= CD_MSF_OFFSET
;
263 sr_set_blocklength(cd
, 2048);
268 cgc
.cmd
[0] = READ_TOC
;
274 cgc
.data_direction
= DMA_FROM_DEVICE
;
275 cgc
.timeout
= VENDOR_TIMEOUT
;
276 rc
= sr_do_ioctl(cd
, &cgc
);
280 if ((rc
= buffer
[2]) == 0) {
281 sr_printk(KERN_WARNING
, cd
,
282 "No finished session\n");
285 cgc
.cmd
[0] = READ_TOC
; /* Read TOC */
286 cgc
.cmd
[6] = rc
& 0x7f; /* number of last session */
292 cgc
.data_direction
= DMA_FROM_DEVICE
;
293 cgc
.timeout
= VENDOR_TIMEOUT
;
294 rc
= sr_do_ioctl(cd
, &cgc
);
298 sector
= buffer
[11] + (buffer
[10] << 8) +
299 (buffer
[9] << 16) + (buffer
[8] << 24);
301 #endif /* CONFIG_BLK_DEV_SR_VENDOR */
304 /* should not happen */
305 sr_printk(KERN_WARNING
, cd
,
306 "unknown vendor code (%i), not initialized ?\n",
312 cd
->ms_offset
= sector
;
314 if (CDS_AUDIO
!= sr_disk_status(cdi
) && 1 == sr_is_xa(cd
))
317 if (2048 != cd
->device
->sector_size
) {
318 sr_set_blocklength(cd
, 2048);
321 cdi
->mask
|= CDC_MULTI_SESSION
;
325 sr_printk(KERN_DEBUG
, cd
, "multisession offset=%lu\n",