emac.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef _EMAC_H_
  13. #define _EMAC_H_
  14. #include <linux/irqreturn.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/clk.h>
  17. #include <linux/platform_device.h>
  18. #include "emac-mac.h"
  19. #include "emac-phy.h"
  20. /* EMAC base register offsets */
  21. #define EMAC_DMA_MAS_CTRL 0x001400
  22. #define EMAC_IRQ_MOD_TIM_INIT 0x001408
  23. #define EMAC_BLK_IDLE_STS 0x00140c
  24. #define EMAC_PHY_LINK_DELAY 0x00141c
  25. #define EMAC_SYS_ALIV_CTRL 0x001434
  26. #define EMAC_MAC_IPGIFG_CTRL 0x001484
  27. #define EMAC_MAC_STA_ADDR0 0x001488
  28. #define EMAC_MAC_STA_ADDR1 0x00148c
  29. #define EMAC_HASH_TAB_REG0 0x001490
  30. #define EMAC_HASH_TAB_REG1 0x001494
  31. #define EMAC_MAC_HALF_DPLX_CTRL 0x001498
  32. #define EMAC_MAX_FRAM_LEN_CTRL 0x00149c
  33. #define EMAC_INT_STATUS 0x001600
  34. #define EMAC_INT_MASK 0x001604
  35. #define EMAC_RXMAC_STATC_REG0 0x001700
  36. #define EMAC_RXMAC_STATC_REG22 0x001758
  37. #define EMAC_TXMAC_STATC_REG0 0x001760
  38. #define EMAC_TXMAC_STATC_REG24 0x0017c0
  39. #define EMAC_CORE_HW_VERSION 0x001974
  40. #define EMAC_IDT_TABLE0 0x001b00
  41. #define EMAC_RXMAC_STATC_REG23 0x001bc8
  42. #define EMAC_RXMAC_STATC_REG24 0x001bcc
  43. #define EMAC_TXMAC_STATC_REG25 0x001bd0
  44. #define EMAC_INT1_MASK 0x001bf0
  45. #define EMAC_INT1_STATUS 0x001bf4
  46. #define EMAC_INT2_MASK 0x001bf8
  47. #define EMAC_INT2_STATUS 0x001bfc
  48. #define EMAC_INT3_MASK 0x001c00
  49. #define EMAC_INT3_STATUS 0x001c04
  50. /* EMAC_DMA_MAS_CTRL */
  51. #define DEV_ID_NUM_BMSK 0x7f000000
  52. #define DEV_ID_NUM_SHFT 24
  53. #define DEV_REV_NUM_BMSK 0xff0000
  54. #define DEV_REV_NUM_SHFT 16
  55. #define INT_RD_CLR_EN 0x4000
  56. #define IRQ_MODERATOR2_EN 0x800
  57. #define IRQ_MODERATOR_EN 0x400
  58. #define LPW_CLK_SEL 0x80
  59. #define LPW_STATE 0x20
  60. #define LPW_MODE 0x10
  61. #define SOFT_RST 0x1
  62. /* EMAC_IRQ_MOD_TIM_INIT */
  63. #define IRQ_MODERATOR2_INIT_BMSK 0xffff0000
  64. #define IRQ_MODERATOR2_INIT_SHFT 16
  65. #define IRQ_MODERATOR_INIT_BMSK 0xffff
  66. #define IRQ_MODERATOR_INIT_SHFT 0
  67. /* EMAC_INT_STATUS */
  68. #define DIS_INT BIT(31)
  69. #define PTP_INT BIT(30)
  70. #define RFD4_UR_INT BIT(29)
  71. #define TX_PKT_INT3 BIT(26)
  72. #define TX_PKT_INT2 BIT(25)
  73. #define TX_PKT_INT1 BIT(24)
  74. #define RX_PKT_INT3 BIT(19)
  75. #define RX_PKT_INT2 BIT(18)
  76. #define RX_PKT_INT1 BIT(17)
  77. #define RX_PKT_INT0 BIT(16)
  78. #define TX_PKT_INT BIT(15)
  79. #define TXQ_TO_INT BIT(14)
  80. #define GPHY_WAKEUP_INT BIT(13)
  81. #define GPHY_LINK_DOWN_INT BIT(12)
  82. #define GPHY_LINK_UP_INT BIT(11)
  83. #define DMAW_TO_INT BIT(10)
  84. #define DMAR_TO_INT BIT(9)
  85. #define TXF_UR_INT BIT(8)
  86. #define RFD3_UR_INT BIT(7)
  87. #define RFD2_UR_INT BIT(6)
  88. #define RFD1_UR_INT BIT(5)
  89. #define RFD0_UR_INT BIT(4)
  90. #define RXF_OF_INT BIT(3)
  91. #define SW_MAN_INT BIT(2)
  92. /* EMAC_MAILBOX_6 */
  93. #define RFD2_PROC_IDX_BMSK 0xfff0000
  94. #define RFD2_PROC_IDX_SHFT 16
  95. #define RFD2_PROD_IDX_BMSK 0xfff
  96. #define RFD2_PROD_IDX_SHFT 0
  97. /* EMAC_CORE_HW_VERSION */
  98. #define MAJOR_BMSK 0xf0000000
  99. #define MAJOR_SHFT 28
  100. #define MINOR_BMSK 0xfff0000
  101. #define MINOR_SHFT 16
  102. #define STEP_BMSK 0xffff
  103. #define STEP_SHFT 0
  104. /* EMAC_EMAC_WRAPPER_CSR1 */
  105. #define TX_INDX_FIFO_SYNC_RST BIT(23)
  106. #define TX_TS_FIFO_SYNC_RST BIT(22)
  107. #define RX_TS_FIFO2_SYNC_RST BIT(21)
  108. #define RX_TS_FIFO1_SYNC_RST BIT(20)
  109. #define TX_TS_ENABLE BIT(16)
  110. #define DIS_1588_CLKS BIT(11)
  111. #define FREQ_MODE BIT(9)
  112. #define ENABLE_RRD_TIMESTAMP BIT(3)
  113. /* EMAC_EMAC_WRAPPER_CSR2 */
  114. #define HDRIVE_BMSK 0x3000
  115. #define HDRIVE_SHFT 12
  116. #define SLB_EN BIT(9)
  117. #define PLB_EN BIT(8)
  118. #define WOL_EN BIT(3)
  119. #define PHY_RESET BIT(0)
  120. #define EMAC_DEV_ID 0x0040
  121. /* SGMII v2 per lane registers */
  122. #define SGMII_LN_RSM_START 0x029C
  123. /* SGMII v2 PHY common registers */
  124. #define SGMII_PHY_CMN_CTRL 0x0408
  125. #define SGMII_PHY_CMN_RESET_CTRL 0x0410
  126. /* SGMII v2 PHY registers per lane */
  127. #define SGMII_PHY_LN_OFFSET 0x0400
  128. #define SGMII_PHY_LN_LANE_STATUS 0x00DC
  129. #define SGMII_PHY_LN_BIST_GEN0 0x008C
  130. #define SGMII_PHY_LN_BIST_GEN1 0x0090
  131. #define SGMII_PHY_LN_BIST_GEN2 0x0094
  132. #define SGMII_PHY_LN_BIST_GEN3 0x0098
  133. #define SGMII_PHY_LN_CDR_CTRL1 0x005C
  134. enum emac_clk_id {
  135. EMAC_CLK_AXI,
  136. EMAC_CLK_CFG_AHB,
  137. EMAC_CLK_HIGH_SPEED,
  138. EMAC_CLK_MDIO,
  139. EMAC_CLK_TX,
  140. EMAC_CLK_RX,
  141. EMAC_CLK_SYS,
  142. EMAC_CLK_CNT
  143. };
  144. #define EMAC_LINK_SPEED_UNKNOWN 0x0
  145. #define EMAC_LINK_SPEED_10_HALF BIT(0)
  146. #define EMAC_LINK_SPEED_10_FULL BIT(1)
  147. #define EMAC_LINK_SPEED_100_HALF BIT(2)
  148. #define EMAC_LINK_SPEED_100_FULL BIT(3)
  149. #define EMAC_LINK_SPEED_1GB_FULL BIT(5)
  150. #define EMAC_MAX_SETUP_LNK_CYCLE 100
  151. /* Wake On Lan */
  152. #define EMAC_WOL_PHY 0x00000001 /* PHY Status Change */
  153. #define EMAC_WOL_MAGIC 0x00000002 /* Magic Packet */
  154. struct emac_stats {
  155. /* rx */
  156. u64 rx_ok; /* good packets */
  157. u64 rx_bcast; /* good broadcast packets */
  158. u64 rx_mcast; /* good multicast packets */
  159. u64 rx_pause; /* pause packet */
  160. u64 rx_ctrl; /* control packets other than pause frame. */
  161. u64 rx_fcs_err; /* packets with bad FCS. */
  162. u64 rx_len_err; /* packets with length mismatch */
  163. u64 rx_byte_cnt; /* good bytes count (without FCS) */
  164. u64 rx_runt; /* runt packets */
  165. u64 rx_frag; /* fragment count */
  166. u64 rx_sz_64; /* packets that are 64 bytes */
  167. u64 rx_sz_65_127; /* packets that are 65-127 bytes */
  168. u64 rx_sz_128_255; /* packets that are 128-255 bytes */
  169. u64 rx_sz_256_511; /* packets that are 256-511 bytes */
  170. u64 rx_sz_512_1023; /* packets that are 512-1023 bytes */
  171. u64 rx_sz_1024_1518; /* packets that are 1024-1518 bytes */
  172. u64 rx_sz_1519_max; /* packets that are 1519-MTU bytes*/
  173. u64 rx_sz_ov; /* packets that are >MTU bytes (truncated) */
  174. u64 rx_rxf_ov; /* packets dropped due to RX FIFO overflow */
  175. u64 rx_align_err; /* alignment errors */
  176. u64 rx_bcast_byte_cnt; /* broadcast packets byte count (without FCS) */
  177. u64 rx_mcast_byte_cnt; /* multicast packets byte count (without FCS) */
  178. u64 rx_err_addr; /* packets dropped due to address filtering */
  179. u64 rx_crc_align; /* CRC align errors */
  180. u64 rx_jabbers; /* jabbers */
  181. /* tx */
  182. u64 tx_ok; /* good packets */
  183. u64 tx_bcast; /* good broadcast packets */
  184. u64 tx_mcast; /* good multicast packets */
  185. u64 tx_pause; /* pause packets */
  186. u64 tx_exc_defer; /* packets with excessive deferral */
  187. u64 tx_ctrl; /* control packets other than pause frame */
  188. u64 tx_defer; /* packets that are deferred. */
  189. u64 tx_byte_cnt; /* good bytes count (without FCS) */
  190. u64 tx_sz_64; /* packets that are 64 bytes */
  191. u64 tx_sz_65_127; /* packets that are 65-127 bytes */
  192. u64 tx_sz_128_255; /* packets that are 128-255 bytes */
  193. u64 tx_sz_256_511; /* packets that are 256-511 bytes */
  194. u64 tx_sz_512_1023; /* packets that are 512-1023 bytes */
  195. u64 tx_sz_1024_1518; /* packets that are 1024-1518 bytes */
  196. u64 tx_sz_1519_max; /* packets that are 1519-MTU bytes */
  197. u64 tx_1_col; /* packets single prior collision */
  198. u64 tx_2_col; /* packets with multiple prior collisions */
  199. u64 tx_late_col; /* packets with late collisions */
  200. u64 tx_abort_col; /* packets aborted due to excess collisions */
  201. u64 tx_underrun; /* packets aborted due to FIFO underrun */
  202. u64 tx_rd_eop; /* count of reads beyond EOP */
  203. u64 tx_len_err; /* packets with length mismatch */
  204. u64 tx_trunc; /* packets truncated due to size >MTU */
  205. u64 tx_bcast_byte; /* broadcast packets byte count (without FCS) */
  206. u64 tx_mcast_byte; /* multicast packets byte count (without FCS) */
  207. u64 tx_col; /* collisions */
  208. spinlock_t lock; /* prevent multiple simultaneous readers */
  209. };
  210. /* RSS hstype Definitions */
  211. #define EMAC_RSS_HSTYP_IPV4_EN 0x00000001
  212. #define EMAC_RSS_HSTYP_TCP4_EN 0x00000002
  213. #define EMAC_RSS_HSTYP_IPV6_EN 0x00000004
  214. #define EMAC_RSS_HSTYP_TCP6_EN 0x00000008
  215. #define EMAC_RSS_HSTYP_ALL_EN (\
  216. EMAC_RSS_HSTYP_IPV4_EN |\
  217. EMAC_RSS_HSTYP_TCP4_EN |\
  218. EMAC_RSS_HSTYP_IPV6_EN |\
  219. EMAC_RSS_HSTYP_TCP6_EN)
  220. #define EMAC_VLAN_TO_TAG(_vlan, _tag) \
  221. (_tag = ((((_vlan) >> 8) & 0xFF) | (((_vlan) & 0xFF) << 8)))
  222. #define EMAC_TAG_TO_VLAN(_tag, _vlan) \
  223. (_vlan = ((((_tag) >> 8) & 0xFF) | (((_tag) & 0xFF) << 8)))
  224. #define EMAC_DEF_RX_BUF_SIZE 1536
  225. #define EMAC_MAX_JUMBO_PKT_SIZE (9 * 1024)
  226. #define EMAC_MAX_TX_OFFLOAD_THRESH (9 * 1024)
  227. #define EMAC_MAX_ETH_FRAME_SIZE EMAC_MAX_JUMBO_PKT_SIZE
  228. #define EMAC_MIN_ETH_FRAME_SIZE 68
  229. #define EMAC_DEF_TX_QUEUES 1
  230. #define EMAC_DEF_RX_QUEUES 1
  231. #define EMAC_MIN_TX_DESCS 128
  232. #define EMAC_MIN_RX_DESCS 128
  233. #define EMAC_MAX_TX_DESCS 16383
  234. #define EMAC_MAX_RX_DESCS 2047
  235. #define EMAC_DEF_TX_DESCS 512
  236. #define EMAC_DEF_RX_DESCS 256
  237. #define EMAC_DEF_RX_IRQ_MOD 250
  238. #define EMAC_DEF_TX_IRQ_MOD 250
  239. #define EMAC_WATCHDOG_TIME (5 * HZ)
  240. /* by default check link every 4 seconds */
  241. #define EMAC_TRY_LINK_TIMEOUT (4 * HZ)
  242. /* emac_irq per-device (per-adapter) irq properties.
  243. * @irq: irq number.
  244. * @mask mask to use over status register.
  245. */
  246. struct emac_irq {
  247. unsigned int irq;
  248. u32 mask;
  249. };
  250. /* The device's main data structure */
  251. struct emac_adapter {
  252. struct net_device *netdev;
  253. struct mii_bus *mii_bus;
  254. struct phy_device *phydev;
  255. void __iomem *base;
  256. void __iomem *csr;
  257. struct emac_phy phy;
  258. struct emac_stats stats;
  259. struct emac_irq irq;
  260. struct clk *clk[EMAC_CLK_CNT];
  261. /* All Descriptor memory */
  262. struct emac_ring_header ring_header;
  263. struct emac_tx_queue tx_q;
  264. struct emac_rx_queue rx_q;
  265. unsigned int tx_desc_cnt;
  266. unsigned int rx_desc_cnt;
  267. unsigned int rrd_size; /* in quad words */
  268. unsigned int rfd_size; /* in quad words */
  269. unsigned int tpd_size; /* in quad words */
  270. unsigned int rxbuf_size;
  271. /* Ring parameter */
  272. u8 tpd_burst;
  273. u8 rfd_burst;
  274. unsigned int dmaw_dly_cnt;
  275. unsigned int dmar_dly_cnt;
  276. enum emac_dma_req_block dmar_block;
  277. enum emac_dma_req_block dmaw_block;
  278. enum emac_dma_order dma_order;
  279. u32 irq_mod;
  280. u32 preamble;
  281. struct work_struct work_thread;
  282. u16 msg_enable;
  283. struct mutex reset_lock;
  284. };
  285. int emac_reinit_locked(struct emac_adapter *adpt);
  286. void emac_reg_update32(void __iomem *addr, u32 mask, u32 val);
  287. irqreturn_t emac_isr(int irq, void *data);
  288. #endif /* _EMAC_H_ */