18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ASCII values for a number of symbolic constants, printing functions, 48c2ecf20Sopenharmony_ci * etc. 58c2ecf20Sopenharmony_ci * Additions for SCSI 2 and Linux 2.2.x by D. Gilbert (990422) 68c2ecf20Sopenharmony_ci * Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 07 3 May 2002) 78c2ecf20Sopenharmony_ci * by D. Gilbert and aeb (20020609) 88c2ecf20Sopenharmony_ci * Updated to SPC-4 T10/1713-D Rev 36g, D. Gilbert 20130701 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/blkdev.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <linux/kernel.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <scsi/scsi.h> 168c2ecf20Sopenharmony_ci#include <scsi/scsi_cmnd.h> 178c2ecf20Sopenharmony_ci#include <scsi/scsi_device.h> 188c2ecf20Sopenharmony_ci#include <scsi/scsi_host.h> 198c2ecf20Sopenharmony_ci#include <scsi/scsi_eh.h> 208c2ecf20Sopenharmony_ci#include <scsi/scsi_dbg.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* Commands with service actions that change the command name */ 238c2ecf20Sopenharmony_ci#define THIRD_PARTY_COPY_OUT 0x83 248c2ecf20Sopenharmony_ci#define THIRD_PARTY_COPY_IN 0x84 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistruct sa_name_list { 278c2ecf20Sopenharmony_ci int opcode; 288c2ecf20Sopenharmony_ci const struct value_name_pair *arr; 298c2ecf20Sopenharmony_ci int arr_sz; 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct value_name_pair { 338c2ecf20Sopenharmony_ci int value; 348c2ecf20Sopenharmony_ci const char * name; 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic const char * cdb_byte0_names[] = { 388c2ecf20Sopenharmony_ci/* 00-03 */ "Test Unit Ready", "Rezero Unit/Rewind", NULL, "Request Sense", 398c2ecf20Sopenharmony_ci/* 04-07 */ "Format Unit/Medium", "Read Block Limits", NULL, 408c2ecf20Sopenharmony_ci "Reassign Blocks", 418c2ecf20Sopenharmony_ci/* 08-0d */ "Read(6)", NULL, "Write(6)", "Seek(6)", NULL, NULL, 428c2ecf20Sopenharmony_ci/* 0e-12 */ NULL, "Read Reverse", "Write Filemarks", "Space", "Inquiry", 438c2ecf20Sopenharmony_ci/* 13-16 */ "Verify(6)", "Recover Buffered Data", "Mode Select(6)", 448c2ecf20Sopenharmony_ci "Reserve(6)", 458c2ecf20Sopenharmony_ci/* 17-1a */ "Release(6)", "Copy", "Erase", "Mode Sense(6)", 468c2ecf20Sopenharmony_ci/* 1b-1d */ "Start/Stop Unit", "Receive Diagnostic", "Send Diagnostic", 478c2ecf20Sopenharmony_ci/* 1e-1f */ "Prevent/Allow Medium Removal", NULL, 488c2ecf20Sopenharmony_ci/* 20-22 */ NULL, NULL, NULL, 498c2ecf20Sopenharmony_ci/* 23-28 */ "Read Format Capacities", "Set Window", 508c2ecf20Sopenharmony_ci "Read Capacity(10)", NULL, NULL, "Read(10)", 518c2ecf20Sopenharmony_ci/* 29-2d */ "Read Generation", "Write(10)", "Seek(10)", "Erase(10)", 528c2ecf20Sopenharmony_ci "Read updated block", 538c2ecf20Sopenharmony_ci/* 2e-31 */ "Write Verify(10)", "Verify(10)", "Search High", "Search Equal", 548c2ecf20Sopenharmony_ci/* 32-34 */ "Search Low", "Set Limits", "Prefetch/Read Position", 558c2ecf20Sopenharmony_ci/* 35-37 */ "Synchronize Cache(10)", "Lock/Unlock Cache(10)", 568c2ecf20Sopenharmony_ci "Read Defect Data(10)", 578c2ecf20Sopenharmony_ci/* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer", 588c2ecf20Sopenharmony_ci "Read Buffer", 598c2ecf20Sopenharmony_ci/* 3d-3f */ "Update Block", "Read Long(10)", "Write Long(10)", 608c2ecf20Sopenharmony_ci/* 40-41 */ "Change Definition", "Write Same(10)", 618c2ecf20Sopenharmony_ci/* 42-48 */ "Unmap/Read sub-channel", "Read TOC/PMA/ATIP", 628c2ecf20Sopenharmony_ci "Read density support", "Play audio(10)", "Get configuration", 638c2ecf20Sopenharmony_ci "Play audio msf", "Sanitize/Play audio track/index", 648c2ecf20Sopenharmony_ci/* 49-4f */ "Play track relative(10)", "Get event status notification", 658c2ecf20Sopenharmony_ci "Pause/resume", "Log Select", "Log Sense", "Stop play/scan", 668c2ecf20Sopenharmony_ci NULL, 678c2ecf20Sopenharmony_ci/* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info", 688c2ecf20Sopenharmony_ci "Reserve track", "Send OPC info", "Mode Select(10)", 698c2ecf20Sopenharmony_ci/* 56-5b */ "Reserve(10)", "Release(10)", "Repair track", "Read master cue", 708c2ecf20Sopenharmony_ci "Mode Sense(10)", "Close track/session", 718c2ecf20Sopenharmony_ci/* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in", 728c2ecf20Sopenharmony_ci "Persistent reserve out", 738c2ecf20Sopenharmony_ci/* 60-67 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 748c2ecf20Sopenharmony_ci/* 68-6f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 758c2ecf20Sopenharmony_ci/* 70-77 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 768c2ecf20Sopenharmony_ci/* 78-7f */ NULL, NULL, NULL, NULL, NULL, NULL, "Extended CDB", 778c2ecf20Sopenharmony_ci "Variable length", 788c2ecf20Sopenharmony_ci/* 80-84 */ "Xdwrite(16)", "Rebuild(16)", "Regenerate(16)", 798c2ecf20Sopenharmony_ci "Third party copy out", "Third party copy in", 808c2ecf20Sopenharmony_ci/* 85-89 */ "ATA command pass through(16)", "Access control in", 818c2ecf20Sopenharmony_ci "Access control out", "Read(16)", "Compare and Write", 828c2ecf20Sopenharmony_ci/* 8a-8f */ "Write(16)", "ORWrite", "Read attributes", "Write attributes", 838c2ecf20Sopenharmony_ci "Write and verify(16)", "Verify(16)", 848c2ecf20Sopenharmony_ci/* 90-94 */ "Pre-fetch(16)", "Synchronize cache(16)", 858c2ecf20Sopenharmony_ci "Lock/unlock cache(16)", "Write same(16)", NULL, 868c2ecf20Sopenharmony_ci/* 95-99 */ NULL, NULL, NULL, NULL, NULL, 878c2ecf20Sopenharmony_ci/* 9a-9f */ NULL, NULL, NULL, "Service action bidirectional", 888c2ecf20Sopenharmony_ci "Service action in(16)", "Service action out(16)", 898c2ecf20Sopenharmony_ci/* a0-a5 */ "Report luns", "ATA command pass through(12)/Blank", 908c2ecf20Sopenharmony_ci "Security protocol in", "Maintenance in", "Maintenance out", 918c2ecf20Sopenharmony_ci "Move medium/play audio(12)", 928c2ecf20Sopenharmony_ci/* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)", 938c2ecf20Sopenharmony_ci "Play track relative(12)", 948c2ecf20Sopenharmony_ci/* aa-ae */ "Write(12)", NULL, "Erase(12), Get Performance", 958c2ecf20Sopenharmony_ci "Read DVD structure", "Write and verify(12)", 968c2ecf20Sopenharmony_ci/* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)", 978c2ecf20Sopenharmony_ci/* b2-b4 */ "Search data low(12)", "Set limits(12)", 988c2ecf20Sopenharmony_ci "Read element status attached", 998c2ecf20Sopenharmony_ci/* b5-b6 */ "Security protocol out", "Send volume tag, set streaming", 1008c2ecf20Sopenharmony_ci/* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf", 1018c2ecf20Sopenharmony_ci/* ba-bc */ "Redundancy group (in), Scan", 1028c2ecf20Sopenharmony_ci "Redundancy group (out), Set cd-rom speed", "Spare (in), Play cd", 1038c2ecf20Sopenharmony_ci/* bd-bf */ "Spare (out), Mechanism status", "Volume set (in), Read cd", 1048c2ecf20Sopenharmony_ci "Volume set (out), Send DVD structure", 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic const struct value_name_pair maint_in_arr[] = { 1088c2ecf20Sopenharmony_ci {0x5, "Report identifying information"}, 1098c2ecf20Sopenharmony_ci {0xa, "Report target port groups"}, 1108c2ecf20Sopenharmony_ci {0xb, "Report aliases"}, 1118c2ecf20Sopenharmony_ci {0xc, "Report supported operation codes"}, 1128c2ecf20Sopenharmony_ci {0xd, "Report supported task management functions"}, 1138c2ecf20Sopenharmony_ci {0xe, "Report priority"}, 1148c2ecf20Sopenharmony_ci {0xf, "Report timestamp"}, 1158c2ecf20Sopenharmony_ci {0x10, "Management protocol in"}, 1168c2ecf20Sopenharmony_ci}; 1178c2ecf20Sopenharmony_ci#define MAINT_IN_SZ ARRAY_SIZE(maint_in_arr) 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic const struct value_name_pair maint_out_arr[] = { 1208c2ecf20Sopenharmony_ci {0x6, "Set identifying information"}, 1218c2ecf20Sopenharmony_ci {0xa, "Set target port groups"}, 1228c2ecf20Sopenharmony_ci {0xb, "Change aliases"}, 1238c2ecf20Sopenharmony_ci {0xc, "Remove I_T nexus"}, 1248c2ecf20Sopenharmony_ci {0xe, "Set priority"}, 1258c2ecf20Sopenharmony_ci {0xf, "Set timestamp"}, 1268c2ecf20Sopenharmony_ci {0x10, "Management protocol out"}, 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci#define MAINT_OUT_SZ ARRAY_SIZE(maint_out_arr) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistatic const struct value_name_pair serv_in12_arr[] = { 1318c2ecf20Sopenharmony_ci {0x1, "Read media serial number"}, 1328c2ecf20Sopenharmony_ci}; 1338c2ecf20Sopenharmony_ci#define SERV_IN12_SZ ARRAY_SIZE(serv_in12_arr) 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic const struct value_name_pair serv_out12_arr[] = { 1368c2ecf20Sopenharmony_ci {-1, "dummy entry"}, 1378c2ecf20Sopenharmony_ci}; 1388c2ecf20Sopenharmony_ci#define SERV_OUT12_SZ ARRAY_SIZE(serv_out12_arr) 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistatic const struct value_name_pair serv_bidi_arr[] = { 1418c2ecf20Sopenharmony_ci {-1, "dummy entry"}, 1428c2ecf20Sopenharmony_ci}; 1438c2ecf20Sopenharmony_ci#define SERV_BIDI_SZ ARRAY_SIZE(serv_bidi_arr) 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistatic const struct value_name_pair serv_in16_arr[] = { 1468c2ecf20Sopenharmony_ci {0x10, "Read capacity(16)"}, 1478c2ecf20Sopenharmony_ci {0x11, "Read long(16)"}, 1488c2ecf20Sopenharmony_ci {0x12, "Get LBA status"}, 1498c2ecf20Sopenharmony_ci {0x13, "Report referrals"}, 1508c2ecf20Sopenharmony_ci}; 1518c2ecf20Sopenharmony_ci#define SERV_IN16_SZ ARRAY_SIZE(serv_in16_arr) 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic const struct value_name_pair serv_out16_arr[] = { 1548c2ecf20Sopenharmony_ci {0x11, "Write long(16)"}, 1558c2ecf20Sopenharmony_ci {0x1f, "Notify data transfer device(16)"}, 1568c2ecf20Sopenharmony_ci}; 1578c2ecf20Sopenharmony_ci#define SERV_OUT16_SZ ARRAY_SIZE(serv_out16_arr) 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic const struct value_name_pair pr_in_arr[] = { 1608c2ecf20Sopenharmony_ci {0x0, "Persistent reserve in, read keys"}, 1618c2ecf20Sopenharmony_ci {0x1, "Persistent reserve in, read reservation"}, 1628c2ecf20Sopenharmony_ci {0x2, "Persistent reserve in, report capabilities"}, 1638c2ecf20Sopenharmony_ci {0x3, "Persistent reserve in, read full status"}, 1648c2ecf20Sopenharmony_ci}; 1658c2ecf20Sopenharmony_ci#define PR_IN_SZ ARRAY_SIZE(pr_in_arr) 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic const struct value_name_pair pr_out_arr[] = { 1688c2ecf20Sopenharmony_ci {0x0, "Persistent reserve out, register"}, 1698c2ecf20Sopenharmony_ci {0x1, "Persistent reserve out, reserve"}, 1708c2ecf20Sopenharmony_ci {0x2, "Persistent reserve out, release"}, 1718c2ecf20Sopenharmony_ci {0x3, "Persistent reserve out, clear"}, 1728c2ecf20Sopenharmony_ci {0x4, "Persistent reserve out, preempt"}, 1738c2ecf20Sopenharmony_ci {0x5, "Persistent reserve out, preempt and abort"}, 1748c2ecf20Sopenharmony_ci {0x6, "Persistent reserve out, register and ignore existing key"}, 1758c2ecf20Sopenharmony_ci {0x7, "Persistent reserve out, register and move"}, 1768c2ecf20Sopenharmony_ci}; 1778c2ecf20Sopenharmony_ci#define PR_OUT_SZ ARRAY_SIZE(pr_out_arr) 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci/* SPC-4 rev 34 renamed the Extended Copy opcode to Third Party Copy Out. 1808c2ecf20Sopenharmony_ci LID1 (List Identifier length: 1 byte) is the Extended Copy found in SPC-2 1818c2ecf20Sopenharmony_ci and SPC-3 */ 1828c2ecf20Sopenharmony_cistatic const struct value_name_pair tpc_out_arr[] = { 1838c2ecf20Sopenharmony_ci {0x0, "Extended copy(LID1)"}, 1848c2ecf20Sopenharmony_ci {0x1, "Extended copy(LID4)"}, 1858c2ecf20Sopenharmony_ci {0x10, "Populate token"}, 1868c2ecf20Sopenharmony_ci {0x11, "Write using token"}, 1878c2ecf20Sopenharmony_ci {0x1c, "Copy operation abort"}, 1888c2ecf20Sopenharmony_ci}; 1898c2ecf20Sopenharmony_ci#define TPC_OUT_SZ ARRAY_SIZE(tpc_out_arr) 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistatic const struct value_name_pair tpc_in_arr[] = { 1928c2ecf20Sopenharmony_ci {0x0, "Receive copy status(LID1)"}, 1938c2ecf20Sopenharmony_ci {0x1, "Receive copy data(LID1)"}, 1948c2ecf20Sopenharmony_ci {0x3, "Receive copy operating parameters"}, 1958c2ecf20Sopenharmony_ci {0x4, "Receive copy failure details(LID1)"}, 1968c2ecf20Sopenharmony_ci {0x5, "Receive copy status(LID4)"}, 1978c2ecf20Sopenharmony_ci {0x6, "Receive copy data(LID4)"}, 1988c2ecf20Sopenharmony_ci {0x7, "Receive ROD token information"}, 1998c2ecf20Sopenharmony_ci {0x8, "Report all ROD tokens"}, 2008c2ecf20Sopenharmony_ci}; 2018c2ecf20Sopenharmony_ci#define TPC_IN_SZ ARRAY_SIZE(tpc_in_arr) 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistatic const struct value_name_pair variable_length_arr[] = { 2058c2ecf20Sopenharmony_ci {0x1, "Rebuild(32)"}, 2068c2ecf20Sopenharmony_ci {0x2, "Regenerate(32)"}, 2078c2ecf20Sopenharmony_ci {0x3, "Xdread(32)"}, 2088c2ecf20Sopenharmony_ci {0x4, "Xdwrite(32)"}, 2098c2ecf20Sopenharmony_ci {0x5, "Xdwrite extended(32)"}, 2108c2ecf20Sopenharmony_ci {0x6, "Xpwrite(32)"}, 2118c2ecf20Sopenharmony_ci {0x7, "Xdwriteread(32)"}, 2128c2ecf20Sopenharmony_ci {0x8, "Xdwrite extended(64)"}, 2138c2ecf20Sopenharmony_ci {0x9, "Read(32)"}, 2148c2ecf20Sopenharmony_ci {0xa, "Verify(32)"}, 2158c2ecf20Sopenharmony_ci {0xb, "Write(32)"}, 2168c2ecf20Sopenharmony_ci {0xc, "Write an verify(32)"}, 2178c2ecf20Sopenharmony_ci {0xd, "Write same(32)"}, 2188c2ecf20Sopenharmony_ci {0x8801, "Format OSD"}, 2198c2ecf20Sopenharmony_ci {0x8802, "Create (osd)"}, 2208c2ecf20Sopenharmony_ci {0x8803, "List (osd)"}, 2218c2ecf20Sopenharmony_ci {0x8805, "Read (osd)"}, 2228c2ecf20Sopenharmony_ci {0x8806, "Write (osd)"}, 2238c2ecf20Sopenharmony_ci {0x8807, "Append (osd)"}, 2248c2ecf20Sopenharmony_ci {0x8808, "Flush (osd)"}, 2258c2ecf20Sopenharmony_ci {0x880a, "Remove (osd)"}, 2268c2ecf20Sopenharmony_ci {0x880b, "Create partition (osd)"}, 2278c2ecf20Sopenharmony_ci {0x880c, "Remove partition (osd)"}, 2288c2ecf20Sopenharmony_ci {0x880e, "Get attributes (osd)"}, 2298c2ecf20Sopenharmony_ci {0x880f, "Set attributes (osd)"}, 2308c2ecf20Sopenharmony_ci {0x8812, "Create and write (osd)"}, 2318c2ecf20Sopenharmony_ci {0x8815, "Create collection (osd)"}, 2328c2ecf20Sopenharmony_ci {0x8816, "Remove collection (osd)"}, 2338c2ecf20Sopenharmony_ci {0x8817, "List collection (osd)"}, 2348c2ecf20Sopenharmony_ci {0x8818, "Set key (osd)"}, 2358c2ecf20Sopenharmony_ci {0x8819, "Set master key (osd)"}, 2368c2ecf20Sopenharmony_ci {0x881a, "Flush collection (osd)"}, 2378c2ecf20Sopenharmony_ci {0x881b, "Flush partition (osd)"}, 2388c2ecf20Sopenharmony_ci {0x881c, "Flush OSD"}, 2398c2ecf20Sopenharmony_ci {0x8f7e, "Perform SCSI command (osd)"}, 2408c2ecf20Sopenharmony_ci {0x8f7f, "Perform task management function (osd)"}, 2418c2ecf20Sopenharmony_ci}; 2428c2ecf20Sopenharmony_ci#define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr) 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_cistatic struct sa_name_list sa_names_arr[] = { 2458c2ecf20Sopenharmony_ci {VARIABLE_LENGTH_CMD, variable_length_arr, VARIABLE_LENGTH_SZ}, 2468c2ecf20Sopenharmony_ci {MAINTENANCE_IN, maint_in_arr, MAINT_IN_SZ}, 2478c2ecf20Sopenharmony_ci {MAINTENANCE_OUT, maint_out_arr, MAINT_OUT_SZ}, 2488c2ecf20Sopenharmony_ci {PERSISTENT_RESERVE_IN, pr_in_arr, PR_IN_SZ}, 2498c2ecf20Sopenharmony_ci {PERSISTENT_RESERVE_OUT, pr_out_arr, PR_OUT_SZ}, 2508c2ecf20Sopenharmony_ci {SERVICE_ACTION_IN_12, serv_in12_arr, SERV_IN12_SZ}, 2518c2ecf20Sopenharmony_ci {SERVICE_ACTION_OUT_12, serv_out12_arr, SERV_OUT12_SZ}, 2528c2ecf20Sopenharmony_ci {SERVICE_ACTION_BIDIRECTIONAL, serv_bidi_arr, SERV_BIDI_SZ}, 2538c2ecf20Sopenharmony_ci {SERVICE_ACTION_IN_16, serv_in16_arr, SERV_IN16_SZ}, 2548c2ecf20Sopenharmony_ci {SERVICE_ACTION_OUT_16, serv_out16_arr, SERV_OUT16_SZ}, 2558c2ecf20Sopenharmony_ci {THIRD_PARTY_COPY_IN, tpc_in_arr, TPC_IN_SZ}, 2568c2ecf20Sopenharmony_ci {THIRD_PARTY_COPY_OUT, tpc_out_arr, TPC_OUT_SZ}, 2578c2ecf20Sopenharmony_ci {0, NULL, 0}, 2588c2ecf20Sopenharmony_ci}; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_cibool scsi_opcode_sa_name(int opcode, int service_action, 2618c2ecf20Sopenharmony_ci const char **cdb_name, const char **sa_name) 2628c2ecf20Sopenharmony_ci{ 2638c2ecf20Sopenharmony_ci struct sa_name_list *sa_name_ptr; 2648c2ecf20Sopenharmony_ci const struct value_name_pair *arr = NULL; 2658c2ecf20Sopenharmony_ci int arr_sz, k; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci *cdb_name = NULL; 2688c2ecf20Sopenharmony_ci if (opcode >= VENDOR_SPECIFIC_CDB) 2698c2ecf20Sopenharmony_ci return false; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci if (opcode < ARRAY_SIZE(cdb_byte0_names)) 2728c2ecf20Sopenharmony_ci *cdb_name = cdb_byte0_names[opcode]; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci for (sa_name_ptr = sa_names_arr; sa_name_ptr->arr; ++sa_name_ptr) { 2758c2ecf20Sopenharmony_ci if (sa_name_ptr->opcode == opcode) { 2768c2ecf20Sopenharmony_ci arr = sa_name_ptr->arr; 2778c2ecf20Sopenharmony_ci arr_sz = sa_name_ptr->arr_sz; 2788c2ecf20Sopenharmony_ci break; 2798c2ecf20Sopenharmony_ci } 2808c2ecf20Sopenharmony_ci } 2818c2ecf20Sopenharmony_ci if (!arr) 2828c2ecf20Sopenharmony_ci return false; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci for (k = 0; k < arr_sz; ++k, ++arr) { 2858c2ecf20Sopenharmony_ci if (service_action == arr->value) 2868c2ecf20Sopenharmony_ci break; 2878c2ecf20Sopenharmony_ci } 2888c2ecf20Sopenharmony_ci if (k < arr_sz) 2898c2ecf20Sopenharmony_ci *sa_name = arr->name; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci return true; 2928c2ecf20Sopenharmony_ci} 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_cistruct error_info { 2958c2ecf20Sopenharmony_ci unsigned short code12; /* 0x0302 looks better than 0x03,0x02 */ 2968c2ecf20Sopenharmony_ci unsigned short size; 2978c2ecf20Sopenharmony_ci}; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci/* 3008c2ecf20Sopenharmony_ci * There are 700+ entries in this table. To save space, we don't store 3018c2ecf20Sopenharmony_ci * (code, pointer) pairs, which would make sizeof(struct 3028c2ecf20Sopenharmony_ci * error_info)==16 on 64 bits. Rather, the second element just stores 3038c2ecf20Sopenharmony_ci * the size (including \0) of the corresponding string, and we use the 3048c2ecf20Sopenharmony_ci * sum of these to get the appropriate offset into additional_text 3058c2ecf20Sopenharmony_ci * defined below. This approach saves 12 bytes per entry. 3068c2ecf20Sopenharmony_ci */ 3078c2ecf20Sopenharmony_cistatic const struct error_info additional[] = 3088c2ecf20Sopenharmony_ci{ 3098c2ecf20Sopenharmony_ci#define SENSE_CODE(c, s) {c, sizeof(s)}, 3108c2ecf20Sopenharmony_ci#include "sense_codes.h" 3118c2ecf20Sopenharmony_ci#undef SENSE_CODE 3128c2ecf20Sopenharmony_ci}; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistatic const char *additional_text = 3158c2ecf20Sopenharmony_ci#define SENSE_CODE(c, s) s "\0" 3168c2ecf20Sopenharmony_ci#include "sense_codes.h" 3178c2ecf20Sopenharmony_ci#undef SENSE_CODE 3188c2ecf20Sopenharmony_ci ; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_cistruct error_info2 { 3218c2ecf20Sopenharmony_ci unsigned char code1, code2_min, code2_max; 3228c2ecf20Sopenharmony_ci const char * str; 3238c2ecf20Sopenharmony_ci const char * fmt; 3248c2ecf20Sopenharmony_ci}; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_cistatic const struct error_info2 additional2[] = 3278c2ecf20Sopenharmony_ci{ 3288c2ecf20Sopenharmony_ci {0x40, 0x00, 0x7f, "Ram failure", ""}, 3298c2ecf20Sopenharmony_ci {0x40, 0x80, 0xff, "Diagnostic failure on component", ""}, 3308c2ecf20Sopenharmony_ci {0x41, 0x00, 0xff, "Data path failure", ""}, 3318c2ecf20Sopenharmony_ci {0x42, 0x00, 0xff, "Power-on or self-test failure", ""}, 3328c2ecf20Sopenharmony_ci {0x4D, 0x00, 0xff, "Tagged overlapped commands", "task tag "}, 3338c2ecf20Sopenharmony_ci {0x70, 0x00, 0xff, "Decompression exception", "short algorithm id of "}, 3348c2ecf20Sopenharmony_ci {0, 0, 0, NULL, NULL} 3358c2ecf20Sopenharmony_ci}; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci/* description of the sense key values */ 3388c2ecf20Sopenharmony_cistatic const char * const snstext[] = { 3398c2ecf20Sopenharmony_ci "No Sense", /* 0: There is no sense information */ 3408c2ecf20Sopenharmony_ci "Recovered Error", /* 1: The last command completed successfully 3418c2ecf20Sopenharmony_ci but used error correction */ 3428c2ecf20Sopenharmony_ci "Not Ready", /* 2: The addressed target is not ready */ 3438c2ecf20Sopenharmony_ci "Medium Error", /* 3: Data error detected on the medium */ 3448c2ecf20Sopenharmony_ci "Hardware Error", /* 4: Controller or device failure */ 3458c2ecf20Sopenharmony_ci "Illegal Request", /* 5: Error in request */ 3468c2ecf20Sopenharmony_ci "Unit Attention", /* 6: Removable medium was changed, or 3478c2ecf20Sopenharmony_ci the target has been reset, or ... */ 3488c2ecf20Sopenharmony_ci "Data Protect", /* 7: Access to the data is blocked */ 3498c2ecf20Sopenharmony_ci "Blank Check", /* 8: Reached unexpected written or unwritten 3508c2ecf20Sopenharmony_ci region of the medium */ 3518c2ecf20Sopenharmony_ci "Vendor Specific(9)", 3528c2ecf20Sopenharmony_ci "Copy Aborted", /* A: COPY or COMPARE was aborted */ 3538c2ecf20Sopenharmony_ci "Aborted Command", /* B: The target aborted the command */ 3548c2ecf20Sopenharmony_ci "Equal", /* C: A SEARCH DATA command found data equal, 3558c2ecf20Sopenharmony_ci reserved in SPC-4 rev 36 */ 3568c2ecf20Sopenharmony_ci "Volume Overflow", /* D: Medium full with still data to be written */ 3578c2ecf20Sopenharmony_ci "Miscompare", /* E: Source data and data on the medium 3588c2ecf20Sopenharmony_ci do not agree */ 3598c2ecf20Sopenharmony_ci "Completed", /* F: command completed sense data reported, 3608c2ecf20Sopenharmony_ci may occur for successful command */ 3618c2ecf20Sopenharmony_ci}; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci/* Get sense key string or NULL if not available */ 3648c2ecf20Sopenharmony_ciconst char * 3658c2ecf20Sopenharmony_ciscsi_sense_key_string(unsigned char key) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci if (key < ARRAY_SIZE(snstext)) 3688c2ecf20Sopenharmony_ci return snstext[key]; 3698c2ecf20Sopenharmony_ci return NULL; 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ciEXPORT_SYMBOL(scsi_sense_key_string); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci/* 3748c2ecf20Sopenharmony_ci * Get additional sense code string or NULL if not available. 3758c2ecf20Sopenharmony_ci * This string may contain a "%x" and should be printed with ascq as arg. 3768c2ecf20Sopenharmony_ci */ 3778c2ecf20Sopenharmony_ciconst char * 3788c2ecf20Sopenharmony_ciscsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt) 3798c2ecf20Sopenharmony_ci{ 3808c2ecf20Sopenharmony_ci int i; 3818c2ecf20Sopenharmony_ci unsigned short code = ((asc << 8) | ascq); 3828c2ecf20Sopenharmony_ci unsigned offset = 0; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci *fmt = NULL; 3858c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(additional); i++) { 3868c2ecf20Sopenharmony_ci if (additional[i].code12 == code) 3878c2ecf20Sopenharmony_ci return additional_text + offset; 3888c2ecf20Sopenharmony_ci offset += additional[i].size; 3898c2ecf20Sopenharmony_ci } 3908c2ecf20Sopenharmony_ci for (i = 0; additional2[i].fmt; i++) { 3918c2ecf20Sopenharmony_ci if (additional2[i].code1 == asc && 3928c2ecf20Sopenharmony_ci ascq >= additional2[i].code2_min && 3938c2ecf20Sopenharmony_ci ascq <= additional2[i].code2_max) { 3948c2ecf20Sopenharmony_ci *fmt = additional2[i].fmt; 3958c2ecf20Sopenharmony_ci return additional2[i].str; 3968c2ecf20Sopenharmony_ci } 3978c2ecf20Sopenharmony_ci } 3988c2ecf20Sopenharmony_ci return NULL; 3998c2ecf20Sopenharmony_ci} 4008c2ecf20Sopenharmony_ciEXPORT_SYMBOL(scsi_extd_sense_format); 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_cistatic const char * const hostbyte_table[]={ 4038c2ecf20Sopenharmony_ci"DID_OK", "DID_NO_CONNECT", "DID_BUS_BUSY", "DID_TIME_OUT", "DID_BAD_TARGET", 4048c2ecf20Sopenharmony_ci"DID_ABORT", "DID_PARITY", "DID_ERROR", "DID_RESET", "DID_BAD_INTR", 4058c2ecf20Sopenharmony_ci"DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE", 4068c2ecf20Sopenharmony_ci"DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE", 4078c2ecf20Sopenharmony_ci"DID_NEXUS_FAILURE", "DID_ALLOC_FAILURE", "DID_MEDIUM_ERROR" }; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_cistatic const char * const driverbyte_table[]={ 4108c2ecf20Sopenharmony_ci"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR", 4118c2ecf20Sopenharmony_ci"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"}; 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ciconst char *scsi_hostbyte_string(int result) 4148c2ecf20Sopenharmony_ci{ 4158c2ecf20Sopenharmony_ci const char *hb_string = NULL; 4168c2ecf20Sopenharmony_ci int hb = host_byte(result); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci if (hb < ARRAY_SIZE(hostbyte_table)) 4198c2ecf20Sopenharmony_ci hb_string = hostbyte_table[hb]; 4208c2ecf20Sopenharmony_ci return hb_string; 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ciEXPORT_SYMBOL(scsi_hostbyte_string); 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ciconst char *scsi_driverbyte_string(int result) 4258c2ecf20Sopenharmony_ci{ 4268c2ecf20Sopenharmony_ci const char *db_string = NULL; 4278c2ecf20Sopenharmony_ci int db = driver_byte(result); 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci if (db < ARRAY_SIZE(driverbyte_table)) 4308c2ecf20Sopenharmony_ci db_string = driverbyte_table[db]; 4318c2ecf20Sopenharmony_ci return db_string; 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ciEXPORT_SYMBOL(scsi_driverbyte_string); 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci#define scsi_mlreturn_name(result) { result, #result } 4368c2ecf20Sopenharmony_cistatic const struct value_name_pair scsi_mlreturn_arr[] = { 4378c2ecf20Sopenharmony_ci scsi_mlreturn_name(NEEDS_RETRY), 4388c2ecf20Sopenharmony_ci scsi_mlreturn_name(SUCCESS), 4398c2ecf20Sopenharmony_ci scsi_mlreturn_name(FAILED), 4408c2ecf20Sopenharmony_ci scsi_mlreturn_name(QUEUED), 4418c2ecf20Sopenharmony_ci scsi_mlreturn_name(SOFT_ERROR), 4428c2ecf20Sopenharmony_ci scsi_mlreturn_name(ADD_TO_MLQUEUE), 4438c2ecf20Sopenharmony_ci scsi_mlreturn_name(TIMEOUT_ERROR), 4448c2ecf20Sopenharmony_ci scsi_mlreturn_name(SCSI_RETURN_NOT_HANDLED), 4458c2ecf20Sopenharmony_ci scsi_mlreturn_name(FAST_IO_FAIL) 4468c2ecf20Sopenharmony_ci}; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ciconst char *scsi_mlreturn_string(int result) 4498c2ecf20Sopenharmony_ci{ 4508c2ecf20Sopenharmony_ci const struct value_name_pair *arr = scsi_mlreturn_arr; 4518c2ecf20Sopenharmony_ci int k; 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci for (k = 0; k < ARRAY_SIZE(scsi_mlreturn_arr); ++k, ++arr) { 4548c2ecf20Sopenharmony_ci if (result == arr->value) 4558c2ecf20Sopenharmony_ci return arr->name; 4568c2ecf20Sopenharmony_ci } 4578c2ecf20Sopenharmony_ci return NULL; 4588c2ecf20Sopenharmony_ci} 4598c2ecf20Sopenharmony_ciEXPORT_SYMBOL(scsi_mlreturn_string); 460