mtk_eth_soc.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. *
  4. * Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org>
  5. * Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org>
  6. * Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com>
  7. */
  8. #ifndef MTK_ETH_H
  9. #define MTK_ETH_H
  10. #include <linux/dma-mapping.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/of_net.h>
  13. #include <linux/u64_stats_sync.h>
  14. #include <linux/refcount.h>
  15. #include <linux/phylink.h>
  16. #define MTK_QDMA_PAGE_SIZE 2048
  17. #define MTK_MAX_RX_LENGTH 1536
  18. #define MTK_TX_DMA_BUF_LEN 0x3fff
  19. #define MTK_DMA_SIZE 256
  20. #define MTK_NAPI_WEIGHT 64
  21. #define MTK_MAC_COUNT 2
  22. #define MTK_RX_ETH_HLEN (VLAN_ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
  23. #define MTK_RX_HLEN (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN)
  24. #define MTK_DMA_DUMMY_DESC 0xffffffff
  25. #define MTK_DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | \
  26. NETIF_MSG_PROBE | \
  27. NETIF_MSG_LINK | \
  28. NETIF_MSG_TIMER | \
  29. NETIF_MSG_IFDOWN | \
  30. NETIF_MSG_IFUP | \
  31. NETIF_MSG_RX_ERR | \
  32. NETIF_MSG_TX_ERR)
  33. #define MTK_HW_FEATURES (NETIF_F_IP_CSUM | \
  34. NETIF_F_RXCSUM | \
  35. NETIF_F_HW_VLAN_CTAG_TX | \
  36. NETIF_F_HW_VLAN_CTAG_RX | \
  37. NETIF_F_SG | NETIF_F_TSO | \
  38. NETIF_F_TSO6 | \
  39. NETIF_F_IPV6_CSUM)
  40. #define MTK_HW_FEATURES_MT7628 (NETIF_F_SG | NETIF_F_RXCSUM)
  41. #define NEXT_DESP_IDX(X, Y) (((X) + 1) & ((Y) - 1))
  42. #define MTK_MAX_RX_RING_NUM 4
  43. #define MTK_HW_LRO_DMA_SIZE 8
  44. #define MTK_MAX_LRO_RX_LENGTH (4096 * 3)
  45. #define MTK_MAX_LRO_IP_CNT 2
  46. #define MTK_HW_LRO_TIMER_UNIT 1 /* 20 us */
  47. #define MTK_HW_LRO_REFRESH_TIME 50000 /* 1 sec. */
  48. #define MTK_HW_LRO_AGG_TIME 10 /* 200us */
  49. #define MTK_HW_LRO_AGE_TIME 50 /* 1ms */
  50. #define MTK_HW_LRO_MAX_AGG_CNT 64
  51. #define MTK_HW_LRO_BW_THRE 3000
  52. #define MTK_HW_LRO_REPLACE_DELTA 1000
  53. #define MTK_HW_LRO_SDL_REMAIN_ROOM 1522
  54. /* Frame Engine Global Reset Register */
  55. #define MTK_RST_GL 0x04
  56. #define RST_GL_PSE BIT(0)
  57. /* Frame Engine Interrupt Status Register */
  58. #define MTK_INT_STATUS2 0x08
  59. #define MTK_GDM1_AF BIT(28)
  60. #define MTK_GDM2_AF BIT(29)
  61. /* PDMA HW LRO Alter Flow Timer Register */
  62. #define MTK_PDMA_LRO_ALT_REFRESH_TIMER 0x1c
  63. /* Frame Engine Interrupt Grouping Register */
  64. #define MTK_FE_INT_GRP 0x20
  65. /* CDMP Ingress Control Register */
  66. #define MTK_CDMQ_IG_CTRL 0x1400
  67. #define MTK_CDMQ_STAG_EN BIT(0)
  68. /* CDMP Exgress Control Register */
  69. #define MTK_CDMP_EG_CTRL 0x404
  70. /* GDM Exgress Control Register */
  71. #define MTK_GDMA_FWD_CFG(x) (0x500 + (x * 0x1000))
  72. #define MTK_GDMA_ICS_EN BIT(22)
  73. #define MTK_GDMA_TCS_EN BIT(21)
  74. #define MTK_GDMA_UCS_EN BIT(20)
  75. /* Unicast Filter MAC Address Register - Low */
  76. #define MTK_GDMA_MAC_ADRL(x) (0x508 + (x * 0x1000))
  77. /* Unicast Filter MAC Address Register - High */
  78. #define MTK_GDMA_MAC_ADRH(x) (0x50C + (x * 0x1000))
  79. /* PDMA RX Base Pointer Register */
  80. #define MTK_PRX_BASE_PTR0 0x900
  81. #define MTK_PRX_BASE_PTR_CFG(x) (MTK_PRX_BASE_PTR0 + (x * 0x10))
  82. /* PDMA RX Maximum Count Register */
  83. #define MTK_PRX_MAX_CNT0 0x904
  84. #define MTK_PRX_MAX_CNT_CFG(x) (MTK_PRX_MAX_CNT0 + (x * 0x10))
  85. /* PDMA RX CPU Pointer Register */
  86. #define MTK_PRX_CRX_IDX0 0x908
  87. #define MTK_PRX_CRX_IDX_CFG(x) (MTK_PRX_CRX_IDX0 + (x * 0x10))
  88. /* PDMA HW LRO Control Registers */
  89. #define MTK_PDMA_LRO_CTRL_DW0 0x980
  90. #define MTK_LRO_EN BIT(0)
  91. #define MTK_L3_CKS_UPD_EN BIT(7)
  92. #define MTK_LRO_ALT_PKT_CNT_MODE BIT(21)
  93. #define MTK_LRO_RING_RELINQUISH_REQ (0x7 << 26)
  94. #define MTK_LRO_RING_RELINQUISH_DONE (0x7 << 29)
  95. #define MTK_PDMA_LRO_CTRL_DW1 0x984
  96. #define MTK_PDMA_LRO_CTRL_DW2 0x988
  97. #define MTK_PDMA_LRO_CTRL_DW3 0x98c
  98. #define MTK_ADMA_MODE BIT(15)
  99. #define MTK_LRO_MIN_RXD_SDL (MTK_HW_LRO_SDL_REMAIN_ROOM << 16)
  100. /* PDMA Global Configuration Register */
  101. #define MTK_PDMA_GLO_CFG 0xa04
  102. #define MTK_MULTI_EN BIT(10)
  103. #define MTK_PDMA_SIZE_8DWORDS (1 << 4)
  104. /* PDMA Reset Index Register */
  105. #define MTK_PDMA_RST_IDX 0xa08
  106. #define MTK_PST_DRX_IDX0 BIT(16)
  107. #define MTK_PST_DRX_IDX_CFG(x) (MTK_PST_DRX_IDX0 << (x))
  108. /* PDMA Delay Interrupt Register */
  109. #define MTK_PDMA_DELAY_INT 0xa0c
  110. #define MTK_PDMA_DELAY_RX_EN BIT(15)
  111. #define MTK_PDMA_DELAY_RX_PINT 4
  112. #define MTK_PDMA_DELAY_RX_PINT_SHIFT 8
  113. #define MTK_PDMA_DELAY_RX_PTIME 4
  114. #define MTK_PDMA_DELAY_RX_DELAY \
  115. (MTK_PDMA_DELAY_RX_EN | MTK_PDMA_DELAY_RX_PTIME | \
  116. (MTK_PDMA_DELAY_RX_PINT << MTK_PDMA_DELAY_RX_PINT_SHIFT))
  117. /* PDMA Interrupt Status Register */
  118. #define MTK_PDMA_INT_STATUS 0xa20
  119. /* PDMA Interrupt Mask Register */
  120. #define MTK_PDMA_INT_MASK 0xa28
  121. /* PDMA HW LRO Alter Flow Delta Register */
  122. #define MTK_PDMA_LRO_ALT_SCORE_DELTA 0xa4c
  123. /* PDMA Interrupt grouping registers */
  124. #define MTK_PDMA_INT_GRP1 0xa50
  125. #define MTK_PDMA_INT_GRP2 0xa54
  126. /* PDMA HW LRO IP Setting Registers */
  127. #define MTK_LRO_RX_RING0_DIP_DW0 0xb04
  128. #define MTK_LRO_DIP_DW0_CFG(x) (MTK_LRO_RX_RING0_DIP_DW0 + (x * 0x40))
  129. #define MTK_RING_MYIP_VLD BIT(9)
  130. /* PDMA HW LRO Ring Control Registers */
  131. #define MTK_LRO_RX_RING0_CTRL_DW1 0xb28
  132. #define MTK_LRO_RX_RING0_CTRL_DW2 0xb2c
  133. #define MTK_LRO_RX_RING0_CTRL_DW3 0xb30
  134. #define MTK_LRO_CTRL_DW1_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW1 + (x * 0x40))
  135. #define MTK_LRO_CTRL_DW2_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW2 + (x * 0x40))
  136. #define MTK_LRO_CTRL_DW3_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW3 + (x * 0x40))
  137. #define MTK_RING_AGE_TIME_L ((MTK_HW_LRO_AGE_TIME & 0x3ff) << 22)
  138. #define MTK_RING_AGE_TIME_H ((MTK_HW_LRO_AGE_TIME >> 10) & 0x3f)
  139. #define MTK_RING_AUTO_LERAN_MODE (3 << 6)
  140. #define MTK_RING_VLD BIT(8)
  141. #define MTK_RING_MAX_AGG_TIME ((MTK_HW_LRO_AGG_TIME & 0xffff) << 10)
  142. #define MTK_RING_MAX_AGG_CNT_L ((MTK_HW_LRO_MAX_AGG_CNT & 0x3f) << 26)
  143. #define MTK_RING_MAX_AGG_CNT_H ((MTK_HW_LRO_MAX_AGG_CNT >> 6) & 0x3)
  144. /* QDMA TX Queue Configuration Registers */
  145. #define MTK_QTX_CFG(x) (0x1800 + (x * 0x10))
  146. #define QDMA_RES_THRES 4
  147. /* QDMA TX Queue Scheduler Registers */
  148. #define MTK_QTX_SCH(x) (0x1804 + (x * 0x10))
  149. /* QDMA RX Base Pointer Register */
  150. #define MTK_QRX_BASE_PTR0 0x1900
  151. /* QDMA RX Maximum Count Register */
  152. #define MTK_QRX_MAX_CNT0 0x1904
  153. /* QDMA RX CPU Pointer Register */
  154. #define MTK_QRX_CRX_IDX0 0x1908
  155. /* QDMA RX DMA Pointer Register */
  156. #define MTK_QRX_DRX_IDX0 0x190C
  157. /* QDMA Global Configuration Register */
  158. #define MTK_QDMA_GLO_CFG 0x1A04
  159. #define MTK_RX_2B_OFFSET BIT(31)
  160. #define MTK_RX_BT_32DWORDS (3 << 11)
  161. #define MTK_NDP_CO_PRO BIT(10)
  162. #define MTK_TX_WB_DDONE BIT(6)
  163. #define MTK_DMA_SIZE_16DWORDS (2 << 4)
  164. #define MTK_RX_DMA_BUSY BIT(3)
  165. #define MTK_TX_DMA_BUSY BIT(1)
  166. #define MTK_RX_DMA_EN BIT(2)
  167. #define MTK_TX_DMA_EN BIT(0)
  168. #define MTK_DMA_BUSY_TIMEOUT HZ
  169. /* QDMA Reset Index Register */
  170. #define MTK_QDMA_RST_IDX 0x1A08
  171. /* QDMA Delay Interrupt Register */
  172. #define MTK_QDMA_DELAY_INT 0x1A0C
  173. /* QDMA Flow Control Register */
  174. #define MTK_QDMA_FC_THRES 0x1A10
  175. #define FC_THRES_DROP_MODE BIT(20)
  176. #define FC_THRES_DROP_EN (7 << 16)
  177. #define FC_THRES_MIN 0x4444
  178. /* QDMA Interrupt Status Register */
  179. #define MTK_QDMA_INT_STATUS 0x1A18
  180. #define MTK_RX_DONE_DLY BIT(30)
  181. #define MTK_RX_DONE_INT3 BIT(19)
  182. #define MTK_RX_DONE_INT2 BIT(18)
  183. #define MTK_RX_DONE_INT1 BIT(17)
  184. #define MTK_RX_DONE_INT0 BIT(16)
  185. #define MTK_TX_DONE_INT3 BIT(3)
  186. #define MTK_TX_DONE_INT2 BIT(2)
  187. #define MTK_TX_DONE_INT1 BIT(1)
  188. #define MTK_TX_DONE_INT0 BIT(0)
  189. #define MTK_RX_DONE_INT MTK_RX_DONE_DLY
  190. #define MTK_TX_DONE_INT (MTK_TX_DONE_INT0 | MTK_TX_DONE_INT1 | \
  191. MTK_TX_DONE_INT2 | MTK_TX_DONE_INT3)
  192. /* QDMA Interrupt grouping registers */
  193. #define MTK_QDMA_INT_GRP1 0x1a20
  194. #define MTK_QDMA_INT_GRP2 0x1a24
  195. #define MTK_RLS_DONE_INT BIT(0)
  196. /* QDMA Interrupt Status Register */
  197. #define MTK_QDMA_INT_MASK 0x1A1C
  198. /* QDMA Interrupt Mask Register */
  199. #define MTK_QDMA_HRED2 0x1A44
  200. /* QDMA TX Forward CPU Pointer Register */
  201. #define MTK_QTX_CTX_PTR 0x1B00
  202. /* QDMA TX Forward DMA Pointer Register */
  203. #define MTK_QTX_DTX_PTR 0x1B04
  204. /* QDMA TX Release CPU Pointer Register */
  205. #define MTK_QTX_CRX_PTR 0x1B10
  206. /* QDMA TX Release DMA Pointer Register */
  207. #define MTK_QTX_DRX_PTR 0x1B14
  208. /* QDMA FQ Head Pointer Register */
  209. #define MTK_QDMA_FQ_HEAD 0x1B20
  210. /* QDMA FQ Head Pointer Register */
  211. #define MTK_QDMA_FQ_TAIL 0x1B24
  212. /* QDMA FQ Free Page Counter Register */
  213. #define MTK_QDMA_FQ_CNT 0x1B28
  214. /* QDMA FQ Free Page Buffer Length Register */
  215. #define MTK_QDMA_FQ_BLEN 0x1B2C
  216. /* GMA1 counter / statics register */
  217. #define MTK_GDM1_RX_GBCNT_L 0x2400
  218. #define MTK_GDM1_RX_GBCNT_H 0x2404
  219. #define MTK_GDM1_RX_GPCNT 0x2408
  220. #define MTK_GDM1_RX_OERCNT 0x2410
  221. #define MTK_GDM1_RX_FERCNT 0x2414
  222. #define MTK_GDM1_RX_SERCNT 0x2418
  223. #define MTK_GDM1_RX_LENCNT 0x241c
  224. #define MTK_GDM1_RX_CERCNT 0x2420
  225. #define MTK_GDM1_RX_FCCNT 0x2424
  226. #define MTK_GDM1_TX_SKIPCNT 0x2428
  227. #define MTK_GDM1_TX_COLCNT 0x242c
  228. #define MTK_GDM1_TX_GBCNT_L 0x2430
  229. #define MTK_GDM1_TX_GBCNT_H 0x2434
  230. #define MTK_GDM1_TX_GPCNT 0x2438
  231. #define MTK_STAT_OFFSET 0x40
  232. /* QDMA descriptor txd4 */
  233. #define TX_DMA_CHKSUM (0x7 << 29)
  234. #define TX_DMA_TSO BIT(28)
  235. #define TX_DMA_FPORT_SHIFT 25
  236. #define TX_DMA_FPORT_MASK 0x7
  237. #define TX_DMA_INS_VLAN BIT(16)
  238. /* QDMA descriptor txd3 */
  239. #define TX_DMA_OWNER_CPU BIT(31)
  240. #define TX_DMA_LS0 BIT(30)
  241. #define TX_DMA_PLEN0(_x) (((_x) & MTK_TX_DMA_BUF_LEN) << 16)
  242. #define TX_DMA_PLEN1(_x) ((_x) & MTK_TX_DMA_BUF_LEN)
  243. #define TX_DMA_SWC BIT(14)
  244. #define TX_DMA_SDL(_x) (((_x) & 0x3fff) << 16)
  245. /* PDMA on MT7628 */
  246. #define TX_DMA_DONE BIT(31)
  247. #define TX_DMA_LS1 BIT(14)
  248. #define TX_DMA_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE)
  249. /* QDMA descriptor rxd2 */
  250. #define RX_DMA_DONE BIT(31)
  251. #define RX_DMA_LSO BIT(30)
  252. #define RX_DMA_PLEN0(_x) (((_x) & 0x3fff) << 16)
  253. #define RX_DMA_GET_PLEN0(_x) (((_x) >> 16) & 0x3fff)
  254. #define RX_DMA_VTAG BIT(15)
  255. /* QDMA descriptor rxd3 */
  256. #define RX_DMA_VID(_x) ((_x) & 0xfff)
  257. /* QDMA descriptor rxd4 */
  258. #define RX_DMA_L4_VALID BIT(24)
  259. #define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
  260. #define RX_DMA_FPORT_SHIFT 19
  261. #define RX_DMA_FPORT_MASK 0x7
  262. /* PHY Indirect Access Control registers */
  263. #define MTK_PHY_IAC 0x10004
  264. #define PHY_IAC_ACCESS BIT(31)
  265. #define PHY_IAC_READ BIT(19)
  266. #define PHY_IAC_WRITE BIT(18)
  267. #define PHY_IAC_START BIT(16)
  268. #define PHY_IAC_ADDR_SHIFT 20
  269. #define PHY_IAC_REG_SHIFT 25
  270. #define PHY_IAC_TIMEOUT HZ
  271. #define MTK_MAC_MISC 0x1000c
  272. #define MTK_MUX_TO_ESW BIT(0)
  273. /* Mac control registers */
  274. #define MTK_MAC_MCR(x) (0x10100 + (x * 0x100))
  275. #define MAC_MCR_MAX_RX_1536 BIT(24)
  276. #define MAC_MCR_IPG_CFG (BIT(18) | BIT(16))
  277. #define MAC_MCR_FORCE_MODE BIT(15)
  278. #define MAC_MCR_TX_EN BIT(14)
  279. #define MAC_MCR_RX_EN BIT(13)
  280. #define MAC_MCR_BACKOFF_EN BIT(9)
  281. #define MAC_MCR_BACKPR_EN BIT(8)
  282. #define MAC_MCR_FORCE_RX_FC BIT(5)
  283. #define MAC_MCR_FORCE_TX_FC BIT(4)
  284. #define MAC_MCR_SPEED_1000 BIT(3)
  285. #define MAC_MCR_SPEED_100 BIT(2)
  286. #define MAC_MCR_FORCE_DPX BIT(1)
  287. #define MAC_MCR_FORCE_LINK BIT(0)
  288. #define MAC_MCR_FORCE_LINK_DOWN (MAC_MCR_FORCE_MODE)
  289. /* Mac status registers */
  290. #define MTK_MAC_MSR(x) (0x10108 + (x * 0x100))
  291. #define MAC_MSR_EEE1G BIT(7)
  292. #define MAC_MSR_EEE100M BIT(6)
  293. #define MAC_MSR_RX_FC BIT(5)
  294. #define MAC_MSR_TX_FC BIT(4)
  295. #define MAC_MSR_SPEED_1000 BIT(3)
  296. #define MAC_MSR_SPEED_100 BIT(2)
  297. #define MAC_MSR_SPEED_MASK (MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100)
  298. #define MAC_MSR_DPX BIT(1)
  299. #define MAC_MSR_LINK BIT(0)
  300. /* TRGMII RXC control register */
  301. #define TRGMII_RCK_CTRL 0x10300
  302. #define DQSI0(x) ((x << 0) & GENMASK(6, 0))
  303. #define DQSI1(x) ((x << 8) & GENMASK(14, 8))
  304. #define RXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
  305. #define RXC_RST BIT(31)
  306. #define RXC_DQSISEL BIT(30)
  307. #define RCK_CTRL_RGMII_1000 (RXC_DQSISEL | RXCTL_DMWTLAT(2) | DQSI1(16))
  308. #define RCK_CTRL_RGMII_10_100 RXCTL_DMWTLAT(2)
  309. #define NUM_TRGMII_CTRL 5
  310. /* TRGMII RXC control register */
  311. #define TRGMII_TCK_CTRL 0x10340
  312. #define TXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
  313. #define TXC_INV BIT(30)
  314. #define TCK_CTRL_RGMII_1000 TXCTL_DMWTLAT(2)
  315. #define TCK_CTRL_RGMII_10_100 (TXC_INV | TXCTL_DMWTLAT(2))
  316. /* TRGMII TX Drive Strength */
  317. #define TRGMII_TD_ODT(i) (0x10354 + 8 * (i))
  318. #define TD_DM_DRVP(x) ((x) & 0xf)
  319. #define TD_DM_DRVN(x) (((x) & 0xf) << 4)
  320. /* TRGMII Interface mode register */
  321. #define INTF_MODE 0x10390
  322. #define TRGMII_INTF_DIS BIT(0)
  323. #define TRGMII_MODE BIT(1)
  324. #define TRGMII_CENTRAL_ALIGNED BIT(2)
  325. #define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
  326. #define INTF_MODE_RGMII_10_100 0
  327. /* GPIO port control registers for GMAC 2*/
  328. #define GPIO_OD33_CTRL8 0x4c0
  329. #define GPIO_BIAS_CTRL 0xed0
  330. #define GPIO_DRV_SEL10 0xf00
  331. /* ethernet subsystem chip id register */
  332. #define ETHSYS_CHIPID0_3 0x0
  333. #define ETHSYS_CHIPID4_7 0x4
  334. #define MT7623_ETH 7623
  335. #define MT7622_ETH 7622
  336. #define MT7621_ETH 7621
  337. /* ethernet system control register */
  338. #define ETHSYS_SYSCFG 0x10
  339. #define SYSCFG_DRAM_TYPE_DDR2 BIT(4)
  340. /* ethernet subsystem config register */
  341. #define ETHSYS_SYSCFG0 0x14
  342. #define SYSCFG0_GE_MASK 0x3
  343. #define SYSCFG0_GE_MODE(x, y) (x << (12 + (y * 2)))
  344. #define SYSCFG0_SGMII_MASK GENMASK(9, 8)
  345. #define SYSCFG0_SGMII_GMAC1 ((2 << 8) & SYSCFG0_SGMII_MASK)
  346. #define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK)
  347. #define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
  348. #define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
  349. /* ethernet subsystem clock register */
  350. #define ETHSYS_CLKCFG0 0x2c
  351. #define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
  352. #define ETHSYS_TRGMII_MT7621_MASK (BIT(5) | BIT(6))
  353. #define ETHSYS_TRGMII_MT7621_APLL BIT(6)
  354. #define ETHSYS_TRGMII_MT7621_DDR_PLL BIT(5)
  355. /* ethernet reset control register */
  356. #define ETHSYS_RSTCTRL 0x34
  357. #define RSTCTRL_FE BIT(6)
  358. #define RSTCTRL_PPE BIT(31)
  359. /* SGMII subsystem config registers */
  360. /* Register to auto-negotiation restart */
  361. #define SGMSYS_PCS_CONTROL_1 0x0
  362. #define SGMII_AN_RESTART BIT(9)
  363. #define SGMII_ISOLATE BIT(10)
  364. #define SGMII_AN_ENABLE BIT(12)
  365. #define SGMII_LINK_STATYS BIT(18)
  366. #define SGMII_AN_ABILITY BIT(19)
  367. #define SGMII_AN_COMPLETE BIT(21)
  368. #define SGMII_PCS_FAULT BIT(23)
  369. #define SGMII_AN_EXPANSION_CLR BIT(30)
  370. /* Register to programmable link timer, the unit in 2 * 8ns */
  371. #define SGMSYS_PCS_LINK_TIMER 0x18
  372. #define SGMII_LINK_TIMER_DEFAULT (0x186a0 & GENMASK(19, 0))
  373. /* Register to control remote fault */
  374. #define SGMSYS_SGMII_MODE 0x20
  375. #define SGMII_IF_MODE_BIT0 BIT(0)
  376. #define SGMII_SPEED_DUPLEX_AN BIT(1)
  377. #define SGMII_SPEED_10 0x0
  378. #define SGMII_SPEED_100 BIT(2)
  379. #define SGMII_SPEED_1000 BIT(3)
  380. #define SGMII_DUPLEX_FULL BIT(4)
  381. #define SGMII_IF_MODE_BIT5 BIT(5)
  382. #define SGMII_REMOTE_FAULT_DIS BIT(8)
  383. #define SGMII_CODE_SYNC_SET_VAL BIT(9)
  384. #define SGMII_CODE_SYNC_SET_EN BIT(10)
  385. #define SGMII_SEND_AN_ERROR_EN BIT(11)
  386. #define SGMII_IF_MODE_MASK GENMASK(5, 1)
  387. /* Register to set SGMII speed, ANA RG_ Control Signals III*/
  388. #define SGMSYS_ANA_RG_CS3 0x2028
  389. #define RG_PHY_SPEED_MASK (BIT(2) | BIT(3))
  390. #define RG_PHY_SPEED_1_25G 0x0
  391. #define RG_PHY_SPEED_3_125G BIT(2)
  392. /* Register to power up QPHY */
  393. #define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
  394. #define SGMII_PHYA_PWD BIT(4)
  395. /* Infrasys subsystem config registers */
  396. #define INFRA_MISC2 0x70c
  397. #define CO_QPHY_SEL BIT(0)
  398. #define GEPHY_MAC_SEL BIT(1)
  399. /* MT7628/88 specific stuff */
  400. #define MT7628_PDMA_OFFSET 0x0800
  401. #define MT7628_SDM_OFFSET 0x0c00
  402. #define MT7628_TX_BASE_PTR0 (MT7628_PDMA_OFFSET + 0x00)
  403. #define MT7628_TX_MAX_CNT0 (MT7628_PDMA_OFFSET + 0x04)
  404. #define MT7628_TX_CTX_IDX0 (MT7628_PDMA_OFFSET + 0x08)
  405. #define MT7628_TX_DTX_IDX0 (MT7628_PDMA_OFFSET + 0x0c)
  406. #define MT7628_PST_DTX_IDX0 BIT(0)
  407. #define MT7628_SDM_MAC_ADRL (MT7628_SDM_OFFSET + 0x0c)
  408. #define MT7628_SDM_MAC_ADRH (MT7628_SDM_OFFSET + 0x10)
  409. /* Counter / stat register */
  410. #define MT7628_SDM_TPCNT (MT7628_SDM_OFFSET + 0x100)
  411. #define MT7628_SDM_TBCNT (MT7628_SDM_OFFSET + 0x104)
  412. #define MT7628_SDM_RPCNT (MT7628_SDM_OFFSET + 0x108)
  413. #define MT7628_SDM_RBCNT (MT7628_SDM_OFFSET + 0x10c)
  414. #define MT7628_SDM_CS_ERR (MT7628_SDM_OFFSET + 0x110)
  415. struct mtk_rx_dma {
  416. unsigned int rxd1;
  417. unsigned int rxd2;
  418. unsigned int rxd3;
  419. unsigned int rxd4;
  420. } __packed __aligned(4);
  421. struct mtk_tx_dma {
  422. unsigned int txd1;
  423. unsigned int txd2;
  424. unsigned int txd3;
  425. unsigned int txd4;
  426. } __packed __aligned(4);
  427. struct mtk_eth;
  428. struct mtk_mac;
  429. /* struct mtk_hw_stats - the structure that holds the traffic statistics.
  430. * @stats_lock: make sure that stats operations are atomic
  431. * @reg_offset: the status register offset of the SoC
  432. * @syncp: the refcount
  433. *
  434. * All of the supported SoCs have hardware counters for traffic statistics.
  435. * Whenever the status IRQ triggers we can read the latest stats from these
  436. * counters and store them in this struct.
  437. */
  438. struct mtk_hw_stats {
  439. u64 tx_bytes;
  440. u64 tx_packets;
  441. u64 tx_skip;
  442. u64 tx_collisions;
  443. u64 rx_bytes;
  444. u64 rx_packets;
  445. u64 rx_overflow;
  446. u64 rx_fcs_errors;
  447. u64 rx_short_errors;
  448. u64 rx_long_errors;
  449. u64 rx_checksum_errors;
  450. u64 rx_flow_control_packets;
  451. spinlock_t stats_lock;
  452. u32 reg_offset;
  453. struct u64_stats_sync syncp;
  454. };
  455. enum mtk_tx_flags {
  456. /* PDMA descriptor can point at 1-2 segments. This enum allows us to
  457. * track how memory was allocated so that it can be freed properly.
  458. */
  459. MTK_TX_FLAGS_SINGLE0 = 0x01,
  460. MTK_TX_FLAGS_PAGE0 = 0x02,
  461. /* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted
  462. * SKB out instead of looking up through hardware TX descriptor.
  463. */
  464. MTK_TX_FLAGS_FPORT0 = 0x04,
  465. MTK_TX_FLAGS_FPORT1 = 0x08,
  466. };
  467. /* This enum allows us to identify how the clock is defined on the array of the
  468. * clock in the order
  469. */
  470. enum mtk_clks_map {
  471. MTK_CLK_ETHIF,
  472. MTK_CLK_SGMIITOP,
  473. MTK_CLK_ESW,
  474. MTK_CLK_GP0,
  475. MTK_CLK_GP1,
  476. MTK_CLK_GP2,
  477. MTK_CLK_FE,
  478. MTK_CLK_TRGPLL,
  479. MTK_CLK_SGMII_TX_250M,
  480. MTK_CLK_SGMII_RX_250M,
  481. MTK_CLK_SGMII_CDR_REF,
  482. MTK_CLK_SGMII_CDR_FB,
  483. MTK_CLK_SGMII2_TX_250M,
  484. MTK_CLK_SGMII2_RX_250M,
  485. MTK_CLK_SGMII2_CDR_REF,
  486. MTK_CLK_SGMII2_CDR_FB,
  487. MTK_CLK_SGMII_CK,
  488. MTK_CLK_ETH2PLL,
  489. MTK_CLK_MAX
  490. };
  491. #define MT7623_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
  492. BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
  493. BIT(MTK_CLK_TRGPLL))
  494. #define MT7622_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
  495. BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
  496. BIT(MTK_CLK_GP2) | \
  497. BIT(MTK_CLK_SGMII_TX_250M) | \
  498. BIT(MTK_CLK_SGMII_RX_250M) | \
  499. BIT(MTK_CLK_SGMII_CDR_REF) | \
  500. BIT(MTK_CLK_SGMII_CDR_FB) | \
  501. BIT(MTK_CLK_SGMII_CK) | \
  502. BIT(MTK_CLK_ETH2PLL))
  503. #define MT7621_CLKS_BITMAP (0)
  504. #define MT7628_CLKS_BITMAP (0)
  505. #define MT7629_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
  506. BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
  507. BIT(MTK_CLK_GP2) | BIT(MTK_CLK_FE) | \
  508. BIT(MTK_CLK_SGMII_TX_250M) | \
  509. BIT(MTK_CLK_SGMII_RX_250M) | \
  510. BIT(MTK_CLK_SGMII_CDR_REF) | \
  511. BIT(MTK_CLK_SGMII_CDR_FB) | \
  512. BIT(MTK_CLK_SGMII2_TX_250M) | \
  513. BIT(MTK_CLK_SGMII2_RX_250M) | \
  514. BIT(MTK_CLK_SGMII2_CDR_REF) | \
  515. BIT(MTK_CLK_SGMII2_CDR_FB) | \
  516. BIT(MTK_CLK_SGMII_CK) | \
  517. BIT(MTK_CLK_ETH2PLL) | BIT(MTK_CLK_SGMIITOP))
  518. enum mtk_dev_state {
  519. MTK_HW_INIT,
  520. MTK_RESETTING
  521. };
  522. /* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at
  523. * by the TX descriptor s
  524. * @skb: The SKB pointer of the packet being sent
  525. * @dma_addr0: The base addr of the first segment
  526. * @dma_len0: The length of the first segment
  527. * @dma_addr1: The base addr of the second segment
  528. * @dma_len1: The length of the second segment
  529. */
  530. struct mtk_tx_buf {
  531. struct sk_buff *skb;
  532. u32 flags;
  533. DEFINE_DMA_UNMAP_ADDR(dma_addr0);
  534. DEFINE_DMA_UNMAP_LEN(dma_len0);
  535. DEFINE_DMA_UNMAP_ADDR(dma_addr1);
  536. DEFINE_DMA_UNMAP_LEN(dma_len1);
  537. };
  538. /* struct mtk_tx_ring - This struct holds info describing a TX ring
  539. * @dma: The descriptor ring
  540. * @buf: The memory pointed at by the ring
  541. * @phys: The physical addr of tx_buf
  542. * @next_free: Pointer to the next free descriptor
  543. * @last_free: Pointer to the last free descriptor
  544. * @thresh: The threshold of minimum amount of free descriptors
  545. * @free_count: QDMA uses a linked list. Track how many free descriptors
  546. * are present
  547. */
  548. struct mtk_tx_ring {
  549. struct mtk_tx_dma *dma;
  550. struct mtk_tx_buf *buf;
  551. dma_addr_t phys;
  552. struct mtk_tx_dma *next_free;
  553. struct mtk_tx_dma *last_free;
  554. u16 thresh;
  555. atomic_t free_count;
  556. int dma_size;
  557. struct mtk_tx_dma *dma_pdma; /* For MT7628/88 PDMA handling */
  558. dma_addr_t phys_pdma;
  559. int cpu_idx;
  560. };
  561. /* PDMA rx ring mode */
  562. enum mtk_rx_flags {
  563. MTK_RX_FLAGS_NORMAL = 0,
  564. MTK_RX_FLAGS_HWLRO,
  565. MTK_RX_FLAGS_QDMA,
  566. };
  567. /* struct mtk_rx_ring - This struct holds info describing a RX ring
  568. * @dma: The descriptor ring
  569. * @data: The memory pointed at by the ring
  570. * @phys: The physical addr of rx_buf
  571. * @frag_size: How big can each fragment be
  572. * @buf_size: The size of each packet buffer
  573. * @calc_idx: The current head of ring
  574. */
  575. struct mtk_rx_ring {
  576. struct mtk_rx_dma *dma;
  577. u8 **data;
  578. dma_addr_t phys;
  579. u16 frag_size;
  580. u16 buf_size;
  581. u16 dma_size;
  582. bool calc_idx_update;
  583. u16 calc_idx;
  584. u32 crx_idx_reg;
  585. };
  586. enum mkt_eth_capabilities {
  587. MTK_RGMII_BIT = 0,
  588. MTK_TRGMII_BIT,
  589. MTK_SGMII_BIT,
  590. MTK_ESW_BIT,
  591. MTK_GEPHY_BIT,
  592. MTK_MUX_BIT,
  593. MTK_INFRA_BIT,
  594. MTK_SHARED_SGMII_BIT,
  595. MTK_HWLRO_BIT,
  596. MTK_SHARED_INT_BIT,
  597. MTK_TRGMII_MT7621_CLK_BIT,
  598. MTK_QDMA_BIT,
  599. MTK_SOC_MT7628_BIT,
  600. /* MUX BITS*/
  601. MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
  602. MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
  603. MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
  604. MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
  605. MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
  606. /* PATH BITS */
  607. MTK_ETH_PATH_GMAC1_RGMII_BIT,
  608. MTK_ETH_PATH_GMAC1_TRGMII_BIT,
  609. MTK_ETH_PATH_GMAC1_SGMII_BIT,
  610. MTK_ETH_PATH_GMAC2_RGMII_BIT,
  611. MTK_ETH_PATH_GMAC2_SGMII_BIT,
  612. MTK_ETH_PATH_GMAC2_GEPHY_BIT,
  613. MTK_ETH_PATH_GDM1_ESW_BIT,
  614. };
  615. /* Supported hardware group on SoCs */
  616. #define MTK_RGMII BIT(MTK_RGMII_BIT)
  617. #define MTK_TRGMII BIT(MTK_TRGMII_BIT)
  618. #define MTK_SGMII BIT(MTK_SGMII_BIT)
  619. #define MTK_ESW BIT(MTK_ESW_BIT)
  620. #define MTK_GEPHY BIT(MTK_GEPHY_BIT)
  621. #define MTK_MUX BIT(MTK_MUX_BIT)
  622. #define MTK_INFRA BIT(MTK_INFRA_BIT)
  623. #define MTK_SHARED_SGMII BIT(MTK_SHARED_SGMII_BIT)
  624. #define MTK_HWLRO BIT(MTK_HWLRO_BIT)
  625. #define MTK_SHARED_INT BIT(MTK_SHARED_INT_BIT)
  626. #define MTK_TRGMII_MT7621_CLK BIT(MTK_TRGMII_MT7621_CLK_BIT)
  627. #define MTK_QDMA BIT(MTK_QDMA_BIT)
  628. #define MTK_SOC_MT7628 BIT(MTK_SOC_MT7628_BIT)
  629. #define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \
  630. BIT(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
  631. #define MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY \
  632. BIT(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
  633. #define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \
  634. BIT(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
  635. #define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
  636. BIT(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
  637. #define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \
  638. BIT(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
  639. /* Supported path present on SoCs */
  640. #define MTK_ETH_PATH_GMAC1_RGMII BIT(MTK_ETH_PATH_GMAC1_RGMII_BIT)
  641. #define MTK_ETH_PATH_GMAC1_TRGMII BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
  642. #define MTK_ETH_PATH_GMAC1_SGMII BIT(MTK_ETH_PATH_GMAC1_SGMII_BIT)
  643. #define MTK_ETH_PATH_GMAC2_RGMII BIT(MTK_ETH_PATH_GMAC2_RGMII_BIT)
  644. #define MTK_ETH_PATH_GMAC2_SGMII BIT(MTK_ETH_PATH_GMAC2_SGMII_BIT)
  645. #define MTK_ETH_PATH_GMAC2_GEPHY BIT(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
  646. #define MTK_ETH_PATH_GDM1_ESW BIT(MTK_ETH_PATH_GDM1_ESW_BIT)
  647. #define MTK_GMAC1_RGMII (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
  648. #define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
  649. #define MTK_GMAC1_SGMII (MTK_ETH_PATH_GMAC1_SGMII | MTK_SGMII)
  650. #define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
  651. #define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
  652. #define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
  653. #define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
  654. /* MUXes present on SoCs */
  655. /* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
  656. #define MTK_MUX_GDM1_TO_GMAC1_ESW (MTK_ETH_MUX_GDM1_TO_GMAC1_ESW | MTK_MUX)
  657. /* 0: GMAC2 -> GEPHY, 1: GMAC0 -> GePHY */
  658. #define MTK_MUX_GMAC2_GMAC0_TO_GEPHY \
  659. (MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY | MTK_MUX | MTK_INFRA)
  660. /* 0: U3 -> QPHY, 1: GMAC2 -> QPHY */
  661. #define MTK_MUX_U3_GMAC2_TO_QPHY \
  662. (MTK_ETH_MUX_U3_GMAC2_TO_QPHY | MTK_MUX | MTK_INFRA)
  663. /* 2: GMAC1 -> SGMII, 3: GMAC2 -> SGMII */
  664. #define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
  665. (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
  666. MTK_SHARED_SGMII)
  667. /* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
  668. #define MTK_MUX_GMAC12_TO_GEPHY_SGMII \
  669. (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
  670. #define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
  671. #define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
  672. MTK_GMAC2_RGMII | MTK_SHARED_INT | \
  673. MTK_TRGMII_MT7621_CLK | MTK_QDMA)
  674. #define MT7622_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_SGMII | MTK_GMAC2_RGMII | \
  675. MTK_GMAC2_SGMII | MTK_GDM1_ESW | \
  676. MTK_MUX_GDM1_TO_GMAC1_ESW | \
  677. MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_QDMA)
  678. #define MT7623_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | MTK_GMAC2_RGMII | \
  679. MTK_QDMA)
  680. #define MT7628_CAPS (MTK_SHARED_INT | MTK_SOC_MT7628)
  681. #define MT7629_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
  682. MTK_GDM1_ESW | MTK_MUX_GDM1_TO_GMAC1_ESW | \
  683. MTK_MUX_GMAC2_GMAC0_TO_GEPHY | \
  684. MTK_MUX_U3_GMAC2_TO_QPHY | \
  685. MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA)
  686. /* struct mtk_eth_data - This is the structure holding all differences
  687. * among various plaforms
  688. * @ana_rgc3: The offset for register ANA_RGC3 related to
  689. * sgmiisys syscon
  690. * @caps Flags shown the extra capability for the SoC
  691. * @hw_features Flags shown HW features
  692. * @required_clks Flags shown the bitmap for required clocks on
  693. * the target SoC
  694. * @required_pctl A bool value to show whether the SoC requires
  695. * the extra setup for those pins used by GMAC.
  696. */
  697. struct mtk_soc_data {
  698. u32 ana_rgc3;
  699. u32 caps;
  700. u32 required_clks;
  701. bool required_pctl;
  702. netdev_features_t hw_features;
  703. };
  704. /* currently no SoC has more than 2 macs */
  705. #define MTK_MAX_DEVS 2
  706. #define MTK_SGMII_PHYSPEED_AN BIT(31)
  707. #define MTK_SGMII_PHYSPEED_MASK GENMASK(2, 0)
  708. #define MTK_SGMII_PHYSPEED_1000 BIT(0)
  709. #define MTK_SGMII_PHYSPEED_2500 BIT(1)
  710. #define MTK_HAS_FLAGS(flags, _x) (((flags) & (_x)) == (_x))
  711. /* struct mtk_sgmii - This is the structure holding sgmii regmap and its
  712. * characteristics
  713. * @regmap: The register map pointing at the range used to setup
  714. * SGMII modes
  715. * @flags: The enum refers to which mode the sgmii wants to run on
  716. * @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap
  717. */
  718. struct mtk_sgmii {
  719. struct regmap *regmap[MTK_MAX_DEVS];
  720. u32 flags[MTK_MAX_DEVS];
  721. u32 ana_rgc3;
  722. };
  723. /* struct mtk_eth - This is the main datasructure for holding the state
  724. * of the driver
  725. * @dev: The device pointer
  726. * @base: The mapped register i/o base
  727. * @page_lock: Make sure that register operations are atomic
  728. * @tx_irq__lock: Make sure that IRQ register operations are atomic
  729. * @rx_irq__lock: Make sure that IRQ register operations are atomic
  730. * @dummy_dev: we run 2 netdevs on 1 physical DMA ring and need a
  731. * dummy for NAPI to work
  732. * @netdev: The netdev instances
  733. * @mac: Each netdev is linked to a physical MAC
  734. * @irq: The IRQ that we are using
  735. * @msg_enable: Ethtool msg level
  736. * @ethsys: The register map pointing at the range used to setup
  737. * MII modes
  738. * @infra: The register map pointing at the range used to setup
  739. * SGMII and GePHY path
  740. * @pctl: The register map pointing at the range used to setup
  741. * GMAC port drive/slew values
  742. * @dma_refcnt: track how many netdevs are using the DMA engine
  743. * @tx_ring: Pointer to the memory holding info about the TX ring
  744. * @rx_ring: Pointer to the memory holding info about the RX ring
  745. * @rx_ring_qdma: Pointer to the memory holding info about the QDMA RX ring
  746. * @tx_napi: The TX NAPI struct
  747. * @rx_napi: The RX NAPI struct
  748. * @scratch_ring: Newer SoCs need memory for a second HW managed TX ring
  749. * @phy_scratch_ring: physical address of scratch_ring
  750. * @scratch_head: The scratch memory that scratch_ring points to.
  751. * @clks: clock array for all clocks required
  752. * @mii_bus: If there is a bus we need to create an instance for it
  753. * @pending_work: The workqueue used to reset the dma ring
  754. * @state: Initialization and runtime state of the device
  755. * @soc: Holding specific data among vaious SoCs
  756. */
  757. struct mtk_eth {
  758. struct device *dev;
  759. void __iomem *base;
  760. spinlock_t page_lock;
  761. spinlock_t tx_irq_lock;
  762. spinlock_t rx_irq_lock;
  763. struct net_device dummy_dev;
  764. struct net_device *netdev[MTK_MAX_DEVS];
  765. struct mtk_mac *mac[MTK_MAX_DEVS];
  766. int irq[3];
  767. u32 msg_enable;
  768. unsigned long sysclk;
  769. struct regmap *ethsys;
  770. struct regmap *infra;
  771. struct mtk_sgmii *sgmii;
  772. struct regmap *pctl;
  773. bool hwlro;
  774. refcount_t dma_refcnt;
  775. struct mtk_tx_ring tx_ring;
  776. struct mtk_rx_ring rx_ring[MTK_MAX_RX_RING_NUM];
  777. struct mtk_rx_ring rx_ring_qdma;
  778. struct napi_struct tx_napi;
  779. struct napi_struct rx_napi;
  780. struct mtk_tx_dma *scratch_ring;
  781. dma_addr_t phy_scratch_ring;
  782. void *scratch_head;
  783. struct clk *clks[MTK_CLK_MAX];
  784. struct mii_bus *mii_bus;
  785. struct work_struct pending_work;
  786. unsigned long state;
  787. const struct mtk_soc_data *soc;
  788. u32 tx_int_mask_reg;
  789. u32 tx_int_status_reg;
  790. u32 rx_dma_l4_valid;
  791. int ip_align;
  792. };
  793. /* struct mtk_mac - the structure that holds the info about the MACs of the
  794. * SoC
  795. * @id: The number of the MAC
  796. * @interface: Interface mode kept for detecting change in hw settings
  797. * @of_node: Our devicetree node
  798. * @hw: Backpointer to our main datastruture
  799. * @hw_stats: Packet statistics counter
  800. */
  801. struct mtk_mac {
  802. int id;
  803. phy_interface_t interface;
  804. unsigned int mode;
  805. int speed;
  806. struct device_node *of_node;
  807. struct phylink *phylink;
  808. struct phylink_config phylink_config;
  809. struct mtk_eth *hw;
  810. struct mtk_hw_stats *hw_stats;
  811. __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT];
  812. int hwlro_ip_cnt;
  813. };
  814. /* the struct describing the SoC. these are declared in the soc_xyz.c files */
  815. extern const struct of_device_id of_mtk_match[];
  816. /* read the hardware status register */
  817. void mtk_stats_update_mac(struct mtk_mac *mac);
  818. void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
  819. u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
  820. int mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *np,
  821. u32 ana_rgc3);
  822. int mtk_sgmii_setup_mode_an(struct mtk_sgmii *ss, int id);
  823. int mtk_sgmii_setup_mode_force(struct mtk_sgmii *ss, int id,
  824. const struct phylink_link_state *state);
  825. void mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id);
  826. int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
  827. int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
  828. int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
  829. #endif /* MTK_ETH_H */