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 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;
100 } else if (!strncmp(vendor, "Beurer", 6) &&
101 !strncmp(model, "Gluco Memory", 12)) {
102 /* The Beurer GL50 evo uses a Cygnal-manufactured CD-on-a-chip
103 that only accepts a subset of SCSI commands. Most of the
104 not-implemented commands are fine to fail, but a few,
105 particularly around the MMC or Audio commands, will put the
106 device into an unrecoverable state, so they need to be
107 avoided at all costs.
109 cd->vendor = VENDOR_CYGNAL_85ED;
112 CDC_CLOSE_TRAY | CDC_OPEN_TRAY |
121 /* small handy function for switching block length using MODE SELECT,
122 * used by sr_read_sector() */
124 int sr_set_blocklength(Scsi_CD *cd, int blocklength)
126 unsigned char *buffer; /* the buffer for the ioctl */
127 struct packet_command cgc;
128 struct ccs_modesel_head *modesel;
131 if (cd->vendor == VENDOR_TOSHIBA)
132 density = (blocklength > 2048) ? 0x81 : 0x83;
134 buffer = kmalloc(512, GFP_KERNEL);
139 sr_printk(KERN_INFO, cd, "MODE SELECT 0x%x/%d\n", density, blocklength);
141 memset(&cgc, 0, sizeof(struct packet_command));
142 cgc.cmd[0] = MODE_SELECT;
143 cgc.cmd[1] = (1 << 4);
145 modesel = (struct ccs_modesel_head *) buffer;
146 memset(modesel, 0, sizeof(*modesel));
147 modesel->block_desc_length = 0x08;
148 modesel->density = density;
149 modesel->block_length_med = (blocklength >> 8) & 0xff;
150 modesel->block_length_lo = blocklength & 0xff;
152 cgc.buflen = sizeof(*modesel);
153 cgc.data_direction = DMA_TO_DEVICE;
154 cgc.timeout = VENDOR_TIMEOUT;
155 if (0 == (rc = sr_do_ioctl(cd, &cgc))) {
156 cd->device->sector_size = blocklength;
160 sr_printk(KERN_INFO, cd,
161 "switching blocklength to %d bytes failed\n",
168 /* This function gets called after a media change. Checks if the CD is
169 multisession, asks for offset etc. */
171 int sr_cd_check(struct cdrom_device_info *cdi)
173 Scsi_CD *cd = cdi->handle;
174 unsigned long sector;
175 unsigned char *buffer; /* the buffer for the ioctl */
176 struct packet_command cgc;
179 if (cd->cdi.mask & CDC_MULTI_SESSION)
182 buffer = kmalloc(512, GFP_KERNEL);
186 sector = 0; /* the multisession sector offset goes here */
187 no_multi = 0; /* flag: the drive can't handle multisession */
190 memset(&cgc, 0, sizeof(struct packet_command));
192 switch (cd->vendor) {
195 cgc.cmd[0] = READ_TOC;
201 cgc.data_direction = DMA_FROM_DEVICE;
202 cgc.timeout = VENDOR_TIMEOUT;
203 rc = sr_do_ioctl(cd, &cgc);
206 if ((buffer[0] << 8) + buffer[1] < 0x0a) {
207 sr_printk(KERN_INFO, cd, "Hmm, seems the drive "
208 "doesn't support multisession CD's\n");
212 sector = buffer[11] + (buffer[10] << 8) +
213 (buffer[9] << 16) + (buffer[8] << 24);
214 if (buffer[6] <= 1) {
215 /* ignore sector offsets from first track */
221 unsigned long min, sec, frame;
228 cgc.data_direction = DMA_FROM_DEVICE;
229 cgc.timeout = VENDOR_TIMEOUT;
230 rc = sr_do_ioctl(cd, &cgc);
233 if (buffer[14] != 0 && buffer[14] != 0xb0) {
234 sr_printk(KERN_INFO, cd, "Hmm, seems the cdrom "
235 "doesn't support multisession CD's\n");
240 min = bcd2bin(buffer[15]);
241 sec = bcd2bin(buffer[16]);
242 frame = bcd2bin(buffer[17]);
243 sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
247 case VENDOR_TOSHIBA:{
248 unsigned long min, sec, frame;
250 /* we request some disc information (is it a XA-CD ?,
251 * where starts the last session ?) */
257 cgc.data_direction = DMA_FROM_DEVICE;
258 cgc.timeout = VENDOR_TIMEOUT;
259 rc = sr_do_ioctl(cd, &cgc);
261 sr_printk(KERN_INFO, cd, "Hmm, seems the drive "
262 "doesn't support multisession CD's\n");
268 min = bcd2bin(buffer[1]);
269 sec = bcd2bin(buffer[2]);
270 frame = bcd2bin(buffer[3]);
271 sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
273 sector -= CD_MSF_OFFSET;
274 sr_set_blocklength(cd, 2048);
279 cgc.cmd[0] = READ_TOC;
285 cgc.data_direction = DMA_FROM_DEVICE;
286 cgc.timeout = VENDOR_TIMEOUT;
287 rc = sr_do_ioctl(cd, &cgc);
291 if ((rc = buffer[2]) == 0) {
292 sr_printk(KERN_WARNING, cd,
293 "No finished session\n");
296 cgc.cmd[0] = READ_TOC; /* Read TOC */
297 cgc.cmd[6] = rc & 0x7f; /* number of last session */
303 cgc.data_direction = DMA_FROM_DEVICE;
304 cgc.timeout = VENDOR_TIMEOUT;
305 rc = sr_do_ioctl(cd, &cgc);
309 sector = buffer[11] + (buffer[10] << 8) +
310 (buffer[9] << 16) + (buffer[8] << 24);
314 /* should not happen */
315 sr_printk(KERN_WARNING, cd,
316 "unknown vendor code (%i), not initialized ?\n",
322 cd->ms_offset = sector;
324 if (CDS_AUDIO != sr_disk_status(cdi) && 1 == sr_is_xa(cd))
327 if (2048 != cd->device->sector_size) {
328 sr_set_blocklength(cd, 2048);
331 cdi->mask |= CDC_MULTI_SESSION;
335 sr_printk(KERN_DEBUG, cd, "multisession offset=%lu\n",