constants.c 15 KB

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