ll_temac.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. #ifndef XILINX_LL_TEMAC_H
  2. #define XILINX_LL_TEMAC_H
  3. #include <linux/netdevice.h>
  4. #include <linux/of.h>
  5. #include <linux/spinlock.h>
  6. #ifdef CONFIG_PPC_DCR
  7. #include <asm/dcr.h>
  8. #include <asm/dcr-regs.h>
  9. #endif
  10. /* packet size info */
  11. #define XTE_HDR_SIZE 14 /* size of Ethernet header */
  12. #define XTE_TRL_SIZE 4 /* size of Ethernet trailer (FCS) */
  13. #define XTE_JUMBO_MTU 9000
  14. #define XTE_MAX_JUMBO_FRAME_SIZE (XTE_JUMBO_MTU + XTE_HDR_SIZE + XTE_TRL_SIZE)
  15. /* Configuration options */
  16. /* Accept all incoming packets.
  17. * This option defaults to disabled (cleared) */
  18. #define XTE_OPTION_PROMISC (1 << 0)
  19. /* Jumbo frame support for Tx & Rx.
  20. * This option defaults to disabled (cleared) */
  21. #define XTE_OPTION_JUMBO (1 << 1)
  22. /* VLAN Rx & Tx frame support.
  23. * This option defaults to disabled (cleared) */
  24. #define XTE_OPTION_VLAN (1 << 2)
  25. /* Enable recognition of flow control frames on Rx
  26. * This option defaults to enabled (set) */
  27. #define XTE_OPTION_FLOW_CONTROL (1 << 4)
  28. /* Strip FCS and PAD from incoming frames.
  29. * Note: PAD from VLAN frames is not stripped.
  30. * This option defaults to disabled (set) */
  31. #define XTE_OPTION_FCS_STRIP (1 << 5)
  32. /* Generate FCS field and add PAD automatically for outgoing frames.
  33. * This option defaults to enabled (set) */
  34. #define XTE_OPTION_FCS_INSERT (1 << 6)
  35. /* Enable Length/Type error checking for incoming frames. When this option is
  36. set, the MAC will filter frames that have a mismatched type/length field
  37. and if XTE_OPTION_REPORT_RXERR is set, the user is notified when these
  38. types of frames are encountered. When this option is cleared, the MAC will
  39. allow these types of frames to be received.
  40. This option defaults to enabled (set) */
  41. #define XTE_OPTION_LENTYPE_ERR (1 << 7)
  42. /* Enable the transmitter.
  43. * This option defaults to enabled (set) */
  44. #define XTE_OPTION_TXEN (1 << 11)
  45. /* Enable the receiver
  46. * This option defaults to enabled (set) */
  47. #define XTE_OPTION_RXEN (1 << 12)
  48. /* Default options set when device is initialized or reset */
  49. #define XTE_OPTION_DEFAULTS \
  50. (XTE_OPTION_TXEN | \
  51. XTE_OPTION_FLOW_CONTROL | \
  52. XTE_OPTION_RXEN)
  53. /* XPS_LL_TEMAC SDMA registers definition */
  54. #define TX_NXTDESC_PTR 0x00 /* r */
  55. #define TX_CURBUF_ADDR 0x01 /* r */
  56. #define TX_CURBUF_LENGTH 0x02 /* r */
  57. #define TX_CURDESC_PTR 0x03 /* rw */
  58. #define TX_TAILDESC_PTR 0x04 /* rw */
  59. #define TX_CHNL_CTRL 0x05 /* rw */
  60. /*
  61. 0:7 24:31 IRQTimeout
  62. 8:15 16:23 IRQCount
  63. 16:20 11:15 Reserved
  64. 21 10 0
  65. 22 9 UseIntOnEnd
  66. 23 8 LdIRQCnt
  67. 24 7 IRQEn
  68. 25:28 3:6 Reserved
  69. 29 2 IrqErrEn
  70. 30 1 IrqDlyEn
  71. 31 0 IrqCoalEn
  72. */
  73. #define CHNL_CTRL_IRQ_IOE (1 << 9)
  74. #define CHNL_CTRL_IRQ_EN (1 << 7)
  75. #define CHNL_CTRL_IRQ_ERR_EN (1 << 2)
  76. #define CHNL_CTRL_IRQ_DLY_EN (1 << 1)
  77. #define CHNL_CTRL_IRQ_COAL_EN (1 << 0)
  78. #define TX_IRQ_REG 0x06 /* rw */
  79. /*
  80. 0:7 24:31 DltTmrValue
  81. 8:15 16:23 ClscCntrValue
  82. 16:17 14:15 Reserved
  83. 18:21 10:13 ClscCnt
  84. 22:23 8:9 DlyCnt
  85. 24:28 3::7 Reserved
  86. 29 2 ErrIrq
  87. 30 1 DlyIrq
  88. 31 0 CoalIrq
  89. */
  90. #define TX_CHNL_STS 0x07 /* r */
  91. /*
  92. 0:9 22:31 Reserved
  93. 10 21 TailPErr
  94. 11 20 CmpErr
  95. 12 19 AddrErr
  96. 13 18 NxtPErr
  97. 14 17 CurPErr
  98. 15 16 BsyWr
  99. 16:23 8:15 Reserved
  100. 24 7 Error
  101. 25 6 IOE
  102. 26 5 SOE
  103. 27 4 Cmplt
  104. 28 3 SOP
  105. 29 2 EOP
  106. 30 1 EngBusy
  107. 31 0 Reserved
  108. */
  109. #define RX_NXTDESC_PTR 0x08 /* r */
  110. #define RX_CURBUF_ADDR 0x09 /* r */
  111. #define RX_CURBUF_LENGTH 0x0a /* r */
  112. #define RX_CURDESC_PTR 0x0b /* rw */
  113. #define RX_TAILDESC_PTR 0x0c /* rw */
  114. #define RX_CHNL_CTRL 0x0d /* rw */
  115. /*
  116. 0:7 24:31 IRQTimeout
  117. 8:15 16:23 IRQCount
  118. 16:20 11:15 Reserved
  119. 21 10 0
  120. 22 9 UseIntOnEnd
  121. 23 8 LdIRQCnt
  122. 24 7 IRQEn
  123. 25:28 3:6 Reserved
  124. 29 2 IrqErrEn
  125. 30 1 IrqDlyEn
  126. 31 0 IrqCoalEn
  127. */
  128. #define RX_IRQ_REG 0x0e /* rw */
  129. #define IRQ_COAL (1 << 0)
  130. #define IRQ_DLY (1 << 1)
  131. #define IRQ_ERR (1 << 2)
  132. #define IRQ_DMAERR (1 << 7) /* this is not documented ??? */
  133. /*
  134. 0:7 24:31 DltTmrValue
  135. 8:15 16:23 ClscCntrValue
  136. 16:17 14:15 Reserved
  137. 18:21 10:13 ClscCnt
  138. 22:23 8:9 DlyCnt
  139. 24:28 3::7 Reserved
  140. */
  141. #define RX_CHNL_STS 0x0f /* r */
  142. #define CHNL_STS_ENGBUSY (1 << 1)
  143. #define CHNL_STS_EOP (1 << 2)
  144. #define CHNL_STS_SOP (1 << 3)
  145. #define CHNL_STS_CMPLT (1 << 4)
  146. #define CHNL_STS_SOE (1 << 5)
  147. #define CHNL_STS_IOE (1 << 6)
  148. #define CHNL_STS_ERR (1 << 7)
  149. #define CHNL_STS_BSYWR (1 << 16)
  150. #define CHNL_STS_CURPERR (1 << 17)
  151. #define CHNL_STS_NXTPERR (1 << 18)
  152. #define CHNL_STS_ADDRERR (1 << 19)
  153. #define CHNL_STS_CMPERR (1 << 20)
  154. #define CHNL_STS_TAILERR (1 << 21)
  155. /*
  156. 0:9 22:31 Reserved
  157. 10 21 TailPErr
  158. 11 20 CmpErr
  159. 12 19 AddrErr
  160. 13 18 NxtPErr
  161. 14 17 CurPErr
  162. 15 16 BsyWr
  163. 16:23 8:15 Reserved
  164. 24 7 Error
  165. 25 6 IOE
  166. 26 5 SOE
  167. 27 4 Cmplt
  168. 28 3 SOP
  169. 29 2 EOP
  170. 30 1 EngBusy
  171. 31 0 Reserved
  172. */
  173. #define DMA_CONTROL_REG 0x10 /* rw */
  174. #define DMA_CONTROL_RST (1 << 0)
  175. #define DMA_TAIL_ENABLE (1 << 2)
  176. /* XPS_LL_TEMAC direct registers definition */
  177. #define XTE_RAF0_OFFSET 0x00
  178. #define RAF0_RST (1 << 0)
  179. #define RAF0_MCSTREJ (1 << 1)
  180. #define RAF0_BCSTREJ (1 << 2)
  181. #define XTE_TPF0_OFFSET 0x04
  182. #define XTE_IFGP0_OFFSET 0x08
  183. #define XTE_ISR0_OFFSET 0x0c
  184. #define ISR0_HARDACSCMPLT (1 << 0)
  185. #define ISR0_AUTONEG (1 << 1)
  186. #define ISR0_RXCMPLT (1 << 2)
  187. #define ISR0_RXREJ (1 << 3)
  188. #define ISR0_RXFIFOOVR (1 << 4)
  189. #define ISR0_TXCMPLT (1 << 5)
  190. #define ISR0_RXDCMLCK (1 << 6)
  191. #define XTE_IPR0_OFFSET 0x10
  192. #define XTE_IER0_OFFSET 0x14
  193. #define XTE_MSW0_OFFSET 0x20
  194. #define XTE_LSW0_OFFSET 0x24
  195. #define XTE_CTL0_OFFSET 0x28
  196. #define XTE_RDY0_OFFSET 0x2c
  197. #define XTE_RSE_MIIM_RR_MASK 0x0002
  198. #define XTE_RSE_MIIM_WR_MASK 0x0004
  199. #define XTE_RSE_CFG_RR_MASK 0x0020
  200. #define XTE_RSE_CFG_WR_MASK 0x0040
  201. #define XTE_RDY0_HARD_ACS_RDY_MASK (0x10000)
  202. /* XPS_LL_TEMAC indirect registers offset definition */
  203. #define XTE_RXC0_OFFSET 0x00000200 /* Rx configuration word 0 */
  204. #define XTE_RXC1_OFFSET 0x00000240 /* Rx configuration word 1 */
  205. #define XTE_RXC1_RXRST_MASK (1 << 31) /* Receiver reset */
  206. #define XTE_RXC1_RXJMBO_MASK (1 << 30) /* Jumbo frame enable */
  207. #define XTE_RXC1_RXFCS_MASK (1 << 29) /* FCS not stripped */
  208. #define XTE_RXC1_RXEN_MASK (1 << 28) /* Receiver enable */
  209. #define XTE_RXC1_RXVLAN_MASK (1 << 27) /* VLAN enable */
  210. #define XTE_RXC1_RXHD_MASK (1 << 26) /* Half duplex */
  211. #define XTE_RXC1_RXLT_MASK (1 << 25) /* Length/type check disable */
  212. #define XTE_TXC_OFFSET 0x00000280 /* Tx configuration */
  213. #define XTE_TXC_TXRST_MASK (1 << 31) /* Transmitter reset */
  214. #define XTE_TXC_TXJMBO_MASK (1 << 30) /* Jumbo frame enable */
  215. #define XTE_TXC_TXFCS_MASK (1 << 29) /* Generate FCS */
  216. #define XTE_TXC_TXEN_MASK (1 << 28) /* Transmitter enable */
  217. #define XTE_TXC_TXVLAN_MASK (1 << 27) /* VLAN enable */
  218. #define XTE_TXC_TXHD_MASK (1 << 26) /* Half duplex */
  219. #define XTE_FCC_OFFSET 0x000002C0 /* Flow control config */
  220. #define XTE_FCC_RXFLO_MASK (1 << 29) /* Rx flow control enable */
  221. #define XTE_FCC_TXFLO_MASK (1 << 30) /* Tx flow control enable */
  222. #define XTE_EMCFG_OFFSET 0x00000300 /* EMAC configuration */
  223. #define XTE_EMCFG_LINKSPD_MASK 0xC0000000 /* Link speed */
  224. #define XTE_EMCFG_HOSTEN_MASK (1 << 26) /* Host interface enable */
  225. #define XTE_EMCFG_LINKSPD_10 0x00000000 /* 10 Mbit LINKSPD_MASK */
  226. #define XTE_EMCFG_LINKSPD_100 (1 << 30) /* 100 Mbit LINKSPD_MASK */
  227. #define XTE_EMCFG_LINKSPD_1000 (1 << 31) /* 1000 Mbit LINKSPD_MASK */
  228. #define XTE_GMIC_OFFSET 0x00000320 /* RGMII/SGMII config */
  229. #define XTE_MC_OFFSET 0x00000340 /* MDIO configuration */
  230. #define XTE_UAW0_OFFSET 0x00000380 /* Unicast address word 0 */
  231. #define XTE_UAW1_OFFSET 0x00000384 /* Unicast address word 1 */
  232. #define XTE_MAW0_OFFSET 0x00000388 /* Multicast addr word 0 */
  233. #define XTE_MAW1_OFFSET 0x0000038C /* Multicast addr word 1 */
  234. #define XTE_AFM_OFFSET 0x00000390 /* Promiscuous mode */
  235. #define XTE_AFM_EPPRM_MASK (1 << 31) /* Promiscuous mode enable */
  236. /* Interrupt Request status */
  237. #define XTE_TIS_OFFSET 0x000003A0
  238. #define TIS_FRIS (1 << 0)
  239. #define TIS_MRIS (1 << 1)
  240. #define TIS_MWIS (1 << 2)
  241. #define TIS_ARIS (1 << 3)
  242. #define TIS_AWIS (1 << 4)
  243. #define TIS_CRIS (1 << 5)
  244. #define TIS_CWIS (1 << 6)
  245. #define XTE_TIE_OFFSET 0x000003A4 /* Interrupt enable */
  246. /** MII Mamagement Control register (MGTCR) */
  247. #define XTE_MGTDR_OFFSET 0x000003B0 /* MII data */
  248. #define XTE_MIIMAI_OFFSET 0x000003B4 /* MII control */
  249. #define CNTLREG_WRITE_ENABLE_MASK 0x8000
  250. #define CNTLREG_EMAC1SEL_MASK 0x0400
  251. #define CNTLREG_ADDRESSCODE_MASK 0x03ff
  252. /* CDMAC descriptor status bit definitions */
  253. #define STS_CTRL_APP0_ERR (1 << 31)
  254. #define STS_CTRL_APP0_IRQONEND (1 << 30)
  255. /* undoccumented */
  256. #define STS_CTRL_APP0_STOPONEND (1 << 29)
  257. #define STS_CTRL_APP0_CMPLT (1 << 28)
  258. #define STS_CTRL_APP0_SOP (1 << 27)
  259. #define STS_CTRL_APP0_EOP (1 << 26)
  260. #define STS_CTRL_APP0_ENGBUSY (1 << 25)
  261. /* undocumented */
  262. #define STS_CTRL_APP0_ENGRST (1 << 24)
  263. #define TX_CONTROL_CALC_CSUM_MASK 1
  264. #define MULTICAST_CAM_TABLE_NUM 4
  265. /* TEMAC Synthesis features */
  266. #define TEMAC_FEATURE_RX_CSUM (1 << 0)
  267. #define TEMAC_FEATURE_TX_CSUM (1 << 1)
  268. /* TX/RX CURDESC_PTR points to first descriptor */
  269. /* TX/RX TAILDESC_PTR points to last descriptor in linked list */
  270. /**
  271. * struct cdmac_bd - LocalLink buffer descriptor format
  272. *
  273. * app0 bits:
  274. * 0 Error
  275. * 1 IrqOnEnd generate an interrupt at completion of DMA op
  276. * 2 reserved
  277. * 3 completed Current descriptor completed
  278. * 4 SOP TX - marks first desc/ RX marks first desct
  279. * 5 EOP TX marks last desc/RX marks last desc
  280. * 6 EngBusy DMA is processing
  281. * 7 reserved
  282. * 8:31 application specific
  283. */
  284. struct cdmac_bd {
  285. u32 next; /* Physical address of next buffer descriptor */
  286. u32 phys;
  287. u32 len;
  288. u32 app0;
  289. u32 app1; /* TX start << 16 | insert */
  290. u32 app2; /* TX csum */
  291. u32 app3;
  292. u32 app4; /* skb for TX length for RX */
  293. };
  294. struct temac_local {
  295. struct net_device *ndev;
  296. struct device *dev;
  297. /* Connection to PHY device */
  298. struct phy_device *phy_dev; /* Pointer to PHY device */
  299. struct device_node *phy_node;
  300. /* MDIO bus data */
  301. struct mii_bus *mii_bus; /* MII bus reference */
  302. int mdio_irqs[PHY_MAX_ADDR]; /* IRQs table for MDIO bus */
  303. /* IO registers, dma functions and IRQs */
  304. void __iomem *regs;
  305. void __iomem *sdma_regs;
  306. #ifdef CONFIG_PPC_DCR
  307. dcr_host_t sdma_dcrs;
  308. #endif
  309. u32 (*dma_in)(struct temac_local *, int);
  310. void (*dma_out)(struct temac_local *, int, u32);
  311. int tx_irq;
  312. int rx_irq;
  313. int emac_num;
  314. struct sk_buff **rx_skb;
  315. spinlock_t rx_lock;
  316. struct mutex indirect_mutex;
  317. u32 options; /* Current options word */
  318. int last_link;
  319. unsigned int temac_features;
  320. /* Buffer descriptors */
  321. struct cdmac_bd *tx_bd_v;
  322. dma_addr_t tx_bd_p;
  323. struct cdmac_bd *rx_bd_v;
  324. dma_addr_t rx_bd_p;
  325. int tx_bd_ci;
  326. int tx_bd_next;
  327. int tx_bd_tail;
  328. int rx_bd_ci;
  329. };
  330. /* xilinx_temac.c */
  331. u32 temac_ior(struct temac_local *lp, int offset);
  332. void temac_iow(struct temac_local *lp, int offset, u32 value);
  333. int temac_indirect_busywait(struct temac_local *lp);
  334. u32 temac_indirect_in32(struct temac_local *lp, int reg);
  335. void temac_indirect_out32(struct temac_local *lp, int reg, u32 value);
  336. /* xilinx_temac_mdio.c */
  337. int temac_mdio_setup(struct temac_local *lp, struct device_node *np);
  338. void temac_mdio_teardown(struct temac_local *lp);
  339. #endif /* XILINX_LL_TEMAC_H */