net: ethernet: mtk_eth_soc: set MDIO bus clock frequency
[platform/kernel/linux-rpi.git] / drivers / net / ethernet / mediatek / mtk_eth_soc.h
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
9 #ifndef MTK_ETH_H
10 #define MTK_ETH_H
11
12 #include <linux/dma-mapping.h>
13 #include <linux/netdevice.h>
14 #include <linux/of_net.h>
15 #include <linux/u64_stats_sync.h>
16 #include <linux/refcount.h>
17 #include <linux/phylink.h>
18 #include <linux/rhashtable.h>
19 #include <linux/dim.h>
20 #include <linux/bitfield.h>
21 #include <net/page_pool.h>
22 #include <linux/bpf_trace.h>
23 #include "mtk_ppe.h"
24
25 #define MTK_MAX_DSA_PORTS       7
26 #define MTK_DSA_PORT_MASK       GENMASK(2, 0)
27
28 #define MTK_QDMA_NUM_QUEUES     16
29 #define MTK_QDMA_PAGE_SIZE      2048
30 #define MTK_MAX_RX_LENGTH       1536
31 #define MTK_MAX_RX_LENGTH_2K    2048
32 #define MTK_TX_DMA_BUF_LEN      0x3fff
33 #define MTK_TX_DMA_BUF_LEN_V2   0xffff
34 #define MTK_QDMA_RING_SIZE      2048
35 #define MTK_DMA_SIZE            512
36 #define MTK_MAC_COUNT           2
37 #define MTK_RX_ETH_HLEN         (ETH_HLEN + ETH_FCS_LEN)
38 #define MTK_RX_HLEN             (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN)
39 #define MTK_DMA_DUMMY_DESC      0xffffffff
40 #define MTK_DEFAULT_MSG_ENABLE  (NETIF_MSG_DRV | \
41                                  NETIF_MSG_PROBE | \
42                                  NETIF_MSG_LINK | \
43                                  NETIF_MSG_TIMER | \
44                                  NETIF_MSG_IFDOWN | \
45                                  NETIF_MSG_IFUP | \
46                                  NETIF_MSG_RX_ERR | \
47                                  NETIF_MSG_TX_ERR)
48 #define MTK_HW_FEATURES         (NETIF_F_IP_CSUM | \
49                                  NETIF_F_RXCSUM | \
50                                  NETIF_F_HW_VLAN_CTAG_TX | \
51                                  NETIF_F_HW_VLAN_CTAG_RX | \
52                                  NETIF_F_SG | NETIF_F_TSO | \
53                                  NETIF_F_TSO6 | \
54                                  NETIF_F_IPV6_CSUM |\
55                                  NETIF_F_HW_TC)
56 #define MTK_HW_FEATURES_MT7628  (NETIF_F_SG | NETIF_F_RXCSUM)
57 #define NEXT_DESP_IDX(X, Y)     (((X) + 1) & ((Y) - 1))
58
59 #define MTK_PP_HEADROOM         XDP_PACKET_HEADROOM
60 #define MTK_PP_PAD              (MTK_PP_HEADROOM + \
61                                  SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
62 #define MTK_PP_MAX_BUF_SIZE     (PAGE_SIZE - MTK_PP_PAD)
63
64 #define MTK_QRX_OFFSET          0x10
65
66 #define MTK_MAX_RX_RING_NUM     4
67 #define MTK_HW_LRO_DMA_SIZE     8
68
69 #define MTK_MAX_LRO_RX_LENGTH           (4096 * 3)
70 #define MTK_MAX_LRO_IP_CNT              2
71 #define MTK_HW_LRO_TIMER_UNIT           1       /* 20 us */
72 #define MTK_HW_LRO_REFRESH_TIME         50000   /* 1 sec. */
73 #define MTK_HW_LRO_AGG_TIME             10      /* 200us */
74 #define MTK_HW_LRO_AGE_TIME             50      /* 1ms */
75 #define MTK_HW_LRO_MAX_AGG_CNT          64
76 #define MTK_HW_LRO_BW_THRE              3000
77 #define MTK_HW_LRO_REPLACE_DELTA        1000
78 #define MTK_HW_LRO_SDL_REMAIN_ROOM      1522
79
80 /* Frame Engine Global Configuration */
81 #define MTK_FE_GLO_CFG          0x00
82 #define MTK_FE_LINK_DOWN_P3     BIT(11)
83 #define MTK_FE_LINK_DOWN_P4     BIT(12)
84
85 /* Frame Engine Global Reset Register */
86 #define MTK_RST_GL              0x04
87 #define RST_GL_PSE              BIT(0)
88
89 /* Frame Engine Interrupt Status Register */
90 #define MTK_INT_STATUS2         0x08
91 #define MTK_FE_INT_ENABLE       0x0c
92 #define MTK_FE_INT_FQ_EMPTY     BIT(8)
93 #define MTK_FE_INT_TSO_FAIL     BIT(12)
94 #define MTK_FE_INT_TSO_ILLEGAL  BIT(13)
95 #define MTK_FE_INT_TSO_ALIGN    BIT(14)
96 #define MTK_FE_INT_RFIFO_OV     BIT(18)
97 #define MTK_FE_INT_RFIFO_UF     BIT(19)
98 #define MTK_GDM1_AF             BIT(28)
99 #define MTK_GDM2_AF             BIT(29)
100
101 /* PDMA HW LRO Alter Flow Timer Register */
102 #define MTK_PDMA_LRO_ALT_REFRESH_TIMER  0x1c
103
104 /* Frame Engine Interrupt Grouping Register */
105 #define MTK_FE_INT_GRP          0x20
106
107 /* CDMP Ingress Control Register */
108 #define MTK_CDMQ_IG_CTRL        0x1400
109 #define MTK_CDMQ_STAG_EN        BIT(0)
110
111 /* CDMQ Exgress Control Register */
112 #define MTK_CDMQ_EG_CTRL        0x1404
113
114 /* CDMP Ingress Control Register */
115 #define MTK_CDMP_IG_CTRL        0x400
116 #define MTK_CDMP_STAG_EN        BIT(0)
117
118 /* CDMP Exgress Control Register */
119 #define MTK_CDMP_EG_CTRL        0x404
120
121 /* GDM Exgress Control Register */
122 #define MTK_GDMA_FWD_CFG(x)     (0x500 + (x * 0x1000))
123 #define MTK_GDMA_SPECIAL_TAG    BIT(24)
124 #define MTK_GDMA_ICS_EN         BIT(22)
125 #define MTK_GDMA_TCS_EN         BIT(21)
126 #define MTK_GDMA_UCS_EN         BIT(20)
127 #define MTK_GDMA_TO_PDMA        0x0
128 #define MTK_GDMA_DROP_ALL       0x7777
129
130 /* Unicast Filter MAC Address Register - Low */
131 #define MTK_GDMA_MAC_ADRL(x)    (0x508 + (x * 0x1000))
132
133 /* Unicast Filter MAC Address Register - High */
134 #define MTK_GDMA_MAC_ADRH(x)    (0x50C + (x * 0x1000))
135
136 /* FE global misc reg*/
137 #define MTK_FE_GLO_MISC         0x124
138
139 /* PSE Free Queue Flow Control  */
140 #define PSE_FQFC_CFG1           0x100
141 #define PSE_FQFC_CFG2           0x104
142 #define PSE_DROP_CFG            0x108
143 #define PSE_PPE0_DROP           0x110
144
145 /* PSE Input Queue Reservation Register*/
146 #define PSE_IQ_REV(x)           (0x140 + (((x) - 1) << 2))
147
148 /* PSE Output Queue Threshold Register*/
149 #define PSE_OQ_TH(x)            (0x160 + (((x) - 1) << 2))
150
151 /* GDM and CDM Threshold */
152 #define MTK_GDM2_THRES          0x1530
153 #define MTK_CDMW0_THRES         0x164c
154 #define MTK_CDMW1_THRES         0x1650
155 #define MTK_CDME0_THRES         0x1654
156 #define MTK_CDME1_THRES         0x1658
157 #define MTK_CDMM_THRES          0x165c
158
159 /* PDMA HW LRO Control Registers */
160 #define MTK_PDMA_LRO_CTRL_DW0   0x980
161 #define MTK_LRO_EN                      BIT(0)
162 #define MTK_L3_CKS_UPD_EN               BIT(7)
163 #define MTK_L3_CKS_UPD_EN_V2            BIT(19)
164 #define MTK_LRO_ALT_PKT_CNT_MODE        BIT(21)
165 #define MTK_LRO_RING_RELINQUISH_REQ     (0x7 << 26)
166 #define MTK_LRO_RING_RELINQUISH_REQ_V2  (0xf << 24)
167 #define MTK_LRO_RING_RELINQUISH_DONE    (0x7 << 29)
168 #define MTK_LRO_RING_RELINQUISH_DONE_V2 (0xf << 28)
169
170 #define MTK_PDMA_LRO_CTRL_DW1   0x984
171 #define MTK_PDMA_LRO_CTRL_DW2   0x988
172 #define MTK_PDMA_LRO_CTRL_DW3   0x98c
173 #define MTK_ADMA_MODE           BIT(15)
174 #define MTK_LRO_MIN_RXD_SDL     (MTK_HW_LRO_SDL_REMAIN_ROOM << 16)
175
176 #define MTK_RX_DMA_LRO_EN       BIT(8)
177 #define MTK_MULTI_EN            BIT(10)
178 #define MTK_PDMA_SIZE_8DWORDS   (1 << 4)
179
180 /* PDMA Global Configuration Register */
181 #define MTK_PDMA_LRO_SDL        0x3000
182 #define MTK_RX_CFG_SDL_OFFSET   16
183
184 /* PDMA Reset Index Register */
185 #define MTK_PST_DRX_IDX0        BIT(16)
186 #define MTK_PST_DRX_IDX_CFG(x)  (MTK_PST_DRX_IDX0 << (x))
187
188 /* PDMA Delay Interrupt Register */
189 #define MTK_PDMA_DELAY_RX_MASK          GENMASK(15, 0)
190 #define MTK_PDMA_DELAY_RX_EN            BIT(15)
191 #define MTK_PDMA_DELAY_RX_PINT_SHIFT    8
192 #define MTK_PDMA_DELAY_RX_PTIME_SHIFT   0
193
194 #define MTK_PDMA_DELAY_TX_MASK          GENMASK(31, 16)
195 #define MTK_PDMA_DELAY_TX_EN            BIT(31)
196 #define MTK_PDMA_DELAY_TX_PINT_SHIFT    24
197 #define MTK_PDMA_DELAY_TX_PTIME_SHIFT   16
198
199 #define MTK_PDMA_DELAY_PINT_MASK        0x7f
200 #define MTK_PDMA_DELAY_PTIME_MASK       0xff
201
202 /* PDMA HW LRO Alter Flow Delta Register */
203 #define MTK_PDMA_LRO_ALT_SCORE_DELTA    0xa4c
204
205 /* PDMA HW LRO IP Setting Registers */
206 #define MTK_LRO_RX_RING0_DIP_DW0        0xb04
207 #define MTK_LRO_DIP_DW0_CFG(x)          (MTK_LRO_RX_RING0_DIP_DW0 + (x * 0x40))
208 #define MTK_RING_MYIP_VLD               BIT(9)
209
210 /* PDMA HW LRO Ring Control Registers */
211 #define MTK_LRO_RX_RING0_CTRL_DW1       0xb28
212 #define MTK_LRO_RX_RING0_CTRL_DW2       0xb2c
213 #define MTK_LRO_RX_RING0_CTRL_DW3       0xb30
214 #define MTK_LRO_CTRL_DW1_CFG(x)         (MTK_LRO_RX_RING0_CTRL_DW1 + (x * 0x40))
215 #define MTK_LRO_CTRL_DW2_CFG(x)         (MTK_LRO_RX_RING0_CTRL_DW2 + (x * 0x40))
216 #define MTK_LRO_CTRL_DW3_CFG(x)         (MTK_LRO_RX_RING0_CTRL_DW3 + (x * 0x40))
217 #define MTK_RING_AGE_TIME_L             ((MTK_HW_LRO_AGE_TIME & 0x3ff) << 22)
218 #define MTK_RING_AGE_TIME_H             ((MTK_HW_LRO_AGE_TIME >> 10) & 0x3f)
219 #define MTK_RING_AUTO_LERAN_MODE        (3 << 6)
220 #define MTK_RING_VLD                    BIT(8)
221 #define MTK_RING_MAX_AGG_TIME           ((MTK_HW_LRO_AGG_TIME & 0xffff) << 10)
222 #define MTK_RING_MAX_AGG_CNT_L          ((MTK_HW_LRO_MAX_AGG_CNT & 0x3f) << 26)
223 #define MTK_RING_MAX_AGG_CNT_H          ((MTK_HW_LRO_MAX_AGG_CNT >> 6) & 0x3)
224
225 /* QDMA TX Queue Configuration Registers */
226 #define MTK_QTX_OFFSET          0x10
227 #define QDMA_RES_THRES          4
228
229 /* QDMA Tx Queue Scheduler Configuration Registers */
230 #define MTK_QTX_SCH_TX_SEL              BIT(31)
231 #define MTK_QTX_SCH_TX_SEL_V2           GENMASK(31, 30)
232
233 #define MTK_QTX_SCH_LEAKY_BUCKET_EN     BIT(30)
234 #define MTK_QTX_SCH_LEAKY_BUCKET_SIZE   GENMASK(29, 28)
235 #define MTK_QTX_SCH_MIN_RATE_EN         BIT(27)
236 #define MTK_QTX_SCH_MIN_RATE_MAN        GENMASK(26, 20)
237 #define MTK_QTX_SCH_MIN_RATE_EXP        GENMASK(19, 16)
238 #define MTK_QTX_SCH_MAX_RATE_WEIGHT     GENMASK(15, 12)
239 #define MTK_QTX_SCH_MAX_RATE_EN         BIT(11)
240 #define MTK_QTX_SCH_MAX_RATE_MAN        GENMASK(10, 4)
241 #define MTK_QTX_SCH_MAX_RATE_EXP        GENMASK(3, 0)
242
243 /* QDMA TX Scheduler Rate Control Register */
244 #define MTK_QDMA_TX_SCH_MAX_WFQ         BIT(15)
245
246 /* QDMA Global Configuration Register */
247 #define MTK_RX_2B_OFFSET        BIT(31)
248 #define MTK_RX_BT_32DWORDS      (3 << 11)
249 #define MTK_NDP_CO_PRO          BIT(10)
250 #define MTK_TX_WB_DDONE         BIT(6)
251 #define MTK_TX_BT_32DWORDS      (3 << 4)
252 #define MTK_RX_DMA_BUSY         BIT(3)
253 #define MTK_TX_DMA_BUSY         BIT(1)
254 #define MTK_RX_DMA_EN           BIT(2)
255 #define MTK_TX_DMA_EN           BIT(0)
256 #define MTK_DMA_BUSY_TIMEOUT_US 1000000
257
258 /* QDMA V2 Global Configuration Register */
259 #define MTK_CHK_DDONE_EN        BIT(28)
260 #define MTK_DMAD_WR_WDONE       BIT(26)
261 #define MTK_WCOMP_EN            BIT(24)
262 #define MTK_RESV_BUF            (0x40 << 16)
263 #define MTK_MUTLI_CNT           (0x4 << 12)
264 #define MTK_LEAKY_BUCKET_EN     BIT(11)
265
266 /* QDMA Flow Control Register */
267 #define FC_THRES_DROP_MODE      BIT(20)
268 #define FC_THRES_DROP_EN        (7 << 16)
269 #define FC_THRES_MIN            0x4444
270
271 /* QDMA Interrupt Status Register */
272 #define MTK_RX_DONE_DLY         BIT(30)
273 #define MTK_TX_DONE_DLY         BIT(28)
274 #define MTK_RX_DONE_INT3        BIT(19)
275 #define MTK_RX_DONE_INT2        BIT(18)
276 #define MTK_RX_DONE_INT1        BIT(17)
277 #define MTK_RX_DONE_INT0        BIT(16)
278 #define MTK_TX_DONE_INT3        BIT(3)
279 #define MTK_TX_DONE_INT2        BIT(2)
280 #define MTK_TX_DONE_INT1        BIT(1)
281 #define MTK_TX_DONE_INT0        BIT(0)
282 #define MTK_RX_DONE_INT         MTK_RX_DONE_DLY
283 #define MTK_TX_DONE_INT         MTK_TX_DONE_DLY
284
285 #define MTK_RX_DONE_INT_V2      BIT(14)
286
287 #define MTK_CDM_TXFIFO_RDY      BIT(7)
288
289 /* QDMA Interrupt grouping registers */
290 #define MTK_RLS_DONE_INT        BIT(0)
291
292 #define MTK_STAT_OFFSET         0x40
293
294 /* QDMA TX NUM */
295 #define QID_BITS_V2(x)          (((x) & 0x3f) << 16)
296 #define MTK_QDMA_GMAC2_QID      8
297
298 #define MTK_TX_DMA_BUF_SHIFT    8
299
300 /* QDMA V2 descriptor txd6 */
301 #define TX_DMA_INS_VLAN_V2      BIT(16)
302 /* QDMA V2 descriptor txd5 */
303 #define TX_DMA_CHKSUM_V2        (0x7 << 28)
304 #define TX_DMA_TSO_V2           BIT(31)
305
306 /* QDMA V2 descriptor txd4 */
307 #define TX_DMA_FPORT_SHIFT_V2   8
308 #define TX_DMA_FPORT_MASK_V2    0xf
309 #define TX_DMA_SWC_V2           BIT(30)
310
311 /* QDMA descriptor txd4 */
312 #define TX_DMA_CHKSUM           (0x7 << 29)
313 #define TX_DMA_TSO              BIT(28)
314 #define TX_DMA_FPORT_SHIFT      25
315 #define TX_DMA_FPORT_MASK       0x7
316 #define TX_DMA_INS_VLAN         BIT(16)
317
318 /* QDMA descriptor txd3 */
319 #define TX_DMA_OWNER_CPU        BIT(31)
320 #define TX_DMA_LS0              BIT(30)
321 #define TX_DMA_PLEN0(x)         (((x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
322 #define TX_DMA_PLEN1(x)         ((x) & eth->soc->txrx.dma_max_len)
323 #define TX_DMA_SWC              BIT(14)
324 #define TX_DMA_PQID             GENMASK(3, 0)
325
326 /* PDMA on MT7628 */
327 #define TX_DMA_DONE             BIT(31)
328 #define TX_DMA_LS1              BIT(14)
329 #define TX_DMA_DESP2_DEF        (TX_DMA_LS0 | TX_DMA_DONE)
330
331 /* QDMA descriptor rxd2 */
332 #define RX_DMA_DONE             BIT(31)
333 #define RX_DMA_LSO              BIT(30)
334 #define RX_DMA_PREP_PLEN0(x)    (((x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
335 #define RX_DMA_GET_PLEN0(x)     (((x) >> eth->soc->txrx.dma_len_offset) & eth->soc->txrx.dma_max_len)
336 #define RX_DMA_VTAG             BIT(15)
337
338 /* QDMA descriptor rxd3 */
339 #define RX_DMA_VID(x)           ((x) & VLAN_VID_MASK)
340 #define RX_DMA_TCI(x)           ((x) & (VLAN_PRIO_MASK | VLAN_VID_MASK))
341 #define RX_DMA_VPID(x)          (((x) >> 16) & 0xffff)
342
343 /* QDMA descriptor rxd4 */
344 #define MTK_RXD4_FOE_ENTRY      GENMASK(13, 0)
345 #define MTK_RXD4_PPE_CPU_REASON GENMASK(18, 14)
346 #define MTK_RXD4_SRC_PORT       GENMASK(21, 19)
347 #define MTK_RXD4_ALG            GENMASK(31, 22)
348
349 /* QDMA descriptor rxd4 */
350 #define RX_DMA_L4_VALID         BIT(24)
351 #define RX_DMA_L4_VALID_PDMA    BIT(30)         /* when PDMA is used */
352 #define RX_DMA_SPECIAL_TAG      BIT(22)
353
354 /* PDMA descriptor rxd5 */
355 #define MTK_RXD5_FOE_ENTRY      GENMASK(14, 0)
356 #define MTK_RXD5_PPE_CPU_REASON GENMASK(22, 18)
357 #define MTK_RXD5_SRC_PORT       GENMASK(29, 26)
358
359 #define RX_DMA_GET_SPORT(x)     (((x) >> 19) & 0x7)
360 #define RX_DMA_GET_SPORT_V2(x)  (((x) >> 26) & 0xf)
361
362 /* PDMA V2 descriptor rxd3 */
363 #define RX_DMA_VTAG_V2          BIT(0)
364 #define RX_DMA_L4_VALID_V2      BIT(2)
365
366 /* PHY Polling and SMI Master Control registers */
367 #define MTK_PPSC                0x10000
368 #define PPSC_MDC_CFG            GENMASK(29, 24)
369 #define PPSC_MDC_TURBO          BIT(20)
370 #define MDC_MAX_FREQ            25000000
371 #define MDC_MAX_DIVIDER         63
372
373 /* PHY Indirect Access Control registers */
374 #define MTK_PHY_IAC             0x10004
375 #define PHY_IAC_ACCESS          BIT(31)
376 #define PHY_IAC_REG_MASK        GENMASK(29, 25)
377 #define PHY_IAC_REG(x)          FIELD_PREP(PHY_IAC_REG_MASK, (x))
378 #define PHY_IAC_ADDR_MASK       GENMASK(24, 20)
379 #define PHY_IAC_ADDR(x)         FIELD_PREP(PHY_IAC_ADDR_MASK, (x))
380 #define PHY_IAC_CMD_MASK        GENMASK(19, 18)
381 #define PHY_IAC_CMD_C45_ADDR    FIELD_PREP(PHY_IAC_CMD_MASK, 0)
382 #define PHY_IAC_CMD_WRITE       FIELD_PREP(PHY_IAC_CMD_MASK, 1)
383 #define PHY_IAC_CMD_C22_READ    FIELD_PREP(PHY_IAC_CMD_MASK, 2)
384 #define PHY_IAC_CMD_C45_READ    FIELD_PREP(PHY_IAC_CMD_MASK, 3)
385 #define PHY_IAC_START_MASK      GENMASK(17, 16)
386 #define PHY_IAC_START_C45       FIELD_PREP(PHY_IAC_START_MASK, 0)
387 #define PHY_IAC_START_C22       FIELD_PREP(PHY_IAC_START_MASK, 1)
388 #define PHY_IAC_DATA_MASK       GENMASK(15, 0)
389 #define PHY_IAC_DATA(x)         FIELD_PREP(PHY_IAC_DATA_MASK, (x))
390 #define PHY_IAC_TIMEOUT         HZ
391
392 #define MTK_MAC_MISC            0x1000c
393 #define MTK_MUX_TO_ESW          BIT(0)
394
395 /* Mac control registers */
396 #define MTK_MAC_MCR(x)          (0x10100 + (x * 0x100))
397 #define MAC_MCR_MAX_RX_MASK     GENMASK(25, 24)
398 #define MAC_MCR_MAX_RX(_x)      (MAC_MCR_MAX_RX_MASK & ((_x) << 24))
399 #define MAC_MCR_MAX_RX_1518     0x0
400 #define MAC_MCR_MAX_RX_1536     0x1
401 #define MAC_MCR_MAX_RX_1552     0x2
402 #define MAC_MCR_MAX_RX_2048     0x3
403 #define MAC_MCR_IPG_CFG         (BIT(18) | BIT(16))
404 #define MAC_MCR_FORCE_MODE      BIT(15)
405 #define MAC_MCR_TX_EN           BIT(14)
406 #define MAC_MCR_RX_EN           BIT(13)
407 #define MAC_MCR_RX_FIFO_CLR_DIS BIT(12)
408 #define MAC_MCR_BACKOFF_EN      BIT(9)
409 #define MAC_MCR_BACKPR_EN       BIT(8)
410 #define MAC_MCR_FORCE_RX_FC     BIT(5)
411 #define MAC_MCR_FORCE_TX_FC     BIT(4)
412 #define MAC_MCR_SPEED_1000      BIT(3)
413 #define MAC_MCR_SPEED_100       BIT(2)
414 #define MAC_MCR_FORCE_DPX       BIT(1)
415 #define MAC_MCR_FORCE_LINK      BIT(0)
416 #define MAC_MCR_FORCE_LINK_DOWN (MAC_MCR_FORCE_MODE)
417
418 /* Mac status registers */
419 #define MTK_MAC_MSR(x)          (0x10108 + (x * 0x100))
420 #define MAC_MSR_EEE1G           BIT(7)
421 #define MAC_MSR_EEE100M         BIT(6)
422 #define MAC_MSR_RX_FC           BIT(5)
423 #define MAC_MSR_TX_FC           BIT(4)
424 #define MAC_MSR_SPEED_1000      BIT(3)
425 #define MAC_MSR_SPEED_100       BIT(2)
426 #define MAC_MSR_SPEED_MASK      (MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100)
427 #define MAC_MSR_DPX             BIT(1)
428 #define MAC_MSR_LINK            BIT(0)
429
430 /* TRGMII RXC control register */
431 #define TRGMII_RCK_CTRL         0x10300
432 #define DQSI0(x)                ((x << 0) & GENMASK(6, 0))
433 #define DQSI1(x)                ((x << 8) & GENMASK(14, 8))
434 #define RXCTL_DMWTLAT(x)        ((x << 16) & GENMASK(18, 16))
435 #define RXC_RST                 BIT(31)
436 #define RXC_DQSISEL             BIT(30)
437 #define RCK_CTRL_RGMII_1000     (RXC_DQSISEL | RXCTL_DMWTLAT(2) | DQSI1(16))
438 #define RCK_CTRL_RGMII_10_100   RXCTL_DMWTLAT(2)
439
440 #define NUM_TRGMII_CTRL         5
441
442 /* TRGMII RXC control register */
443 #define TRGMII_TCK_CTRL         0x10340
444 #define TXCTL_DMWTLAT(x)        ((x << 16) & GENMASK(18, 16))
445 #define TXC_INV                 BIT(30)
446 #define TCK_CTRL_RGMII_1000     TXCTL_DMWTLAT(2)
447 #define TCK_CTRL_RGMII_10_100   (TXC_INV | TXCTL_DMWTLAT(2))
448
449 /* TRGMII TX Drive Strength */
450 #define TRGMII_TD_ODT(i)        (0x10354 + 8 * (i))
451 #define  TD_DM_DRVP(x)          ((x) & 0xf)
452 #define  TD_DM_DRVN(x)          (((x) & 0xf) << 4)
453
454 /* TRGMII Interface mode register */
455 #define INTF_MODE               0x10390
456 #define TRGMII_INTF_DIS         BIT(0)
457 #define TRGMII_MODE             BIT(1)
458 #define TRGMII_CENTRAL_ALIGNED  BIT(2)
459 #define INTF_MODE_RGMII_1000    (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
460 #define INTF_MODE_RGMII_10_100  0
461
462 /* GPIO port control registers for GMAC 2*/
463 #define GPIO_OD33_CTRL8         0x4c0
464 #define GPIO_BIAS_CTRL          0xed0
465 #define GPIO_DRV_SEL10          0xf00
466
467 /* ethernet subsystem chip id register */
468 #define ETHSYS_CHIPID0_3        0x0
469 #define ETHSYS_CHIPID4_7        0x4
470 #define MT7623_ETH              7623
471 #define MT7622_ETH              7622
472 #define MT7621_ETH              7621
473
474 /* ethernet system control register */
475 #define ETHSYS_SYSCFG           0x10
476 #define SYSCFG_DRAM_TYPE_DDR2   BIT(4)
477
478 /* ethernet subsystem config register */
479 #define ETHSYS_SYSCFG0          0x14
480 #define SYSCFG0_GE_MASK         0x3
481 #define SYSCFG0_GE_MODE(x, y)   (x << (12 + (y * 2)))
482 #define SYSCFG0_SGMII_MASK     GENMASK(9, 8)
483 #define SYSCFG0_SGMII_GMAC1    ((2 << 8) & SYSCFG0_SGMII_MASK)
484 #define SYSCFG0_SGMII_GMAC2    ((3 << 8) & SYSCFG0_SGMII_MASK)
485 #define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
486 #define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
487
488
489 /* ethernet subsystem clock register */
490 #define ETHSYS_CLKCFG0          0x2c
491 #define ETHSYS_TRGMII_CLK_SEL362_5      BIT(11)
492 #define ETHSYS_TRGMII_MT7621_MASK       (BIT(5) | BIT(6))
493 #define ETHSYS_TRGMII_MT7621_APLL       BIT(6)
494 #define ETHSYS_TRGMII_MT7621_DDR_PLL    BIT(5)
495
496 /* ethernet reset control register */
497 #define ETHSYS_RSTCTRL                  0x34
498 #define RSTCTRL_FE                      BIT(6)
499 #define RSTCTRL_PPE0                    BIT(31)
500 #define RSTCTRL_PPE0_V2                 BIT(30)
501 #define RSTCTRL_PPE1                    BIT(31)
502 #define RSTCTRL_ETH                     BIT(23)
503
504 /* ethernet reset check idle register */
505 #define ETHSYS_FE_RST_CHK_IDLE_EN       0x28
506
507 /* ethernet dma channel agent map */
508 #define ETHSYS_DMA_AG_MAP       0x408
509 #define ETHSYS_DMA_AG_MAP_PDMA  BIT(0)
510 #define ETHSYS_DMA_AG_MAP_QDMA  BIT(1)
511 #define ETHSYS_DMA_AG_MAP_PPE   BIT(2)
512
513 /* SGMII subsystem config registers */
514 /* BMCR (low 16) BMSR (high 16) */
515 #define SGMSYS_PCS_CONTROL_1    0x0
516 #define SGMII_BMCR              GENMASK(15, 0)
517 #define SGMII_BMSR              GENMASK(31, 16)
518 #define SGMII_AN_RESTART        BIT(9)
519 #define SGMII_ISOLATE           BIT(10)
520 #define SGMII_AN_ENABLE         BIT(12)
521 #define SGMII_LINK_STATYS       BIT(18)
522 #define SGMII_AN_ABILITY        BIT(19)
523 #define SGMII_AN_COMPLETE       BIT(21)
524 #define SGMII_PCS_FAULT         BIT(23)
525 #define SGMII_AN_EXPANSION_CLR  BIT(30)
526
527 #define SGMSYS_PCS_ADVERTISE    0x8
528 #define SGMII_ADVERTISE         GENMASK(15, 0)
529 #define SGMII_LPA               GENMASK(31, 16)
530
531 /* Register to programmable link timer, the unit in 2 * 8ns */
532 #define SGMSYS_PCS_LINK_TIMER   0x18
533 #define SGMII_LINK_TIMER_MASK   GENMASK(19, 0)
534 #define SGMII_LINK_TIMER_DEFAULT        (0x186a0 & SGMII_LINK_TIMER_MASK)
535
536 /* Register to control remote fault */
537 #define SGMSYS_SGMII_MODE               0x20
538 #define SGMII_IF_MODE_SGMII             BIT(0)
539 #define SGMII_SPEED_DUPLEX_AN           BIT(1)
540 #define SGMII_SPEED_MASK                GENMASK(3, 2)
541 #define SGMII_SPEED_10                  FIELD_PREP(SGMII_SPEED_MASK, 0)
542 #define SGMII_SPEED_100                 FIELD_PREP(SGMII_SPEED_MASK, 1)
543 #define SGMII_SPEED_1000                FIELD_PREP(SGMII_SPEED_MASK, 2)
544 #define SGMII_DUPLEX_HALF               BIT(4)
545 #define SGMII_IF_MODE_BIT5              BIT(5)
546 #define SGMII_REMOTE_FAULT_DIS          BIT(8)
547 #define SGMII_CODE_SYNC_SET_VAL         BIT(9)
548 #define SGMII_CODE_SYNC_SET_EN          BIT(10)
549 #define SGMII_SEND_AN_ERROR_EN          BIT(11)
550 #define SGMII_IF_MODE_MASK              GENMASK(5, 1)
551
552 /* Register to reset SGMII design */
553 #define SGMII_RESERVED_0        0x34
554 #define SGMII_SW_RESET          BIT(0)
555
556 /* Register to set SGMII speed, ANA RG_ Control Signals III*/
557 #define SGMSYS_ANA_RG_CS3       0x2028
558 #define RG_PHY_SPEED_MASK       (BIT(2) | BIT(3))
559 #define RG_PHY_SPEED_1_25G      0x0
560 #define RG_PHY_SPEED_3_125G     BIT(2)
561
562 /* Register to power up QPHY */
563 #define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
564 #define SGMII_PHYA_PWD          BIT(4)
565
566 /* Register to QPHY wrapper control */
567 #define SGMSYS_QPHY_WRAP_CTRL   0xec
568 #define SGMII_PN_SWAP_MASK      GENMASK(1, 0)
569 #define SGMII_PN_SWAP_TX_RX     (BIT(0) | BIT(1))
570 #define MTK_SGMII_FLAG_PN_SWAP  BIT(0)
571
572 /* Infrasys subsystem config registers */
573 #define INFRA_MISC2            0x70c
574 #define CO_QPHY_SEL            BIT(0)
575 #define GEPHY_MAC_SEL          BIT(1)
576
577 /* Top misc registers */
578 #define USB_PHY_SWITCH_REG      0x218
579 #define QPHY_SEL_MASK           GENMASK(1, 0)
580 #define SGMII_QPHY_SEL          0x2
581
582 /* MT7628/88 specific stuff */
583 #define MT7628_PDMA_OFFSET      0x0800
584 #define MT7628_SDM_OFFSET       0x0c00
585
586 #define MT7628_TX_BASE_PTR0     (MT7628_PDMA_OFFSET + 0x00)
587 #define MT7628_TX_MAX_CNT0      (MT7628_PDMA_OFFSET + 0x04)
588 #define MT7628_TX_CTX_IDX0      (MT7628_PDMA_OFFSET + 0x08)
589 #define MT7628_TX_DTX_IDX0      (MT7628_PDMA_OFFSET + 0x0c)
590 #define MT7628_PST_DTX_IDX0     BIT(0)
591
592 #define MT7628_SDM_MAC_ADRL     (MT7628_SDM_OFFSET + 0x0c)
593 #define MT7628_SDM_MAC_ADRH     (MT7628_SDM_OFFSET + 0x10)
594
595 /* Counter / stat register */
596 #define MT7628_SDM_TPCNT        (MT7628_SDM_OFFSET + 0x100)
597 #define MT7628_SDM_TBCNT        (MT7628_SDM_OFFSET + 0x104)
598 #define MT7628_SDM_RPCNT        (MT7628_SDM_OFFSET + 0x108)
599 #define MT7628_SDM_RBCNT        (MT7628_SDM_OFFSET + 0x10c)
600 #define MT7628_SDM_CS_ERR       (MT7628_SDM_OFFSET + 0x110)
601
602 #define MTK_FE_CDM1_FSM         0x220
603 #define MTK_FE_CDM2_FSM         0x224
604 #define MTK_FE_CDM3_FSM         0x238
605 #define MTK_FE_CDM4_FSM         0x298
606 #define MTK_FE_CDM5_FSM         0x318
607 #define MTK_FE_CDM6_FSM         0x328
608 #define MTK_FE_GDM1_FSM         0x228
609 #define MTK_FE_GDM2_FSM         0x22C
610
611 #define MTK_MAC_FSM(x)          (0x1010C + ((x) * 0x100))
612
613 struct mtk_rx_dma {
614         unsigned int rxd1;
615         unsigned int rxd2;
616         unsigned int rxd3;
617         unsigned int rxd4;
618 } __packed __aligned(4);
619
620 struct mtk_rx_dma_v2 {
621         unsigned int rxd1;
622         unsigned int rxd2;
623         unsigned int rxd3;
624         unsigned int rxd4;
625         unsigned int rxd5;
626         unsigned int rxd6;
627         unsigned int rxd7;
628         unsigned int rxd8;
629 } __packed __aligned(4);
630
631 struct mtk_tx_dma {
632         unsigned int txd1;
633         unsigned int txd2;
634         unsigned int txd3;
635         unsigned int txd4;
636 } __packed __aligned(4);
637
638 struct mtk_tx_dma_v2 {
639         unsigned int txd1;
640         unsigned int txd2;
641         unsigned int txd3;
642         unsigned int txd4;
643         unsigned int txd5;
644         unsigned int txd6;
645         unsigned int txd7;
646         unsigned int txd8;
647 } __packed __aligned(4);
648
649 struct mtk_eth;
650 struct mtk_mac;
651
652 struct mtk_xdp_stats {
653         u64 rx_xdp_redirect;
654         u64 rx_xdp_pass;
655         u64 rx_xdp_drop;
656         u64 rx_xdp_tx;
657         u64 rx_xdp_tx_errors;
658         u64 tx_xdp_xmit;
659         u64 tx_xdp_xmit_errors;
660 };
661
662 /* struct mtk_hw_stats - the structure that holds the traffic statistics.
663  * @stats_lock:         make sure that stats operations are atomic
664  * @reg_offset:         the status register offset of the SoC
665  * @syncp:              the refcount
666  *
667  * All of the supported SoCs have hardware counters for traffic statistics.
668  * Whenever the status IRQ triggers we can read the latest stats from these
669  * counters and store them in this struct.
670  */
671 struct mtk_hw_stats {
672         u64 tx_bytes;
673         u64 tx_packets;
674         u64 tx_skip;
675         u64 tx_collisions;
676         u64 rx_bytes;
677         u64 rx_packets;
678         u64 rx_overflow;
679         u64 rx_fcs_errors;
680         u64 rx_short_errors;
681         u64 rx_long_errors;
682         u64 rx_checksum_errors;
683         u64 rx_flow_control_packets;
684
685         struct mtk_xdp_stats    xdp_stats;
686
687         spinlock_t              stats_lock;
688         u32                     reg_offset;
689         struct u64_stats_sync   syncp;
690 };
691
692 enum mtk_tx_flags {
693         /* PDMA descriptor can point at 1-2 segments. This enum allows us to
694          * track how memory was allocated so that it can be freed properly.
695          */
696         MTK_TX_FLAGS_SINGLE0    = 0x01,
697         MTK_TX_FLAGS_PAGE0      = 0x02,
698
699         /* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted
700          * SKB out instead of looking up through hardware TX descriptor.
701          */
702         MTK_TX_FLAGS_FPORT0     = 0x04,
703         MTK_TX_FLAGS_FPORT1     = 0x08,
704 };
705
706 /* This enum allows us to identify how the clock is defined on the array of the
707  * clock in the order
708  */
709 enum mtk_clks_map {
710         MTK_CLK_ETHIF,
711         MTK_CLK_SGMIITOP,
712         MTK_CLK_ESW,
713         MTK_CLK_GP0,
714         MTK_CLK_GP1,
715         MTK_CLK_GP2,
716         MTK_CLK_FE,
717         MTK_CLK_TRGPLL,
718         MTK_CLK_SGMII_TX_250M,
719         MTK_CLK_SGMII_RX_250M,
720         MTK_CLK_SGMII_CDR_REF,
721         MTK_CLK_SGMII_CDR_FB,
722         MTK_CLK_SGMII2_TX_250M,
723         MTK_CLK_SGMII2_RX_250M,
724         MTK_CLK_SGMII2_CDR_REF,
725         MTK_CLK_SGMII2_CDR_FB,
726         MTK_CLK_SGMII_CK,
727         MTK_CLK_ETH2PLL,
728         MTK_CLK_WOCPU0,
729         MTK_CLK_WOCPU1,
730         MTK_CLK_NETSYS0,
731         MTK_CLK_NETSYS1,
732         MTK_CLK_MAX
733 };
734
735 #define MT7623_CLKS_BITMAP      (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) |  \
736                                  BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
737                                  BIT(MTK_CLK_TRGPLL))
738 #define MT7622_CLKS_BITMAP      (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) |  \
739                                  BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
740                                  BIT(MTK_CLK_GP2) | \
741                                  BIT(MTK_CLK_SGMII_TX_250M) | \
742                                  BIT(MTK_CLK_SGMII_RX_250M) | \
743                                  BIT(MTK_CLK_SGMII_CDR_REF) | \
744                                  BIT(MTK_CLK_SGMII_CDR_FB) | \
745                                  BIT(MTK_CLK_SGMII_CK) | \
746                                  BIT(MTK_CLK_ETH2PLL))
747 #define MT7621_CLKS_BITMAP      (0)
748 #define MT7628_CLKS_BITMAP      (0)
749 #define MT7629_CLKS_BITMAP      (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) |  \
750                                  BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
751                                  BIT(MTK_CLK_GP2) | BIT(MTK_CLK_FE) | \
752                                  BIT(MTK_CLK_SGMII_TX_250M) | \
753                                  BIT(MTK_CLK_SGMII_RX_250M) | \
754                                  BIT(MTK_CLK_SGMII_CDR_REF) | \
755                                  BIT(MTK_CLK_SGMII_CDR_FB) | \
756                                  BIT(MTK_CLK_SGMII2_TX_250M) | \
757                                  BIT(MTK_CLK_SGMII2_RX_250M) | \
758                                  BIT(MTK_CLK_SGMII2_CDR_REF) | \
759                                  BIT(MTK_CLK_SGMII2_CDR_FB) | \
760                                  BIT(MTK_CLK_SGMII_CK) | \
761                                  BIT(MTK_CLK_ETH2PLL) | BIT(MTK_CLK_SGMIITOP))
762 #define MT7981_CLKS_BITMAP      (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
763                                  BIT(MTK_CLK_WOCPU0) | \
764                                  BIT(MTK_CLK_SGMII_TX_250M) | \
765                                  BIT(MTK_CLK_SGMII_RX_250M) | \
766                                  BIT(MTK_CLK_SGMII_CDR_REF) | \
767                                  BIT(MTK_CLK_SGMII_CDR_FB) | \
768                                  BIT(MTK_CLK_SGMII2_TX_250M) | \
769                                  BIT(MTK_CLK_SGMII2_RX_250M) | \
770                                  BIT(MTK_CLK_SGMII2_CDR_REF) | \
771                                  BIT(MTK_CLK_SGMII2_CDR_FB) | \
772                                  BIT(MTK_CLK_SGMII_CK))
773 #define MT7986_CLKS_BITMAP      (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
774                                  BIT(MTK_CLK_WOCPU1) | BIT(MTK_CLK_WOCPU0) | \
775                                  BIT(MTK_CLK_SGMII_TX_250M) | \
776                                  BIT(MTK_CLK_SGMII_RX_250M) | \
777                                  BIT(MTK_CLK_SGMII_CDR_REF) | \
778                                  BIT(MTK_CLK_SGMII_CDR_FB) | \
779                                  BIT(MTK_CLK_SGMII2_TX_250M) | \
780                                  BIT(MTK_CLK_SGMII2_RX_250M) | \
781                                  BIT(MTK_CLK_SGMII2_CDR_REF) | \
782                                  BIT(MTK_CLK_SGMII2_CDR_FB))
783
784 enum mtk_dev_state {
785         MTK_HW_INIT,
786         MTK_RESETTING
787 };
788
789 enum mtk_tx_buf_type {
790         MTK_TYPE_SKB,
791         MTK_TYPE_XDP_TX,
792         MTK_TYPE_XDP_NDO,
793 };
794
795 /* struct mtk_tx_buf -  This struct holds the pointers to the memory pointed at
796  *                      by the TX descriptor    s
797  * @skb:                The SKB pointer of the packet being sent
798  * @dma_addr0:          The base addr of the first segment
799  * @dma_len0:           The length of the first segment
800  * @dma_addr1:          The base addr of the second segment
801  * @dma_len1:           The length of the second segment
802  */
803 struct mtk_tx_buf {
804         enum mtk_tx_buf_type type;
805         void *data;
806
807         u32 flags;
808         DEFINE_DMA_UNMAP_ADDR(dma_addr0);
809         DEFINE_DMA_UNMAP_LEN(dma_len0);
810         DEFINE_DMA_UNMAP_ADDR(dma_addr1);
811         DEFINE_DMA_UNMAP_LEN(dma_len1);
812 };
813
814 /* struct mtk_tx_ring - This struct holds info describing a TX ring
815  * @dma:                The descriptor ring
816  * @buf:                The memory pointed at by the ring
817  * @phys:               The physical addr of tx_buf
818  * @next_free:          Pointer to the next free descriptor
819  * @last_free:          Pointer to the last free descriptor
820  * @last_free_ptr:      Hardware pointer value of the last free descriptor
821  * @thresh:             The threshold of minimum amount of free descriptors
822  * @free_count:         QDMA uses a linked list. Track how many free descriptors
823  *                      are present
824  */
825 struct mtk_tx_ring {
826         void *dma;
827         struct mtk_tx_buf *buf;
828         dma_addr_t phys;
829         struct mtk_tx_dma *next_free;
830         struct mtk_tx_dma *last_free;
831         u32 last_free_ptr;
832         u16 thresh;
833         atomic_t free_count;
834         int dma_size;
835         struct mtk_tx_dma *dma_pdma;    /* For MT7628/88 PDMA handling */
836         dma_addr_t phys_pdma;
837         int cpu_idx;
838 };
839
840 /* PDMA rx ring mode */
841 enum mtk_rx_flags {
842         MTK_RX_FLAGS_NORMAL = 0,
843         MTK_RX_FLAGS_HWLRO,
844         MTK_RX_FLAGS_QDMA,
845 };
846
847 /* struct mtk_rx_ring - This struct holds info describing a RX ring
848  * @dma:                The descriptor ring
849  * @data:               The memory pointed at by the ring
850  * @phys:               The physical addr of rx_buf
851  * @frag_size:          How big can each fragment be
852  * @buf_size:           The size of each packet buffer
853  * @calc_idx:           The current head of ring
854  */
855 struct mtk_rx_ring {
856         void *dma;
857         u8 **data;
858         dma_addr_t phys;
859         u16 frag_size;
860         u16 buf_size;
861         u16 dma_size;
862         bool calc_idx_update;
863         u16 calc_idx;
864         u32 crx_idx_reg;
865         /* page_pool */
866         struct page_pool *page_pool;
867         struct xdp_rxq_info xdp_q;
868 };
869
870 enum mkt_eth_capabilities {
871         MTK_RGMII_BIT = 0,
872         MTK_TRGMII_BIT,
873         MTK_SGMII_BIT,
874         MTK_ESW_BIT,
875         MTK_GEPHY_BIT,
876         MTK_MUX_BIT,
877         MTK_INFRA_BIT,
878         MTK_SHARED_SGMII_BIT,
879         MTK_HWLRO_BIT,
880         MTK_SHARED_INT_BIT,
881         MTK_TRGMII_MT7621_CLK_BIT,
882         MTK_QDMA_BIT,
883         MTK_NETSYS_V2_BIT,
884         MTK_SOC_MT7628_BIT,
885         MTK_RSTCTRL_PPE1_BIT,
886         MTK_U3_COPHY_V2_BIT,
887
888         /* MUX BITS*/
889         MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
890         MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
891         MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
892         MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
893         MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
894
895         /* PATH BITS */
896         MTK_ETH_PATH_GMAC1_RGMII_BIT,
897         MTK_ETH_PATH_GMAC1_TRGMII_BIT,
898         MTK_ETH_PATH_GMAC1_SGMII_BIT,
899         MTK_ETH_PATH_GMAC2_RGMII_BIT,
900         MTK_ETH_PATH_GMAC2_SGMII_BIT,
901         MTK_ETH_PATH_GMAC2_GEPHY_BIT,
902         MTK_ETH_PATH_GDM1_ESW_BIT,
903 };
904
905 /* Supported hardware group on SoCs */
906 #define MTK_RGMII               BIT(MTK_RGMII_BIT)
907 #define MTK_TRGMII              BIT(MTK_TRGMII_BIT)
908 #define MTK_SGMII               BIT(MTK_SGMII_BIT)
909 #define MTK_ESW                 BIT(MTK_ESW_BIT)
910 #define MTK_GEPHY               BIT(MTK_GEPHY_BIT)
911 #define MTK_MUX                 BIT(MTK_MUX_BIT)
912 #define MTK_INFRA               BIT(MTK_INFRA_BIT)
913 #define MTK_SHARED_SGMII        BIT(MTK_SHARED_SGMII_BIT)
914 #define MTK_HWLRO               BIT(MTK_HWLRO_BIT)
915 #define MTK_SHARED_INT          BIT(MTK_SHARED_INT_BIT)
916 #define MTK_TRGMII_MT7621_CLK   BIT(MTK_TRGMII_MT7621_CLK_BIT)
917 #define MTK_QDMA                BIT(MTK_QDMA_BIT)
918 #define MTK_NETSYS_V2           BIT(MTK_NETSYS_V2_BIT)
919 #define MTK_SOC_MT7628          BIT(MTK_SOC_MT7628_BIT)
920 #define MTK_RSTCTRL_PPE1        BIT(MTK_RSTCTRL_PPE1_BIT)
921 #define MTK_U3_COPHY_V2         BIT(MTK_U3_COPHY_V2_BIT)
922
923 #define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW           \
924         BIT(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
925 #define MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY        \
926         BIT(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
927 #define MTK_ETH_MUX_U3_GMAC2_TO_QPHY            \
928         BIT(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
929 #define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII  \
930         BIT(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
931 #define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII       \
932         BIT(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
933
934 /* Supported path present on SoCs */
935 #define MTK_ETH_PATH_GMAC1_RGMII        BIT(MTK_ETH_PATH_GMAC1_RGMII_BIT)
936 #define MTK_ETH_PATH_GMAC1_TRGMII       BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
937 #define MTK_ETH_PATH_GMAC1_SGMII        BIT(MTK_ETH_PATH_GMAC1_SGMII_BIT)
938 #define MTK_ETH_PATH_GMAC2_RGMII        BIT(MTK_ETH_PATH_GMAC2_RGMII_BIT)
939 #define MTK_ETH_PATH_GMAC2_SGMII        BIT(MTK_ETH_PATH_GMAC2_SGMII_BIT)
940 #define MTK_ETH_PATH_GMAC2_GEPHY        BIT(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
941 #define MTK_ETH_PATH_GDM1_ESW           BIT(MTK_ETH_PATH_GDM1_ESW_BIT)
942
943 #define MTK_GMAC1_RGMII         (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
944 #define MTK_GMAC1_TRGMII        (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
945 #define MTK_GMAC1_SGMII         (MTK_ETH_PATH_GMAC1_SGMII | MTK_SGMII)
946 #define MTK_GMAC2_RGMII         (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
947 #define MTK_GMAC2_SGMII         (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
948 #define MTK_GMAC2_GEPHY         (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
949 #define MTK_GDM1_ESW            (MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
950
951 /* MUXes present on SoCs */
952 /* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
953 #define MTK_MUX_GDM1_TO_GMAC1_ESW (MTK_ETH_MUX_GDM1_TO_GMAC1_ESW | MTK_MUX)
954
955 /* 0: GMAC2 -> GEPHY, 1: GMAC0 -> GePHY */
956 #define MTK_MUX_GMAC2_GMAC0_TO_GEPHY    \
957         (MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY | MTK_MUX | MTK_INFRA)
958
959 /* 0: U3 -> QPHY, 1: GMAC2 -> QPHY */
960 #define MTK_MUX_U3_GMAC2_TO_QPHY        \
961         (MTK_ETH_MUX_U3_GMAC2_TO_QPHY | MTK_MUX | MTK_INFRA)
962
963 /* 2: GMAC1 -> SGMII, 3: GMAC2 -> SGMII */
964 #define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII      \
965         (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
966         MTK_SHARED_SGMII)
967
968 /* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
969 #define MTK_MUX_GMAC12_TO_GEPHY_SGMII   \
970         (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
971
972 #define MTK_HAS_CAPS(caps, _x)          (((caps) & (_x)) == (_x))
973
974 #define MT7621_CAPS  (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
975                       MTK_GMAC2_RGMII | MTK_SHARED_INT | \
976                       MTK_TRGMII_MT7621_CLK | MTK_QDMA)
977
978 #define MT7622_CAPS  (MTK_GMAC1_RGMII | MTK_GMAC1_SGMII | MTK_GMAC2_RGMII | \
979                       MTK_GMAC2_SGMII | MTK_GDM1_ESW | \
980                       MTK_MUX_GDM1_TO_GMAC1_ESW | \
981                       MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_QDMA)
982
983 #define MT7623_CAPS  (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | MTK_GMAC2_RGMII | \
984                       MTK_QDMA)
985
986 #define MT7628_CAPS  (MTK_SHARED_INT | MTK_SOC_MT7628)
987
988 #define MT7629_CAPS  (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
989                       MTK_GDM1_ESW | MTK_MUX_GDM1_TO_GMAC1_ESW | \
990                       MTK_MUX_GMAC2_GMAC0_TO_GEPHY | \
991                       MTK_MUX_U3_GMAC2_TO_QPHY | \
992                       MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA)
993
994 #define MT7981_CAPS  (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
995                       MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
996                       MTK_MUX_U3_GMAC2_TO_QPHY | MTK_U3_COPHY_V2 | \
997                       MTK_NETSYS_V2 | MTK_RSTCTRL_PPE1)
998
999 #define MT7986_CAPS  (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \
1000                       MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
1001                       MTK_NETSYS_V2 | MTK_RSTCTRL_PPE1)
1002
1003 struct mtk_tx_dma_desc_info {
1004         dma_addr_t      addr;
1005         u32             size;
1006         u16             vlan_tci;
1007         u16             qid;
1008         u8              gso:1;
1009         u8              csum:1;
1010         u8              vlan:1;
1011         u8              first:1;
1012         u8              last:1;
1013 };
1014
1015 struct mtk_reg_map {
1016         u32     tx_irq_mask;
1017         u32     tx_irq_status;
1018         struct {
1019                 u32     rx_ptr;         /* rx base pointer */
1020                 u32     rx_cnt_cfg;     /* rx max count configuration */
1021                 u32     pcrx_ptr;       /* rx cpu pointer */
1022                 u32     glo_cfg;        /* global configuration */
1023                 u32     rst_idx;        /* reset index */
1024                 u32     delay_irq;      /* delay interrupt */
1025                 u32     irq_status;     /* interrupt status */
1026                 u32     irq_mask;       /* interrupt mask */
1027                 u32     adma_rx_dbg0;
1028                 u32     int_grp;
1029         } pdma;
1030         struct {
1031                 u32     qtx_cfg;        /* tx queue configuration */
1032                 u32     qtx_sch;        /* tx queue scheduler configuration */
1033                 u32     rx_ptr;         /* rx base pointer */
1034                 u32     rx_cnt_cfg;     /* rx max count configuration */
1035                 u32     qcrx_ptr;       /* rx cpu pointer */
1036                 u32     glo_cfg;        /* global configuration */
1037                 u32     rst_idx;        /* reset index */
1038                 u32     delay_irq;      /* delay interrupt */
1039                 u32     fc_th;          /* flow control */
1040                 u32     int_grp;
1041                 u32     hred;           /* interrupt mask */
1042                 u32     ctx_ptr;        /* tx acquire cpu pointer */
1043                 u32     dtx_ptr;        /* tx acquire dma pointer */
1044                 u32     crx_ptr;        /* tx release cpu pointer */
1045                 u32     drx_ptr;        /* tx release dma pointer */
1046                 u32     fq_head;        /* fq head pointer */
1047                 u32     fq_tail;        /* fq tail pointer */
1048                 u32     fq_count;       /* fq free page count */
1049                 u32     fq_blen;        /* fq free page buffer length */
1050                 u32     tx_sch_rate;    /* tx scheduler rate control registers */
1051         } qdma;
1052         u32     gdm1_cnt;
1053         u32     gdma_to_ppe;
1054         u32     ppe_base;
1055         u32     wdma_base[2];
1056         u32     pse_iq_sta;
1057         u32     pse_oq_sta;
1058 };
1059
1060 /* struct mtk_eth_data -        This is the structure holding all differences
1061  *                              among various plaforms
1062  * @reg_map                     Soc register map.
1063  * @ana_rgc3:                   The offset for register ANA_RGC3 related to
1064  *                              sgmiisys syscon
1065  * @caps                        Flags shown the extra capability for the SoC
1066  * @hw_features                 Flags shown HW features
1067  * @required_clks               Flags shown the bitmap for required clocks on
1068  *                              the target SoC
1069  * @required_pctl               A bool value to show whether the SoC requires
1070  *                              the extra setup for those pins used by GMAC.
1071  * @hash_offset                 Flow table hash offset.
1072  * @foe_entry_size              Foe table entry size.
1073  * @txd_size                    Tx DMA descriptor size.
1074  * @rxd_size                    Rx DMA descriptor size.
1075  * @rx_irq_done_mask            Rx irq done register mask.
1076  * @rx_dma_l4_valid             Rx DMA valid register mask.
1077  * @dma_max_len                 Max DMA tx/rx buffer length.
1078  * @dma_len_offset              Tx/Rx DMA length field offset.
1079  */
1080 struct mtk_soc_data {
1081         const struct mtk_reg_map *reg_map;
1082         u32             ana_rgc3;
1083         u32             caps;
1084         u32             required_clks;
1085         bool            required_pctl;
1086         u8              offload_version;
1087         u8              hash_offset;
1088         u16             foe_entry_size;
1089         netdev_features_t hw_features;
1090         struct {
1091                 u32     txd_size;
1092                 u32     rxd_size;
1093                 u32     rx_irq_done_mask;
1094                 u32     rx_dma_l4_valid;
1095                 u32     dma_max_len;
1096                 u32     dma_len_offset;
1097         } txrx;
1098 };
1099
1100 #define MTK_DMA_MONITOR_TIMEOUT         msecs_to_jiffies(1000)
1101
1102 /* currently no SoC has more than 2 macs */
1103 #define MTK_MAX_DEVS                    2
1104
1105 /* struct mtk_pcs -    This structure holds each sgmii regmap and associated
1106  *                     data
1107  * @regmap:            The register map pointing at the range used to setup
1108  *                     SGMII modes
1109  * @ana_rgc3:          The offset refers to register ANA_RGC3 related to regmap
1110  * @interface:         Currently configured interface mode
1111  * @pcs:               Phylink PCS structure
1112  * @flags:             Flags indicating hardware properties
1113  */
1114 struct mtk_pcs {
1115         struct regmap   *regmap;
1116         u32             ana_rgc3;
1117         phy_interface_t interface;
1118         struct phylink_pcs pcs;
1119         u32             flags;
1120 };
1121
1122 /* struct mtk_sgmii -  This is the structure holding sgmii regmap and its
1123  *                     characteristics
1124  * @pcs                Array of individual PCS structures
1125  */
1126 struct mtk_sgmii {
1127         struct mtk_pcs  pcs[MTK_MAX_DEVS];
1128 };
1129
1130 /* struct mtk_eth -     This is the main datasructure for holding the state
1131  *                      of the driver
1132  * @dev:                The device pointer
1133  * @dev:                The device pointer used for dma mapping/alloc
1134  * @base:               The mapped register i/o base
1135  * @page_lock:          Make sure that register operations are atomic
1136  * @tx_irq__lock:       Make sure that IRQ register operations are atomic
1137  * @rx_irq__lock:       Make sure that IRQ register operations are atomic
1138  * @dim_lock:           Make sure that Net DIM operations are atomic
1139  * @dummy_dev:          we run 2 netdevs on 1 physical DMA ring and need a
1140  *                      dummy for NAPI to work
1141  * @netdev:             The netdev instances
1142  * @mac:                Each netdev is linked to a physical MAC
1143  * @irq:                The IRQ that we are using
1144  * @msg_enable:         Ethtool msg level
1145  * @ethsys:             The register map pointing at the range used to setup
1146  *                      MII modes
1147  * @infra:              The register map pointing at the range used to setup
1148  *                      SGMII and GePHY path
1149  * @pctl:               The register map pointing at the range used to setup
1150  *                      GMAC port drive/slew values
1151  * @dma_refcnt:         track how many netdevs are using the DMA engine
1152  * @tx_ring:            Pointer to the memory holding info about the TX ring
1153  * @rx_ring:            Pointer to the memory holding info about the RX ring
1154  * @rx_ring_qdma:       Pointer to the memory holding info about the QDMA RX ring
1155  * @tx_napi:            The TX NAPI struct
1156  * @rx_napi:            The RX NAPI struct
1157  * @rx_events:          Net DIM RX event counter
1158  * @rx_packets:         Net DIM RX packet counter
1159  * @rx_bytes:           Net DIM RX byte counter
1160  * @rx_dim:             Net DIM RX context
1161  * @tx_events:          Net DIM TX event counter
1162  * @tx_packets:         Net DIM TX packet counter
1163  * @tx_bytes:           Net DIM TX byte counter
1164  * @tx_dim:             Net DIM TX context
1165  * @scratch_ring:       Newer SoCs need memory for a second HW managed TX ring
1166  * @phy_scratch_ring:   physical address of scratch_ring
1167  * @scratch_head:       The scratch memory that scratch_ring points to.
1168  * @clks:               clock array for all clocks required
1169  * @mii_bus:            If there is a bus we need to create an instance for it
1170  * @pending_work:       The workqueue used to reset the dma ring
1171  * @state:              Initialization and runtime state of the device
1172  * @soc:                Holding specific data among vaious SoCs
1173  */
1174
1175 struct mtk_eth {
1176         struct device                   *dev;
1177         struct device                   *dma_dev;
1178         void __iomem                    *base;
1179         spinlock_t                      page_lock;
1180         spinlock_t                      tx_irq_lock;
1181         spinlock_t                      rx_irq_lock;
1182         struct net_device               dummy_dev;
1183         struct net_device               *netdev[MTK_MAX_DEVS];
1184         struct mtk_mac                  *mac[MTK_MAX_DEVS];
1185         int                             irq[3];
1186         u32                             msg_enable;
1187         unsigned long                   sysclk;
1188         struct regmap                   *ethsys;
1189         struct regmap                   *infra;
1190         struct mtk_sgmii                *sgmii;
1191         struct regmap                   *pctl;
1192         bool                            hwlro;
1193         refcount_t                      dma_refcnt;
1194         struct mtk_tx_ring              tx_ring;
1195         struct mtk_rx_ring              rx_ring[MTK_MAX_RX_RING_NUM];
1196         struct mtk_rx_ring              rx_ring_qdma;
1197         struct napi_struct              tx_napi;
1198         struct napi_struct              rx_napi;
1199         void                            *scratch_ring;
1200         dma_addr_t                      phy_scratch_ring;
1201         void                            *scratch_head;
1202         struct clk                      *clks[MTK_CLK_MAX];
1203
1204         struct mii_bus                  *mii_bus;
1205         struct work_struct              pending_work;
1206         unsigned long                   state;
1207
1208         const struct mtk_soc_data       *soc;
1209
1210         spinlock_t                      dim_lock;
1211
1212         u32                             rx_events;
1213         u32                             rx_packets;
1214         u32                             rx_bytes;
1215         struct dim                      rx_dim;
1216
1217         u32                             tx_events;
1218         u32                             tx_packets;
1219         u32                             tx_bytes;
1220         struct dim                      tx_dim;
1221
1222         int                             ip_align;
1223
1224         struct metadata_dst             *dsa_meta[MTK_MAX_DSA_PORTS];
1225
1226         struct mtk_ppe                  *ppe[2];
1227         struct rhashtable               flow_table;
1228
1229         struct bpf_prog                 __rcu *prog;
1230
1231         struct {
1232                 struct delayed_work monitor_work;
1233                 u32 wdidx;
1234                 u8 wdma_hang_count;
1235                 u8 qdma_hang_count;
1236                 u8 adma_hang_count;
1237         } reset;
1238 };
1239
1240 /* struct mtk_mac -     the structure that holds the info about the MACs of the
1241  *                      SoC
1242  * @id:                 The number of the MAC
1243  * @interface:          Interface mode kept for detecting change in hw settings
1244  * @of_node:            Our devicetree node
1245  * @hw:                 Backpointer to our main datastruture
1246  * @hw_stats:           Packet statistics counter
1247  */
1248 struct mtk_mac {
1249         int                             id;
1250         phy_interface_t                 interface;
1251         int                             speed;
1252         struct device_node              *of_node;
1253         struct phylink                  *phylink;
1254         struct phylink_config           phylink_config;
1255         struct mtk_eth                  *hw;
1256         struct mtk_hw_stats             *hw_stats;
1257         __be32                          hwlro_ip[MTK_MAX_LRO_IP_CNT];
1258         int                             hwlro_ip_cnt;
1259         unsigned int                    syscfg0;
1260         struct notifier_block           device_notifier;
1261 };
1262
1263 /* the struct describing the SoC. these are declared in the soc_xyz.c files */
1264 extern const struct of_device_id of_mtk_match[];
1265
1266 static inline struct mtk_foe_entry *
1267 mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
1268 {
1269         const struct mtk_soc_data *soc = ppe->eth->soc;
1270
1271         return ppe->foe_table + hash * soc->foe_entry_size;
1272 }
1273
1274 static inline u32 mtk_get_ib1_ts_mask(struct mtk_eth *eth)
1275 {
1276         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1277                 return MTK_FOE_IB1_BIND_TIMESTAMP_V2;
1278
1279         return MTK_FOE_IB1_BIND_TIMESTAMP;
1280 }
1281
1282 static inline u32 mtk_get_ib1_ppoe_mask(struct mtk_eth *eth)
1283 {
1284         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1285                 return MTK_FOE_IB1_BIND_PPPOE_V2;
1286
1287         return MTK_FOE_IB1_BIND_PPPOE;
1288 }
1289
1290 static inline u32 mtk_get_ib1_vlan_tag_mask(struct mtk_eth *eth)
1291 {
1292         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1293                 return MTK_FOE_IB1_BIND_VLAN_TAG_V2;
1294
1295         return MTK_FOE_IB1_BIND_VLAN_TAG;
1296 }
1297
1298 static inline u32 mtk_get_ib1_vlan_layer_mask(struct mtk_eth *eth)
1299 {
1300         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1301                 return MTK_FOE_IB1_BIND_VLAN_LAYER_V2;
1302
1303         return MTK_FOE_IB1_BIND_VLAN_LAYER;
1304 }
1305
1306 static inline u32 mtk_prep_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
1307 {
1308         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1309                 return FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER_V2, val);
1310
1311         return FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, val);
1312 }
1313
1314 static inline u32 mtk_get_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
1315 {
1316         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1317                 return FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER_V2, val);
1318
1319         return FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER, val);
1320 }
1321
1322 static inline u32 mtk_get_ib1_pkt_type_mask(struct mtk_eth *eth)
1323 {
1324         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1325                 return MTK_FOE_IB1_PACKET_TYPE_V2;
1326
1327         return MTK_FOE_IB1_PACKET_TYPE;
1328 }
1329
1330 static inline u32 mtk_get_ib1_pkt_type(struct mtk_eth *eth, u32 val)
1331 {
1332         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1333                 return FIELD_GET(MTK_FOE_IB1_PACKET_TYPE_V2, val);
1334
1335         return FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, val);
1336 }
1337
1338 static inline u32 mtk_get_ib2_multicast_mask(struct mtk_eth *eth)
1339 {
1340         if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
1341                 return MTK_FOE_IB2_MULTICAST_V2;
1342
1343         return MTK_FOE_IB2_MULTICAST;
1344 }
1345
1346 /* read the hardware status register */
1347 void mtk_stats_update_mac(struct mtk_mac *mac);
1348
1349 void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
1350 u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
1351
1352 struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id);
1353 int mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *np,
1354                    u32 ana_rgc3);
1355
1356 int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
1357 int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
1358 int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
1359
1360 int mtk_eth_offload_init(struct mtk_eth *eth);
1361 int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
1362                      void *type_data);
1363 void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
1364
1365
1366 #endif /* MTK_ETH_H */