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 */
64 #define VENDOR_CYGNAL_85ED 5 /* CD-on-a-chip */
66 #define VENDOR_TIMEOUT 30*HZ
68 void sr_vendor_init(Scsi_CD
*cd
)
70 #ifndef CONFIG_BLK_DEV_SR_VENDOR
71 cd
->vendor
= VENDOR_SCSI3
;
73 const char *vendor
= cd
->device
->vendor
;
74 const char *model
= cd
->device
->model
;
77 cd
->vendor
= VENDOR_SCSI3
;
79 /* this is true for scsi3/mmc drives - no more checks */
82 if (cd
->device
->type
== TYPE_WORM
) {
83 cd
->vendor
= VENDOR_WRITER
;
85 } else if (!strncmp(vendor
, "NEC", 3)) {
86 cd
->vendor
= VENDOR_NEC
;
87 if (!strncmp(model
, "CD-ROM DRIVE:25", 15) ||
88 !strncmp(model
, "CD-ROM DRIVE:36", 15) ||
89 !strncmp(model
, "CD-ROM DRIVE:83", 15) ||
90 !strncmp(model
, "CD-ROM DRIVE:84 ", 16)
92 /* my NEC 3x returns the read-raw data if a read-raw
93 is followed by a read for the same sector - aeb */
94 || !strncmp(model
, "CD-ROM DRIVE:500", 16)
97 /* these can't handle multisession, may hang */
98 cd
->cdi
.mask
|= CDC_MULTI_SESSION
;
100 } else if (!strncmp(vendor
, "TOSHIBA", 7)) {
101 cd
->vendor
= VENDOR_TOSHIBA
;
103 } else if (!strncmp(vendor
, "Beurer", 6) &&
104 !strncmp(model
, "Gluco Memory", 12)) {
105 /* The Beurer GL50 evo uses a Cygnal-manufactured CD-on-a-chip
106 that only accepts a subset of SCSI commands. Most of the
107 not-implemented commands are fine to fail, but a few,
108 particularly around the MMC or Audio commands, will put the
109 device into an unrecoverable state, so they need to be
110 avoided at all costs.
112 cd
->vendor
= VENDOR_CYGNAL_85ED
;
115 CDC_CLOSE_TRAY
| CDC_OPEN_TRAY
|
125 /* small handy function for switching block length using MODE SELECT,
126 * used by sr_read_sector() */
128 int sr_set_blocklength(Scsi_CD
*cd
, int blocklength
)
130 unsigned char *buffer
; /* the buffer for the ioctl */
131 struct packet_command cgc
;
132 struct ccs_modesel_head
*modesel
;
135 #ifdef CONFIG_BLK_DEV_SR_VENDOR
136 if (cd
->vendor
== VENDOR_TOSHIBA
)
137 density
= (blocklength
> 2048) ? 0x81 : 0x83;
140 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
145 sr_printk(KERN_INFO
, cd
, "MODE SELECT 0x%x/%d\n", density
, blocklength
);
147 memset(&cgc
, 0, sizeof(struct packet_command
));
148 cgc
.cmd
[0] = MODE_SELECT
;
149 cgc
.cmd
[1] = (1 << 4);
151 modesel
= (struct ccs_modesel_head
*) buffer
;
152 memset(modesel
, 0, sizeof(*modesel
));
153 modesel
->block_desc_length
= 0x08;
154 modesel
->density
= density
;
155 modesel
->block_length_med
= (blocklength
>> 8) & 0xff;
156 modesel
->block_length_lo
= blocklength
& 0xff;
158 cgc
.buflen
= sizeof(*modesel
);
159 cgc
.data_direction
= DMA_TO_DEVICE
;
160 cgc
.timeout
= VENDOR_TIMEOUT
;
161 if (0 == (rc
= sr_do_ioctl(cd
, &cgc
))) {
162 cd
->device
->sector_size
= blocklength
;
166 sr_printk(KERN_INFO
, cd
,
167 "switching blocklength to %d bytes failed\n",
174 /* This function gets called after a media change. Checks if the CD is
175 multisession, asks for offset etc. */
177 int sr_cd_check(struct cdrom_device_info
*cdi
)
179 Scsi_CD
*cd
= cdi
->handle
;
180 unsigned long sector
;
181 unsigned char *buffer
; /* the buffer for the ioctl */
182 struct packet_command cgc
;
185 if (cd
->cdi
.mask
& CDC_MULTI_SESSION
)
188 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
192 sector
= 0; /* the multisession sector offset goes here */
193 no_multi
= 0; /* flag: the drive can't handle multisession */
196 memset(&cgc
, 0, sizeof(struct packet_command
));
198 switch (cd
->vendor
) {
201 cgc
.cmd
[0] = READ_TOC
;
207 cgc
.data_direction
= DMA_FROM_DEVICE
;
208 cgc
.timeout
= VENDOR_TIMEOUT
;
209 rc
= sr_do_ioctl(cd
, &cgc
);
212 if ((buffer
[0] << 8) + buffer
[1] < 0x0a) {
213 sr_printk(KERN_INFO
, cd
, "Hmm, seems the drive "
214 "doesn't support multisession CD's\n");
218 sector
= buffer
[11] + (buffer
[10] << 8) +
219 (buffer
[9] << 16) + (buffer
[8] << 24);
220 if (buffer
[6] <= 1) {
221 /* ignore sector offsets from first track */
226 #ifdef CONFIG_BLK_DEV_SR_VENDOR
228 unsigned long min
, sec
, frame
;
235 cgc
.data_direction
= DMA_FROM_DEVICE
;
236 cgc
.timeout
= VENDOR_TIMEOUT
;
237 rc
= sr_do_ioctl(cd
, &cgc
);
240 if (buffer
[14] != 0 && buffer
[14] != 0xb0) {
241 sr_printk(KERN_INFO
, cd
, "Hmm, seems the cdrom "
242 "doesn't support multisession CD's\n");
247 min
= bcd2bin(buffer
[15]);
248 sec
= bcd2bin(buffer
[16]);
249 frame
= bcd2bin(buffer
[17]);
250 sector
= min
* CD_SECS
* CD_FRAMES
+ sec
* CD_FRAMES
+ frame
;
254 case VENDOR_TOSHIBA
:{
255 unsigned long min
, sec
, frame
;
257 /* we request some disc information (is it a XA-CD ?,
258 * where starts the last session ?) */
264 cgc
.data_direction
= DMA_FROM_DEVICE
;
265 cgc
.timeout
= VENDOR_TIMEOUT
;
266 rc
= sr_do_ioctl(cd
, &cgc
);
268 sr_printk(KERN_INFO
, cd
, "Hmm, seems the drive "
269 "doesn't support multisession CD's\n");
275 min
= bcd2bin(buffer
[1]);
276 sec
= bcd2bin(buffer
[2]);
277 frame
= bcd2bin(buffer
[3]);
278 sector
= min
* CD_SECS
* CD_FRAMES
+ sec
* CD_FRAMES
+ frame
;
280 sector
-= CD_MSF_OFFSET
;
281 sr_set_blocklength(cd
, 2048);
286 cgc
.cmd
[0] = READ_TOC
;
292 cgc
.data_direction
= DMA_FROM_DEVICE
;
293 cgc
.timeout
= VENDOR_TIMEOUT
;
294 rc
= sr_do_ioctl(cd
, &cgc
);
298 if ((rc
= buffer
[2]) == 0) {
299 sr_printk(KERN_WARNING
, cd
,
300 "No finished session\n");
303 cgc
.cmd
[0] = READ_TOC
; /* Read TOC */
304 cgc
.cmd
[6] = rc
& 0x7f; /* number of last session */
310 cgc
.data_direction
= DMA_FROM_DEVICE
;
311 cgc
.timeout
= VENDOR_TIMEOUT
;
312 rc
= sr_do_ioctl(cd
, &cgc
);
316 sector
= buffer
[11] + (buffer
[10] << 8) +
317 (buffer
[9] << 16) + (buffer
[8] << 24);
319 #endif /* CONFIG_BLK_DEV_SR_VENDOR */
322 /* should not happen */
323 sr_printk(KERN_WARNING
, cd
,
324 "unknown vendor code (%i), not initialized ?\n",
330 cd
->ms_offset
= sector
;
332 if (CDS_AUDIO
!= sr_disk_status(cdi
) && 1 == sr_is_xa(cd
))
335 if (2048 != cd
->device
->sector_size
) {
336 sr_set_blocklength(cd
, 2048);
339 cdi
->mask
|= CDC_MULTI_SESSION
;
343 sr_printk(KERN_DEBUG
, cd
, "multisession offset=%lu\n",