fsl_sata.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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_HDR_SNOOP 0x00000400 /* Command header snoop */
  98. #define HCONTROL_PMP_ATTACHED 0x00000200 /* Port multiplier attached */
  99. /* Interrupt enable */
  100. #define HCONTROL_FATAL_ERR 0x00000020
  101. #define HCONTROL_PHY_RDY 0x00000010
  102. #define HCONTROL_SIGNATURE 0x00000008
  103. #define HCONTROL_SNOTIFY 0x00000004
  104. #define HCONTROL_DEVICE_ERR 0x00000002
  105. #define HCONTROL_CMD_COMPLETE 0x00000001
  106. #define HCONTROL_INT_EN_ALL (HCONTROL_FATAL_ERR | \
  107. HCONTROL_PHY_RDY | \
  108. HCONTROL_SIGNATURE | \
  109. HCONTROL_SNOTIFY | \
  110. HCONTROL_DEVICE_ERR | \
  111. HCONTROL_CMD_COMPLETE)
  112. /* SStatus register
  113. */
  114. #define SSTATUS_IPM_MASK 0x00000780
  115. #define SSTATUS_IPM_NOPRESENT 0x00000000
  116. #define SSTATUS_IPM_ACTIVE 0x00000080
  117. #define SSTATUS_IPM_PATIAL 0x00000100
  118. #define SSTATUS_IPM_SLUMBER 0x00000300
  119. #define SSTATUS_SPD_MASK 0x000000f0
  120. #define SSTATUS_SPD_GEN1 0x00000010
  121. #define SSTATUS_SPD_GEN2 0x00000020
  122. #define SSTATUS_DET_MASK 0x0000000f
  123. #define SSTATUS_DET_NODEVICE 0x00000000
  124. #define SSTATUS_DET_DISCONNECT 0x00000001
  125. #define SSTATUS_DET_CONNECT 0x00000003
  126. #define SSTATUS_DET_PHY_OFFLINE 0x00000004
  127. /* SControl register
  128. */
  129. #define SCONTROL_SPM_MASK 0x0000f000
  130. #define SCONTROL_SPM_GO_PARTIAL 0x00001000
  131. #define SCONTROL_SPM_GO_SLUMBER 0x00002000
  132. #define SCONTROL_SPM_GO_ACTIVE 0x00004000
  133. #define SCONTROL_IPM_MASK 0x00000f00
  134. #define SCONTROL_IPM_NO_RESTRICT 0x00000000
  135. #define SCONTROL_IPM_PARTIAL 0x00000100
  136. #define SCONTROL_IPM_SLUMBER 0x00000200
  137. #define SCONTROL_IPM_PART_SLUM 0x00000300
  138. #define SCONTROL_SPD_MASK 0x000000f0
  139. #define SCONTROL_SPD_NO_RESTRICT 0x00000000
  140. #define SCONTROL_SPD_GEN1 0x00000010
  141. #define SCONTROL_SPD_GEN2 0x00000020
  142. #define SCONTROL_DET_MASK 0x0000000f
  143. #define SCONTROL_DET_HRESET 0x00000001
  144. #define SCONTROL_DET_DISABLE 0x00000004
  145. /* TransCfg register
  146. */
  147. #define TRANSCFG_DFIS_SIZE_SHIFT 16
  148. #define TRANSCFG_RX_WATER_MARK_MASK 0x0000001f
  149. /* PhyCtrlCfg register
  150. */
  151. #define PHYCTRLCFG_FPRFTI_MASK 0x00000018
  152. #define PHYCTRLCFG_LOOPBACK_MASK 0x0000000e
  153. /*
  154. * Command Header Entry
  155. */
  156. typedef struct cmd_hdr_entry {
  157. u32 cda; /* Command Descriptor Address, 4 bytes aligned */
  158. u32 prde_fis_len; /* Number of PRD entries and FIS length */
  159. u32 ttl; /* Total transfer length */
  160. u32 attribute; /* the attribute of command */
  161. } __attribute__ ((packed)) cmd_hdr_entry_t;
  162. #define SATA_HC_CMD_HDR_ENTRY_SIZE sizeof(struct cmd_hdr_entry)
  163. /* cda
  164. */
  165. #define CMD_HDR_CDA_ALIGN 4
  166. /* prde_fis_len
  167. */
  168. #define CMD_HDR_PRD_ENTRY_SHIFT 16
  169. #define CMD_HDR_PRD_ENTRY_MASK 0x003f0000
  170. #define CMD_HDR_FIS_LEN_SHIFT 2
  171. /* attribute
  172. */
  173. #define CMD_HDR_ATTR_RES 0x00000800 /* Reserved bit, should be 1 */
  174. #define CMD_HDR_ATTR_VBIST 0x00000400 /* Vendor BIST */
  175. #define CMD_HDR_ATTR_SNOOP 0x00000200 /* Snoop enable for all descriptor */
  176. #define CMD_HDR_ATTR_FPDMA 0x00000100 /* FPDMA queued command */
  177. #define CMD_HDR_ATTR_RESET 0x00000080 /* Reset - a SRST or device reset */
  178. #define CMD_HDR_ATTR_BIST 0x00000040 /* BIST - require the host to enter BIST mode */
  179. #define CMD_HDR_ATTR_ATAPI 0x00000020 /* ATAPI command */
  180. #define CMD_HDR_ATTR_TAG 0x0000001f /* TAG mask */
  181. /* command type
  182. */
  183. enum cmd_type {
  184. CMD_VENDOR_BIST,
  185. CMD_BIST,
  186. CMD_RESET, /* SRST or device reset */
  187. CMD_ATAPI,
  188. CMD_NCQ,
  189. CMD_ATA, /* None of all above */
  190. };
  191. /*
  192. * Command Header Table
  193. */
  194. typedef struct cmd_hdr_tbl {
  195. cmd_hdr_entry_t cmd_slot[SATA_HC_MAX_CMD];
  196. } __attribute__ ((packed)) cmd_hdr_tbl_t;
  197. #define SATA_HC_CMD_HDR_TBL_SIZE sizeof(struct cmd_hdr_tbl)
  198. #define SATA_HC_CMD_HDR_TBL_ALIGN 4
  199. /*
  200. * PRD entry - Physical Region Descriptor entry
  201. */
  202. typedef struct prd_entry {
  203. u32 dba; /* Data base address, 4 bytes aligned */
  204. u32 res1;
  205. u32 res2;
  206. u32 ext_c_ddc; /* Indirect PRD flags, snoop and data word count */
  207. } __attribute__ ((packed)) prd_entry_t;
  208. #define SATA_HC_CMD_DESC_PRD_SIZE sizeof(struct prd_entry)
  209. /* dba
  210. */
  211. #define PRD_ENTRY_DBA_ALIGN 4
  212. /* ext_c_ddc
  213. */
  214. #define PRD_ENTRY_EXT 0x80000000 /* extension flag or called indirect descriptor flag */
  215. #define PRD_ENTRY_DATA_SNOOP 0x00400000 /* Snoop enable for all data associated with the PRD entry */
  216. #define PRD_ENTRY_LEN_MASK 0x003fffff /* Data word count */
  217. #define PRD_ENTRY_MAX_XFER_SZ (PRD_ENTRY_LEN_MASK + 1)
  218. /*
  219. * This SATA host controller supports a max of 16 direct PRD entries, but if use
  220. * chained indirect PRD entries, then the contollers supports upto a max of 63
  221. * entries including direct and indirect PRD entries.
  222. * The PRDT is an array of 63 PRD entries contigiously, but the PRD entries#15
  223. * will be setup as an indirect descriptor, pointing to it's next (contigious)
  224. * PRD entries#16.
  225. */
  226. #define SATA_HC_MAX_PRD 63 /* Max PRD entry numbers per command */
  227. #define SATA_HC_MAX_PRD_DIRECT 16 /* Direct PRDT entries */
  228. #define SATA_HC_MAX_PRD_USABLE (SATA_HC_MAX_PRD - 1)
  229. #define SATA_HC_MAX_XFER_LEN 0x4000000
  230. /*
  231. * PRDT - Physical Region Descriptor Table
  232. */
  233. typedef struct prdt {
  234. prd_entry_t prdt[SATA_HC_MAX_PRD];
  235. } __attribute__ ((packed)) prdt_t;
  236. /*
  237. * Command Descriptor
  238. */
  239. #define SATA_HC_CMD_DESC_CFIS_SIZE 32 /* bytes */
  240. #define SATA_HC_CMD_DESC_SFIS_SIZE 32 /* bytes */
  241. #define SATA_HC_CMD_DESC_ACMD_SIZE 16 /* bytes */
  242. #define SATA_HC_CMD_DESC_RES 16 /* bytes */
  243. typedef struct cmd_desc {
  244. u8 cfis[SATA_HC_CMD_DESC_CFIS_SIZE];
  245. u8 sfis[SATA_HC_CMD_DESC_SFIS_SIZE];
  246. u8 acmd[SATA_HC_CMD_DESC_ACMD_SIZE];
  247. u8 res[SATA_HC_CMD_DESC_RES];
  248. prd_entry_t prdt[SATA_HC_MAX_PRD];
  249. } __attribute__ ((packed)) cmd_desc_t;
  250. #define SATA_HC_CMD_DESC_SIZE sizeof(struct cmd_desc)
  251. #define SATA_HC_CMD_DESC_ALIGN 4
  252. /*
  253. * CFIS - Command FIS, which is H2D register FIS, the struct defination
  254. * of Non-Queued command is different than NCQ command. see them is sata2.h
  255. */
  256. typedef struct cfis {
  257. u8 fis_type;
  258. u8 pm_port_c;
  259. u8 command;
  260. u8 features;
  261. u8 lba_low;
  262. u8 lba_mid;
  263. u8 lba_high;
  264. u8 device;
  265. u8 lba_low_exp;
  266. u8 lba_mid_exp;
  267. u8 lba_high_exp;
  268. u8 features_exp;
  269. u8 sector_count;
  270. u8 sector_count_exp;
  271. u8 res1;
  272. u8 control;
  273. u8 res2[4];
  274. } __attribute__ ((packed)) cfis_t;
  275. /*
  276. * SFIS - Status FIS, which is D2H register FIS.
  277. */
  278. typedef struct sfis {
  279. u8 fis_type;
  280. u8 pm_port_i;
  281. u8 status;
  282. u8 error;
  283. u8 lba_low;
  284. u8 lba_mid;
  285. u8 lba_high;
  286. u8 device;
  287. u8 lba_low_exp;
  288. u8 lba_mid_exp;
  289. u8 lba_high_exp;
  290. u8 res1;
  291. u8 sector_count;
  292. u8 sector_count_exp;
  293. u8 res2[2];
  294. u8 res3[4];
  295. } __attribute__ ((packed)) sfis_t;
  296. /*
  297. * SATA device driver info
  298. */
  299. typedef struct fsl_sata_info {
  300. u32 sata_reg_base;
  301. u32 flags;
  302. } fsl_sata_info_t;
  303. #define FLAGS_DMA 0x00000000
  304. #define FLAGS_FPDMA 0x00000001
  305. /*
  306. * SATA device driver struct
  307. */
  308. typedef struct fsl_sata {
  309. char name[12];
  310. fsl_sata_reg_t *reg_base; /* the base address of controller register */
  311. void *cmd_hdr_tbl_offset; /* alloc address of command header table */
  312. cmd_hdr_tbl_t *cmd_hdr; /* aligned address of command header table */
  313. void *cmd_desc_offset; /* alloc address of command descriptor */
  314. cmd_desc_t *cmd_desc; /* aligned address of command descriptor */
  315. int link; /* PHY link status */
  316. /* device attribute */
  317. int ata_device_type; /* device type */
  318. int lba48;
  319. int queue_depth; /* Max NCQ queue depth */
  320. u16 pio;
  321. u16 mwdma;
  322. u16 udma;
  323. int wcache;
  324. int flush;
  325. int flush_ext;
  326. } fsl_sata_t;
  327. #define READ_CMD 0
  328. #define WRITE_CMD 1
  329. #endif /* __FSL_SATA_H__ */