Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * ASCII values for a number of symbolic constants, printing functions, |
| 3 | * etc. |
| 4 | * Additions for SCSI 2 and Linux 2.2.x by D. Gilbert (990422) |
| 5 | * Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 07 3 May 2002) |
| 6 | * by D. Gilbert and aeb (20020609) |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 7 | * Updated to SPC-4 T10/1713-D Rev 36g, D. Gilbert 20130701 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/blkdev.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> |
| 13 | |
| 14 | #include <scsi/scsi.h> |
Christoph Hellwig | beb4048 | 2006-06-10 18:01:03 +0200 | [diff] [blame] | 15 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <scsi/scsi_device.h> |
| 17 | #include <scsi/scsi_host.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <scsi/scsi_eh.h> |
Adrian Bunk | de540a5 | 2005-08-20 21:27:27 +0200 | [diff] [blame] | 19 | #include <scsi/scsi_dbg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | /* Commands with service actions that change the command name */ |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 22 | #define THIRD_PARTY_COPY_OUT 0x83 |
| 23 | #define THIRD_PARTY_COPY_IN 0x84 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Hannes Reinecke | 234d677 | 2014-10-24 14:26:55 +0200 | [diff] [blame] | 25 | struct sa_name_list { |
| 26 | int opcode; |
| 27 | const struct value_name_pair *arr; |
| 28 | int arr_sz; |
| 29 | }; |
| 30 | |
| 31 | struct value_name_pair { |
| 32 | int value; |
| 33 | const char * name; |
| 34 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static const char * cdb_byte0_names[] = { |
| 37 | /* 00-03 */ "Test Unit Ready", "Rezero Unit/Rewind", NULL, "Request Sense", |
| 38 | /* 04-07 */ "Format Unit/Medium", "Read Block Limits", NULL, |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 39 | "Reassign Blocks", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 40 | /* 08-0d */ "Read(6)", NULL, "Write(6)", "Seek(6)", NULL, NULL, |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 41 | /* 0e-12 */ NULL, "Read Reverse", "Write Filemarks", "Space", "Inquiry", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 42 | /* 13-16 */ "Verify(6)", "Recover Buffered Data", "Mode Select(6)", |
| 43 | "Reserve(6)", |
| 44 | /* 17-1a */ "Release(6)", "Copy", "Erase", "Mode Sense(6)", |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 45 | /* 1b-1d */ "Start/Stop Unit", "Receive Diagnostic", "Send Diagnostic", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* 1e-1f */ "Prevent/Allow Medium Removal", NULL, |
| 47 | /* 20-22 */ NULL, NULL, NULL, |
| 48 | /* 23-28 */ "Read Format Capacities", "Set Window", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 49 | "Read Capacity(10)", NULL, NULL, "Read(10)", |
| 50 | /* 29-2d */ "Read Generation", "Write(10)", "Seek(10)", "Erase(10)", |
| 51 | "Read updated block", |
| 52 | /* 2e-31 */ "Write Verify(10)", "Verify(10)", "Search High", "Search Equal", |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 53 | /* 32-34 */ "Search Low", "Set Limits", "Prefetch/Read Position", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 54 | /* 35-37 */ "Synchronize Cache(10)", "Lock/Unlock Cache(10)", |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 55 | "Read Defect Data(10)", |
| 56 | /* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer", |
| 57 | "Read Buffer", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 58 | /* 3d-3f */ "Update Block", "Read Long(10)", "Write Long(10)", |
| 59 | /* 40-41 */ "Change Definition", "Write Same(10)", |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 60 | /* 42-48 */ "Unmap/Read sub-channel", "Read TOC/PMA/ATIP", |
| 61 | "Read density support", "Play audio(10)", "Get configuration", |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 62 | "Play audio msf", "Sanitize/Play audio track/index", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 63 | /* 49-4f */ "Play track relative(10)", "Get event status notification", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | "Pause/resume", "Log Select", "Log Sense", "Stop play/scan", |
| 65 | NULL, |
| 66 | /* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 67 | "Reserve track", "Send OPC info", "Mode Select(10)", |
| 68 | /* 56-5b */ "Reserve(10)", "Release(10)", "Repair track", "Read master cue", |
| 69 | "Mode Sense(10)", "Close track/session", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in", |
| 71 | "Persistent reserve out", |
| 72 | /* 60-67 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 73 | /* 68-6f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 74 | /* 70-77 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 75 | /* 78-7f */ NULL, NULL, NULL, NULL, NULL, NULL, "Extended CDB", |
| 76 | "Variable length", |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 77 | /* 80-84 */ "Xdwrite(16)", "Rebuild(16)", "Regenerate(16)", |
| 78 | "Third party copy out", "Third party copy in", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 79 | /* 85-89 */ "ATA command pass through(16)", "Access control in", |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 80 | "Access control out", "Read(16)", "Compare and Write", |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 81 | /* 8a-8f */ "Write(16)", "ORWrite", "Read attributes", "Write attributes", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 82 | "Write and verify(16)", "Verify(16)", |
| 83 | /* 90-94 */ "Pre-fetch(16)", "Synchronize cache(16)", |
| 84 | "Lock/unlock cache(16)", "Write same(16)", NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* 95-99 */ NULL, NULL, NULL, NULL, NULL, |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 86 | /* 9a-9f */ NULL, NULL, NULL, "Service action bidirectional", |
| 87 | "Service action in(16)", "Service action out(16)", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 88 | /* a0-a5 */ "Report luns", "ATA command pass through(12)/Blank", |
| 89 | "Security protocol in", "Maintenance in", "Maintenance out", |
| 90 | "Move medium/play audio(12)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)", |
| 92 | "Play track relative(12)", |
| 93 | /* aa-ae */ "Write(12)", NULL, "Erase(12), Get Performance", |
| 94 | "Read DVD structure", "Write and verify(12)", |
| 95 | /* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)", |
| 96 | /* b2-b4 */ "Search data low(12)", "Set limits(12)", |
| 97 | "Read element status attached", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 98 | /* b5-b6 */ "Security protocol out", "Send volume tag, set streaming", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf", |
| 100 | /* ba-bc */ "Redundancy group (in), Scan", |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 101 | "Redundancy group (out), Set cd-rom speed", "Spare (in), Play cd", |
| 102 | /* bd-bf */ "Spare (out), Mechanism status", "Volume set (in), Read cd", |
| 103 | "Volume set (out), Send DVD structure", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | static const struct value_name_pair maint_in_arr[] = { |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 107 | {0x5, "Report identifying information"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | {0xa, "Report target port groups"}, |
| 109 | {0xb, "Report aliases"}, |
| 110 | {0xc, "Report supported operation codes"}, |
| 111 | {0xd, "Report supported task management functions"}, |
| 112 | {0xe, "Report priority"}, |
Douglas Gilbert | a507c6a | 2006-07-02 13:48:10 -0400 | [diff] [blame] | 113 | {0xf, "Report timestamp"}, |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 114 | {0x10, "Management protocol in"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 116 | #define MAINT_IN_SZ ARRAY_SIZE(maint_in_arr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | static const struct value_name_pair maint_out_arr[] = { |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 119 | {0x6, "Set identifying information"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | {0xa, "Set target port groups"}, |
| 121 | {0xb, "Change aliases"}, |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 122 | {0xc, "Remove I_T nexus"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | {0xe, "Set priority"}, |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 124 | {0xf, "Set timestamp"}, |
| 125 | {0x10, "Management protocol out"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | }; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 127 | #define MAINT_OUT_SZ ARRAY_SIZE(maint_out_arr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | static const struct value_name_pair serv_in12_arr[] = { |
| 130 | {0x1, "Read media serial number"}, |
| 131 | }; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 132 | #define SERV_IN12_SZ ARRAY_SIZE(serv_in12_arr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | static const struct value_name_pair serv_out12_arr[] = { |
| 135 | {-1, "dummy entry"}, |
| 136 | }; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 137 | #define SERV_OUT12_SZ ARRAY_SIZE(serv_out12_arr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 139 | static const struct value_name_pair serv_bidi_arr[] = { |
| 140 | {-1, "dummy entry"}, |
| 141 | }; |
| 142 | #define SERV_BIDI_SZ ARRAY_SIZE(serv_bidi_arr) |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | static const struct value_name_pair serv_in16_arr[] = { |
| 145 | {0x10, "Read capacity(16)"}, |
| 146 | {0x11, "Read long(16)"}, |
Martin K. Petersen | f57e450 | 2009-10-15 14:43:23 -0400 | [diff] [blame] | 147 | {0x12, "Get LBA status"}, |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 148 | {0x13, "Report referrals"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | }; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 150 | #define SERV_IN16_SZ ARRAY_SIZE(serv_in16_arr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | static const struct value_name_pair serv_out16_arr[] = { |
| 153 | {0x11, "Write long(16)"}, |
| 154 | {0x1f, "Notify data transfer device(16)"}, |
| 155 | }; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 156 | #define SERV_OUT16_SZ ARRAY_SIZE(serv_out16_arr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 158 | static const struct value_name_pair pr_in_arr[] = { |
| 159 | {0x0, "Persistent reserve in, read keys"}, |
| 160 | {0x1, "Persistent reserve in, read reservation"}, |
| 161 | {0x2, "Persistent reserve in, report capabilities"}, |
| 162 | {0x3, "Persistent reserve in, read full status"}, |
| 163 | }; |
| 164 | #define PR_IN_SZ ARRAY_SIZE(pr_in_arr) |
| 165 | |
| 166 | static const struct value_name_pair pr_out_arr[] = { |
| 167 | {0x0, "Persistent reserve out, register"}, |
| 168 | {0x1, "Persistent reserve out, reserve"}, |
| 169 | {0x2, "Persistent reserve out, release"}, |
| 170 | {0x3, "Persistent reserve out, clear"}, |
| 171 | {0x4, "Persistent reserve out, preempt"}, |
| 172 | {0x5, "Persistent reserve out, preempt and abort"}, |
| 173 | {0x6, "Persistent reserve out, register and ignore existing key"}, |
| 174 | {0x7, "Persistent reserve out, register and move"}, |
| 175 | }; |
| 176 | #define PR_OUT_SZ ARRAY_SIZE(pr_out_arr) |
| 177 | |
| 178 | /* SPC-4 rev 34 renamed the Extended Copy opcode to Third Party Copy Out. |
| 179 | LID1 (List Identifier length: 1 byte) is the Extended Copy found in SPC-2 |
| 180 | and SPC-3 */ |
| 181 | static const struct value_name_pair tpc_out_arr[] = { |
| 182 | {0x0, "Extended copy(LID1)"}, |
| 183 | {0x1, "Extended copy(LID4)"}, |
| 184 | {0x10, "Populate token"}, |
| 185 | {0x11, "Write using token"}, |
| 186 | {0x1c, "Copy operation abort"}, |
| 187 | }; |
| 188 | #define TPC_OUT_SZ ARRAY_SIZE(tpc_out_arr) |
| 189 | |
| 190 | static const struct value_name_pair tpc_in_arr[] = { |
| 191 | {0x0, "Receive copy status(LID1)"}, |
| 192 | {0x1, "Receive copy data(LID1)"}, |
| 193 | {0x3, "Receive copy operating parameters"}, |
| 194 | {0x4, "Receive copy failure details(LID1)"}, |
| 195 | {0x5, "Receive copy status(LID4)"}, |
| 196 | {0x6, "Receive copy data(LID4)"}, |
| 197 | {0x7, "Receive ROD token information"}, |
| 198 | {0x8, "Report all ROD tokens"}, |
| 199 | }; |
| 200 | #define TPC_IN_SZ ARRAY_SIZE(tpc_in_arr) |
| 201 | |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | static const struct value_name_pair variable_length_arr[] = { |
| 204 | {0x1, "Rebuild(32)"}, |
| 205 | {0x2, "Regenerate(32)"}, |
| 206 | {0x3, "Xdread(32)"}, |
| 207 | {0x4, "Xdwrite(32)"}, |
| 208 | {0x5, "Xdwrite extended(32)"}, |
| 209 | {0x6, "Xpwrite(32)"}, |
| 210 | {0x7, "Xdwriteread(32)"}, |
| 211 | {0x8, "Xdwrite extended(64)"}, |
| 212 | {0x9, "Read(32)"}, |
| 213 | {0xa, "Verify(32)"}, |
| 214 | {0xb, "Write(32)"}, |
| 215 | {0xc, "Write an verify(32)"}, |
| 216 | {0xd, "Write same(32)"}, |
| 217 | {0x8801, "Format OSD"}, |
| 218 | {0x8802, "Create (osd)"}, |
| 219 | {0x8803, "List (osd)"}, |
| 220 | {0x8805, "Read (osd)"}, |
| 221 | {0x8806, "Write (osd)"}, |
| 222 | {0x8807, "Append (osd)"}, |
| 223 | {0x8808, "Flush (osd)"}, |
| 224 | {0x880a, "Remove (osd)"}, |
| 225 | {0x880b, "Create partition (osd)"}, |
| 226 | {0x880c, "Remove partition (osd)"}, |
| 227 | {0x880e, "Get attributes (osd)"}, |
| 228 | {0x880f, "Set attributes (osd)"}, |
| 229 | {0x8812, "Create and write (osd)"}, |
| 230 | {0x8815, "Create collection (osd)"}, |
| 231 | {0x8816, "Remove collection (osd)"}, |
| 232 | {0x8817, "List collection (osd)"}, |
| 233 | {0x8818, "Set key (osd)"}, |
| 234 | {0x8819, "Set master key (osd)"}, |
| 235 | {0x881a, "Flush collection (osd)"}, |
| 236 | {0x881b, "Flush partition (osd)"}, |
| 237 | {0x881c, "Flush OSD"}, |
| 238 | {0x8f7e, "Perform SCSI command (osd)"}, |
| 239 | {0x8f7f, "Perform task management function (osd)"}, |
| 240 | }; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 241 | #define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Hannes Reinecke | 6033f97 | 2014-10-24 14:26:54 +0200 | [diff] [blame] | 243 | static struct sa_name_list sa_names_arr[] = { |
| 244 | {VARIABLE_LENGTH_CMD, variable_length_arr, VARIABLE_LENGTH_SZ}, |
| 245 | {MAINTENANCE_IN, maint_in_arr, MAINT_IN_SZ}, |
| 246 | {MAINTENANCE_OUT, maint_out_arr, MAINT_OUT_SZ}, |
| 247 | {PERSISTENT_RESERVE_IN, pr_in_arr, PR_IN_SZ}, |
| 248 | {PERSISTENT_RESERVE_OUT, pr_out_arr, PR_OUT_SZ}, |
| 249 | {SERVICE_ACTION_IN_12, serv_in12_arr, SERV_IN12_SZ}, |
| 250 | {SERVICE_ACTION_OUT_12, serv_out12_arr, SERV_OUT12_SZ}, |
| 251 | {SERVICE_ACTION_BIDIRECTIONAL, serv_bidi_arr, SERV_BIDI_SZ}, |
| 252 | {SERVICE_ACTION_IN_16, serv_in16_arr, SERV_IN16_SZ}, |
| 253 | {SERVICE_ACTION_OUT_16, serv_out16_arr, SERV_OUT16_SZ}, |
| 254 | {THIRD_PARTY_COPY_IN, tpc_in_arr, TPC_IN_SZ}, |
| 255 | {THIRD_PARTY_COPY_OUT, tpc_out_arr, TPC_OUT_SZ}, |
| 256 | {0, NULL, 0}, |
| 257 | }; |
| 258 | |
Hannes Reinecke | 9e5ed2a | 2015-01-08 07:43:44 +0100 | [diff] [blame] | 259 | bool scsi_opcode_sa_name(int opcode, int service_action, |
| 260 | const char **cdb_name, const char **sa_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
Hannes Reinecke | 6033f97 | 2014-10-24 14:26:54 +0200 | [diff] [blame] | 262 | struct sa_name_list *sa_name_ptr; |
| 263 | const struct value_name_pair *arr = NULL; |
| 264 | int arr_sz, k; |
| 265 | |
Hannes Reinecke | 2478a73 | 2014-10-24 14:26:56 +0200 | [diff] [blame] | 266 | *cdb_name = NULL; |
| 267 | if (opcode >= VENDOR_SPECIFIC_CDB) |
| 268 | return false; |
| 269 | |
| 270 | if (opcode < ARRAY_SIZE(cdb_byte0_names)) |
| 271 | *cdb_name = cdb_byte0_names[opcode]; |
| 272 | |
Hannes Reinecke | 6033f97 | 2014-10-24 14:26:54 +0200 | [diff] [blame] | 273 | for (sa_name_ptr = sa_names_arr; sa_name_ptr->arr; ++sa_name_ptr) { |
| 274 | if (sa_name_ptr->opcode == opcode) { |
| 275 | arr = sa_name_ptr->arr; |
| 276 | arr_sz = sa_name_ptr->arr_sz; |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | if (!arr) |
| 281 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | for (k = 0; k < arr_sz; ++k, ++arr) { |
| 284 | if (service_action == arr->value) |
| 285 | break; |
| 286 | } |
Hannes Reinecke | 6033f97 | 2014-10-24 14:26:54 +0200 | [diff] [blame] | 287 | if (k < arr_sz) |
| 288 | *sa_name = arr->name; |
| 289 | |
| 290 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | struct error_info { |
| 294 | unsigned short code12; /* 0x0302 looks better than 0x03,0x02 */ |
Rasmus Villemoes | e1f0bce | 2016-03-22 20:32:05 +0100 | [diff] [blame] | 295 | unsigned short size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
Rasmus Villemoes | e1f0bce | 2016-03-22 20:32:05 +0100 | [diff] [blame] | 298 | /* |
| 299 | * There are 700+ entries in this table. To save space, we don't store |
| 300 | * (code, pointer) pairs, which would make sizeof(struct |
| 301 | * error_info)==16 on 64 bits. Rather, the second element just stores |
| 302 | * the size (including \0) of the corresponding string, and we use the |
| 303 | * sum of these to get the appropriate offset into additional_text |
| 304 | * defined below. This approach saves 12 bytes per entry. |
| 305 | */ |
Martin K. Petersen | 62d42a6 | 2007-02-28 12:37:06 -0500 | [diff] [blame] | 306 | static const struct error_info additional[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
Rasmus Villemoes | e1f0bce | 2016-03-22 20:32:05 +0100 | [diff] [blame] | 308 | #define SENSE_CODE(c, s) {c, sizeof(s)}, |
Rasmus Villemoes | 9d99a2e | 2016-03-22 20:32:04 +0100 | [diff] [blame] | 309 | #include "sense_codes.h" |
| 310 | #undef SENSE_CODE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
Rasmus Villemoes | e1f0bce | 2016-03-22 20:32:05 +0100 | [diff] [blame] | 313 | static const char *additional_text = |
| 314 | #define SENSE_CODE(c, s) s "\0" |
| 315 | #include "sense_codes.h" |
| 316 | #undef SENSE_CODE |
| 317 | ; |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | struct error_info2 { |
| 320 | unsigned char code1, code2_min, code2_max; |
Hannes Reinecke | d811b84 | 2014-10-24 14:26:45 +0200 | [diff] [blame] | 321 | const char * str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | const char * fmt; |
| 323 | }; |
| 324 | |
Arjan van de Ven | 0ad7820 | 2005-11-28 16:22:25 +0100 | [diff] [blame] | 325 | static const struct error_info2 additional2[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Hannes Reinecke | d811b84 | 2014-10-24 14:26:45 +0200 | [diff] [blame] | 327 | {0x40, 0x00, 0x7f, "Ram failure", ""}, |
| 328 | {0x40, 0x80, 0xff, "Diagnostic failure on component", ""}, |
| 329 | {0x41, 0x00, 0xff, "Data path failure", ""}, |
| 330 | {0x42, 0x00, 0xff, "Power-on or self-test failure", ""}, |
| 331 | {0x4D, 0x00, 0xff, "Tagged overlapped commands", "task tag "}, |
| 332 | {0x70, 0x00, 0xff, "Decompression exception", "short algorithm id of "}, |
| 333 | {0, 0, 0, NULL, NULL} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | /* description of the sense key values */ |
Arjan van de Ven | 0ad7820 | 2005-11-28 16:22:25 +0100 | [diff] [blame] | 337 | static const char * const snstext[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | "No Sense", /* 0: There is no sense information */ |
| 339 | "Recovered Error", /* 1: The last command completed successfully |
| 340 | but used error correction */ |
| 341 | "Not Ready", /* 2: The addressed target is not ready */ |
| 342 | "Medium Error", /* 3: Data error detected on the medium */ |
| 343 | "Hardware Error", /* 4: Controller or device failure */ |
| 344 | "Illegal Request", /* 5: Error in request */ |
| 345 | "Unit Attention", /* 6: Removable medium was changed, or |
| 346 | the target has been reset, or ... */ |
| 347 | "Data Protect", /* 7: Access to the data is blocked */ |
| 348 | "Blank Check", /* 8: Reached unexpected written or unwritten |
| 349 | region of the medium */ |
| 350 | "Vendor Specific(9)", |
| 351 | "Copy Aborted", /* A: COPY or COMPARE was aborted */ |
| 352 | "Aborted Command", /* B: The target aborted the command */ |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 353 | "Equal", /* C: A SEARCH DATA command found data equal, |
| 354 | reserved in SPC-4 rev 36 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | "Volume Overflow", /* D: Medium full with still data to be written */ |
| 356 | "Miscompare", /* E: Source data and data on the medium |
| 357 | do not agree */ |
Douglas Gilbert | 655ee63 | 2013-07-02 00:17:34 -0400 | [diff] [blame] | 358 | "Completed", /* F: command completed sense data reported, |
| 359 | may occur for successful command */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | /* Get sense key string or NULL if not available */ |
| 363 | const char * |
| 364 | scsi_sense_key_string(unsigned char key) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if (key <= 0xE) |
| 366 | return snstext[key]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return NULL; |
| 368 | } |
| 369 | EXPORT_SYMBOL(scsi_sense_key_string); |
| 370 | |
| 371 | /* |
| 372 | * Get additional sense code string or NULL if not available. |
| 373 | * This string may contain a "%x" and should be printed with ascq as arg. |
| 374 | */ |
| 375 | const char * |
Hannes Reinecke | d811b84 | 2014-10-24 14:26:45 +0200 | [diff] [blame] | 376 | scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt) |
| 377 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | int i; |
| 379 | unsigned short code = ((asc << 8) | ascq); |
Rasmus Villemoes | e1f0bce | 2016-03-22 20:32:05 +0100 | [diff] [blame] | 380 | unsigned offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
Dan Carpenter | 249b15b | 2014-12-02 14:07:30 +0300 | [diff] [blame] | 382 | *fmt = NULL; |
Rasmus Villemoes | e1f0bce | 2016-03-22 20:32:05 +0100 | [diff] [blame] | 383 | for (i = 0; i < ARRAY_SIZE(additional); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | if (additional[i].code12 == code) |
Rasmus Villemoes | e1f0bce | 2016-03-22 20:32:05 +0100 | [diff] [blame] | 385 | return additional_text + offset; |
| 386 | offset += additional[i].size; |
| 387 | } |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 388 | for (i = 0; additional2[i].fmt; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | if (additional2[i].code1 == asc && |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 390 | ascq >= additional2[i].code2_min && |
Hannes Reinecke | d811b84 | 2014-10-24 14:26:45 +0200 | [diff] [blame] | 391 | ascq <= additional2[i].code2_max) { |
| 392 | *fmt = additional2[i].fmt; |
| 393 | return additional2[i].str; |
| 394 | } |
Douglas Gilbert | b4567ca | 2009-06-25 15:43:02 -0400 | [diff] [blame] | 395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | return NULL; |
| 397 | } |
| 398 | EXPORT_SYMBOL(scsi_extd_sense_format); |
| 399 | |
Arjan van de Ven | 0ad7820 | 2005-11-28 16:22:25 +0100 | [diff] [blame] | 400 | static const char * const hostbyte_table[]={ |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 401 | "DID_OK", "DID_NO_CONNECT", "DID_BUS_BUSY", "DID_TIME_OUT", "DID_BAD_TARGET", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | "DID_ABORT", "DID_PARITY", "DID_ERROR", "DID_RESET", "DID_BAD_INTR", |
Mike Christie | a4dfaa6 | 2008-08-19 18:45:25 -0500 | [diff] [blame] | 403 | "DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE", |
Moger, Babu | f1ba8a4 | 2012-07-27 17:28:40 +0000 | [diff] [blame] | 404 | "DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE", |
| 405 | "DID_NEXUS_FAILURE" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Arjan van de Ven | 0ad7820 | 2005-11-28 16:22:25 +0100 | [diff] [blame] | 407 | static const char * const driverbyte_table[]={ |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 408 | "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"}; |
Martin K. Petersen | 684b7fe | 2007-02-27 22:39:44 -0500 | [diff] [blame] | 410 | |
Hannes Reinecke | 3cc958c | 2014-10-24 14:26:59 +0200 | [diff] [blame] | 411 | const char *scsi_hostbyte_string(int result) |
| 412 | { |
| 413 | const char *hb_string = NULL; |
Hannes Reinecke | 3cc958c | 2014-10-24 14:26:59 +0200 | [diff] [blame] | 414 | int hb = host_byte(result); |
| 415 | |
| 416 | if (hb < ARRAY_SIZE(hostbyte_table)) |
| 417 | hb_string = hostbyte_table[hb]; |
Hannes Reinecke | 3cc958c | 2014-10-24 14:26:59 +0200 | [diff] [blame] | 418 | return hb_string; |
| 419 | } |
| 420 | EXPORT_SYMBOL(scsi_hostbyte_string); |
| 421 | |
| 422 | const char *scsi_driverbyte_string(int result) |
| 423 | { |
| 424 | const char *db_string = NULL; |
Hannes Reinecke | 3cc958c | 2014-10-24 14:26:59 +0200 | [diff] [blame] | 425 | int db = driver_byte(result); |
| 426 | |
| 427 | if (db < ARRAY_SIZE(driverbyte_table)) |
| 428 | db_string = driverbyte_table[db]; |
Hannes Reinecke | 3cc958c | 2014-10-24 14:26:59 +0200 | [diff] [blame] | 429 | return db_string; |
| 430 | } |
| 431 | EXPORT_SYMBOL(scsi_driverbyte_string); |
| 432 | |
Hannes Reinecke | c11c004 | 2014-10-24 14:27:01 +0200 | [diff] [blame] | 433 | #define scsi_mlreturn_name(result) { result, #result } |
| 434 | static const struct value_name_pair scsi_mlreturn_arr[] = { |
| 435 | scsi_mlreturn_name(NEEDS_RETRY), |
| 436 | scsi_mlreturn_name(SUCCESS), |
| 437 | scsi_mlreturn_name(FAILED), |
| 438 | scsi_mlreturn_name(QUEUED), |
| 439 | scsi_mlreturn_name(SOFT_ERROR), |
| 440 | scsi_mlreturn_name(ADD_TO_MLQUEUE), |
| 441 | scsi_mlreturn_name(TIMEOUT_ERROR), |
| 442 | scsi_mlreturn_name(SCSI_RETURN_NOT_HANDLED), |
| 443 | scsi_mlreturn_name(FAST_IO_FAIL) |
| 444 | }; |
Hannes Reinecke | c11c004 | 2014-10-24 14:27:01 +0200 | [diff] [blame] | 445 | |
| 446 | const char *scsi_mlreturn_string(int result) |
Martin K. Petersen | 684b7fe | 2007-02-27 22:39:44 -0500 | [diff] [blame] | 447 | { |
Hannes Reinecke | c11c004 | 2014-10-24 14:27:01 +0200 | [diff] [blame] | 448 | const struct value_name_pair *arr = scsi_mlreturn_arr; |
| 449 | int k; |
| 450 | |
| 451 | for (k = 0; k < ARRAY_SIZE(scsi_mlreturn_arr); ++k, ++arr) { |
| 452 | if (result == arr->value) |
| 453 | return arr->name; |
| 454 | } |
Hannes Reinecke | c11c004 | 2014-10-24 14:27:01 +0200 | [diff] [blame] | 455 | return NULL; |
| 456 | } |
| 457 | EXPORT_SYMBOL(scsi_mlreturn_string); |