2 * linux/drivers/ide/ide_cd.h
4 * Copyright (C) 1996-98 Erik Andersen
5 * Copyright (C) 1998-2000 Jens Axboe
10 #include <linux/cdrom.h>
11 #include <asm/byteorder.h>
13 /* Turn this on to have the driver print out the meanings of the
14 ATAPI error codes. This will use up additional kernel-space
17 #ifndef VERBOSE_IDE_CD_ERRORS
18 #define VERBOSE_IDE_CD_ERRORS 1
22 /* Turning this on will remove code to work around various nonstandard
23 ATAPI implementations. If you know your drive follows the standard,
24 this will give you a slightly smaller kernel. */
26 #ifndef STANDARD_ATAPI
27 #define STANDARD_ATAPI 0
31 /* Turning this on will disable the door-locking functionality.
32 This is apparently needed for supermount. */
34 #ifndef NO_DOOR_LOCKING
35 #define NO_DOOR_LOCKING 0
39 * typical timeout for packet command
41 #define ATAPI_WAIT_PC (60 * HZ)
42 #define ATAPI_WAIT_WRITE_BUSY (10 * HZ)
44 /************************************************************************/
48 #define SECTOR_SIZE (1 << SECTOR_BITS)
50 #define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS)
51 #define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32)
53 /* Configuration flags. These describe the capabilities of the drive.
54 They generally do not change after initialization, unless we learn
55 more about the drive from stuff failing. */
56 struct ide_cd_config_flags {
57 __u8 drq_interrupt : 1; /* Device sends an interrupt when ready
58 for a packet command. */
59 __u8 no_doorlock : 1; /* Drive cannot lock the door. */
60 __u8 no_eject : 1; /* Drive cannot eject the disc. */
61 __u8 nec260 : 1; /* Drive is a pre-1.2 NEC 260 drive. */
62 __u8 tocaddr_as_bcd : 1; /* TOC addresses are in BCD. */
63 __u8 toctracks_as_bcd : 1; /* TOC track numbers are in BCD. */
64 __u8 limit_nframes : 1; /* Drive does not provide data in
65 multiples of SECTOR_SIZE when more
66 than one interrupt is needed. */
67 __u8 seeking : 1; /* Seeking in progress */
68 __u8 no_speed_select : 1; /* SET_CD_SPEED command is unsupported. */
69 byte max_speed; /* Max speed of the drive */
71 #define CDROM_CONFIG_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->config_flags))
74 /* State flags. These give information about the current state of the
75 drive, and will change during normal operation. */
76 struct ide_cd_state_flags {
77 __u8 media_changed : 1; /* Driver has noticed a media change. */
78 __u8 toc_valid : 1; /* Saved TOC information is current. */
79 __u8 door_locked : 1; /* We think that the drive door is locked. */
80 __u8 writing : 1; /* the drive is currently writing */
82 byte current_speed; /* Current speed of the drive */
85 #define CDROM_STATE_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->state_flags))
87 /* Structure of a MSF cdrom address. */
95 /* Space to hold the disk TOC. */
97 struct atapi_toc_header {
98 unsigned short toc_length;
103 struct atapi_toc_entry {
105 #if defined(__BIG_ENDIAN_BITFIELD)
108 #elif defined(__LITTLE_ENDIAN_BITFIELD)
112 #error "Please fix <asm/byteorder.h>"
118 struct atapi_msf msf;
123 int last_session_lba;
125 unsigned long capacity;
126 struct atapi_toc_header hdr;
127 struct atapi_toc_entry ent[MAX_TRACKS+1];
128 /* One extra for the leadout. */
131 /* This should probably go into cdrom.h along with the other
132 * generic stuff now in the Mt. Fuji spec.
134 struct atapi_capabilities_page {
135 struct mode_page_header header;
136 #if defined(__BIG_ENDIAN_BITFIELD)
137 __u8 parameters_saveable : 1;
140 #elif defined(__LITTLE_ENDIAN_BITFIELD)
143 __u8 parameters_saveable : 1;
145 #error "Please fix <asm/byteorder.h>"
150 #if defined(__BIG_ENDIAN_BITFIELD)
152 /* Drive supports reading of DVD-RAM discs */
153 __u8 dvd_ram_read : 1;
154 /* Drive supports reading of DVD-R discs */
156 /* Drive supports reading of DVD-ROM discs */
158 /* Drive supports reading CD-R discs with addressing method 2 */
159 __u8 method2 : 1; /* reserved in 1.2 */
160 /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */
161 __u8 cd_rw_read : 1; /* reserved in 1.2 */
162 /* Drive supports read from CD-R discs (orange book, part II) */
163 __u8 cd_r_read : 1; /* reserved in 1.2 */
164 #elif defined(__LITTLE_ENDIAN_BITFIELD)
165 /* Drive supports read from CD-R discs (orange book, part II) */
166 __u8 cd_r_read : 1; /* reserved in 1.2 */
167 /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */
168 __u8 cd_rw_read : 1; /* reserved in 1.2 */
169 /* Drive supports reading CD-R discs with addressing method 2 */
171 /* Drive supports reading of DVD-ROM discs */
173 /* Drive supports reading of DVD-R discs */
175 /* Drive supports reading of DVD-RAM discs */
176 __u8 dvd_ram_read : 1;
179 #error "Please fix <asm/byteorder.h>"
182 #if defined(__BIG_ENDIAN_BITFIELD)
184 /* Drive can write DVD-RAM discs */
185 __u8 dvd_ram_write : 1;
186 /* Drive can write DVD-R discs */
187 __u8 dvd_r_write : 1;
189 /* Drive can fake writes */
191 /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */
192 __u8 cd_rw_write : 1; /* reserved in 1.2 */
193 /* Drive supports write to CD-R discs (orange book, part II) */
194 __u8 cd_r_write : 1; /* reserved in 1.2 */
195 #elif defined(__LITTLE_ENDIAN_BITFIELD)
196 /* Drive can write to CD-R discs (orange book, part II) */
197 __u8 cd_r_write : 1; /* reserved in 1.2 */
198 /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */
199 __u8 cd_rw_write : 1; /* reserved in 1.2 */
200 /* Drive can fake writes */
203 /* Drive can write DVD-R discs */
204 __u8 dvd_r_write : 1;
205 /* Drive can write DVD-RAM discs */
206 __u8 dvd_ram_write : 1;
209 #error "Please fix <asm/byteorder.h>"
212 #if defined(__BIG_ENDIAN_BITFIELD)
214 /* Drive can read multisession discs. */
215 __u8 multisession : 1;
216 /* Drive can read mode 2, form 2 data. */
217 __u8 mode2_form2 : 1;
218 /* Drive can read mode 2, form 1 (XA) data. */
219 __u8 mode2_form1 : 1;
220 /* Drive supports digital output on port 2. */
222 /* Drive supports digital output on port 1. */
224 /* Drive can deliver a composite audio/video data stream. */
226 /* Drive supports audio play operations. */
228 #elif defined(__LITTLE_ENDIAN_BITFIELD)
229 /* Drive supports audio play operations. */
231 /* Drive can deliver a composite audio/video data stream. */
233 /* Drive supports digital output on port 1. */
235 /* Drive supports digital output on port 2. */
237 /* Drive can read mode 2, form 1 (XA) data. */
238 __u8 mode2_form1 : 1;
239 /* Drive can read mode 2, form 2 data. */
240 __u8 mode2_form2 : 1;
241 /* Drive can read multisession discs. */
242 __u8 multisession : 1;
245 #error "Please fix <asm/byteorder.h>"
248 #if defined(__BIG_ENDIAN_BITFIELD)
250 /* Drive can return Media Catalog Number (UPC) info. */
252 /* Drive can return International Standard Recording Code info. */
254 /* Drive supports C2 error pointers. */
255 __u8 c2_pointers : 1;
256 /* R-W data will be returned deinterleaved and error corrected. */
258 /* Subchannel reads can return combined R-W information. */
259 __u8 rw_supported : 1;
260 /* Drive can continue a read cdda operation from a loss of streaming.*/
261 __u8 cdda_accurate : 1;
262 /* Drive can read Red Book audio data. */
264 #elif defined(__LITTLE_ENDIAN_BITFIELD)
265 /* Drive can read Red Book audio data. */
267 /* Drive can continue a read cdda operation from a loss of streaming.*/
268 __u8 cdda_accurate : 1;
269 /* Subchannel reads can return combined R-W information. */
270 __u8 rw_supported : 1;
271 /* R-W data will be returned deinterleaved and error corrected. */
273 /* Drive supports C2 error pointers. */
274 __u8 c2_pointers : 1;
275 /* Drive can return International Standard Recording Code info. */
277 /* Drive can return Media Catalog Number (UPC) info. */
281 #error "Please fix <asm/byteorder.h>"
284 #if defined(__BIG_ENDIAN_BITFIELD)
285 /* Drive mechanism types. */
286 mechtype_t mechtype : 3;
288 /* Drive can eject a disc or changer cartridge. */
290 /* State of prevent/allow jumper. */
291 __u8 prevent_jumper : 1;
292 /* Present state of door lock. */
294 /* Drive can lock the door. */
296 #elif defined(__LITTLE_ENDIAN_BITFIELD)
298 /* Drive can lock the door. */
300 /* Present state of door lock. */
302 /* State of prevent/allow jumper. */
303 __u8 prevent_jumper : 1;
304 /* Drive can eject a disc or changer cartridge. */
307 /* Drive mechanism types. */
308 mechtype_t mechtype : 3;
310 #error "Please fix <asm/byteorder.h>"
313 #if defined(__BIG_ENDIAN_BITFIELD)
315 /* Drive supports software slot selection. */
316 __u8 sss : 1; /* reserved in 1.2 */
317 /* Changer can report exact contents of slots. */
318 __u8 disc_present : 1; /* reserved in 1.2 */
319 /* Audio for each channel can be muted independently. */
320 __u8 separate_mute : 1;
321 /* Audio level for each channel can be controlled independently. */
322 __u8 separate_volume : 1;
323 #elif defined(__LITTLE_ENDIAN_BITFIELD)
325 /* Audio level for each channel can be controlled independently. */
326 __u8 separate_volume : 1;
327 /* Audio for each channel can be muted independently. */
328 __u8 separate_mute : 1;
329 /* Changer can report exact contents of slots. */
330 __u8 disc_present : 1; /* reserved in 1.2 */
331 /* Drive supports software slot selection. */
332 __u8 sss : 1; /* reserved in 1.2 */
335 #error "Please fix <asm/byteorder.h>"
338 /* Note: the following four fields are returned in big-endian form. */
339 /* Maximum speed (in kB/s). */
340 unsigned short maxspeed;
341 /* Number of discrete volume levels. */
342 unsigned short n_vol_levels;
343 /* Size of cache in drive, in kB. */
344 unsigned short buffer_size;
345 /* Current speed (in kB/s). */
346 unsigned short curspeed;
350 /* Extra per-device info for cdrom drives. */
353 ide_driver_t *driver;
354 struct gendisk *disk;
357 /* Buffer for table of contents. NULL if we haven't allocated
358 a TOC buffer for this device yet. */
360 struct atapi_toc *toc;
362 unsigned long sector_buffered;
363 unsigned long nsectors_buffered;
364 unsigned char *buffer;
366 /* The result of the last successful request sense command
368 struct request_sense sense_data;
370 struct request request_sense_request;
372 unsigned long last_block;
373 unsigned long start_seek;
375 struct ide_cd_config_flags config_flags;
376 struct ide_cd_state_flags state_flags;
378 /* Per-device info needed by cdrom.c generic driver. */
379 struct cdrom_device_info devinfo;
381 unsigned long write_timeout;
384 /****************************************************************************
385 * Descriptions of ATAPI error codes.
388 /* This stuff should be in cdrom.h, since it is now generic... */
390 /* ATAPI sense keys (from table 140 of ATAPI 2.6) */
391 #define NO_SENSE 0x00
392 #define RECOVERED_ERROR 0x01
393 #define NOT_READY 0x02
394 #define MEDIUM_ERROR 0x03
395 #define HARDWARE_ERROR 0x04
396 #define ILLEGAL_REQUEST 0x05
397 #define UNIT_ATTENTION 0x06
398 #define DATA_PROTECT 0x07
399 #define BLANK_CHECK 0x08
400 #define ABORTED_COMMAND 0x0b
401 #define MISCOMPARE 0x0e
405 /* This stuff should be in cdrom.h, since it is now generic... */
406 #if VERBOSE_IDE_CD_ERRORS
408 /* The generic packet command opcodes for CD/DVD Logical Units,
409 * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
410 static const struct {
411 unsigned short packet_command;
412 const char * const text;
413 } packet_command_texts[] = {
414 { GPCMD_TEST_UNIT_READY, "Test Unit Ready" },
415 { GPCMD_REQUEST_SENSE, "Request Sense" },
416 { GPCMD_FORMAT_UNIT, "Format Unit" },
417 { GPCMD_INQUIRY, "Inquiry" },
418 { GPCMD_START_STOP_UNIT, "Start/Stop Unit" },
419 { GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, "Prevent/Allow Medium Removal" },
420 { GPCMD_READ_FORMAT_CAPACITIES, "Read Format Capacities" },
421 { GPCMD_READ_CDVD_CAPACITY, "Read Cd/Dvd Capacity" },
422 { GPCMD_READ_10, "Read 10" },
423 { GPCMD_WRITE_10, "Write 10" },
424 { GPCMD_SEEK, "Seek" },
425 { GPCMD_WRITE_AND_VERIFY_10, "Write and Verify 10" },
426 { GPCMD_VERIFY_10, "Verify 10" },
427 { GPCMD_FLUSH_CACHE, "Flush Cache" },
428 { GPCMD_READ_SUBCHANNEL, "Read Subchannel" },
429 { GPCMD_READ_TOC_PMA_ATIP, "Read Table of Contents" },
430 { GPCMD_READ_HEADER, "Read Header" },
431 { GPCMD_PLAY_AUDIO_10, "Play Audio 10" },
432 { GPCMD_GET_CONFIGURATION, "Get Configuration" },
433 { GPCMD_PLAY_AUDIO_MSF, "Play Audio MSF" },
434 { GPCMD_PLAYAUDIO_TI, "Play Audio TrackIndex" },
435 { GPCMD_GET_EVENT_STATUS_NOTIFICATION, "Get Event Status Notification" },
436 { GPCMD_PAUSE_RESUME, "Pause/Resume" },
437 { GPCMD_STOP_PLAY_SCAN, "Stop Play/Scan" },
438 { GPCMD_READ_DISC_INFO, "Read Disc Info" },
439 { GPCMD_READ_TRACK_RZONE_INFO, "Read Track Rzone Info" },
440 { GPCMD_RESERVE_RZONE_TRACK, "Reserve Rzone Track" },
441 { GPCMD_SEND_OPC, "Send OPC" },
442 { GPCMD_MODE_SELECT_10, "Mode Select 10" },
443 { GPCMD_REPAIR_RZONE_TRACK, "Repair Rzone Track" },
444 { GPCMD_MODE_SENSE_10, "Mode Sense 10" },
445 { GPCMD_CLOSE_TRACK, "Close Track" },
446 { GPCMD_BLANK, "Blank" },
447 { GPCMD_SEND_EVENT, "Send Event" },
448 { GPCMD_SEND_KEY, "Send Key" },
449 { GPCMD_REPORT_KEY, "Report Key" },
450 { GPCMD_LOAD_UNLOAD, "Load/Unload" },
451 { GPCMD_SET_READ_AHEAD, "Set Read-ahead" },
452 { GPCMD_READ_12, "Read 12" },
453 { GPCMD_GET_PERFORMANCE, "Get Performance" },
454 { GPCMD_SEND_DVD_STRUCTURE, "Send DVD Structure" },
455 { GPCMD_READ_DVD_STRUCTURE, "Read DVD Structure" },
456 { GPCMD_SET_STREAMING, "Set Streaming" },
457 { GPCMD_READ_CD_MSF, "Read CD MSF" },
458 { GPCMD_SCAN, "Scan" },
459 { GPCMD_SET_SPEED, "Set Speed" },
460 { GPCMD_PLAY_CD, "Play CD" },
461 { GPCMD_MECHANISM_STATUS, "Mechanism Status" },
462 { GPCMD_READ_CD, "Read CD" },
467 /* From Table 303 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
468 static const char * const sense_key_texts[16] = {
487 /* From Table 304 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
488 static const struct {
489 unsigned long asc_ascq;
490 const char * const text;
491 } sense_data_texts[] = {
492 { 0x000000, "No additional sense information" },
493 { 0x000011, "Play operation in progress" },
494 { 0x000012, "Play operation paused" },
495 { 0x000013, "Play operation successfully completed" },
496 { 0x000014, "Play operation stopped due to error" },
497 { 0x000015, "No current audio status to return" },
498 { 0x010c0a, "Write error - padding blocks added" },
499 { 0x011700, "Recovered data with no error correction applied" },
500 { 0x011701, "Recovered data with retries" },
501 { 0x011702, "Recovered data with positive head offset" },
502 { 0x011703, "Recovered data with negative head offset" },
503 { 0x011704, "Recovered data with retries and/or CIRC applied" },
504 { 0x011705, "Recovered data using previous sector ID" },
505 { 0x011800, "Recovered data with error correction applied" },
506 { 0x011801, "Recovered data with error correction and retries applied"},
507 { 0x011802, "Recovered data - the data was auto-reallocated" },
508 { 0x011803, "Recovered data with CIRC" },
509 { 0x011804, "Recovered data with L-EC" },
511 "Failure prediction threshold exceeded - Predicted logical unit failure" },
513 "Failure prediction threshold exceeded - Predicted media failure" },
514 { 0x015dff, "Failure prediction threshold exceeded - False" },
515 { 0x017301, "Power calibration area almost full" },
516 { 0x020400, "Logical unit not ready - cause not reportable" },
517 /* Following is misspelled in ATAPI 2.6, _and_ in Mt. Fuji */
519 "Logical unit not ready - in progress [sic] of becoming ready" },
520 { 0x020402, "Logical unit not ready - initializing command required" },
521 { 0x020403, "Logical unit not ready - manual intervention required" },
522 { 0x020404, "Logical unit not ready - format in progress" },
523 { 0x020407, "Logical unit not ready - operation in progress" },
524 { 0x020408, "Logical unit not ready - long write in progress" },
525 { 0x020600, "No reference position found (media may be upside down)" },
526 { 0x023000, "Incompatible medium installed" },
527 { 0x023a00, "Medium not present" },
528 { 0x025300, "Media load or eject failed" },
529 { 0x025700, "Unable to recover table of contents" },
530 { 0x030300, "Peripheral device write fault" },
531 { 0x030301, "No write current" },
532 { 0x030302, "Excessive write errors" },
533 { 0x030c00, "Write error" },
534 { 0x030c01, "Write error - Recovered with auto reallocation" },
535 { 0x030c02, "Write error - auto reallocation failed" },
536 { 0x030c03, "Write error - recommend reassignment" },
537 { 0x030c04, "Compression check miscompare error" },
538 { 0x030c05, "Data expansion occurred during compress" },
539 { 0x030c06, "Block not compressible" },
540 { 0x030c07, "Write error - recovery needed" },
541 { 0x030c08, "Write error - recovery failed" },
542 { 0x030c09, "Write error - loss of streaming" },
543 { 0x031100, "Unrecovered read error" },
544 { 0x031106, "CIRC unrecovered error" },
545 { 0x033101, "Format command failed" },
546 { 0x033200, "No defect spare location available" },
547 { 0x033201, "Defect list update failure" },
548 { 0x035100, "Erase failure" },
549 { 0x037200, "Session fixation error" },
550 { 0x037201, "Session fixation error writin lead-in" },
551 { 0x037202, "Session fixation error writin lead-out" },
552 { 0x037300, "CD control error" },
553 { 0x037302, "Power calibration area is full" },
554 { 0x037303, "Power calibration area error" },
555 { 0x037304, "Program memory area / RMA update failure" },
556 { 0x037305, "Program memory area / RMA is full" },
557 { 0x037306, "Program memory area / RMA is (almost) full" },
559 { 0x040200, "No seek complete" },
560 { 0x040300, "Write fault" },
561 { 0x040900, "Track following error" },
562 { 0x040901, "Tracking servo failure" },
563 { 0x040902, "Focus servo failure" },
564 { 0x040903, "Spindle servo failure" },
565 { 0x041500, "Random positioning error" },
566 { 0x041501, "Mechanical positioning or changer error" },
567 { 0x041502, "Positioning error detected by read of medium" },
568 { 0x043c00, "Mechanical positioning or changer error" },
569 { 0x044000, "Diagnostic failure on component (ASCQ)" },
570 { 0x044400, "Internal CD/DVD logical unit failure" },
571 { 0x04b600, "Media load mechanism failed" },
572 { 0x051a00, "Parameter list length error" },
573 { 0x052000, "Invalid command operation code" },
574 { 0x052100, "Logical block address out of range" },
575 { 0x052102, "Invalid address for write" },
576 { 0x052400, "Invalid field in command packet" },
577 { 0x052600, "Invalid field in parameter list" },
578 { 0x052601, "Parameter not supported" },
579 { 0x052602, "Parameter value invalid" },
580 { 0x052700, "Write protected media" },
581 { 0x052c00, "Command sequence error" },
582 { 0x052c03, "Current program area is not empty" },
583 { 0x052c04, "Current program area is empty" },
584 { 0x053001, "Cannot read medium - unknown format" },
585 { 0x053002, "Cannot read medium - incompatible format" },
586 { 0x053900, "Saving parameters not supported" },
587 { 0x054e00, "Overlapped commands attempted" },
588 { 0x055302, "Medium removal prevented" },
589 { 0x055500, "System resource failure" },
590 { 0x056300, "End of user area encountered on this track" },
591 { 0x056400, "Illegal mode for this track or incompatible medium" },
592 { 0x056f00, "Copy protection key exchange failure - Authentication failure" },
593 { 0x056f01, "Copy protection key exchange failure - Key not present" },
594 { 0x056f02, "Copy protection key exchange failure - Key not established" },
595 { 0x056f03, "Read of scrambled sector without authentication" },
596 { 0x056f04, "Media region code is mismatched to logical unit" },
597 { 0x056f05, "Drive region must be permanent / region reset count error" },
598 { 0x057203, "Session fixation error - incomplete track in session" },
599 { 0x057204, "Empty or partially written reserved track" },
600 { 0x057205, "No more RZONE reservations are allowed" },
601 { 0x05bf00, "Loss of streaming" },
602 { 0x062800, "Not ready to ready transition, medium may have changed" },
603 { 0x062900, "Power on, reset or hardware reset occurred" },
604 { 0x062a00, "Parameters changed" },
605 { 0x062a01, "Mode parameters changed" },
606 { 0x062e00, "Insufficient time for operation" },
607 { 0x063f00, "Logical unit operating conditions have changed" },
608 { 0x063f01, "Microcode has been changed" },
609 { 0x065a00, "Operator request or state change input (unspecified)" },
610 { 0x065a01, "Operator medium removal request" },
611 { 0x0bb900, "Play operation aborted" },
613 /* Here we use 0xff for the key (not a valid key) to signify
614 * that these can have _any_ key value associated with them... */
615 { 0xff0401, "Logical unit is in process of becoming ready" },
616 { 0xff0400, "Logical unit not ready, cause not reportable" },
617 { 0xff0402, "Logical unit not ready, initializing command required" },
618 { 0xff0403, "Logical unit not ready, manual intervention required" },
619 { 0xff0500, "Logical unit does not respond to selection" },
620 { 0xff0800, "Logical unit communication failure" },
621 { 0xff0802, "Logical unit communication parity error" },
622 { 0xff0801, "Logical unit communication time-out" },
623 { 0xff2500, "Logical unit not supported" },
624 { 0xff4c00, "Logical unit failed self-configuration" },
625 { 0xff3e00, "Logical unit has not self-configured yet" },
630 #endif /* _IDE_CD_H */