blob: 74651887385c0688f8b2c57836d8821817e6f2b8 [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)
270#define MTK_RSS_INDR_TABLE_DW0 (MTK_PDMA_RSS_GLO_CFG + 0x50)
271#define MTK_RSS_INDR_TABLE_DW1 (MTK_PDMA_RSS_GLO_CFG + 0x54)
272#define MTK_RSS_INDR_TABLE_DW2 (MTK_PDMA_RSS_GLO_CFG + 0x58)
273#define MTK_RSS_INDR_TABLE_DW3 (MTK_PDMA_RSS_GLO_CFG + 0x5C)
274#define MTK_RSS_INDR_TABLE_DW4 (MTK_PDMA_RSS_GLO_CFG + 0x60)
275#define MTK_RSS_INDR_TABLE_DW5 (MTK_PDMA_RSS_GLO_CFG + 0x64)
276#define MTK_RSS_INDR_TABLE_DW6 (MTK_PDMA_RSS_GLO_CFG + 0x68)
277#define MTK_RSS_INDR_TABLE_DW7 (MTK_PDMA_RSS_GLO_CFG + 0x6C)
developer94806ec2023-05-19 14:16:44 +0800278#define MTK_RSS_INDR_TABLE_SIZE4 0x39393939
developer18f46a82021-07-20 21:08:21 +0800279
developerfd40db22021-04-29 10:08:25 +0800280/* PDMA Global Configuration Register */
281#define MTK_PDMA_GLO_CFG (PDMA_BASE + 0x204)
developer77d03a72021-06-06 00:06:00 +0800282#define MTK_RX_DMA_LRO_EN BIT(8)
developerfd40db22021-04-29 10:08:25 +0800283#define MTK_MULTI_EN BIT(10)
284#define MTK_PDMA_SIZE_8DWORDS (1 << 4)
285
developer77d03a72021-06-06 00:06:00 +0800286/* PDMA Global Configuration Register */
287#define MTK_PDMA_RX_CFG (PDMA_BASE + 0x210)
288#define MTK_PDMA_LRO_SDL (0x3000)
289#define MTK_RX_CFG_SDL_OFFSET (16)
290
developerfd40db22021-04-29 10:08:25 +0800291/* PDMA Reset Index Register */
292#define MTK_PDMA_RST_IDX (PDMA_BASE + 0x208)
293#define MTK_PST_DRX_IDX0 BIT(16)
294#define MTK_PST_DRX_IDX_CFG(x) (MTK_PST_DRX_IDX0 << (x))
295
296/* PDMA Delay Interrupt Register */
297#define MTK_PDMA_DELAY_INT (PDMA_BASE + 0x20c)
developer8ecd51b2023-03-13 11:28:28 +0800298#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer089e8852022-09-28 14:43:46 +0800299#define MTK_PDMA_RSS_DELAY_INT (PDMA_BASE + 0x2c0)
developer8ecd51b2023-03-13 11:28:28 +0800300#else
301#define MTK_PDMA_RSS_DELAY_INT (PDMA_BASE + 0x270)
302#endif
developerfd40db22021-04-29 10:08:25 +0800303#define MTK_PDMA_DELAY_RX_EN BIT(15)
304#define MTK_PDMA_DELAY_RX_PINT 4
305#define MTK_PDMA_DELAY_RX_PINT_SHIFT 8
306#define MTK_PDMA_DELAY_RX_PTIME 4
307#define MTK_PDMA_DELAY_RX_DELAY \
308 (MTK_PDMA_DELAY_RX_EN | MTK_PDMA_DELAY_RX_PTIME | \
309 (MTK_PDMA_DELAY_RX_PINT << MTK_PDMA_DELAY_RX_PINT_SHIFT))
310
311/* PDMA Interrupt Status Register */
312#define MTK_PDMA_INT_STATUS (PDMA_BASE + 0x220)
313
314/* PDMA Interrupt Mask Register */
315#define MTK_PDMA_INT_MASK (PDMA_BASE + 0x228)
316
developerfd40db22021-04-29 10:08:25 +0800317/* PDMA Interrupt grouping registers */
318#define MTK_PDMA_INT_GRP1 (PDMA_BASE + 0x250)
319#define MTK_PDMA_INT_GRP2 (PDMA_BASE + 0x254)
developer8ecd51b2023-03-13 11:28:28 +0800320#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer18f46a82021-07-20 21:08:21 +0800321#define MTK_PDMA_INT_GRP3 (PDMA_BASE + 0x258)
322#else
323#define MTK_PDMA_INT_GRP3 (PDMA_BASE + 0x22c)
324#endif
325#define MTK_LRO_RX1_DLY_INT 0xa70
326#define MTK_MAX_DELAY_INT 0x8f0f8f0f
developerfd40db22021-04-29 10:08:25 +0800327
328/* PDMA HW LRO IP Setting Registers */
developer8ecd51b2023-03-13 11:28:28 +0800329#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer77d03a72021-06-06 00:06:00 +0800330#define MTK_LRO_RX_RING0_DIP_DW0 (PDMA_BASE + 0x414)
331#else
developerfd40db22021-04-29 10:08:25 +0800332#define MTK_LRO_RX_RING0_DIP_DW0 (PDMA_BASE + 0x304)
developer77d03a72021-06-06 00:06:00 +0800333#endif
developerfd40db22021-04-29 10:08:25 +0800334#define MTK_LRO_DIP_DW0_CFG(x) (MTK_LRO_RX_RING0_DIP_DW0 + (x * 0x40))
335#define MTK_RING_MYIP_VLD BIT(9)
336
developer77d03a72021-06-06 00:06:00 +0800337/* PDMA HW LRO ALT Debug Registers */
338#define MTK_LRO_ALT_DBG (PDMA_BASE + 0x440)
339#define MTK_LRO_ALT_INDEX_OFFSET (8)
340
341/* PDMA HW LRO ALT Data Registers */
342#define MTK_LRO_ALT_DBG_DATA (PDMA_BASE + 0x444)
343
developerfd40db22021-04-29 10:08:25 +0800344/* PDMA HW LRO Ring Control Registers */
developerfd40db22021-04-29 10:08:25 +0800345#define MTK_LRO_CTRL_DW1_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW1 + (x * 0x40))
346#define MTK_LRO_CTRL_DW2_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW2 + (x * 0x40))
347#define MTK_LRO_CTRL_DW3_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW3 + (x * 0x40))
348#define MTK_RING_AGE_TIME_L ((MTK_HW_LRO_AGE_TIME & 0x3ff) << 22)
349#define MTK_RING_AGE_TIME_H ((MTK_HW_LRO_AGE_TIME >> 10) & 0x3f)
developer18f46a82021-07-20 21:08:21 +0800350#define MTK_RING_PSE_MODE (1 << 6)
developerfd40db22021-04-29 10:08:25 +0800351#define MTK_RING_AUTO_LERAN_MODE (3 << 6)
352#define MTK_RING_VLD BIT(8)
353#define MTK_RING_MAX_AGG_TIME ((MTK_HW_LRO_AGG_TIME & 0xffff) << 10)
354#define MTK_RING_MAX_AGG_CNT_L ((MTK_HW_LRO_MAX_AGG_CNT & 0x3f) << 26)
355#define MTK_RING_MAX_AGG_CNT_H ((MTK_HW_LRO_MAX_AGG_CNT >> 6) & 0x3)
356
developer77d03a72021-06-06 00:06:00 +0800357/* LRO_RX_RING_CTRL_DW masks */
358#define MTK_LRO_RING_AGG_TIME_MASK BITS(10, 25)
359#define MTK_LRO_RING_AGG_CNT_L_MASK BITS(26, 31)
360#define MTK_LRO_RING_AGG_CNT_H_MASK BITS(0, 1)
361#define MTK_LRO_RING_AGE_TIME_L_MASK BITS(22, 31)
362#define MTK_LRO_RING_AGE_TIME_H_MASK BITS(0, 5)
363
364/* LRO_RX_RING_CTRL_DW0 offsets */
365#define MTK_RX_IPV6_FORCE_OFFSET (0)
366#define MTK_RX_IPV4_FORCE_OFFSET (1)
367
368/* LRO_RX_RING_CTRL_DW1 offsets */
369#define MTK_LRO_RING_AGE_TIME_L_OFFSET (22)
370
371/* LRO_RX_RING_CTRL_DW2 offsets */
372#define MTK_LRO_RING_AGE_TIME_H_OFFSET (0)
373#define MTK_RX_MODE_OFFSET (6)
374#define MTK_RX_PORT_VALID_OFFSET (8)
375#define MTK_RX_MYIP_VALID_OFFSET (9)
376#define MTK_LRO_RING_AGG_TIME_OFFSET (10)
377#define MTK_LRO_RING_AGG_CNT_L_OFFSET (26)
378
379/* LRO_RX_RING_CTRL_DW3 offsets */
380#define MTK_LRO_RING_AGG_CNT_H_OFFSET (0)
381
382/* LRO_RX_RING_STP_DTP_DW offsets */
383#define MTK_RX_TCP_DEST_PORT_OFFSET (0)
384#define MTK_RX_TCP_SRC_PORT_OFFSET (16)
385
developerfd40db22021-04-29 10:08:25 +0800386/* QDMA TX Queue Configuration Registers */
387#define MTK_QTX_CFG(x) (QDMA_BASE + (x * 0x10))
388#define QDMA_RES_THRES 4
389
390/* QDMA TX Queue Scheduler Registers */
391#define MTK_QTX_SCH(x) (QDMA_BASE + 4 + (x * 0x10))
392
393/* QDMA RX Base Pointer Register */
394#define MTK_QRX_BASE_PTR0 (QDMA_BASE + 0x100)
395#define MTK_QRX_BASE_PTR_CFG(x) (MTK_QRX_BASE_PTR0 + ((x) * 0x10))
396
397/* QDMA RX Maximum Count Register */
398#define MTK_QRX_MAX_CNT0 (QDMA_BASE + 0x104)
399#define MTK_QRX_MAX_CNT_CFG(x) (MTK_QRX_MAX_CNT0 + ((x) * 0x10))
400
401/* QDMA RX CPU Pointer Register */
402#define MTK_QRX_CRX_IDX0 (QDMA_BASE + 0x108)
403#define MTK_QRX_CRX_IDX_CFG(x) (MTK_QRX_CRX_IDX0 + ((x) * 0x10))
404
405/* QDMA RX DMA Pointer Register */
406#define MTK_QRX_DRX_IDX0 (QDMA_BASE + 0x10c)
407
developer329d8ee2022-08-02 08:49:42 +0800408/* QDMA Page Configuration Register */
409#define MTK_QDMA_PAGE (QDMA_BASE + 0x1f0)
410
developerfd40db22021-04-29 10:08:25 +0800411/* QDMA Global Configuration Register */
412#define MTK_QDMA_GLO_CFG (QDMA_BASE + 0x204)
413#define MTK_RX_2B_OFFSET BIT(31)
developer58ab5842022-06-01 15:10:25 +0800414#define MTK_PKT_RX_WDONE BIT(27)
developerfd40db22021-04-29 10:08:25 +0800415#define MTK_RX_BT_32DWORDS (3 << 11)
416#define MTK_NDP_CO_PRO BIT(10)
417#define MTK_TX_WB_DDONE BIT(6)
418#define MTK_DMA_SIZE_16DWORDS (2 << 4)
419#define MTK_DMA_SIZE_32DWORDS (3 << 4)
420#define MTK_RX_DMA_BUSY BIT(3)
421#define MTK_TX_DMA_BUSY BIT(1)
422#define MTK_RX_DMA_EN BIT(2)
423#define MTK_TX_DMA_EN BIT(0)
424#define MTK_DMA_BUSY_TIMEOUT HZ
425
426/* QDMA V2 Global Configuration Register */
427#define MTK_CHK_DDONE_EN BIT(28)
428#define MTK_DMAD_WR_WDONE BIT(26)
429#define MTK_WCOMP_EN BIT(24)
developer2cdef092022-04-15 17:27:55 +0800430#define MTK_RESV_BUF (0x80 << 16)
developerfd40db22021-04-29 10:08:25 +0800431#define MTK_MUTLI_CNT (0x4 << 12)
developer19d84562022-04-21 17:01:06 +0800432#define MTK_RESV_BUF_MASK (0xff << 16)
developerfd40db22021-04-29 10:08:25 +0800433
434/* QDMA Reset Index Register */
435#define MTK_QDMA_RST_IDX (QDMA_BASE + 0x208)
436
437/* QDMA Delay Interrupt Register */
438#define MTK_QDMA_DELAY_INT (QDMA_BASE + 0x20c)
439
440/* QDMA Flow Control Register */
441#define MTK_QDMA_FC_THRES (QDMA_BASE + 0x210)
442#define FC_THRES_DROP_MODE BIT(20)
443#define FC_THRES_DROP_EN (7 << 16)
444#define FC_THRES_MIN 0x4444
445
446/* QDMA Interrupt Status Register */
447#define MTK_QDMA_INT_STATUS (QDMA_BASE + 0x218)
developer8ecd51b2023-03-13 11:28:28 +0800448#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer94806ec2023-05-19 14:16:44 +0800449#define MTK_RX_DONE_INT(ring_no) \
developer089e8852022-09-28 14:43:46 +0800450 (MTK_HAS_CAPS(eth->soc->caps, MTK_RSS) ? (BIT(24 + (ring_no))) : \
451 ((ring_no) ? BIT(16 + (ring_no)) : BIT(14)))
developerfd40db22021-04-29 10:08:25 +0800452#else
developer94806ec2023-05-19 14:16:44 +0800453#define MTK_RX_DONE_INT(ring_no) \
454 (MTK_HAS_CAPS(eth->soc->caps, MTK_RSS) ? (BIT(16 + (ring_no))) : \
455 ((ring_no) ? BIT(24 + (ring_no)) : BIT(30)))
developerfd40db22021-04-29 10:08:25 +0800456#endif
457#define MTK_RX_DONE_INT3 BIT(19)
458#define MTK_RX_DONE_INT2 BIT(18)
459#define MTK_RX_DONE_INT1 BIT(17)
460#define MTK_RX_DONE_INT0 BIT(16)
461#define MTK_TX_DONE_INT3 BIT(3)
462#define MTK_TX_DONE_INT2 BIT(2)
463#define MTK_TX_DONE_INT1 BIT(1)
464#define MTK_TX_DONE_INT0 BIT(0)
developerfd40db22021-04-29 10:08:25 +0800465#define MTK_TX_DONE_DLY BIT(28)
466#define MTK_TX_DONE_INT MTK_TX_DONE_DLY
467
468/* QDMA Interrupt grouping registers */
469#define MTK_QDMA_INT_GRP1 (QDMA_BASE + 0x220)
470#define MTK_QDMA_INT_GRP2 (QDMA_BASE + 0x224)
471#define MTK_RLS_DONE_INT BIT(0)
472
473/* QDMA Interrupt Status Register */
474#define MTK_QDMA_INT_MASK (QDMA_BASE + 0x21c)
475
developer8051e042022-04-08 13:26:36 +0800476/* QDMA DMA FSM */
477#define MTK_QDMA_FSM (QDMA_BASE + 0x234)
478
developerfd40db22021-04-29 10:08:25 +0800479/* QDMA Interrupt Mask Register */
480#define MTK_QDMA_HRED2 (QDMA_BASE + 0x244)
481
482/* QDMA TX Forward CPU Pointer Register */
483#define MTK_QTX_CTX_PTR (QDMA_BASE +0x300)
484
485/* QDMA TX Forward DMA Pointer Register */
486#define MTK_QTX_DTX_PTR (QDMA_BASE +0x304)
487
developer8051e042022-04-08 13:26:36 +0800488/* QDMA TX Forward DMA Counter */
489#define MTK_QDMA_FWD_CNT (QDMA_BASE + 0x308)
490
developerfd40db22021-04-29 10:08:25 +0800491/* QDMA TX Release CPU Pointer Register */
492#define MTK_QTX_CRX_PTR (QDMA_BASE +0x310)
493
494/* QDMA TX Release DMA Pointer Register */
495#define MTK_QTX_DRX_PTR (QDMA_BASE +0x314)
496
497/* QDMA FQ Head Pointer Register */
498#define MTK_QDMA_FQ_HEAD (QDMA_BASE +0x320)
499
500/* QDMA FQ Head Pointer Register */
501#define MTK_QDMA_FQ_TAIL (QDMA_BASE +0x324)
502
503/* QDMA FQ Free Page Counter Register */
504#define MTK_QDMA_FQ_CNT (QDMA_BASE +0x328)
505
506/* QDMA FQ Free Page Buffer Length Register */
507#define MTK_QDMA_FQ_BLEN (QDMA_BASE +0x32c)
508
developer8051e042022-04-08 13:26:36 +0800509/* WDMA Registers */
developer37482a42022-12-26 13:31:13 +0800510#define MTK_WDMA_CTX_PTR(x) (WDMA_BASE(x) + 0x8)
developer8051e042022-04-08 13:26:36 +0800511#define MTK_WDMA_DTX_PTR(x) (WDMA_BASE(x) + 0xC)
512#define MTK_WDMA_GLO_CFG(x) (WDMA_BASE(x) + 0x204)
513#define MTK_WDMA_TX_DBG_MON0(x) (WDMA_BASE(x) + 0x230)
developer37482a42022-12-26 13:31:13 +0800514#define MTK_WDMA_RX_DBG_MON1(x) (WDMA_BASE(x) + 0x3c4)
515#define MTK_WDMA_CRX_PTR(x) (WDMA_BASE(x) + 0x108)
516#define MTK_WDMA_DRX_PTR(x) (WDMA_BASE(x) + 0x10C)
developer8051e042022-04-08 13:26:36 +0800517#define MTK_CDM_TXFIFO_RDY BIT(7)
518
developer37482a42022-12-26 13:31:13 +0800519/*TDMA Register*/
520#define MTK_TDMA_GLO_CFG (0x6204)
521
developerfd40db22021-04-29 10:08:25 +0800522/* GMA1 Received Good Byte Count Register */
developer089e8852022-09-28 14:43:46 +0800523#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developerfd40db22021-04-29 10:08:25 +0800524#define MTK_GDM1_TX_GBCNT 0x1C00
525#else
526#define MTK_GDM1_TX_GBCNT 0x2400
527#endif
developer089e8852022-09-28 14:43:46 +0800528
529#if defined(CONFIG_MEDIATEK_NETSYS_V3)
530#define MTK_STAT_OFFSET 0x80
531#else
developerfd40db22021-04-29 10:08:25 +0800532#define MTK_STAT_OFFSET 0x40
developer089e8852022-09-28 14:43:46 +0800533#endif
developerfd40db22021-04-29 10:08:25 +0800534
535/* QDMA TX NUM */
536#define MTK_QDMA_TX_NUM 16
developer797e46c2022-07-29 12:05:32 +0800537#define MTK_QDMA_PAGE_NUM 8
developerfd40db22021-04-29 10:08:25 +0800538#define MTK_QDMA_TX_MASK ((MTK_QDMA_TX_NUM) - 1)
539#define QID_LOW_BITS(x) ((x) & 0xf)
540#define QID_HIGH_BITS(x) ((((x) >> 4) & 0x3) << 20)
541#define QID_BITS_V2(x) (((x) & 0x3f) << 16)
542
developerdc0d45f2021-12-27 13:01:22 +0800543#define MTK_QDMA_GMAC2_QID 8
544
developerfd40db22021-04-29 10:08:25 +0800545/* QDMA V2 descriptor txd6 */
546#define TX_DMA_INS_VLAN_V2 BIT(16)
547
548/* QDMA V2 descriptor txd5 */
549#define TX_DMA_CHKSUM_V2 (0x7 << 28)
550#define TX_DMA_TSO_V2 BIT(31)
developer089e8852022-09-28 14:43:46 +0800551#define TX_DMA_SPTAG_V3 BIT(27)
developerfd40db22021-04-29 10:08:25 +0800552
553/* QDMA V2 descriptor txd4 */
554#define TX_DMA_FPORT_SHIFT_V2 8
555#define TX_DMA_FPORT_MASK_V2 0xf
556#define TX_DMA_SWC_V2 BIT(30)
557
developerfd40db22021-04-29 10:08:25 +0800558#define MTK_TX_DMA_BUF_LEN 0x3fff
developere9356982022-07-04 09:03:20 +0800559#define MTK_TX_DMA_BUF_LEN_V2 0xffff
developerfd40db22021-04-29 10:08:25 +0800560#define MTK_TX_DMA_BUF_SHIFT 16
developere9356982022-07-04 09:03:20 +0800561#define MTK_TX_DMA_BUF_SHIFT_V2 8
developerfd40db22021-04-29 10:08:25 +0800562
developer8ecd51b2023-03-13 11:28:28 +0800563#define MTK_RX_DMA_BUF_LEN 0x3fff
564#define MTK_RX_DMA_BUF_SHIFT 16
565
developerfd40db22021-04-29 10:08:25 +0800566#define RX_DMA_SPORT_SHIFT 19
developere9356982022-07-04 09:03:20 +0800567#define RX_DMA_SPORT_SHIFT_V2 26
developerfd40db22021-04-29 10:08:25 +0800568#define RX_DMA_SPORT_MASK 0x7
developere9356982022-07-04 09:03:20 +0800569#define RX_DMA_SPORT_MASK_V2 0xf
developerfd40db22021-04-29 10:08:25 +0800570
571/* QDMA descriptor txd4 */
572#define TX_DMA_CHKSUM (0x7 << 29)
573#define TX_DMA_TSO BIT(28)
574#define TX_DMA_FPORT_SHIFT 25
575#define TX_DMA_FPORT_MASK 0x7
576#define TX_DMA_INS_VLAN BIT(16)
577
578/* QDMA descriptor txd3 */
579#define TX_DMA_OWNER_CPU BIT(31)
580#define TX_DMA_LS0 BIT(30)
developere9356982022-07-04 09:03:20 +0800581#define TX_DMA_PLEN0(_x) (((_x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
582#define TX_DMA_PLEN1(_x) ((_x) & eth->soc->txrx.dma_max_len)
developerfd40db22021-04-29 10:08:25 +0800583#define TX_DMA_SWC BIT(14)
developer089e8852022-09-28 14:43:46 +0800584#define TX_DMA_SDP1(_x) ((((u64)(_x)) >> 32) & 0xf)
developerfd40db22021-04-29 10:08:25 +0800585
586/* PDMA on MT7628 */
587#define TX_DMA_DONE BIT(31)
588#define TX_DMA_LS1 BIT(14)
589#define TX_DMA_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE)
590
591/* QDMA descriptor rxd2 */
592#define RX_DMA_DONE BIT(31)
593#define RX_DMA_LSO BIT(30)
developer8ecd51b2023-03-13 11:28:28 +0800594#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developere9356982022-07-04 09:03:20 +0800595#define RX_DMA_PLEN0(_x) (((_x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
596#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 +0800597#else
598#define RX_DMA_PLEN0(_x) \
599 (((_x) & MTK_RX_DMA_BUF_LEN) << MTK_RX_DMA_BUF_SHIFT)
600#define RX_DMA_GET_PLEN0(_x) \
601 (((_x) >> MTK_RX_DMA_BUF_SHIFT) & MTK_RX_DMA_BUF_LEN)
602#endif
603
developer77d03a72021-06-06 00:06:00 +0800604#define RX_DMA_GET_AGG_CNT(_x) (((_x) >> 2) & 0xff)
605#define RX_DMA_GET_REV(_x) (((_x) >> 10) & 0x1f)
developerfd40db22021-04-29 10:08:25 +0800606#define RX_DMA_VTAG BIT(15)
developer089e8852022-09-28 14:43:46 +0800607#define RX_DMA_SDP1(_x) ((((u64)(_x)) >> 32) & 0xf)
developerfd40db22021-04-29 10:08:25 +0800608
609/* QDMA descriptor rxd3 */
610#define RX_DMA_VID(_x) ((_x) & VLAN_VID_MASK)
611#define RX_DMA_TCI(_x) ((_x) & (VLAN_PRIO_MASK | VLAN_VID_MASK))
612#define RX_DMA_VPID(_x) (((_x) >> 16) & 0xffff)
613
614/* QDMA descriptor rxd4 */
615#define RX_DMA_L4_VALID BIT(24)
616#define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
617#define RX_DMA_SPECIAL_TAG BIT(22) /* switch header in packet */
618
619#define RX_DMA_GET_SPORT(_x) (((_x) >> RX_DMA_SPORT_SHIFT) & RX_DMA_SPORT_MASK)
developere9356982022-07-04 09:03:20 +0800620#define RX_DMA_GET_SPORT_V2(_x) (((_x) >> RX_DMA_SPORT_SHIFT_V2) & RX_DMA_SPORT_MASK_V2)
developerfd40db22021-04-29 10:08:25 +0800621
622/* PDMA V2 descriptor rxd3 */
623#define RX_DMA_VTAG_V2 BIT(0)
624#define RX_DMA_L4_VALID_V2 BIT(2)
625
626/* PDMA V2 descriptor rxd4 */
627#define RX_DMA_VID_V2(_x) RX_DMA_VID(_x)
developer255bba22021-07-27 15:16:33 +0800628#define RX_DMA_TCI_V2(_x) RX_DMA_TCI(_x)
629#define RX_DMA_VPID_V2(_x) RX_DMA_VPID(_x)
developerfd40db22021-04-29 10:08:25 +0800630
developer77d03a72021-06-06 00:06:00 +0800631/* PDMA V2 descriptor rxd6 */
632#define RX_DMA_GET_FLUSH_RSN_V2(_x) ((_x) & 0x7)
633#define RX_DMA_GET_AGG_CNT_V2(_x) (((_x) >> 16) & 0xff)
developer006325c2022-10-06 16:39:50 +0800634#define RX_DMA_GET_TOPS_CRSN(_x) (((_x) >> 24) & 0xff)
developer77d03a72021-06-06 00:06:00 +0800635
developerc8acd8d2022-11-10 09:07:10 +0800636/* PHY Polling and SMI Master Control registers */
637#define MTK_PPSC 0x10000
638#define PPSC_MDC_CFG GENMASK(29, 24)
639#define PPSC_MDC_TURBO BIT(20)
developerc4d8da72023-03-16 14:37:28 +0800640#define MDC_MAX_FREQ 25000000
641#define MDC_MAX_DIVIDER 63
developerc8acd8d2022-11-10 09:07:10 +0800642
developerfd40db22021-04-29 10:08:25 +0800643/* PHY Indirect Access Control registers */
644#define MTK_PHY_IAC 0x10004
645#define PHY_IAC_ACCESS BIT(31)
646#define PHY_IAC_READ BIT(19)
developer599cda42022-05-24 15:13:31 +0800647#define PHY_IAC_READ_C45 (3 << 18)
648#define PHY_IAC_ADDR_C45 (0 << 18)
developerfd40db22021-04-29 10:08:25 +0800649#define PHY_IAC_WRITE BIT(18)
650#define PHY_IAC_START BIT(16)
developer599cda42022-05-24 15:13:31 +0800651#define PHY_IAC_START_C45 (0 << 16)
developerfd40db22021-04-29 10:08:25 +0800652#define PHY_IAC_ADDR_SHIFT 20
653#define PHY_IAC_REG_SHIFT 25
654#define PHY_IAC_TIMEOUT HZ
655
developerc8acd8d2022-11-10 09:07:10 +0800656#if defined(CONFIG_MEDIATEK_NETSYS_V3)
657#define MTK_MAC_MISC 0x10010
658#else
developerfd40db22021-04-29 10:08:25 +0800659#define MTK_MAC_MISC 0x1000c
developerc8acd8d2022-11-10 09:07:10 +0800660#endif
661#define MISC_MDC_TURBO BIT(4)
developerfd40db22021-04-29 10:08:25 +0800662#define MTK_MUX_TO_ESW BIT(0)
663
developer089e8852022-09-28 14:43:46 +0800664/* XMAC status registers */
665#define MTK_XGMAC_STS(x) ((x == MTK_GMAC3_ID) ? 0x1001C : 0x1000C)
developer2b9bc722023-03-09 11:48:44 +0800666#define MTK_XGMAC_FORCE_LINK(x) ((x == MTK_GMAC2_ID) ? BIT(31) : BIT(15))
developer089e8852022-09-28 14:43:46 +0800667#define MTK_USXGMII_PCS_LINK BIT(8)
668#define MTK_XGMAC_RX_FC BIT(5)
669#define MTK_XGMAC_TX_FC BIT(4)
670#define MTK_USXGMII_PCS_MODE GENMASK(3, 1)
671#define MTK_XGMAC_LINK_STS BIT(0)
672
673/* GSW bridge registers */
674#define MTK_GSW_CFG (0x10080)
675#define GSWTX_IPG_MASK GENMASK(19, 16)
676#define GSWTX_IPG_SHIFT 16
677#define GSWRX_IPG_MASK GENMASK(3, 0)
678#define GSWRX_IPG_SHIFT 0
679#define GSW_IPG_11 11
680
developerfd40db22021-04-29 10:08:25 +0800681/* Mac control registers */
682#define MTK_MAC_MCR(x) (0x10100 + (x * 0x100))
683#define MAC_MCR_MAX_RX_1536 BIT(24)
developerd8a29752022-08-19 13:32:03 +0800684#define MAC_MCR_IPG_CFG (BIT(18) | BIT(16) | BIT(12))
developerfd40db22021-04-29 10:08:25 +0800685#define MAC_MCR_FORCE_MODE BIT(15)
686#define MAC_MCR_TX_EN BIT(14)
687#define MAC_MCR_RX_EN BIT(13)
688#define MAC_MCR_BACKOFF_EN BIT(9)
689#define MAC_MCR_BACKPR_EN BIT(8)
developer9b725932022-11-24 16:25:56 +0800690#define MAC_MCR_FORCE_EEE1000 BIT(7)
691#define MAC_MCR_FORCE_EEE100 BIT(6)
developerfd40db22021-04-29 10:08:25 +0800692#define MAC_MCR_FORCE_RX_FC BIT(5)
693#define MAC_MCR_FORCE_TX_FC BIT(4)
694#define MAC_MCR_SPEED_1000 BIT(3)
695#define MAC_MCR_SPEED_100 BIT(2)
696#define MAC_MCR_FORCE_DPX BIT(1)
697#define MAC_MCR_FORCE_LINK BIT(0)
698#define MAC_MCR_FORCE_LINK_DOWN (MAC_MCR_FORCE_MODE)
699
developer089e8852022-09-28 14:43:46 +0800700/* XFI Mac control registers */
701#define MTK_XMAC_MCR(x) (0x12000 + ((x - 1) * 0x1000))
702#define XMAC_MCR_TRX_DISABLE 0xf
703#define XMAC_MCR_FORCE_TX_FC BIT(5)
704#define XMAC_MCR_FORCE_RX_FC BIT(4)
705
developer9b725932022-11-24 16:25:56 +0800706/* Mac EEE control registers */
707#define MTK_MAC_EEE(x) (0x10104 + (x * 0x100))
708#define MAC_EEE_WAKEUP_TIME_1000 GENMASK(31, 24)
709#define MAC_EEE_WAKEUP_TIME_100 GENMASK(23, 16)
710#define MAC_EEE_LPI_TXIDLE_THD GENMASK(15, 8)
711#define MAC_EEE_RESV0 GENMASK(7, 4)
712#define MAC_EEE_CKG_TXILDE BIT(3)
713#define MAC_EEE_CKG_RXLPI BIT(2)
714#define MAC_EEE_TX_DOWN_REQ BIT(1)
715#define MAC_EEE_LPI_MODE BIT(0)
716
developerfd40db22021-04-29 10:08:25 +0800717/* Mac status registers */
718#define MTK_MAC_MSR(x) (0x10108 + (x * 0x100))
719#define MAC_MSR_EEE1G BIT(7)
720#define MAC_MSR_EEE100M BIT(6)
721#define MAC_MSR_RX_FC BIT(5)
722#define MAC_MSR_TX_FC BIT(4)
723#define MAC_MSR_SPEED_1000 BIT(3)
724#define MAC_MSR_SPEED_100 BIT(2)
725#define MAC_MSR_SPEED_MASK (MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100)
726#define MAC_MSR_DPX BIT(1)
727#define MAC_MSR_LINK BIT(0)
728
729/* TRGMII RXC control register */
730#define TRGMII_RCK_CTRL 0x10300
731#define DQSI0(x) ((x << 0) & GENMASK(6, 0))
732#define DQSI1(x) ((x << 8) & GENMASK(14, 8))
733#define RXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
734#define RXC_RST BIT(31)
735#define RXC_DQSISEL BIT(30)
736#define RCK_CTRL_RGMII_1000 (RXC_DQSISEL | RXCTL_DMWTLAT(2) | DQSI1(16))
737#define RCK_CTRL_RGMII_10_100 RXCTL_DMWTLAT(2)
738
739#define NUM_TRGMII_CTRL 5
740
741/* TRGMII RXC control register */
742#define TRGMII_TCK_CTRL 0x10340
743#define TXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
744#define TXC_INV BIT(30)
745#define TCK_CTRL_RGMII_1000 TXCTL_DMWTLAT(2)
746#define TCK_CTRL_RGMII_10_100 (TXC_INV | TXCTL_DMWTLAT(2))
747
748/* TRGMII TX Drive Strength */
749#define TRGMII_TD_ODT(i) (0x10354 + 8 * (i))
750#define TD_DM_DRVP(x) ((x) & 0xf)
751#define TD_DM_DRVN(x) (((x) & 0xf) << 4)
752
753/* TRGMII Interface mode register */
754#define INTF_MODE 0x10390
755#define TRGMII_INTF_DIS BIT(0)
756#define TRGMII_MODE BIT(1)
757#define TRGMII_CENTRAL_ALIGNED BIT(2)
758#define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
759#define INTF_MODE_RGMII_10_100 0
760
761/* GPIO port control registers for GMAC 2*/
762#define GPIO_OD33_CTRL8 0x4c0
763#define GPIO_BIAS_CTRL 0xed0
764#define GPIO_DRV_SEL10 0xf00
765
developer0fef5222023-04-26 14:48:31 +0800766/* SoC hardware version register */
767#define HWVER_BIT_NETSYS_1_2 BIT(0)
768#define HWVER_BIT_NETSYS_3 BIT(8)
769
developerfd40db22021-04-29 10:08:25 +0800770/* ethernet subsystem chip id register */
771#define ETHSYS_CHIPID0_3 0x0
772#define ETHSYS_CHIPID4_7 0x4
773#define MT7623_ETH 7623
774#define MT7622_ETH 7622
775#define MT7621_ETH 7621
776
777/* ethernet system control register */
778#define ETHSYS_SYSCFG 0x10
779#define SYSCFG_DRAM_TYPE_DDR2 BIT(4)
780
781/* ethernet subsystem config register */
782#define ETHSYS_SYSCFG0 0x14
783#define SYSCFG0_GE_MASK 0x3
784#define SYSCFG0_GE_MODE(x, y) (x << (12 + (y * 2)))
developer089e8852022-09-28 14:43:46 +0800785#define SYSCFG0_SGMII_MASK GENMASK(9, 7)
developerfd40db22021-04-29 10:08:25 +0800786#define SYSCFG0_SGMII_GMAC1 ((2 << 8) & SYSCFG0_SGMII_MASK)
787#define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK)
788#define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
789#define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
developer089e8852022-09-28 14:43:46 +0800790#define SYSCFG0_SGMII_GMAC3_V2 BIT(7)
developerfd40db22021-04-29 10:08:25 +0800791
792
793/* ethernet subsystem clock register */
794#define ETHSYS_CLKCFG0 0x2c
795#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
796#define ETHSYS_TRGMII_MT7621_MASK (BIT(5) | BIT(6))
797#define ETHSYS_TRGMII_MT7621_APLL BIT(6)
798#define ETHSYS_TRGMII_MT7621_DDR_PLL BIT(5)
799
800/* ethernet reset control register */
developer545abf02021-07-15 17:47:01 +0800801#define ETHSYS_RSTCTRL 0x34
802#define RSTCTRL_FE BIT(6)
developer545abf02021-07-15 17:47:01 +0800803#define RSTCTRL_ETH BIT(23)
developer8051e042022-04-08 13:26:36 +0800804#if defined(CONFIG_MEDIATEK_NETSYS_V2)
805#define RSTCTRL_PPE0 BIT(30)
806#define RSTCTRL_PPE1 BIT(31)
developer37482a42022-12-26 13:31:13 +0800807#elif defined(CONFIG_MEDIATEK_NETSYS_V3)
808#define RSTCTRL_PPE0 BIT(29)
809#define RSTCTRL_PPE1 BIT(30)
810#define RSTCTRL_PPE2 BIT(31)
811#define RSTCTRL_WDMA0 BIT(24)
812#define RSTCTRL_WDMA1 BIT(25)
813#define RSTCTRL_WDMA2 BIT(26)
developera5eb8d62022-04-22 15:42:20 +0800814#else
developer8051e042022-04-08 13:26:36 +0800815#define RSTCTRL_PPE0 BIT(31)
developer37482a42022-12-26 13:31:13 +0800816#define RSTCTRL_PPE1 0
developer8051e042022-04-08 13:26:36 +0800817#endif
developer545abf02021-07-15 17:47:01 +0800818
819/* ethernet reset check idle register */
820#define ETHSYS_FE_RST_CHK_IDLE_EN 0x28
821
developer3f28d382023-03-07 16:06:30 +0800822/* ethernet dma channel agent map */
823#define ETHSYS_DMA_AG_MAP 0x408
824#define ETHSYS_DMA_AG_MAP_PDMA BIT(0)
825#define ETHSYS_DMA_AG_MAP_QDMA BIT(1)
826#define ETHSYS_DMA_AG_MAP_PPE BIT(2)
developerfd40db22021-04-29 10:08:25 +0800827
828/* SGMII subsystem config registers */
developerfd40db22021-04-29 10:08:25 +0800829#define SGMSYS_PCS_CONTROL_1 0x0
developer38afb1a2023-04-17 09:57:27 +0800830#define SGMII_BMSR GENMASK(31, 16)
developerfd40db22021-04-29 10:08:25 +0800831#define SGMII_AN_RESTART BIT(9)
832#define SGMII_ISOLATE BIT(10)
833#define SGMII_AN_ENABLE BIT(12)
834#define SGMII_LINK_STATYS BIT(18)
835#define SGMII_AN_ABILITY BIT(19)
836#define SGMII_AN_COMPLETE BIT(21)
837#define SGMII_PCS_FAULT BIT(23)
838#define SGMII_AN_EXPANSION_CLR BIT(30)
839
developer089e8852022-09-28 14:43:46 +0800840/* Register to set SGMII speed */
developer38afb1a2023-04-17 09:57:27 +0800841#define SGMSYS_PCS_ADVERTISE 0x08
842#define SGMII_ADVERTISE GENMASK(15, 0)
843#define SGMII_LPA GENMASK(31, 16)
844#define SGMII_LPA_SPEED_MASK GENMASK(11, 10)
845#define SGMII_LPA_SPEED_10 0
846#define SGMII_LPA_SPEED_100 1
847#define SGMII_LPA_SPEED_1000 2
848#define SGMII_LPA_DUPLEX BIT(12)
849#define SGMII_LPA_LINK BIT(15)
developer089e8852022-09-28 14:43:46 +0800850
developerfd40db22021-04-29 10:08:25 +0800851/* Register to programmable link timer, the unit in 2 * 8ns */
852#define SGMSYS_PCS_LINK_TIMER 0x18
853#define SGMII_LINK_TIMER_DEFAULT (0x186a0 & GENMASK(19, 0))
854
855/* Register to control remote fault */
856#define SGMSYS_SGMII_MODE 0x20
developer38afb1a2023-04-17 09:57:27 +0800857#define SGMII_IF_MODE_SGMII BIT(0)
developerfd40db22021-04-29 10:08:25 +0800858#define SGMII_SPEED_DUPLEX_AN BIT(1)
developer089e8852022-09-28 14:43:46 +0800859#define SGMII_SPEED_MASK GENMASK(3, 2)
developerfd40db22021-04-29 10:08:25 +0800860#define SGMII_SPEED_10 0x0
861#define SGMII_SPEED_100 BIT(2)
862#define SGMII_SPEED_1000 BIT(3)
developer4e8a3fd2023-04-10 18:05:44 +0800863#define SGMII_DUPLEX_HALF BIT(4)
developerfd40db22021-04-29 10:08:25 +0800864#define SGMII_IF_MODE_BIT5 BIT(5)
865#define SGMII_REMOTE_FAULT_DIS BIT(8)
866#define SGMII_CODE_SYNC_SET_VAL BIT(9)
867#define SGMII_CODE_SYNC_SET_EN BIT(10)
868#define SGMII_SEND_AN_ERROR_EN BIT(11)
869#define SGMII_IF_MODE_MASK GENMASK(5, 1)
870
developer2b76a9d2022-09-20 14:59:45 +0800871/* Register to reset SGMII design */
872#define SGMII_RESERVED_0 0x34
873#define SGMII_SW_RESET BIT(0)
874
developerfd40db22021-04-29 10:08:25 +0800875/* Register to set SGMII speed, ANA RG_ Control Signals III*/
876#define SGMSYS_ANA_RG_CS3 0x2028
877#define RG_PHY_SPEED_MASK (BIT(2) | BIT(3))
878#define RG_PHY_SPEED_1_25G 0x0
879#define RG_PHY_SPEED_3_125G BIT(2)
880
881/* Register to power up QPHY */
882#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
883#define SGMII_PHYA_PWD BIT(4)
884
developerf8ac94a2021-07-29 16:40:01 +0800885/* Register to QPHY wrapper control */
886#define SGMSYS_QPHY_WRAP_CTRL 0xec
887#define SGMII_PN_SWAP_MASK GENMASK(1, 0)
888#define SGMII_PN_SWAP_TX_RX (BIT(0) | BIT(1))
889
developer089e8852022-09-28 14:43:46 +0800890/* USXGMII subsystem config registers */
891/* Register to control speed */
892#define RG_PHY_TOP_SPEED_CTRL1 0x80C
developer95169b62023-05-12 17:58:58 +0800893#define USXGMII_RATE_UPDATE_MODE BIT(31)
894#define USXGMII_MAC_CK_GATED BIT(29)
895#define USXGMII_IF_FORCE_EN BIT(28)
896#define USXGMII_RATE_ADAPT_MODE GENMASK(10, 8)
897#define USXGMII_RATE_ADAPT_MODE_X1 0
898#define USXGMII_RATE_ADAPT_MODE_X2 1
899#define USXGMII_RATE_ADAPT_MODE_X4 2
900#define USXGMII_RATE_ADAPT_MODE_X10 3
901#define USXGMII_RATE_ADAPT_MODE_X100 4
902#define USXGMII_RATE_ADAPT_MODE_X5 5
903#define USXGMII_RATE_ADAPT_MODE_X50 6
904#define USXGMII_XFI_RX_MODE GENMASK(6, 4)
905#define USXGMII_XFI_RX_MODE_10G 0
906#define USXGMII_XFI_RX_MODE_5G 1
907#define USXGMII_XFI_TX_MODE GENMASK(2, 0)
908#define USXGMII_XFI_TX_MODE_10G 0
909#define USXGMII_XFI_TX_MODE_5G 1
developer089e8852022-09-28 14:43:46 +0800910
911/* Register to control PCS AN */
912#define RG_PCS_AN_CTRL0 0x810
developer4e8a3fd2023-04-10 18:05:44 +0800913#define USXGMII_AN_RESTART BIT(31)
developer95169b62023-05-12 17:58:58 +0800914#define USXGMII_AN_SYNC_CNT GENMASK(30, 11)
developer4e8a3fd2023-04-10 18:05:44 +0800915#define USXGMII_AN_ENABLE BIT(0)
916
developer95169b62023-05-12 17:58:58 +0800917#define RG_PCS_AN_CTRL2 0x818
918#define USXGMII_LINK_TIMER_IDLE_DETECT GENMASK(29, 20)
919#define USXGMII_LINK_TIMER_COMP_ACK_DETECT GENMASK(19, 10)
920#define USXGMII_LINK_TIMER_AN_RESTART GENMASK(9, 0)
921
922/* Register to read PCS AN status */
developer4e8a3fd2023-04-10 18:05:44 +0800923#define RG_PCS_AN_STS0 0x81C
924#define USXGMII_LPA_SPEED_MASK GENMASK(11, 9)
925#define USXGMII_LPA_SPEED_10 0
926#define USXGMII_LPA_SPEED_100 1
927#define USXGMII_LPA_SPEED_1000 2
928#define USXGMII_LPA_SPEED_10000 3
929#define USXGMII_LPA_SPEED_2500 4
930#define USXGMII_LPA_SPEED_5000 5
931#define USXGMII_LPA_DUPLEX BIT(12)
932#define USXGMII_LPA_LINK BIT(15)
933#define USXGMII_LPA_LATCH BIT(31)
developer089e8852022-09-28 14:43:46 +0800934
935/* Register to control USXGMII XFI PLL digital */
936#define XFI_PLL_DIG_GLB8 0x08
937#define RG_XFI_PLL_EN BIT(31)
938
939/* Register to control USXGMII XFI PLL analog */
940#define XFI_PLL_ANA_GLB8 0x108
941#define RG_XFI_PLL_ANA_SWWA 0x02283248
942
developerfd40db22021-04-29 10:08:25 +0800943/* Infrasys subsystem config registers */
944#define INFRA_MISC2 0x70c
945#define CO_QPHY_SEL BIT(0)
946#define GEPHY_MAC_SEL BIT(1)
947
developer024387a2022-12-07 22:18:27 +0800948/* Toprgu subsystem config registers */
949#define TOPRGU_SWSYSRST 0x18
950#define SWSYSRST_UNLOCK_KEY GENMASK(31, 24)
951#define SWSYSRST_XFI_PLL_GRST BIT(16)
952#define SWSYSRST_XFI_PEXPT1_GRST BIT(15)
953#define SWSYSRST_XFI_PEXPT0_GRST BIT(14)
developer6aa00162023-03-20 11:56:51 +0800954#define SWSYSRST_XFI1_GRST BIT(13)
955#define SWSYSRST_XFI0_GRST BIT(12)
developer024387a2022-12-07 22:18:27 +0800956#define SWSYSRST_SGMII1_GRST BIT(2)
957#define SWSYSRST_SGMII0_GRST BIT(1)
958#define TOPRGU_SWSYSRST_EN 0xFC
959
developer255bba22021-07-27 15:16:33 +0800960/* Top misc registers */
developer089e8852022-09-28 14:43:46 +0800961#define TOP_MISC_NETSYS_PCS_MUX 0x84
962#define NETSYS_PCS_MUX_MASK GENMASK(1, 0)
963#define MUX_G2_USXGMII_SEL BIT(1)
964#define MUX_HSGMII1_G1_SEL BIT(0)
developer255bba22021-07-27 15:16:33 +0800965#define USB_PHY_SWITCH_REG 0x218
966#define QPHY_SEL_MASK GENMASK(1, 0)
developerf1816a92021-11-15 12:18:02 +0800967#define SGMII_QPHY_SEL 0x2
developer255bba22021-07-27 15:16:33 +0800968
developerfd40db22021-04-29 10:08:25 +0800969/*MDIO control*/
970#define MII_MMD_ACC_CTL_REG 0x0d
971#define MII_MMD_ADDR_DATA_REG 0x0e
972#define MMD_OP_MODE_DATA BIT(14)
973
974/* MT7628/88 specific stuff */
975#define MT7628_PDMA_OFFSET 0x0800
976#define MT7628_SDM_OFFSET 0x0c00
977
978#define MT7628_TX_BASE_PTR0 (MT7628_PDMA_OFFSET + 0x00)
979#define MT7628_TX_MAX_CNT0 (MT7628_PDMA_OFFSET + 0x04)
980#define MT7628_TX_CTX_IDX0 (MT7628_PDMA_OFFSET + 0x08)
981#define MT7628_TX_DTX_IDX0 (MT7628_PDMA_OFFSET + 0x0c)
982#define MT7628_PST_DTX_IDX0 BIT(0)
983
984#define MT7628_SDM_MAC_ADRL (MT7628_SDM_OFFSET + 0x0c)
985#define MT7628_SDM_MAC_ADRH (MT7628_SDM_OFFSET + 0x10)
986
987struct mtk_rx_dma {
988 unsigned int rxd1;
989 unsigned int rxd2;
990 unsigned int rxd3;
991 unsigned int rxd4;
developere9356982022-07-04 09:03:20 +0800992} __packed __aligned(4);
993
994struct mtk_rx_dma_v2 {
995 unsigned int rxd1;
996 unsigned int rxd2;
997 unsigned int rxd3;
998 unsigned int rxd4;
developerfd40db22021-04-29 10:08:25 +0800999 unsigned int rxd5;
1000 unsigned int rxd6;
1001 unsigned int rxd7;
1002 unsigned int rxd8;
developerfd40db22021-04-29 10:08:25 +08001003} __packed __aligned(4);
1004
1005struct mtk_tx_dma {
1006 unsigned int txd1;
1007 unsigned int txd2;
1008 unsigned int txd3;
1009 unsigned int txd4;
developere9356982022-07-04 09:03:20 +08001010} __packed __aligned(4);
1011
1012struct mtk_tx_dma_v2 {
1013 unsigned int txd1;
1014 unsigned int txd2;
1015 unsigned int txd3;
1016 unsigned int txd4;
developerfd40db22021-04-29 10:08:25 +08001017 unsigned int txd5;
1018 unsigned int txd6;
1019 unsigned int txd7;
1020 unsigned int txd8;
developerfd40db22021-04-29 10:08:25 +08001021} __packed __aligned(4);
1022
1023struct mtk_eth;
1024struct mtk_mac;
1025
1026/* struct mtk_hw_stats - the structure that holds the traffic statistics.
1027 * @stats_lock: make sure that stats operations are atomic
1028 * @reg_offset: the status register offset of the SoC
1029 * @syncp: the refcount
1030 *
1031 * All of the supported SoCs have hardware counters for traffic statistics.
1032 * Whenever the status IRQ triggers we can read the latest stats from these
1033 * counters and store them in this struct.
1034 */
1035struct mtk_hw_stats {
1036 u64 tx_bytes;
1037 u64 tx_packets;
1038 u64 tx_skip;
1039 u64 tx_collisions;
1040 u64 rx_bytes;
1041 u64 rx_packets;
1042 u64 rx_overflow;
1043 u64 rx_fcs_errors;
1044 u64 rx_short_errors;
1045 u64 rx_long_errors;
1046 u64 rx_checksum_errors;
1047 u64 rx_flow_control_packets;
1048
1049 spinlock_t stats_lock;
1050 u32 reg_offset;
1051 struct u64_stats_sync syncp;
1052};
1053
1054enum mtk_tx_flags {
1055 /* PDMA descriptor can point at 1-2 segments. This enum allows us to
1056 * track how memory was allocated so that it can be freed properly.
1057 */
1058 MTK_TX_FLAGS_SINGLE0 = 0x01,
1059 MTK_TX_FLAGS_PAGE0 = 0x02,
1060
1061 /* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted
1062 * SKB out instead of looking up through hardware TX descriptor.
1063 */
1064 MTK_TX_FLAGS_FPORT0 = 0x04,
1065 MTK_TX_FLAGS_FPORT1 = 0x08,
developer089e8852022-09-28 14:43:46 +08001066 MTK_TX_FLAGS_FPORT2 = 0x10,
developerfd40db22021-04-29 10:08:25 +08001067};
1068
1069/* This enum allows us to identify how the clock is defined on the array of the
1070 * clock in the order
1071 */
1072enum mtk_clks_map {
1073 MTK_CLK_ETHIF,
1074 MTK_CLK_SGMIITOP,
1075 MTK_CLK_ESW,
1076 MTK_CLK_GP0,
1077 MTK_CLK_GP1,
1078 MTK_CLK_GP2,
developer1bbcf512022-11-18 16:09:33 +08001079 MTK_CLK_GP3,
1080 MTK_CLK_XGP1,
1081 MTK_CLK_XGP2,
1082 MTK_CLK_XGP3,
1083 MTK_CLK_CRYPTO,
developerfd40db22021-04-29 10:08:25 +08001084 MTK_CLK_FE,
1085 MTK_CLK_TRGPLL,
1086 MTK_CLK_SGMII_TX_250M,
1087 MTK_CLK_SGMII_RX_250M,
1088 MTK_CLK_SGMII_CDR_REF,
1089 MTK_CLK_SGMII_CDR_FB,
1090 MTK_CLK_SGMII2_TX_250M,
1091 MTK_CLK_SGMII2_RX_250M,
1092 MTK_CLK_SGMII2_CDR_REF,
1093 MTK_CLK_SGMII2_CDR_FB,
1094 MTK_CLK_SGMII_CK,
1095 MTK_CLK_ETH2PLL,
1096 MTK_CLK_WOCPU0,
1097 MTK_CLK_WOCPU1,
developer5cfc67a2022-12-29 19:06:51 +08001098 MTK_CLK_ETHWARP_WOCPU2,
1099 MTK_CLK_ETHWARP_WOCPU1,
1100 MTK_CLK_ETHWARP_WOCPU0,
1101 MTK_CLK_TOP_USXGMII_SBUS_0_SEL,
1102 MTK_CLK_TOP_USXGMII_SBUS_1_SEL,
1103 MTK_CLK_TOP_SGM_0_SEL,
1104 MTK_CLK_TOP_SGM_1_SEL,
1105 MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL,
1106 MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL,
1107 MTK_CLK_TOP_ETH_GMII_SEL,
1108 MTK_CLK_TOP_ETH_REFCK_50M_SEL,
1109 MTK_CLK_TOP_ETH_SYS_200M_SEL,
1110 MTK_CLK_TOP_ETH_SYS_SEL,
1111 MTK_CLK_TOP_ETH_XGMII_SEL,
1112 MTK_CLK_TOP_ETH_MII_SEL,
1113 MTK_CLK_TOP_NETSYS_SEL,
1114 MTK_CLK_TOP_NETSYS_500M_SEL,
1115 MTK_CLK_TOP_NETSYS_PAO_2X_SEL,
1116 MTK_CLK_TOP_NETSYS_SYNC_250M_SEL,
1117 MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL,
1118 MTK_CLK_TOP_NETSYS_WARP_SEL,
developerfd40db22021-04-29 10:08:25 +08001119 MTK_CLK_MAX
1120};
1121
1122#define MT7623_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1123 BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
1124 BIT(MTK_CLK_TRGPLL))
1125#define MT7622_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1126 BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
1127 BIT(MTK_CLK_GP2) | \
1128 BIT(MTK_CLK_SGMII_TX_250M) | \
1129 BIT(MTK_CLK_SGMII_RX_250M) | \
1130 BIT(MTK_CLK_SGMII_CDR_REF) | \
1131 BIT(MTK_CLK_SGMII_CDR_FB) | \
1132 BIT(MTK_CLK_SGMII_CK) | \
1133 BIT(MTK_CLK_ETH2PLL))
1134#define MT7621_CLKS_BITMAP (0)
1135#define MT7628_CLKS_BITMAP (0)
1136#define MT7629_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1137 BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
1138 BIT(MTK_CLK_GP2) | BIT(MTK_CLK_FE) | \
1139 BIT(MTK_CLK_SGMII_TX_250M) | \
1140 BIT(MTK_CLK_SGMII_RX_250M) | \
1141 BIT(MTK_CLK_SGMII_CDR_REF) | \
1142 BIT(MTK_CLK_SGMII_CDR_FB) | \
1143 BIT(MTK_CLK_SGMII2_TX_250M) | \
1144 BIT(MTK_CLK_SGMII2_RX_250M) | \
1145 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1146 BIT(MTK_CLK_SGMII2_CDR_FB) | \
1147 BIT(MTK_CLK_SGMII_CK) | \
1148 BIT(MTK_CLK_ETH2PLL) | BIT(MTK_CLK_SGMIITOP))
1149
1150#define MT7986_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
1151 BIT(MTK_CLK_WOCPU1) | BIT(MTK_CLK_WOCPU0) | \
1152 BIT(MTK_CLK_SGMII_TX_250M) | \
1153 BIT(MTK_CLK_SGMII_RX_250M) | \
1154 BIT(MTK_CLK_SGMII_CDR_REF) | \
1155 BIT(MTK_CLK_SGMII_CDR_FB) | \
1156 BIT(MTK_CLK_SGMII2_TX_250M) | \
1157 BIT(MTK_CLK_SGMII2_RX_250M) | \
1158 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1159 BIT(MTK_CLK_SGMII2_CDR_FB))
1160
developer255bba22021-07-27 15:16:33 +08001161
developer9e9fb4c2021-11-30 17:33:04 +08001162#define MT7981_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
1163 BIT(MTK_CLK_WOCPU0) | \
1164 BIT(MTK_CLK_SGMII_TX_250M) | \
1165 BIT(MTK_CLK_SGMII_RX_250M) | \
1166 BIT(MTK_CLK_SGMII_CDR_REF) | \
1167 BIT(MTK_CLK_SGMII_CDR_FB) | \
1168 BIT(MTK_CLK_SGMII2_TX_250M) | \
1169 BIT(MTK_CLK_SGMII2_RX_250M) | \
1170 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1171 BIT(MTK_CLK_SGMII2_CDR_FB))
developer089e8852022-09-28 14:43:46 +08001172
developer1bbcf512022-11-18 16:09:33 +08001173#define MT7988_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_ESW) | \
1174 BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
1175 BIT(MTK_CLK_GP3) | BIT(MTK_CLK_XGP1) | \
1176 BIT(MTK_CLK_XGP2) | BIT(MTK_CLK_XGP3) | \
1177 BIT(MTK_CLK_CRYPTO) | \
developer089e8852022-09-28 14:43:46 +08001178 BIT(MTK_CLK_SGMII_TX_250M) | \
1179 BIT(MTK_CLK_SGMII_RX_250M) | \
developer089e8852022-09-28 14:43:46 +08001180 BIT(MTK_CLK_SGMII2_TX_250M) | \
1181 BIT(MTK_CLK_SGMII2_RX_250M) | \
developer5cfc67a2022-12-29 19:06:51 +08001182 BIT(MTK_CLK_ETHWARP_WOCPU2) | \
1183 BIT(MTK_CLK_ETHWARP_WOCPU1) | \
1184 BIT(MTK_CLK_ETHWARP_WOCPU0) | \
1185 BIT(MTK_CLK_TOP_USXGMII_SBUS_0_SEL) | \
1186 BIT(MTK_CLK_TOP_USXGMII_SBUS_1_SEL) | \
1187 BIT(MTK_CLK_TOP_SGM_0_SEL) | \
1188 BIT(MTK_CLK_TOP_SGM_1_SEL) | \
1189 BIT(MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL) | \
1190 BIT(MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL) | \
1191 BIT(MTK_CLK_TOP_ETH_GMII_SEL) | \
1192 BIT(MTK_CLK_TOP_ETH_REFCK_50M_SEL) | \
1193 BIT(MTK_CLK_TOP_ETH_SYS_200M_SEL) | \
1194 BIT(MTK_CLK_TOP_ETH_SYS_SEL) | \
1195 BIT(MTK_CLK_TOP_ETH_XGMII_SEL) | \
1196 BIT(MTK_CLK_TOP_ETH_MII_SEL) | \
1197 BIT(MTK_CLK_TOP_NETSYS_SEL) | \
1198 BIT(MTK_CLK_TOP_NETSYS_500M_SEL) | \
1199 BIT(MTK_CLK_TOP_NETSYS_PAO_2X_SEL) | \
1200 BIT(MTK_CLK_TOP_NETSYS_SYNC_250M_SEL) | \
1201 BIT(MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL) | \
1202 BIT(MTK_CLK_TOP_NETSYS_WARP_SEL))
developer089e8852022-09-28 14:43:46 +08001203
developerfd40db22021-04-29 10:08:25 +08001204enum mtk_dev_state {
1205 MTK_HW_INIT,
1206 MTK_RESETTING
1207};
1208
developer089e8852022-09-28 14:43:46 +08001209/* PSE Port Definition */
1210enum mtk_pse_port {
1211 PSE_ADMA_PORT = 0,
1212 PSE_GDM1_PORT,
1213 PSE_GDM2_PORT,
1214 PSE_PPE0_PORT,
1215 PSE_PPE1_PORT,
1216 PSE_QDMA_TX_PORT,
1217 PSE_QDMA_RX_PORT,
1218 PSE_DROP_PORT,
1219 PSE_WDMA0_PORT,
1220 PSE_WDMA1_PORT,
1221 PSE_TDMA_PORT,
1222 PSE_NONE_PORT,
1223 PSE_PPE2_PORT,
1224 PSE_WDMA2_PORT,
1225 PSE_EIP197_PORT,
1226 PSE_GDM3_PORT,
1227 PSE_PORT_MAX
1228};
1229
1230/* GMAC Identifier */
1231enum mtk_gmac_id {
1232 MTK_GMAC1_ID = 0,
1233 MTK_GMAC2_ID,
1234 MTK_GMAC3_ID,
1235 MTK_GMAC_ID_MAX
1236};
1237
1238/* GDM Type */
1239enum mtk_gdm_type {
1240 MTK_GDM_TYPE = 0,
1241 MTK_XGDM_TYPE,
1242 MTK_GDM_TYPE_MAX
1243};
1244
developer0fef5222023-04-26 14:48:31 +08001245enum mtk_hw_id {
1246 MTK_HWID_V1 = 0,
1247 MTK_HWID_V2,
1248 MTK_HWID_MAX
1249};
1250
developer30e13e72022-11-03 10:21:24 +08001251static inline const char *gdm_type(int type)
1252{
1253 switch (type) {
1254 case MTK_GDM_TYPE:
1255 return "gdm";
1256 case MTK_XGDM_TYPE:
1257 return "xgdm";
1258 default:
1259 return "unkown";
1260 }
1261}
1262
developerfd40db22021-04-29 10:08:25 +08001263/* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at
1264 * by the TX descriptor s
1265 * @skb: The SKB pointer of the packet being sent
1266 * @dma_addr0: The base addr of the first segment
1267 * @dma_len0: The length of the first segment
1268 * @dma_addr1: The base addr of the second segment
1269 * @dma_len1: The length of the second segment
1270 */
1271struct mtk_tx_buf {
1272 struct sk_buff *skb;
1273 u32 flags;
1274 DEFINE_DMA_UNMAP_ADDR(dma_addr0);
1275 DEFINE_DMA_UNMAP_LEN(dma_len0);
1276 DEFINE_DMA_UNMAP_ADDR(dma_addr1);
1277 DEFINE_DMA_UNMAP_LEN(dma_len1);
1278};
1279
1280/* struct mtk_tx_ring - This struct holds info describing a TX ring
1281 * @dma: The descriptor ring
1282 * @buf: The memory pointed at by the ring
1283 * @phys: The physical addr of tx_buf
1284 * @next_free: Pointer to the next free descriptor
1285 * @last_free: Pointer to the last free descriptor
developerc4671b22021-05-28 13:16:42 +08001286 * @last_free_ptr: Hardware pointer value of the last free descriptor
developerfd40db22021-04-29 10:08:25 +08001287 * @thresh: The threshold of minimum amount of free descriptors
1288 * @free_count: QDMA uses a linked list. Track how many free descriptors
1289 * are present
1290 */
1291struct mtk_tx_ring {
developere9356982022-07-04 09:03:20 +08001292 void *dma;
developerfd40db22021-04-29 10:08:25 +08001293 struct mtk_tx_buf *buf;
1294 dma_addr_t phys;
developere9356982022-07-04 09:03:20 +08001295 void *next_free;
1296 void *last_free;
developerc4671b22021-05-28 13:16:42 +08001297 u32 last_free_ptr;
developerfd40db22021-04-29 10:08:25 +08001298 u16 thresh;
1299 atomic_t free_count;
1300 int dma_size;
developere9356982022-07-04 09:03:20 +08001301 void *dma_pdma; /* For MT7628/88 PDMA handling */
developerfd40db22021-04-29 10:08:25 +08001302 dma_addr_t phys_pdma;
1303 int cpu_idx;
1304};
1305
1306/* PDMA rx ring mode */
1307enum mtk_rx_flags {
1308 MTK_RX_FLAGS_NORMAL = 0,
1309 MTK_RX_FLAGS_HWLRO,
1310 MTK_RX_FLAGS_QDMA,
1311};
1312
1313/* struct mtk_rx_ring - This struct holds info describing a RX ring
1314 * @dma: The descriptor ring
1315 * @data: The memory pointed at by the ring
1316 * @phys: The physical addr of rx_buf
1317 * @frag_size: How big can each fragment be
1318 * @buf_size: The size of each packet buffer
1319 * @calc_idx: The current head of ring
developer77d03a72021-06-06 00:06:00 +08001320 * @ring_no: The index of ring
developerfd40db22021-04-29 10:08:25 +08001321 */
1322struct mtk_rx_ring {
developere9356982022-07-04 09:03:20 +08001323 void *dma;
developerfd40db22021-04-29 10:08:25 +08001324 u8 **data;
1325 dma_addr_t phys;
1326 u16 frag_size;
1327 u16 buf_size;
1328 u16 dma_size;
1329 bool calc_idx_update;
1330 u16 calc_idx;
1331 u32 crx_idx_reg;
developer77d03a72021-06-06 00:06:00 +08001332 u32 ring_no;
developerfd40db22021-04-29 10:08:25 +08001333};
1334
developer18f46a82021-07-20 21:08:21 +08001335/* struct mtk_napi - This is the structure holding NAPI-related information,
1336 * and a mtk_napi struct is binding to one interrupt group
1337 * @napi: The NAPI struct
1338 * @rx_ring: Pointer to the memory holding info about the RX ring
1339 * @irq_grp_idx: The index indicates which interrupt group that this
1340 * mtk_napi is binding to
1341 */
1342struct mtk_napi {
1343 struct napi_struct napi;
1344 struct mtk_eth *eth;
1345 struct mtk_rx_ring *rx_ring;
1346 u32 irq_grp_no;
1347};
1348
developerfd40db22021-04-29 10:08:25 +08001349enum mkt_eth_capabilities {
1350 MTK_RGMII_BIT = 0,
1351 MTK_TRGMII_BIT,
1352 MTK_SGMII_BIT,
developer30e13e72022-11-03 10:21:24 +08001353 MTK_XGMII_BIT,
developer089e8852022-09-28 14:43:46 +08001354 MTK_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001355 MTK_ESW_BIT,
1356 MTK_GEPHY_BIT,
1357 MTK_MUX_BIT,
1358 MTK_INFRA_BIT,
1359 MTK_SHARED_SGMII_BIT,
1360 MTK_HWLRO_BIT,
developer18f46a82021-07-20 21:08:21 +08001361 MTK_RSS_BIT,
developerfd40db22021-04-29 10:08:25 +08001362 MTK_SHARED_INT_BIT,
1363 MTK_TRGMII_MT7621_CLK_BIT,
1364 MTK_QDMA_BIT,
developer089e8852022-09-28 14:43:46 +08001365 MTK_NETSYS_V1_BIT,
developera2bdbd52021-05-31 19:10:17 +08001366 MTK_NETSYS_V2_BIT,
developer8ecd51b2023-03-13 11:28:28 +08001367 MTK_NETSYS_RX_V2_BIT,
developer089e8852022-09-28 14:43:46 +08001368 MTK_NETSYS_V3_BIT,
developerfd40db22021-04-29 10:08:25 +08001369 MTK_SOC_MT7628_BIT,
developer545abf02021-07-15 17:47:01 +08001370 MTK_RSTCTRL_PPE1_BIT,
developer37482a42022-12-26 13:31:13 +08001371 MTK_RSTCTRL_PPE2_BIT,
developer255bba22021-07-27 15:16:33 +08001372 MTK_U3_COPHY_V2_BIT,
developer089e8852022-09-28 14:43:46 +08001373 MTK_8GB_ADDRESSING_BIT,
developerfd40db22021-04-29 10:08:25 +08001374
1375 /* MUX BITS*/
1376 MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
1377 MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
1378 MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
developer30e13e72022-11-03 10:21:24 +08001379 MTK_ETH_MUX_GMAC2_TO_XGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001380 MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
1381 MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
developer089e8852022-09-28 14:43:46 +08001382 MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT,
1383 MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001384
1385 /* PATH BITS */
1386 MTK_ETH_PATH_GMAC1_RGMII_BIT,
1387 MTK_ETH_PATH_GMAC1_TRGMII_BIT,
1388 MTK_ETH_PATH_GMAC1_SGMII_BIT,
1389 MTK_ETH_PATH_GMAC2_RGMII_BIT,
1390 MTK_ETH_PATH_GMAC2_SGMII_BIT,
developer30e13e72022-11-03 10:21:24 +08001391 MTK_ETH_PATH_GMAC2_XGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001392 MTK_ETH_PATH_GMAC2_GEPHY_BIT,
developer089e8852022-09-28 14:43:46 +08001393 MTK_ETH_PATH_GMAC3_SGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001394 MTK_ETH_PATH_GDM1_ESW_BIT,
developer089e8852022-09-28 14:43:46 +08001395 MTK_ETH_PATH_GMAC1_USXGMII_BIT,
1396 MTK_ETH_PATH_GMAC2_USXGMII_BIT,
1397 MTK_ETH_PATH_GMAC3_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001398};
1399
1400/* Supported hardware group on SoCs */
developer425b23a2022-10-12 16:00:41 +08001401#define MTK_RGMII BIT_ULL(MTK_RGMII_BIT)
1402#define MTK_TRGMII BIT_ULL(MTK_TRGMII_BIT)
1403#define MTK_SGMII BIT_ULL(MTK_SGMII_BIT)
developer30e13e72022-11-03 10:21:24 +08001404#define MTK_XGMII BIT_ULL(MTK_XGMII_BIT)
developer425b23a2022-10-12 16:00:41 +08001405#define MTK_USXGMII BIT_ULL(MTK_USXGMII_BIT)
1406#define MTK_ESW BIT_ULL(MTK_ESW_BIT)
1407#define MTK_GEPHY BIT_ULL(MTK_GEPHY_BIT)
1408#define MTK_MUX BIT_ULL(MTK_MUX_BIT)
1409#define MTK_INFRA BIT_ULL(MTK_INFRA_BIT)
1410#define MTK_SHARED_SGMII BIT_ULL(MTK_SHARED_SGMII_BIT)
1411#define MTK_HWLRO BIT_ULL(MTK_HWLRO_BIT)
1412#define MTK_RSS BIT_ULL(MTK_RSS_BIT)
1413#define MTK_SHARED_INT BIT_ULL(MTK_SHARED_INT_BIT)
1414#define MTK_TRGMII_MT7621_CLK BIT_ULL(MTK_TRGMII_MT7621_CLK_BIT)
1415#define MTK_QDMA BIT_ULL(MTK_QDMA_BIT)
1416#define MTK_NETSYS_V1 BIT_ULL(MTK_NETSYS_V1_BIT)
1417#define MTK_NETSYS_V2 BIT_ULL(MTK_NETSYS_V2_BIT)
developer8ecd51b2023-03-13 11:28:28 +08001418#define MTK_NETSYS_RX_V2 BIT(MTK_NETSYS_RX_V2_BIT)
developer425b23a2022-10-12 16:00:41 +08001419#define MTK_NETSYS_V3 BIT_ULL(MTK_NETSYS_V3_BIT)
1420#define MTK_SOC_MT7628 BIT_ULL(MTK_SOC_MT7628_BIT)
1421#define MTK_RSTCTRL_PPE1 BIT_ULL(MTK_RSTCTRL_PPE1_BIT)
developer37482a42022-12-26 13:31:13 +08001422#define MTK_RSTCTRL_PPE2 BIT_ULL(MTK_RSTCTRL_PPE2_BIT)
developer425b23a2022-10-12 16:00:41 +08001423#define MTK_U3_COPHY_V2 BIT_ULL(MTK_U3_COPHY_V2_BIT)
1424#define MTK_8GB_ADDRESSING BIT_ULL(MTK_8GB_ADDRESSING_BIT)
developerfd40db22021-04-29 10:08:25 +08001425
1426#define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \
developer425b23a2022-10-12 16:00:41 +08001427 BIT_ULL(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
developerfd40db22021-04-29 10:08:25 +08001428#define MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY \
developer425b23a2022-10-12 16:00:41 +08001429 BIT_ULL(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
developerfd40db22021-04-29 10:08:25 +08001430#define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \
developer425b23a2022-10-12 16:00:41 +08001431 BIT_ULL(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
developer30e13e72022-11-03 10:21:24 +08001432#define MTK_ETH_MUX_GMAC2_TO_XGMII \
1433 BIT_ULL(MTK_ETH_MUX_GMAC2_TO_XGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001434#define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
developer425b23a2022-10-12 16:00:41 +08001435 BIT_ULL(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001436#define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \
developer425b23a2022-10-12 16:00:41 +08001437 BIT_ULL(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
developer089e8852022-09-28 14:43:46 +08001438#define MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII \
developer425b23a2022-10-12 16:00:41 +08001439 BIT_ULL(MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT)
developer089e8852022-09-28 14:43:46 +08001440#define MTK_ETH_MUX_GMAC123_TO_USXGMII \
developer425b23a2022-10-12 16:00:41 +08001441 BIT_ULL(MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001442
1443/* Supported path present on SoCs */
developer425b23a2022-10-12 16:00:41 +08001444#define MTK_ETH_PATH_GMAC1_RGMII BIT_ULL(MTK_ETH_PATH_GMAC1_RGMII_BIT)
1445#define MTK_ETH_PATH_GMAC1_TRGMII BIT_ULL(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
1446#define MTK_ETH_PATH_GMAC1_SGMII BIT_ULL(MTK_ETH_PATH_GMAC1_SGMII_BIT)
1447#define MTK_ETH_PATH_GMAC2_RGMII BIT_ULL(MTK_ETH_PATH_GMAC2_RGMII_BIT)
1448#define MTK_ETH_PATH_GMAC2_SGMII BIT_ULL(MTK_ETH_PATH_GMAC2_SGMII_BIT)
developer30e13e72022-11-03 10:21:24 +08001449#define MTK_ETH_PATH_GMAC2_XGMII BIT_ULL(MTK_ETH_PATH_GMAC2_XGMII_BIT)
developer425b23a2022-10-12 16:00:41 +08001450#define MTK_ETH_PATH_GMAC2_GEPHY BIT_ULL(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
1451#define MTK_ETH_PATH_GMAC3_SGMII BIT_ULL(MTK_ETH_PATH_GMAC3_SGMII_BIT)
1452#define MTK_ETH_PATH_GDM1_ESW BIT_ULL(MTK_ETH_PATH_GDM1_ESW_BIT)
1453#define MTK_ETH_PATH_GMAC1_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC1_USXGMII_BIT)
1454#define MTK_ETH_PATH_GMAC2_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC2_USXGMII_BIT)
1455#define MTK_ETH_PATH_GMAC3_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC3_USXGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001456
1457#define MTK_GMAC1_RGMII (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
1458#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
1459#define MTK_GMAC1_SGMII (MTK_ETH_PATH_GMAC1_SGMII | MTK_SGMII)
1460#define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
1461#define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
developer30e13e72022-11-03 10:21:24 +08001462#define MTK_GMAC2_XGMII (MTK_ETH_PATH_GMAC2_XGMII | MTK_XGMII)
developerfd40db22021-04-29 10:08:25 +08001463#define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
developer089e8852022-09-28 14:43:46 +08001464#define MTK_GMAC3_SGMII (MTK_ETH_PATH_GMAC3_SGMII | MTK_SGMII)
developerfd40db22021-04-29 10:08:25 +08001465#define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
developer089e8852022-09-28 14:43:46 +08001466#define MTK_GMAC1_USXGMII (MTK_ETH_PATH_GMAC1_USXGMII | MTK_USXGMII)
1467#define MTK_GMAC2_USXGMII (MTK_ETH_PATH_GMAC2_USXGMII | MTK_USXGMII)
1468#define MTK_GMAC3_USXGMII (MTK_ETH_PATH_GMAC3_USXGMII | MTK_USXGMII)
developerfd40db22021-04-29 10:08:25 +08001469
1470/* MUXes present on SoCs */
1471/* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
1472#define MTK_MUX_GDM1_TO_GMAC1_ESW (MTK_ETH_MUX_GDM1_TO_GMAC1_ESW | MTK_MUX)
1473
1474/* 0: GMAC2 -> GEPHY, 1: GMAC0 -> GePHY */
1475#define MTK_MUX_GMAC2_GMAC0_TO_GEPHY \
1476 (MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY | MTK_MUX | MTK_INFRA)
1477
1478/* 0: U3 -> QPHY, 1: GMAC2 -> QPHY */
1479#define MTK_MUX_U3_GMAC2_TO_QPHY \
1480 (MTK_ETH_MUX_U3_GMAC2_TO_QPHY | MTK_MUX | MTK_INFRA)
1481
1482/* 2: GMAC1 -> SGMII, 3: GMAC2 -> SGMII */
1483#define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
1484 (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
1485 MTK_SHARED_SGMII)
1486
developer30e13e72022-11-03 10:21:24 +08001487/* 2: GMAC2 -> XGMII */
1488#define MTK_MUX_GMAC2_TO_XGMII \
1489 (MTK_ETH_MUX_GMAC2_TO_XGMII | MTK_MUX | MTK_INFRA)
1490
developerfd40db22021-04-29 10:08:25 +08001491/* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
1492#define MTK_MUX_GMAC12_TO_GEPHY_SGMII \
1493 (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
1494
developer089e8852022-09-28 14:43:46 +08001495#define MTK_MUX_GMAC123_TO_GEPHY_SGMII \
1496 (MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII | MTK_MUX)
1497
1498#define MTK_MUX_GMAC123_TO_USXGMII \
1499 (MTK_ETH_MUX_GMAC123_TO_USXGMII | MTK_MUX | MTK_INFRA)
1500
developerfd40db22021-04-29 10:08:25 +08001501#define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
1502
1503#define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
1504 MTK_GMAC2_RGMII | MTK_SHARED_INT | \
developer089e8852022-09-28 14:43:46 +08001505 MTK_TRGMII_MT7621_CLK | MTK_QDMA | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001506
1507#define MT7622_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_SGMII | MTK_GMAC2_RGMII | \
1508 MTK_GMAC2_SGMII | MTK_GDM1_ESW | \
developer089e8852022-09-28 14:43:46 +08001509 MTK_MUX_GDM1_TO_GMAC1_ESW | MTK_NETSYS_V1 | \
developerfd40db22021-04-29 10:08:25 +08001510 MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_QDMA)
1511
1512#define MT7623_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | MTK_GMAC2_RGMII | \
developer089e8852022-09-28 14:43:46 +08001513 MTK_QDMA | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001514
developer089e8852022-09-28 14:43:46 +08001515#define MT7628_CAPS (MTK_SHARED_INT | MTK_SOC_MT7628 | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001516
1517#define MT7629_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
1518 MTK_GDM1_ESW | MTK_MUX_GDM1_TO_GMAC1_ESW | \
1519 MTK_MUX_GMAC2_GMAC0_TO_GEPHY | \
developer089e8852022-09-28 14:43:46 +08001520 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_NETSYS_V1 | \
developerfd40db22021-04-29 10:08:25 +08001521 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA)
1522
developerfd40db22021-04-29 10:08:25 +08001523#define MT7986_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \
1524 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
developer8ecd51b2023-03-13 11:28:28 +08001525 MTK_NETSYS_V2)
developerfd40db22021-04-29 10:08:25 +08001526
developer255bba22021-07-27 15:16:33 +08001527#define MT7981_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
1528 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
1529 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_U3_COPHY_V2 | \
1530 MTK_NETSYS_V2)
1531
developer089e8852022-09-28 14:43:46 +08001532#define MT7988_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC3_SGMII | \
1533 MTK_MUX_GMAC123_TO_GEPHY_SGMII | MTK_QDMA | \
developer37482a42022-12-26 13:31:13 +08001534 MTK_NETSYS_V3 | MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | \
developer089e8852022-09-28 14:43:46 +08001535 MTK_GMAC1_USXGMII | MTK_GMAC2_USXGMII | \
developer30e13e72022-11-03 10:21:24 +08001536 MTK_GMAC3_USXGMII | MTK_MUX_GMAC123_TO_USXGMII | \
developer8ecd51b2023-03-13 11:28:28 +08001537 MTK_GMAC2_XGMII | MTK_MUX_GMAC2_TO_XGMII | MTK_RSS | \
1538 MTK_NETSYS_RX_V2)
developer089e8852022-09-28 14:43:46 +08001539
developere9356982022-07-04 09:03:20 +08001540struct mtk_tx_dma_desc_info {
1541 dma_addr_t addr;
1542 u32 size;
1543 u16 vlan_tci;
1544 u16 qid;
1545 u8 gso:1;
1546 u8 csum:1;
1547 u8 vlan:1;
1548 u8 first:1;
1549 u8 last:1;
1550};
1551
developer68ce74f2023-01-03 16:11:57 +08001552struct mtk_reg_map {
1553 u32 tx_irq_mask;
1554 u32 tx_irq_status;
1555 struct {
1556 u32 rx_ptr; /* rx base pointer */
1557 u32 rx_cnt_cfg; /* rx max count configuration */
1558 u32 pcrx_ptr; /* rx cpu pointer */
1559 u32 glo_cfg; /* global configuration */
1560 u32 rst_idx; /* reset index */
1561 u32 delay_irq; /* delay interrupt */
1562 u32 irq_status; /* interrupt status */
1563 u32 irq_mask; /* interrupt mask */
1564 u32 int_grp; /* interrupt group1 */
1565 u32 int_grp2; /* interrupt group2 */
1566 } pdma;
1567 struct {
1568 u32 qtx_cfg; /* tx queue configuration */
1569 u32 qtx_sch; /* tx queue scheduler configuration */
1570 u32 rx_ptr; /* rx base pointer */
1571 u32 rx_cnt_cfg; /* rx max count configuration */
1572 u32 qcrx_ptr; /* rx cpu pointer */
1573 u32 glo_cfg; /* global configuration */
1574 u32 rst_idx; /* reset index */
1575 u32 delay_irq; /* delay interrupt */
1576 u32 fc_th; /* flow control */
1577 u32 int_grp; /* interrupt group1 */
1578 u32 int_grp2; /* interrupt group2 */
1579 u32 hred2; /* interrupt mask */
1580 u32 ctx_ptr; /* tx acquire cpu pointer */
1581 u32 dtx_ptr; /* tx acquire dma pointer */
1582 u32 crx_ptr; /* tx release cpu pointer */
1583 u32 drx_ptr; /* tx release dma pointer */
1584 u32 fq_head; /* fq head pointer */
1585 u32 fq_tail; /* fq tail pointer */
1586 u32 fq_count; /* fq free page count */
1587 u32 fq_blen; /* fq free page buffer length */
1588 u32 tx_sch_rate; /* tx scheduler rate control
1589 registers */
1590 } qdma;
1591 u32 gdm1_cnt;
1592 u32 gdma_to_ppe0;
1593 u32 ppe_base[3];
1594 u32 wdma_base[3];
1595};
1596
developerfd40db22021-04-29 10:08:25 +08001597/* struct mtk_eth_data - This is the structure holding all differences
1598 * among various plaforms
developer68ce74f2023-01-03 16:11:57 +08001599 * @reg_map Soc register map.
1600 * @ana_rgc3: The offset for register ANA_RGC3 related to
developerfd40db22021-04-29 10:08:25 +08001601 * sgmiisys syscon
1602 * @caps Flags shown the extra capability for the SoC
1603 * @hw_features Flags shown HW features
1604 * @required_clks Flags shown the bitmap for required clocks on
1605 * the target SoC
1606 * @required_pctl A bool value to show whether the SoC requires
1607 * the extra setup for those pins used by GMAC.
developere9356982022-07-04 09:03:20 +08001608 * @txd_size Tx DMA descriptor size.
1609 * @rxd_size Rx DMA descriptor size.
developer68ce74f2023-01-03 16:11:57 +08001610 * @rx_dma_l4_valid Rx DMA valid register mask.
developere9356982022-07-04 09:03:20 +08001611 * @dma_max_len Max DMA tx/rx buffer length.
1612 * @dma_len_offset Tx/Rx DMA length field offset.
developerfd40db22021-04-29 10:08:25 +08001613 */
1614struct mtk_soc_data {
developer68ce74f2023-01-03 16:11:57 +08001615 const struct mtk_reg_map *reg_map;
1616 u32 ana_rgc3;
developer089e8852022-09-28 14:43:46 +08001617 u64 caps;
developer5cfc67a2022-12-29 19:06:51 +08001618 u64 required_clks;
developerfd40db22021-04-29 10:08:25 +08001619 bool required_pctl;
1620 netdev_features_t hw_features;
1621 bool has_sram;
developere9356982022-07-04 09:03:20 +08001622 struct {
1623 u32 txd_size;
1624 u32 rxd_size;
developer68ce74f2023-01-03 16:11:57 +08001625 u32 rx_dma_l4_valid;
developere9356982022-07-04 09:03:20 +08001626 u32 dma_max_len;
1627 u32 dma_len_offset;
1628 } txrx;
developerfd40db22021-04-29 10:08:25 +08001629};
1630
developer089e8852022-09-28 14:43:46 +08001631/* currently no SoC has more than 3 macs */
1632#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1633#define MTK_MAX_DEVS 3
1634#else
1635#define MTK_MAX_DEVS 2
1636#endif
developerfd40db22021-04-29 10:08:25 +08001637
1638#define MTK_SGMII_PHYSPEED_AN BIT(31)
1639#define MTK_SGMII_PHYSPEED_MASK GENMASK(2, 0)
1640#define MTK_SGMII_PHYSPEED_1000 BIT(0)
1641#define MTK_SGMII_PHYSPEED_2500 BIT(1)
developer089e8852022-09-28 14:43:46 +08001642#define MTK_SGMII_PHYSPEED_5000 BIT(2)
1643#define MTK_SGMII_PHYSPEED_10000 BIT(3)
developerf8ac94a2021-07-29 16:40:01 +08001644#define MTK_SGMII_PN_SWAP BIT(16)
developerfd40db22021-04-29 10:08:25 +08001645#define MTK_HAS_FLAGS(flags, _x) (((flags) & (_x)) == (_x))
1646
developer4e8a3fd2023-04-10 18:05:44 +08001647/* struct mtk_sgmii_pcs - This structure holds each sgmii regmap and associated
1648 * data
1649 * @regmap: The register map pointing at the range used to setup
1650 * SGMII modes
1651 * @regmap_pextp: The register map pointing at the range used to setup
1652 * PHYA
1653 * @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap
1654 * @id: The element is used to record the index of PCS
1655 * @pcs: Phylink PCS structure
developerfd40db22021-04-29 10:08:25 +08001656 */
developer4e8a3fd2023-04-10 18:05:44 +08001657struct mtk_sgmii_pcs {
1658 struct mtk_eth *eth;
1659 struct regmap *regmap;
1660 struct regmap *regmap_pextp;
1661 phy_interface_t interface;
1662 u32 flags;
1663 u32 ana_rgc3;
1664 u8 id;
1665 struct phylink_pcs pcs;
1666};
developerfd40db22021-04-29 10:08:25 +08001667
developer4e8a3fd2023-04-10 18:05:44 +08001668/* struct mtk_sgmii - This is the structure holding sgmii regmap and its
1669 * characteristics
1670 * @pll: The register map pointing at the range used to setup
1671 * PLL
1672 * @pcs Array of individual PCS structures
1673 */
1674struct mtk_sgmii {
1675 struct mtk_sgmii_pcs pcs[MTK_MAX_DEVS];
1676 struct regmap *pll;
developerfd40db22021-04-29 10:08:25 +08001677};
1678
developer4e8a3fd2023-04-10 18:05:44 +08001679/* struct mtk_usxgmii_pcs - This structure holds each usxgmii regmap and
1680 * associated data
1681 * @regmap: The register map pointing at the range used to setup
1682 * USXGMII modes
1683 * @regmap_pextp: The register map pointing at the range used to setup
1684 * PHYA
1685 * @id: The element is used to record the index of PCS
1686 * @pcs: Phylink PCS structure
1687 */
1688struct mtk_usxgmii_pcs {
1689 struct mtk_eth *eth;
1690 struct regmap *regmap;
1691 struct regmap *regmap_pextp;
1692 phy_interface_t interface;
1693 u8 id;
1694 struct phylink_pcs pcs;
1695};
1696
1697/* struct mtk_usxgmii - This is the structure holding usxgmii regmap and its
1698 * characteristics
1699 * @pll: The register map pointing at the range used to setup
1700 * PLL
1701 * @pcs Array of individual PCS structures
1702 */
1703struct mtk_usxgmii {
1704 struct mtk_usxgmii_pcs pcs[MTK_MAX_DEVS];
1705 struct regmap *pll;
1706};
developer8051e042022-04-08 13:26:36 +08001707
1708/* struct mtk_reset_event - This is the structure holding statistics counters
1709 * for reset events
1710 * @count: The counter is used to record the number of events
1711 */
1712struct mtk_reset_event {
1713 u32 count[32];
1714};
1715
developera2613e62022-07-01 18:29:37 +08001716/* struct mtk_phylink_priv - This is the structure holding private data for phylink
1717 * @desc: Pointer to the memory holding info about the phylink gpio
1718 * @id: The element is used to record the phy index of phylink
1719 * @phyaddr: The element is used to record the phy address of phylink
1720 * @link: The element is used to record the phy link status of phylink
1721 */
1722struct mtk_phylink_priv {
1723 struct net_device *dev;
1724 struct gpio_desc *desc;
1725 char label[16];
1726 int id;
1727 int phyaddr;
1728 int link;
1729};
1730
developerfd40db22021-04-29 10:08:25 +08001731/* struct mtk_eth - This is the main datasructure for holding the state
1732 * of the driver
1733 * @dev: The device pointer
developer3f28d382023-03-07 16:06:30 +08001734 * @dma_dev: The device pointer used for dma mapping/alloc
developerfd40db22021-04-29 10:08:25 +08001735 * @base: The mapped register i/o base
1736 * @page_lock: Make sure that register operations are atomic
1737 * @tx_irq__lock: Make sure that IRQ register operations are atomic
1738 * @rx_irq__lock: Make sure that IRQ register operations are atomic
1739 * @dummy_dev: we run 2 netdevs on 1 physical DMA ring and need a
1740 * dummy for NAPI to work
1741 * @netdev: The netdev instances
1742 * @mac: Each netdev is linked to a physical MAC
1743 * @irq: The IRQ that we are using
1744 * @msg_enable: Ethtool msg level
1745 * @ethsys: The register map pointing at the range used to setup
1746 * MII modes
1747 * @infra: The register map pointing at the range used to setup
1748 * SGMII and GePHY path
1749 * @pctl: The register map pointing at the range used to setup
1750 * GMAC port drive/slew values
1751 * @dma_refcnt: track how many netdevs are using the DMA engine
1752 * @tx_ring: Pointer to the memory holding info about the TX ring
1753 * @rx_ring: Pointer to the memory holding info about the RX ring
1754 * @rx_ring_qdma: Pointer to the memory holding info about the QDMA RX ring
1755 * @tx_napi: The TX NAPI struct
1756 * @rx_napi: The RX NAPI struct
1757 * @scratch_ring: Newer SoCs need memory for a second HW managed TX ring
1758 * @phy_scratch_ring: physical address of scratch_ring
1759 * @scratch_head: The scratch memory that scratch_ring points to.
1760 * @clks: clock array for all clocks required
1761 * @mii_bus: If there is a bus we need to create an instance for it
1762 * @pending_work: The workqueue used to reset the dma ring
1763 * @state: Initialization and runtime state of the device
1764 * @soc: Holding specific data among vaious SoCs
1765 */
1766
1767struct mtk_eth {
1768 struct device *dev;
developer3f28d382023-03-07 16:06:30 +08001769 struct device *dma_dev;
developerfd40db22021-04-29 10:08:25 +08001770 void __iomem *base;
developer089e8852022-09-28 14:43:46 +08001771 void __iomem *sram_base;
developerfd40db22021-04-29 10:08:25 +08001772 spinlock_t page_lock;
1773 spinlock_t tx_irq_lock;
1774 spinlock_t rx_irq_lock;
1775 struct net_device dummy_dev;
1776 struct net_device *netdev[MTK_MAX_DEVS];
1777 struct mtk_mac *mac[MTK_MAX_DEVS];
developer94806ec2023-05-19 14:16:44 +08001778 int irq_fe[MTK_FE_IRQ_NUM];
1779 int irq_pdma[MTK_PDMA_IRQ_NUM];
developer0fef5222023-04-26 14:48:31 +08001780 u8 hwver;
developerfd40db22021-04-29 10:08:25 +08001781 u32 msg_enable;
1782 unsigned long sysclk;
1783 struct regmap *ethsys;
1784 struct regmap *infra;
developer089e8852022-09-28 14:43:46 +08001785 struct regmap *toprgu;
developer4e8a3fd2023-04-10 18:05:44 +08001786 struct mtk_sgmii *sgmii;
1787 struct mtk_usxgmii *usxgmii;
developerfd40db22021-04-29 10:08:25 +08001788 struct regmap *pctl;
1789 bool hwlro;
1790 refcount_t dma_refcnt;
1791 struct mtk_tx_ring tx_ring;
1792 struct mtk_rx_ring rx_ring[MTK_MAX_RX_RING_NUM];
1793 struct mtk_rx_ring rx_ring_qdma;
1794 struct napi_struct tx_napi;
developer18f46a82021-07-20 21:08:21 +08001795 struct mtk_napi rx_napi[MTK_RX_NAPI_NUM];
developere9356982022-07-04 09:03:20 +08001796 void *scratch_ring;
developer8051e042022-04-08 13:26:36 +08001797 struct mtk_reset_event reset_event;
developerfd40db22021-04-29 10:08:25 +08001798 dma_addr_t phy_scratch_ring;
1799 void *scratch_head;
1800 struct clk *clks[MTK_CLK_MAX];
1801
1802 struct mii_bus *mii_bus;
1803 struct work_struct pending_work;
1804 unsigned long state;
1805
1806 const struct mtk_soc_data *soc;
1807
developerfd40db22021-04-29 10:08:25 +08001808 u32 rx_dma_l4_valid;
1809 int ip_align;
developerd82e8372022-02-09 15:00:09 +08001810 spinlock_t syscfg0_lock;
developer8051e042022-04-08 13:26:36 +08001811 struct timer_list mtk_dma_monitor_timer;
developerfd40db22021-04-29 10:08:25 +08001812};
1813
1814/* struct mtk_mac - the structure that holds the info about the MACs of the
1815 * SoC
1816 * @id: The number of the MAC
1817 * @interface: Interface mode kept for detecting change in hw settings
1818 * @of_node: Our devicetree node
1819 * @hw: Backpointer to our main datastruture
1820 * @hw_stats: Packet statistics counter
1821 */
1822struct mtk_mac {
developerfb556ca2021-10-13 10:52:09 +08001823 unsigned int id;
developerfd40db22021-04-29 10:08:25 +08001824 phy_interface_t interface;
1825 unsigned int mode;
developer089e8852022-09-28 14:43:46 +08001826 unsigned int type;
developerfd40db22021-04-29 10:08:25 +08001827 int speed;
1828 struct device_node *of_node;
1829 struct phylink *phylink;
1830 struct phylink_config phylink_config;
developera2613e62022-07-01 18:29:37 +08001831 struct mtk_phylink_priv phylink_priv;
developerfd40db22021-04-29 10:08:25 +08001832 struct mtk_eth *hw;
1833 struct mtk_hw_stats *hw_stats;
1834 __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT];
1835 int hwlro_ip_cnt;
developer4e8a3fd2023-04-10 18:05:44 +08001836 unsigned int syscfg0;
developer9b725932022-11-24 16:25:56 +08001837 bool tx_lpi_enabled;
1838 u32 tx_lpi_timer;
developerfd40db22021-04-29 10:08:25 +08001839};
1840
1841/* the struct describing the SoC. these are declared in the soc_xyz.c files */
developer7cd7e5e2022-11-17 13:57:32 +08001842extern struct mtk_eth *g_eth;
developerfd40db22021-04-29 10:08:25 +08001843extern const struct of_device_id of_mtk_match[];
developer77d03a72021-06-06 00:06:00 +08001844extern u32 mtk_hwlro_stats_ebl;
developer7979ddb2023-04-24 17:19:21 +08001845extern u32 dbg_show_level;
developerfd40db22021-04-29 10:08:25 +08001846
1847/* read the hardware status register */
1848void mtk_stats_update_mac(struct mtk_mac *mac);
1849
1850void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
1851u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
developer8051e042022-04-08 13:26:36 +08001852u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned reg);
developerfd40db22021-04-29 10:08:25 +08001853
developer4e8a3fd2023-04-10 18:05:44 +08001854struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id);
1855int mtk_sgmii_init(struct mtk_eth *eth, struct device_node *np,
developerfd40db22021-04-29 10:08:25 +08001856 u32 ana_rgc3);
developerfd40db22021-04-29 10:08:25 +08001857
1858int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
developer30e13e72022-11-03 10:21:24 +08001859int mtk_gmac_xgmii_path_setup(struct mtk_eth *eth, int mac_id);
developerfd40db22021-04-29 10:08:25 +08001860int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
1861int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
developer089e8852022-09-28 14:43:46 +08001862int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id);
developerdca0fde2022-12-14 11:40:35 +08001863void mtk_gdm_config(struct mtk_eth *eth, u32 id, u32 config);
developer8051e042022-04-08 13:26:36 +08001864void ethsys_reset(struct mtk_eth *eth, u32 reset_bits);
developerfd40db22021-04-29 10:08:25 +08001865
developer089e8852022-09-28 14:43:46 +08001866int mtk_mac2xgmii_id(struct mtk_eth *eth, int mac_id);
developer4e8a3fd2023-04-10 18:05:44 +08001867struct phylink_pcs *mtk_usxgmii_select_pcs(struct mtk_usxgmii *ss, int id);
1868int mtk_usxgmii_init(struct mtk_eth *eth, struct device_node *r);
developer089e8852022-09-28 14:43:46 +08001869int mtk_toprgu_init(struct mtk_eth *eth, struct device_node *r);
developer0baa6962023-01-31 14:25:23 +08001870int mtk_dump_usxgmii(struct regmap *pmap, char *name, u32 offset, u32 range);
developer3f28d382023-03-07 16:06:30 +08001871
1872void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
developerfd40db22021-04-29 10:08:25 +08001873#endif /* MTK_ETH_H */