fsl_sata.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2007-2008 Freescale Semiconductor, Inc.
  4. * Dave Liu <daveliu@freescale.com>
  5. */
  6. #ifndef __FSL_SATA_H__
  7. #define __FSL_SATA_H__
  8. #define SATA_HC_MAX_NUM 4 /* Max host controller numbers */
  9. #define SATA_HC_MAX_CMD 16 /* Max command queue depth per host controller */
  10. #define SATA_HC_MAX_PORT 16 /* Max port number per host controller */
  11. /*
  12. * SATA Host Controller Registers
  13. */
  14. typedef struct fsl_sata_reg {
  15. /* SATA command registers */
  16. u32 cqr; /* Command queue register */
  17. u8 res1[0x4];
  18. u32 car; /* Command active register */
  19. u8 res2[0x4];
  20. u32 ccr; /* Command completed register */
  21. u8 res3[0x4];
  22. u32 cer; /* Command error register */
  23. u8 res4[0x4];
  24. u32 der; /* Device error register */
  25. u32 chba; /* Command header base address */
  26. u32 hstatus; /* Host status register */
  27. u32 hcontrol; /* Host control register */
  28. u32 cqpmp; /* Port number queue register */
  29. u32 sig; /* Signature register */
  30. u32 icc; /* Interrupt coalescing control register */
  31. u8 res5[0xc4];
  32. /* SATA supperset registers */
  33. u32 sstatus; /* SATA interface status register */
  34. u32 serror; /* SATA interface error register */
  35. u32 scontrol; /* SATA interface control register */
  36. u32 snotification; /* SATA interface notification register */
  37. u8 res6[0x30];
  38. /* SATA control status registers */
  39. u32 transcfg; /* Transport layer configuration */
  40. u32 transstatus; /* Transport layer status */
  41. u32 linkcfg; /* Link layer configuration */
  42. u32 linkcfg1; /* Link layer configuration1 */
  43. u32 linkcfg2; /* Link layer configuration2 */
  44. u32 linkstatus; /* Link layer status */
  45. u32 linkstatus1; /* Link layer status1 */
  46. u32 phyctrlcfg; /* PHY control configuration */
  47. u8 res7[0x2b0];
  48. /* SATA system control registers */
  49. u32 syspr; /* System priority register - big endian */
  50. u8 res8[0xbec];
  51. } __attribute__ ((packed)) fsl_sata_reg_t;
  52. /* HStatus register
  53. */
  54. #define HSTATUS_ONOFF 0x80000000 /* Online/offline status */
  55. #define HSTATUS_FORCE_OFFLINE 0x40000000 /* In process going offline */
  56. #define HSTATUS_BIST_ERR 0x20000000
  57. /* Fatal error */
  58. #define HSTATUS_MASTER_ERR 0x00004000
  59. #define HSTATUS_DATA_UNDERRUN 0x00002000
  60. #define HSTATUS_DATA_OVERRUN 0x00001000
  61. #define HSTATUS_CRC_ERR_TX 0x00000800
  62. #define HSTATUS_CRC_ERR_RX 0x00000400
  63. #define HSTATUS_FIFO_OVERFLOW_TX 0x00000200
  64. #define HSTATUS_FIFO_OVERFLOW_RX 0x00000100
  65. #define HSTATUS_FATAL_ERR_ALL (HSTATUS_MASTER_ERR | \
  66. HSTATUS_DATA_UNDERRUN | \
  67. HSTATUS_DATA_OVERRUN | \
  68. HSTATUS_CRC_ERR_TX | \
  69. HSTATUS_CRC_ERR_RX | \
  70. HSTATUS_FIFO_OVERFLOW_TX | \
  71. HSTATUS_FIFO_OVERFLOW_RX)
  72. /* Interrupt status */
  73. #define HSTATUS_FATAL_ERR 0x00000020
  74. #define HSTATUS_PHY_RDY 0x00000010
  75. #define HSTATUS_SIGNATURE 0x00000008
  76. #define HSTATUS_SNOTIFY 0x00000004
  77. #define HSTATUS_DEVICE_ERR 0x00000002
  78. #define HSTATUS_CMD_COMPLETE 0x00000001
  79. /* HControl register
  80. */
  81. #define HCONTROL_ONOFF 0x80000000 /* Online or offline request */
  82. #define HCONTROL_FORCE_OFFLINE 0x40000000 /* Force offline request */
  83. #define HCONTROL_ENTERPRISE_EN 0x10000000 /* Enterprise mode enabled */
  84. #define HCONTROL_HDR_SNOOP 0x00000400 /* Command header snoop */
  85. #define HCONTROL_PMP_ATTACHED 0x00000200 /* Port multiplier attached */
  86. /* Interrupt enable */
  87. #define HCONTROL_FATAL_ERR 0x00000020
  88. #define HCONTROL_PHY_RDY 0x00000010
  89. #define HCONTROL_SIGNATURE 0x00000008
  90. #define HCONTROL_SNOTIFY 0x00000004
  91. #define HCONTROL_DEVICE_ERR 0x00000002
  92. #define HCONTROL_CMD_COMPLETE 0x00000001
  93. #define HCONTROL_INT_EN_ALL (HCONTROL_FATAL_ERR | \
  94. HCONTROL_PHY_RDY | \
  95. HCONTROL_SIGNATURE | \
  96. HCONTROL_SNOTIFY | \
  97. HCONTROL_DEVICE_ERR | \
  98. HCONTROL_CMD_COMPLETE)
  99. /* SStatus register
  100. */
  101. #define SSTATUS_IPM_MASK 0x00000780
  102. #define SSTATUS_IPM_NOPRESENT 0x00000000
  103. #define SSTATUS_IPM_ACTIVE 0x00000080
  104. #define SSTATUS_IPM_PATIAL 0x00000100
  105. #define SSTATUS_IPM_SLUMBER 0x00000300
  106. #define SSTATUS_SPD_MASK 0x000000f0
  107. #define SSTATUS_SPD_GEN1 0x00000010
  108. #define SSTATUS_SPD_GEN2 0x00000020
  109. #define SSTATUS_DET_MASK 0x0000000f
  110. #define SSTATUS_DET_NODEVICE 0x00000000
  111. #define SSTATUS_DET_DISCONNECT 0x00000001
  112. #define SSTATUS_DET_CONNECT 0x00000003
  113. #define SSTATUS_DET_PHY_OFFLINE 0x00000004
  114. /* SControl register
  115. */
  116. #define SCONTROL_SPM_MASK 0x0000f000
  117. #define SCONTROL_SPM_GO_PARTIAL 0x00001000
  118. #define SCONTROL_SPM_GO_SLUMBER 0x00002000
  119. #define SCONTROL_SPM_GO_ACTIVE 0x00004000
  120. #define SCONTROL_IPM_MASK 0x00000f00
  121. #define SCONTROL_IPM_NO_RESTRICT 0x00000000
  122. #define SCONTROL_IPM_PARTIAL 0x00000100
  123. #define SCONTROL_IPM_SLUMBER 0x00000200
  124. #define SCONTROL_IPM_PART_SLUM 0x00000300
  125. #define SCONTROL_SPD_MASK 0x000000f0
  126. #define SCONTROL_SPD_NO_RESTRICT 0x00000000
  127. #define SCONTROL_SPD_GEN1 0x00000010
  128. #define SCONTROL_SPD_GEN2 0x00000020
  129. #define SCONTROL_DET_MASK 0x0000000f
  130. #define SCONTROL_DET_HRESET 0x00000001
  131. #define SCONTROL_DET_DISABLE 0x00000004
  132. /* TransCfg register
  133. */
  134. #define TRANSCFG_DFIS_SIZE_SHIFT 16
  135. #define TRANSCFG_RX_WATER_MARK_MASK 0x0000001f
  136. /* PhyCtrlCfg register
  137. */
  138. #define PHYCTRLCFG_FPRFTI_MASK 0x00000018
  139. #define PHYCTRLCFG_LOOPBACK_MASK 0x0000000e
  140. /*
  141. * Command Header Entry
  142. */
  143. typedef struct cmd_hdr_entry {
  144. __le32 cda; /* Command Descriptor Address,
  145. 4 bytes aligned */
  146. __le32 prde_fis_len; /* Number of PRD entries and FIS length */
  147. __le32 ttl; /* Total transfer length */
  148. __le32 attribute; /* the attribute of command */
  149. } __attribute__ ((packed)) cmd_hdr_entry_t;
  150. #define SATA_HC_CMD_HDR_ENTRY_SIZE sizeof(struct cmd_hdr_entry)
  151. /* cda
  152. */
  153. #define CMD_HDR_CDA_ALIGN 4
  154. /* prde_fis_len
  155. */
  156. #define CMD_HDR_PRD_ENTRY_SHIFT 16
  157. #define CMD_HDR_PRD_ENTRY_MASK 0x003f0000
  158. #define CMD_HDR_FIS_LEN_SHIFT 2
  159. /* attribute
  160. */
  161. #define CMD_HDR_ATTR_RES 0x00000800 /* Reserved bit, should be 1 */
  162. #define CMD_HDR_ATTR_VBIST 0x00000400 /* Vendor BIST */
  163. #define CMD_HDR_ATTR_SNOOP 0x00000200 /* Snoop enable for all descriptor */
  164. #define CMD_HDR_ATTR_FPDMA 0x00000100 /* FPDMA queued command */
  165. #define CMD_HDR_ATTR_RESET 0x00000080 /* Reset - a SRST or device reset */
  166. #define CMD_HDR_ATTR_BIST 0x00000040 /* BIST - require the host to enter BIST mode */
  167. #define CMD_HDR_ATTR_ATAPI 0x00000020 /* ATAPI command */
  168. #define CMD_HDR_ATTR_TAG 0x0000001f /* TAG mask */
  169. /* command type
  170. */
  171. enum cmd_type {
  172. CMD_VENDOR_BIST,
  173. CMD_BIST,
  174. CMD_RESET, /* SRST or device reset */
  175. CMD_ATAPI,
  176. CMD_NCQ,
  177. CMD_ATA, /* None of all above */
  178. };
  179. /*
  180. * Command Header Table
  181. */
  182. typedef struct cmd_hdr_tbl {
  183. cmd_hdr_entry_t cmd_slot[SATA_HC_MAX_CMD];
  184. } __attribute__ ((packed)) cmd_hdr_tbl_t;
  185. #define SATA_HC_CMD_HDR_TBL_SIZE sizeof(struct cmd_hdr_tbl)
  186. #define SATA_HC_CMD_HDR_TBL_ALIGN 4
  187. /*
  188. * PRD entry - Physical Region Descriptor entry
  189. */
  190. typedef struct prd_entry {
  191. __le32 dba; /* Data base address, 4 bytes aligned */
  192. u32 res1;
  193. u32 res2;
  194. __le32 ext_c_ddc; /* Indirect PRD flags, snoop and data word count */
  195. } __attribute__ ((packed)) prd_entry_t;
  196. #define SATA_HC_CMD_DESC_PRD_SIZE sizeof(struct prd_entry)
  197. /* dba
  198. */
  199. #define PRD_ENTRY_DBA_ALIGN 4
  200. /* ext_c_ddc
  201. */
  202. #define PRD_ENTRY_EXT 0x80000000 /* extension flag */
  203. #ifdef CONFIG_FSL_SATA_V2
  204. #define PRD_ENTRY_DATA_SNOOP 0x10000000 /* Data snoop enable */
  205. #else
  206. #define PRD_ENTRY_DATA_SNOOP 0x00400000 /* Data snoop enable */
  207. #endif
  208. #define PRD_ENTRY_LEN_MASK 0x003fffff /* Data word count */
  209. #define PRD_ENTRY_MAX_XFER_SZ (PRD_ENTRY_LEN_MASK + 1)
  210. /*
  211. * This SATA host controller supports a max of 16 direct PRD entries, but if use
  212. * chained indirect PRD entries, then the contollers supports upto a max of 63
  213. * entries including direct and indirect PRD entries.
  214. * The PRDT is an array of 63 PRD entries contigiously, but the PRD entries#15
  215. * will be setup as an indirect descriptor, pointing to it's next (contigious)
  216. * PRD entries#16.
  217. */
  218. #define SATA_HC_MAX_PRD 63 /* Max PRD entry numbers per command */
  219. #define SATA_HC_MAX_PRD_DIRECT 16 /* Direct PRDT entries */
  220. #define SATA_HC_MAX_PRD_USABLE (SATA_HC_MAX_PRD - 1)
  221. #define SATA_HC_MAX_XFER_LEN 0x4000000
  222. /*
  223. * PRDT - Physical Region Descriptor Table
  224. */
  225. typedef struct prdt {
  226. prd_entry_t prdt[SATA_HC_MAX_PRD];
  227. } __attribute__ ((packed)) prdt_t;
  228. /*
  229. * Command Descriptor
  230. */
  231. #define SATA_HC_CMD_DESC_CFIS_SIZE 32 /* bytes */
  232. #define SATA_HC_CMD_DESC_SFIS_SIZE 32 /* bytes */
  233. #define SATA_HC_CMD_DESC_ACMD_SIZE 16 /* bytes */
  234. #define SATA_HC_CMD_DESC_RES 16 /* bytes */
  235. typedef struct cmd_desc {
  236. u8 cfis[SATA_HC_CMD_DESC_CFIS_SIZE];
  237. u8 sfis[SATA_HC_CMD_DESC_SFIS_SIZE];
  238. u8 acmd[SATA_HC_CMD_DESC_ACMD_SIZE];
  239. u8 res[SATA_HC_CMD_DESC_RES];
  240. prd_entry_t prdt[SATA_HC_MAX_PRD];
  241. } __attribute__ ((packed)) cmd_desc_t;
  242. #define SATA_HC_CMD_DESC_SIZE sizeof(struct cmd_desc)
  243. #define SATA_HC_CMD_DESC_ALIGN 4
  244. /*
  245. * SATA device driver info
  246. */
  247. typedef struct fsl_sata_info {
  248. u32 sata_reg_base;
  249. u32 flags;
  250. } fsl_sata_info_t;
  251. #define FLAGS_DMA 0x00000000
  252. #define FLAGS_FPDMA 0x00000001
  253. /*
  254. * SATA device driver struct
  255. */
  256. typedef struct fsl_sata {
  257. char name[12];
  258. fsl_sata_reg_t *reg_base; /* the base address of controller register */
  259. void *cmd_hdr_tbl_offset; /* alloc address of command header table */
  260. cmd_hdr_tbl_t *cmd_hdr; /* aligned address of command header table */
  261. void *cmd_desc_offset; /* alloc address of command descriptor */
  262. cmd_desc_t *cmd_desc; /* aligned address of command descriptor */
  263. int link; /* PHY link status */
  264. /* device attribute */
  265. int ata_device_type; /* device type */
  266. int lba48;
  267. int queue_depth; /* Max NCQ queue depth */
  268. u16 pio;
  269. u16 mwdma;
  270. u16 udma;
  271. int wcache;
  272. int flush;
  273. int flush_ext;
  274. } fsl_sata_t;
  275. #define READ_CMD 0
  276. #define WRITE_CMD 1
  277. #endif /* __FSL_SATA_H__ */