scsi.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 <asm/cache.h>
  9. #include <linux/dma-direction.h>
  10. /* Fix this to the maximum */
  11. #define SCSI_MAX_DEVICE \
  12. (CONFIG_SYS_SCSI_MAX_SCSI_ID * CONFIG_SYS_SCSI_MAX_LUN)
  13. struct udevice;
  14. /**
  15. * struct scsi_cmd - information about a SCSI command to be processed
  16. *
  17. * @cmd: command
  18. * @sense_buf: for request sense
  19. * @status: SCSI Status
  20. * @target: Target ID
  21. * @lun: Target LUN
  22. * @cmdlen: command len
  23. * @datalen: Total data length
  24. * @pdata: pointer to data
  25. * @msgout: Messge out buffer (NOT USED)
  26. * @msgin: Message in buffer
  27. * @sensecmdlen: Sense command len
  28. * @sensedatalen: Sense data len
  29. * @sensecmd: Sense command
  30. * @contr_stat: Controller Status
  31. * @trans_bytes: tranfered bytes
  32. * @priv: Private value
  33. * @dma_dir: Direction of data structure
  34. */
  35. struct scsi_cmd {
  36. unsigned char cmd[16];
  37. unsigned char sense_buf[64]
  38. __attribute__((aligned(ARCH_DMA_MINALIGN)));
  39. unsigned char status;
  40. unsigned char target;
  41. unsigned char lun;
  42. unsigned char cmdlen;
  43. unsigned long datalen;
  44. unsigned char *pdata;
  45. unsigned char msgout[12];
  46. unsigned char msgin[12];
  47. unsigned char sensecmdlen;
  48. unsigned long sensedatalen;
  49. unsigned char sensecmd[6];
  50. unsigned long contr_stat;
  51. unsigned long trans_bytes;
  52. unsigned int priv;
  53. enum dma_data_direction dma_dir;
  54. };
  55. /*-----------------------------------------------------------
  56. **
  57. ** SCSI constants.
  58. **
  59. **-----------------------------------------------------------
  60. */
  61. /*
  62. ** Messages
  63. */
  64. #define M_COMPLETE (0x00)
  65. #define M_EXTENDED (0x01)
  66. #define M_SAVE_DP (0x02)
  67. #define M_RESTORE_DP (0x03)
  68. #define M_DISCONNECT (0x04)
  69. #define M_ID_ERROR (0x05)
  70. #define M_ABORT (0x06)
  71. #define M_REJECT (0x07)
  72. #define M_NOOP (0x08)
  73. #define M_PARITY (0x09)
  74. #define M_LCOMPLETE (0x0a)
  75. #define M_FCOMPLETE (0x0b)
  76. #define M_RESET (0x0c)
  77. #define M_ABORT_TAG (0x0d)
  78. #define M_CLEAR_QUEUE (0x0e)
  79. #define M_INIT_REC (0x0f)
  80. #define M_REL_REC (0x10)
  81. #define M_TERMINATE (0x11)
  82. #define M_SIMPLE_TAG (0x20)
  83. #define M_HEAD_TAG (0x21)
  84. #define M_ORDERED_TAG (0x22)
  85. #define M_IGN_RESIDUE (0x23)
  86. #define M_IDENTIFY (0x80)
  87. #define M_X_MODIFY_DP (0x00)
  88. #define M_X_SYNC_REQ (0x01)
  89. #define M_X_WIDE_REQ (0x03)
  90. #define M_X_PPR_REQ (0x04)
  91. /*
  92. ** Status
  93. */
  94. #define S_GOOD (0x00)
  95. #define S_CHECK_COND (0x02)
  96. #define S_COND_MET (0x04)
  97. #define S_BUSY (0x08)
  98. #define S_INT (0x10)
  99. #define S_INT_COND_MET (0x14)
  100. #define S_CONFLICT (0x18)
  101. #define S_TERMINATED (0x20)
  102. #define S_QUEUE_FULL (0x28)
  103. #define S_ILLEGAL (0xff)
  104. #define S_SENSE (0x80)
  105. /*
  106. * Sense_keys
  107. */
  108. #define SENSE_NO_SENSE 0x0
  109. #define SENSE_RECOVERED_ERROR 0x1
  110. #define SENSE_NOT_READY 0x2
  111. #define SENSE_MEDIUM_ERROR 0x3
  112. #define SENSE_HARDWARE_ERROR 0x4
  113. #define SENSE_ILLEGAL_REQUEST 0x5
  114. #define SENSE_UNIT_ATTENTION 0x6
  115. #define SENSE_DATA_PROTECT 0x7
  116. #define SENSE_BLANK_CHECK 0x8
  117. #define SENSE_VENDOR_SPECIFIC 0x9
  118. #define SENSE_COPY_ABORTED 0xA
  119. #define SENSE_ABORTED_COMMAND 0xB
  120. #define SENSE_VOLUME_OVERFLOW 0xD
  121. #define SENSE_MISCOMPARE 0xE
  122. #define SCSI_CHANGE_DEF 0x40 /* Change Definition (Optional) */
  123. #define SCSI_COMPARE 0x39 /* Compare (O) */
  124. #define SCSI_COPY 0x18 /* Copy (O) */
  125. #define SCSI_COP_VERIFY 0x3A /* Copy and Verify (O) */
  126. #define SCSI_INQUIRY 0x12 /* Inquiry (MANDATORY) */
  127. #define SCSI_LOG_SELECT 0x4C /* Log Select (O) */
  128. #define SCSI_LOG_SENSE 0x4D /* Log Sense (O) */
  129. #define SCSI_MODE_SEL6 0x15 /* Mode Select 6-byte (Device Specific) */
  130. #define SCSI_MODE_SEL10 0x55 /* Mode Select 10-byte (Device Specific) */
  131. #define SCSI_MODE_SEN6 0x1A /* Mode Sense 6-byte (Device Specific) */
  132. #define SCSI_MODE_SEN10 0x5A /* Mode Sense 10-byte (Device Specific) */
  133. #define SCSI_READ_BUFF 0x3C /* Read Buffer (O) */
  134. #define SCSI_REQ_SENSE 0x03 /* Request Sense (MANDATORY) */
  135. #define SCSI_SEND_DIAG 0x1D /* Send Diagnostic (O) */
  136. #define SCSI_TST_U_RDY 0x00 /* Test Unit Ready (MANDATORY) */
  137. #define SCSI_WRITE_BUFF 0x3B /* Write Buffer (O) */
  138. /***************************************************************************
  139. * %%% Commands Unique to Direct Access Devices %%%
  140. ***************************************************************************/
  141. #define SCSI_COMPARE 0x39 /* Compare (O) */
  142. #define SCSI_FORMAT 0x04 /* Format Unit (MANDATORY) */
  143. #define SCSI_LCK_UN_CAC 0x36 /* Lock Unlock Cache (O) */
  144. #define SCSI_PREFETCH 0x34 /* Prefetch (O) */
  145. #define SCSI_MED_REMOVL 0x1E /* Prevent/Allow medium Removal (O) */
  146. #define SCSI_READ6 0x08 /* Read 6-byte (MANDATORY) */
  147. #define SCSI_READ10 0x28 /* Read 10-byte (MANDATORY) */
  148. #define SCSI_READ16 0x48
  149. #define SCSI_RD_CAPAC 0x25 /* Read Capacity (MANDATORY) */
  150. #define SCSI_RD_CAPAC10 SCSI_RD_CAPAC /* Read Capacity (10) */
  151. #define SCSI_RD_CAPAC16 0x9e /* Read Capacity (16) */
  152. #define SCSI_RD_DEFECT 0x37 /* Read Defect Data (O) */
  153. #define SCSI_READ_LONG 0x3E /* Read Long (O) */
  154. #define SCSI_REASS_BLK 0x07 /* Reassign Blocks (O) */
  155. #define SCSI_RCV_DIAG 0x1C /* Receive Diagnostic Results (O) */
  156. #define SCSI_RELEASE 0x17 /* Release Unit (MANDATORY) */
  157. #define SCSI_REZERO 0x01 /* Rezero Unit (O) */
  158. #define SCSI_SRCH_DAT_E 0x31 /* Search Data Equal (O) */
  159. #define SCSI_SRCH_DAT_H 0x30 /* Search Data High (O) */
  160. #define SCSI_SRCH_DAT_L 0x32 /* Search Data Low (O) */
  161. #define SCSI_SEEK6 0x0B /* Seek 6-Byte (O) */
  162. #define SCSI_SEEK10 0x2B /* Seek 10-Byte (O) */
  163. #define SCSI_SEND_DIAG 0x1D /* Send Diagnostics (MANDATORY) */
  164. #define SCSI_SET_LIMIT 0x33 /* Set Limits (O) */
  165. #define SCSI_START_STP 0x1B /* Start/Stop Unit (O) */
  166. #define SCSI_SYNC_CACHE 0x35 /* Synchronize Cache (O) */
  167. #define SCSI_VERIFY 0x2F /* Verify (O) */
  168. #define SCSI_WRITE6 0x0A /* Write 6-Byte (MANDATORY) */
  169. #define SCSI_WRITE10 0x2A /* Write 10-Byte (MANDATORY) */
  170. #define SCSI_WRT_VERIFY 0x2E /* Write and Verify (O) */
  171. #define SCSI_WRITE_LONG 0x3F /* Write Long (O) */
  172. #define SCSI_WRITE_SAME 0x41 /* Write Same (O) */
  173. /**
  174. * enum scsi_cmd_phase - current phase of the SCSI protocol
  175. *
  176. * @SCSIPH_START: Start phase
  177. * @SCSIPH_DATA: Data phase
  178. * @SCSIPH_STATUS: Status phase
  179. */
  180. enum scsi_cmd_phase {
  181. SCSIPH_START,
  182. SCSIPH_DATA,
  183. SCSIPH_STATUS,
  184. };
  185. /**
  186. * struct scsi_inquiry_resp - holds a SCSI inquiry command
  187. *
  188. * @type; command type
  189. * @flags; command flags
  190. * @version; command version
  191. * @data_format; data format
  192. * @additional_len; additional data length
  193. * @spare[3]; spare bytes
  194. * @vendor[8]; vendor information
  195. * @product[16]; production information
  196. * @revision[4]; revision information
  197. */
  198. struct scsi_inquiry_resp {
  199. u8 type;
  200. u8 flags;
  201. u8 version;
  202. u8 data_format;
  203. u8 additional_len;
  204. u8 spare[3];
  205. char vendor[8];
  206. char product[16];
  207. char revision[4];
  208. };
  209. /**
  210. * struct scsi_read_capacity_resp - holds the response to a read-capacity cmd
  211. *
  212. * @last_block_addr: Logical block address of last block
  213. * @block_len: Length of each block in bytes
  214. */
  215. struct scsi_read_capacity_resp {
  216. u32 last_block_addr;
  217. u32 block_len;
  218. };
  219. /**
  220. * struct scsi_read10_req - holds a SCSI READ10 request
  221. *
  222. * @cmd; command type
  223. * @lun_flags; LUN flags
  224. * @lba; Logical block address to start reading from
  225. * @spare; spare bytes
  226. * @xfer_len: number of blocks to read
  227. * @spare2: more spare bytes
  228. */
  229. struct __packed scsi_read10_req {
  230. u8 cmd;
  231. u8 lun_flags;
  232. u32 lba;
  233. u8 spare;
  234. u16 xfer_len;
  235. u8 spare2[3];
  236. };
  237. /** struct scsi_write10_req - data for the write10 command */
  238. struct __packed scsi_write10_req {
  239. u8 cmd;
  240. u8 lun_flags;
  241. u32 lba;
  242. u8 spare;
  243. u16 xfer_len;
  244. u8 spare2[3];
  245. };
  246. /**
  247. * struct scsi_plat - stores information about SCSI controller
  248. *
  249. * @base: Controller base address
  250. * @max_lun: Maximum number of logical units
  251. * @max_id: Maximum number of target ids
  252. * @max_bytes_per_req: Maximum number of bytes per read/write request
  253. */
  254. struct scsi_plat {
  255. unsigned long base;
  256. unsigned long max_lun;
  257. unsigned long max_id;
  258. unsigned long max_bytes_per_req;
  259. };
  260. /* Operations for SCSI */
  261. struct scsi_ops {
  262. /**
  263. * exec() - execute a command
  264. *
  265. * @dev: SCSI bus
  266. * @cmd: Command to execute
  267. * @return 0 if OK, -ve on error
  268. */
  269. int (*exec)(struct udevice *dev, struct scsi_cmd *cmd);
  270. /**
  271. * bus_reset() - reset the bus
  272. *
  273. * @dev: SCSI bus to reset
  274. * @return 0 if OK, -ve on error
  275. */
  276. int (*bus_reset)(struct udevice *dev);
  277. };
  278. #define scsi_get_ops(dev) ((struct scsi_ops *)(dev)->driver->ops)
  279. extern struct scsi_ops scsi_ops;
  280. /**
  281. * scsi_exec() - execute a command
  282. *
  283. * @dev: SCSI bus
  284. * @cmd: Command to execute
  285. * Return: 0 if OK, -ve on error
  286. */
  287. int scsi_exec(struct udevice *dev, struct scsi_cmd *cmd);
  288. /**
  289. * scsi_bus_reset() - reset the bus
  290. *
  291. * @dev: SCSI bus to reset
  292. * Return: 0 if OK, -ve on error
  293. */
  294. int scsi_bus_reset(struct udevice *dev);
  295. /**
  296. * scsi_scan() - Scan all SCSI controllers for available devices
  297. *
  298. * @vebose: true to show information about each device found
  299. */
  300. int scsi_scan(bool verbose);
  301. /**
  302. * scsi_scan_dev() - scan a SCSI bus and create devices
  303. *
  304. * @dev: SCSI bus
  305. * @verbose: true to show information about each device found
  306. */
  307. int scsi_scan_dev(struct udevice *dev, bool verbose);
  308. #ifndef CONFIG_DM_SCSI
  309. void scsi_low_level_init(int busdevfunc);
  310. void scsi_init(void);
  311. #endif
  312. #define SCSI_IDENTIFY 0xC0 /* not used */
  313. /* Hardware errors */
  314. #define SCSI_SEL_TIME_OUT 0x00000101 /* Selection time out */
  315. #define SCSI_HNS_TIME_OUT 0x00000102 /* Handshake */
  316. #define SCSI_MA_TIME_OUT 0x00000103 /* Phase error */
  317. #define SCSI_UNEXP_DIS 0x00000104 /* unexpected disconnect */
  318. #define SCSI_INT_STATE 0x00010000 /* unknown Interrupt number is stored in 16 LSB */
  319. #endif /* _SCSI_H */