scsi_proto.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * This header file contains public constants and structures used by
  4. * both the SCSI initiator and the SCSI target code.
  5. *
  6. * For documentation on the OPCODES, MESSAGES, and SENSE values,
  7. * please consult the SCSI standard.
  8. */
  9. #ifndef _SCSI_PROTO_H_
  10. #define _SCSI_PROTO_H_
  11. #include <linux/types.h>
  12. /*
  13. * SCSI opcodes
  14. */
  15. #define TEST_UNIT_READY 0x00
  16. #define REZERO_UNIT 0x01
  17. #define REQUEST_SENSE 0x03
  18. #define FORMAT_UNIT 0x04
  19. #define READ_BLOCK_LIMITS 0x05
  20. #define REASSIGN_BLOCKS 0x07
  21. #define INITIALIZE_ELEMENT_STATUS 0x07
  22. #define READ_6 0x08
  23. #define WRITE_6 0x0a
  24. #define SEEK_6 0x0b
  25. #define READ_REVERSE 0x0f
  26. #define WRITE_FILEMARKS 0x10
  27. #define SPACE 0x11
  28. #define INQUIRY 0x12
  29. #define RECOVER_BUFFERED_DATA 0x14
  30. #define MODE_SELECT 0x15
  31. #define RESERVE 0x16
  32. #define RELEASE 0x17
  33. #define COPY 0x18
  34. #define ERASE 0x19
  35. #define MODE_SENSE 0x1a
  36. #define START_STOP 0x1b
  37. #define RECEIVE_DIAGNOSTIC 0x1c
  38. #define SEND_DIAGNOSTIC 0x1d
  39. #define ALLOW_MEDIUM_REMOVAL 0x1e
  40. #define READ_FORMAT_CAPACITIES 0x23
  41. #define SET_WINDOW 0x24
  42. #define READ_CAPACITY 0x25
  43. #define READ_10 0x28
  44. #define WRITE_10 0x2a
  45. #define SEEK_10 0x2b
  46. #define POSITION_TO_ELEMENT 0x2b
  47. #define WRITE_VERIFY 0x2e
  48. #define VERIFY 0x2f
  49. #define SEARCH_HIGH 0x30
  50. #define SEARCH_EQUAL 0x31
  51. #define SEARCH_LOW 0x32
  52. #define SET_LIMITS 0x33
  53. #define PRE_FETCH 0x34
  54. #define READ_POSITION 0x34
  55. #define SYNCHRONIZE_CACHE 0x35
  56. #define LOCK_UNLOCK_CACHE 0x36
  57. #define READ_DEFECT_DATA 0x37
  58. #define MEDIUM_SCAN 0x38
  59. #define COMPARE 0x39
  60. #define COPY_VERIFY 0x3a
  61. #define WRITE_BUFFER 0x3b
  62. #define READ_BUFFER 0x3c
  63. #define UPDATE_BLOCK 0x3d
  64. #define READ_LONG 0x3e
  65. #define WRITE_LONG 0x3f
  66. #define CHANGE_DEFINITION 0x40
  67. #define WRITE_SAME 0x41
  68. #define UNMAP 0x42
  69. #define READ_TOC 0x43
  70. #define READ_HEADER 0x44
  71. #define GET_EVENT_STATUS_NOTIFICATION 0x4a
  72. #define LOG_SELECT 0x4c
  73. #define LOG_SENSE 0x4d
  74. #define XDWRITEREAD_10 0x53
  75. #define MODE_SELECT_10 0x55
  76. #define RESERVE_10 0x56
  77. #define RELEASE_10 0x57
  78. #define MODE_SENSE_10 0x5a
  79. #define PERSISTENT_RESERVE_IN 0x5e
  80. #define PERSISTENT_RESERVE_OUT 0x5f
  81. #define VARIABLE_LENGTH_CMD 0x7f
  82. #define REPORT_LUNS 0xa0
  83. #define SECURITY_PROTOCOL_IN 0xa2
  84. #define MAINTENANCE_IN 0xa3
  85. #define MAINTENANCE_OUT 0xa4
  86. #define MOVE_MEDIUM 0xa5
  87. #define EXCHANGE_MEDIUM 0xa6
  88. #define READ_12 0xa8
  89. #define SERVICE_ACTION_OUT_12 0xa9
  90. #define WRITE_12 0xaa
  91. #define READ_MEDIA_SERIAL_NUMBER 0xab /* Obsolete with SPC-2 */
  92. #define SERVICE_ACTION_IN_12 0xab
  93. #define WRITE_VERIFY_12 0xae
  94. #define VERIFY_12 0xaf
  95. #define SEARCH_HIGH_12 0xb0
  96. #define SEARCH_EQUAL_12 0xb1
  97. #define SEARCH_LOW_12 0xb2
  98. #define SECURITY_PROTOCOL_OUT 0xb5
  99. #define READ_ELEMENT_STATUS 0xb8
  100. #define SEND_VOLUME_TAG 0xb6
  101. #define WRITE_LONG_2 0xea
  102. #define EXTENDED_COPY 0x83
  103. #define RECEIVE_COPY_RESULTS 0x84
  104. #define ACCESS_CONTROL_IN 0x86
  105. #define ACCESS_CONTROL_OUT 0x87
  106. #define READ_16 0x88
  107. #define COMPARE_AND_WRITE 0x89
  108. #define WRITE_16 0x8a
  109. #define READ_ATTRIBUTE 0x8c
  110. #define WRITE_ATTRIBUTE 0x8d
  111. #define WRITE_VERIFY_16 0x8e
  112. #define VERIFY_16 0x8f
  113. #define SYNCHRONIZE_CACHE_16 0x91
  114. #define WRITE_SAME_16 0x93
  115. #define ZBC_OUT 0x94
  116. #define ZBC_IN 0x95
  117. #define SERVICE_ACTION_BIDIRECTIONAL 0x9d
  118. #define SERVICE_ACTION_IN_16 0x9e
  119. #define SERVICE_ACTION_OUT_16 0x9f
  120. /* values for service action in */
  121. #define SAI_READ_CAPACITY_16 0x10
  122. #define SAI_GET_LBA_STATUS 0x12
  123. #define SAI_REPORT_REFERRALS 0x13
  124. /* values for maintenance in */
  125. #define MI_REPORT_IDENTIFYING_INFORMATION 0x05
  126. #define MI_REPORT_TARGET_PGS 0x0a
  127. #define MI_REPORT_ALIASES 0x0b
  128. #define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
  129. #define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
  130. #define MI_REPORT_PRIORITY 0x0e
  131. #define MI_REPORT_TIMESTAMP 0x0f
  132. #define MI_MANAGEMENT_PROTOCOL_IN 0x10
  133. /* value for MI_REPORT_TARGET_PGS ext header */
  134. #define MI_EXT_HDR_PARAM_FMT 0x20
  135. /* values for maintenance out */
  136. #define MO_SET_IDENTIFYING_INFORMATION 0x06
  137. #define MO_SET_TARGET_PGS 0x0a
  138. #define MO_CHANGE_ALIASES 0x0b
  139. #define MO_SET_PRIORITY 0x0e
  140. #define MO_SET_TIMESTAMP 0x0f
  141. #define MO_MANAGEMENT_PROTOCOL_OUT 0x10
  142. /* values for ZBC_IN */
  143. #define ZI_REPORT_ZONES 0x00
  144. /* values for ZBC_OUT */
  145. #define ZO_CLOSE_ZONE 0x01
  146. #define ZO_FINISH_ZONE 0x02
  147. #define ZO_OPEN_ZONE 0x03
  148. #define ZO_RESET_WRITE_POINTER 0x04
  149. /* values for variable length command */
  150. #define XDREAD_32 0x03
  151. #define XDWRITE_32 0x04
  152. #define XPWRITE_32 0x06
  153. #define XDWRITEREAD_32 0x07
  154. #define READ_32 0x09
  155. #define VERIFY_32 0x0a
  156. #define WRITE_32 0x0b
  157. #define WRITE_VERIFY_32 0x0c
  158. #define WRITE_SAME_32 0x0d
  159. #define ATA_32 0x1ff0
  160. /* Values for T10/04-262r7 */
  161. #define ATA_16 0x85 /* 16-byte pass-thru */
  162. #define ATA_12 0xa1 /* 12-byte pass-thru */
  163. /* Vendor specific CDBs start here */
  164. #define VENDOR_SPECIFIC_CDB 0xc0
  165. /*
  166. * SCSI command lengths
  167. */
  168. #define SCSI_MAX_VARLEN_CDB_SIZE 260
  169. /* defined in T10 SCSI Primary Commands-2 (SPC2) */
  170. struct scsi_varlen_cdb_hdr {
  171. __u8 opcode; /* opcode always == VARIABLE_LENGTH_CMD */
  172. __u8 control;
  173. __u8 misc[5];
  174. __u8 additional_cdb_length; /* total cdb length - 8 */
  175. __be16 service_action;
  176. /* service specific data follows */
  177. };
  178. /*
  179. * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
  180. * T10/1561-D Revision 4 Draft dated 7th November 2002.
  181. */
  182. #define SAM_STAT_GOOD 0x00
  183. #define SAM_STAT_CHECK_CONDITION 0x02
  184. #define SAM_STAT_CONDITION_MET 0x04
  185. #define SAM_STAT_BUSY 0x08
  186. #define SAM_STAT_INTERMEDIATE 0x10
  187. #define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14
  188. #define SAM_STAT_RESERVATION_CONFLICT 0x18
  189. #define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */
  190. #define SAM_STAT_TASK_SET_FULL 0x28
  191. #define SAM_STAT_ACA_ACTIVE 0x30
  192. #define SAM_STAT_TASK_ABORTED 0x40
  193. /*
  194. * Status codes. These are deprecated as they are shifted 1 bit right
  195. * from those found in the SCSI standards. This causes confusion for
  196. * applications that are ported to several OSes. Prefer SAM Status codes
  197. * above.
  198. */
  199. #define GOOD 0x00
  200. #define CHECK_CONDITION 0x01
  201. #define CONDITION_GOOD 0x02
  202. #define BUSY 0x04
  203. #define INTERMEDIATE_GOOD 0x08
  204. #define INTERMEDIATE_C_GOOD 0x0a
  205. #define RESERVATION_CONFLICT 0x0c
  206. #define COMMAND_TERMINATED 0x11
  207. #define QUEUE_FULL 0x14
  208. #define ACA_ACTIVE 0x18
  209. #define TASK_ABORTED 0x20
  210. #define STATUS_MASK 0xfe
  211. /*
  212. * SENSE KEYS
  213. */
  214. #define NO_SENSE 0x00
  215. #define RECOVERED_ERROR 0x01
  216. #define NOT_READY 0x02
  217. #define MEDIUM_ERROR 0x03
  218. #define HARDWARE_ERROR 0x04
  219. #define ILLEGAL_REQUEST 0x05
  220. #define UNIT_ATTENTION 0x06
  221. #define DATA_PROTECT 0x07
  222. #define BLANK_CHECK 0x08
  223. #define COPY_ABORTED 0x0a
  224. #define ABORTED_COMMAND 0x0b
  225. #define VOLUME_OVERFLOW 0x0d
  226. #define MISCOMPARE 0x0e
  227. /*
  228. * DEVICE TYPES
  229. * Please keep them in 0x%02x format for $MODALIAS to work
  230. */
  231. #define TYPE_DISK 0x00
  232. #define TYPE_TAPE 0x01
  233. #define TYPE_PRINTER 0x02
  234. #define TYPE_PROCESSOR 0x03 /* HP scanners use this */
  235. #define TYPE_WORM 0x04 /* Treated as ROM by our system */
  236. #define TYPE_ROM 0x05
  237. #define TYPE_SCANNER 0x06
  238. #define TYPE_MOD 0x07 /* Magneto-optical disk -
  239. * - treated as TYPE_DISK */
  240. #define TYPE_MEDIUM_CHANGER 0x08
  241. #define TYPE_COMM 0x09 /* Communications device */
  242. #define TYPE_RAID 0x0c
  243. #define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
  244. #define TYPE_RBC 0x0e
  245. #define TYPE_OSD 0x11
  246. #define TYPE_ZBC 0x14
  247. #define TYPE_WLUN 0x1e /* well-known logical unit */
  248. #define TYPE_NO_LUN 0x7f
  249. /* SCSI protocols; these are taken from SPC-3 section 7.5 */
  250. enum scsi_protocol {
  251. SCSI_PROTOCOL_FCP = 0, /* Fibre Channel */
  252. SCSI_PROTOCOL_SPI = 1, /* parallel SCSI */
  253. SCSI_PROTOCOL_SSA = 2, /* Serial Storage Architecture - Obsolete */
  254. SCSI_PROTOCOL_SBP = 3, /* firewire */
  255. SCSI_PROTOCOL_SRP = 4, /* Infiniband RDMA */
  256. SCSI_PROTOCOL_ISCSI = 5,
  257. SCSI_PROTOCOL_SAS = 6,
  258. SCSI_PROTOCOL_ADT = 7, /* Media Changers */
  259. SCSI_PROTOCOL_ATA = 8,
  260. SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
  261. };
  262. /*
  263. * ScsiLun: 8 byte LUN.
  264. */
  265. struct scsi_lun {
  266. __u8 scsi_lun[8];
  267. };
  268. /* SPC asymmetric access states */
  269. #define SCSI_ACCESS_STATE_OPTIMAL 0x00
  270. #define SCSI_ACCESS_STATE_ACTIVE 0x01
  271. #define SCSI_ACCESS_STATE_STANDBY 0x02
  272. #define SCSI_ACCESS_STATE_UNAVAILABLE 0x03
  273. #define SCSI_ACCESS_STATE_LBA 0x04
  274. #define SCSI_ACCESS_STATE_OFFLINE 0x0e
  275. #define SCSI_ACCESS_STATE_TRANSITIONING 0x0f
  276. /* Values for REPORT TARGET GROUP STATES */
  277. #define SCSI_ACCESS_STATE_MASK 0x0f
  278. #define SCSI_ACCESS_STATE_PREFERRED 0x80
  279. /* Reporting options for REPORT ZONES */
  280. enum zbc_zone_reporting_options {
  281. ZBC_ZONE_REPORTING_OPTION_ALL = 0,
  282. ZBC_ZONE_REPORTING_OPTION_EMPTY,
  283. ZBC_ZONE_REPORTING_OPTION_IMPLICIT_OPEN,
  284. ZBC_ZONE_REPORTING_OPTION_EXPLICIT_OPEN,
  285. ZBC_ZONE_REPORTING_OPTION_CLOSED,
  286. ZBC_ZONE_REPORTING_OPTION_FULL,
  287. ZBC_ZONE_REPORTING_OPTION_READONLY,
  288. ZBC_ZONE_REPORTING_OPTION_OFFLINE,
  289. ZBC_ZONE_REPORTING_OPTION_NEED_RESET_WP = 0x10,
  290. ZBC_ZONE_REPORTING_OPTION_NON_SEQWRITE,
  291. ZBC_ZONE_REPORTING_OPTION_NON_WP = 0x3f,
  292. };
  293. #define ZBC_REPORT_ZONE_PARTIAL 0x80
  294. #endif /* _SCSI_PROTO_H_ */