scsi.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 <asm/param.h>
  10. #include <scsi/scsi_common.h>
  11. #include <scsi/scsi_proto.h>
  12. #include <scsi/scsi_status.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. /*
  28. * standard mode-select header prepended to all mode-select commands
  29. */
  30. struct ccs_modesel_head {
  31. __u8 _r1; /* reserved */
  32. __u8 medium; /* device-specific medium type */
  33. __u8 _r2; /* reserved */
  34. __u8 block_desc_length; /* block descriptor length */
  35. __u8 density; /* device-specific density code */
  36. __u8 number_blocks_hi; /* number of blocks in this block desc */
  37. __u8 number_blocks_med;
  38. __u8 number_blocks_lo;
  39. __u8 _r3;
  40. __u8 block_length_hi; /* block length for blocks in this desc */
  41. __u8 block_length_med;
  42. __u8 block_length_lo;
  43. };
  44. /*
  45. * The Well Known LUNS (SAM-3) in our int representation of a LUN
  46. */
  47. #define SCSI_W_LUN_BASE 0xc100
  48. #define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1)
  49. #define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2)
  50. #define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3)
  51. static inline int scsi_is_wlun(u64 lun)
  52. {
  53. return (lun & 0xff00) == SCSI_W_LUN_BASE;
  54. }
  55. /**
  56. * scsi_status_is_check_condition - check the status return.
  57. *
  58. * @status: the status passed up from the driver (including host and
  59. * driver components)
  60. *
  61. * Returns: %true if the status code is SAM_STAT_CHECK_CONDITION.
  62. */
  63. static inline int scsi_status_is_check_condition(int status)
  64. {
  65. if (status < 0)
  66. return false;
  67. status &= 0xfe;
  68. return status == SAM_STAT_CHECK_CONDITION;
  69. }
  70. /*
  71. * Extended message codes.
  72. */
  73. #define EXTENDED_MODIFY_DATA_POINTER 0x00
  74. #define EXTENDED_SDTR 0x01
  75. #define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */
  76. #define EXTENDED_WDTR 0x03
  77. #define EXTENDED_PPR 0x04
  78. #define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
  79. /*
  80. * Internal return values.
  81. */
  82. enum scsi_disposition {
  83. NEEDS_RETRY = 0x2001,
  84. SUCCESS = 0x2002,
  85. FAILED = 0x2003,
  86. QUEUED = 0x2004,
  87. SOFT_ERROR = 0x2005,
  88. ADD_TO_MLQUEUE = 0x2006,
  89. TIMEOUT_ERROR = 0x2007,
  90. SCSI_RETURN_NOT_HANDLED = 0x2008,
  91. FAST_IO_FAIL = 0x2009,
  92. };
  93. /*
  94. * Status values returned by the .queuecommand() callback if a command has not
  95. * been queued.
  96. */
  97. enum scsi_qc_status {
  98. SCSI_MLQUEUE_HOST_BUSY = 0x1055,
  99. SCSI_MLQUEUE_DEVICE_BUSY = 0x1056,
  100. SCSI_MLQUEUE_EH_RETRY = 0x1057,
  101. SCSI_MLQUEUE_TARGET_BUSY = 0x1058,
  102. };
  103. /*
  104. * Use these to separate status msg and our bytes
  105. *
  106. * These are set by:
  107. *
  108. * status byte = set from target device
  109. * msg_byte (unused)
  110. * host_byte = set by low-level driver to indicate status.
  111. */
  112. #define status_byte(result) (result & 0xff)
  113. #define host_byte(result) (((result) >> 16) & 0xff)
  114. #define sense_class(sense) (((sense) >> 4) & 0x7)
  115. #define sense_error(sense) ((sense) & 0xf)
  116. #define sense_valid(sense) ((sense) & 0x80)
  117. /*
  118. * default timeouts
  119. */
  120. #define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * HZ)
  121. #define START_STOP_TIMEOUT (60 * HZ)
  122. #define MOVE_MEDIUM_TIMEOUT (5 * 60 * HZ)
  123. #define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ)
  124. #define READ_DEFECT_DATA_TIMEOUT (60 * HZ )
  125. #define IDENTIFY_BASE 0x80
  126. #define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
  127. ((can_disconnect) ? 0x40 : 0) |\
  128. ((lun) & 0x07))
  129. /*
  130. * struct scsi_device::scsi_level values. For SCSI devices other than those
  131. * prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1)
  132. * where "resp" is a byte array of the response to an INQUIRY. The scsi_level
  133. * variable is visible to the user via sysfs.
  134. */
  135. #define SCSI_UNKNOWN 0
  136. #define SCSI_1 1
  137. #define SCSI_1_CCS 2
  138. #define SCSI_2 3
  139. #define SCSI_3 4 /* SPC */
  140. #define SCSI_SPC_2 5
  141. #define SCSI_SPC_3 6
  142. #define SCSI_SPC_4 7
  143. #define SCSI_SPC_5 8
  144. #define SCSI_SPC_6 14
  145. /*
  146. * INQ PERIPHERAL QUALIFIERS
  147. */
  148. #define SCSI_INQ_PQ_CON 0x00
  149. #define SCSI_INQ_PQ_NOT_CON 0x01
  150. #define SCSI_INQ_PQ_NOT_CAP 0x03
  151. /*
  152. * Here are some scsi specific ioctl commands which are sometimes useful.
  153. *
  154. * Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395
  155. */
  156. /* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */
  157. #define SCSI_IOCTL_GET_IDLUN 0x5382
  158. /* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */
  159. /* Used to obtain the host number of a device. */
  160. #define SCSI_IOCTL_PROBE_HOST 0x5385
  161. /* Used to obtain the bus number for a device */
  162. #define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
  163. /* Used to obtain the PCI location of a device */
  164. #define SCSI_IOCTL_GET_PCI 0x5387
  165. /**
  166. * scsi_status_is_good - check the status return.
  167. *
  168. * @status: the status passed up from the driver (including host and
  169. * driver components)
  170. *
  171. * Returns: %true for known good conditions that may be treated as
  172. * command completed normally
  173. */
  174. static inline bool scsi_status_is_good(int status)
  175. {
  176. if (status < 0)
  177. return false;
  178. if (host_byte(status) == DID_NO_CONNECT)
  179. return false;
  180. /*
  181. * FIXME: bit0 is listed as reserved in SCSI-2, but is
  182. * significant in SCSI-3. For now, we follow the SCSI-2
  183. * behaviour and ignore reserved bits.
  184. */
  185. status &= 0xfe;
  186. return ((status == SAM_STAT_GOOD) ||
  187. (status == SAM_STAT_CONDITION_MET) ||
  188. /* Next two "intermediate" statuses are obsolete in SAM-4 */
  189. (status == SAM_STAT_INTERMEDIATE) ||
  190. (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
  191. /* FIXME: this is obsolete in SAM-3 */
  192. (status == SAM_STAT_COMMAND_TERMINATED));
  193. }
  194. #endif /* _SCSI_SCSI_H */