ll_temac.h 13 KB

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