18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Verbose error logging for ATAPI CD/DVD devices.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 1994-1996  Scott Snyder <snyder@fnald0.fnal.gov>
68c2ecf20Sopenharmony_ci * Copyright (C) 1996-1998  Erik Andersen <andersee@debian.org>
78c2ecf20Sopenharmony_ci * Copyright (C) 1998-2000  Jens Axboe <axboe@suse.de>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/kernel.h>
118c2ecf20Sopenharmony_ci#include <linux/blkdev.h>
128c2ecf20Sopenharmony_ci#include <linux/cdrom.h>
138c2ecf20Sopenharmony_ci#include <linux/ide.h>
148c2ecf20Sopenharmony_ci#include <scsi/scsi.h>
158c2ecf20Sopenharmony_ci#include "ide-cd.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#ifndef CONFIG_BLK_DEV_IDECD_VERBOSE_ERRORS
188c2ecf20Sopenharmony_civoid ide_cd_log_error(const char *name, struct request *failed_command,
198c2ecf20Sopenharmony_ci		      struct request_sense *sense)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	/* Suppress printing unit attention and `in progress of becoming ready'
228c2ecf20Sopenharmony_ci	   errors when we're not being verbose. */
238c2ecf20Sopenharmony_ci	if (sense->sense_key == UNIT_ATTENTION ||
248c2ecf20Sopenharmony_ci	    (sense->sense_key == NOT_READY && (sense->asc == 4 ||
258c2ecf20Sopenharmony_ci						sense->asc == 0x3a)))
268c2ecf20Sopenharmony_ci		return;
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	printk(KERN_ERR "%s: error code: 0x%02x  sense_key: 0x%02x  "
298c2ecf20Sopenharmony_ci			"asc: 0x%02x  ascq: 0x%02x\n",
308c2ecf20Sopenharmony_ci			name, sense->error_code, sense->sense_key,
318c2ecf20Sopenharmony_ci			sense->asc, sense->ascq);
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci#else
348c2ecf20Sopenharmony_ci/* The generic packet command opcodes for CD/DVD Logical Units,
358c2ecf20Sopenharmony_ci * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
368c2ecf20Sopenharmony_cistatic const struct {
378c2ecf20Sopenharmony_ci	unsigned short packet_command;
388c2ecf20Sopenharmony_ci	const char * const text;
398c2ecf20Sopenharmony_ci} packet_command_texts[] = {
408c2ecf20Sopenharmony_ci	{ GPCMD_TEST_UNIT_READY, "Test Unit Ready" },
418c2ecf20Sopenharmony_ci	{ GPCMD_REQUEST_SENSE, "Request Sense" },
428c2ecf20Sopenharmony_ci	{ GPCMD_FORMAT_UNIT, "Format Unit" },
438c2ecf20Sopenharmony_ci	{ GPCMD_INQUIRY, "Inquiry" },
448c2ecf20Sopenharmony_ci	{ GPCMD_START_STOP_UNIT, "Start/Stop Unit" },
458c2ecf20Sopenharmony_ci	{ GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, "Prevent/Allow Medium Removal" },
468c2ecf20Sopenharmony_ci	{ GPCMD_READ_FORMAT_CAPACITIES, "Read Format Capacities" },
478c2ecf20Sopenharmony_ci	{ GPCMD_READ_CDVD_CAPACITY, "Read Cd/Dvd Capacity" },
488c2ecf20Sopenharmony_ci	{ GPCMD_READ_10, "Read 10" },
498c2ecf20Sopenharmony_ci	{ GPCMD_WRITE_10, "Write 10" },
508c2ecf20Sopenharmony_ci	{ GPCMD_SEEK, "Seek" },
518c2ecf20Sopenharmony_ci	{ GPCMD_WRITE_AND_VERIFY_10, "Write and Verify 10" },
528c2ecf20Sopenharmony_ci	{ GPCMD_VERIFY_10, "Verify 10" },
538c2ecf20Sopenharmony_ci	{ GPCMD_FLUSH_CACHE, "Flush Cache" },
548c2ecf20Sopenharmony_ci	{ GPCMD_READ_SUBCHANNEL, "Read Subchannel" },
558c2ecf20Sopenharmony_ci	{ GPCMD_READ_TOC_PMA_ATIP, "Read Table of Contents" },
568c2ecf20Sopenharmony_ci	{ GPCMD_READ_HEADER, "Read Header" },
578c2ecf20Sopenharmony_ci	{ GPCMD_PLAY_AUDIO_10, "Play Audio 10" },
588c2ecf20Sopenharmony_ci	{ GPCMD_GET_CONFIGURATION, "Get Configuration" },
598c2ecf20Sopenharmony_ci	{ GPCMD_PLAY_AUDIO_MSF, "Play Audio MSF" },
608c2ecf20Sopenharmony_ci	{ GPCMD_PLAYAUDIO_TI, "Play Audio TrackIndex" },
618c2ecf20Sopenharmony_ci	{ GPCMD_GET_EVENT_STATUS_NOTIFICATION,
628c2ecf20Sopenharmony_ci		"Get Event Status Notification" },
638c2ecf20Sopenharmony_ci	{ GPCMD_PAUSE_RESUME, "Pause/Resume" },
648c2ecf20Sopenharmony_ci	{ GPCMD_STOP_PLAY_SCAN, "Stop Play/Scan" },
658c2ecf20Sopenharmony_ci	{ GPCMD_READ_DISC_INFO, "Read Disc Info" },
668c2ecf20Sopenharmony_ci	{ GPCMD_READ_TRACK_RZONE_INFO, "Read Track Rzone Info" },
678c2ecf20Sopenharmony_ci	{ GPCMD_RESERVE_RZONE_TRACK, "Reserve Rzone Track" },
688c2ecf20Sopenharmony_ci	{ GPCMD_SEND_OPC, "Send OPC" },
698c2ecf20Sopenharmony_ci	{ GPCMD_MODE_SELECT_10, "Mode Select 10" },
708c2ecf20Sopenharmony_ci	{ GPCMD_REPAIR_RZONE_TRACK, "Repair Rzone Track" },
718c2ecf20Sopenharmony_ci	{ GPCMD_MODE_SENSE_10, "Mode Sense 10" },
728c2ecf20Sopenharmony_ci	{ GPCMD_CLOSE_TRACK, "Close Track" },
738c2ecf20Sopenharmony_ci	{ GPCMD_BLANK, "Blank" },
748c2ecf20Sopenharmony_ci	{ GPCMD_SEND_EVENT, "Send Event" },
758c2ecf20Sopenharmony_ci	{ GPCMD_SEND_KEY, "Send Key" },
768c2ecf20Sopenharmony_ci	{ GPCMD_REPORT_KEY, "Report Key" },
778c2ecf20Sopenharmony_ci	{ GPCMD_LOAD_UNLOAD, "Load/Unload" },
788c2ecf20Sopenharmony_ci	{ GPCMD_SET_READ_AHEAD, "Set Read-ahead" },
798c2ecf20Sopenharmony_ci	{ GPCMD_READ_12, "Read 12" },
808c2ecf20Sopenharmony_ci	{ GPCMD_GET_PERFORMANCE, "Get Performance" },
818c2ecf20Sopenharmony_ci	{ GPCMD_SEND_DVD_STRUCTURE, "Send DVD Structure" },
828c2ecf20Sopenharmony_ci	{ GPCMD_READ_DVD_STRUCTURE, "Read DVD Structure" },
838c2ecf20Sopenharmony_ci	{ GPCMD_SET_STREAMING, "Set Streaming" },
848c2ecf20Sopenharmony_ci	{ GPCMD_READ_CD_MSF, "Read CD MSF" },
858c2ecf20Sopenharmony_ci	{ GPCMD_SCAN, "Scan" },
868c2ecf20Sopenharmony_ci	{ GPCMD_SET_SPEED, "Set Speed" },
878c2ecf20Sopenharmony_ci	{ GPCMD_PLAY_CD, "Play CD" },
888c2ecf20Sopenharmony_ci	{ GPCMD_MECHANISM_STATUS, "Mechanism Status" },
898c2ecf20Sopenharmony_ci	{ GPCMD_READ_CD, "Read CD" },
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* From Table 303 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
938c2ecf20Sopenharmony_cistatic const char * const sense_key_texts[16] = {
948c2ecf20Sopenharmony_ci	"No sense data",
958c2ecf20Sopenharmony_ci	"Recovered error",
968c2ecf20Sopenharmony_ci	"Not ready",
978c2ecf20Sopenharmony_ci	"Medium error",
988c2ecf20Sopenharmony_ci	"Hardware error",
998c2ecf20Sopenharmony_ci	"Illegal request",
1008c2ecf20Sopenharmony_ci	"Unit attention",
1018c2ecf20Sopenharmony_ci	"Data protect",
1028c2ecf20Sopenharmony_ci	"Blank check",
1038c2ecf20Sopenharmony_ci	"(reserved)",
1048c2ecf20Sopenharmony_ci	"(reserved)",
1058c2ecf20Sopenharmony_ci	"Aborted command",
1068c2ecf20Sopenharmony_ci	"(reserved)",
1078c2ecf20Sopenharmony_ci	"(reserved)",
1088c2ecf20Sopenharmony_ci	"Miscompare",
1098c2ecf20Sopenharmony_ci	"(reserved)",
1108c2ecf20Sopenharmony_ci};
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* From Table 304 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
1138c2ecf20Sopenharmony_cistatic const struct {
1148c2ecf20Sopenharmony_ci	unsigned long asc_ascq;
1158c2ecf20Sopenharmony_ci	const char * const text;
1168c2ecf20Sopenharmony_ci} sense_data_texts[] = {
1178c2ecf20Sopenharmony_ci	{ 0x000000, "No additional sense information" },
1188c2ecf20Sopenharmony_ci	{ 0x000011, "Play operation in progress" },
1198c2ecf20Sopenharmony_ci	{ 0x000012, "Play operation paused" },
1208c2ecf20Sopenharmony_ci	{ 0x000013, "Play operation successfully completed" },
1218c2ecf20Sopenharmony_ci	{ 0x000014, "Play operation stopped due to error" },
1228c2ecf20Sopenharmony_ci	{ 0x000015, "No current audio status to return" },
1238c2ecf20Sopenharmony_ci	{ 0x010c0a, "Write error - padding blocks added" },
1248c2ecf20Sopenharmony_ci	{ 0x011700, "Recovered data with no error correction applied" },
1258c2ecf20Sopenharmony_ci	{ 0x011701, "Recovered data with retries" },
1268c2ecf20Sopenharmony_ci	{ 0x011702, "Recovered data with positive head offset" },
1278c2ecf20Sopenharmony_ci	{ 0x011703, "Recovered data with negative head offset" },
1288c2ecf20Sopenharmony_ci	{ 0x011704, "Recovered data with retries and/or CIRC applied" },
1298c2ecf20Sopenharmony_ci	{ 0x011705, "Recovered data using previous sector ID" },
1308c2ecf20Sopenharmony_ci	{ 0x011800, "Recovered data with error correction applied" },
1318c2ecf20Sopenharmony_ci	{ 0x011801, "Recovered data with error correction and retries applied"},
1328c2ecf20Sopenharmony_ci	{ 0x011802, "Recovered data - the data was auto-reallocated" },
1338c2ecf20Sopenharmony_ci	{ 0x011803, "Recovered data with CIRC" },
1348c2ecf20Sopenharmony_ci	{ 0x011804, "Recovered data with L-EC" },
1358c2ecf20Sopenharmony_ci	{ 0x015d00, "Failure prediction threshold exceeded"
1368c2ecf20Sopenharmony_ci		    " - Predicted logical unit failure" },
1378c2ecf20Sopenharmony_ci	{ 0x015d01, "Failure prediction threshold exceeded"
1388c2ecf20Sopenharmony_ci		    " - Predicted media failure" },
1398c2ecf20Sopenharmony_ci	{ 0x015dff, "Failure prediction threshold exceeded - False" },
1408c2ecf20Sopenharmony_ci	{ 0x017301, "Power calibration area almost full" },
1418c2ecf20Sopenharmony_ci	{ 0x020400, "Logical unit not ready - cause not reportable" },
1428c2ecf20Sopenharmony_ci	/* Following is misspelled in ATAPI 2.6, _and_ in Mt. Fuji */
1438c2ecf20Sopenharmony_ci	{ 0x020401, "Logical unit not ready"
1448c2ecf20Sopenharmony_ci		    " - in progress [sic] of becoming ready" },
1458c2ecf20Sopenharmony_ci	{ 0x020402, "Logical unit not ready - initializing command required" },
1468c2ecf20Sopenharmony_ci	{ 0x020403, "Logical unit not ready - manual intervention required" },
1478c2ecf20Sopenharmony_ci	{ 0x020404, "Logical unit not ready - format in progress" },
1488c2ecf20Sopenharmony_ci	{ 0x020407, "Logical unit not ready - operation in progress" },
1498c2ecf20Sopenharmony_ci	{ 0x020408, "Logical unit not ready - long write in progress" },
1508c2ecf20Sopenharmony_ci	{ 0x020600, "No reference position found (media may be upside down)" },
1518c2ecf20Sopenharmony_ci	{ 0x023000, "Incompatible medium installed" },
1528c2ecf20Sopenharmony_ci	{ 0x023a00, "Medium not present" },
1538c2ecf20Sopenharmony_ci	{ 0x025300, "Media load or eject failed" },
1548c2ecf20Sopenharmony_ci	{ 0x025700, "Unable to recover table of contents" },
1558c2ecf20Sopenharmony_ci	{ 0x030300, "Peripheral device write fault" },
1568c2ecf20Sopenharmony_ci	{ 0x030301, "No write current" },
1578c2ecf20Sopenharmony_ci	{ 0x030302, "Excessive write errors" },
1588c2ecf20Sopenharmony_ci	{ 0x030c00, "Write error" },
1598c2ecf20Sopenharmony_ci	{ 0x030c01, "Write error - Recovered with auto reallocation" },
1608c2ecf20Sopenharmony_ci	{ 0x030c02, "Write error - auto reallocation failed" },
1618c2ecf20Sopenharmony_ci	{ 0x030c03, "Write error - recommend reassignment" },
1628c2ecf20Sopenharmony_ci	{ 0x030c04, "Compression check miscompare error" },
1638c2ecf20Sopenharmony_ci	{ 0x030c05, "Data expansion occurred during compress" },
1648c2ecf20Sopenharmony_ci	{ 0x030c06, "Block not compressible" },
1658c2ecf20Sopenharmony_ci	{ 0x030c07, "Write error - recovery needed" },
1668c2ecf20Sopenharmony_ci	{ 0x030c08, "Write error - recovery failed" },
1678c2ecf20Sopenharmony_ci	{ 0x030c09, "Write error - loss of streaming" },
1688c2ecf20Sopenharmony_ci	{ 0x031100, "Unrecovered read error" },
1698c2ecf20Sopenharmony_ci	{ 0x031106, "CIRC unrecovered error" },
1708c2ecf20Sopenharmony_ci	{ 0x033101, "Format command failed" },
1718c2ecf20Sopenharmony_ci	{ 0x033200, "No defect spare location available" },
1728c2ecf20Sopenharmony_ci	{ 0x033201, "Defect list update failure" },
1738c2ecf20Sopenharmony_ci	{ 0x035100, "Erase failure" },
1748c2ecf20Sopenharmony_ci	{ 0x037200, "Session fixation error" },
1758c2ecf20Sopenharmony_ci	{ 0x037201, "Session fixation error writin lead-in" },
1768c2ecf20Sopenharmony_ci	{ 0x037202, "Session fixation error writin lead-out" },
1778c2ecf20Sopenharmony_ci	{ 0x037300, "CD control error" },
1788c2ecf20Sopenharmony_ci	{ 0x037302, "Power calibration area is full" },
1798c2ecf20Sopenharmony_ci	{ 0x037303, "Power calibration area error" },
1808c2ecf20Sopenharmony_ci	{ 0x037304, "Program memory area / RMA update failure" },
1818c2ecf20Sopenharmony_ci	{ 0x037305, "Program memory area / RMA is full" },
1828c2ecf20Sopenharmony_ci	{ 0x037306, "Program memory area / RMA is (almost) full" },
1838c2ecf20Sopenharmony_ci	{ 0x040200, "No seek complete" },
1848c2ecf20Sopenharmony_ci	{ 0x040300, "Write fault" },
1858c2ecf20Sopenharmony_ci	{ 0x040900, "Track following error" },
1868c2ecf20Sopenharmony_ci	{ 0x040901, "Tracking servo failure" },
1878c2ecf20Sopenharmony_ci	{ 0x040902, "Focus servo failure" },
1888c2ecf20Sopenharmony_ci	{ 0x040903, "Spindle servo failure" },
1898c2ecf20Sopenharmony_ci	{ 0x041500, "Random positioning error" },
1908c2ecf20Sopenharmony_ci	{ 0x041501, "Mechanical positioning or changer error" },
1918c2ecf20Sopenharmony_ci	{ 0x041502, "Positioning error detected by read of medium" },
1928c2ecf20Sopenharmony_ci	{ 0x043c00, "Mechanical positioning or changer error" },
1938c2ecf20Sopenharmony_ci	{ 0x044000, "Diagnostic failure on component (ASCQ)" },
1948c2ecf20Sopenharmony_ci	{ 0x044400, "Internal CD/DVD logical unit failure" },
1958c2ecf20Sopenharmony_ci	{ 0x04b600, "Media load mechanism failed" },
1968c2ecf20Sopenharmony_ci	{ 0x051a00, "Parameter list length error" },
1978c2ecf20Sopenharmony_ci	{ 0x052000, "Invalid command operation code" },
1988c2ecf20Sopenharmony_ci	{ 0x052100, "Logical block address out of range" },
1998c2ecf20Sopenharmony_ci	{ 0x052102, "Invalid address for write" },
2008c2ecf20Sopenharmony_ci	{ 0x052400, "Invalid field in command packet" },
2018c2ecf20Sopenharmony_ci	{ 0x052600, "Invalid field in parameter list" },
2028c2ecf20Sopenharmony_ci	{ 0x052601, "Parameter not supported" },
2038c2ecf20Sopenharmony_ci	{ 0x052602, "Parameter value invalid" },
2048c2ecf20Sopenharmony_ci	{ 0x052700, "Write protected media" },
2058c2ecf20Sopenharmony_ci	{ 0x052c00, "Command sequence error" },
2068c2ecf20Sopenharmony_ci	{ 0x052c03, "Current program area is not empty" },
2078c2ecf20Sopenharmony_ci	{ 0x052c04, "Current program area is empty" },
2088c2ecf20Sopenharmony_ci	{ 0x053001, "Cannot read medium - unknown format" },
2098c2ecf20Sopenharmony_ci	{ 0x053002, "Cannot read medium - incompatible format" },
2108c2ecf20Sopenharmony_ci	{ 0x053900, "Saving parameters not supported" },
2118c2ecf20Sopenharmony_ci	{ 0x054e00, "Overlapped commands attempted" },
2128c2ecf20Sopenharmony_ci	{ 0x055302, "Medium removal prevented" },
2138c2ecf20Sopenharmony_ci	{ 0x055500, "System resource failure" },
2148c2ecf20Sopenharmony_ci	{ 0x056300, "End of user area encountered on this track" },
2158c2ecf20Sopenharmony_ci	{ 0x056400, "Illegal mode for this track or incompatible medium" },
2168c2ecf20Sopenharmony_ci	{ 0x056f00, "Copy protection key exchange failure"
2178c2ecf20Sopenharmony_ci		    " - Authentication failure" },
2188c2ecf20Sopenharmony_ci	{ 0x056f01, "Copy protection key exchange failure - Key not present" },
2198c2ecf20Sopenharmony_ci	{ 0x056f02, "Copy protection key exchange failure"
2208c2ecf20Sopenharmony_ci		     " - Key not established" },
2218c2ecf20Sopenharmony_ci	{ 0x056f03, "Read of scrambled sector without authentication" },
2228c2ecf20Sopenharmony_ci	{ 0x056f04, "Media region code is mismatched to logical unit" },
2238c2ecf20Sopenharmony_ci	{ 0x056f05, "Drive region must be permanent"
2248c2ecf20Sopenharmony_ci		    " / region reset count error" },
2258c2ecf20Sopenharmony_ci	{ 0x057203, "Session fixation error - incomplete track in session" },
2268c2ecf20Sopenharmony_ci	{ 0x057204, "Empty or partially written reserved track" },
2278c2ecf20Sopenharmony_ci	{ 0x057205, "No more RZONE reservations are allowed" },
2288c2ecf20Sopenharmony_ci	{ 0x05bf00, "Loss of streaming" },
2298c2ecf20Sopenharmony_ci	{ 0x062800, "Not ready to ready transition, medium may have changed" },
2308c2ecf20Sopenharmony_ci	{ 0x062900, "Power on, reset or hardware reset occurred" },
2318c2ecf20Sopenharmony_ci	{ 0x062a00, "Parameters changed" },
2328c2ecf20Sopenharmony_ci	{ 0x062a01, "Mode parameters changed" },
2338c2ecf20Sopenharmony_ci	{ 0x062e00, "Insufficient time for operation" },
2348c2ecf20Sopenharmony_ci	{ 0x063f00, "Logical unit operating conditions have changed" },
2358c2ecf20Sopenharmony_ci	{ 0x063f01, "Microcode has been changed" },
2368c2ecf20Sopenharmony_ci	{ 0x065a00, "Operator request or state change input (unspecified)" },
2378c2ecf20Sopenharmony_ci	{ 0x065a01, "Operator medium removal request" },
2388c2ecf20Sopenharmony_ci	{ 0x0bb900, "Play operation aborted" },
2398c2ecf20Sopenharmony_ci	/* Here we use 0xff for the key (not a valid key) to signify
2408c2ecf20Sopenharmony_ci	 * that these can have _any_ key value associated with them... */
2418c2ecf20Sopenharmony_ci	{ 0xff0401, "Logical unit is in process of becoming ready" },
2428c2ecf20Sopenharmony_ci	{ 0xff0400, "Logical unit not ready, cause not reportable" },
2438c2ecf20Sopenharmony_ci	{ 0xff0402, "Logical unit not ready, initializing command required" },
2448c2ecf20Sopenharmony_ci	{ 0xff0403, "Logical unit not ready, manual intervention required" },
2458c2ecf20Sopenharmony_ci	{ 0xff0500, "Logical unit does not respond to selection" },
2468c2ecf20Sopenharmony_ci	{ 0xff0800, "Logical unit communication failure" },
2478c2ecf20Sopenharmony_ci	{ 0xff0802, "Logical unit communication parity error" },
2488c2ecf20Sopenharmony_ci	{ 0xff0801, "Logical unit communication time-out" },
2498c2ecf20Sopenharmony_ci	{ 0xff2500, "Logical unit not supported" },
2508c2ecf20Sopenharmony_ci	{ 0xff4c00, "Logical unit failed self-configuration" },
2518c2ecf20Sopenharmony_ci	{ 0xff3e00, "Logical unit has not self-configured yet" },
2528c2ecf20Sopenharmony_ci};
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_civoid ide_cd_log_error(const char *name, struct request *failed_command,
2558c2ecf20Sopenharmony_ci		      struct request_sense *sense)
2568c2ecf20Sopenharmony_ci{
2578c2ecf20Sopenharmony_ci	int i;
2588c2ecf20Sopenharmony_ci	const char *s = "bad sense key!";
2598c2ecf20Sopenharmony_ci	char buf[80];
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	printk(KERN_ERR "ATAPI device %s:\n", name);
2628c2ecf20Sopenharmony_ci	if (sense->error_code == 0x70)
2638c2ecf20Sopenharmony_ci		printk(KERN_CONT "  Error: ");
2648c2ecf20Sopenharmony_ci	else if (sense->error_code == 0x71)
2658c2ecf20Sopenharmony_ci		printk("  Deferred Error: ");
2668c2ecf20Sopenharmony_ci	else if (sense->error_code == 0x7f)
2678c2ecf20Sopenharmony_ci		printk(KERN_CONT "  Vendor-specific Error: ");
2688c2ecf20Sopenharmony_ci	else
2698c2ecf20Sopenharmony_ci		printk(KERN_CONT "  Unknown Error Type: ");
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	if (sense->sense_key < ARRAY_SIZE(sense_key_texts))
2728c2ecf20Sopenharmony_ci		s = sense_key_texts[sense->sense_key];
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	printk(KERN_CONT "%s -- (Sense key=0x%02x)\n", s, sense->sense_key);
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	if (sense->asc == 0x40) {
2778c2ecf20Sopenharmony_ci		sprintf(buf, "Diagnostic failure on component 0x%02x",
2788c2ecf20Sopenharmony_ci			sense->ascq);
2798c2ecf20Sopenharmony_ci		s = buf;
2808c2ecf20Sopenharmony_ci	} else {
2818c2ecf20Sopenharmony_ci		int lo = 0, mid, hi = ARRAY_SIZE(sense_data_texts);
2828c2ecf20Sopenharmony_ci		unsigned long key = (sense->sense_key << 16);
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci		key |= (sense->asc << 8);
2858c2ecf20Sopenharmony_ci		if (!(sense->ascq >= 0x80 && sense->ascq <= 0xdd))
2868c2ecf20Sopenharmony_ci			key |= sense->ascq;
2878c2ecf20Sopenharmony_ci		s = NULL;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci		while (hi > lo) {
2908c2ecf20Sopenharmony_ci			mid = (lo + hi) / 2;
2918c2ecf20Sopenharmony_ci			if (sense_data_texts[mid].asc_ascq == key ||
2928c2ecf20Sopenharmony_ci			    sense_data_texts[mid].asc_ascq == (0xff0000|key)) {
2938c2ecf20Sopenharmony_ci				s = sense_data_texts[mid].text;
2948c2ecf20Sopenharmony_ci				break;
2958c2ecf20Sopenharmony_ci			} else if (sense_data_texts[mid].asc_ascq > key)
2968c2ecf20Sopenharmony_ci				hi = mid;
2978c2ecf20Sopenharmony_ci			else
2988c2ecf20Sopenharmony_ci				lo = mid + 1;
2998c2ecf20Sopenharmony_ci		}
3008c2ecf20Sopenharmony_ci	}
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	if (s == NULL) {
3038c2ecf20Sopenharmony_ci		if (sense->asc > 0x80)
3048c2ecf20Sopenharmony_ci			s = "(vendor-specific error)";
3058c2ecf20Sopenharmony_ci		else
3068c2ecf20Sopenharmony_ci			s = "(reserved error code)";
3078c2ecf20Sopenharmony_ci	}
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci	printk(KERN_ERR "  %s -- (asc=0x%02x, ascq=0x%02x)\n",
3108c2ecf20Sopenharmony_ci			s, sense->asc, sense->ascq);
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	if (failed_command != NULL) {
3138c2ecf20Sopenharmony_ci		int lo = 0, mid, hi = ARRAY_SIZE(packet_command_texts);
3148c2ecf20Sopenharmony_ci		s = NULL;
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci		while (hi > lo) {
3178c2ecf20Sopenharmony_ci			mid = (lo + hi) / 2;
3188c2ecf20Sopenharmony_ci			if (packet_command_texts[mid].packet_command ==
3198c2ecf20Sopenharmony_ci			    scsi_req(failed_command)->cmd[0]) {
3208c2ecf20Sopenharmony_ci				s = packet_command_texts[mid].text;
3218c2ecf20Sopenharmony_ci				break;
3228c2ecf20Sopenharmony_ci			}
3238c2ecf20Sopenharmony_ci			if (packet_command_texts[mid].packet_command >
3248c2ecf20Sopenharmony_ci			    scsi_req(failed_command)->cmd[0])
3258c2ecf20Sopenharmony_ci				hi = mid;
3268c2ecf20Sopenharmony_ci			else
3278c2ecf20Sopenharmony_ci				lo = mid + 1;
3288c2ecf20Sopenharmony_ci		}
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci		printk(KERN_ERR "  The failed \"%s\" packet command "
3318c2ecf20Sopenharmony_ci				"was: \n  \"", s);
3328c2ecf20Sopenharmony_ci		for (i = 0; i < BLK_MAX_CDB; i++)
3338c2ecf20Sopenharmony_ci			printk(KERN_CONT "%02x ", scsi_req(failed_command)->cmd[i]);
3348c2ecf20Sopenharmony_ci		printk(KERN_CONT "\"\n");
3358c2ecf20Sopenharmony_ci	}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	/* The SKSV bit specifies validity of the sense_key_specific
3388c2ecf20Sopenharmony_ci	 * in the next two commands. It is bit 7 of the first byte.
3398c2ecf20Sopenharmony_ci	 * In the case of NOT_READY, if SKSV is set the drive can
3408c2ecf20Sopenharmony_ci	 * give us nice ETA readings.
3418c2ecf20Sopenharmony_ci	 */
3428c2ecf20Sopenharmony_ci	if (sense->sense_key == NOT_READY && (sense->sks[0] & 0x80)) {
3438c2ecf20Sopenharmony_ci		int progress = (sense->sks[1] << 8 | sense->sks[2]) * 100;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci		printk(KERN_ERR "  Command is %02d%% complete\n",
3468c2ecf20Sopenharmony_ci				progress / 0xffff);
3478c2ecf20Sopenharmony_ci	}
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	if (sense->sense_key == ILLEGAL_REQUEST &&
3508c2ecf20Sopenharmony_ci	    (sense->sks[0] & 0x80) != 0) {
3518c2ecf20Sopenharmony_ci		printk(KERN_ERR "  Error in %s byte %d",
3528c2ecf20Sopenharmony_ci				(sense->sks[0] & 0x40) != 0 ?
3538c2ecf20Sopenharmony_ci				"command packet" : "command data",
3548c2ecf20Sopenharmony_ci				(sense->sks[1] << 8) + sense->sks[2]);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci		if ((sense->sks[0] & 0x40) != 0)
3578c2ecf20Sopenharmony_ci			printk(KERN_CONT " bit %d", sense->sks[0] & 0x07);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci		printk(KERN_CONT "\n");
3608c2ecf20Sopenharmony_ci	}
3618c2ecf20Sopenharmony_ci}
3628c2ecf20Sopenharmony_ci#endif
363