scsi.h 9.5 KB

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