emac.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
  3. */
  4. #ifndef _EMAC_H_
  5. #define _EMAC_H_
  6. #include <linux/irqreturn.h>
  7. #include <linux/netdevice.h>
  8. #include <linux/clk.h>
  9. #include <linux/platform_device.h>
  10. #include "emac-mac.h"
  11. #include "emac-phy.h"
  12. #include "emac-sgmii.h"
  13. /* EMAC base register offsets */
  14. #define EMAC_DMA_MAS_CTRL 0x1400
  15. #define EMAC_IRQ_MOD_TIM_INIT 0x1408
  16. #define EMAC_BLK_IDLE_STS 0x140c
  17. #define EMAC_PHY_LINK_DELAY 0x141c
  18. #define EMAC_SYS_ALIV_CTRL 0x1434
  19. #define EMAC_MAC_CTRL 0x1480
  20. #define EMAC_MAC_IPGIFG_CTRL 0x1484
  21. #define EMAC_MAC_STA_ADDR0 0x1488
  22. #define EMAC_MAC_STA_ADDR1 0x148c
  23. #define EMAC_HASH_TAB_REG0 0x1490
  24. #define EMAC_HASH_TAB_REG1 0x1494
  25. #define EMAC_MAC_HALF_DPLX_CTRL 0x1498
  26. #define EMAC_MAX_FRAM_LEN_CTRL 0x149c
  27. #define EMAC_WOL_CTRL0 0x14a0
  28. #define EMAC_RSS_KEY0 0x14b0
  29. #define EMAC_H1TPD_BASE_ADDR_LO 0x14e0
  30. #define EMAC_H2TPD_BASE_ADDR_LO 0x14e4
  31. #define EMAC_H3TPD_BASE_ADDR_LO 0x14e8
  32. #define EMAC_INTER_SRAM_PART9 0x1534
  33. #define EMAC_DESC_CTRL_0 0x1540
  34. #define EMAC_DESC_CTRL_1 0x1544
  35. #define EMAC_DESC_CTRL_2 0x1550
  36. #define EMAC_DESC_CTRL_10 0x1554
  37. #define EMAC_DESC_CTRL_12 0x1558
  38. #define EMAC_DESC_CTRL_13 0x155c
  39. #define EMAC_DESC_CTRL_3 0x1560
  40. #define EMAC_DESC_CTRL_4 0x1564
  41. #define EMAC_DESC_CTRL_5 0x1568
  42. #define EMAC_DESC_CTRL_14 0x156c
  43. #define EMAC_DESC_CTRL_15 0x1570
  44. #define EMAC_DESC_CTRL_16 0x1574
  45. #define EMAC_DESC_CTRL_6 0x1578
  46. #define EMAC_DESC_CTRL_8 0x1580
  47. #define EMAC_DESC_CTRL_9 0x1584
  48. #define EMAC_DESC_CTRL_11 0x1588
  49. #define EMAC_TXQ_CTRL_0 0x1590
  50. #define EMAC_TXQ_CTRL_1 0x1594
  51. #define EMAC_TXQ_CTRL_2 0x1598
  52. #define EMAC_RXQ_CTRL_0 0x15a0
  53. #define EMAC_RXQ_CTRL_1 0x15a4
  54. #define EMAC_RXQ_CTRL_2 0x15a8
  55. #define EMAC_RXQ_CTRL_3 0x15ac
  56. #define EMAC_BASE_CPU_NUMBER 0x15b8
  57. #define EMAC_DMA_CTRL 0x15c0
  58. #define EMAC_MAILBOX_0 0x15e0
  59. #define EMAC_MAILBOX_5 0x15e4
  60. #define EMAC_MAILBOX_6 0x15e8
  61. #define EMAC_MAILBOX_13 0x15ec
  62. #define EMAC_MAILBOX_2 0x15f4
  63. #define EMAC_MAILBOX_3 0x15f8
  64. #define EMAC_INT_STATUS 0x1600
  65. #define EMAC_INT_MASK 0x1604
  66. #define EMAC_MAILBOX_11 0x160c
  67. #define EMAC_AXI_MAST_CTRL 0x1610
  68. #define EMAC_MAILBOX_12 0x1614
  69. #define EMAC_MAILBOX_9 0x1618
  70. #define EMAC_MAILBOX_10 0x161c
  71. #define EMAC_ATHR_HEADER_CTRL 0x1620
  72. #define EMAC_RXMAC_STATC_REG0 0x1700
  73. #define EMAC_RXMAC_STATC_REG22 0x1758
  74. #define EMAC_TXMAC_STATC_REG0 0x1760
  75. #define EMAC_TXMAC_STATC_REG24 0x17c0
  76. #define EMAC_CLK_GATE_CTRL 0x1814
  77. #define EMAC_CORE_HW_VERSION 0x1974
  78. #define EMAC_MISC_CTRL 0x1990
  79. #define EMAC_MAILBOX_7 0x19e0
  80. #define EMAC_MAILBOX_8 0x19e4
  81. #define EMAC_IDT_TABLE0 0x1b00
  82. #define EMAC_RXMAC_STATC_REG23 0x1bc8
  83. #define EMAC_RXMAC_STATC_REG24 0x1bcc
  84. #define EMAC_TXMAC_STATC_REG25 0x1bd0
  85. #define EMAC_MAILBOX_15 0x1bd4
  86. #define EMAC_MAILBOX_16 0x1bd8
  87. #define EMAC_INT1_MASK 0x1bf0
  88. #define EMAC_INT1_STATUS 0x1bf4
  89. #define EMAC_INT2_MASK 0x1bf8
  90. #define EMAC_INT2_STATUS 0x1bfc
  91. #define EMAC_INT3_MASK 0x1c00
  92. #define EMAC_INT3_STATUS 0x1c04
  93. /* EMAC_DMA_MAS_CTRL */
  94. #define DEV_ID_NUM_BMSK 0x7f000000
  95. #define DEV_ID_NUM_SHFT 24
  96. #define DEV_REV_NUM_BMSK 0xff0000
  97. #define DEV_REV_NUM_SHFT 16
  98. #define INT_RD_CLR_EN 0x4000
  99. #define IRQ_MODERATOR2_EN 0x800
  100. #define IRQ_MODERATOR_EN 0x400
  101. #define LPW_CLK_SEL 0x80
  102. #define LPW_STATE 0x20
  103. #define LPW_MODE 0x10
  104. #define SOFT_RST 0x1
  105. /* EMAC_IRQ_MOD_TIM_INIT */
  106. #define IRQ_MODERATOR2_INIT_BMSK 0xffff0000
  107. #define IRQ_MODERATOR2_INIT_SHFT 16
  108. #define IRQ_MODERATOR_INIT_BMSK 0xffff
  109. #define IRQ_MODERATOR_INIT_SHFT 0
  110. /* EMAC_INT_STATUS */
  111. #define DIS_INT BIT(31)
  112. #define PTP_INT BIT(30)
  113. #define RFD4_UR_INT BIT(29)
  114. #define TX_PKT_INT3 BIT(26)
  115. #define TX_PKT_INT2 BIT(25)
  116. #define TX_PKT_INT1 BIT(24)
  117. #define RX_PKT_INT3 BIT(19)
  118. #define RX_PKT_INT2 BIT(18)
  119. #define RX_PKT_INT1 BIT(17)
  120. #define RX_PKT_INT0 BIT(16)
  121. #define TX_PKT_INT BIT(15)
  122. #define TXQ_TO_INT BIT(14)
  123. #define GPHY_WAKEUP_INT BIT(13)
  124. #define GPHY_LINK_DOWN_INT BIT(12)
  125. #define GPHY_LINK_UP_INT BIT(11)
  126. #define DMAW_TO_INT BIT(10)
  127. #define DMAR_TO_INT BIT(9)
  128. #define TXF_UR_INT BIT(8)
  129. #define RFD3_UR_INT BIT(7)
  130. #define RFD2_UR_INT BIT(6)
  131. #define RFD1_UR_INT BIT(5)
  132. #define RFD0_UR_INT BIT(4)
  133. #define RXF_OF_INT BIT(3)
  134. #define SW_MAN_INT BIT(2)
  135. /* EMAC_MAILBOX_6 */
  136. #define RFD2_PROC_IDX_BMSK 0xfff0000
  137. #define RFD2_PROC_IDX_SHFT 16
  138. #define RFD2_PROD_IDX_BMSK 0xfff
  139. #define RFD2_PROD_IDX_SHFT 0
  140. /* EMAC_CORE_HW_VERSION */
  141. #define MAJOR_BMSK 0xf0000000
  142. #define MAJOR_SHFT 28
  143. #define MINOR_BMSK 0xfff0000
  144. #define MINOR_SHFT 16
  145. #define STEP_BMSK 0xffff
  146. #define STEP_SHFT 0
  147. /* EMAC_EMAC_WRAPPER_CSR1 */
  148. #define TX_INDX_FIFO_SYNC_RST BIT(23)
  149. #define TX_TS_FIFO_SYNC_RST BIT(22)
  150. #define RX_TS_FIFO2_SYNC_RST BIT(21)
  151. #define RX_TS_FIFO1_SYNC_RST BIT(20)
  152. #define TX_TS_ENABLE BIT(16)
  153. #define DIS_1588_CLKS BIT(11)
  154. #define FREQ_MODE BIT(9)
  155. #define ENABLE_RRD_TIMESTAMP BIT(3)
  156. /* EMAC_EMAC_WRAPPER_CSR2 */
  157. #define HDRIVE_BMSK 0x3000
  158. #define HDRIVE_SHFT 12
  159. #define SLB_EN BIT(9)
  160. #define PLB_EN BIT(8)
  161. #define WOL_EN BIT(3)
  162. #define PHY_RESET BIT(0)
  163. #define EMAC_DEV_ID 0x0040
  164. /* SGMII v2 per lane registers */
  165. #define SGMII_LN_RSM_START 0x029C
  166. /* SGMII v2 PHY common registers */
  167. #define SGMII_PHY_CMN_CTRL 0x0408
  168. #define SGMII_PHY_CMN_RESET_CTRL 0x0410
  169. /* SGMII v2 PHY registers per lane */
  170. #define SGMII_PHY_LN_OFFSET 0x0400
  171. #define SGMII_PHY_LN_LANE_STATUS 0x00DC
  172. #define SGMII_PHY_LN_BIST_GEN0 0x008C
  173. #define SGMII_PHY_LN_BIST_GEN1 0x0090
  174. #define SGMII_PHY_LN_BIST_GEN2 0x0094
  175. #define SGMII_PHY_LN_BIST_GEN3 0x0098
  176. #define SGMII_PHY_LN_CDR_CTRL1 0x005C
  177. enum emac_clk_id {
  178. EMAC_CLK_AXI,
  179. EMAC_CLK_CFG_AHB,
  180. EMAC_CLK_HIGH_SPEED,
  181. EMAC_CLK_MDIO,
  182. EMAC_CLK_TX,
  183. EMAC_CLK_RX,
  184. EMAC_CLK_SYS,
  185. EMAC_CLK_CNT
  186. };
  187. #define EMAC_LINK_SPEED_UNKNOWN 0x0
  188. #define EMAC_LINK_SPEED_10_HALF BIT(0)
  189. #define EMAC_LINK_SPEED_10_FULL BIT(1)
  190. #define EMAC_LINK_SPEED_100_HALF BIT(2)
  191. #define EMAC_LINK_SPEED_100_FULL BIT(3)
  192. #define EMAC_LINK_SPEED_1GB_FULL BIT(5)
  193. #define EMAC_MAX_SETUP_LNK_CYCLE 100
  194. struct emac_stats {
  195. /* rx */
  196. u64 rx_ok; /* good packets */
  197. u64 rx_bcast; /* good broadcast packets */
  198. u64 rx_mcast; /* good multicast packets */
  199. u64 rx_pause; /* pause packet */
  200. u64 rx_ctrl; /* control packets other than pause frame. */
  201. u64 rx_fcs_err; /* packets with bad FCS. */
  202. u64 rx_len_err; /* packets with length mismatch */
  203. u64 rx_byte_cnt; /* good bytes count (without FCS) */
  204. u64 rx_runt; /* runt packets */
  205. u64 rx_frag; /* fragment count */
  206. u64 rx_sz_64; /* packets that are 64 bytes */
  207. u64 rx_sz_65_127; /* packets that are 65-127 bytes */
  208. u64 rx_sz_128_255; /* packets that are 128-255 bytes */
  209. u64 rx_sz_256_511; /* packets that are 256-511 bytes */
  210. u64 rx_sz_512_1023; /* packets that are 512-1023 bytes */
  211. u64 rx_sz_1024_1518; /* packets that are 1024-1518 bytes */
  212. u64 rx_sz_1519_max; /* packets that are 1519-MTU bytes*/
  213. u64 rx_sz_ov; /* packets that are >MTU bytes (truncated) */
  214. u64 rx_rxf_ov; /* packets dropped due to RX FIFO overflow */
  215. u64 rx_align_err; /* alignment errors */
  216. u64 rx_bcast_byte_cnt; /* broadcast packets byte count (without FCS) */
  217. u64 rx_mcast_byte_cnt; /* multicast packets byte count (without FCS) */
  218. u64 rx_err_addr; /* packets dropped due to address filtering */
  219. u64 rx_crc_align; /* CRC align errors */
  220. u64 rx_jabbers; /* jabbers */
  221. /* tx */
  222. u64 tx_ok; /* good packets */
  223. u64 tx_bcast; /* good broadcast packets */
  224. u64 tx_mcast; /* good multicast packets */
  225. u64 tx_pause; /* pause packets */
  226. u64 tx_exc_defer; /* packets with excessive deferral */
  227. u64 tx_ctrl; /* control packets other than pause frame */
  228. u64 tx_defer; /* packets that are deferred. */
  229. u64 tx_byte_cnt; /* good bytes count (without FCS) */
  230. u64 tx_sz_64; /* packets that are 64 bytes */
  231. u64 tx_sz_65_127; /* packets that are 65-127 bytes */
  232. u64 tx_sz_128_255; /* packets that are 128-255 bytes */
  233. u64 tx_sz_256_511; /* packets that are 256-511 bytes */
  234. u64 tx_sz_512_1023; /* packets that are 512-1023 bytes */
  235. u64 tx_sz_1024_1518; /* packets that are 1024-1518 bytes */
  236. u64 tx_sz_1519_max; /* packets that are 1519-MTU bytes */
  237. u64 tx_1_col; /* packets single prior collision */
  238. u64 tx_2_col; /* packets with multiple prior collisions */
  239. u64 tx_late_col; /* packets with late collisions */
  240. u64 tx_abort_col; /* packets aborted due to excess collisions */
  241. u64 tx_underrun; /* packets aborted due to FIFO underrun */
  242. u64 tx_rd_eop; /* count of reads beyond EOP */
  243. u64 tx_len_err; /* packets with length mismatch */
  244. u64 tx_trunc; /* packets truncated due to size >MTU */
  245. u64 tx_bcast_byte; /* broadcast packets byte count (without FCS) */
  246. u64 tx_mcast_byte; /* multicast packets byte count (without FCS) */
  247. u64 tx_col; /* collisions */
  248. spinlock_t lock; /* prevent multiple simultaneous readers */
  249. };
  250. /* RSS hstype Definitions */
  251. #define EMAC_RSS_HSTYP_IPV4_EN 0x00000001
  252. #define EMAC_RSS_HSTYP_TCP4_EN 0x00000002
  253. #define EMAC_RSS_HSTYP_IPV6_EN 0x00000004
  254. #define EMAC_RSS_HSTYP_TCP6_EN 0x00000008
  255. #define EMAC_RSS_HSTYP_ALL_EN (\
  256. EMAC_RSS_HSTYP_IPV4_EN |\
  257. EMAC_RSS_HSTYP_TCP4_EN |\
  258. EMAC_RSS_HSTYP_IPV6_EN |\
  259. EMAC_RSS_HSTYP_TCP6_EN)
  260. #define EMAC_VLAN_TO_TAG(_vlan, _tag) \
  261. (_tag = ((((_vlan) >> 8) & 0xFF) | (((_vlan) & 0xFF) << 8)))
  262. #define EMAC_TAG_TO_VLAN(_tag, _vlan) \
  263. (_vlan = ((((_tag) >> 8) & 0xFF) | (((_tag) & 0xFF) << 8)))
  264. #define EMAC_DEF_RX_BUF_SIZE 1536
  265. #define EMAC_MAX_JUMBO_PKT_SIZE (9 * 1024)
  266. #define EMAC_MAX_TX_OFFLOAD_THRESH (9 * 1024)
  267. #define EMAC_MAX_ETH_FRAME_SIZE EMAC_MAX_JUMBO_PKT_SIZE
  268. #define EMAC_MIN_ETH_FRAME_SIZE 68
  269. #define EMAC_DEF_TX_QUEUES 1
  270. #define EMAC_DEF_RX_QUEUES 1
  271. #define EMAC_MIN_TX_DESCS 128
  272. #define EMAC_MIN_RX_DESCS 128
  273. #define EMAC_MAX_TX_DESCS 16383
  274. #define EMAC_MAX_RX_DESCS 2047
  275. #define EMAC_DEF_TX_DESCS 512
  276. #define EMAC_DEF_RX_DESCS 256
  277. #define EMAC_DEF_RX_IRQ_MOD 250
  278. #define EMAC_DEF_TX_IRQ_MOD 250
  279. #define EMAC_WATCHDOG_TIME (5 * HZ)
  280. /* by default check link every 4 seconds */
  281. #define EMAC_TRY_LINK_TIMEOUT (4 * HZ)
  282. /* emac_irq per-device (per-adapter) irq properties.
  283. * @irq: irq number.
  284. * @mask mask to use over status register.
  285. */
  286. struct emac_irq {
  287. unsigned int irq;
  288. u32 mask;
  289. };
  290. /* The device's main data structure */
  291. struct emac_adapter {
  292. struct net_device *netdev;
  293. struct mii_bus *mii_bus;
  294. struct phy_device *phydev;
  295. void __iomem *base;
  296. void __iomem *csr;
  297. struct emac_sgmii phy;
  298. struct emac_stats stats;
  299. struct emac_irq irq;
  300. struct clk *clk[EMAC_CLK_CNT];
  301. /* All Descriptor memory */
  302. struct emac_ring_header ring_header;
  303. struct emac_tx_queue tx_q;
  304. struct emac_rx_queue rx_q;
  305. unsigned int tx_desc_cnt;
  306. unsigned int rx_desc_cnt;
  307. unsigned int rrd_size; /* in quad words */
  308. unsigned int rfd_size; /* in quad words */
  309. unsigned int tpd_size; /* in quad words */
  310. unsigned int rxbuf_size;
  311. /* Flow control / pause frames support. If automatic=True, do whatever
  312. * the PHY does. Otherwise, use tx_flow_control and rx_flow_control.
  313. */
  314. bool automatic;
  315. bool tx_flow_control;
  316. bool rx_flow_control;
  317. /* True == use single-pause-frame mode. */
  318. bool single_pause_mode;
  319. /* Ring parameter */
  320. u8 tpd_burst;
  321. u8 rfd_burst;
  322. unsigned int dmaw_dly_cnt;
  323. unsigned int dmar_dly_cnt;
  324. enum emac_dma_req_block dmar_block;
  325. enum emac_dma_req_block dmaw_block;
  326. enum emac_dma_order dma_order;
  327. u32 irq_mod;
  328. u32 preamble;
  329. struct work_struct work_thread;
  330. u16 msg_enable;
  331. struct mutex reset_lock;
  332. };
  333. int emac_reinit_locked(struct emac_adapter *adpt);
  334. void emac_reg_update32(void __iomem *addr, u32 mask, u32 val);
  335. void emac_set_ethtool_ops(struct net_device *netdev);
  336. void emac_update_hw_stats(struct emac_adapter *adpt);
  337. #endif /* _EMAC_H_ */