sata_sil.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2011 Freescale Semiconductor, Inc.
  4. * Copyright 2019 NXP
  5. * Author: Tang Yuantian <b29983@freescale.com>
  6. */
  7. #ifndef SATA_SIL3132_H
  8. #define SATA_SIL3132_H
  9. #define READ_CMD 0
  10. #define WRITE_CMD 1
  11. /*
  12. * SATA device driver struct for each dev
  13. */
  14. struct sil_sata {
  15. char name[12];
  16. void *port; /* the port base address */
  17. int lba48;
  18. u16 pio;
  19. u16 mwdma;
  20. u16 udma;
  21. #ifdef CONFIG_DM_PCI
  22. struct udevice *devno;
  23. #else
  24. pci_dev_t devno;
  25. #endif
  26. int wcache;
  27. int flush;
  28. int flush_ext;
  29. int id;
  30. };
  31. /* sata info for each controller */
  32. struct sata_info {
  33. ulong iobase[3];
  34. pci_dev_t devno;
  35. int portbase;
  36. int maxport;
  37. };
  38. /*
  39. * Scatter gather entry (SGE),MUST 8 bytes aligned
  40. */
  41. struct sil_sge {
  42. __le64 addr;
  43. __le32 cnt;
  44. __le32 flags;
  45. } __attribute__ ((aligned(8), packed));
  46. /*
  47. * Port request block, MUST 8 bytes aligned
  48. */
  49. struct sil_prb {
  50. __le16 ctrl;
  51. __le16 prot;
  52. __le32 rx_cnt;
  53. struct sata_fis_h2d fis;
  54. } __attribute__ ((aligned(8), packed));
  55. struct sil_cmd_block {
  56. struct sil_prb prb;
  57. struct sil_sge sge;
  58. };
  59. enum {
  60. HOST_SLOT_STAT = 0x00, /* 32 bit slot stat * 4 */
  61. HOST_CTRL = 0x40,
  62. HOST_IRQ_STAT = 0x44,
  63. HOST_PHY_CFG = 0x48,
  64. HOST_BIST_CTRL = 0x50,
  65. HOST_BIST_PTRN = 0x54,
  66. HOST_BIST_STAT = 0x58,
  67. HOST_MEM_BIST_STAT = 0x5c,
  68. HOST_FLASH_CMD = 0x70,
  69. /* 8 bit regs */
  70. HOST_FLASH_DATA = 0x74,
  71. HOST_TRANSITION_DETECT = 0x75,
  72. HOST_GPIO_CTRL = 0x76,
  73. HOST_I2C_ADDR = 0x78, /* 32 bit */
  74. HOST_I2C_DATA = 0x7c,
  75. HOST_I2C_XFER_CNT = 0x7e,
  76. HOST_I2C_CTRL = 0x7f,
  77. /* HOST_SLOT_STAT bits */
  78. HOST_SSTAT_ATTN = (1 << 31),
  79. /* HOST_CTRL bits */
  80. HOST_CTRL_M66EN = (1 << 16), /* M66EN PCI bus signal */
  81. HOST_CTRL_TRDY = (1 << 17), /* latched PCI TRDY */
  82. HOST_CTRL_STOP = (1 << 18), /* latched PCI STOP */
  83. HOST_CTRL_DEVSEL = (1 << 19), /* latched PCI DEVSEL */
  84. HOST_CTRL_REQ64 = (1 << 20), /* latched PCI REQ64 */
  85. HOST_CTRL_GLOBAL_RST = (1 << 31), /* global reset */
  86. /*
  87. * Port registers
  88. * (8192 bytes @ +0x0000, +0x2000, +0x4000 and +0x6000 @ BAR2)
  89. */
  90. PORT_REGS_SIZE = 0x2000,
  91. PORT_LRAM = 0x0000, /* 31 LRAM slots and PMP regs */
  92. PORT_LRAM_SLOT_SZ = 0x0080, /* 32 bytes PRB + 2 SGE, ACT... */
  93. PORT_PMP = 0x0f80, /* 8 bytes PMP * 16 (128 bytes) */
  94. PORT_PMP_STATUS = 0x0000, /* port device status offset */
  95. PORT_PMP_QACTIVE = 0x0004, /* port device QActive offset */
  96. PORT_PMP_SIZE = 0x0008, /* 8 bytes per PMP */
  97. /* 32 bit regs */
  98. PORT_CTRL_STAT = 0x1000, /* write: ctrl-set, read: stat */
  99. PORT_CTRL_CLR = 0x1004, /* write: ctrl-clear */
  100. PORT_IRQ_STAT = 0x1008, /* high: status, low: interrupt */
  101. PORT_IRQ_ENABLE_SET = 0x1010, /* write: enable-set */
  102. PORT_IRQ_ENABLE_CLR = 0x1014, /* write: enable-clear */
  103. PORT_ACTIVATE_UPPER_ADDR = 0x101c,
  104. PORT_EXEC_FIFO = 0x1020, /* command execution fifo */
  105. PORT_CMD_ERR = 0x1024, /* command error number */
  106. PORT_FIS_CFG = 0x1028,
  107. PORT_FIFO_THRES = 0x102c,
  108. /* 16 bit regs */
  109. PORT_DECODE_ERR_CNT = 0x1040,
  110. PORT_DECODE_ERR_THRESH = 0x1042,
  111. PORT_CRC_ERR_CNT = 0x1044,
  112. PORT_CRC_ERR_THRESH = 0x1046,
  113. PORT_HSHK_ERR_CNT = 0x1048,
  114. PORT_HSHK_ERR_THRESH = 0x104a,
  115. /* 32 bit regs */
  116. PORT_PHY_CFG = 0x1050,
  117. PORT_SLOT_STAT = 0x1800,
  118. PORT_CMD_ACTIVATE = 0x1c00, /* 64 bit cmd activate * 31 */
  119. PORT_CONTEXT = 0x1e04,
  120. PORT_EXEC_DIAG = 0x1e00, /* 32bit exec diag * 16 */
  121. PORT_PSD_DIAG = 0x1e40, /* 32bit psd diag * 16 */
  122. PORT_SCONTROL = 0x1f00,
  123. PORT_SSTATUS = 0x1f04,
  124. PORT_SERROR = 0x1f08,
  125. PORT_SACTIVE = 0x1f0c,
  126. /* PORT_CTRL_STAT bits */
  127. PORT_CS_PORT_RST = (1 << 0), /* port reset */
  128. PORT_CS_DEV_RST = (1 << 1), /* device reset */
  129. PORT_CS_INIT = (1 << 2), /* port initialize */
  130. PORT_CS_IRQ_WOC = (1 << 3), /* interrupt write one to clear */
  131. PORT_CS_CDB16 = (1 << 5), /* 0=12b cdb, 1=16b cdb */
  132. PORT_CS_PMP_RESUME = (1 << 6), /* PMP resume */
  133. PORT_CS_32BIT_ACTV = (1 << 10), /* 32-bit activation */
  134. PORT_CS_PMP_EN = (1 << 13), /* port multiplier enable */
  135. PORT_CS_RDY = (1 << 31), /* port ready to accept commands */
  136. /* PORT_IRQ_STAT/ENABLE_SET/CLR */
  137. /* bits[11:0] are masked */
  138. PORT_IRQ_COMPLETE = (1 << 0), /* command(s) completed */
  139. PORT_IRQ_ERROR = (1 << 1), /* command execution error */
  140. PORT_IRQ_PORTRDY_CHG = (1 << 2), /* port ready change */
  141. PORT_IRQ_PWR_CHG = (1 << 3), /* power management change */
  142. PORT_IRQ_PHYRDY_CHG = (1 << 4), /* PHY ready change */
  143. PORT_IRQ_COMWAKE = (1 << 5), /* COMWAKE received */
  144. PORT_IRQ_UNK_FIS = (1 << 6), /* unknown FIS received */
  145. PORT_IRQ_DEV_XCHG = (1 << 7), /* device exchanged */
  146. PORT_IRQ_8B10B = (1 << 8), /* 8b/10b decode error threshold */
  147. PORT_IRQ_CRC = (1 << 9), /* CRC error threshold */
  148. PORT_IRQ_HANDSHAKE = (1 << 10), /* handshake error threshold */
  149. PORT_IRQ_SDB_NOTIFY = (1 << 11), /* SDB notify received */
  150. DEF_PORT_IRQ = PORT_IRQ_COMPLETE | PORT_IRQ_ERROR |
  151. PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG |
  152. PORT_IRQ_UNK_FIS | PORT_IRQ_SDB_NOTIFY,
  153. /* bits[27:16] are unmasked (raw) */
  154. PORT_IRQ_RAW_SHIFT = 16,
  155. PORT_IRQ_MASKED_MASK = 0x7ff,
  156. PORT_IRQ_RAW_MASK = (0x7ff << PORT_IRQ_RAW_SHIFT),
  157. /* ENABLE_SET/CLR specific, intr steering - 2 bit field */
  158. PORT_IRQ_STEER_SHIFT = 30,
  159. PORT_IRQ_STEER_MASK = (3 << PORT_IRQ_STEER_SHIFT),
  160. /* PORT_CMD_ERR constants */
  161. PORT_CERR_DEV = 1, /* Error bit in D2H Register FIS */
  162. PORT_CERR_SDB = 2, /* Error bit in SDB FIS */
  163. PORT_CERR_DATA = 3, /* Error in data FIS not detected by dev */
  164. PORT_CERR_SEND = 4, /* Initial cmd FIS transmission failure */
  165. PORT_CERR_INCONSISTENT = 5, /* Protocol mismatch */
  166. PORT_CERR_DIRECTION = 6, /* Data direction mismatch */
  167. PORT_CERR_UNDERRUN = 7, /* Ran out of SGEs while writing */
  168. PORT_CERR_OVERRUN = 8, /* Ran out of SGEs while reading */
  169. /* bits of PRB control field */
  170. PRB_CTRL_PROTOCOL = (1 << 0), /* override def. ATA protocol */
  171. PRB_CTRL_PACKET_READ = (1 << 4), /* PACKET cmd read */
  172. PRB_CTRL_PACKET_WRITE = (1 << 5), /* PACKET cmd write */
  173. PRB_CTRL_NIEN = (1 << 6), /* Mask completion irq */
  174. PRB_CTRL_SRST = (1 << 7), /* Soft reset request (ign BSY?) */
  175. /* PRB protocol field */
  176. PRB_PROT_PACKET = (1 << 0),
  177. PRB_PROT_TCQ = (1 << 1),
  178. PRB_PROT_NCQ = (1 << 2),
  179. PRB_PROT_READ = (1 << 3),
  180. PRB_PROT_WRITE = (1 << 4),
  181. PRB_PROT_TRANSPARENT = (1 << 5),
  182. /*
  183. * Other constants
  184. */
  185. SGE_TRM = (1 << 31), /* Last SGE in chain */
  186. SGE_LNK = (1 << 30), /* linked list
  187. Points to SGT, not SGE */
  188. SGE_DRD = (1 << 29), /* discard data read (/dev/null)
  189. data address ignored */
  190. CMD_ERR = 0x21,
  191. };
  192. #if CONFIG_IS_ENABLED(BLK)
  193. #define ATA_MAX_PORTS 32
  194. struct sil_sata_priv {
  195. int port_num;
  196. struct sil_sata *sil_sata_desc[ATA_MAX_PORTS];
  197. };
  198. #endif
  199. #endif