scsi_proto.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 VENDOR_SPECIFIC 0x09
  224. #define COPY_ABORTED 0x0a
  225. #define ABORTED_COMMAND 0x0b
  226. #define VOLUME_OVERFLOW 0x0d
  227. #define MISCOMPARE 0x0e
  228. /*
  229. * DEVICE TYPES
  230. * Please keep them in 0x%02x format for $MODALIAS to work
  231. */
  232. #define TYPE_DISK 0x00
  233. #define TYPE_TAPE 0x01
  234. #define TYPE_PRINTER 0x02
  235. #define TYPE_PROCESSOR 0x03 /* HP scanners use this */
  236. #define TYPE_WORM 0x04 /* Treated as ROM by our system */
  237. #define TYPE_ROM 0x05
  238. #define TYPE_SCANNER 0x06
  239. #define TYPE_MOD 0x07 /* Magneto-optical disk -
  240. * - treated as TYPE_DISK */
  241. #define TYPE_MEDIUM_CHANGER 0x08
  242. #define TYPE_COMM 0x09 /* Communications device */
  243. #define TYPE_RAID 0x0c
  244. #define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
  245. #define TYPE_RBC 0x0e
  246. #define TYPE_OSD 0x11
  247. #define TYPE_ZBC 0x14
  248. #define TYPE_WLUN 0x1e /* well-known logical unit */
  249. #define TYPE_NO_LUN 0x7f
  250. /* SCSI protocols; these are taken from SPC-3 section 7.5 */
  251. enum scsi_protocol {
  252. SCSI_PROTOCOL_FCP = 0, /* Fibre Channel */
  253. SCSI_PROTOCOL_SPI = 1, /* parallel SCSI */
  254. SCSI_PROTOCOL_SSA = 2, /* Serial Storage Architecture - Obsolete */
  255. SCSI_PROTOCOL_SBP = 3, /* firewire */
  256. SCSI_PROTOCOL_SRP = 4, /* Infiniband RDMA */
  257. SCSI_PROTOCOL_ISCSI = 5,
  258. SCSI_PROTOCOL_SAS = 6,
  259. SCSI_PROTOCOL_ADT = 7, /* Media Changers */
  260. SCSI_PROTOCOL_ATA = 8,
  261. SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
  262. };
  263. /*
  264. * ScsiLun: 8 byte LUN.
  265. */
  266. struct scsi_lun {
  267. __u8 scsi_lun[8];
  268. };
  269. /* SPC asymmetric access states */
  270. #define SCSI_ACCESS_STATE_OPTIMAL 0x00
  271. #define SCSI_ACCESS_STATE_ACTIVE 0x01
  272. #define SCSI_ACCESS_STATE_STANDBY 0x02
  273. #define SCSI_ACCESS_STATE_UNAVAILABLE 0x03
  274. #define SCSI_ACCESS_STATE_LBA 0x04
  275. #define SCSI_ACCESS_STATE_OFFLINE 0x0e
  276. #define SCSI_ACCESS_STATE_TRANSITIONING 0x0f
  277. /* Values for REPORT TARGET GROUP STATES */
  278. #define SCSI_ACCESS_STATE_MASK 0x0f
  279. #define SCSI_ACCESS_STATE_PREFERRED 0x80
  280. /* Reporting options for REPORT ZONES */
  281. enum zbc_zone_reporting_options {
  282. ZBC_ZONE_REPORTING_OPTION_ALL = 0x00,
  283. ZBC_ZONE_REPORTING_OPTION_EMPTY = 0x01,
  284. ZBC_ZONE_REPORTING_OPTION_IMPLICIT_OPEN = 0x02,
  285. ZBC_ZONE_REPORTING_OPTION_EXPLICIT_OPEN = 0x03,
  286. ZBC_ZONE_REPORTING_OPTION_CLOSED = 0x04,
  287. ZBC_ZONE_REPORTING_OPTION_FULL = 0x05,
  288. ZBC_ZONE_REPORTING_OPTION_READONLY = 0x06,
  289. ZBC_ZONE_REPORTING_OPTION_OFFLINE = 0x07,
  290. /* 0x08 to 0x0f are reserved */
  291. ZBC_ZONE_REPORTING_OPTION_NEED_RESET_WP = 0x10,
  292. ZBC_ZONE_REPORTING_OPTION_NON_SEQWRITE = 0x11,
  293. /* 0x12 to 0x3e are reserved */
  294. ZBC_ZONE_REPORTING_OPTION_NON_WP = 0x3f,
  295. };
  296. #define ZBC_REPORT_ZONE_PARTIAL 0x80
  297. /* Zone types of REPORT ZONES zone descriptors */
  298. enum zbc_zone_type {
  299. ZBC_ZONE_TYPE_CONV = 0x1,
  300. ZBC_ZONE_TYPE_SEQWRITE_REQ = 0x2,
  301. ZBC_ZONE_TYPE_SEQWRITE_PREF = 0x3,
  302. /* 0x4 to 0xf are reserved */
  303. };
  304. /* Zone conditions of REPORT ZONES zone descriptors */
  305. enum zbc_zone_cond {
  306. ZBC_ZONE_COND_NO_WP = 0x0,
  307. ZBC_ZONE_COND_EMPTY = 0x1,
  308. ZBC_ZONE_COND_IMP_OPEN = 0x2,
  309. ZBC_ZONE_COND_EXP_OPEN = 0x3,
  310. ZBC_ZONE_COND_CLOSED = 0x4,
  311. /* 0x5 to 0xc are reserved */
  312. ZBC_ZONE_COND_READONLY = 0xd,
  313. ZBC_ZONE_COND_FULL = 0xe,
  314. ZBC_ZONE_COND_OFFLINE = 0xf,
  315. };
  316. #endif /* _SCSI_PROTO_H_ */