blob: 06c2b0ac4bf32869665991795012ba049adf1d42 [file] [log] [blame]
developerfd40db22021-04-29 10:08:25 +08001/* 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
19#define MTK_QDMA_PAGE_SIZE 2048
20#define MTK_MAX_RX_LENGTH 1536
developerb3a9e7b2023-02-08 15:18:10 +080021#define MTK_MIN_TX_LENGTH 60
developerfd40db22021-04-29 10:08:25 +080022#define MTK_DMA_SIZE 2048
23#define MTK_NAPI_WEIGHT 256
developer089e8852022-09-28 14:43:46 +080024
25#if defined(CONFIG_MEDIATEK_NETSYS_V3)
26#define MTK_MAC_COUNT 3
27#else
developerfd40db22021-04-29 10:08:25 +080028#define MTK_MAC_COUNT 2
developer089e8852022-09-28 14:43:46 +080029#endif
30
developerfd40db22021-04-29 10:08:25 +080031#define MTK_RX_ETH_HLEN (VLAN_ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
32#define MTK_RX_HLEN (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN)
33#define MTK_DMA_DUMMY_DESC 0xffffffff
34#define MTK_DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | \
35 NETIF_MSG_PROBE | \
36 NETIF_MSG_LINK | \
37 NETIF_MSG_TIMER | \
38 NETIF_MSG_IFDOWN | \
39 NETIF_MSG_IFUP | \
40 NETIF_MSG_RX_ERR | \
41 NETIF_MSG_TX_ERR)
42#define MTK_HW_FEATURES (NETIF_F_IP_CSUM | \
43 NETIF_F_RXCSUM | \
44 NETIF_F_HW_VLAN_CTAG_TX | \
developerfd40db22021-04-29 10:08:25 +080045 NETIF_F_SG | NETIF_F_TSO | \
46 NETIF_F_TSO6 | \
47 NETIF_F_IPV6_CSUM)
48#define MTK_SET_FEATURES (NETIF_F_LRO | \
49 NETIF_F_HW_VLAN_CTAG_RX)
50#define MTK_HW_FEATURES_MT7628 (NETIF_F_SG | NETIF_F_RXCSUM)
51#define NEXT_DESP_IDX(X, Y) (((X) + 1) & ((Y) - 1))
52
developer68ce74f2023-01-03 16:11:57 +080053#define MTK_QRX_OFFSET 0x10
54
developerfd40db22021-04-29 10:08:25 +080055#define MTK_HW_LRO_DMA_SIZE 8
56
57#define MTK_MAX_LRO_RX_LENGTH (4096 * 3)
58#define MTK_MAX_LRO_IP_CNT 2
59#define MTK_HW_LRO_TIMER_UNIT 1 /* 20 us */
60#define MTK_HW_LRO_REFRESH_TIME 50000 /* 1 sec. */
61#define MTK_HW_LRO_AGG_TIME 10 /* 200us */
62#define MTK_HW_LRO_AGE_TIME 50 /* 1ms */
63#define MTK_HW_LRO_MAX_AGG_CNT 64
64#define MTK_HW_LRO_BW_THRE 3000
65#define MTK_HW_LRO_REPLACE_DELTA 1000
66#define MTK_HW_LRO_SDL_REMAIN_ROOM 1522
67
developer8051e042022-04-08 13:26:36 +080068/* Frame Engine Global Configuration */
69#define MTK_FE_GLO_CFG 0x00
70#define MTK_FE_LINK_DOWN_P3 BIT(11)
71#define MTK_FE_LINK_DOWN_P4 BIT(12)
72
developerfd40db22021-04-29 10:08:25 +080073/* Frame Engine Global Reset Register */
74#define MTK_RST_GL 0x04
75#define RST_GL_PSE BIT(0)
76
77/* Frame Engine Interrupt Status Register */
developer8051e042022-04-08 13:26:36 +080078#define MTK_FE_INT_STATUS 0x08
79#define MTK_FE_INT_STATUS2 0x28
80#define MTK_FE_INT_ENABLE 0x0C
81#define MTK_FE_INT_FQ_EMPTY BIT(8)
82#define MTK_FE_INT_TSO_FAIL BIT(12)
83#define MTK_FE_INT_TSO_ILLEGAL BIT(13)
84#define MTK_FE_INT_TSO_ALIGN BIT(14)
85#define MTK_FE_INT_RFIFO_OV BIT(18)
86#define MTK_FE_INT_RFIFO_UF BIT(19)
developerfd40db22021-04-29 10:08:25 +080087#define MTK_GDM1_AF BIT(28)
88#define MTK_GDM2_AF BIT(29)
developer94806ec2023-05-19 14:16:44 +080089#define MTK_FE_IRQ_NUM (4)
90#define MTK_PDMA_IRQ_NUM (4)
91#define MTK_MAX_IRQ_NUM (MTK_FE_IRQ_NUM + MTK_PDMA_IRQ_NUM)
developerfd40db22021-04-29 10:08:25 +080092
93/* PDMA HW LRO Alter Flow Timer Register */
94#define MTK_PDMA_LRO_ALT_REFRESH_TIMER 0x1c
95
96/* Frame Engine Interrupt Grouping Register */
97#define MTK_FE_INT_GRP 0x20
98
developer77d03a72021-06-06 00:06:00 +080099/* Frame Engine LRO auto-learn table info */
100#define MTK_FE_ALT_CF8 0x300
101#define MTK_FE_ALT_SGL_CFC 0x304
102#define MTK_FE_ALT_SEQ_CFC 0x308
103
developerfd40db22021-04-29 10:08:25 +0800104/* CDMP Ingress Control Register */
105#define MTK_CDMQ_IG_CTRL 0x1400
106#define MTK_CDMQ_STAG_EN BIT(0)
107
108/* CDMP Ingress Control Register */
109#define MTK_CDMP_IG_CTRL 0x400
110#define MTK_CDMP_STAG_EN BIT(0)
111
112/* CDMP Exgress Control Register */
113#define MTK_CDMP_EG_CTRL 0x404
114
developer089e8852022-09-28 14:43:46 +0800115/* GDM Ingress Control Register */
116#define MTK_GDMA_FWD_CFG(x) ((x == MTK_GMAC3_ID) ? \
117 0x540 : 0x500 + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800118#define MTK_GDMA_SPECIAL_TAG BIT(24)
119#define MTK_GDMA_ICS_EN BIT(22)
120#define MTK_GDMA_TCS_EN BIT(21)
121#define MTK_GDMA_UCS_EN BIT(20)
developer089e8852022-09-28 14:43:46 +0800122#define MTK_GDMA_STRP_CRC BIT(16)
developerfd40db22021-04-29 10:08:25 +0800123#define MTK_GDMA_TO_PDMA 0x0
124#define MTK_GDMA_DROP_ALL 0x7777
125
developer089e8852022-09-28 14:43:46 +0800126/* GDM Egress Control Register */
127#define MTK_GDMA_EG_CTRL(x) ((x == MTK_GMAC3_ID) ? \
128 0x544 : 0x504 + (x * 0x1000))
129#define MTK_GDMA_XGDM_SEL BIT(31)
130
developerfd40db22021-04-29 10:08:25 +0800131/* Unicast Filter MAC Address Register - Low */
developer089e8852022-09-28 14:43:46 +0800132#define MTK_GDMA_MAC_ADRL(x) ((x == MTK_GMAC3_ID) ? \
133 0x548 : 0x508 + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800134
135/* Unicast Filter MAC Address Register - High */
developer089e8852022-09-28 14:43:46 +0800136#define MTK_GDMA_MAC_ADRH(x) ((x == MTK_GMAC3_ID) ? \
137 0x54C : 0x50C + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800138
139/* Internal SRAM offset */
developer089e8852022-09-28 14:43:46 +0800140#if defined(CONFIG_MEDIATEK_NETSYS_V3)
141#define MTK_ETH_SRAM_OFFSET 0x300000
142#else
developerfd40db22021-04-29 10:08:25 +0800143#define MTK_ETH_SRAM_OFFSET 0x40000
developer089e8852022-09-28 14:43:46 +0800144#endif
developerfd40db22021-04-29 10:08:25 +0800145
146/* FE global misc reg*/
147#define MTK_FE_GLO_MISC 0x124
148
developerfef9efd2021-06-16 18:28:09 +0800149/* PSE Free Queue Flow Control */
150#define PSE_FQFC_CFG1 0x100
151#define PSE_FQFC_CFG2 0x104
developer459b78e2022-07-01 17:25:10 +0800152#define PSE_NO_DROP_CFG 0x108
153#define PSE_PPE0_DROP 0x110
developerfef9efd2021-06-16 18:28:09 +0800154
developer15f760a2022-10-12 15:57:21 +0800155/* PSE Last FreeQ Page Request Control */
156#define PSE_DUMY_REQ 0x10C
157#define PSE_DUMMY_WORK_GDM(x) BIT(16 + (x))
158#define DUMMY_PAGE_THR 0x151
159
developerfd40db22021-04-29 10:08:25 +0800160/* PSE Input Queue Reservation Register*/
161#define PSE_IQ_REV(x) (0x140 + ((x - 1) * 0x4))
162
163/* PSE Output Queue Threshold Register*/
164#define PSE_OQ_TH(x) (0x160 + ((x - 1) * 0x4))
165
developerfef9efd2021-06-16 18:28:09 +0800166/* GDM and CDM Threshold */
167#define MTK_GDM2_THRES 0x1530
168#define MTK_CDMW0_THRES 0x164c
169#define MTK_CDMW1_THRES 0x1650
170#define MTK_CDME0_THRES 0x1654
171#define MTK_CDME1_THRES 0x1658
172#define MTK_CDMM_THRES 0x165c
173
developerfd40db22021-04-29 10:08:25 +0800174#define MTK_PDMA_V2 BIT(4)
developerfd40db22021-04-29 10:08:25 +0800175
developer089e8852022-09-28 14:43:46 +0800176#if defined(CONFIG_MEDIATEK_NETSYS_V3)
177#define PDMA_BASE 0x6800
178#define QDMA_BASE 0x4400
179#define WDMA_BASE(x) (0x4800 + ((x) * 0x400))
developer2a050ba2022-12-01 16:11:06 +0800180#define PPE_BASE(x) ((x == 2) ? 0x2E00 : 0x2200 + ((x) * 0x400))
developer089e8852022-09-28 14:43:46 +0800181#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
developer8ecd51b2023-03-13 11:28:28 +0800182#ifdef CONFIG_MEDIATEK_NETSYS_RX_V2
developerfd40db22021-04-29 10:08:25 +0800183#define PDMA_BASE 0x6000
developer8ecd51b2023-03-13 11:28:28 +0800184#else
185#define PDMA_BASE 0x4000
186#endif
developerfd40db22021-04-29 10:08:25 +0800187#define QDMA_BASE 0x4400
developer8051e042022-04-08 13:26:36 +0800188#define WDMA_BASE(x) (0x4800 + ((x) * 0x400))
189#define PPE_BASE(x) (0x2200 + ((x) * 0x400))
developerfd40db22021-04-29 10:08:25 +0800190#else
191#define PDMA_BASE 0x0800
192#define QDMA_BASE 0x1800
developer8051e042022-04-08 13:26:36 +0800193#define WDMA_BASE(x) (0x2800 + ((x) * 0x400))
194#define PPE_BASE(x) (0xE00 + ((x) * 0x400))
developerfd40db22021-04-29 10:08:25 +0800195#endif
196/* PDMA RX Base Pointer Register */
197#define MTK_PRX_BASE_PTR0 (PDMA_BASE + 0x100)
198#define MTK_PRX_BASE_PTR_CFG(x) (MTK_PRX_BASE_PTR0 + (x * 0x10))
199
200/* PDMA RX Maximum Count Register */
201#define MTK_PRX_MAX_CNT0 (MTK_PRX_BASE_PTR0 + 0x04)
202#define MTK_PRX_MAX_CNT_CFG(x) (MTK_PRX_MAX_CNT0 + (x * 0x10))
203
204/* PDMA RX CPU Pointer Register */
205#define MTK_PRX_CRX_IDX0 (MTK_PRX_BASE_PTR0 + 0x08)
206#define MTK_PRX_CRX_IDX_CFG(x) (MTK_PRX_CRX_IDX0 + (x * 0x10))
207
developer77f3fd42021-10-05 15:16:05 +0800208/* PDMA RX DMA Pointer Register */
209#define MTK_PRX_DRX_IDX0 (MTK_PRX_BASE_PTR0 + 0x0c)
210#define MTK_PRX_DRX_IDX_CFG(x) (MTK_PRX_DRX_IDX0 + (x * 0x10))
211
developerfd40db22021-04-29 10:08:25 +0800212/* PDMA HW LRO Control Registers */
developer77d03a72021-06-06 00:06:00 +0800213#define BITS(m, n) (~(BIT(m) - 1) & ((BIT(n) - 1) | BIT(n)))
developer8ecd51b2023-03-13 11:28:28 +0800214#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer77d03a72021-06-06 00:06:00 +0800215#define MTK_MAX_RX_RING_NUM (8)
216#define MTK_HW_LRO_RING_NUM (4)
217#define IS_HW_LRO_RING(ring_no) (((ring_no) > 3) && ((ring_no) < 8))
218#define MTK_PDMA_LRO_CTRL_DW0 (PDMA_BASE + 0x408)
219#define MTK_LRO_ALT_SCORE_DELTA (PDMA_BASE + 0x41c)
220#define MTK_LRO_RX_RING0_CTRL_DW1 (PDMA_BASE + 0x438)
221#define MTK_LRO_RX_RING0_CTRL_DW2 (PDMA_BASE + 0x43c)
222#define MTK_LRO_RX_RING0_CTRL_DW3 (PDMA_BASE + 0x440)
223#define MTK_L3_CKS_UPD_EN BIT(19)
224#define MTK_LRO_CRSN_BNW BIT(22)
225#define MTK_LRO_RING_RELINGUISH_REQ (0xf << 24)
226#define MTK_LRO_RING_RELINGUISH_DONE (0xf << 28)
227#else
228#define MTK_MAX_RX_RING_NUM (4)
229#define MTK_HW_LRO_RING_NUM (3)
230#define IS_HW_LRO_RING(ring_no) (((ring_no) > 0) && ((ring_no) < 4))
231#define MTK_PDMA_LRO_CTRL_DW0 (PDMA_BASE + 0x180)
232#define MTK_LRO_ALT_SCORE_DELTA (PDMA_BASE + 0x24c)
233#define MTK_LRO_RX_RING0_CTRL_DW1 (PDMA_BASE + 0x328)
234#define MTK_LRO_RX_RING0_CTRL_DW2 (PDMA_BASE + 0x32c)
235#define MTK_LRO_RX_RING0_CTRL_DW3 (PDMA_BASE + 0x330)
236#define MTK_LRO_CRSN_BNW BIT(6)
developerfd40db22021-04-29 10:08:25 +0800237#define MTK_L3_CKS_UPD_EN BIT(7)
developer77d03a72021-06-06 00:06:00 +0800238#define MTK_LRO_RING_RELINGUISH_REQ (0x7 << 26)
239#define MTK_LRO_RING_RELINGUISH_DONE (0x7 << 29)
240#endif
241
242#define IS_NORMAL_RING(ring_no) ((ring_no) == 0)
243#define MTK_LRO_EN BIT(0)
developer18f46a82021-07-20 21:08:21 +0800244#define MTK_NON_LRO_MULTI_EN BIT(2)
245#define MTK_LRO_DLY_INT_EN BIT(5)
developerfd40db22021-04-29 10:08:25 +0800246#define MTK_LRO_ALT_PKT_CNT_MODE BIT(21)
developer77d03a72021-06-06 00:06:00 +0800247#define MTK_LRO_L4_CTRL_PSH_EN BIT(23)
248#define MTK_CTRL_DW0_SDL_OFFSET (3)
249#define MTK_CTRL_DW0_SDL_MASK BITS(3, 18)
developerfd40db22021-04-29 10:08:25 +0800250
251#define MTK_PDMA_LRO_CTRL_DW1 (MTK_PDMA_LRO_CTRL_DW0 + 0x04)
252#define MTK_PDMA_LRO_CTRL_DW2 (MTK_PDMA_LRO_CTRL_DW0 + 0x08)
253#define MTK_PDMA_LRO_CTRL_DW3 (MTK_PDMA_LRO_CTRL_DW0 + 0x0c)
254#define MTK_ADMA_MODE BIT(15)
255#define MTK_LRO_MIN_RXD_SDL (MTK_HW_LRO_SDL_REMAIN_ROOM << 16)
256
developer18f46a82021-07-20 21:08:21 +0800257/* PDMA RSS Control Registers */
developer8ecd51b2023-03-13 11:28:28 +0800258#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer18f46a82021-07-20 21:08:21 +0800259#define MTK_PDMA_RSS_GLO_CFG (PDMA_BASE + 0x800)
developer94806ec2023-05-19 14:16:44 +0800260#define MTK_RX_NAPI_NUM (4)
developer18f46a82021-07-20 21:08:21 +0800261#else
developer8ecd51b2023-03-13 11:28:28 +0800262#define MTK_PDMA_RSS_GLO_CFG 0x2800
developeredb02af2023-03-31 13:31:28 +0800263#define MTK_RX_NAPI_NUM (1)
developer18f46a82021-07-20 21:08:21 +0800264#endif
developer94806ec2023-05-19 14:16:44 +0800265#define MTK_RSS_RING(x) (x)
developer18f46a82021-07-20 21:08:21 +0800266#define MTK_RSS_EN BIT(0)
267#define MTK_RSS_CFG_REQ BIT(2)
268#define MTK_RSS_IPV6_STATIC_HASH (0x7 << 8)
269#define MTK_RSS_IPV4_STATIC_HASH (0x7 << 12)
developere3d0de22023-05-30 17:45:00 +0800270#define MTK_RSS_INDR_TABLE_DW(x) (MTK_PDMA_RSS_GLO_CFG + 0x50 + \
271 ((x) * 0x4))
developer18f46a82021-07-20 21:08:21 +0800272
developerfd40db22021-04-29 10:08:25 +0800273/* PDMA Global Configuration Register */
274#define MTK_PDMA_GLO_CFG (PDMA_BASE + 0x204)
developer77d03a72021-06-06 00:06:00 +0800275#define MTK_RX_DMA_LRO_EN BIT(8)
developerfd40db22021-04-29 10:08:25 +0800276#define MTK_MULTI_EN BIT(10)
277#define MTK_PDMA_SIZE_8DWORDS (1 << 4)
278
developer77d03a72021-06-06 00:06:00 +0800279/* PDMA Global Configuration Register */
280#define MTK_PDMA_RX_CFG (PDMA_BASE + 0x210)
281#define MTK_PDMA_LRO_SDL (0x3000)
282#define MTK_RX_CFG_SDL_OFFSET (16)
283
developerfd40db22021-04-29 10:08:25 +0800284/* PDMA Reset Index Register */
285#define MTK_PDMA_RST_IDX (PDMA_BASE + 0x208)
286#define MTK_PST_DRX_IDX0 BIT(16)
287#define MTK_PST_DRX_IDX_CFG(x) (MTK_PST_DRX_IDX0 << (x))
288
289/* PDMA Delay Interrupt Register */
290#define MTK_PDMA_DELAY_INT (PDMA_BASE + 0x20c)
developer8ecd51b2023-03-13 11:28:28 +0800291#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer089e8852022-09-28 14:43:46 +0800292#define MTK_PDMA_RSS_DELAY_INT (PDMA_BASE + 0x2c0)
developer8ecd51b2023-03-13 11:28:28 +0800293#else
294#define MTK_PDMA_RSS_DELAY_INT (PDMA_BASE + 0x270)
295#endif
developerfd40db22021-04-29 10:08:25 +0800296#define MTK_PDMA_DELAY_RX_EN BIT(15)
297#define MTK_PDMA_DELAY_RX_PINT 4
298#define MTK_PDMA_DELAY_RX_PINT_SHIFT 8
299#define MTK_PDMA_DELAY_RX_PTIME 4
300#define MTK_PDMA_DELAY_RX_DELAY \
301 (MTK_PDMA_DELAY_RX_EN | MTK_PDMA_DELAY_RX_PTIME | \
302 (MTK_PDMA_DELAY_RX_PINT << MTK_PDMA_DELAY_RX_PINT_SHIFT))
303
304/* PDMA Interrupt Status Register */
305#define MTK_PDMA_INT_STATUS (PDMA_BASE + 0x220)
306
307/* PDMA Interrupt Mask Register */
308#define MTK_PDMA_INT_MASK (PDMA_BASE + 0x228)
309
developerfd40db22021-04-29 10:08:25 +0800310/* PDMA Interrupt grouping registers */
311#define MTK_PDMA_INT_GRP1 (PDMA_BASE + 0x250)
312#define MTK_PDMA_INT_GRP2 (PDMA_BASE + 0x254)
developer8ecd51b2023-03-13 11:28:28 +0800313#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer18f46a82021-07-20 21:08:21 +0800314#define MTK_PDMA_INT_GRP3 (PDMA_BASE + 0x258)
315#else
316#define MTK_PDMA_INT_GRP3 (PDMA_BASE + 0x22c)
317#endif
318#define MTK_LRO_RX1_DLY_INT 0xa70
319#define MTK_MAX_DELAY_INT 0x8f0f8f0f
developerfd40db22021-04-29 10:08:25 +0800320
321/* PDMA HW LRO IP Setting Registers */
developer8ecd51b2023-03-13 11:28:28 +0800322#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer77d03a72021-06-06 00:06:00 +0800323#define MTK_LRO_RX_RING0_DIP_DW0 (PDMA_BASE + 0x414)
324#else
developerfd40db22021-04-29 10:08:25 +0800325#define MTK_LRO_RX_RING0_DIP_DW0 (PDMA_BASE + 0x304)
developer77d03a72021-06-06 00:06:00 +0800326#endif
developerfd40db22021-04-29 10:08:25 +0800327#define MTK_LRO_DIP_DW0_CFG(x) (MTK_LRO_RX_RING0_DIP_DW0 + (x * 0x40))
328#define MTK_RING_MYIP_VLD BIT(9)
329
developer77d03a72021-06-06 00:06:00 +0800330/* PDMA HW LRO ALT Debug Registers */
331#define MTK_LRO_ALT_DBG (PDMA_BASE + 0x440)
332#define MTK_LRO_ALT_INDEX_OFFSET (8)
333
334/* PDMA HW LRO ALT Data Registers */
335#define MTK_LRO_ALT_DBG_DATA (PDMA_BASE + 0x444)
336
developerfd40db22021-04-29 10:08:25 +0800337/* PDMA HW LRO Ring Control Registers */
developerfd40db22021-04-29 10:08:25 +0800338#define MTK_LRO_CTRL_DW1_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW1 + (x * 0x40))
339#define MTK_LRO_CTRL_DW2_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW2 + (x * 0x40))
340#define MTK_LRO_CTRL_DW3_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW3 + (x * 0x40))
341#define MTK_RING_AGE_TIME_L ((MTK_HW_LRO_AGE_TIME & 0x3ff) << 22)
342#define MTK_RING_AGE_TIME_H ((MTK_HW_LRO_AGE_TIME >> 10) & 0x3f)
developer18f46a82021-07-20 21:08:21 +0800343#define MTK_RING_PSE_MODE (1 << 6)
developerfd40db22021-04-29 10:08:25 +0800344#define MTK_RING_AUTO_LERAN_MODE (3 << 6)
345#define MTK_RING_VLD BIT(8)
346#define MTK_RING_MAX_AGG_TIME ((MTK_HW_LRO_AGG_TIME & 0xffff) << 10)
347#define MTK_RING_MAX_AGG_CNT_L ((MTK_HW_LRO_MAX_AGG_CNT & 0x3f) << 26)
348#define MTK_RING_MAX_AGG_CNT_H ((MTK_HW_LRO_MAX_AGG_CNT >> 6) & 0x3)
349
developer77d03a72021-06-06 00:06:00 +0800350/* LRO_RX_RING_CTRL_DW masks */
351#define MTK_LRO_RING_AGG_TIME_MASK BITS(10, 25)
352#define MTK_LRO_RING_AGG_CNT_L_MASK BITS(26, 31)
353#define MTK_LRO_RING_AGG_CNT_H_MASK BITS(0, 1)
354#define MTK_LRO_RING_AGE_TIME_L_MASK BITS(22, 31)
355#define MTK_LRO_RING_AGE_TIME_H_MASK BITS(0, 5)
356
357/* LRO_RX_RING_CTRL_DW0 offsets */
358#define MTK_RX_IPV6_FORCE_OFFSET (0)
359#define MTK_RX_IPV4_FORCE_OFFSET (1)
360
361/* LRO_RX_RING_CTRL_DW1 offsets */
362#define MTK_LRO_RING_AGE_TIME_L_OFFSET (22)
363
364/* LRO_RX_RING_CTRL_DW2 offsets */
365#define MTK_LRO_RING_AGE_TIME_H_OFFSET (0)
366#define MTK_RX_MODE_OFFSET (6)
367#define MTK_RX_PORT_VALID_OFFSET (8)
368#define MTK_RX_MYIP_VALID_OFFSET (9)
369#define MTK_LRO_RING_AGG_TIME_OFFSET (10)
370#define MTK_LRO_RING_AGG_CNT_L_OFFSET (26)
371
372/* LRO_RX_RING_CTRL_DW3 offsets */
373#define MTK_LRO_RING_AGG_CNT_H_OFFSET (0)
374
375/* LRO_RX_RING_STP_DTP_DW offsets */
376#define MTK_RX_TCP_DEST_PORT_OFFSET (0)
377#define MTK_RX_TCP_SRC_PORT_OFFSET (16)
378
developerfd40db22021-04-29 10:08:25 +0800379/* QDMA TX Queue Configuration Registers */
380#define MTK_QTX_CFG(x) (QDMA_BASE + (x * 0x10))
381#define QDMA_RES_THRES 4
382
383/* QDMA TX Queue Scheduler Registers */
384#define MTK_QTX_SCH(x) (QDMA_BASE + 4 + (x * 0x10))
385
386/* QDMA RX Base Pointer Register */
387#define MTK_QRX_BASE_PTR0 (QDMA_BASE + 0x100)
388#define MTK_QRX_BASE_PTR_CFG(x) (MTK_QRX_BASE_PTR0 + ((x) * 0x10))
389
390/* QDMA RX Maximum Count Register */
391#define MTK_QRX_MAX_CNT0 (QDMA_BASE + 0x104)
392#define MTK_QRX_MAX_CNT_CFG(x) (MTK_QRX_MAX_CNT0 + ((x) * 0x10))
393
394/* QDMA RX CPU Pointer Register */
395#define MTK_QRX_CRX_IDX0 (QDMA_BASE + 0x108)
396#define MTK_QRX_CRX_IDX_CFG(x) (MTK_QRX_CRX_IDX0 + ((x) * 0x10))
397
398/* QDMA RX DMA Pointer Register */
399#define MTK_QRX_DRX_IDX0 (QDMA_BASE + 0x10c)
400
developer329d8ee2022-08-02 08:49:42 +0800401/* QDMA Page Configuration Register */
402#define MTK_QDMA_PAGE (QDMA_BASE + 0x1f0)
403
developerfd40db22021-04-29 10:08:25 +0800404/* QDMA Global Configuration Register */
405#define MTK_QDMA_GLO_CFG (QDMA_BASE + 0x204)
406#define MTK_RX_2B_OFFSET BIT(31)
developer58ab5842022-06-01 15:10:25 +0800407#define MTK_PKT_RX_WDONE BIT(27)
developerfd40db22021-04-29 10:08:25 +0800408#define MTK_RX_BT_32DWORDS (3 << 11)
409#define MTK_NDP_CO_PRO BIT(10)
410#define MTK_TX_WB_DDONE BIT(6)
411#define MTK_DMA_SIZE_16DWORDS (2 << 4)
412#define MTK_DMA_SIZE_32DWORDS (3 << 4)
413#define MTK_RX_DMA_BUSY BIT(3)
414#define MTK_TX_DMA_BUSY BIT(1)
415#define MTK_RX_DMA_EN BIT(2)
416#define MTK_TX_DMA_EN BIT(0)
417#define MTK_DMA_BUSY_TIMEOUT HZ
418
419/* QDMA V2 Global Configuration Register */
420#define MTK_CHK_DDONE_EN BIT(28)
421#define MTK_DMAD_WR_WDONE BIT(26)
422#define MTK_WCOMP_EN BIT(24)
developer2cdef092022-04-15 17:27:55 +0800423#define MTK_RESV_BUF (0x80 << 16)
developerfd40db22021-04-29 10:08:25 +0800424#define MTK_MUTLI_CNT (0x4 << 12)
developer19d84562022-04-21 17:01:06 +0800425#define MTK_RESV_BUF_MASK (0xff << 16)
developerfd40db22021-04-29 10:08:25 +0800426
427/* QDMA Reset Index Register */
428#define MTK_QDMA_RST_IDX (QDMA_BASE + 0x208)
429
430/* QDMA Delay Interrupt Register */
431#define MTK_QDMA_DELAY_INT (QDMA_BASE + 0x20c)
432
433/* QDMA Flow Control Register */
434#define MTK_QDMA_FC_THRES (QDMA_BASE + 0x210)
435#define FC_THRES_DROP_MODE BIT(20)
436#define FC_THRES_DROP_EN (7 << 16)
437#define FC_THRES_MIN 0x4444
438
439/* QDMA Interrupt Status Register */
440#define MTK_QDMA_INT_STATUS (QDMA_BASE + 0x218)
developer8ecd51b2023-03-13 11:28:28 +0800441#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer94806ec2023-05-19 14:16:44 +0800442#define MTK_RX_DONE_INT(ring_no) \
developer089e8852022-09-28 14:43:46 +0800443 (MTK_HAS_CAPS(eth->soc->caps, MTK_RSS) ? (BIT(24 + (ring_no))) : \
444 ((ring_no) ? BIT(16 + (ring_no)) : BIT(14)))
developerfd40db22021-04-29 10:08:25 +0800445#else
developer94806ec2023-05-19 14:16:44 +0800446#define MTK_RX_DONE_INT(ring_no) \
447 (MTK_HAS_CAPS(eth->soc->caps, MTK_RSS) ? (BIT(16 + (ring_no))) : \
448 ((ring_no) ? BIT(24 + (ring_no)) : BIT(30)))
developerfd40db22021-04-29 10:08:25 +0800449#endif
450#define MTK_RX_DONE_INT3 BIT(19)
451#define MTK_RX_DONE_INT2 BIT(18)
452#define MTK_RX_DONE_INT1 BIT(17)
453#define MTK_RX_DONE_INT0 BIT(16)
454#define MTK_TX_DONE_INT3 BIT(3)
455#define MTK_TX_DONE_INT2 BIT(2)
456#define MTK_TX_DONE_INT1 BIT(1)
457#define MTK_TX_DONE_INT0 BIT(0)
developerfd40db22021-04-29 10:08:25 +0800458#define MTK_TX_DONE_DLY BIT(28)
459#define MTK_TX_DONE_INT MTK_TX_DONE_DLY
460
461/* QDMA Interrupt grouping registers */
462#define MTK_QDMA_INT_GRP1 (QDMA_BASE + 0x220)
463#define MTK_QDMA_INT_GRP2 (QDMA_BASE + 0x224)
464#define MTK_RLS_DONE_INT BIT(0)
465
466/* QDMA Interrupt Status Register */
467#define MTK_QDMA_INT_MASK (QDMA_BASE + 0x21c)
468
developer8051e042022-04-08 13:26:36 +0800469/* QDMA DMA FSM */
470#define MTK_QDMA_FSM (QDMA_BASE + 0x234)
471
developerfd40db22021-04-29 10:08:25 +0800472/* QDMA Interrupt Mask Register */
473#define MTK_QDMA_HRED2 (QDMA_BASE + 0x244)
474
475/* QDMA TX Forward CPU Pointer Register */
476#define MTK_QTX_CTX_PTR (QDMA_BASE +0x300)
477
478/* QDMA TX Forward DMA Pointer Register */
479#define MTK_QTX_DTX_PTR (QDMA_BASE +0x304)
480
developer8051e042022-04-08 13:26:36 +0800481/* QDMA TX Forward DMA Counter */
482#define MTK_QDMA_FWD_CNT (QDMA_BASE + 0x308)
483
developerfd40db22021-04-29 10:08:25 +0800484/* QDMA TX Release CPU Pointer Register */
485#define MTK_QTX_CRX_PTR (QDMA_BASE +0x310)
486
487/* QDMA TX Release DMA Pointer Register */
488#define MTK_QTX_DRX_PTR (QDMA_BASE +0x314)
489
490/* QDMA FQ Head Pointer Register */
491#define MTK_QDMA_FQ_HEAD (QDMA_BASE +0x320)
492
493/* QDMA FQ Head Pointer Register */
494#define MTK_QDMA_FQ_TAIL (QDMA_BASE +0x324)
495
496/* QDMA FQ Free Page Counter Register */
497#define MTK_QDMA_FQ_CNT (QDMA_BASE +0x328)
498
499/* QDMA FQ Free Page Buffer Length Register */
500#define MTK_QDMA_FQ_BLEN (QDMA_BASE +0x32c)
501
developer8051e042022-04-08 13:26:36 +0800502/* WDMA Registers */
developer37482a42022-12-26 13:31:13 +0800503#define MTK_WDMA_CTX_PTR(x) (WDMA_BASE(x) + 0x8)
developer8051e042022-04-08 13:26:36 +0800504#define MTK_WDMA_DTX_PTR(x) (WDMA_BASE(x) + 0xC)
505#define MTK_WDMA_GLO_CFG(x) (WDMA_BASE(x) + 0x204)
506#define MTK_WDMA_TX_DBG_MON0(x) (WDMA_BASE(x) + 0x230)
developer37482a42022-12-26 13:31:13 +0800507#define MTK_WDMA_RX_DBG_MON1(x) (WDMA_BASE(x) + 0x3c4)
508#define MTK_WDMA_CRX_PTR(x) (WDMA_BASE(x) + 0x108)
509#define MTK_WDMA_DRX_PTR(x) (WDMA_BASE(x) + 0x10C)
developer8051e042022-04-08 13:26:36 +0800510#define MTK_CDM_TXFIFO_RDY BIT(7)
511
developer37482a42022-12-26 13:31:13 +0800512/*TDMA Register*/
513#define MTK_TDMA_GLO_CFG (0x6204)
514
developerfd40db22021-04-29 10:08:25 +0800515/* GMA1 Received Good Byte Count Register */
developer089e8852022-09-28 14:43:46 +0800516#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developerfd40db22021-04-29 10:08:25 +0800517#define MTK_GDM1_TX_GBCNT 0x1C00
518#else
519#define MTK_GDM1_TX_GBCNT 0x2400
520#endif
developer089e8852022-09-28 14:43:46 +0800521
522#if defined(CONFIG_MEDIATEK_NETSYS_V3)
523#define MTK_STAT_OFFSET 0x80
524#else
developerfd40db22021-04-29 10:08:25 +0800525#define MTK_STAT_OFFSET 0x40
developer089e8852022-09-28 14:43:46 +0800526#endif
developerfd40db22021-04-29 10:08:25 +0800527
528/* QDMA TX NUM */
529#define MTK_QDMA_TX_NUM 16
developer797e46c2022-07-29 12:05:32 +0800530#define MTK_QDMA_PAGE_NUM 8
developerfd40db22021-04-29 10:08:25 +0800531#define MTK_QDMA_TX_MASK ((MTK_QDMA_TX_NUM) - 1)
532#define QID_LOW_BITS(x) ((x) & 0xf)
533#define QID_HIGH_BITS(x) ((((x) >> 4) & 0x3) << 20)
534#define QID_BITS_V2(x) (((x) & 0x3f) << 16)
535
developerdc0d45f2021-12-27 13:01:22 +0800536#define MTK_QDMA_GMAC2_QID 8
537
developerfd40db22021-04-29 10:08:25 +0800538/* QDMA V2 descriptor txd6 */
539#define TX_DMA_INS_VLAN_V2 BIT(16)
540
541/* QDMA V2 descriptor txd5 */
542#define TX_DMA_CHKSUM_V2 (0x7 << 28)
543#define TX_DMA_TSO_V2 BIT(31)
developer089e8852022-09-28 14:43:46 +0800544#define TX_DMA_SPTAG_V3 BIT(27)
developerfd40db22021-04-29 10:08:25 +0800545
546/* QDMA V2 descriptor txd4 */
547#define TX_DMA_FPORT_SHIFT_V2 8
548#define TX_DMA_FPORT_MASK_V2 0xf
549#define TX_DMA_SWC_V2 BIT(30)
550
developerfd40db22021-04-29 10:08:25 +0800551#define MTK_TX_DMA_BUF_LEN 0x3fff
developere9356982022-07-04 09:03:20 +0800552#define MTK_TX_DMA_BUF_LEN_V2 0xffff
developerfd40db22021-04-29 10:08:25 +0800553#define MTK_TX_DMA_BUF_SHIFT 16
developere9356982022-07-04 09:03:20 +0800554#define MTK_TX_DMA_BUF_SHIFT_V2 8
developerfd40db22021-04-29 10:08:25 +0800555
developer8ecd51b2023-03-13 11:28:28 +0800556#define MTK_RX_DMA_BUF_LEN 0x3fff
557#define MTK_RX_DMA_BUF_SHIFT 16
558
developerfd40db22021-04-29 10:08:25 +0800559#define RX_DMA_SPORT_SHIFT 19
developere9356982022-07-04 09:03:20 +0800560#define RX_DMA_SPORT_SHIFT_V2 26
developerfd40db22021-04-29 10:08:25 +0800561#define RX_DMA_SPORT_MASK 0x7
developere9356982022-07-04 09:03:20 +0800562#define RX_DMA_SPORT_MASK_V2 0xf
developerfd40db22021-04-29 10:08:25 +0800563
564/* QDMA descriptor txd4 */
565#define TX_DMA_CHKSUM (0x7 << 29)
566#define TX_DMA_TSO BIT(28)
567#define TX_DMA_FPORT_SHIFT 25
568#define TX_DMA_FPORT_MASK 0x7
569#define TX_DMA_INS_VLAN BIT(16)
570
571/* QDMA descriptor txd3 */
572#define TX_DMA_OWNER_CPU BIT(31)
573#define TX_DMA_LS0 BIT(30)
developere9356982022-07-04 09:03:20 +0800574#define TX_DMA_PLEN0(_x) (((_x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
575#define TX_DMA_PLEN1(_x) ((_x) & eth->soc->txrx.dma_max_len)
developerfd40db22021-04-29 10:08:25 +0800576#define TX_DMA_SWC BIT(14)
developer089e8852022-09-28 14:43:46 +0800577#define TX_DMA_SDP1(_x) ((((u64)(_x)) >> 32) & 0xf)
developerfd40db22021-04-29 10:08:25 +0800578
579/* PDMA on MT7628 */
580#define TX_DMA_DONE BIT(31)
581#define TX_DMA_LS1 BIT(14)
582#define TX_DMA_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE)
583
584/* QDMA descriptor rxd2 */
585#define RX_DMA_DONE BIT(31)
586#define RX_DMA_LSO BIT(30)
developer8ecd51b2023-03-13 11:28:28 +0800587#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developere9356982022-07-04 09:03:20 +0800588#define RX_DMA_PLEN0(_x) (((_x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
589#define RX_DMA_GET_PLEN0(_x) (((_x) >> eth->soc->txrx.dma_len_offset) & eth->soc->txrx.dma_max_len)
developer8ecd51b2023-03-13 11:28:28 +0800590#else
591#define RX_DMA_PLEN0(_x) \
592 (((_x) & MTK_RX_DMA_BUF_LEN) << MTK_RX_DMA_BUF_SHIFT)
593#define RX_DMA_GET_PLEN0(_x) \
594 (((_x) >> MTK_RX_DMA_BUF_SHIFT) & MTK_RX_DMA_BUF_LEN)
595#endif
596
developer77d03a72021-06-06 00:06:00 +0800597#define RX_DMA_GET_AGG_CNT(_x) (((_x) >> 2) & 0xff)
598#define RX_DMA_GET_REV(_x) (((_x) >> 10) & 0x1f)
developerfd40db22021-04-29 10:08:25 +0800599#define RX_DMA_VTAG BIT(15)
developer089e8852022-09-28 14:43:46 +0800600#define RX_DMA_SDP1(_x) ((((u64)(_x)) >> 32) & 0xf)
developerfd40db22021-04-29 10:08:25 +0800601
602/* QDMA descriptor rxd3 */
603#define RX_DMA_VID(_x) ((_x) & VLAN_VID_MASK)
604#define RX_DMA_TCI(_x) ((_x) & (VLAN_PRIO_MASK | VLAN_VID_MASK))
605#define RX_DMA_VPID(_x) (((_x) >> 16) & 0xffff)
606
607/* QDMA descriptor rxd4 */
608#define RX_DMA_L4_VALID BIT(24)
609#define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
610#define RX_DMA_SPECIAL_TAG BIT(22) /* switch header in packet */
611
612#define RX_DMA_GET_SPORT(_x) (((_x) >> RX_DMA_SPORT_SHIFT) & RX_DMA_SPORT_MASK)
developere9356982022-07-04 09:03:20 +0800613#define RX_DMA_GET_SPORT_V2(_x) (((_x) >> RX_DMA_SPORT_SHIFT_V2) & RX_DMA_SPORT_MASK_V2)
developerfd40db22021-04-29 10:08:25 +0800614
615/* PDMA V2 descriptor rxd3 */
616#define RX_DMA_VTAG_V2 BIT(0)
617#define RX_DMA_L4_VALID_V2 BIT(2)
618
619/* PDMA V2 descriptor rxd4 */
620#define RX_DMA_VID_V2(_x) RX_DMA_VID(_x)
developer255bba22021-07-27 15:16:33 +0800621#define RX_DMA_TCI_V2(_x) RX_DMA_TCI(_x)
622#define RX_DMA_VPID_V2(_x) RX_DMA_VPID(_x)
developerfd40db22021-04-29 10:08:25 +0800623
developer77d03a72021-06-06 00:06:00 +0800624/* PDMA V2 descriptor rxd6 */
625#define RX_DMA_GET_FLUSH_RSN_V2(_x) ((_x) & 0x7)
626#define RX_DMA_GET_AGG_CNT_V2(_x) (((_x) >> 16) & 0xff)
developer006325c2022-10-06 16:39:50 +0800627#define RX_DMA_GET_TOPS_CRSN(_x) (((_x) >> 24) & 0xff)
developer77d03a72021-06-06 00:06:00 +0800628
developerc8acd8d2022-11-10 09:07:10 +0800629/* PHY Polling and SMI Master Control registers */
630#define MTK_PPSC 0x10000
631#define PPSC_MDC_CFG GENMASK(29, 24)
632#define PPSC_MDC_TURBO BIT(20)
developerc4d8da72023-03-16 14:37:28 +0800633#define MDC_MAX_FREQ 25000000
634#define MDC_MAX_DIVIDER 63
developerc8acd8d2022-11-10 09:07:10 +0800635
developerfd40db22021-04-29 10:08:25 +0800636/* PHY Indirect Access Control registers */
637#define MTK_PHY_IAC 0x10004
638#define PHY_IAC_ACCESS BIT(31)
639#define PHY_IAC_READ BIT(19)
developer599cda42022-05-24 15:13:31 +0800640#define PHY_IAC_READ_C45 (3 << 18)
641#define PHY_IAC_ADDR_C45 (0 << 18)
developerfd40db22021-04-29 10:08:25 +0800642#define PHY_IAC_WRITE BIT(18)
643#define PHY_IAC_START BIT(16)
developer599cda42022-05-24 15:13:31 +0800644#define PHY_IAC_START_C45 (0 << 16)
developerfd40db22021-04-29 10:08:25 +0800645#define PHY_IAC_ADDR_SHIFT 20
646#define PHY_IAC_REG_SHIFT 25
647#define PHY_IAC_TIMEOUT HZ
648
developerc8acd8d2022-11-10 09:07:10 +0800649#if defined(CONFIG_MEDIATEK_NETSYS_V3)
650#define MTK_MAC_MISC 0x10010
651#else
developerfd40db22021-04-29 10:08:25 +0800652#define MTK_MAC_MISC 0x1000c
developerc8acd8d2022-11-10 09:07:10 +0800653#endif
654#define MISC_MDC_TURBO BIT(4)
developerfd40db22021-04-29 10:08:25 +0800655#define MTK_MUX_TO_ESW BIT(0)
656
developer089e8852022-09-28 14:43:46 +0800657/* XMAC status registers */
658#define MTK_XGMAC_STS(x) ((x == MTK_GMAC3_ID) ? 0x1001C : 0x1000C)
developer2b9bc722023-03-09 11:48:44 +0800659#define MTK_XGMAC_FORCE_LINK(x) ((x == MTK_GMAC2_ID) ? BIT(31) : BIT(15))
developer089e8852022-09-28 14:43:46 +0800660#define MTK_USXGMII_PCS_LINK BIT(8)
661#define MTK_XGMAC_RX_FC BIT(5)
662#define MTK_XGMAC_TX_FC BIT(4)
663#define MTK_USXGMII_PCS_MODE GENMASK(3, 1)
664#define MTK_XGMAC_LINK_STS BIT(0)
665
666/* GSW bridge registers */
667#define MTK_GSW_CFG (0x10080)
668#define GSWTX_IPG_MASK GENMASK(19, 16)
669#define GSWTX_IPG_SHIFT 16
670#define GSWRX_IPG_MASK GENMASK(3, 0)
671#define GSWRX_IPG_SHIFT 0
672#define GSW_IPG_11 11
673
developerfd40db22021-04-29 10:08:25 +0800674/* Mac control registers */
675#define MTK_MAC_MCR(x) (0x10100 + (x * 0x100))
676#define MAC_MCR_MAX_RX_1536 BIT(24)
developerd8a29752022-08-19 13:32:03 +0800677#define MAC_MCR_IPG_CFG (BIT(18) | BIT(16) | BIT(12))
developerfd40db22021-04-29 10:08:25 +0800678#define MAC_MCR_FORCE_MODE BIT(15)
679#define MAC_MCR_TX_EN BIT(14)
680#define MAC_MCR_RX_EN BIT(13)
681#define MAC_MCR_BACKOFF_EN BIT(9)
682#define MAC_MCR_BACKPR_EN BIT(8)
developer9b725932022-11-24 16:25:56 +0800683#define MAC_MCR_FORCE_EEE1000 BIT(7)
684#define MAC_MCR_FORCE_EEE100 BIT(6)
developerfd40db22021-04-29 10:08:25 +0800685#define MAC_MCR_FORCE_RX_FC BIT(5)
686#define MAC_MCR_FORCE_TX_FC BIT(4)
687#define MAC_MCR_SPEED_1000 BIT(3)
688#define MAC_MCR_SPEED_100 BIT(2)
689#define MAC_MCR_FORCE_DPX BIT(1)
690#define MAC_MCR_FORCE_LINK BIT(0)
691#define MAC_MCR_FORCE_LINK_DOWN (MAC_MCR_FORCE_MODE)
692
developer089e8852022-09-28 14:43:46 +0800693/* XFI Mac control registers */
694#define MTK_XMAC_MCR(x) (0x12000 + ((x - 1) * 0x1000))
695#define XMAC_MCR_TRX_DISABLE 0xf
696#define XMAC_MCR_FORCE_TX_FC BIT(5)
697#define XMAC_MCR_FORCE_RX_FC BIT(4)
698
developer9b725932022-11-24 16:25:56 +0800699/* Mac EEE control registers */
700#define MTK_MAC_EEE(x) (0x10104 + (x * 0x100))
701#define MAC_EEE_WAKEUP_TIME_1000 GENMASK(31, 24)
702#define MAC_EEE_WAKEUP_TIME_100 GENMASK(23, 16)
703#define MAC_EEE_LPI_TXIDLE_THD GENMASK(15, 8)
704#define MAC_EEE_RESV0 GENMASK(7, 4)
705#define MAC_EEE_CKG_TXILDE BIT(3)
706#define MAC_EEE_CKG_RXLPI BIT(2)
707#define MAC_EEE_TX_DOWN_REQ BIT(1)
708#define MAC_EEE_LPI_MODE BIT(0)
709
developerfd40db22021-04-29 10:08:25 +0800710/* Mac status registers */
711#define MTK_MAC_MSR(x) (0x10108 + (x * 0x100))
712#define MAC_MSR_EEE1G BIT(7)
713#define MAC_MSR_EEE100M BIT(6)
714#define MAC_MSR_RX_FC BIT(5)
715#define MAC_MSR_TX_FC BIT(4)
716#define MAC_MSR_SPEED_1000 BIT(3)
717#define MAC_MSR_SPEED_100 BIT(2)
718#define MAC_MSR_SPEED_MASK (MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100)
719#define MAC_MSR_DPX BIT(1)
720#define MAC_MSR_LINK BIT(0)
721
722/* TRGMII RXC control register */
723#define TRGMII_RCK_CTRL 0x10300
724#define DQSI0(x) ((x << 0) & GENMASK(6, 0))
725#define DQSI1(x) ((x << 8) & GENMASK(14, 8))
726#define RXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
727#define RXC_RST BIT(31)
728#define RXC_DQSISEL BIT(30)
729#define RCK_CTRL_RGMII_1000 (RXC_DQSISEL | RXCTL_DMWTLAT(2) | DQSI1(16))
730#define RCK_CTRL_RGMII_10_100 RXCTL_DMWTLAT(2)
731
732#define NUM_TRGMII_CTRL 5
733
734/* TRGMII RXC control register */
735#define TRGMII_TCK_CTRL 0x10340
736#define TXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
737#define TXC_INV BIT(30)
738#define TCK_CTRL_RGMII_1000 TXCTL_DMWTLAT(2)
739#define TCK_CTRL_RGMII_10_100 (TXC_INV | TXCTL_DMWTLAT(2))
740
741/* TRGMII TX Drive Strength */
742#define TRGMII_TD_ODT(i) (0x10354 + 8 * (i))
743#define TD_DM_DRVP(x) ((x) & 0xf)
744#define TD_DM_DRVN(x) (((x) & 0xf) << 4)
745
746/* TRGMII Interface mode register */
747#define INTF_MODE 0x10390
748#define TRGMII_INTF_DIS BIT(0)
749#define TRGMII_MODE BIT(1)
750#define TRGMII_CENTRAL_ALIGNED BIT(2)
751#define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
752#define INTF_MODE_RGMII_10_100 0
753
754/* GPIO port control registers for GMAC 2*/
755#define GPIO_OD33_CTRL8 0x4c0
756#define GPIO_BIAS_CTRL 0xed0
757#define GPIO_DRV_SEL10 0xf00
758
developer0fef5222023-04-26 14:48:31 +0800759/* SoC hardware version register */
760#define HWVER_BIT_NETSYS_1_2 BIT(0)
761#define HWVER_BIT_NETSYS_3 BIT(8)
762
developerfd40db22021-04-29 10:08:25 +0800763/* ethernet subsystem chip id register */
764#define ETHSYS_CHIPID0_3 0x0
765#define ETHSYS_CHIPID4_7 0x4
766#define MT7623_ETH 7623
767#define MT7622_ETH 7622
768#define MT7621_ETH 7621
769
770/* ethernet system control register */
771#define ETHSYS_SYSCFG 0x10
772#define SYSCFG_DRAM_TYPE_DDR2 BIT(4)
773
774/* ethernet subsystem config register */
775#define ETHSYS_SYSCFG0 0x14
776#define SYSCFG0_GE_MASK 0x3
777#define SYSCFG0_GE_MODE(x, y) (x << (12 + (y * 2)))
developer089e8852022-09-28 14:43:46 +0800778#define SYSCFG0_SGMII_MASK GENMASK(9, 7)
developerfd40db22021-04-29 10:08:25 +0800779#define SYSCFG0_SGMII_GMAC1 ((2 << 8) & SYSCFG0_SGMII_MASK)
780#define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK)
781#define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
782#define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
developer089e8852022-09-28 14:43:46 +0800783#define SYSCFG0_SGMII_GMAC3_V2 BIT(7)
developerfd40db22021-04-29 10:08:25 +0800784
785
786/* ethernet subsystem clock register */
787#define ETHSYS_CLKCFG0 0x2c
788#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
789#define ETHSYS_TRGMII_MT7621_MASK (BIT(5) | BIT(6))
790#define ETHSYS_TRGMII_MT7621_APLL BIT(6)
791#define ETHSYS_TRGMII_MT7621_DDR_PLL BIT(5)
792
793/* ethernet reset control register */
developer545abf02021-07-15 17:47:01 +0800794#define ETHSYS_RSTCTRL 0x34
795#define RSTCTRL_FE BIT(6)
developer545abf02021-07-15 17:47:01 +0800796#define RSTCTRL_ETH BIT(23)
developer8051e042022-04-08 13:26:36 +0800797#if defined(CONFIG_MEDIATEK_NETSYS_V2)
798#define RSTCTRL_PPE0 BIT(30)
799#define RSTCTRL_PPE1 BIT(31)
developer37482a42022-12-26 13:31:13 +0800800#elif defined(CONFIG_MEDIATEK_NETSYS_V3)
801#define RSTCTRL_PPE0 BIT(29)
802#define RSTCTRL_PPE1 BIT(30)
803#define RSTCTRL_PPE2 BIT(31)
804#define RSTCTRL_WDMA0 BIT(24)
805#define RSTCTRL_WDMA1 BIT(25)
806#define RSTCTRL_WDMA2 BIT(26)
developera5eb8d62022-04-22 15:42:20 +0800807#else
developer8051e042022-04-08 13:26:36 +0800808#define RSTCTRL_PPE0 BIT(31)
developer37482a42022-12-26 13:31:13 +0800809#define RSTCTRL_PPE1 0
developer8051e042022-04-08 13:26:36 +0800810#endif
developer545abf02021-07-15 17:47:01 +0800811
812/* ethernet reset check idle register */
813#define ETHSYS_FE_RST_CHK_IDLE_EN 0x28
814
developer3f28d382023-03-07 16:06:30 +0800815/* ethernet dma channel agent map */
816#define ETHSYS_DMA_AG_MAP 0x408
817#define ETHSYS_DMA_AG_MAP_PDMA BIT(0)
818#define ETHSYS_DMA_AG_MAP_QDMA BIT(1)
819#define ETHSYS_DMA_AG_MAP_PPE BIT(2)
developerfd40db22021-04-29 10:08:25 +0800820
821/* SGMII subsystem config registers */
developerfd40db22021-04-29 10:08:25 +0800822#define SGMSYS_PCS_CONTROL_1 0x0
developer38afb1a2023-04-17 09:57:27 +0800823#define SGMII_BMSR GENMASK(31, 16)
developerfd40db22021-04-29 10:08:25 +0800824#define SGMII_AN_RESTART BIT(9)
825#define SGMII_ISOLATE BIT(10)
826#define SGMII_AN_ENABLE BIT(12)
827#define SGMII_LINK_STATYS BIT(18)
828#define SGMII_AN_ABILITY BIT(19)
829#define SGMII_AN_COMPLETE BIT(21)
830#define SGMII_PCS_FAULT BIT(23)
831#define SGMII_AN_EXPANSION_CLR BIT(30)
832
developer089e8852022-09-28 14:43:46 +0800833/* Register to set SGMII speed */
developer38afb1a2023-04-17 09:57:27 +0800834#define SGMSYS_PCS_ADVERTISE 0x08
835#define SGMII_ADVERTISE GENMASK(15, 0)
836#define SGMII_LPA GENMASK(31, 16)
837#define SGMII_LPA_SPEED_MASK GENMASK(11, 10)
838#define SGMII_LPA_SPEED_10 0
839#define SGMII_LPA_SPEED_100 1
840#define SGMII_LPA_SPEED_1000 2
841#define SGMII_LPA_DUPLEX BIT(12)
842#define SGMII_LPA_LINK BIT(15)
developer089e8852022-09-28 14:43:46 +0800843
developerfd40db22021-04-29 10:08:25 +0800844/* Register to programmable link timer, the unit in 2 * 8ns */
845#define SGMSYS_PCS_LINK_TIMER 0x18
846#define SGMII_LINK_TIMER_DEFAULT (0x186a0 & GENMASK(19, 0))
847
848/* Register to control remote fault */
849#define SGMSYS_SGMII_MODE 0x20
developer38afb1a2023-04-17 09:57:27 +0800850#define SGMII_IF_MODE_SGMII BIT(0)
developerfd40db22021-04-29 10:08:25 +0800851#define SGMII_SPEED_DUPLEX_AN BIT(1)
developer089e8852022-09-28 14:43:46 +0800852#define SGMII_SPEED_MASK GENMASK(3, 2)
developerfd40db22021-04-29 10:08:25 +0800853#define SGMII_SPEED_10 0x0
854#define SGMII_SPEED_100 BIT(2)
855#define SGMII_SPEED_1000 BIT(3)
developer4e8a3fd2023-04-10 18:05:44 +0800856#define SGMII_DUPLEX_HALF BIT(4)
developerfd40db22021-04-29 10:08:25 +0800857#define SGMII_IF_MODE_BIT5 BIT(5)
858#define SGMII_REMOTE_FAULT_DIS BIT(8)
859#define SGMII_CODE_SYNC_SET_VAL BIT(9)
860#define SGMII_CODE_SYNC_SET_EN BIT(10)
861#define SGMII_SEND_AN_ERROR_EN BIT(11)
862#define SGMII_IF_MODE_MASK GENMASK(5, 1)
863
developer2b76a9d2022-09-20 14:59:45 +0800864/* Register to reset SGMII design */
865#define SGMII_RESERVED_0 0x34
866#define SGMII_SW_RESET BIT(0)
867
developerfd40db22021-04-29 10:08:25 +0800868/* Register to set SGMII speed, ANA RG_ Control Signals III*/
869#define SGMSYS_ANA_RG_CS3 0x2028
870#define RG_PHY_SPEED_MASK (BIT(2) | BIT(3))
871#define RG_PHY_SPEED_1_25G 0x0
872#define RG_PHY_SPEED_3_125G BIT(2)
873
874/* Register to power up QPHY */
875#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
876#define SGMII_PHYA_PWD BIT(4)
877
developerf8ac94a2021-07-29 16:40:01 +0800878/* Register to QPHY wrapper control */
879#define SGMSYS_QPHY_WRAP_CTRL 0xec
880#define SGMII_PN_SWAP_MASK GENMASK(1, 0)
881#define SGMII_PN_SWAP_TX_RX (BIT(0) | BIT(1))
882
developer089e8852022-09-28 14:43:46 +0800883/* USXGMII subsystem config registers */
884/* Register to control speed */
885#define RG_PHY_TOP_SPEED_CTRL1 0x80C
developer95169b62023-05-12 17:58:58 +0800886#define USXGMII_RATE_UPDATE_MODE BIT(31)
887#define USXGMII_MAC_CK_GATED BIT(29)
888#define USXGMII_IF_FORCE_EN BIT(28)
889#define USXGMII_RATE_ADAPT_MODE GENMASK(10, 8)
890#define USXGMII_RATE_ADAPT_MODE_X1 0
891#define USXGMII_RATE_ADAPT_MODE_X2 1
892#define USXGMII_RATE_ADAPT_MODE_X4 2
893#define USXGMII_RATE_ADAPT_MODE_X10 3
894#define USXGMII_RATE_ADAPT_MODE_X100 4
895#define USXGMII_RATE_ADAPT_MODE_X5 5
896#define USXGMII_RATE_ADAPT_MODE_X50 6
897#define USXGMII_XFI_RX_MODE GENMASK(6, 4)
898#define USXGMII_XFI_RX_MODE_10G 0
899#define USXGMII_XFI_RX_MODE_5G 1
900#define USXGMII_XFI_TX_MODE GENMASK(2, 0)
901#define USXGMII_XFI_TX_MODE_10G 0
902#define USXGMII_XFI_TX_MODE_5G 1
developer089e8852022-09-28 14:43:46 +0800903
904/* Register to control PCS AN */
905#define RG_PCS_AN_CTRL0 0x810
developer4e8a3fd2023-04-10 18:05:44 +0800906#define USXGMII_AN_RESTART BIT(31)
developer95169b62023-05-12 17:58:58 +0800907#define USXGMII_AN_SYNC_CNT GENMASK(30, 11)
developer4e8a3fd2023-04-10 18:05:44 +0800908#define USXGMII_AN_ENABLE BIT(0)
909
developer95169b62023-05-12 17:58:58 +0800910#define RG_PCS_AN_CTRL2 0x818
911#define USXGMII_LINK_TIMER_IDLE_DETECT GENMASK(29, 20)
912#define USXGMII_LINK_TIMER_COMP_ACK_DETECT GENMASK(19, 10)
913#define USXGMII_LINK_TIMER_AN_RESTART GENMASK(9, 0)
914
915/* Register to read PCS AN status */
developer4e8a3fd2023-04-10 18:05:44 +0800916#define RG_PCS_AN_STS0 0x81C
917#define USXGMII_LPA_SPEED_MASK GENMASK(11, 9)
918#define USXGMII_LPA_SPEED_10 0
919#define USXGMII_LPA_SPEED_100 1
920#define USXGMII_LPA_SPEED_1000 2
921#define USXGMII_LPA_SPEED_10000 3
922#define USXGMII_LPA_SPEED_2500 4
923#define USXGMII_LPA_SPEED_5000 5
924#define USXGMII_LPA_DUPLEX BIT(12)
925#define USXGMII_LPA_LINK BIT(15)
926#define USXGMII_LPA_LATCH BIT(31)
developer089e8852022-09-28 14:43:46 +0800927
928/* Register to control USXGMII XFI PLL digital */
929#define XFI_PLL_DIG_GLB8 0x08
930#define RG_XFI_PLL_EN BIT(31)
931
932/* Register to control USXGMII XFI PLL analog */
933#define XFI_PLL_ANA_GLB8 0x108
934#define RG_XFI_PLL_ANA_SWWA 0x02283248
935
developerfd40db22021-04-29 10:08:25 +0800936/* Infrasys subsystem config registers */
937#define INFRA_MISC2 0x70c
938#define CO_QPHY_SEL BIT(0)
939#define GEPHY_MAC_SEL BIT(1)
940
developer024387a2022-12-07 22:18:27 +0800941/* Toprgu subsystem config registers */
942#define TOPRGU_SWSYSRST 0x18
943#define SWSYSRST_UNLOCK_KEY GENMASK(31, 24)
944#define SWSYSRST_XFI_PLL_GRST BIT(16)
945#define SWSYSRST_XFI_PEXPT1_GRST BIT(15)
946#define SWSYSRST_XFI_PEXPT0_GRST BIT(14)
developer6aa00162023-03-20 11:56:51 +0800947#define SWSYSRST_XFI1_GRST BIT(13)
948#define SWSYSRST_XFI0_GRST BIT(12)
developer024387a2022-12-07 22:18:27 +0800949#define SWSYSRST_SGMII1_GRST BIT(2)
950#define SWSYSRST_SGMII0_GRST BIT(1)
951#define TOPRGU_SWSYSRST_EN 0xFC
952
developer255bba22021-07-27 15:16:33 +0800953/* Top misc registers */
developer089e8852022-09-28 14:43:46 +0800954#define TOP_MISC_NETSYS_PCS_MUX 0x84
955#define NETSYS_PCS_MUX_MASK GENMASK(1, 0)
956#define MUX_G2_USXGMII_SEL BIT(1)
957#define MUX_HSGMII1_G1_SEL BIT(0)
developer255bba22021-07-27 15:16:33 +0800958#define USB_PHY_SWITCH_REG 0x218
959#define QPHY_SEL_MASK GENMASK(1, 0)
developerf1816a92021-11-15 12:18:02 +0800960#define SGMII_QPHY_SEL 0x2
developer255bba22021-07-27 15:16:33 +0800961
developerfd40db22021-04-29 10:08:25 +0800962/*MDIO control*/
963#define MII_MMD_ACC_CTL_REG 0x0d
964#define MII_MMD_ADDR_DATA_REG 0x0e
965#define MMD_OP_MODE_DATA BIT(14)
966
967/* MT7628/88 specific stuff */
968#define MT7628_PDMA_OFFSET 0x0800
969#define MT7628_SDM_OFFSET 0x0c00
970
971#define MT7628_TX_BASE_PTR0 (MT7628_PDMA_OFFSET + 0x00)
972#define MT7628_TX_MAX_CNT0 (MT7628_PDMA_OFFSET + 0x04)
973#define MT7628_TX_CTX_IDX0 (MT7628_PDMA_OFFSET + 0x08)
974#define MT7628_TX_DTX_IDX0 (MT7628_PDMA_OFFSET + 0x0c)
975#define MT7628_PST_DTX_IDX0 BIT(0)
976
977#define MT7628_SDM_MAC_ADRL (MT7628_SDM_OFFSET + 0x0c)
978#define MT7628_SDM_MAC_ADRH (MT7628_SDM_OFFSET + 0x10)
979
980struct mtk_rx_dma {
981 unsigned int rxd1;
982 unsigned int rxd2;
983 unsigned int rxd3;
984 unsigned int rxd4;
developere9356982022-07-04 09:03:20 +0800985} __packed __aligned(4);
986
987struct mtk_rx_dma_v2 {
988 unsigned int rxd1;
989 unsigned int rxd2;
990 unsigned int rxd3;
991 unsigned int rxd4;
developerfd40db22021-04-29 10:08:25 +0800992 unsigned int rxd5;
993 unsigned int rxd6;
994 unsigned int rxd7;
995 unsigned int rxd8;
developerfd40db22021-04-29 10:08:25 +0800996} __packed __aligned(4);
997
998struct mtk_tx_dma {
999 unsigned int txd1;
1000 unsigned int txd2;
1001 unsigned int txd3;
1002 unsigned int txd4;
developere9356982022-07-04 09:03:20 +08001003} __packed __aligned(4);
1004
1005struct mtk_tx_dma_v2 {
1006 unsigned int txd1;
1007 unsigned int txd2;
1008 unsigned int txd3;
1009 unsigned int txd4;
developerfd40db22021-04-29 10:08:25 +08001010 unsigned int txd5;
1011 unsigned int txd6;
1012 unsigned int txd7;
1013 unsigned int txd8;
developerfd40db22021-04-29 10:08:25 +08001014} __packed __aligned(4);
1015
1016struct mtk_eth;
1017struct mtk_mac;
1018
1019/* struct mtk_hw_stats - the structure that holds the traffic statistics.
1020 * @stats_lock: make sure that stats operations are atomic
1021 * @reg_offset: the status register offset of the SoC
1022 * @syncp: the refcount
1023 *
1024 * All of the supported SoCs have hardware counters for traffic statistics.
1025 * Whenever the status IRQ triggers we can read the latest stats from these
1026 * counters and store them in this struct.
1027 */
1028struct mtk_hw_stats {
1029 u64 tx_bytes;
1030 u64 tx_packets;
1031 u64 tx_skip;
1032 u64 tx_collisions;
1033 u64 rx_bytes;
1034 u64 rx_packets;
1035 u64 rx_overflow;
1036 u64 rx_fcs_errors;
1037 u64 rx_short_errors;
1038 u64 rx_long_errors;
1039 u64 rx_checksum_errors;
1040 u64 rx_flow_control_packets;
1041
1042 spinlock_t stats_lock;
1043 u32 reg_offset;
1044 struct u64_stats_sync syncp;
1045};
1046
1047enum mtk_tx_flags {
1048 /* PDMA descriptor can point at 1-2 segments. This enum allows us to
1049 * track how memory was allocated so that it can be freed properly.
1050 */
1051 MTK_TX_FLAGS_SINGLE0 = 0x01,
1052 MTK_TX_FLAGS_PAGE0 = 0x02,
1053
1054 /* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted
1055 * SKB out instead of looking up through hardware TX descriptor.
1056 */
1057 MTK_TX_FLAGS_FPORT0 = 0x04,
1058 MTK_TX_FLAGS_FPORT1 = 0x08,
developer089e8852022-09-28 14:43:46 +08001059 MTK_TX_FLAGS_FPORT2 = 0x10,
developerfd40db22021-04-29 10:08:25 +08001060};
1061
1062/* This enum allows us to identify how the clock is defined on the array of the
1063 * clock in the order
1064 */
1065enum mtk_clks_map {
1066 MTK_CLK_ETHIF,
1067 MTK_CLK_SGMIITOP,
1068 MTK_CLK_ESW,
1069 MTK_CLK_GP0,
1070 MTK_CLK_GP1,
1071 MTK_CLK_GP2,
developer1bbcf512022-11-18 16:09:33 +08001072 MTK_CLK_GP3,
1073 MTK_CLK_XGP1,
1074 MTK_CLK_XGP2,
1075 MTK_CLK_XGP3,
1076 MTK_CLK_CRYPTO,
developerfd40db22021-04-29 10:08:25 +08001077 MTK_CLK_FE,
1078 MTK_CLK_TRGPLL,
1079 MTK_CLK_SGMII_TX_250M,
1080 MTK_CLK_SGMII_RX_250M,
1081 MTK_CLK_SGMII_CDR_REF,
1082 MTK_CLK_SGMII_CDR_FB,
1083 MTK_CLK_SGMII2_TX_250M,
1084 MTK_CLK_SGMII2_RX_250M,
1085 MTK_CLK_SGMII2_CDR_REF,
1086 MTK_CLK_SGMII2_CDR_FB,
1087 MTK_CLK_SGMII_CK,
1088 MTK_CLK_ETH2PLL,
1089 MTK_CLK_WOCPU0,
1090 MTK_CLK_WOCPU1,
developer5cfc67a2022-12-29 19:06:51 +08001091 MTK_CLK_ETHWARP_WOCPU2,
1092 MTK_CLK_ETHWARP_WOCPU1,
1093 MTK_CLK_ETHWARP_WOCPU0,
1094 MTK_CLK_TOP_USXGMII_SBUS_0_SEL,
1095 MTK_CLK_TOP_USXGMII_SBUS_1_SEL,
1096 MTK_CLK_TOP_SGM_0_SEL,
1097 MTK_CLK_TOP_SGM_1_SEL,
1098 MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL,
1099 MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL,
1100 MTK_CLK_TOP_ETH_GMII_SEL,
1101 MTK_CLK_TOP_ETH_REFCK_50M_SEL,
1102 MTK_CLK_TOP_ETH_SYS_200M_SEL,
1103 MTK_CLK_TOP_ETH_SYS_SEL,
1104 MTK_CLK_TOP_ETH_XGMII_SEL,
1105 MTK_CLK_TOP_ETH_MII_SEL,
1106 MTK_CLK_TOP_NETSYS_SEL,
1107 MTK_CLK_TOP_NETSYS_500M_SEL,
1108 MTK_CLK_TOP_NETSYS_PAO_2X_SEL,
1109 MTK_CLK_TOP_NETSYS_SYNC_250M_SEL,
1110 MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL,
1111 MTK_CLK_TOP_NETSYS_WARP_SEL,
developerfd40db22021-04-29 10:08:25 +08001112 MTK_CLK_MAX
1113};
1114
1115#define MT7623_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1116 BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
1117 BIT(MTK_CLK_TRGPLL))
1118#define MT7622_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1119 BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
1120 BIT(MTK_CLK_GP2) | \
1121 BIT(MTK_CLK_SGMII_TX_250M) | \
1122 BIT(MTK_CLK_SGMII_RX_250M) | \
1123 BIT(MTK_CLK_SGMII_CDR_REF) | \
1124 BIT(MTK_CLK_SGMII_CDR_FB) | \
1125 BIT(MTK_CLK_SGMII_CK) | \
1126 BIT(MTK_CLK_ETH2PLL))
1127#define MT7621_CLKS_BITMAP (0)
1128#define MT7628_CLKS_BITMAP (0)
1129#define MT7629_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1130 BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
1131 BIT(MTK_CLK_GP2) | BIT(MTK_CLK_FE) | \
1132 BIT(MTK_CLK_SGMII_TX_250M) | \
1133 BIT(MTK_CLK_SGMII_RX_250M) | \
1134 BIT(MTK_CLK_SGMII_CDR_REF) | \
1135 BIT(MTK_CLK_SGMII_CDR_FB) | \
1136 BIT(MTK_CLK_SGMII2_TX_250M) | \
1137 BIT(MTK_CLK_SGMII2_RX_250M) | \
1138 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1139 BIT(MTK_CLK_SGMII2_CDR_FB) | \
1140 BIT(MTK_CLK_SGMII_CK) | \
1141 BIT(MTK_CLK_ETH2PLL) | BIT(MTK_CLK_SGMIITOP))
1142
1143#define MT7986_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
1144 BIT(MTK_CLK_WOCPU1) | BIT(MTK_CLK_WOCPU0) | \
1145 BIT(MTK_CLK_SGMII_TX_250M) | \
1146 BIT(MTK_CLK_SGMII_RX_250M) | \
1147 BIT(MTK_CLK_SGMII_CDR_REF) | \
1148 BIT(MTK_CLK_SGMII_CDR_FB) | \
1149 BIT(MTK_CLK_SGMII2_TX_250M) | \
1150 BIT(MTK_CLK_SGMII2_RX_250M) | \
1151 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1152 BIT(MTK_CLK_SGMII2_CDR_FB))
1153
developer255bba22021-07-27 15:16:33 +08001154
developer9e9fb4c2021-11-30 17:33:04 +08001155#define MT7981_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
1156 BIT(MTK_CLK_WOCPU0) | \
1157 BIT(MTK_CLK_SGMII_TX_250M) | \
1158 BIT(MTK_CLK_SGMII_RX_250M) | \
1159 BIT(MTK_CLK_SGMII_CDR_REF) | \
1160 BIT(MTK_CLK_SGMII_CDR_FB) | \
1161 BIT(MTK_CLK_SGMII2_TX_250M) | \
1162 BIT(MTK_CLK_SGMII2_RX_250M) | \
1163 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1164 BIT(MTK_CLK_SGMII2_CDR_FB))
developer089e8852022-09-28 14:43:46 +08001165
developer1bbcf512022-11-18 16:09:33 +08001166#define MT7988_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_ESW) | \
1167 BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
1168 BIT(MTK_CLK_GP3) | BIT(MTK_CLK_XGP1) | \
1169 BIT(MTK_CLK_XGP2) | BIT(MTK_CLK_XGP3) | \
1170 BIT(MTK_CLK_CRYPTO) | \
developer089e8852022-09-28 14:43:46 +08001171 BIT(MTK_CLK_SGMII_TX_250M) | \
1172 BIT(MTK_CLK_SGMII_RX_250M) | \
developer089e8852022-09-28 14:43:46 +08001173 BIT(MTK_CLK_SGMII2_TX_250M) | \
1174 BIT(MTK_CLK_SGMII2_RX_250M) | \
developer5cfc67a2022-12-29 19:06:51 +08001175 BIT(MTK_CLK_ETHWARP_WOCPU2) | \
1176 BIT(MTK_CLK_ETHWARP_WOCPU1) | \
1177 BIT(MTK_CLK_ETHWARP_WOCPU0) | \
1178 BIT(MTK_CLK_TOP_USXGMII_SBUS_0_SEL) | \
1179 BIT(MTK_CLK_TOP_USXGMII_SBUS_1_SEL) | \
1180 BIT(MTK_CLK_TOP_SGM_0_SEL) | \
1181 BIT(MTK_CLK_TOP_SGM_1_SEL) | \
1182 BIT(MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL) | \
1183 BIT(MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL) | \
1184 BIT(MTK_CLK_TOP_ETH_GMII_SEL) | \
1185 BIT(MTK_CLK_TOP_ETH_REFCK_50M_SEL) | \
1186 BIT(MTK_CLK_TOP_ETH_SYS_200M_SEL) | \
1187 BIT(MTK_CLK_TOP_ETH_SYS_SEL) | \
1188 BIT(MTK_CLK_TOP_ETH_XGMII_SEL) | \
1189 BIT(MTK_CLK_TOP_ETH_MII_SEL) | \
1190 BIT(MTK_CLK_TOP_NETSYS_SEL) | \
1191 BIT(MTK_CLK_TOP_NETSYS_500M_SEL) | \
1192 BIT(MTK_CLK_TOP_NETSYS_PAO_2X_SEL) | \
1193 BIT(MTK_CLK_TOP_NETSYS_SYNC_250M_SEL) | \
1194 BIT(MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL) | \
1195 BIT(MTK_CLK_TOP_NETSYS_WARP_SEL))
developer089e8852022-09-28 14:43:46 +08001196
developerfd40db22021-04-29 10:08:25 +08001197enum mtk_dev_state {
1198 MTK_HW_INIT,
1199 MTK_RESETTING
1200};
1201
developer089e8852022-09-28 14:43:46 +08001202/* PSE Port Definition */
1203enum mtk_pse_port {
1204 PSE_ADMA_PORT = 0,
1205 PSE_GDM1_PORT,
1206 PSE_GDM2_PORT,
1207 PSE_PPE0_PORT,
1208 PSE_PPE1_PORT,
1209 PSE_QDMA_TX_PORT,
1210 PSE_QDMA_RX_PORT,
1211 PSE_DROP_PORT,
1212 PSE_WDMA0_PORT,
1213 PSE_WDMA1_PORT,
1214 PSE_TDMA_PORT,
1215 PSE_NONE_PORT,
1216 PSE_PPE2_PORT,
1217 PSE_WDMA2_PORT,
1218 PSE_EIP197_PORT,
1219 PSE_GDM3_PORT,
1220 PSE_PORT_MAX
1221};
1222
1223/* GMAC Identifier */
1224enum mtk_gmac_id {
1225 MTK_GMAC1_ID = 0,
1226 MTK_GMAC2_ID,
1227 MTK_GMAC3_ID,
1228 MTK_GMAC_ID_MAX
1229};
1230
1231/* GDM Type */
1232enum mtk_gdm_type {
1233 MTK_GDM_TYPE = 0,
1234 MTK_XGDM_TYPE,
1235 MTK_GDM_TYPE_MAX
1236};
1237
developer0fef5222023-04-26 14:48:31 +08001238enum mtk_hw_id {
1239 MTK_HWID_V1 = 0,
1240 MTK_HWID_V2,
1241 MTK_HWID_MAX
1242};
1243
developer30e13e72022-11-03 10:21:24 +08001244static inline const char *gdm_type(int type)
1245{
1246 switch (type) {
1247 case MTK_GDM_TYPE:
1248 return "gdm";
1249 case MTK_XGDM_TYPE:
1250 return "xgdm";
1251 default:
1252 return "unkown";
1253 }
1254}
1255
developerfd40db22021-04-29 10:08:25 +08001256/* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at
1257 * by the TX descriptor s
1258 * @skb: The SKB pointer of the packet being sent
1259 * @dma_addr0: The base addr of the first segment
1260 * @dma_len0: The length of the first segment
1261 * @dma_addr1: The base addr of the second segment
1262 * @dma_len1: The length of the second segment
1263 */
1264struct mtk_tx_buf {
1265 struct sk_buff *skb;
1266 u32 flags;
1267 DEFINE_DMA_UNMAP_ADDR(dma_addr0);
1268 DEFINE_DMA_UNMAP_LEN(dma_len0);
1269 DEFINE_DMA_UNMAP_ADDR(dma_addr1);
1270 DEFINE_DMA_UNMAP_LEN(dma_len1);
1271};
1272
1273/* struct mtk_tx_ring - This struct holds info describing a TX ring
1274 * @dma: The descriptor ring
1275 * @buf: The memory pointed at by the ring
1276 * @phys: The physical addr of tx_buf
1277 * @next_free: Pointer to the next free descriptor
1278 * @last_free: Pointer to the last free descriptor
developerc4671b22021-05-28 13:16:42 +08001279 * @last_free_ptr: Hardware pointer value of the last free descriptor
developerfd40db22021-04-29 10:08:25 +08001280 * @thresh: The threshold of minimum amount of free descriptors
1281 * @free_count: QDMA uses a linked list. Track how many free descriptors
1282 * are present
1283 */
1284struct mtk_tx_ring {
developere9356982022-07-04 09:03:20 +08001285 void *dma;
developerfd40db22021-04-29 10:08:25 +08001286 struct mtk_tx_buf *buf;
1287 dma_addr_t phys;
developere9356982022-07-04 09:03:20 +08001288 void *next_free;
1289 void *last_free;
developerc4671b22021-05-28 13:16:42 +08001290 u32 last_free_ptr;
developerfd40db22021-04-29 10:08:25 +08001291 u16 thresh;
1292 atomic_t free_count;
1293 int dma_size;
developere9356982022-07-04 09:03:20 +08001294 void *dma_pdma; /* For MT7628/88 PDMA handling */
developerfd40db22021-04-29 10:08:25 +08001295 dma_addr_t phys_pdma;
1296 int cpu_idx;
1297};
1298
1299/* PDMA rx ring mode */
1300enum mtk_rx_flags {
1301 MTK_RX_FLAGS_NORMAL = 0,
1302 MTK_RX_FLAGS_HWLRO,
1303 MTK_RX_FLAGS_QDMA,
1304};
1305
1306/* struct mtk_rx_ring - This struct holds info describing a RX ring
1307 * @dma: The descriptor ring
1308 * @data: The memory pointed at by the ring
1309 * @phys: The physical addr of rx_buf
1310 * @frag_size: How big can each fragment be
1311 * @buf_size: The size of each packet buffer
1312 * @calc_idx: The current head of ring
developer77d03a72021-06-06 00:06:00 +08001313 * @ring_no: The index of ring
developerfd40db22021-04-29 10:08:25 +08001314 */
1315struct mtk_rx_ring {
developere9356982022-07-04 09:03:20 +08001316 void *dma;
developerfd40db22021-04-29 10:08:25 +08001317 u8 **data;
1318 dma_addr_t phys;
1319 u16 frag_size;
1320 u16 buf_size;
1321 u16 dma_size;
1322 bool calc_idx_update;
1323 u16 calc_idx;
1324 u32 crx_idx_reg;
developer77d03a72021-06-06 00:06:00 +08001325 u32 ring_no;
developerfd40db22021-04-29 10:08:25 +08001326};
1327
developer18f46a82021-07-20 21:08:21 +08001328/* struct mtk_napi - This is the structure holding NAPI-related information,
1329 * and a mtk_napi struct is binding to one interrupt group
1330 * @napi: The NAPI struct
1331 * @rx_ring: Pointer to the memory holding info about the RX ring
1332 * @irq_grp_idx: The index indicates which interrupt group that this
1333 * mtk_napi is binding to
1334 */
1335struct mtk_napi {
1336 struct napi_struct napi;
1337 struct mtk_eth *eth;
1338 struct mtk_rx_ring *rx_ring;
1339 u32 irq_grp_no;
1340};
1341
developerfd40db22021-04-29 10:08:25 +08001342enum mkt_eth_capabilities {
1343 MTK_RGMII_BIT = 0,
1344 MTK_TRGMII_BIT,
1345 MTK_SGMII_BIT,
developer30e13e72022-11-03 10:21:24 +08001346 MTK_XGMII_BIT,
developer089e8852022-09-28 14:43:46 +08001347 MTK_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001348 MTK_ESW_BIT,
1349 MTK_GEPHY_BIT,
1350 MTK_MUX_BIT,
1351 MTK_INFRA_BIT,
1352 MTK_SHARED_SGMII_BIT,
1353 MTK_HWLRO_BIT,
developer18f46a82021-07-20 21:08:21 +08001354 MTK_RSS_BIT,
developerfd40db22021-04-29 10:08:25 +08001355 MTK_SHARED_INT_BIT,
1356 MTK_TRGMII_MT7621_CLK_BIT,
1357 MTK_QDMA_BIT,
developer089e8852022-09-28 14:43:46 +08001358 MTK_NETSYS_V1_BIT,
developera2bdbd52021-05-31 19:10:17 +08001359 MTK_NETSYS_V2_BIT,
developer8ecd51b2023-03-13 11:28:28 +08001360 MTK_NETSYS_RX_V2_BIT,
developer089e8852022-09-28 14:43:46 +08001361 MTK_NETSYS_V3_BIT,
developerfd40db22021-04-29 10:08:25 +08001362 MTK_SOC_MT7628_BIT,
developer545abf02021-07-15 17:47:01 +08001363 MTK_RSTCTRL_PPE1_BIT,
developer37482a42022-12-26 13:31:13 +08001364 MTK_RSTCTRL_PPE2_BIT,
developer255bba22021-07-27 15:16:33 +08001365 MTK_U3_COPHY_V2_BIT,
developer089e8852022-09-28 14:43:46 +08001366 MTK_8GB_ADDRESSING_BIT,
developerfd40db22021-04-29 10:08:25 +08001367
1368 /* MUX BITS*/
1369 MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
1370 MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
1371 MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
developer30e13e72022-11-03 10:21:24 +08001372 MTK_ETH_MUX_GMAC2_TO_XGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001373 MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
1374 MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
developer089e8852022-09-28 14:43:46 +08001375 MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT,
1376 MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001377
1378 /* PATH BITS */
1379 MTK_ETH_PATH_GMAC1_RGMII_BIT,
1380 MTK_ETH_PATH_GMAC1_TRGMII_BIT,
1381 MTK_ETH_PATH_GMAC1_SGMII_BIT,
1382 MTK_ETH_PATH_GMAC2_RGMII_BIT,
1383 MTK_ETH_PATH_GMAC2_SGMII_BIT,
developer30e13e72022-11-03 10:21:24 +08001384 MTK_ETH_PATH_GMAC2_XGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001385 MTK_ETH_PATH_GMAC2_GEPHY_BIT,
developer089e8852022-09-28 14:43:46 +08001386 MTK_ETH_PATH_GMAC3_SGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001387 MTK_ETH_PATH_GDM1_ESW_BIT,
developer089e8852022-09-28 14:43:46 +08001388 MTK_ETH_PATH_GMAC1_USXGMII_BIT,
1389 MTK_ETH_PATH_GMAC2_USXGMII_BIT,
1390 MTK_ETH_PATH_GMAC3_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001391};
1392
1393/* Supported hardware group on SoCs */
developer425b23a2022-10-12 16:00:41 +08001394#define MTK_RGMII BIT_ULL(MTK_RGMII_BIT)
1395#define MTK_TRGMII BIT_ULL(MTK_TRGMII_BIT)
1396#define MTK_SGMII BIT_ULL(MTK_SGMII_BIT)
developer30e13e72022-11-03 10:21:24 +08001397#define MTK_XGMII BIT_ULL(MTK_XGMII_BIT)
developer425b23a2022-10-12 16:00:41 +08001398#define MTK_USXGMII BIT_ULL(MTK_USXGMII_BIT)
1399#define MTK_ESW BIT_ULL(MTK_ESW_BIT)
1400#define MTK_GEPHY BIT_ULL(MTK_GEPHY_BIT)
1401#define MTK_MUX BIT_ULL(MTK_MUX_BIT)
1402#define MTK_INFRA BIT_ULL(MTK_INFRA_BIT)
1403#define MTK_SHARED_SGMII BIT_ULL(MTK_SHARED_SGMII_BIT)
1404#define MTK_HWLRO BIT_ULL(MTK_HWLRO_BIT)
1405#define MTK_RSS BIT_ULL(MTK_RSS_BIT)
1406#define MTK_SHARED_INT BIT_ULL(MTK_SHARED_INT_BIT)
1407#define MTK_TRGMII_MT7621_CLK BIT_ULL(MTK_TRGMII_MT7621_CLK_BIT)
1408#define MTK_QDMA BIT_ULL(MTK_QDMA_BIT)
1409#define MTK_NETSYS_V1 BIT_ULL(MTK_NETSYS_V1_BIT)
1410#define MTK_NETSYS_V2 BIT_ULL(MTK_NETSYS_V2_BIT)
developer8ecd51b2023-03-13 11:28:28 +08001411#define MTK_NETSYS_RX_V2 BIT(MTK_NETSYS_RX_V2_BIT)
developer425b23a2022-10-12 16:00:41 +08001412#define MTK_NETSYS_V3 BIT_ULL(MTK_NETSYS_V3_BIT)
1413#define MTK_SOC_MT7628 BIT_ULL(MTK_SOC_MT7628_BIT)
1414#define MTK_RSTCTRL_PPE1 BIT_ULL(MTK_RSTCTRL_PPE1_BIT)
developer37482a42022-12-26 13:31:13 +08001415#define MTK_RSTCTRL_PPE2 BIT_ULL(MTK_RSTCTRL_PPE2_BIT)
developer425b23a2022-10-12 16:00:41 +08001416#define MTK_U3_COPHY_V2 BIT_ULL(MTK_U3_COPHY_V2_BIT)
1417#define MTK_8GB_ADDRESSING BIT_ULL(MTK_8GB_ADDRESSING_BIT)
developerfd40db22021-04-29 10:08:25 +08001418
1419#define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \
developer425b23a2022-10-12 16:00:41 +08001420 BIT_ULL(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
developerfd40db22021-04-29 10:08:25 +08001421#define MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY \
developer425b23a2022-10-12 16:00:41 +08001422 BIT_ULL(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
developerfd40db22021-04-29 10:08:25 +08001423#define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \
developer425b23a2022-10-12 16:00:41 +08001424 BIT_ULL(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
developer30e13e72022-11-03 10:21:24 +08001425#define MTK_ETH_MUX_GMAC2_TO_XGMII \
1426 BIT_ULL(MTK_ETH_MUX_GMAC2_TO_XGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001427#define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
developer425b23a2022-10-12 16:00:41 +08001428 BIT_ULL(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001429#define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \
developer425b23a2022-10-12 16:00:41 +08001430 BIT_ULL(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
developer089e8852022-09-28 14:43:46 +08001431#define MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII \
developer425b23a2022-10-12 16:00:41 +08001432 BIT_ULL(MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT)
developer089e8852022-09-28 14:43:46 +08001433#define MTK_ETH_MUX_GMAC123_TO_USXGMII \
developer425b23a2022-10-12 16:00:41 +08001434 BIT_ULL(MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001435
1436/* Supported path present on SoCs */
developer425b23a2022-10-12 16:00:41 +08001437#define MTK_ETH_PATH_GMAC1_RGMII BIT_ULL(MTK_ETH_PATH_GMAC1_RGMII_BIT)
1438#define MTK_ETH_PATH_GMAC1_TRGMII BIT_ULL(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
1439#define MTK_ETH_PATH_GMAC1_SGMII BIT_ULL(MTK_ETH_PATH_GMAC1_SGMII_BIT)
1440#define MTK_ETH_PATH_GMAC2_RGMII BIT_ULL(MTK_ETH_PATH_GMAC2_RGMII_BIT)
1441#define MTK_ETH_PATH_GMAC2_SGMII BIT_ULL(MTK_ETH_PATH_GMAC2_SGMII_BIT)
developer30e13e72022-11-03 10:21:24 +08001442#define MTK_ETH_PATH_GMAC2_XGMII BIT_ULL(MTK_ETH_PATH_GMAC2_XGMII_BIT)
developer425b23a2022-10-12 16:00:41 +08001443#define MTK_ETH_PATH_GMAC2_GEPHY BIT_ULL(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
1444#define MTK_ETH_PATH_GMAC3_SGMII BIT_ULL(MTK_ETH_PATH_GMAC3_SGMII_BIT)
1445#define MTK_ETH_PATH_GDM1_ESW BIT_ULL(MTK_ETH_PATH_GDM1_ESW_BIT)
1446#define MTK_ETH_PATH_GMAC1_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC1_USXGMII_BIT)
1447#define MTK_ETH_PATH_GMAC2_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC2_USXGMII_BIT)
1448#define MTK_ETH_PATH_GMAC3_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC3_USXGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001449
1450#define MTK_GMAC1_RGMII (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
1451#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
1452#define MTK_GMAC1_SGMII (MTK_ETH_PATH_GMAC1_SGMII | MTK_SGMII)
1453#define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
1454#define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
developer30e13e72022-11-03 10:21:24 +08001455#define MTK_GMAC2_XGMII (MTK_ETH_PATH_GMAC2_XGMII | MTK_XGMII)
developerfd40db22021-04-29 10:08:25 +08001456#define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
developer089e8852022-09-28 14:43:46 +08001457#define MTK_GMAC3_SGMII (MTK_ETH_PATH_GMAC3_SGMII | MTK_SGMII)
developerfd40db22021-04-29 10:08:25 +08001458#define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
developer089e8852022-09-28 14:43:46 +08001459#define MTK_GMAC1_USXGMII (MTK_ETH_PATH_GMAC1_USXGMII | MTK_USXGMII)
1460#define MTK_GMAC2_USXGMII (MTK_ETH_PATH_GMAC2_USXGMII | MTK_USXGMII)
1461#define MTK_GMAC3_USXGMII (MTK_ETH_PATH_GMAC3_USXGMII | MTK_USXGMII)
developerfd40db22021-04-29 10:08:25 +08001462
1463/* MUXes present on SoCs */
1464/* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
1465#define MTK_MUX_GDM1_TO_GMAC1_ESW (MTK_ETH_MUX_GDM1_TO_GMAC1_ESW | MTK_MUX)
1466
1467/* 0: GMAC2 -> GEPHY, 1: GMAC0 -> GePHY */
1468#define MTK_MUX_GMAC2_GMAC0_TO_GEPHY \
1469 (MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY | MTK_MUX | MTK_INFRA)
1470
1471/* 0: U3 -> QPHY, 1: GMAC2 -> QPHY */
1472#define MTK_MUX_U3_GMAC2_TO_QPHY \
1473 (MTK_ETH_MUX_U3_GMAC2_TO_QPHY | MTK_MUX | MTK_INFRA)
1474
1475/* 2: GMAC1 -> SGMII, 3: GMAC2 -> SGMII */
1476#define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
1477 (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
1478 MTK_SHARED_SGMII)
1479
developer30e13e72022-11-03 10:21:24 +08001480/* 2: GMAC2 -> XGMII */
1481#define MTK_MUX_GMAC2_TO_XGMII \
1482 (MTK_ETH_MUX_GMAC2_TO_XGMII | MTK_MUX | MTK_INFRA)
1483
developerfd40db22021-04-29 10:08:25 +08001484/* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
1485#define MTK_MUX_GMAC12_TO_GEPHY_SGMII \
1486 (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
1487
developer089e8852022-09-28 14:43:46 +08001488#define MTK_MUX_GMAC123_TO_GEPHY_SGMII \
1489 (MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII | MTK_MUX)
1490
1491#define MTK_MUX_GMAC123_TO_USXGMII \
1492 (MTK_ETH_MUX_GMAC123_TO_USXGMII | MTK_MUX | MTK_INFRA)
1493
developerfd40db22021-04-29 10:08:25 +08001494#define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
1495
1496#define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
1497 MTK_GMAC2_RGMII | MTK_SHARED_INT | \
developer089e8852022-09-28 14:43:46 +08001498 MTK_TRGMII_MT7621_CLK | MTK_QDMA | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001499
1500#define MT7622_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_SGMII | MTK_GMAC2_RGMII | \
1501 MTK_GMAC2_SGMII | MTK_GDM1_ESW | \
developer089e8852022-09-28 14:43:46 +08001502 MTK_MUX_GDM1_TO_GMAC1_ESW | MTK_NETSYS_V1 | \
developerfd40db22021-04-29 10:08:25 +08001503 MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_QDMA)
1504
1505#define MT7623_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | MTK_GMAC2_RGMII | \
developer089e8852022-09-28 14:43:46 +08001506 MTK_QDMA | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001507
developer089e8852022-09-28 14:43:46 +08001508#define MT7628_CAPS (MTK_SHARED_INT | MTK_SOC_MT7628 | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001509
1510#define MT7629_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
1511 MTK_GDM1_ESW | MTK_MUX_GDM1_TO_GMAC1_ESW | \
1512 MTK_MUX_GMAC2_GMAC0_TO_GEPHY | \
developer089e8852022-09-28 14:43:46 +08001513 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_NETSYS_V1 | \
developerfd40db22021-04-29 10:08:25 +08001514 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA)
1515
developerfd40db22021-04-29 10:08:25 +08001516#define MT7986_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \
1517 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
developer8ecd51b2023-03-13 11:28:28 +08001518 MTK_NETSYS_V2)
developerfd40db22021-04-29 10:08:25 +08001519
developer255bba22021-07-27 15:16:33 +08001520#define MT7981_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
1521 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
1522 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_U3_COPHY_V2 | \
1523 MTK_NETSYS_V2)
1524
developer089e8852022-09-28 14:43:46 +08001525#define MT7988_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC3_SGMII | \
1526 MTK_MUX_GMAC123_TO_GEPHY_SGMII | MTK_QDMA | \
developer37482a42022-12-26 13:31:13 +08001527 MTK_NETSYS_V3 | MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | \
developer089e8852022-09-28 14:43:46 +08001528 MTK_GMAC1_USXGMII | MTK_GMAC2_USXGMII | \
developer30e13e72022-11-03 10:21:24 +08001529 MTK_GMAC3_USXGMII | MTK_MUX_GMAC123_TO_USXGMII | \
developer8ecd51b2023-03-13 11:28:28 +08001530 MTK_GMAC2_XGMII | MTK_MUX_GMAC2_TO_XGMII | MTK_RSS | \
1531 MTK_NETSYS_RX_V2)
developer089e8852022-09-28 14:43:46 +08001532
developere9356982022-07-04 09:03:20 +08001533struct mtk_tx_dma_desc_info {
1534 dma_addr_t addr;
1535 u32 size;
1536 u16 vlan_tci;
1537 u16 qid;
1538 u8 gso:1;
1539 u8 csum:1;
1540 u8 vlan:1;
1541 u8 first:1;
1542 u8 last:1;
1543};
1544
developer68ce74f2023-01-03 16:11:57 +08001545struct mtk_reg_map {
1546 u32 tx_irq_mask;
1547 u32 tx_irq_status;
1548 struct {
1549 u32 rx_ptr; /* rx base pointer */
1550 u32 rx_cnt_cfg; /* rx max count configuration */
1551 u32 pcrx_ptr; /* rx cpu pointer */
1552 u32 glo_cfg; /* global configuration */
1553 u32 rst_idx; /* reset index */
1554 u32 delay_irq; /* delay interrupt */
1555 u32 irq_status; /* interrupt status */
1556 u32 irq_mask; /* interrupt mask */
1557 u32 int_grp; /* interrupt group1 */
1558 u32 int_grp2; /* interrupt group2 */
1559 } pdma;
1560 struct {
1561 u32 qtx_cfg; /* tx queue configuration */
1562 u32 qtx_sch; /* tx queue scheduler configuration */
1563 u32 rx_ptr; /* rx base pointer */
1564 u32 rx_cnt_cfg; /* rx max count configuration */
1565 u32 qcrx_ptr; /* rx cpu pointer */
1566 u32 glo_cfg; /* global configuration */
1567 u32 rst_idx; /* reset index */
1568 u32 delay_irq; /* delay interrupt */
1569 u32 fc_th; /* flow control */
1570 u32 int_grp; /* interrupt group1 */
1571 u32 int_grp2; /* interrupt group2 */
1572 u32 hred2; /* interrupt mask */
1573 u32 ctx_ptr; /* tx acquire cpu pointer */
1574 u32 dtx_ptr; /* tx acquire dma pointer */
1575 u32 crx_ptr; /* tx release cpu pointer */
1576 u32 drx_ptr; /* tx release dma pointer */
1577 u32 fq_head; /* fq head pointer */
1578 u32 fq_tail; /* fq tail pointer */
1579 u32 fq_count; /* fq free page count */
1580 u32 fq_blen; /* fq free page buffer length */
1581 u32 tx_sch_rate; /* tx scheduler rate control
1582 registers */
1583 } qdma;
1584 u32 gdm1_cnt;
1585 u32 gdma_to_ppe0;
1586 u32 ppe_base[3];
1587 u32 wdma_base[3];
1588};
1589
developerfd40db22021-04-29 10:08:25 +08001590/* struct mtk_eth_data - This is the structure holding all differences
1591 * among various plaforms
developer68ce74f2023-01-03 16:11:57 +08001592 * @reg_map Soc register map.
1593 * @ana_rgc3: The offset for register ANA_RGC3 related to
developerfd40db22021-04-29 10:08:25 +08001594 * sgmiisys syscon
1595 * @caps Flags shown the extra capability for the SoC
1596 * @hw_features Flags shown HW features
1597 * @required_clks Flags shown the bitmap for required clocks on
1598 * the target SoC
1599 * @required_pctl A bool value to show whether the SoC requires
1600 * the extra setup for those pins used by GMAC.
developere9356982022-07-04 09:03:20 +08001601 * @txd_size Tx DMA descriptor size.
1602 * @rxd_size Rx DMA descriptor size.
developer68ce74f2023-01-03 16:11:57 +08001603 * @rx_dma_l4_valid Rx DMA valid register mask.
developere9356982022-07-04 09:03:20 +08001604 * @dma_max_len Max DMA tx/rx buffer length.
1605 * @dma_len_offset Tx/Rx DMA length field offset.
developerfd40db22021-04-29 10:08:25 +08001606 */
1607struct mtk_soc_data {
developer68ce74f2023-01-03 16:11:57 +08001608 const struct mtk_reg_map *reg_map;
1609 u32 ana_rgc3;
developere3d0de22023-05-30 17:45:00 +08001610 u32 rss_num;
developer089e8852022-09-28 14:43:46 +08001611 u64 caps;
developer5cfc67a2022-12-29 19:06:51 +08001612 u64 required_clks;
developerfd40db22021-04-29 10:08:25 +08001613 bool required_pctl;
1614 netdev_features_t hw_features;
1615 bool has_sram;
developere9356982022-07-04 09:03:20 +08001616 struct {
1617 u32 txd_size;
1618 u32 rxd_size;
developer68ce74f2023-01-03 16:11:57 +08001619 u32 rx_dma_l4_valid;
developere9356982022-07-04 09:03:20 +08001620 u32 dma_max_len;
1621 u32 dma_len_offset;
1622 } txrx;
developerfd40db22021-04-29 10:08:25 +08001623};
1624
developer089e8852022-09-28 14:43:46 +08001625/* currently no SoC has more than 3 macs */
1626#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1627#define MTK_MAX_DEVS 3
1628#else
1629#define MTK_MAX_DEVS 2
1630#endif
developerfd40db22021-04-29 10:08:25 +08001631
1632#define MTK_SGMII_PHYSPEED_AN BIT(31)
1633#define MTK_SGMII_PHYSPEED_MASK GENMASK(2, 0)
1634#define MTK_SGMII_PHYSPEED_1000 BIT(0)
1635#define MTK_SGMII_PHYSPEED_2500 BIT(1)
developer089e8852022-09-28 14:43:46 +08001636#define MTK_SGMII_PHYSPEED_5000 BIT(2)
1637#define MTK_SGMII_PHYSPEED_10000 BIT(3)
developerf8ac94a2021-07-29 16:40:01 +08001638#define MTK_SGMII_PN_SWAP BIT(16)
developerfd40db22021-04-29 10:08:25 +08001639#define MTK_HAS_FLAGS(flags, _x) (((flags) & (_x)) == (_x))
1640
developer4e8a3fd2023-04-10 18:05:44 +08001641/* struct mtk_sgmii_pcs - This structure holds each sgmii regmap and associated
1642 * data
1643 * @regmap: The register map pointing at the range used to setup
1644 * SGMII modes
1645 * @regmap_pextp: The register map pointing at the range used to setup
1646 * PHYA
1647 * @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap
1648 * @id: The element is used to record the index of PCS
1649 * @pcs: Phylink PCS structure
developerfd40db22021-04-29 10:08:25 +08001650 */
developer4e8a3fd2023-04-10 18:05:44 +08001651struct mtk_sgmii_pcs {
1652 struct mtk_eth *eth;
1653 struct regmap *regmap;
1654 struct regmap *regmap_pextp;
1655 phy_interface_t interface;
1656 u32 flags;
1657 u32 ana_rgc3;
1658 u8 id;
1659 struct phylink_pcs pcs;
1660};
developerfd40db22021-04-29 10:08:25 +08001661
developer4e8a3fd2023-04-10 18:05:44 +08001662/* struct mtk_sgmii - This is the structure holding sgmii regmap and its
1663 * characteristics
1664 * @pll: The register map pointing at the range used to setup
1665 * PLL
1666 * @pcs Array of individual PCS structures
1667 */
1668struct mtk_sgmii {
1669 struct mtk_sgmii_pcs pcs[MTK_MAX_DEVS];
1670 struct regmap *pll;
developerfd40db22021-04-29 10:08:25 +08001671};
1672
developer4e8a3fd2023-04-10 18:05:44 +08001673/* struct mtk_usxgmii_pcs - This structure holds each usxgmii regmap and
1674 * associated data
1675 * @regmap: The register map pointing at the range used to setup
1676 * USXGMII modes
1677 * @regmap_pextp: The register map pointing at the range used to setup
1678 * PHYA
1679 * @id: The element is used to record the index of PCS
1680 * @pcs: Phylink PCS structure
1681 */
1682struct mtk_usxgmii_pcs {
1683 struct mtk_eth *eth;
1684 struct regmap *regmap;
1685 struct regmap *regmap_pextp;
1686 phy_interface_t interface;
1687 u8 id;
1688 struct phylink_pcs pcs;
1689};
1690
1691/* struct mtk_usxgmii - This is the structure holding usxgmii regmap and its
1692 * characteristics
1693 * @pll: The register map pointing at the range used to setup
1694 * PLL
1695 * @pcs Array of individual PCS structures
1696 */
1697struct mtk_usxgmii {
1698 struct mtk_usxgmii_pcs pcs[MTK_MAX_DEVS];
1699 struct regmap *pll;
1700};
developer8051e042022-04-08 13:26:36 +08001701
1702/* struct mtk_reset_event - This is the structure holding statistics counters
1703 * for reset events
1704 * @count: The counter is used to record the number of events
1705 */
1706struct mtk_reset_event {
1707 u32 count[32];
1708};
1709
developera2613e62022-07-01 18:29:37 +08001710/* struct mtk_phylink_priv - This is the structure holding private data for phylink
1711 * @desc: Pointer to the memory holding info about the phylink gpio
1712 * @id: The element is used to record the phy index of phylink
1713 * @phyaddr: The element is used to record the phy address of phylink
1714 * @link: The element is used to record the phy link status of phylink
1715 */
1716struct mtk_phylink_priv {
1717 struct net_device *dev;
1718 struct gpio_desc *desc;
1719 char label[16];
1720 int id;
1721 int phyaddr;
1722 int link;
1723};
1724
developerfd40db22021-04-29 10:08:25 +08001725/* struct mtk_eth - This is the main datasructure for holding the state
1726 * of the driver
1727 * @dev: The device pointer
developer3f28d382023-03-07 16:06:30 +08001728 * @dma_dev: The device pointer used for dma mapping/alloc
developerfd40db22021-04-29 10:08:25 +08001729 * @base: The mapped register i/o base
1730 * @page_lock: Make sure that register operations are atomic
1731 * @tx_irq__lock: Make sure that IRQ register operations are atomic
1732 * @rx_irq__lock: Make sure that IRQ register operations are atomic
1733 * @dummy_dev: we run 2 netdevs on 1 physical DMA ring and need a
1734 * dummy for NAPI to work
1735 * @netdev: The netdev instances
1736 * @mac: Each netdev is linked to a physical MAC
1737 * @irq: The IRQ that we are using
1738 * @msg_enable: Ethtool msg level
1739 * @ethsys: The register map pointing at the range used to setup
1740 * MII modes
1741 * @infra: The register map pointing at the range used to setup
1742 * SGMII and GePHY path
1743 * @pctl: The register map pointing at the range used to setup
1744 * GMAC port drive/slew values
1745 * @dma_refcnt: track how many netdevs are using the DMA engine
1746 * @tx_ring: Pointer to the memory holding info about the TX ring
1747 * @rx_ring: Pointer to the memory holding info about the RX ring
1748 * @rx_ring_qdma: Pointer to the memory holding info about the QDMA RX ring
1749 * @tx_napi: The TX NAPI struct
1750 * @rx_napi: The RX NAPI struct
1751 * @scratch_ring: Newer SoCs need memory for a second HW managed TX ring
1752 * @phy_scratch_ring: physical address of scratch_ring
1753 * @scratch_head: The scratch memory that scratch_ring points to.
1754 * @clks: clock array for all clocks required
1755 * @mii_bus: If there is a bus we need to create an instance for it
1756 * @pending_work: The workqueue used to reset the dma ring
1757 * @state: Initialization and runtime state of the device
1758 * @soc: Holding specific data among vaious SoCs
1759 */
1760
1761struct mtk_eth {
1762 struct device *dev;
developer3f28d382023-03-07 16:06:30 +08001763 struct device *dma_dev;
developerfd40db22021-04-29 10:08:25 +08001764 void __iomem *base;
developer089e8852022-09-28 14:43:46 +08001765 void __iomem *sram_base;
developerfd40db22021-04-29 10:08:25 +08001766 spinlock_t page_lock;
1767 spinlock_t tx_irq_lock;
1768 spinlock_t rx_irq_lock;
1769 struct net_device dummy_dev;
1770 struct net_device *netdev[MTK_MAX_DEVS];
1771 struct mtk_mac *mac[MTK_MAX_DEVS];
developer94806ec2023-05-19 14:16:44 +08001772 int irq_fe[MTK_FE_IRQ_NUM];
1773 int irq_pdma[MTK_PDMA_IRQ_NUM];
developer0fef5222023-04-26 14:48:31 +08001774 u8 hwver;
developerfd40db22021-04-29 10:08:25 +08001775 u32 msg_enable;
1776 unsigned long sysclk;
1777 struct regmap *ethsys;
1778 struct regmap *infra;
developer089e8852022-09-28 14:43:46 +08001779 struct regmap *toprgu;
developer4e8a3fd2023-04-10 18:05:44 +08001780 struct mtk_sgmii *sgmii;
1781 struct mtk_usxgmii *usxgmii;
developerfd40db22021-04-29 10:08:25 +08001782 struct regmap *pctl;
1783 bool hwlro;
1784 refcount_t dma_refcnt;
1785 struct mtk_tx_ring tx_ring;
1786 struct mtk_rx_ring rx_ring[MTK_MAX_RX_RING_NUM];
1787 struct mtk_rx_ring rx_ring_qdma;
1788 struct napi_struct tx_napi;
developer18f46a82021-07-20 21:08:21 +08001789 struct mtk_napi rx_napi[MTK_RX_NAPI_NUM];
developere9356982022-07-04 09:03:20 +08001790 void *scratch_ring;
developer8051e042022-04-08 13:26:36 +08001791 struct mtk_reset_event reset_event;
developerfd40db22021-04-29 10:08:25 +08001792 dma_addr_t phy_scratch_ring;
1793 void *scratch_head;
1794 struct clk *clks[MTK_CLK_MAX];
1795
1796 struct mii_bus *mii_bus;
1797 struct work_struct pending_work;
1798 unsigned long state;
1799
1800 const struct mtk_soc_data *soc;
1801
developerfd40db22021-04-29 10:08:25 +08001802 u32 rx_dma_l4_valid;
1803 int ip_align;
developerd82e8372022-02-09 15:00:09 +08001804 spinlock_t syscfg0_lock;
developer8051e042022-04-08 13:26:36 +08001805 struct timer_list mtk_dma_monitor_timer;
developerfd40db22021-04-29 10:08:25 +08001806};
1807
1808/* struct mtk_mac - the structure that holds the info about the MACs of the
1809 * SoC
1810 * @id: The number of the MAC
1811 * @interface: Interface mode kept for detecting change in hw settings
1812 * @of_node: Our devicetree node
1813 * @hw: Backpointer to our main datastruture
1814 * @hw_stats: Packet statistics counter
1815 */
1816struct mtk_mac {
developerfb556ca2021-10-13 10:52:09 +08001817 unsigned int id;
developerfd40db22021-04-29 10:08:25 +08001818 phy_interface_t interface;
1819 unsigned int mode;
developer089e8852022-09-28 14:43:46 +08001820 unsigned int type;
developerfd40db22021-04-29 10:08:25 +08001821 int speed;
1822 struct device_node *of_node;
1823 struct phylink *phylink;
1824 struct phylink_config phylink_config;
developera2613e62022-07-01 18:29:37 +08001825 struct mtk_phylink_priv phylink_priv;
developerfd40db22021-04-29 10:08:25 +08001826 struct mtk_eth *hw;
1827 struct mtk_hw_stats *hw_stats;
1828 __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT];
1829 int hwlro_ip_cnt;
developer4e8a3fd2023-04-10 18:05:44 +08001830 unsigned int syscfg0;
developer9b725932022-11-24 16:25:56 +08001831 bool tx_lpi_enabled;
1832 u32 tx_lpi_timer;
developerfd40db22021-04-29 10:08:25 +08001833};
1834
1835/* the struct describing the SoC. these are declared in the soc_xyz.c files */
developer7cd7e5e2022-11-17 13:57:32 +08001836extern struct mtk_eth *g_eth;
developerfd40db22021-04-29 10:08:25 +08001837extern const struct of_device_id of_mtk_match[];
developer77d03a72021-06-06 00:06:00 +08001838extern u32 mtk_hwlro_stats_ebl;
developer7979ddb2023-04-24 17:19:21 +08001839extern u32 dbg_show_level;
developerfd40db22021-04-29 10:08:25 +08001840
1841/* read the hardware status register */
1842void mtk_stats_update_mac(struct mtk_mac *mac);
1843
1844void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
1845u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
developer8051e042022-04-08 13:26:36 +08001846u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned reg);
developerfd40db22021-04-29 10:08:25 +08001847
developer4e8a3fd2023-04-10 18:05:44 +08001848struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id);
1849int mtk_sgmii_init(struct mtk_eth *eth, struct device_node *np,
developerfd40db22021-04-29 10:08:25 +08001850 u32 ana_rgc3);
developerfd40db22021-04-29 10:08:25 +08001851
1852int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
developer30e13e72022-11-03 10:21:24 +08001853int mtk_gmac_xgmii_path_setup(struct mtk_eth *eth, int mac_id);
developerfd40db22021-04-29 10:08:25 +08001854int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
1855int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
developer089e8852022-09-28 14:43:46 +08001856int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id);
developerdca0fde2022-12-14 11:40:35 +08001857void mtk_gdm_config(struct mtk_eth *eth, u32 id, u32 config);
developer8051e042022-04-08 13:26:36 +08001858void ethsys_reset(struct mtk_eth *eth, u32 reset_bits);
developerfd40db22021-04-29 10:08:25 +08001859
developer089e8852022-09-28 14:43:46 +08001860int mtk_mac2xgmii_id(struct mtk_eth *eth, int mac_id);
developer4e8a3fd2023-04-10 18:05:44 +08001861struct phylink_pcs *mtk_usxgmii_select_pcs(struct mtk_usxgmii *ss, int id);
1862int mtk_usxgmii_init(struct mtk_eth *eth, struct device_node *r);
developer089e8852022-09-28 14:43:46 +08001863int mtk_toprgu_init(struct mtk_eth *eth, struct device_node *r);
developer0baa6962023-01-31 14:25:23 +08001864int mtk_dump_usxgmii(struct regmap *pmap, char *name, u32 offset, u32 range);
developer3f28d382023-03-07 16:06:30 +08001865
1866void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
developere3d0de22023-05-30 17:45:00 +08001867int mtk_rss_set_indr_tbl(struct mtk_eth *eth, int num);
developerfd40db22021-04-29 10:08:25 +08001868#endif /* MTK_ETH_H */