1 |
1275 |
phoenix |
#include <linux/kernel.h>
|
2 |
|
|
#include <linux/sched.h>
|
3 |
|
|
#include <linux/mm.h>
|
4 |
|
|
#include <linux/fs.h>
|
5 |
|
|
#include <asm/uaccess.h>
|
6 |
|
|
#include <linux/errno.h>
|
7 |
|
|
#include <linux/string.h>
|
8 |
|
|
|
9 |
|
|
#include <linux/blk.h>
|
10 |
|
|
#include <linux/blkpg.h>
|
11 |
|
|
#include "scsi.h"
|
12 |
|
|
#include "hosts.h"
|
13 |
|
|
#include <scsi/scsi_ioctl.h>
|
14 |
|
|
|
15 |
|
|
#include <linux/cdrom.h>
|
16 |
|
|
#include "sr.h"
|
17 |
|
|
|
18 |
|
|
#if 0
|
19 |
|
|
#define DEBUG
|
20 |
|
|
#endif
|
21 |
|
|
|
22 |
|
|
/* The sr_is_xa() seems to trigger firmware bugs with some drives :-(
|
23 |
|
|
* It is off by default and can be turned on with this module parameter */
|
24 |
|
|
static int xa_test = 0;
|
25 |
|
|
|
26 |
|
|
extern void get_sectorsize(int);
|
27 |
|
|
|
28 |
|
|
#define IOCTL_RETRIES 3
|
29 |
|
|
/* The CDROM is fairly slow, so we need a little extra time */
|
30 |
|
|
/* In fact, it is very slow if it has to spin up first */
|
31 |
|
|
#define IOCTL_TIMEOUT 30*HZ
|
32 |
|
|
|
33 |
|
|
/* ATAPI drives don't have a SCMD_PLAYAUDIO_TI command. When these drives
|
34 |
|
|
are emulating a SCSI device via the idescsi module, they need to have
|
35 |
|
|
CDROMPLAYTRKIND commands translated into CDROMPLAYMSF commands for them */
|
36 |
|
|
|
37 |
|
|
static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti)
|
38 |
|
|
{
|
39 |
|
|
struct cdrom_tocentry trk0_te, trk1_te;
|
40 |
|
|
struct cdrom_tochdr tochdr;
|
41 |
|
|
u_char sr_cmd[10];
|
42 |
|
|
int ntracks, ret;
|
43 |
|
|
|
44 |
|
|
if ((ret = sr_audio_ioctl(cdi, CDROMREADTOCHDR, &tochdr)))
|
45 |
|
|
return ret;
|
46 |
|
|
|
47 |
|
|
ntracks = tochdr.cdth_trk1 - tochdr.cdth_trk0 + 1;
|
48 |
|
|
|
49 |
|
|
if (ti->cdti_trk1 == ntracks)
|
50 |
|
|
ti->cdti_trk1 = CDROM_LEADOUT;
|
51 |
|
|
else if (ti->cdti_trk1 != CDROM_LEADOUT)
|
52 |
|
|
ti->cdti_trk1 ++;
|
53 |
|
|
|
54 |
|
|
trk0_te.cdte_track = ti->cdti_trk0;
|
55 |
|
|
trk0_te.cdte_format = CDROM_MSF;
|
56 |
|
|
trk1_te.cdte_track = ti->cdti_trk1;
|
57 |
|
|
trk1_te.cdte_format = CDROM_MSF;
|
58 |
|
|
|
59 |
|
|
if ((ret = sr_audio_ioctl(cdi, CDROMREADTOCENTRY, &trk0_te)))
|
60 |
|
|
return ret;
|
61 |
|
|
if ((ret = sr_audio_ioctl(cdi, CDROMREADTOCENTRY, &trk1_te)))
|
62 |
|
|
return ret;
|
63 |
|
|
|
64 |
|
|
sr_cmd[0] = GPCMD_PLAY_AUDIO_MSF;
|
65 |
|
|
sr_cmd[3] = trk0_te.cdte_addr.msf.minute;
|
66 |
|
|
sr_cmd[4] = trk0_te.cdte_addr.msf.second;
|
67 |
|
|
sr_cmd[5] = trk0_te.cdte_addr.msf.frame;
|
68 |
|
|
sr_cmd[6] = trk1_te.cdte_addr.msf.minute;
|
69 |
|
|
sr_cmd[7] = trk1_te.cdte_addr.msf.second;
|
70 |
|
|
sr_cmd[8] = trk1_te.cdte_addr.msf.frame;
|
71 |
|
|
return sr_do_ioctl(MINOR(cdi->dev), sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
/* We do our own retries because we want to know what the specific
|
75 |
|
|
error code is. Normally the UNIT_ATTENTION code will automatically
|
76 |
|
|
clear after one error */
|
77 |
|
|
|
78 |
|
|
int sr_do_ioctl(int target, unsigned char *sr_cmd, void *buffer, unsigned buflength, int quiet, int readwrite, struct request_sense *sense)
|
79 |
|
|
{
|
80 |
|
|
Scsi_Request *SRpnt;
|
81 |
|
|
Scsi_Device *SDev;
|
82 |
|
|
struct request *req;
|
83 |
|
|
int result, err = 0, retries = 0;
|
84 |
|
|
char *bounce_buffer;
|
85 |
|
|
|
86 |
|
|
SDev = scsi_CDs[target].device;
|
87 |
|
|
SRpnt = scsi_allocate_request(scsi_CDs[target].device);
|
88 |
|
|
if (!SRpnt) {
|
89 |
|
|
printk("Unable to allocate SCSI request in sr_do_ioctl");
|
90 |
|
|
return -ENOMEM;
|
91 |
|
|
}
|
92 |
|
|
SRpnt->sr_data_direction = readwrite;
|
93 |
|
|
|
94 |
|
|
/* use ISA DMA buffer if necessary */
|
95 |
|
|
SRpnt->sr_request.buffer = buffer;
|
96 |
|
|
if (buffer && SRpnt->sr_host->unchecked_isa_dma &&
|
97 |
|
|
(virt_to_phys(buffer) + buflength - 1 > ISA_DMA_THRESHOLD)) {
|
98 |
|
|
bounce_buffer = (char *) scsi_malloc((buflength + 511) & ~511);
|
99 |
|
|
if (bounce_buffer == NULL) {
|
100 |
|
|
printk("SCSI DMA pool exhausted.");
|
101 |
|
|
return -ENOMEM;
|
102 |
|
|
}
|
103 |
|
|
memcpy(bounce_buffer, (char *) buffer, buflength);
|
104 |
|
|
buffer = bounce_buffer;
|
105 |
|
|
}
|
106 |
|
|
retry:
|
107 |
|
|
if (!scsi_block_when_processing_errors(SDev))
|
108 |
|
|
return -ENODEV;
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
scsi_wait_req(SRpnt, (void *) sr_cmd, (void *) buffer, buflength,
|
112 |
|
|
IOCTL_TIMEOUT, IOCTL_RETRIES);
|
113 |
|
|
|
114 |
|
|
req = &SRpnt->sr_request;
|
115 |
|
|
if (SRpnt->sr_buffer && req->buffer && SRpnt->sr_buffer != req->buffer) {
|
116 |
|
|
memcpy(req->buffer, SRpnt->sr_buffer, SRpnt->sr_bufflen);
|
117 |
|
|
scsi_free(SRpnt->sr_buffer, (SRpnt->sr_bufflen + 511) & ~511);
|
118 |
|
|
SRpnt->sr_buffer = req->buffer;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
result = SRpnt->sr_result;
|
122 |
|
|
|
123 |
|
|
/* Minimal error checking. Ignore cases we know about, and report the rest. */
|
124 |
|
|
if (driver_byte(result) != 0) {
|
125 |
|
|
switch (SRpnt->sr_sense_buffer[2] & 0xf) {
|
126 |
|
|
case UNIT_ATTENTION:
|
127 |
|
|
scsi_CDs[target].device->changed = 1;
|
128 |
|
|
if (!quiet)
|
129 |
|
|
printk(KERN_INFO "sr%d: disc change detected.\n", target);
|
130 |
|
|
if (retries++ < 10)
|
131 |
|
|
goto retry;
|
132 |
|
|
err = -ENOMEDIUM;
|
133 |
|
|
break;
|
134 |
|
|
case NOT_READY: /* This happens if there is no disc in drive */
|
135 |
|
|
if (SRpnt->sr_sense_buffer[12] == 0x04 &&
|
136 |
|
|
SRpnt->sr_sense_buffer[13] == 0x01) {
|
137 |
|
|
/* sense: Logical unit is in process of becoming ready */
|
138 |
|
|
if (!quiet)
|
139 |
|
|
printk(KERN_INFO "sr%d: CDROM not ready yet.\n", target);
|
140 |
|
|
if (retries++ < 10) {
|
141 |
|
|
/* sleep 2 sec and try again */
|
142 |
|
|
scsi_sleep(2 * HZ);
|
143 |
|
|
goto retry;
|
144 |
|
|
} else {
|
145 |
|
|
/* 20 secs are enough? */
|
146 |
|
|
err = -ENOMEDIUM;
|
147 |
|
|
break;
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
if (!quiet)
|
151 |
|
|
printk(KERN_INFO "sr%d: CDROM not ready. Make sure there is a disc in the drive.\n", target);
|
152 |
|
|
#ifdef DEBUG
|
153 |
|
|
print_req_sense("sr", SRpnt);
|
154 |
|
|
#endif
|
155 |
|
|
err = -ENOMEDIUM;
|
156 |
|
|
break;
|
157 |
|
|
case ILLEGAL_REQUEST:
|
158 |
|
|
if (!quiet)
|
159 |
|
|
printk(KERN_ERR "sr%d: CDROM (ioctl) reports ILLEGAL "
|
160 |
|
|
"REQUEST.\n", target);
|
161 |
|
|
err = -EIO;
|
162 |
|
|
if (SRpnt->sr_sense_buffer[12] == 0x20 &&
|
163 |
|
|
SRpnt->sr_sense_buffer[13] == 0x00)
|
164 |
|
|
/* sense: Invalid command operation code */
|
165 |
|
|
err = -EDRIVE_CANT_DO_THIS;
|
166 |
|
|
#ifdef DEBUG
|
167 |
|
|
print_command(sr_cmd);
|
168 |
|
|
print_req_sense("sr", SRpnt);
|
169 |
|
|
#endif
|
170 |
|
|
break;
|
171 |
|
|
default:
|
172 |
|
|
printk(KERN_ERR "sr%d: CDROM (ioctl) error, command: ", target);
|
173 |
|
|
print_command(sr_cmd);
|
174 |
|
|
print_req_sense("sr", SRpnt);
|
175 |
|
|
err = -EIO;
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
if (sense)
|
180 |
|
|
memcpy(sense, SRpnt->sr_sense_buffer, sizeof(*sense));
|
181 |
|
|
|
182 |
|
|
/* Wake up a process waiting for device */
|
183 |
|
|
scsi_release_request(SRpnt);
|
184 |
|
|
SRpnt = NULL;
|
185 |
|
|
return err;
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
/* ---------------------------------------------------------------------- */
|
189 |
|
|
/* interface to cdrom.c */
|
190 |
|
|
|
191 |
|
|
static int test_unit_ready(int minor)
|
192 |
|
|
{
|
193 |
|
|
u_char sr_cmd[10];
|
194 |
|
|
|
195 |
|
|
sr_cmd[0] = GPCMD_TEST_UNIT_READY;
|
196 |
|
|
sr_cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
|
197 |
|
|
((scsi_CDs[minor].device->lun) << 5) : 0;
|
198 |
|
|
sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
|
199 |
|
|
return sr_do_ioctl(minor, sr_cmd, NULL, 0, 1, SCSI_DATA_NONE, NULL);
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
int sr_tray_move(struct cdrom_device_info *cdi, int pos)
|
203 |
|
|
{
|
204 |
|
|
u_char sr_cmd[10];
|
205 |
|
|
|
206 |
|
|
sr_cmd[0] = GPCMD_START_STOP_UNIT;
|
207 |
|
|
sr_cmd[1] = (scsi_CDs[MINOR(cdi->dev)].device->scsi_level <= SCSI_2) ?
|
208 |
|
|
((scsi_CDs[MINOR(cdi->dev)].device->lun) << 5) : 0;
|
209 |
|
|
sr_cmd[2] = sr_cmd[3] = sr_cmd[5] = 0;
|
210 |
|
|
sr_cmd[4] = (pos == 0) ? 0x03 /* close */ : 0x02 /* eject */ ;
|
211 |
|
|
|
212 |
|
|
return sr_do_ioctl(MINOR(cdi->dev), sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
int sr_lock_door(struct cdrom_device_info *cdi, int lock)
|
216 |
|
|
{
|
217 |
|
|
return scsi_ioctl(scsi_CDs[MINOR(cdi->dev)].device,
|
218 |
|
|
lock ? SCSI_IOCTL_DOORLOCK : SCSI_IOCTL_DOORUNLOCK,
|
219 |
|
|
0);
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
int sr_drive_status(struct cdrom_device_info *cdi, int slot)
|
223 |
|
|
{
|
224 |
|
|
if (CDSL_CURRENT != slot) {
|
225 |
|
|
/* we have no changer support */
|
226 |
|
|
return -EINVAL;
|
227 |
|
|
}
|
228 |
|
|
if (0 == test_unit_ready(MINOR(cdi->dev)))
|
229 |
|
|
return CDS_DISC_OK;
|
230 |
|
|
|
231 |
|
|
return CDS_TRAY_OPEN;
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
int sr_disk_status(struct cdrom_device_info *cdi)
|
235 |
|
|
{
|
236 |
|
|
struct cdrom_tochdr toc_h;
|
237 |
|
|
struct cdrom_tocentry toc_e;
|
238 |
|
|
int i, rc, have_datatracks = 0;
|
239 |
|
|
|
240 |
|
|
/* look for data tracks */
|
241 |
|
|
if (0 != (rc = sr_audio_ioctl(cdi, CDROMREADTOCHDR, &toc_h)))
|
242 |
|
|
return (rc == -ENOMEDIUM) ? CDS_NO_DISC : CDS_NO_INFO;
|
243 |
|
|
|
244 |
|
|
for (i = toc_h.cdth_trk0; i <= toc_h.cdth_trk1; i++) {
|
245 |
|
|
toc_e.cdte_track = i;
|
246 |
|
|
toc_e.cdte_format = CDROM_LBA;
|
247 |
|
|
if (sr_audio_ioctl(cdi, CDROMREADTOCENTRY, &toc_e))
|
248 |
|
|
return CDS_NO_INFO;
|
249 |
|
|
if (toc_e.cdte_ctrl & CDROM_DATA_TRACK) {
|
250 |
|
|
have_datatracks = 1;
|
251 |
|
|
break;
|
252 |
|
|
}
|
253 |
|
|
}
|
254 |
|
|
if (!have_datatracks)
|
255 |
|
|
return CDS_AUDIO;
|
256 |
|
|
|
257 |
|
|
if (scsi_CDs[MINOR(cdi->dev)].xa_flag)
|
258 |
|
|
return CDS_XA_2_1;
|
259 |
|
|
else
|
260 |
|
|
return CDS_DATA_1;
|
261 |
|
|
}
|
262 |
|
|
|
263 |
|
|
int sr_get_last_session(struct cdrom_device_info *cdi,
|
264 |
|
|
struct cdrom_multisession *ms_info)
|
265 |
|
|
{
|
266 |
|
|
ms_info->addr.lba = scsi_CDs[MINOR(cdi->dev)].ms_offset;
|
267 |
|
|
ms_info->xa_flag = scsi_CDs[MINOR(cdi->dev)].xa_flag ||
|
268 |
|
|
(scsi_CDs[MINOR(cdi->dev)].ms_offset > 0);
|
269 |
|
|
|
270 |
|
|
return 0;
|
271 |
|
|
}
|
272 |
|
|
|
273 |
|
|
int sr_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
|
274 |
|
|
{
|
275 |
|
|
u_char sr_cmd[10];
|
276 |
|
|
char buffer[32];
|
277 |
|
|
int result;
|
278 |
|
|
|
279 |
|
|
sr_cmd[0] = GPCMD_READ_SUBCHANNEL;
|
280 |
|
|
sr_cmd[1] = (scsi_CDs[MINOR(cdi->dev)].device->scsi_level <= SCSI_2) ?
|
281 |
|
|
((scsi_CDs[MINOR(cdi->dev)].device->lun) << 5) : 0;
|
282 |
|
|
sr_cmd[2] = 0x40; /* I do want the subchannel info */
|
283 |
|
|
sr_cmd[3] = 0x02; /* Give me medium catalog number info */
|
284 |
|
|
sr_cmd[4] = sr_cmd[5] = 0;
|
285 |
|
|
sr_cmd[6] = 0;
|
286 |
|
|
sr_cmd[7] = 0;
|
287 |
|
|
sr_cmd[8] = 24;
|
288 |
|
|
sr_cmd[9] = 0;
|
289 |
|
|
|
290 |
|
|
result = sr_do_ioctl(MINOR(cdi->dev), sr_cmd, buffer, 24, 0, SCSI_DATA_READ, NULL);
|
291 |
|
|
|
292 |
|
|
memcpy(mcn->medium_catalog_number, buffer + 9, 13);
|
293 |
|
|
mcn->medium_catalog_number[13] = 0;
|
294 |
|
|
|
295 |
|
|
return result;
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
int sr_reset(struct cdrom_device_info *cdi)
|
299 |
|
|
{
|
300 |
|
|
invalidate_buffers(cdi->dev);
|
301 |
|
|
return 0;
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
int sr_select_speed(struct cdrom_device_info *cdi, int speed)
|
305 |
|
|
{
|
306 |
|
|
u_char sr_cmd[MAX_COMMAND_SIZE];
|
307 |
|
|
|
308 |
|
|
if (speed == 0)
|
309 |
|
|
speed = 0xffff; /* set to max */
|
310 |
|
|
else
|
311 |
|
|
speed *= 177; /* Nx to kbyte/s */
|
312 |
|
|
|
313 |
|
|
memset(sr_cmd, 0, MAX_COMMAND_SIZE);
|
314 |
|
|
sr_cmd[0] = GPCMD_SET_SPEED; /* SET CD SPEED */
|
315 |
|
|
sr_cmd[1] = (scsi_CDs[MINOR(cdi->dev)].device->scsi_level <= SCSI_2) ?
|
316 |
|
|
((scsi_CDs[MINOR(cdi->dev)].device->lun) << 5) : 0;
|
317 |
|
|
sr_cmd[2] = (speed >> 8) & 0xff; /* MSB for speed (in kbytes/sec) */
|
318 |
|
|
sr_cmd[3] = speed & 0xff; /* LSB */
|
319 |
|
|
|
320 |
|
|
if (sr_do_ioctl(MINOR(cdi->dev), sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL))
|
321 |
|
|
return -EIO;
|
322 |
|
|
return 0;
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
/* ----------------------------------------------------------------------- */
|
326 |
|
|
/* this is called by the generic cdrom driver. arg is a _kernel_ pointer, */
|
327 |
|
|
/* because the generic cdrom driver does the user access stuff for us. */
|
328 |
|
|
/* only cdromreadtochdr and cdromreadtocentry are left - for use with the */
|
329 |
|
|
/* sr_disk_status interface for the generic cdrom driver. */
|
330 |
|
|
|
331 |
|
|
int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void *arg)
|
332 |
|
|
{
|
333 |
|
|
u_char sr_cmd[10];
|
334 |
|
|
int result, target = MINOR(cdi->dev);
|
335 |
|
|
unsigned char buffer[32];
|
336 |
|
|
|
337 |
|
|
memset(sr_cmd, 0, sizeof(sr_cmd));
|
338 |
|
|
|
339 |
|
|
switch (cmd) {
|
340 |
|
|
case CDROMREADTOCHDR:
|
341 |
|
|
{
|
342 |
|
|
struct cdrom_tochdr *tochdr = (struct cdrom_tochdr *) arg;
|
343 |
|
|
|
344 |
|
|
sr_cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
|
345 |
|
|
sr_cmd[1] = (scsi_CDs[target].device->scsi_level <= SCSI_2) ?
|
346 |
|
|
((scsi_CDs[target].device->lun) << 5) : 0;
|
347 |
|
|
sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
|
348 |
|
|
sr_cmd[8] = 12; /* LSB of length */
|
349 |
|
|
|
350 |
|
|
result = sr_do_ioctl(target, sr_cmd, buffer, 12, 1, SCSI_DATA_READ, NULL);
|
351 |
|
|
|
352 |
|
|
tochdr->cdth_trk0 = buffer[2];
|
353 |
|
|
tochdr->cdth_trk1 = buffer[3];
|
354 |
|
|
|
355 |
|
|
break;
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
case CDROMREADTOCENTRY:
|
359 |
|
|
{
|
360 |
|
|
struct cdrom_tocentry *tocentry = (struct cdrom_tocentry *) arg;
|
361 |
|
|
|
362 |
|
|
sr_cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
|
363 |
|
|
sr_cmd[1] = (scsi_CDs[target].device->scsi_level <= SCSI_2) ?
|
364 |
|
|
((scsi_CDs[target].device->lun) << 5) : 0;
|
365 |
|
|
sr_cmd[1] |= (tocentry->cdte_format == CDROM_MSF) ? 0x02 : 0;
|
366 |
|
|
sr_cmd[2] = sr_cmd[3] = sr_cmd[4] = sr_cmd[5] = 0;
|
367 |
|
|
sr_cmd[6] = tocentry->cdte_track;
|
368 |
|
|
sr_cmd[8] = 12; /* LSB of length */
|
369 |
|
|
|
370 |
|
|
result = sr_do_ioctl(target, sr_cmd, buffer, 12, 0, SCSI_DATA_READ, NULL);
|
371 |
|
|
|
372 |
|
|
tocentry->cdte_ctrl = buffer[5] & 0xf;
|
373 |
|
|
tocentry->cdte_adr = buffer[5] >> 4;
|
374 |
|
|
tocentry->cdte_datamode = (tocentry->cdte_ctrl & 0x04) ? 1 : 0;
|
375 |
|
|
if (tocentry->cdte_format == CDROM_MSF) {
|
376 |
|
|
tocentry->cdte_addr.msf.minute = buffer[9];
|
377 |
|
|
tocentry->cdte_addr.msf.second = buffer[10];
|
378 |
|
|
tocentry->cdte_addr.msf.frame = buffer[11];
|
379 |
|
|
} else
|
380 |
|
|
tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
|
381 |
|
|
+ buffer[10]) << 8) + buffer[11];
|
382 |
|
|
|
383 |
|
|
break;
|
384 |
|
|
}
|
385 |
|
|
|
386 |
|
|
case CDROMPLAYTRKIND: {
|
387 |
|
|
struct cdrom_ti* ti = (struct cdrom_ti*)arg;
|
388 |
|
|
|
389 |
|
|
sr_cmd[0] = GPCMD_PLAYAUDIO_TI;
|
390 |
|
|
sr_cmd[1] = (scsi_CDs[target].device->scsi_level <= SCSI_2) ?
|
391 |
|
|
(scsi_CDs[target].device->lun << 5) : 0;
|
392 |
|
|
sr_cmd[4] = ti->cdti_trk0;
|
393 |
|
|
sr_cmd[5] = ti->cdti_ind0;
|
394 |
|
|
sr_cmd[7] = ti->cdti_trk1;
|
395 |
|
|
sr_cmd[8] = ti->cdti_ind1;
|
396 |
|
|
|
397 |
|
|
result = sr_do_ioctl(target, sr_cmd, NULL, 0, 0, SCSI_DATA_NONE, NULL);
|
398 |
|
|
if (result == -EDRIVE_CANT_DO_THIS)
|
399 |
|
|
result = sr_fake_playtrkind(cdi, ti);
|
400 |
|
|
|
401 |
|
|
break;
|
402 |
|
|
}
|
403 |
|
|
|
404 |
|
|
default:
|
405 |
|
|
return -EINVAL;
|
406 |
|
|
}
|
407 |
|
|
|
408 |
|
|
#if 0
|
409 |
|
|
if (result)
|
410 |
|
|
printk("DEBUG: sr_audio: result for ioctl %x: %x\n", cmd, result);
|
411 |
|
|
#endif
|
412 |
|
|
|
413 |
|
|
return result;
|
414 |
|
|
}
|
415 |
|
|
|
416 |
|
|
/* -----------------------------------------------------------------------
|
417 |
|
|
* a function to read all sorts of funny cdrom sectors using the READ_CD
|
418 |
|
|
* scsi-3 mmc command
|
419 |
|
|
*
|
420 |
|
|
* lba: linear block address
|
421 |
|
|
* format: 0 = data (anything)
|
422 |
|
|
* 1 = audio
|
423 |
|
|
* 2 = data (mode 1)
|
424 |
|
|
* 3 = data (mode 2)
|
425 |
|
|
* 4 = data (mode 2 form1)
|
426 |
|
|
* 5 = data (mode 2 form2)
|
427 |
|
|
* blksize: 2048 | 2336 | 2340 | 2352
|
428 |
|
|
*/
|
429 |
|
|
|
430 |
|
|
int sr_read_cd(int minor, unsigned char *dest, int lba, int format, int blksize)
|
431 |
|
|
{
|
432 |
|
|
unsigned char cmd[MAX_COMMAND_SIZE];
|
433 |
|
|
|
434 |
|
|
#ifdef DEBUG
|
435 |
|
|
printk("sr%d: sr_read_cd lba=%d format=%d blksize=%d\n",
|
436 |
|
|
minor, lba, format, blksize);
|
437 |
|
|
#endif
|
438 |
|
|
|
439 |
|
|
memset(cmd, 0, MAX_COMMAND_SIZE);
|
440 |
|
|
cmd[0] = GPCMD_READ_CD; /* READ_CD */
|
441 |
|
|
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
|
442 |
|
|
(scsi_CDs[minor].device->lun << 5) : 0;
|
443 |
|
|
cmd[1] |= ((format & 7) << 2);
|
444 |
|
|
cmd[2] = (unsigned char) (lba >> 24) & 0xff;
|
445 |
|
|
cmd[3] = (unsigned char) (lba >> 16) & 0xff;
|
446 |
|
|
cmd[4] = (unsigned char) (lba >> 8) & 0xff;
|
447 |
|
|
cmd[5] = (unsigned char) lba & 0xff;
|
448 |
|
|
cmd[8] = 1;
|
449 |
|
|
switch (blksize) {
|
450 |
|
|
case 2336:
|
451 |
|
|
cmd[9] = 0x58;
|
452 |
|
|
break;
|
453 |
|
|
case 2340:
|
454 |
|
|
cmd[9] = 0x78;
|
455 |
|
|
break;
|
456 |
|
|
case 2352:
|
457 |
|
|
cmd[9] = 0xf8;
|
458 |
|
|
break;
|
459 |
|
|
default:
|
460 |
|
|
cmd[9] = 0x10;
|
461 |
|
|
break;
|
462 |
|
|
}
|
463 |
|
|
return sr_do_ioctl(minor, cmd, dest, blksize, 0, SCSI_DATA_READ, NULL);
|
464 |
|
|
}
|
465 |
|
|
|
466 |
|
|
/*
|
467 |
|
|
* read sectors with blocksizes other than 2048
|
468 |
|
|
*/
|
469 |
|
|
|
470 |
|
|
int sr_read_sector(int minor, int lba, int blksize, unsigned char *dest)
|
471 |
|
|
{
|
472 |
|
|
unsigned char cmd[MAX_COMMAND_SIZE]; /* the scsi-command */
|
473 |
|
|
int rc;
|
474 |
|
|
|
475 |
|
|
/* we try the READ CD command first... */
|
476 |
|
|
if (scsi_CDs[minor].readcd_known) {
|
477 |
|
|
rc = sr_read_cd(minor, dest, lba, 0, blksize);
|
478 |
|
|
if (-EDRIVE_CANT_DO_THIS != rc)
|
479 |
|
|
return rc;
|
480 |
|
|
scsi_CDs[minor].readcd_known = 0;
|
481 |
|
|
printk("CDROM does'nt support READ CD (0xbe) command\n");
|
482 |
|
|
/* fall & retry the other way */
|
483 |
|
|
}
|
484 |
|
|
/* ... if this fails, we switch the blocksize using MODE SELECT */
|
485 |
|
|
if (blksize != scsi_CDs[minor].device->sector_size) {
|
486 |
|
|
if (0 != (rc = sr_set_blocklength(minor, blksize)))
|
487 |
|
|
return rc;
|
488 |
|
|
}
|
489 |
|
|
#ifdef DEBUG
|
490 |
|
|
printk("sr%d: sr_read_sector lba=%d blksize=%d\n", minor, lba, blksize);
|
491 |
|
|
#endif
|
492 |
|
|
|
493 |
|
|
memset(cmd, 0, MAX_COMMAND_SIZE);
|
494 |
|
|
cmd[0] = GPCMD_READ_10;
|
495 |
|
|
cmd[1] = (scsi_CDs[minor].device->scsi_level <= SCSI_2) ?
|
496 |
|
|
(scsi_CDs[minor].device->lun << 5) : 0;
|
497 |
|
|
cmd[2] = (unsigned char) (lba >> 24) & 0xff;
|
498 |
|
|
cmd[3] = (unsigned char) (lba >> 16) & 0xff;
|
499 |
|
|
cmd[4] = (unsigned char) (lba >> 8) & 0xff;
|
500 |
|
|
cmd[5] = (unsigned char) lba & 0xff;
|
501 |
|
|
cmd[8] = 1;
|
502 |
|
|
rc = sr_do_ioctl(minor, cmd, dest, blksize, 0, SCSI_DATA_READ, NULL);
|
503 |
|
|
|
504 |
|
|
return rc;
|
505 |
|
|
}
|
506 |
|
|
|
507 |
|
|
/*
|
508 |
|
|
* read a sector in raw mode to check the sector format
|
509 |
|
|
* ret: 1 == mode2 (XA), 0 == mode1, <0 == error
|
510 |
|
|
*/
|
511 |
|
|
|
512 |
|
|
int sr_is_xa(int minor)
|
513 |
|
|
{
|
514 |
|
|
unsigned char *raw_sector;
|
515 |
|
|
int is_xa;
|
516 |
|
|
|
517 |
|
|
if (!xa_test)
|
518 |
|
|
return 0;
|
519 |
|
|
|
520 |
|
|
raw_sector = (unsigned char *) scsi_malloc(2048 + 512);
|
521 |
|
|
if (!raw_sector)
|
522 |
|
|
return -ENOMEM;
|
523 |
|
|
if (0 == sr_read_sector(minor, scsi_CDs[minor].ms_offset + 16,
|
524 |
|
|
CD_FRAMESIZE_RAW1, raw_sector)) {
|
525 |
|
|
is_xa = (raw_sector[3] == 0x02) ? 1 : 0;
|
526 |
|
|
} else {
|
527 |
|
|
/* read a raw sector failed for some reason. */
|
528 |
|
|
is_xa = -1;
|
529 |
|
|
}
|
530 |
|
|
scsi_free(raw_sector, 2048 + 512);
|
531 |
|
|
#ifdef DEBUG
|
532 |
|
|
printk("sr%d: sr_is_xa: %d\n", minor, is_xa);
|
533 |
|
|
#endif
|
534 |
|
|
return is_xa;
|
535 |
|
|
}
|
536 |
|
|
|
537 |
|
|
int sr_dev_ioctl(struct cdrom_device_info *cdi,
|
538 |
|
|
unsigned int cmd, unsigned long arg)
|
539 |
|
|
{
|
540 |
|
|
int target;
|
541 |
|
|
|
542 |
|
|
target = MINOR(cdi->dev);
|
543 |
|
|
|
544 |
|
|
switch (cmd) {
|
545 |
|
|
case BLKGETSIZE:
|
546 |
|
|
return put_user(scsi_CDs[target].capacity, (unsigned long *) arg);
|
547 |
|
|
case BLKGETSIZE64:
|
548 |
|
|
return put_user((u64)scsi_CDs[target].capacity << 9, (u64 *)arg);
|
549 |
|
|
case BLKROSET:
|
550 |
|
|
case BLKROGET:
|
551 |
|
|
case BLKRASET:
|
552 |
|
|
case BLKRAGET:
|
553 |
|
|
case BLKFLSBUF:
|
554 |
|
|
case BLKSSZGET:
|
555 |
|
|
return blk_ioctl(cdi->dev, cmd, arg);
|
556 |
|
|
|
557 |
|
|
default:
|
558 |
|
|
return scsi_ioctl(scsi_CDs[target].device, cmd, (void *) arg);
|
559 |
|
|
}
|
560 |
|
|
}
|
561 |
|
|
|
562 |
|
|
/*
|
563 |
|
|
* Overrides for Emacs so that we follow Linus's tabbing style.
|
564 |
|
|
* Emacs will notice this stuff at the end of the file and automatically
|
565 |
|
|
* adjust the settings for this buffer only. This must remain at the end
|
566 |
|
|
* of the file.
|
567 |
|
|
* ---------------------------------------------------------------------------
|
568 |
|
|
* Local variables:
|
569 |
|
|
* c-indent-level: 4
|
570 |
|
|
* c-brace-imaginary-offset: 0
|
571 |
|
|
* c-brace-offset: -4
|
572 |
|
|
* c-argdecl-indent: 4
|
573 |
|
|
* c-label-offset: -4
|
574 |
|
|
* c-continued-statement-offset: 4
|
575 |
|
|
* c-continued-brace-offset: 0
|
576 |
|
|
* indent-tabs-mode: nil
|
577 |
|
|
* tab-width: 8
|
578 |
|
|
* End:
|
579 |
|
|
*/
|