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/config.h>
38 #include <linux/errno.h>
39 #include <linux/string.h>
40 #include <linux/bcd.h>
42 #include <linux/blkdev.h>
45 #include <scsi/scsi_ioctl.h>
47 #include <linux/cdrom.h>
54 /* here are some constants to sort the vendors into groups */
56 #define VENDOR_SCSI3 1 /* default: scsi-3 mmc */
59 #define VENDOR_TOSHIBA 3
60 #define VENDOR_WRITER 4 /* pre-scsi3 writers */
62 #define VENDOR_TIMEOUT 30*HZ
64 void sr_vendor_init(Scsi_CD *cd)
66 #ifndef CONFIG_BLK_DEV_SR_VENDOR
67 cd->vendor = VENDOR_SCSI3;
69 char *vendor = cd->device->vendor;
70 char *model = cd->device->model;
73 cd->vendor = VENDOR_SCSI3;
75 /* this is true for scsi3/mmc drives - no more checks */
78 if (cd->device->type == TYPE_WORM) {
79 cd->vendor = VENDOR_WRITER;
81 } else if (!strncmp(vendor, "NEC", 3)) {
82 cd->vendor = VENDOR_NEC;
83 if (!strncmp(model, "CD-ROM DRIVE:25", 15) ||
84 !strncmp(model, "CD-ROM DRIVE:36", 15) ||
85 !strncmp(model, "CD-ROM DRIVE:83", 15) ||
86 !strncmp(model, "CD-ROM DRIVE:84 ", 16)
88 /* my NEC 3x returns the read-raw data if a read-raw
89 is followed by a read for the same sector - aeb */
90 || !strncmp(model, "CD-ROM DRIVE:500", 16)
93 /* these can't handle multisession, may hang */
94 cd->cdi.mask |= CDC_MULTI_SESSION;
96 } else if (!strncmp(vendor, "TOSHIBA", 7)) {
97 cd->vendor = VENDOR_TOSHIBA;
104 /* small handy function for switching block length using MODE SELECT,
105 * used by sr_read_sector() */
107 int sr_set_blocklength(Scsi_CD *cd, int blocklength)
109 unsigned char *buffer; /* the buffer for the ioctl */
110 struct cdrom_generic_command cgc;
111 struct ccs_modesel_head *modesel;
114 #ifdef CONFIG_BLK_DEV_SR_VENDOR
115 if (cd->vendor == VENDOR_TOSHIBA)
116 density = (blocklength > 2048) ? 0x81 : 0x83;
119 buffer = (unsigned char *) kmalloc(512, GFP_KERNEL | GFP_DMA);
124 printk("%s: MODE SELECT 0x%x/%d\n", cd->cdi.name, density, blocklength);
126 memset(&cgc, 0, sizeof(struct cdrom_generic_command));
127 cgc.cmd[0] = MODE_SELECT;
128 cgc.cmd[1] = (1 << 4);
130 modesel = (struct ccs_modesel_head *) buffer;
131 memset(modesel, 0, sizeof(*modesel));
132 modesel->block_desc_length = 0x08;
133 modesel->density = density;
134 modesel->block_length_med = (blocklength >> 8) & 0xff;
135 modesel->block_length_lo = blocklength & 0xff;
137 cgc.buflen = sizeof(*modesel);
138 cgc.data_direction = SCSI_DATA_WRITE;
139 cgc.timeout = VENDOR_TIMEOUT;
140 if (0 == (rc = sr_do_ioctl(cd, &cgc))) {
141 cd->device->sector_size = blocklength;
145 printk("%s: switching blocklength to %d bytes failed\n",
146 cd->cdi.name, blocklength);
152 /* This function gets called after a media change. Checks if the CD is
153 multisession, asks for offset etc. */
155 int sr_cd_check(struct cdrom_device_info *cdi)
157 Scsi_CD *cd = cdi->handle;
158 unsigned long sector;
159 unsigned char *buffer; /* the buffer for the ioctl */
160 struct cdrom_generic_command cgc;
163 if (cd->cdi.mask & CDC_MULTI_SESSION)
166 buffer = (unsigned char *) kmalloc(512, GFP_KERNEL | GFP_DMA);
170 sector = 0; /* the multisession sector offset goes here */
171 no_multi = 0; /* flag: the drive can't handle multisession */
174 memset(&cgc, 0, sizeof(struct cdrom_generic_command));
176 switch (cd->vendor) {
179 cgc.cmd[0] = READ_TOC;
185 cgc.data_direction = SCSI_DATA_READ;
186 cgc.timeout = VENDOR_TIMEOUT;
187 rc = sr_do_ioctl(cd, &cgc);
190 if ((buffer[0] << 8) + buffer[1] < 0x0a) {
191 printk(KERN_INFO "%s: Hmm, seems the drive "
192 "doesn't support multisession CD's\n", cd->cdi.name);
196 sector = buffer[11] + (buffer[10] << 8) +
197 (buffer[9] << 16) + (buffer[8] << 24);
198 if (buffer[6] <= 1) {
199 /* ignore sector offsets from first track */
204 #ifdef CONFIG_BLK_DEV_SR_VENDOR
206 unsigned long min, sec, frame;
213 cgc.data_direction = SCSI_DATA_READ;
214 cgc.timeout = VENDOR_TIMEOUT;
215 rc = sr_do_ioctl(cd, &cgc);
218 if (buffer[14] != 0 && buffer[14] != 0xb0) {
219 printk(KERN_INFO "%s: Hmm, seems the cdrom "
220 "doesn't support multisession CD's\n",
225 min = BCD2BIN(buffer[15]);
226 sec = BCD2BIN(buffer[16]);
227 frame = BCD2BIN(buffer[17]);
228 sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
232 case VENDOR_TOSHIBA:{
233 unsigned long min, sec, frame;
235 /* we request some disc information (is it a XA-CD ?,
236 * where starts the last session ?) */
242 cgc.data_direction = SCSI_DATA_READ;
243 cgc.timeout = VENDOR_TIMEOUT;
244 rc = sr_do_ioctl(cd, &cgc);
246 printk(KERN_INFO "%s: Hmm, seems the drive "
247 "doesn't support multisession CD's\n",
254 min = BCD2BIN(buffer[1]);
255 sec = BCD2BIN(buffer[2]);
256 frame = BCD2BIN(buffer[3]);
257 sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
259 sector -= CD_MSF_OFFSET;
260 sr_set_blocklength(cd, 2048);
265 cgc.cmd[0] = READ_TOC;
271 cgc.data_direction = SCSI_DATA_READ;
272 cgc.timeout = VENDOR_TIMEOUT;
273 rc = sr_do_ioctl(cd, &cgc);
277 if ((rc = buffer[2]) == 0) {
279 "%s: No finished session\n", cd->cdi.name);
282 cgc.cmd[0] = READ_TOC; /* Read TOC */
283 cgc.cmd[6] = rc & 0x7f; /* number of last session */
289 cgc.data_direction = SCSI_DATA_READ;
290 cgc.timeout = VENDOR_TIMEOUT;
291 rc = sr_do_ioctl(cd, &cgc);
295 sector = buffer[11] + (buffer[10] << 8) +
296 (buffer[9] << 16) + (buffer[8] << 24);
298 #endif /* CONFIG_BLK_DEV_SR_VENDOR */
301 /* should not happen */
303 "%s: unknown vendor code (%i), not initialized ?\n",
304 cd->cdi.name, cd->vendor);
309 cd->ms_offset = sector;
311 if (CDS_AUDIO != sr_disk_status(cdi) && 1 == sr_is_xa(cd))
314 if (2048 != cd->device->sector_size) {
315 sr_set_blocklength(cd, 2048);
318 cdi->mask |= CDC_MULTI_SESSION;
322 printk(KERN_DEBUG "%s: multisession offset=%lu\n",
323 cd->cdi.name, sector);