Line data Source code
1 : /* -*-linux-c-*-
2 :
3 : * vendor-specific code for SCSI CD-ROM's goes here.
4 : *
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).
8 : *
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).
11 : *
12 : * Rearranged stuff here: SCSI-3 is included allways, support
13 : * for NEC/TOSHIBA/HP commands is optional.
14 : *
15 : * Gerd Knorr <kraxel@cs.tu-berlin.de>
16 : *
17 : * --------------------------------------------------------------------------
18 : *
19 : * support for XA/multisession-CD's
20 : *
21 : * - NEC: Detection and support of multisession CD's.
22 : *
23 : * - TOSHIBA: Detection and support of multisession CD's.
24 : * Some XA-Sector tweaking, required for older drives.
25 : *
26 : * - SONY: Detection and support of multisession CD's.
27 : * added by Thomas Quinot <thomas@cuivre.freenix.fr>
28 : *
29 : * - PIONEER, HITACHI, PLEXTOR, MATSHITA, TEAC, PHILIPS: known to
30 : * work with SONY (SCSI3 now) code.
31 : *
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.
35 : */
36 :
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>
42 :
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>
48 :
49 : #include "sr.h"
50 :
51 : #if 0
52 : #define DEBUG
53 : #endif
54 :
55 : /* here are some constants to sort the vendors into groups */
56 :
57 : #define VENDOR_SCSI3 1 /* default: scsi-3 mmc */
58 :
59 : #define VENDOR_NEC 2
60 : #define VENDOR_TOSHIBA 3
61 : #define VENDOR_WRITER 4 /* pre-scsi3 writers */
62 :
63 : #define VENDOR_TIMEOUT 30*HZ
64 :
65 : void sr_vendor_init(Scsi_CD *cd)
66 : {
67 1 : #ifndef CONFIG_BLK_DEV_SR_VENDOR
68 1 : cd->vendor = VENDOR_SCSI3;
69 1 : #else
70 2 : const char *vendor = cd->device->vendor;
71 2 : const char *model = cd->device->model;
72 1 :
73 1 : /* default */
74 2 : cd->vendor = VENDOR_SCSI3;
75 2 : if (cd->readcd_known)
76 : /* this is true for scsi3/mmc drives - no more checks */
77 1 : return;
78 :
79 3 : if (cd->device->type == TYPE_WORM) {
80 1 : cd->vendor = VENDOR_WRITER;
81 :
82 3 : } else if (!strncmp(vendor, "NEC", 3)) {
83 1 : cd->vendor = VENDOR_NEC;
84 12 : 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)
88 : #if 0
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)
92 : #endif
93 : )
94 : /* these can't handle multisession, may hang */
95 4 : cd->cdi.mask |= CDC_MULTI_SESSION;
96 :
97 3 : } else if (!strncmp(vendor, "TOSHIBA", 7)) {
98 1 : cd->vendor = VENDOR_TOSHIBA;
99 1 :
100 : }
101 : #endif
102 : }
103 :
104 :
105 : /* small handy function for switching block length using MODE SELECT,
106 : * used by sr_read_sector() */
107 :
108 : int sr_set_blocklength(Scsi_CD *cd, int blocklength)
109 : {
110 6 : unsigned char *buffer; /* the buffer for the ioctl */
111 6 : struct packet_command cgc;
112 6 : struct ccs_modesel_head *modesel;
113 12 : int rc, density = 0;
114 6 :
115 6 : #ifdef CONFIG_BLK_DEV_SR_VENDOR
116 12 : if (cd->vendor == VENDOR_TOSHIBA)
117 36 : density = (blocklength > 2048) ? 0x81 : 0x83;
118 : #endif
119 :
120 18 : buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
121 12 : if (!buffer)
122 6 : return -ENOMEM;
123 :
124 : #ifdef DEBUG
125 : printk("%s: MODE SELECT 0x%x/%d\n", cd->cdi.name, density, blocklength);
126 : #endif
127 6 : memset(&cgc, 0, sizeof(struct packet_command));
128 6 : cgc.cmd[0] = MODE_SELECT;
129 6 : cgc.cmd[1] = (1 << 4);
130 6 : cgc.cmd[4] = 12;
131 6 : modesel = (struct ccs_modesel_head *) buffer;
132 6 : memset(modesel, 0, sizeof(*modesel));
133 6 : modesel->block_desc_length = 0x08;
134 6 : modesel->density = density;
135 6 : modesel->block_length_med = (blocklength >> 8) & 0xff;
136 6 : modesel->block_length_lo = blocklength & 0xff;
137 6 : cgc.buffer = buffer;
138 6 : cgc.buflen = sizeof(*modesel);
139 6 : cgc.data_direction = DMA_TO_DEVICE;
140 6 : cgc.timeout = VENDOR_TIMEOUT;
141 30 : if (0 == (rc = sr_do_ioctl(cd, &cgc))) {
142 6 : cd->device->sector_size = blocklength;
143 : }
144 : #ifdef DEBUG
145 : else
146 : printk("%s: switching blocklength to %d bytes failed\n",
147 : cd->cdi.name, blocklength);
148 : #endif
149 6 : kfree(buffer);
150 6 : return rc;
151 : }
152 :
153 : /* This function gets called after a media change. Checks if the CD is
154 : multisession, asks for offset etc. */
155 :
156 : int sr_cd_check(struct cdrom_device_info *cdi)
157 : {
158 3 : Scsi_CD *cd = cdi->handle;
159 1 : unsigned long sector;
160 1 : unsigned char *buffer; /* the buffer for the ioctl */
161 1 : struct packet_command cgc;
162 1 : int rc, no_multi;
163 1 :
164 3 : if (cd->cdi.mask & CDC_MULTI_SESSION)
165 2 : return 0;
166 1 :
167 4 : buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
168 3 : if (!buffer)
169 2 : return -ENOMEM;
170 1 :
171 2 : sector = 0; /* the multisession sector offset goes here */
172 2 : no_multi = 0; /* flag: the drive can't handle multisession */
173 2 : rc = 0;
174 1 :
175 2 : memset(&cgc, 0, sizeof(struct packet_command));
176 1 :
177 1 : switch (cd->vendor) {
178 1 :
179 3 : case VENDOR_SCSI3:
180 1 : cgc.cmd[0] = READ_TOC;
181 1 : cgc.cmd[8] = 12;
182 1 : cgc.cmd[9] = 0x40;
183 1 : cgc.buffer = buffer;
184 1 : cgc.buflen = 12;
185 1 : cgc.quiet = 1;
186 1 : cgc.data_direction = DMA_FROM_DEVICE;
187 1 : cgc.timeout = VENDOR_TIMEOUT;
188 3 : rc = sr_do_ioctl(cd, &cgc);
189 2 : if (rc != 0)
190 1 : break;
191 2 : if ((buffer[0] << 8) + buffer[1] < 0x0a) {
192 1 : printk(KERN_INFO "%s: Hmm, seems the drive "
193 : "doesn't support multisession CD's\n", cd->cdi.name);
194 1 : no_multi = 1;
195 1 : break;
196 : }
197 1 : sector = buffer[11] + (buffer[10] << 8) +
198 : (buffer[9] << 16) + (buffer[8] << 24);
199 2 : if (buffer[6] <= 1) {
200 : /* ignore sector offsets from first track */
201 1 : sector = 0;
202 : }
203 1 : break;
204 1 :
205 : #ifdef CONFIG_BLK_DEV_SR_VENDOR
206 3 : case VENDOR_NEC:{
207 : unsigned long min, sec, frame;
208 1 : cgc.cmd[0] = 0xde;
209 1 : cgc.cmd[1] = 0x03;
210 1 : cgc.cmd[2] = 0xb0;
211 1 : cgc.buffer = buffer;
212 1 : cgc.buflen = 0x16;
213 1 : cgc.quiet = 1;
214 1 : cgc.data_direction = DMA_FROM_DEVICE;
215 1 : cgc.timeout = VENDOR_TIMEOUT;
216 3 : rc = sr_do_ioctl(cd, &cgc);
217 2 : if (rc != 0)
218 1 : break;
219 4 : if (buffer[14] != 0 && buffer[14] != 0xb0) {
220 1 : printk(KERN_INFO "%s: Hmm, seems the cdrom "
221 : "doesn't support multisession CD's\n",
222 : cd->cdi.name);
223 1 : no_multi = 1;
224 1 : break;
225 : }
226 2 : min = bcd2bin(buffer[15]);
227 2 : sec = bcd2bin(buffer[16]);
228 2 : frame = bcd2bin(buffer[17]);
229 1 : sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
230 1 : break;
231 1 : }
232 :
233 3 : case VENDOR_TOSHIBA:{
234 : unsigned long min, sec, frame;
235 :
236 : /* we request some disc information (is it a XA-CD ?,
237 : * where starts the last session ?) */
238 1 : cgc.cmd[0] = 0xc7;
239 1 : cgc.cmd[1] = 0x03;
240 1 : cgc.buffer = buffer;
241 1 : cgc.buflen = 4;
242 1 : cgc.quiet = 1;
243 1 : cgc.data_direction = DMA_FROM_DEVICE;
244 1 : cgc.timeout = VENDOR_TIMEOUT;
245 3 : rc = sr_do_ioctl(cd, &cgc);
246 2 : if (rc == -EINVAL) {
247 1 : printk(KERN_INFO "%s: Hmm, seems the drive "
248 : "doesn't support multisession CD's\n",
249 : cd->cdi.name);
250 1 : no_multi = 1;
251 1 : break;
252 : }
253 2 : if (rc != 0)
254 1 : break;
255 2 : min = bcd2bin(buffer[1]);
256 2 : sec = bcd2bin(buffer[2]);
257 2 : frame = bcd2bin(buffer[3]);
258 1 : sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
259 2 : if (sector)
260 1 : sector -= CD_MSF_OFFSET;
261 3 : sr_set_blocklength(cd, 2048);
262 1 : break;
263 1 : }
264 :
265 3 : case VENDOR_WRITER:
266 1 : cgc.cmd[0] = READ_TOC;
267 1 : cgc.cmd[8] = 0x04;
268 1 : cgc.cmd[9] = 0x40;
269 1 : cgc.buffer = buffer;
270 1 : cgc.buflen = 0x04;
271 1 : cgc.quiet = 1;
272 1 : cgc.data_direction = DMA_FROM_DEVICE;
273 1 : cgc.timeout = VENDOR_TIMEOUT;
274 3 : rc = sr_do_ioctl(cd, &cgc);
275 2 : if (rc != 0) {
276 1 : break;
277 : }
278 3 : if ((rc = buffer[2]) == 0) {
279 1 : printk(KERN_WARNING
280 : "%s: No finished session\n", cd->cdi.name);
281 1 : break;
282 : }
283 1 : cgc.cmd[0] = READ_TOC; /* Read TOC */
284 1 : cgc.cmd[6] = rc & 0x7f; /* number of last session */
285 1 : cgc.cmd[8] = 0x0c;
286 1 : cgc.cmd[9] = 0x40;
287 1 : cgc.buffer = buffer;
288 1 : cgc.buflen = 12;
289 1 : cgc.quiet = 1;
290 1 : cgc.data_direction = DMA_FROM_DEVICE;
291 1 : cgc.timeout = VENDOR_TIMEOUT;
292 3 : rc = sr_do_ioctl(cd, &cgc);
293 2 : if (rc != 0) {
294 1 : break;
295 : }
296 1 : sector = buffer[11] + (buffer[10] << 8) +
297 : (buffer[9] << 16) + (buffer[8] << 24);
298 1 : break;
299 1 : #endif /* CONFIG_BLK_DEV_SR_VENDOR */
300 :
301 1 : default:
302 1 : /* should not happen */
303 1 : printk(KERN_WARNING
304 : "%s: unknown vendor code (%i), not initialized ?\n",
305 : cd->cdi.name, cd->vendor);
306 1 : sector = 0;
307 1 : no_multi = 1;
308 1 : break;
309 : }
310 7 : cd->ms_offset = sector;
311 7 : cd->xa_flag = 0;
312 36 : if (CDS_AUDIO != sr_disk_status(cdi) && 1 == sr_is_xa(cd))
313 1 : cd->xa_flag = 1;
314 :
315 4 : if (2048 != cd->device->sector_size) {
316 6 : sr_set_blocklength(cd, 2048);
317 : }
318 6 : if (no_multi)
319 3 : cdi->mask |= CDC_MULTI_SESSION;
320 :
321 : #ifdef DEBUG
322 : if (sector)
323 : printk(KERN_DEBUG "%s: multisession offset=%lu\n",
324 : cd->cdi.name, sector);
325 : #endif
326 3 : kfree(buffer);
327 3 : return rc;
328 : }
|