ide-cd_verbose.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Verbose error logging for ATAPI CD/DVD devices.
  4. *
  5. * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov>
  6. * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org>
  7. * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/blkdev.h>
  11. #include <linux/cdrom.h>
  12. #include <linux/ide.h>
  13. #include <scsi/scsi.h>
  14. #include "ide-cd.h"
  15. #ifndef CONFIG_BLK_DEV_IDECD_VERBOSE_ERRORS
  16. void ide_cd_log_error(const char *name, struct request *failed_command,
  17. struct request_sense *sense)
  18. {
  19. /* Suppress printing unit attention and `in progress of becoming ready'
  20. errors when we're not being verbose. */
  21. if (sense->sense_key == UNIT_ATTENTION ||
  22. (sense->sense_key == NOT_READY && (sense->asc == 4 ||
  23. sense->asc == 0x3a)))
  24. return;
  25. printk(KERN_ERR "%s: error code: 0x%02x sense_key: 0x%02x "
  26. "asc: 0x%02x ascq: 0x%02x\n",
  27. name, sense->error_code, sense->sense_key,
  28. sense->asc, sense->ascq);
  29. }
  30. #else
  31. /* The generic packet command opcodes for CD/DVD Logical Units,
  32. * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
  33. static const struct {
  34. unsigned short packet_command;
  35. const char * const text;
  36. } packet_command_texts[] = {
  37. { GPCMD_TEST_UNIT_READY, "Test Unit Ready" },
  38. { GPCMD_REQUEST_SENSE, "Request Sense" },
  39. { GPCMD_FORMAT_UNIT, "Format Unit" },
  40. { GPCMD_INQUIRY, "Inquiry" },
  41. { GPCMD_START_STOP_UNIT, "Start/Stop Unit" },
  42. { GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, "Prevent/Allow Medium Removal" },
  43. { GPCMD_READ_FORMAT_CAPACITIES, "Read Format Capacities" },
  44. { GPCMD_READ_CDVD_CAPACITY, "Read Cd/Dvd Capacity" },
  45. { GPCMD_READ_10, "Read 10" },
  46. { GPCMD_WRITE_10, "Write 10" },
  47. { GPCMD_SEEK, "Seek" },
  48. { GPCMD_WRITE_AND_VERIFY_10, "Write and Verify 10" },
  49. { GPCMD_VERIFY_10, "Verify 10" },
  50. { GPCMD_FLUSH_CACHE, "Flush Cache" },
  51. { GPCMD_READ_SUBCHANNEL, "Read Subchannel" },
  52. { GPCMD_READ_TOC_PMA_ATIP, "Read Table of Contents" },
  53. { GPCMD_READ_HEADER, "Read Header" },
  54. { GPCMD_PLAY_AUDIO_10, "Play Audio 10" },
  55. { GPCMD_GET_CONFIGURATION, "Get Configuration" },
  56. { GPCMD_PLAY_AUDIO_MSF, "Play Audio MSF" },
  57. { GPCMD_PLAYAUDIO_TI, "Play Audio TrackIndex" },
  58. { GPCMD_GET_EVENT_STATUS_NOTIFICATION,
  59. "Get Event Status Notification" },
  60. { GPCMD_PAUSE_RESUME, "Pause/Resume" },
  61. { GPCMD_STOP_PLAY_SCAN, "Stop Play/Scan" },
  62. { GPCMD_READ_DISC_INFO, "Read Disc Info" },
  63. { GPCMD_READ_TRACK_RZONE_INFO, "Read Track Rzone Info" },
  64. { GPCMD_RESERVE_RZONE_TRACK, "Reserve Rzone Track" },
  65. { GPCMD_SEND_OPC, "Send OPC" },
  66. { GPCMD_MODE_SELECT_10, "Mode Select 10" },
  67. { GPCMD_REPAIR_RZONE_TRACK, "Repair Rzone Track" },
  68. { GPCMD_MODE_SENSE_10, "Mode Sense 10" },
  69. { GPCMD_CLOSE_TRACK, "Close Track" },
  70. { GPCMD_BLANK, "Blank" },
  71. { GPCMD_SEND_EVENT, "Send Event" },
  72. { GPCMD_SEND_KEY, "Send Key" },
  73. { GPCMD_REPORT_KEY, "Report Key" },
  74. { GPCMD_LOAD_UNLOAD, "Load/Unload" },
  75. { GPCMD_SET_READ_AHEAD, "Set Read-ahead" },
  76. { GPCMD_READ_12, "Read 12" },
  77. { GPCMD_GET_PERFORMANCE, "Get Performance" },
  78. { GPCMD_SEND_DVD_STRUCTURE, "Send DVD Structure" },
  79. { GPCMD_READ_DVD_STRUCTURE, "Read DVD Structure" },
  80. { GPCMD_SET_STREAMING, "Set Streaming" },
  81. { GPCMD_READ_CD_MSF, "Read CD MSF" },
  82. { GPCMD_SCAN, "Scan" },
  83. { GPCMD_SET_SPEED, "Set Speed" },
  84. { GPCMD_PLAY_CD, "Play CD" },
  85. { GPCMD_MECHANISM_STATUS, "Mechanism Status" },
  86. { GPCMD_READ_CD, "Read CD" },
  87. };
  88. /* From Table 303 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
  89. static const char * const sense_key_texts[16] = {
  90. "No sense data",
  91. "Recovered error",
  92. "Not ready",
  93. "Medium error",
  94. "Hardware error",
  95. "Illegal request",
  96. "Unit attention",
  97. "Data protect",
  98. "Blank check",
  99. "(reserved)",
  100. "(reserved)",
  101. "Aborted command",
  102. "(reserved)",
  103. "(reserved)",
  104. "Miscompare",
  105. "(reserved)",
  106. };
  107. /* From Table 304 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
  108. static const struct {
  109. unsigned long asc_ascq;
  110. const char * const text;
  111. } sense_data_texts[] = {
  112. { 0x000000, "No additional sense information" },
  113. { 0x000011, "Play operation in progress" },
  114. { 0x000012, "Play operation paused" },
  115. { 0x000013, "Play operation successfully completed" },
  116. { 0x000014, "Play operation stopped due to error" },
  117. { 0x000015, "No current audio status to return" },
  118. { 0x010c0a, "Write error - padding blocks added" },
  119. { 0x011700, "Recovered data with no error correction applied" },
  120. { 0x011701, "Recovered data with retries" },
  121. { 0x011702, "Recovered data with positive head offset" },
  122. { 0x011703, "Recovered data with negative head offset" },
  123. { 0x011704, "Recovered data with retries and/or CIRC applied" },
  124. { 0x011705, "Recovered data using previous sector ID" },
  125. { 0x011800, "Recovered data with error correction applied" },
  126. { 0x011801, "Recovered data with error correction and retries applied"},
  127. { 0x011802, "Recovered data - the data was auto-reallocated" },
  128. { 0x011803, "Recovered data with CIRC" },
  129. { 0x011804, "Recovered data with L-EC" },
  130. { 0x015d00, "Failure prediction threshold exceeded"
  131. " - Predicted logical unit failure" },
  132. { 0x015d01, "Failure prediction threshold exceeded"
  133. " - Predicted media failure" },
  134. { 0x015dff, "Failure prediction threshold exceeded - False" },
  135. { 0x017301, "Power calibration area almost full" },
  136. { 0x020400, "Logical unit not ready - cause not reportable" },
  137. /* Following is misspelled in ATAPI 2.6, _and_ in Mt. Fuji */
  138. { 0x020401, "Logical unit not ready"
  139. " - in progress [sic] of becoming ready" },
  140. { 0x020402, "Logical unit not ready - initializing command required" },
  141. { 0x020403, "Logical unit not ready - manual intervention required" },
  142. { 0x020404, "Logical unit not ready - format in progress" },
  143. { 0x020407, "Logical unit not ready - operation in progress" },
  144. { 0x020408, "Logical unit not ready - long write in progress" },
  145. { 0x020600, "No reference position found (media may be upside down)" },
  146. { 0x023000, "Incompatible medium installed" },
  147. { 0x023a00, "Medium not present" },
  148. { 0x025300, "Media load or eject failed" },
  149. { 0x025700, "Unable to recover table of contents" },
  150. { 0x030300, "Peripheral device write fault" },
  151. { 0x030301, "No write current" },
  152. { 0x030302, "Excessive write errors" },
  153. { 0x030c00, "Write error" },
  154. { 0x030c01, "Write error - Recovered with auto reallocation" },
  155. { 0x030c02, "Write error - auto reallocation failed" },
  156. { 0x030c03, "Write error - recommend reassignment" },
  157. { 0x030c04, "Compression check miscompare error" },
  158. { 0x030c05, "Data expansion occurred during compress" },
  159. { 0x030c06, "Block not compressible" },
  160. { 0x030c07, "Write error - recovery needed" },
  161. { 0x030c08, "Write error - recovery failed" },
  162. { 0x030c09, "Write error - loss of streaming" },
  163. { 0x031100, "Unrecovered read error" },
  164. { 0x031106, "CIRC unrecovered error" },
  165. { 0x033101, "Format command failed" },
  166. { 0x033200, "No defect spare location available" },
  167. { 0x033201, "Defect list update failure" },
  168. { 0x035100, "Erase failure" },
  169. { 0x037200, "Session fixation error" },
  170. { 0x037201, "Session fixation error writin lead-in" },
  171. { 0x037202, "Session fixation error writin lead-out" },
  172. { 0x037300, "CD control error" },
  173. { 0x037302, "Power calibration area is full" },
  174. { 0x037303, "Power calibration area error" },
  175. { 0x037304, "Program memory area / RMA update failure" },
  176. { 0x037305, "Program memory area / RMA is full" },
  177. { 0x037306, "Program memory area / RMA is (almost) full" },
  178. { 0x040200, "No seek complete" },
  179. { 0x040300, "Write fault" },
  180. { 0x040900, "Track following error" },
  181. { 0x040901, "Tracking servo failure" },
  182. { 0x040902, "Focus servo failure" },
  183. { 0x040903, "Spindle servo failure" },
  184. { 0x041500, "Random positioning error" },
  185. { 0x041501, "Mechanical positioning or changer error" },
  186. { 0x041502, "Positioning error detected by read of medium" },
  187. { 0x043c00, "Mechanical positioning or changer error" },
  188. { 0x044000, "Diagnostic failure on component (ASCQ)" },
  189. { 0x044400, "Internal CD/DVD logical unit failure" },
  190. { 0x04b600, "Media load mechanism failed" },
  191. { 0x051a00, "Parameter list length error" },
  192. { 0x052000, "Invalid command operation code" },
  193. { 0x052100, "Logical block address out of range" },
  194. { 0x052102, "Invalid address for write" },
  195. { 0x052400, "Invalid field in command packet" },
  196. { 0x052600, "Invalid field in parameter list" },
  197. { 0x052601, "Parameter not supported" },
  198. { 0x052602, "Parameter value invalid" },
  199. { 0x052700, "Write protected media" },
  200. { 0x052c00, "Command sequence error" },
  201. { 0x052c03, "Current program area is not empty" },
  202. { 0x052c04, "Current program area is empty" },
  203. { 0x053001, "Cannot read medium - unknown format" },
  204. { 0x053002, "Cannot read medium - incompatible format" },
  205. { 0x053900, "Saving parameters not supported" },
  206. { 0x054e00, "Overlapped commands attempted" },
  207. { 0x055302, "Medium removal prevented" },
  208. { 0x055500, "System resource failure" },
  209. { 0x056300, "End of user area encountered on this track" },
  210. { 0x056400, "Illegal mode for this track or incompatible medium" },
  211. { 0x056f00, "Copy protection key exchange failure"
  212. " - Authentication failure" },
  213. { 0x056f01, "Copy protection key exchange failure - Key not present" },
  214. { 0x056f02, "Copy protection key exchange failure"
  215. " - Key not established" },
  216. { 0x056f03, "Read of scrambled sector without authentication" },
  217. { 0x056f04, "Media region code is mismatched to logical unit" },
  218. { 0x056f05, "Drive region must be permanent"
  219. " / region reset count error" },
  220. { 0x057203, "Session fixation error - incomplete track in session" },
  221. { 0x057204, "Empty or partially written reserved track" },
  222. { 0x057205, "No more RZONE reservations are allowed" },
  223. { 0x05bf00, "Loss of streaming" },
  224. { 0x062800, "Not ready to ready transition, medium may have changed" },
  225. { 0x062900, "Power on, reset or hardware reset occurred" },
  226. { 0x062a00, "Parameters changed" },
  227. { 0x062a01, "Mode parameters changed" },
  228. { 0x062e00, "Insufficient time for operation" },
  229. { 0x063f00, "Logical unit operating conditions have changed" },
  230. { 0x063f01, "Microcode has been changed" },
  231. { 0x065a00, "Operator request or state change input (unspecified)" },
  232. { 0x065a01, "Operator medium removal request" },
  233. { 0x0bb900, "Play operation aborted" },
  234. /* Here we use 0xff for the key (not a valid key) to signify
  235. * that these can have _any_ key value associated with them... */
  236. { 0xff0401, "Logical unit is in process of becoming ready" },
  237. { 0xff0400, "Logical unit not ready, cause not reportable" },
  238. { 0xff0402, "Logical unit not ready, initializing command required" },
  239. { 0xff0403, "Logical unit not ready, manual intervention required" },
  240. { 0xff0500, "Logical unit does not respond to selection" },
  241. { 0xff0800, "Logical unit communication failure" },
  242. { 0xff0802, "Logical unit communication parity error" },
  243. { 0xff0801, "Logical unit communication time-out" },
  244. { 0xff2500, "Logical unit not supported" },
  245. { 0xff4c00, "Logical unit failed self-configuration" },
  246. { 0xff3e00, "Logical unit has not self-configured yet" },
  247. };
  248. void ide_cd_log_error(const char *name, struct request *failed_command,
  249. struct request_sense *sense)
  250. {
  251. int i;
  252. const char *s = "bad sense key!";
  253. char buf[80];
  254. printk(KERN_ERR "ATAPI device %s:\n", name);
  255. if (sense->error_code == 0x70)
  256. printk(KERN_CONT " Error: ");
  257. else if (sense->error_code == 0x71)
  258. printk(" Deferred Error: ");
  259. else if (sense->error_code == 0x7f)
  260. printk(KERN_CONT " Vendor-specific Error: ");
  261. else
  262. printk(KERN_CONT " Unknown Error Type: ");
  263. if (sense->sense_key < ARRAY_SIZE(sense_key_texts))
  264. s = sense_key_texts[sense->sense_key];
  265. printk(KERN_CONT "%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
  266. if (sense->asc == 0x40) {
  267. sprintf(buf, "Diagnostic failure on component 0x%02x",
  268. sense->ascq);
  269. s = buf;
  270. } else {
  271. int lo = 0, mid, hi = ARRAY_SIZE(sense_data_texts);
  272. unsigned long key = (sense->sense_key << 16);
  273. key |= (sense->asc << 8);
  274. if (!(sense->ascq >= 0x80 && sense->ascq <= 0xdd))
  275. key |= sense->ascq;
  276. s = NULL;
  277. while (hi > lo) {
  278. mid = (lo + hi) / 2;
  279. if (sense_data_texts[mid].asc_ascq == key ||
  280. sense_data_texts[mid].asc_ascq == (0xff0000|key)) {
  281. s = sense_data_texts[mid].text;
  282. break;
  283. } else if (sense_data_texts[mid].asc_ascq > key)
  284. hi = mid;
  285. else
  286. lo = mid + 1;
  287. }
  288. }
  289. if (s == NULL) {
  290. if (sense->asc > 0x80)
  291. s = "(vendor-specific error)";
  292. else
  293. s = "(reserved error code)";
  294. }
  295. printk(KERN_ERR " %s -- (asc=0x%02x, ascq=0x%02x)\n",
  296. s, sense->asc, sense->ascq);
  297. if (failed_command != NULL) {
  298. int lo = 0, mid, hi = ARRAY_SIZE(packet_command_texts);
  299. s = NULL;
  300. while (hi > lo) {
  301. mid = (lo + hi) / 2;
  302. if (packet_command_texts[mid].packet_command ==
  303. scsi_req(failed_command)->cmd[0]) {
  304. s = packet_command_texts[mid].text;
  305. break;
  306. }
  307. if (packet_command_texts[mid].packet_command >
  308. scsi_req(failed_command)->cmd[0])
  309. hi = mid;
  310. else
  311. lo = mid + 1;
  312. }
  313. printk(KERN_ERR " The failed \"%s\" packet command "
  314. "was: \n \"", s);
  315. for (i = 0; i < BLK_MAX_CDB; i++)
  316. printk(KERN_CONT "%02x ", scsi_req(failed_command)->cmd[i]);
  317. printk(KERN_CONT "\"\n");
  318. }
  319. /* The SKSV bit specifies validity of the sense_key_specific
  320. * in the next two commands. It is bit 7 of the first byte.
  321. * In the case of NOT_READY, if SKSV is set the drive can
  322. * give us nice ETA readings.
  323. */
  324. if (sense->sense_key == NOT_READY && (sense->sks[0] & 0x80)) {
  325. int progress = (sense->sks[1] << 8 | sense->sks[2]) * 100;
  326. printk(KERN_ERR " Command is %02d%% complete\n",
  327. progress / 0xffff);
  328. }
  329. if (sense->sense_key == ILLEGAL_REQUEST &&
  330. (sense->sks[0] & 0x80) != 0) {
  331. printk(KERN_ERR " Error in %s byte %d",
  332. (sense->sks[0] & 0x40) != 0 ?
  333. "command packet" : "command data",
  334. (sense->sks[1] << 8) + sense->sks[2]);
  335. if ((sense->sks[0] & 0x40) != 0)
  336. printk(KERN_CONT " bit %d", sense->sks[0] & 0x07);
  337. printk(KERN_CONT "\n");
  338. }
  339. }
  340. #endif