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 */
72 /* State flags. These give information about the current state of the
73 drive, and will change during normal operation. */
74 struct ide_cd_state_flags
{
75 __u8 media_changed
: 1; /* Driver has noticed a media change. */
76 __u8 toc_valid
: 1; /* Saved TOC information is current. */
77 __u8 door_locked
: 1; /* We think that the drive door is locked. */
78 __u8 writing
: 1; /* the drive is currently writing */
80 byte current_speed
; /* Current speed of the drive */
83 /* Structure of a MSF cdrom address. */
91 /* Space to hold the disk TOC. */
93 struct atapi_toc_header
{
94 unsigned short toc_length
;
99 struct atapi_toc_entry
{
101 #if defined(__BIG_ENDIAN_BITFIELD)
104 #elif defined(__LITTLE_ENDIAN_BITFIELD)
108 #error "Please fix <asm/byteorder.h>"
114 struct atapi_msf msf
;
119 int last_session_lba
;
121 unsigned long capacity
;
122 struct atapi_toc_header hdr
;
123 struct atapi_toc_entry ent
[MAX_TRACKS
+1];
124 /* One extra for the leadout. */
127 /* This should probably go into cdrom.h along with the other
128 * generic stuff now in the Mt. Fuji spec.
130 struct atapi_capabilities_page
{
131 struct mode_page_header header
;
132 #if defined(__BIG_ENDIAN_BITFIELD)
133 __u8 parameters_saveable
: 1;
136 #elif defined(__LITTLE_ENDIAN_BITFIELD)
139 __u8 parameters_saveable
: 1;
141 #error "Please fix <asm/byteorder.h>"
146 #if defined(__BIG_ENDIAN_BITFIELD)
148 /* Drive supports reading of DVD-RAM discs */
149 __u8 dvd_ram_read
: 1;
150 /* Drive supports reading of DVD-R discs */
152 /* Drive supports reading of DVD-ROM discs */
154 /* Drive supports reading CD-R discs with addressing method 2 */
155 __u8 method2
: 1; /* reserved in 1.2 */
156 /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */
157 __u8 cd_rw_read
: 1; /* reserved in 1.2 */
158 /* Drive supports read from CD-R discs (orange book, part II) */
159 __u8 cd_r_read
: 1; /* reserved in 1.2 */
160 #elif defined(__LITTLE_ENDIAN_BITFIELD)
161 /* Drive supports read from CD-R discs (orange book, part II) */
162 __u8 cd_r_read
: 1; /* reserved in 1.2 */
163 /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */
164 __u8 cd_rw_read
: 1; /* reserved in 1.2 */
165 /* Drive supports reading CD-R discs with addressing method 2 */
167 /* Drive supports reading of DVD-ROM discs */
169 /* Drive supports reading of DVD-R discs */
171 /* Drive supports reading of DVD-RAM discs */
172 __u8 dvd_ram_read
: 1;
175 #error "Please fix <asm/byteorder.h>"
178 #if defined(__BIG_ENDIAN_BITFIELD)
180 /* Drive can write DVD-RAM discs */
181 __u8 dvd_ram_write
: 1;
182 /* Drive can write DVD-R discs */
183 __u8 dvd_r_write
: 1;
185 /* Drive can fake writes */
187 /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */
188 __u8 cd_rw_write
: 1; /* reserved in 1.2 */
189 /* Drive supports write to CD-R discs (orange book, part II) */
190 __u8 cd_r_write
: 1; /* reserved in 1.2 */
191 #elif defined(__LITTLE_ENDIAN_BITFIELD)
192 /* Drive can write to CD-R discs (orange book, part II) */
193 __u8 cd_r_write
: 1; /* reserved in 1.2 */
194 /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */
195 __u8 cd_rw_write
: 1; /* reserved in 1.2 */
196 /* Drive can fake writes */
199 /* Drive can write DVD-R discs */
200 __u8 dvd_r_write
: 1;
201 /* Drive can write DVD-RAM discs */
202 __u8 dvd_ram_write
: 1;
205 #error "Please fix <asm/byteorder.h>"
208 #if defined(__BIG_ENDIAN_BITFIELD)
210 /* Drive can read multisession discs. */
211 __u8 multisession
: 1;
212 /* Drive can read mode 2, form 2 data. */
213 __u8 mode2_form2
: 1;
214 /* Drive can read mode 2, form 1 (XA) data. */
215 __u8 mode2_form1
: 1;
216 /* Drive supports digital output on port 2. */
218 /* Drive supports digital output on port 1. */
220 /* Drive can deliver a composite audio/video data stream. */
222 /* Drive supports audio play operations. */
224 #elif defined(__LITTLE_ENDIAN_BITFIELD)
225 /* Drive supports audio play operations. */
227 /* Drive can deliver a composite audio/video data stream. */
229 /* Drive supports digital output on port 1. */
231 /* Drive supports digital output on port 2. */
233 /* Drive can read mode 2, form 1 (XA) data. */
234 __u8 mode2_form1
: 1;
235 /* Drive can read mode 2, form 2 data. */
236 __u8 mode2_form2
: 1;
237 /* Drive can read multisession discs. */
238 __u8 multisession
: 1;
241 #error "Please fix <asm/byteorder.h>"
244 #if defined(__BIG_ENDIAN_BITFIELD)
246 /* Drive can return Media Catalog Number (UPC) info. */
248 /* Drive can return International Standard Recording Code info. */
250 /* Drive supports C2 error pointers. */
251 __u8 c2_pointers
: 1;
252 /* R-W data will be returned deinterleaved and error corrected. */
254 /* Subchannel reads can return combined R-W information. */
255 __u8 rw_supported
: 1;
256 /* Drive can continue a read cdda operation from a loss of streaming.*/
257 __u8 cdda_accurate
: 1;
258 /* Drive can read Red Book audio data. */
260 #elif defined(__LITTLE_ENDIAN_BITFIELD)
261 /* Drive can read Red Book audio data. */
263 /* Drive can continue a read cdda operation from a loss of streaming.*/
264 __u8 cdda_accurate
: 1;
265 /* Subchannel reads can return combined R-W information. */
266 __u8 rw_supported
: 1;
267 /* R-W data will be returned deinterleaved and error corrected. */
269 /* Drive supports C2 error pointers. */
270 __u8 c2_pointers
: 1;
271 /* Drive can return International Standard Recording Code info. */
273 /* Drive can return Media Catalog Number (UPC) info. */
277 #error "Please fix <asm/byteorder.h>"
280 #if defined(__BIG_ENDIAN_BITFIELD)
281 /* Drive mechanism types. */
282 mechtype_t mechtype
: 3;
284 /* Drive can eject a disc or changer cartridge. */
286 /* State of prevent/allow jumper. */
287 __u8 prevent_jumper
: 1;
288 /* Present state of door lock. */
290 /* Drive can lock the door. */
292 #elif defined(__LITTLE_ENDIAN_BITFIELD)
294 /* Drive can lock the door. */
296 /* Present state of door lock. */
298 /* State of prevent/allow jumper. */
299 __u8 prevent_jumper
: 1;
300 /* Drive can eject a disc or changer cartridge. */
303 /* Drive mechanism types. */
304 mechtype_t mechtype
: 3;
306 #error "Please fix <asm/byteorder.h>"
309 #if defined(__BIG_ENDIAN_BITFIELD)
311 /* Drive supports software slot selection. */
312 __u8 sss
: 1; /* reserved in 1.2 */
313 /* Changer can report exact contents of slots. */
314 __u8 disc_present
: 1; /* reserved in 1.2 */
315 /* Audio for each channel can be muted independently. */
316 __u8 separate_mute
: 1;
317 /* Audio level for each channel can be controlled independently. */
318 __u8 separate_volume
: 1;
319 #elif defined(__LITTLE_ENDIAN_BITFIELD)
321 /* Audio level for each channel can be controlled independently. */
322 __u8 separate_volume
: 1;
323 /* Audio for each channel can be muted independently. */
324 __u8 separate_mute
: 1;
325 /* Changer can report exact contents of slots. */
326 __u8 disc_present
: 1; /* reserved in 1.2 */
327 /* Drive supports software slot selection. */
328 __u8 sss
: 1; /* reserved in 1.2 */
331 #error "Please fix <asm/byteorder.h>"
334 /* Note: the following four fields are returned in big-endian form. */
335 /* Maximum speed (in kB/s). */
336 unsigned short maxspeed
;
337 /* Number of discrete volume levels. */
338 unsigned short n_vol_levels
;
339 /* Size of cache in drive, in kB. */
340 unsigned short buffer_size
;
341 /* Current speed (in kB/s). */
342 unsigned short curspeed
;
346 /* Extra per-device info for cdrom drives. */
349 ide_driver_t
*driver
;
350 struct gendisk
*disk
;
353 /* Buffer for table of contents. NULL if we haven't allocated
354 a TOC buffer for this device yet. */
356 struct atapi_toc
*toc
;
358 unsigned long sector_buffered
;
359 unsigned long nsectors_buffered
;
360 unsigned char *buffer
;
362 /* The result of the last successful request sense command
364 struct request_sense sense_data
;
366 struct request request_sense_request
;
368 unsigned long last_block
;
369 unsigned long start_seek
;
371 struct ide_cd_config_flags config_flags
;
372 struct ide_cd_state_flags state_flags
;
374 /* Per-device info needed by cdrom.c generic driver. */
375 struct cdrom_device_info devinfo
;
377 unsigned long write_timeout
;
380 /****************************************************************************
381 * Descriptions of ATAPI error codes.
384 /* This stuff should be in cdrom.h, since it is now generic... */
386 /* ATAPI sense keys (from table 140 of ATAPI 2.6) */
387 #define NO_SENSE 0x00
388 #define RECOVERED_ERROR 0x01
389 #define NOT_READY 0x02
390 #define MEDIUM_ERROR 0x03
391 #define HARDWARE_ERROR 0x04
392 #define ILLEGAL_REQUEST 0x05
393 #define UNIT_ATTENTION 0x06
394 #define DATA_PROTECT 0x07
395 #define BLANK_CHECK 0x08
396 #define ABORTED_COMMAND 0x0b
397 #define MISCOMPARE 0x0e
401 /* This stuff should be in cdrom.h, since it is now generic... */
402 #if VERBOSE_IDE_CD_ERRORS
404 /* The generic packet command opcodes for CD/DVD Logical Units,
405 * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
406 static const struct {
407 unsigned short packet_command
;
408 const char * const text
;
409 } packet_command_texts
[] = {
410 { GPCMD_TEST_UNIT_READY
, "Test Unit Ready" },
411 { GPCMD_REQUEST_SENSE
, "Request Sense" },
412 { GPCMD_FORMAT_UNIT
, "Format Unit" },
413 { GPCMD_INQUIRY
, "Inquiry" },
414 { GPCMD_START_STOP_UNIT
, "Start/Stop Unit" },
415 { GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL
, "Prevent/Allow Medium Removal" },
416 { GPCMD_READ_FORMAT_CAPACITIES
, "Read Format Capacities" },
417 { GPCMD_READ_CDVD_CAPACITY
, "Read Cd/Dvd Capacity" },
418 { GPCMD_READ_10
, "Read 10" },
419 { GPCMD_WRITE_10
, "Write 10" },
420 { GPCMD_SEEK
, "Seek" },
421 { GPCMD_WRITE_AND_VERIFY_10
, "Write and Verify 10" },
422 { GPCMD_VERIFY_10
, "Verify 10" },
423 { GPCMD_FLUSH_CACHE
, "Flush Cache" },
424 { GPCMD_READ_SUBCHANNEL
, "Read Subchannel" },
425 { GPCMD_READ_TOC_PMA_ATIP
, "Read Table of Contents" },
426 { GPCMD_READ_HEADER
, "Read Header" },
427 { GPCMD_PLAY_AUDIO_10
, "Play Audio 10" },
428 { GPCMD_GET_CONFIGURATION
, "Get Configuration" },
429 { GPCMD_PLAY_AUDIO_MSF
, "Play Audio MSF" },
430 { GPCMD_PLAYAUDIO_TI
, "Play Audio TrackIndex" },
431 { GPCMD_GET_EVENT_STATUS_NOTIFICATION
, "Get Event Status Notification" },
432 { GPCMD_PAUSE_RESUME
, "Pause/Resume" },
433 { GPCMD_STOP_PLAY_SCAN
, "Stop Play/Scan" },
434 { GPCMD_READ_DISC_INFO
, "Read Disc Info" },
435 { GPCMD_READ_TRACK_RZONE_INFO
, "Read Track Rzone Info" },
436 { GPCMD_RESERVE_RZONE_TRACK
, "Reserve Rzone Track" },
437 { GPCMD_SEND_OPC
, "Send OPC" },
438 { GPCMD_MODE_SELECT_10
, "Mode Select 10" },
439 { GPCMD_REPAIR_RZONE_TRACK
, "Repair Rzone Track" },
440 { GPCMD_MODE_SENSE_10
, "Mode Sense 10" },
441 { GPCMD_CLOSE_TRACK
, "Close Track" },
442 { GPCMD_BLANK
, "Blank" },
443 { GPCMD_SEND_EVENT
, "Send Event" },
444 { GPCMD_SEND_KEY
, "Send Key" },
445 { GPCMD_REPORT_KEY
, "Report Key" },
446 { GPCMD_LOAD_UNLOAD
, "Load/Unload" },
447 { GPCMD_SET_READ_AHEAD
, "Set Read-ahead" },
448 { GPCMD_READ_12
, "Read 12" },
449 { GPCMD_GET_PERFORMANCE
, "Get Performance" },
450 { GPCMD_SEND_DVD_STRUCTURE
, "Send DVD Structure" },
451 { GPCMD_READ_DVD_STRUCTURE
, "Read DVD Structure" },
452 { GPCMD_SET_STREAMING
, "Set Streaming" },
453 { GPCMD_READ_CD_MSF
, "Read CD MSF" },
454 { GPCMD_SCAN
, "Scan" },
455 { GPCMD_SET_SPEED
, "Set Speed" },
456 { GPCMD_PLAY_CD
, "Play CD" },
457 { GPCMD_MECHANISM_STATUS
, "Mechanism Status" },
458 { GPCMD_READ_CD
, "Read CD" },
463 /* From Table 303 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
464 static const char * const sense_key_texts
[16] = {
483 /* From Table 304 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
484 static const struct {
485 unsigned long asc_ascq
;
486 const char * const text
;
487 } sense_data_texts
[] = {
488 { 0x000000, "No additional sense information" },
489 { 0x000011, "Play operation in progress" },
490 { 0x000012, "Play operation paused" },
491 { 0x000013, "Play operation successfully completed" },
492 { 0x000014, "Play operation stopped due to error" },
493 { 0x000015, "No current audio status to return" },
494 { 0x010c0a, "Write error - padding blocks added" },
495 { 0x011700, "Recovered data with no error correction applied" },
496 { 0x011701, "Recovered data with retries" },
497 { 0x011702, "Recovered data with positive head offset" },
498 { 0x011703, "Recovered data with negative head offset" },
499 { 0x011704, "Recovered data with retries and/or CIRC applied" },
500 { 0x011705, "Recovered data using previous sector ID" },
501 { 0x011800, "Recovered data with error correction applied" },
502 { 0x011801, "Recovered data with error correction and retries applied"},
503 { 0x011802, "Recovered data - the data was auto-reallocated" },
504 { 0x011803, "Recovered data with CIRC" },
505 { 0x011804, "Recovered data with L-EC" },
507 "Failure prediction threshold exceeded - Predicted logical unit failure" },
509 "Failure prediction threshold exceeded - Predicted media failure" },
510 { 0x015dff, "Failure prediction threshold exceeded - False" },
511 { 0x017301, "Power calibration area almost full" },
512 { 0x020400, "Logical unit not ready - cause not reportable" },
513 /* Following is misspelled in ATAPI 2.6, _and_ in Mt. Fuji */
515 "Logical unit not ready - in progress [sic] of becoming ready" },
516 { 0x020402, "Logical unit not ready - initializing command required" },
517 { 0x020403, "Logical unit not ready - manual intervention required" },
518 { 0x020404, "Logical unit not ready - format in progress" },
519 { 0x020407, "Logical unit not ready - operation in progress" },
520 { 0x020408, "Logical unit not ready - long write in progress" },
521 { 0x020600, "No reference position found (media may be upside down)" },
522 { 0x023000, "Incompatible medium installed" },
523 { 0x023a00, "Medium not present" },
524 { 0x025300, "Media load or eject failed" },
525 { 0x025700, "Unable to recover table of contents" },
526 { 0x030300, "Peripheral device write fault" },
527 { 0x030301, "No write current" },
528 { 0x030302, "Excessive write errors" },
529 { 0x030c00, "Write error" },
530 { 0x030c01, "Write error - Recovered with auto reallocation" },
531 { 0x030c02, "Write error - auto reallocation failed" },
532 { 0x030c03, "Write error - recommend reassignment" },
533 { 0x030c04, "Compression check miscompare error" },
534 { 0x030c05, "Data expansion occurred during compress" },
535 { 0x030c06, "Block not compressible" },
536 { 0x030c07, "Write error - recovery needed" },
537 { 0x030c08, "Write error - recovery failed" },
538 { 0x030c09, "Write error - loss of streaming" },
539 { 0x031100, "Unrecovered read error" },
540 { 0x031106, "CIRC unrecovered error" },
541 { 0x033101, "Format command failed" },
542 { 0x033200, "No defect spare location available" },
543 { 0x033201, "Defect list update failure" },
544 { 0x035100, "Erase failure" },
545 { 0x037200, "Session fixation error" },
546 { 0x037201, "Session fixation error writin lead-in" },
547 { 0x037202, "Session fixation error writin lead-out" },
548 { 0x037300, "CD control error" },
549 { 0x037302, "Power calibration area is full" },
550 { 0x037303, "Power calibration area error" },
551 { 0x037304, "Program memory area / RMA update failure" },
552 { 0x037305, "Program memory area / RMA is full" },
553 { 0x037306, "Program memory area / RMA is (almost) full" },
555 { 0x040200, "No seek complete" },
556 { 0x040300, "Write fault" },
557 { 0x040900, "Track following error" },
558 { 0x040901, "Tracking servo failure" },
559 { 0x040902, "Focus servo failure" },
560 { 0x040903, "Spindle servo failure" },
561 { 0x041500, "Random positioning error" },
562 { 0x041501, "Mechanical positioning or changer error" },
563 { 0x041502, "Positioning error detected by read of medium" },
564 { 0x043c00, "Mechanical positioning or changer error" },
565 { 0x044000, "Diagnostic failure on component (ASCQ)" },
566 { 0x044400, "Internal CD/DVD logical unit failure" },
567 { 0x04b600, "Media load mechanism failed" },
568 { 0x051a00, "Parameter list length error" },
569 { 0x052000, "Invalid command operation code" },
570 { 0x052100, "Logical block address out of range" },
571 { 0x052102, "Invalid address for write" },
572 { 0x052400, "Invalid field in command packet" },
573 { 0x052600, "Invalid field in parameter list" },
574 { 0x052601, "Parameter not supported" },
575 { 0x052602, "Parameter value invalid" },
576 { 0x052700, "Write protected media" },
577 { 0x052c00, "Command sequence error" },
578 { 0x052c03, "Current program area is not empty" },
579 { 0x052c04, "Current program area is empty" },
580 { 0x053001, "Cannot read medium - unknown format" },
581 { 0x053002, "Cannot read medium - incompatible format" },
582 { 0x053900, "Saving parameters not supported" },
583 { 0x054e00, "Overlapped commands attempted" },
584 { 0x055302, "Medium removal prevented" },
585 { 0x055500, "System resource failure" },
586 { 0x056300, "End of user area encountered on this track" },
587 { 0x056400, "Illegal mode for this track or incompatible medium" },
588 { 0x056f00, "Copy protection key exchange failure - Authentication failure" },
589 { 0x056f01, "Copy protection key exchange failure - Key not present" },
590 { 0x056f02, "Copy protection key exchange failure - Key not established" },
591 { 0x056f03, "Read of scrambled sector without authentication" },
592 { 0x056f04, "Media region code is mismatched to logical unit" },
593 { 0x056f05, "Drive region must be permanent / region reset count error" },
594 { 0x057203, "Session fixation error - incomplete track in session" },
595 { 0x057204, "Empty or partially written reserved track" },
596 { 0x057205, "No more RZONE reservations are allowed" },
597 { 0x05bf00, "Loss of streaming" },
598 { 0x062800, "Not ready to ready transition, medium may have changed" },
599 { 0x062900, "Power on, reset or hardware reset occurred" },
600 { 0x062a00, "Parameters changed" },
601 { 0x062a01, "Mode parameters changed" },
602 { 0x062e00, "Insufficient time for operation" },
603 { 0x063f00, "Logical unit operating conditions have changed" },
604 { 0x063f01, "Microcode has been changed" },
605 { 0x065a00, "Operator request or state change input (unspecified)" },
606 { 0x065a01, "Operator medium removal request" },
607 { 0x0bb900, "Play operation aborted" },
609 /* Here we use 0xff for the key (not a valid key) to signify
610 * that these can have _any_ key value associated with them... */
611 { 0xff0401, "Logical unit is in process of becoming ready" },
612 { 0xff0400, "Logical unit not ready, cause not reportable" },
613 { 0xff0402, "Logical unit not ready, initializing command required" },
614 { 0xff0403, "Logical unit not ready, manual intervention required" },
615 { 0xff0500, "Logical unit does not respond to selection" },
616 { 0xff0800, "Logical unit communication failure" },
617 { 0xff0802, "Logical unit communication parity error" },
618 { 0xff0801, "Logical unit communication time-out" },
619 { 0xff2500, "Logical unit not supported" },
620 { 0xff4c00, "Logical unit failed self-configuration" },
621 { 0xff3e00, "Logical unit has not self-configured yet" },
626 #endif /* _IDE_CD_H */