scsi.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2001
  4. * Denis Peter, MPL AG Switzerland
  5. */
  6. #ifndef _SCSI_H
  7. #define _SCSI_H
  8. #include <linux/dma-direction.h>
  9. struct scsi_cmd {
  10. unsigned char cmd[16]; /* command */
  11. /* for request sense */
  12. unsigned char sense_buf[64]
  13. __attribute__((aligned(ARCH_DMA_MINALIGN)));
  14. unsigned char status; /* SCSI Status */
  15. unsigned char target; /* Target ID */
  16. unsigned char lun; /* Target LUN */
  17. unsigned char cmdlen; /* command len */
  18. unsigned long datalen; /* Total data length */
  19. unsigned char * pdata; /* pointer to data */
  20. unsigned char msgout[12]; /* Messge out buffer (NOT USED) */
  21. unsigned char msgin[12]; /* Message in buffer */
  22. unsigned char sensecmdlen; /* Sense command len */
  23. unsigned long sensedatalen; /* Sense data len */
  24. unsigned char sensecmd[6]; /* Sense command */
  25. unsigned long contr_stat; /* Controller Status */
  26. unsigned long trans_bytes; /* tranfered bytes */
  27. unsigned int priv;
  28. enum dma_data_direction dma_dir;
  29. };
  30. /*-----------------------------------------------------------
  31. **
  32. ** SCSI constants.
  33. **
  34. **-----------------------------------------------------------
  35. */
  36. /*
  37. ** Messages
  38. */
  39. #define M_COMPLETE (0x00)
  40. #define M_EXTENDED (0x01)
  41. #define M_SAVE_DP (0x02)
  42. #define M_RESTORE_DP (0x03)
  43. #define M_DISCONNECT (0x04)
  44. #define M_ID_ERROR (0x05)
  45. #define M_ABORT (0x06)
  46. #define M_REJECT (0x07)
  47. #define M_NOOP (0x08)
  48. #define M_PARITY (0x09)
  49. #define M_LCOMPLETE (0x0a)
  50. #define M_FCOMPLETE (0x0b)
  51. #define M_RESET (0x0c)
  52. #define M_ABORT_TAG (0x0d)
  53. #define M_CLEAR_QUEUE (0x0e)
  54. #define M_INIT_REC (0x0f)
  55. #define M_REL_REC (0x10)
  56. #define M_TERMINATE (0x11)
  57. #define M_SIMPLE_TAG (0x20)
  58. #define M_HEAD_TAG (0x21)
  59. #define M_ORDERED_TAG (0x22)
  60. #define M_IGN_RESIDUE (0x23)
  61. #define M_IDENTIFY (0x80)
  62. #define M_X_MODIFY_DP (0x00)
  63. #define M_X_SYNC_REQ (0x01)
  64. #define M_X_WIDE_REQ (0x03)
  65. #define M_X_PPR_REQ (0x04)
  66. /*
  67. ** Status
  68. */
  69. #define S_GOOD (0x00)
  70. #define S_CHECK_COND (0x02)
  71. #define S_COND_MET (0x04)
  72. #define S_BUSY (0x08)
  73. #define S_INT (0x10)
  74. #define S_INT_COND_MET (0x14)
  75. #define S_CONFLICT (0x18)
  76. #define S_TERMINATED (0x20)
  77. #define S_QUEUE_FULL (0x28)
  78. #define S_ILLEGAL (0xff)
  79. #define S_SENSE (0x80)
  80. /*
  81. * Sense_keys
  82. */
  83. #define SENSE_NO_SENSE 0x0
  84. #define SENSE_RECOVERED_ERROR 0x1
  85. #define SENSE_NOT_READY 0x2
  86. #define SENSE_MEDIUM_ERROR 0x3
  87. #define SENSE_HARDWARE_ERROR 0x4
  88. #define SENSE_ILLEGAL_REQUEST 0x5
  89. #define SENSE_UNIT_ATTENTION 0x6
  90. #define SENSE_DATA_PROTECT 0x7
  91. #define SENSE_BLANK_CHECK 0x8
  92. #define SENSE_VENDOR_SPECIFIC 0x9
  93. #define SENSE_COPY_ABORTED 0xA
  94. #define SENSE_ABORTED_COMMAND 0xB
  95. #define SENSE_VOLUME_OVERFLOW 0xD
  96. #define SENSE_MISCOMPARE 0xE
  97. #define SCSI_CHANGE_DEF 0x40 /* Change Definition (Optional) */
  98. #define SCSI_COMPARE 0x39 /* Compare (O) */
  99. #define SCSI_COPY 0x18 /* Copy (O) */
  100. #define SCSI_COP_VERIFY 0x3A /* Copy and Verify (O) */
  101. #define SCSI_INQUIRY 0x12 /* Inquiry (MANDATORY) */
  102. #define SCSI_LOG_SELECT 0x4C /* Log Select (O) */
  103. #define SCSI_LOG_SENSE 0x4D /* Log Sense (O) */
  104. #define SCSI_MODE_SEL6 0x15 /* Mode Select 6-byte (Device Specific) */
  105. #define SCSI_MODE_SEL10 0x55 /* Mode Select 10-byte (Device Specific) */
  106. #define SCSI_MODE_SEN6 0x1A /* Mode Sense 6-byte (Device Specific) */
  107. #define SCSI_MODE_SEN10 0x5A /* Mode Sense 10-byte (Device Specific) */
  108. #define SCSI_READ_BUFF 0x3C /* Read Buffer (O) */
  109. #define SCSI_REQ_SENSE 0x03 /* Request Sense (MANDATORY) */
  110. #define SCSI_SEND_DIAG 0x1D /* Send Diagnostic (O) */
  111. #define SCSI_TST_U_RDY 0x00 /* Test Unit Ready (MANDATORY) */
  112. #define SCSI_WRITE_BUFF 0x3B /* Write Buffer (O) */
  113. /***************************************************************************
  114. * %%% Commands Unique to Direct Access Devices %%%
  115. ***************************************************************************/
  116. #define SCSI_COMPARE 0x39 /* Compare (O) */
  117. #define SCSI_FORMAT 0x04 /* Format Unit (MANDATORY) */
  118. #define SCSI_LCK_UN_CAC 0x36 /* Lock Unlock Cache (O) */
  119. #define SCSI_PREFETCH 0x34 /* Prefetch (O) */
  120. #define SCSI_MED_REMOVL 0x1E /* Prevent/Allow medium Removal (O) */
  121. #define SCSI_READ6 0x08 /* Read 6-byte (MANDATORY) */
  122. #define SCSI_READ10 0x28 /* Read 10-byte (MANDATORY) */
  123. #define SCSI_READ16 0x48
  124. #define SCSI_RD_CAPAC 0x25 /* Read Capacity (MANDATORY) */
  125. #define SCSI_RD_CAPAC10 SCSI_RD_CAPAC /* Read Capacity (10) */
  126. #define SCSI_RD_CAPAC16 0x9e /* Read Capacity (16) */
  127. #define SCSI_RD_DEFECT 0x37 /* Read Defect Data (O) */
  128. #define SCSI_READ_LONG 0x3E /* Read Long (O) */
  129. #define SCSI_REASS_BLK 0x07 /* Reassign Blocks (O) */
  130. #define SCSI_RCV_DIAG 0x1C /* Receive Diagnostic Results (O) */
  131. #define SCSI_RELEASE 0x17 /* Release Unit (MANDATORY) */
  132. #define SCSI_REZERO 0x01 /* Rezero Unit (O) */
  133. #define SCSI_SRCH_DAT_E 0x31 /* Search Data Equal (O) */
  134. #define SCSI_SRCH_DAT_H 0x30 /* Search Data High (O) */
  135. #define SCSI_SRCH_DAT_L 0x32 /* Search Data Low (O) */
  136. #define SCSI_SEEK6 0x0B /* Seek 6-Byte (O) */
  137. #define SCSI_SEEK10 0x2B /* Seek 10-Byte (O) */
  138. #define SCSI_SEND_DIAG 0x1D /* Send Diagnostics (MANDATORY) */
  139. #define SCSI_SET_LIMIT 0x33 /* Set Limits (O) */
  140. #define SCSI_START_STP 0x1B /* Start/Stop Unit (O) */
  141. #define SCSI_SYNC_CACHE 0x35 /* Synchronize Cache (O) */
  142. #define SCSI_VERIFY 0x2F /* Verify (O) */
  143. #define SCSI_WRITE6 0x0A /* Write 6-Byte (MANDATORY) */
  144. #define SCSI_WRITE10 0x2A /* Write 10-Byte (MANDATORY) */
  145. #define SCSI_WRT_VERIFY 0x2E /* Write and Verify (O) */
  146. #define SCSI_WRITE_LONG 0x3F /* Write Long (O) */
  147. #define SCSI_WRITE_SAME 0x41 /* Write Same (O) */
  148. /**
  149. * struct scsi_platdata - stores information about SCSI controller
  150. *
  151. * @base: Controller base address
  152. * @max_lun: Maximum number of logical units
  153. * @max_id: Maximum number of target ids
  154. * @max_bytes_per_req: Maximum number of bytes per read/write request
  155. */
  156. struct scsi_platdata {
  157. unsigned long base;
  158. unsigned long max_lun;
  159. unsigned long max_id;
  160. unsigned long max_bytes_per_req;
  161. };
  162. /* Operations for SCSI */
  163. struct scsi_ops {
  164. /**
  165. * exec() - execute a command
  166. *
  167. * @dev: SCSI bus
  168. * @cmd: Command to execute
  169. * @return 0 if OK, -ve on error
  170. */
  171. int (*exec)(struct udevice *dev, struct scsi_cmd *cmd);
  172. /**
  173. * bus_reset() - reset the bus
  174. *
  175. * @dev: SCSI bus to reset
  176. * @return 0 if OK, -ve on error
  177. */
  178. int (*bus_reset)(struct udevice *dev);
  179. };
  180. #define scsi_get_ops(dev) ((struct scsi_ops *)(dev)->driver->ops)
  181. extern struct scsi_ops scsi_ops;
  182. /**
  183. * scsi_exec() - execute a command
  184. *
  185. * @dev: SCSI bus
  186. * @cmd: Command to execute
  187. * @return 0 if OK, -ve on error
  188. */
  189. int scsi_exec(struct udevice *dev, struct scsi_cmd *cmd);
  190. /**
  191. * scsi_bus_reset() - reset the bus
  192. *
  193. * @dev: SCSI bus to reset
  194. * @return 0 if OK, -ve on error
  195. */
  196. int scsi_bus_reset(struct udevice *dev);
  197. /**
  198. * scsi_scan() - Scan all SCSI controllers for available devices
  199. *
  200. * @vebose: true to show information about each device found
  201. */
  202. int scsi_scan(bool verbose);
  203. /**
  204. * scsi_scan_dev() - scan a SCSI bus and create devices
  205. *
  206. * @dev: SCSI bus
  207. * @verbose: true to show information about each device found
  208. */
  209. int scsi_scan_dev(struct udevice *dev, bool verbose);
  210. #ifndef CONFIG_DM_SCSI
  211. void scsi_low_level_init(int busdevfunc);
  212. void scsi_init(void);
  213. #endif
  214. #define SCSI_IDENTIFY 0xC0 /* not used */
  215. /* Hardware errors */
  216. #define SCSI_SEL_TIME_OUT 0x00000101 /* Selection time out */
  217. #define SCSI_HNS_TIME_OUT 0x00000102 /* Handshake */
  218. #define SCSI_MA_TIME_OUT 0x00000103 /* Phase error */
  219. #define SCSI_UNEXP_DIS 0x00000104 /* unexpected disconnect */
  220. #define SCSI_INT_STATE 0x00010000 /* unknown Interrupt number is stored in 16 LSB */
  221. #endif /* _SCSI_H */