scsi.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * This header file contains public constants and structures used by
  4. * the SCSI initiator code.
  5. */
  6. #ifndef _SCSI_SCSI_H
  7. #define _SCSI_SCSI_H
  8. #include <linux/types.h>
  9. #include <linux/scatterlist.h>
  10. #include <linux/kernel.h>
  11. #include <scsi/scsi_common.h>
  12. #include <scsi/scsi_proto.h>
  13. struct scsi_cmnd;
  14. enum scsi_timeouts {
  15. SCSI_DEFAULT_EH_TIMEOUT = 10 * HZ,
  16. };
  17. /*
  18. * DIX-capable adapters effectively support infinite chaining for the
  19. * protection information scatterlist
  20. */
  21. #define SCSI_MAX_PROT_SG_SEGMENTS 0xFFFF
  22. /*
  23. * Special value for scanning to specify scanning or rescanning of all
  24. * possible channels, (target) ids, or luns on a given shost.
  25. */
  26. #define SCAN_WILD_CARD ~0
  27. /** scsi_status_is_good - check the status return.
  28. *
  29. * @status: the status passed up from the driver (including host and
  30. * driver components)
  31. *
  32. * This returns true for known good conditions that may be treated as
  33. * command completed normally
  34. */
  35. static inline int scsi_status_is_good(int status)
  36. {
  37. /*
  38. * FIXME: bit0 is listed as reserved in SCSI-2, but is
  39. * significant in SCSI-3. For now, we follow the SCSI-2
  40. * behaviour and ignore reserved bits.
  41. */
  42. status &= 0xfe;
  43. return ((status == SAM_STAT_GOOD) ||
  44. (status == SAM_STAT_CONDITION_MET) ||
  45. /* Next two "intermediate" statuses are obsolete in SAM-4 */
  46. (status == SAM_STAT_INTERMEDIATE) ||
  47. (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
  48. /* FIXME: this is obsolete in SAM-3 */
  49. (status == SAM_STAT_COMMAND_TERMINATED));
  50. }
  51. /*
  52. * standard mode-select header prepended to all mode-select commands
  53. */
  54. struct ccs_modesel_head {
  55. __u8 _r1; /* reserved */
  56. __u8 medium; /* device-specific medium type */
  57. __u8 _r2; /* reserved */
  58. __u8 block_desc_length; /* block descriptor length */
  59. __u8 density; /* device-specific density code */
  60. __u8 number_blocks_hi; /* number of blocks in this block desc */
  61. __u8 number_blocks_med;
  62. __u8 number_blocks_lo;
  63. __u8 _r3;
  64. __u8 block_length_hi; /* block length for blocks in this desc */
  65. __u8 block_length_med;
  66. __u8 block_length_lo;
  67. };
  68. /*
  69. * The Well Known LUNS (SAM-3) in our int representation of a LUN
  70. */
  71. #define SCSI_W_LUN_BASE 0xc100
  72. #define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1)
  73. #define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2)
  74. #define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3)
  75. static inline int scsi_is_wlun(u64 lun)
  76. {
  77. return (lun & 0xff00) == SCSI_W_LUN_BASE;
  78. }
  79. /**
  80. * scsi_status_is_check_condition - check the status return.
  81. *
  82. * @status: the status passed up from the driver (including host and
  83. * driver components)
  84. *
  85. * This returns true if the status code is SAM_STAT_CHECK_CONDITION.
  86. */
  87. static inline int scsi_status_is_check_condition(int status)
  88. {
  89. if (status < 0)
  90. return false;
  91. status &= 0xfe;
  92. return status == SAM_STAT_CHECK_CONDITION;
  93. }
  94. /*
  95. * MESSAGE CODES
  96. */
  97. #define COMMAND_COMPLETE 0x00
  98. #define EXTENDED_MESSAGE 0x01
  99. #define EXTENDED_MODIFY_DATA_POINTER 0x00
  100. #define EXTENDED_SDTR 0x01
  101. #define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */
  102. #define EXTENDED_WDTR 0x03
  103. #define EXTENDED_PPR 0x04
  104. #define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
  105. #define SAVE_POINTERS 0x02
  106. #define RESTORE_POINTERS 0x03
  107. #define DISCONNECT 0x04
  108. #define INITIATOR_ERROR 0x05
  109. #define ABORT_TASK_SET 0x06
  110. #define MESSAGE_REJECT 0x07
  111. #define NOP 0x08
  112. #define MSG_PARITY_ERROR 0x09
  113. #define LINKED_CMD_COMPLETE 0x0a
  114. #define LINKED_FLG_CMD_COMPLETE 0x0b
  115. #define TARGET_RESET 0x0c
  116. #define ABORT_TASK 0x0d
  117. #define CLEAR_TASK_SET 0x0e
  118. #define INITIATE_RECOVERY 0x0f /* SCSI-II only */
  119. #define RELEASE_RECOVERY 0x10 /* SCSI-II only */
  120. #define CLEAR_ACA 0x16
  121. #define LOGICAL_UNIT_RESET 0x17
  122. #define SIMPLE_QUEUE_TAG 0x20
  123. #define HEAD_OF_QUEUE_TAG 0x21
  124. #define ORDERED_QUEUE_TAG 0x22
  125. #define IGNORE_WIDE_RESIDUE 0x23
  126. #define ACA 0x24
  127. #define QAS_REQUEST 0x55
  128. /* Old SCSI2 names, don't use in new code */
  129. #define BUS_DEVICE_RESET TARGET_RESET
  130. #define ABORT ABORT_TASK_SET
  131. /*
  132. * Host byte codes
  133. */
  134. #define DID_OK 0x00 /* NO error */
  135. #define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
  136. #define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
  137. #define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
  138. #define DID_BAD_TARGET 0x04 /* BAD target. */
  139. #define DID_ABORT 0x05 /* Told to abort for some other reason */
  140. #define DID_PARITY 0x06 /* Parity error */
  141. #define DID_ERROR 0x07 /* Internal error */
  142. #define DID_RESET 0x08 /* Reset by somebody. */
  143. #define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
  144. #define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
  145. #define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
  146. #define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */
  147. #define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also
  148. * without decrementing the retry count */
  149. #define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution
  150. * and the driver blocked the port to
  151. * recover the link. Transport class will
  152. * retry or fail IO */
  153. #define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */
  154. #define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on
  155. * other paths */
  156. #define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other
  157. * paths might yield different results */
  158. #define DID_ALLOC_FAILURE 0x12 /* Space allocation on the device failed */
  159. #define DID_MEDIUM_ERROR 0x13 /* Medium error */
  160. #define DRIVER_OK 0x00 /* Driver status */
  161. /*
  162. * These indicate the error that occurred, and what is available.
  163. */
  164. #define DRIVER_BUSY 0x01
  165. #define DRIVER_SOFT 0x02
  166. #define DRIVER_MEDIA 0x03
  167. #define DRIVER_ERROR 0x04
  168. #define DRIVER_INVALID 0x05
  169. #define DRIVER_TIMEOUT 0x06
  170. #define DRIVER_HARD 0x07
  171. #define DRIVER_SENSE 0x08
  172. /*
  173. * Internal return values.
  174. */
  175. #define NEEDS_RETRY 0x2001
  176. #define SUCCESS 0x2002
  177. #define FAILED 0x2003
  178. #define QUEUED 0x2004
  179. #define SOFT_ERROR 0x2005
  180. #define ADD_TO_MLQUEUE 0x2006
  181. #define TIMEOUT_ERROR 0x2007
  182. #define SCSI_RETURN_NOT_HANDLED 0x2008
  183. #define FAST_IO_FAIL 0x2009
  184. /*
  185. * Midlevel queue return values.
  186. */
  187. #define SCSI_MLQUEUE_HOST_BUSY 0x1055
  188. #define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
  189. #define SCSI_MLQUEUE_EH_RETRY 0x1057
  190. #define SCSI_MLQUEUE_TARGET_BUSY 0x1058
  191. /*
  192. * Use these to separate status msg and our bytes
  193. *
  194. * These are set by:
  195. *
  196. * status byte = set from target device
  197. * msg_byte = return status from host adapter itself.
  198. * host_byte = set by low-level driver to indicate status.
  199. * driver_byte = set by mid-level.
  200. */
  201. #define status_byte(result) (((result) >> 1) & 0x7f)
  202. #define msg_byte(result) (((result) >> 8) & 0xff)
  203. #define host_byte(result) (((result) >> 16) & 0xff)
  204. #define driver_byte(result) (((result) >> 24) & 0xff)
  205. #define sense_class(sense) (((sense) >> 4) & 0x7)
  206. #define sense_error(sense) ((sense) & 0xf)
  207. #define sense_valid(sense) ((sense) & 0x80)
  208. /*
  209. * default timeouts
  210. */
  211. #define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * HZ)
  212. #define START_STOP_TIMEOUT (60 * HZ)
  213. #define MOVE_MEDIUM_TIMEOUT (5 * 60 * HZ)
  214. #define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ)
  215. #define READ_DEFECT_DATA_TIMEOUT (60 * HZ )
  216. #define IDENTIFY_BASE 0x80
  217. #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
  218. ((can_disconnect) ? 0x40 : 0) |\
  219. ((lun) & 0x07))
  220. /*
  221. * struct scsi_device::scsi_level values. For SCSI devices other than those
  222. * prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1)
  223. * where "resp" is a byte array of the response to an INQUIRY. The scsi_level
  224. * variable is visible to the user via sysfs.
  225. */
  226. #define SCSI_UNKNOWN 0
  227. #define SCSI_1 1
  228. #define SCSI_1_CCS 2
  229. #define SCSI_2 3
  230. #define SCSI_3 4 /* SPC */
  231. #define SCSI_SPC_2 5
  232. #define SCSI_SPC_3 6
  233. /*
  234. * INQ PERIPHERAL QUALIFIERS
  235. */
  236. #define SCSI_INQ_PQ_CON 0x00
  237. #define SCSI_INQ_PQ_NOT_CON 0x01
  238. #define SCSI_INQ_PQ_NOT_CAP 0x03
  239. /*
  240. * Here are some scsi specific ioctl commands which are sometimes useful.
  241. *
  242. * Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395
  243. */
  244. /* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */
  245. #define SCSI_IOCTL_GET_IDLUN 0x5382
  246. /* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */
  247. /* Used to obtain the host number of a device. */
  248. #define SCSI_IOCTL_PROBE_HOST 0x5385
  249. /* Used to obtain the bus number for a device */
  250. #define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
  251. /* Used to obtain the PCI location of a device */
  252. #define SCSI_IOCTL_GET_PCI 0x5387
  253. #endif /* _SCSI_SCSI_H */