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