fsl_sata.h 10 KB

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