blob: 355b74587962a837c155966d203453d7b2ce35fb [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
developer8b96bb72023-10-26 16:31:12 +080055#define MTK_HW_LRO_DMA_SIZE 64
developerfd40db22021-04-29 10:08:25 +080056
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
developerea49c302023-06-27 16:06:41 +080068#define MTK_RSS_HASH_KEYSIZE 40
69#define MTK_RSS_MAX_INDIRECTION_TABLE 128
70
developer8051e042022-04-08 13:26:36 +080071/* Frame Engine Global Configuration */
developer65f32592023-08-02 09:35:49 +080072#define MTK_FE_GLO_CFG(x) ((x == MTK_GMAC3_ID) ? 0x24 : 0x00)
73#define MTK_FE_LINK_DOWN_P1 BIT(9)
74#define MTK_FE_LINK_DOWN_P2 BIT(10)
developer8051e042022-04-08 13:26:36 +080075#define MTK_FE_LINK_DOWN_P3 BIT(11)
76#define MTK_FE_LINK_DOWN_P4 BIT(12)
developer65f32592023-08-02 09:35:49 +080077#define MTK_FE_LINK_DOWN_P15 BIT(7)
developer8051e042022-04-08 13:26:36 +080078
developerfd40db22021-04-29 10:08:25 +080079/* Frame Engine Global Reset Register */
80#define MTK_RST_GL 0x04
81#define RST_GL_PSE BIT(0)
82
83/* Frame Engine Interrupt Status Register */
developer8051e042022-04-08 13:26:36 +080084#define MTK_FE_INT_STATUS 0x08
85#define MTK_FE_INT_STATUS2 0x28
86#define MTK_FE_INT_ENABLE 0x0C
87#define MTK_FE_INT_FQ_EMPTY BIT(8)
88#define MTK_FE_INT_TSO_FAIL BIT(12)
89#define MTK_FE_INT_TSO_ILLEGAL BIT(13)
90#define MTK_FE_INT_TSO_ALIGN BIT(14)
91#define MTK_FE_INT_RFIFO_OV BIT(18)
92#define MTK_FE_INT_RFIFO_UF BIT(19)
developerfd40db22021-04-29 10:08:25 +080093#define MTK_GDM1_AF BIT(28)
94#define MTK_GDM2_AF BIT(29)
developer46ed9492023-10-31 15:19:05 +080095#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer94806ec2023-05-19 14:16:44 +080096#define MTK_FE_IRQ_NUM (4)
developer46ed9492023-10-31 15:19:05 +080097#else
98#define MTK_FE_IRQ_NUM (3)
99#endif
developer94806ec2023-05-19 14:16:44 +0800100#define MTK_PDMA_IRQ_NUM (4)
101#define MTK_MAX_IRQ_NUM (MTK_FE_IRQ_NUM + MTK_PDMA_IRQ_NUM)
developerfd40db22021-04-29 10:08:25 +0800102
103/* PDMA HW LRO Alter Flow Timer Register */
104#define MTK_PDMA_LRO_ALT_REFRESH_TIMER 0x1c
105
106/* Frame Engine Interrupt Grouping Register */
107#define MTK_FE_INT_GRP 0x20
108
developer77d03a72021-06-06 00:06:00 +0800109/* Frame Engine LRO auto-learn table info */
110#define MTK_FE_ALT_CF8 0x300
111#define MTK_FE_ALT_SGL_CFC 0x304
112#define MTK_FE_ALT_SEQ_CFC 0x308
113
developerfd40db22021-04-29 10:08:25 +0800114/* CDMP Ingress Control Register */
115#define MTK_CDMQ_IG_CTRL 0x1400
116#define MTK_CDMQ_STAG_EN BIT(0)
117
118/* CDMP Ingress Control Register */
119#define MTK_CDMP_IG_CTRL 0x400
120#define MTK_CDMP_STAG_EN BIT(0)
121
122/* CDMP Exgress Control Register */
123#define MTK_CDMP_EG_CTRL 0x404
124
developer089e8852022-09-28 14:43:46 +0800125/* GDM Ingress Control Register */
126#define MTK_GDMA_FWD_CFG(x) ((x == MTK_GMAC3_ID) ? \
127 0x540 : 0x500 + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800128#define MTK_GDMA_SPECIAL_TAG BIT(24)
129#define MTK_GDMA_ICS_EN BIT(22)
130#define MTK_GDMA_TCS_EN BIT(21)
131#define MTK_GDMA_UCS_EN BIT(20)
developer089e8852022-09-28 14:43:46 +0800132#define MTK_GDMA_STRP_CRC BIT(16)
developerfd40db22021-04-29 10:08:25 +0800133#define MTK_GDMA_TO_PDMA 0x0
134#define MTK_GDMA_DROP_ALL 0x7777
135
developer089e8852022-09-28 14:43:46 +0800136/* GDM Egress Control Register */
137#define MTK_GDMA_EG_CTRL(x) ((x == MTK_GMAC3_ID) ? \
138 0x544 : 0x504 + (x * 0x1000))
139#define MTK_GDMA_XGDM_SEL BIT(31)
140
developerfd40db22021-04-29 10:08:25 +0800141/* Unicast Filter MAC Address Register - Low */
developer089e8852022-09-28 14:43:46 +0800142#define MTK_GDMA_MAC_ADRL(x) ((x == MTK_GMAC3_ID) ? \
143 0x548 : 0x508 + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800144
145/* Unicast Filter MAC Address Register - High */
developer089e8852022-09-28 14:43:46 +0800146#define MTK_GDMA_MAC_ADRH(x) ((x == MTK_GMAC3_ID) ? \
147 0x54C : 0x50C + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800148
149/* Internal SRAM offset */
developer089e8852022-09-28 14:43:46 +0800150#if defined(CONFIG_MEDIATEK_NETSYS_V3)
151#define MTK_ETH_SRAM_OFFSET 0x300000
152#else
developerfd40db22021-04-29 10:08:25 +0800153#define MTK_ETH_SRAM_OFFSET 0x40000
developer089e8852022-09-28 14:43:46 +0800154#endif
developerfd40db22021-04-29 10:08:25 +0800155
156/* FE global misc reg*/
157#define MTK_FE_GLO_MISC 0x124
158
developerfef9efd2021-06-16 18:28:09 +0800159/* PSE Free Queue Flow Control */
160#define PSE_FQFC_CFG1 0x100
161#define PSE_FQFC_CFG2 0x104
developer459b78e2022-07-01 17:25:10 +0800162#define PSE_NO_DROP_CFG 0x108
163#define PSE_PPE0_DROP 0x110
developerfef9efd2021-06-16 18:28:09 +0800164
developer15f760a2022-10-12 15:57:21 +0800165/* PSE Last FreeQ Page Request Control */
166#define PSE_DUMY_REQ 0x10C
167#define PSE_DUMMY_WORK_GDM(x) BIT(16 + (x))
168#define DUMMY_PAGE_THR 0x151
169
developerfd40db22021-04-29 10:08:25 +0800170/* PSE Input Queue Reservation Register*/
171#define PSE_IQ_REV(x) (0x140 + ((x - 1) * 0x4))
172
173/* PSE Output Queue Threshold Register*/
174#define PSE_OQ_TH(x) (0x160 + ((x - 1) * 0x4))
175
developerfef9efd2021-06-16 18:28:09 +0800176/* GDM and CDM Threshold */
177#define MTK_GDM2_THRES 0x1530
developer11d19612024-03-19 12:36:15 +0800178#define MTK_CDM2_THRES 0x1534
developerfef9efd2021-06-16 18:28:09 +0800179#define MTK_CDMW0_THRES 0x164c
180#define MTK_CDMW1_THRES 0x1650
181#define MTK_CDME0_THRES 0x1654
182#define MTK_CDME1_THRES 0x1658
183#define MTK_CDMM_THRES 0x165c
184
developerfd40db22021-04-29 10:08:25 +0800185#define MTK_PDMA_V2 BIT(4)
developerfd40db22021-04-29 10:08:25 +0800186
developer089e8852022-09-28 14:43:46 +0800187#if defined(CONFIG_MEDIATEK_NETSYS_V3)
188#define PDMA_BASE 0x6800
189#define QDMA_BASE 0x4400
190#define WDMA_BASE(x) (0x4800 + ((x) * 0x400))
developer2a050ba2022-12-01 16:11:06 +0800191#define PPE_BASE(x) ((x == 2) ? 0x2E00 : 0x2200 + ((x) * 0x400))
developer089e8852022-09-28 14:43:46 +0800192#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
developer8ecd51b2023-03-13 11:28:28 +0800193#ifdef CONFIG_MEDIATEK_NETSYS_RX_V2
developerfd40db22021-04-29 10:08:25 +0800194#define PDMA_BASE 0x6000
developer8ecd51b2023-03-13 11:28:28 +0800195#else
196#define PDMA_BASE 0x4000
197#endif
developerfd40db22021-04-29 10:08:25 +0800198#define QDMA_BASE 0x4400
developer8051e042022-04-08 13:26:36 +0800199#define WDMA_BASE(x) (0x4800 + ((x) * 0x400))
200#define PPE_BASE(x) (0x2200 + ((x) * 0x400))
developerfd40db22021-04-29 10:08:25 +0800201#else
202#define PDMA_BASE 0x0800
203#define QDMA_BASE 0x1800
developer8051e042022-04-08 13:26:36 +0800204#define WDMA_BASE(x) (0x2800 + ((x) * 0x400))
205#define PPE_BASE(x) (0xE00 + ((x) * 0x400))
developerfd40db22021-04-29 10:08:25 +0800206#endif
developer5f353462024-02-19 10:42:15 +0800207/* PDMA TX CPU Pointer Register */
208#define MTK_PTX_CTX_IDX0 (PDMA_BASE + 0x08)
209
210/* PDMA TX DMA Pointer Register */
211#define MTK_PTX_DTX_IDX0 (PDMA_BASE + 0x0c)
212
developerfd40db22021-04-29 10:08:25 +0800213/* PDMA RX Base Pointer Register */
214#define MTK_PRX_BASE_PTR0 (PDMA_BASE + 0x100)
215#define MTK_PRX_BASE_PTR_CFG(x) (MTK_PRX_BASE_PTR0 + (x * 0x10))
216
217/* PDMA RX Maximum Count Register */
218#define MTK_PRX_MAX_CNT0 (MTK_PRX_BASE_PTR0 + 0x04)
219#define MTK_PRX_MAX_CNT_CFG(x) (MTK_PRX_MAX_CNT0 + (x * 0x10))
220
221/* PDMA RX CPU Pointer Register */
222#define MTK_PRX_CRX_IDX0 (MTK_PRX_BASE_PTR0 + 0x08)
223#define MTK_PRX_CRX_IDX_CFG(x) (MTK_PRX_CRX_IDX0 + (x * 0x10))
224
developer77f3fd42021-10-05 15:16:05 +0800225/* PDMA RX DMA Pointer Register */
226#define MTK_PRX_DRX_IDX0 (MTK_PRX_BASE_PTR0 + 0x0c)
227#define MTK_PRX_DRX_IDX_CFG(x) (MTK_PRX_DRX_IDX0 + (x * 0x10))
228
developerfd40db22021-04-29 10:08:25 +0800229/* PDMA HW LRO Control Registers */
developer77d03a72021-06-06 00:06:00 +0800230#define BITS(m, n) (~(BIT(m) - 1) & ((BIT(n) - 1) | BIT(n)))
developer8ecd51b2023-03-13 11:28:28 +0800231#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer77d03a72021-06-06 00:06:00 +0800232#define MTK_MAX_RX_RING_NUM (8)
233#define MTK_HW_LRO_RING_NUM (4)
developerddc36672023-10-16 15:13:58 +0800234#define MTK_HW_LRO_RING(x) ((x) + 4)
developer77d03a72021-06-06 00:06:00 +0800235#define IS_HW_LRO_RING(ring_no) (((ring_no) > 3) && ((ring_no) < 8))
236#define MTK_PDMA_LRO_CTRL_DW0 (PDMA_BASE + 0x408)
237#define MTK_LRO_ALT_SCORE_DELTA (PDMA_BASE + 0x41c)
238#define MTK_LRO_RX_RING0_CTRL_DW1 (PDMA_BASE + 0x438)
239#define MTK_LRO_RX_RING0_CTRL_DW2 (PDMA_BASE + 0x43c)
240#define MTK_LRO_RX_RING0_CTRL_DW3 (PDMA_BASE + 0x440)
241#define MTK_L3_CKS_UPD_EN BIT(19)
242#define MTK_LRO_CRSN_BNW BIT(22)
243#define MTK_LRO_RING_RELINGUISH_REQ (0xf << 24)
244#define MTK_LRO_RING_RELINGUISH_DONE (0xf << 28)
245#else
246#define MTK_MAX_RX_RING_NUM (4)
247#define MTK_HW_LRO_RING_NUM (3)
developerddc36672023-10-16 15:13:58 +0800248#define MTK_HW_LRO_RING(x) ((x) + 1)
developer77d03a72021-06-06 00:06:00 +0800249#define IS_HW_LRO_RING(ring_no) (((ring_no) > 0) && ((ring_no) < 4))
250#define MTK_PDMA_LRO_CTRL_DW0 (PDMA_BASE + 0x180)
251#define MTK_LRO_ALT_SCORE_DELTA (PDMA_BASE + 0x24c)
252#define MTK_LRO_RX_RING0_CTRL_DW1 (PDMA_BASE + 0x328)
253#define MTK_LRO_RX_RING0_CTRL_DW2 (PDMA_BASE + 0x32c)
254#define MTK_LRO_RX_RING0_CTRL_DW3 (PDMA_BASE + 0x330)
255#define MTK_LRO_CRSN_BNW BIT(6)
developerfd40db22021-04-29 10:08:25 +0800256#define MTK_L3_CKS_UPD_EN BIT(7)
developer77d03a72021-06-06 00:06:00 +0800257#define MTK_LRO_RING_RELINGUISH_REQ (0x7 << 26)
258#define MTK_LRO_RING_RELINGUISH_DONE (0x7 << 29)
259#endif
260
261#define IS_NORMAL_RING(ring_no) ((ring_no) == 0)
262#define MTK_LRO_EN BIT(0)
developer18f46a82021-07-20 21:08:21 +0800263#define MTK_NON_LRO_MULTI_EN BIT(2)
264#define MTK_LRO_DLY_INT_EN BIT(5)
developerfd40db22021-04-29 10:08:25 +0800265#define MTK_LRO_ALT_PKT_CNT_MODE BIT(21)
developer77d03a72021-06-06 00:06:00 +0800266#define MTK_LRO_L4_CTRL_PSH_EN BIT(23)
267#define MTK_CTRL_DW0_SDL_OFFSET (3)
268#define MTK_CTRL_DW0_SDL_MASK BITS(3, 18)
developerfd40db22021-04-29 10:08:25 +0800269
270#define MTK_PDMA_LRO_CTRL_DW1 (MTK_PDMA_LRO_CTRL_DW0 + 0x04)
271#define MTK_PDMA_LRO_CTRL_DW2 (MTK_PDMA_LRO_CTRL_DW0 + 0x08)
272#define MTK_PDMA_LRO_CTRL_DW3 (MTK_PDMA_LRO_CTRL_DW0 + 0x0c)
273#define MTK_ADMA_MODE BIT(15)
274#define MTK_LRO_MIN_RXD_SDL (MTK_HW_LRO_SDL_REMAIN_ROOM << 16)
275
developer18f46a82021-07-20 21:08:21 +0800276/* PDMA RSS Control Registers */
developer8ecd51b2023-03-13 11:28:28 +0800277#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer18f46a82021-07-20 21:08:21 +0800278#define MTK_PDMA_RSS_GLO_CFG (PDMA_BASE + 0x800)
developer18f46a82021-07-20 21:08:21 +0800279#else
developer8ecd51b2023-03-13 11:28:28 +0800280#define MTK_PDMA_RSS_GLO_CFG 0x2800
developer18f46a82021-07-20 21:08:21 +0800281#endif
developerddc36672023-10-16 15:13:58 +0800282#define MTK_RX_NAPI_NUM (8)
283#define MTK_RX_RSS_NUM (3)
284#define MTK_RSS_RING(x) ((x) + 1)
developer18f46a82021-07-20 21:08:21 +0800285#define MTK_RSS_EN BIT(0)
286#define MTK_RSS_CFG_REQ BIT(2)
287#define MTK_RSS_IPV6_STATIC_HASH (0x7 << 8)
288#define MTK_RSS_IPV4_STATIC_HASH (0x7 << 12)
developerea49c302023-06-27 16:06:41 +0800289#define MTK_RSS_HASH_KEY_DW(x) (MTK_PDMA_RSS_GLO_CFG + 0x20 + \
290 ((x) * 0x4))
developere3d0de22023-05-30 17:45:00 +0800291#define MTK_RSS_INDR_TABLE_DW(x) (MTK_PDMA_RSS_GLO_CFG + 0x50 + \
292 ((x) * 0x4))
developer18f46a82021-07-20 21:08:21 +0800293
developerfd40db22021-04-29 10:08:25 +0800294/* PDMA Global Configuration Register */
295#define MTK_PDMA_GLO_CFG (PDMA_BASE + 0x204)
developer77d03a72021-06-06 00:06:00 +0800296#define MTK_RX_DMA_LRO_EN BIT(8)
developerfd40db22021-04-29 10:08:25 +0800297#define MTK_MULTI_EN BIT(10)
298#define MTK_PDMA_SIZE_8DWORDS (1 << 4)
299
developer77d03a72021-06-06 00:06:00 +0800300/* PDMA Global Configuration Register */
301#define MTK_PDMA_RX_CFG (PDMA_BASE + 0x210)
302#define MTK_PDMA_LRO_SDL (0x3000)
303#define MTK_RX_CFG_SDL_OFFSET (16)
304
developerfd40db22021-04-29 10:08:25 +0800305/* PDMA Reset Index Register */
306#define MTK_PDMA_RST_IDX (PDMA_BASE + 0x208)
307#define MTK_PST_DRX_IDX0 BIT(16)
developera7fbeec2024-02-02 13:56:07 +0800308#define MTK_PST_DTX_IDX0 BIT(0)
developerfd40db22021-04-29 10:08:25 +0800309#define MTK_PST_DRX_IDX_CFG(x) (MTK_PST_DRX_IDX0 << (x))
developera7fbeec2024-02-02 13:56:07 +0800310#define MTK_PST_DTX_IDX_CFG(x) (MTK_PST_DTX_IDX0 << (x))
developerfd40db22021-04-29 10:08:25 +0800311
developerd2fb0622023-07-20 17:11:42 +0800312/*PDMA HW RX Index Register*/
313#define MTK_ADMA_DRX_PTR (PDMA_BASE + 0x10C)
314
developerfd40db22021-04-29 10:08:25 +0800315/* PDMA Delay Interrupt Register */
316#define MTK_PDMA_DELAY_INT (PDMA_BASE + 0x20c)
developera7fbeec2024-02-02 13:56:07 +0800317#define MTK_PDMA_TX_DELAY_INT0 (PDMA_BASE + 0x2b0)
318#define MTK_PDMA_TX_DELAY_INT1 (PDMA_BASE + 0x2b4)
developer8ecd51b2023-03-13 11:28:28 +0800319#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer089e8852022-09-28 14:43:46 +0800320#define MTK_PDMA_RSS_DELAY_INT (PDMA_BASE + 0x2c0)
developer8ecd51b2023-03-13 11:28:28 +0800321#else
322#define MTK_PDMA_RSS_DELAY_INT (PDMA_BASE + 0x270)
323#endif
developerfd40db22021-04-29 10:08:25 +0800324#define MTK_PDMA_DELAY_RX_EN BIT(15)
325#define MTK_PDMA_DELAY_RX_PINT 4
326#define MTK_PDMA_DELAY_RX_PINT_SHIFT 8
327#define MTK_PDMA_DELAY_RX_PTIME 4
328#define MTK_PDMA_DELAY_RX_DELAY \
329 (MTK_PDMA_DELAY_RX_EN | MTK_PDMA_DELAY_RX_PTIME | \
330 (MTK_PDMA_DELAY_RX_PINT << MTK_PDMA_DELAY_RX_PINT_SHIFT))
331
332/* PDMA Interrupt Status Register */
333#define MTK_PDMA_INT_STATUS (PDMA_BASE + 0x220)
334
335/* PDMA Interrupt Mask Register */
336#define MTK_PDMA_INT_MASK (PDMA_BASE + 0x228)
337
developerfd40db22021-04-29 10:08:25 +0800338/* PDMA Interrupt grouping registers */
339#define MTK_PDMA_INT_GRP1 (PDMA_BASE + 0x250)
340#define MTK_PDMA_INT_GRP2 (PDMA_BASE + 0x254)
developer8ecd51b2023-03-13 11:28:28 +0800341#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer18f46a82021-07-20 21:08:21 +0800342#define MTK_PDMA_INT_GRP3 (PDMA_BASE + 0x258)
343#else
344#define MTK_PDMA_INT_GRP3 (PDMA_BASE + 0x22c)
345#endif
developer933f09b2023-09-12 11:13:01 +0800346#define MTK_LRO_RX1_DLY_INT (PDMA_BASE + 0x270)
347#define MTK_LRO_RX2_DLY_INT (PDMA_BASE + 0x274)
348#define MTK_LRO_RX3_DLY_INT (PDMA_BASE + 0x278)
349#define MTK_MAX_DELAY_INT 0x8f0f
350#define MTK_MAX_DELAY_INT_V2 0x8f0f8f0f
developerfd40db22021-04-29 10:08:25 +0800351
352/* PDMA HW LRO IP Setting Registers */
developer8ecd51b2023-03-13 11:28:28 +0800353#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer77d03a72021-06-06 00:06:00 +0800354#define MTK_LRO_RX_RING0_DIP_DW0 (PDMA_BASE + 0x414)
355#else
developerfd40db22021-04-29 10:08:25 +0800356#define MTK_LRO_RX_RING0_DIP_DW0 (PDMA_BASE + 0x304)
developer77d03a72021-06-06 00:06:00 +0800357#endif
developerfd40db22021-04-29 10:08:25 +0800358#define MTK_LRO_DIP_DW0_CFG(x) (MTK_LRO_RX_RING0_DIP_DW0 + (x * 0x40))
359#define MTK_RING_MYIP_VLD BIT(9)
360
developer77d03a72021-06-06 00:06:00 +0800361/* PDMA HW LRO ALT Debug Registers */
362#define MTK_LRO_ALT_DBG (PDMA_BASE + 0x440)
363#define MTK_LRO_ALT_INDEX_OFFSET (8)
364
365/* PDMA HW LRO ALT Data Registers */
366#define MTK_LRO_ALT_DBG_DATA (PDMA_BASE + 0x444)
367
developerfd40db22021-04-29 10:08:25 +0800368/* PDMA HW LRO Ring Control Registers */
developerfd40db22021-04-29 10:08:25 +0800369#define MTK_LRO_CTRL_DW1_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW1 + (x * 0x40))
370#define MTK_LRO_CTRL_DW2_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW2 + (x * 0x40))
371#define MTK_LRO_CTRL_DW3_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW3 + (x * 0x40))
372#define MTK_RING_AGE_TIME_L ((MTK_HW_LRO_AGE_TIME & 0x3ff) << 22)
373#define MTK_RING_AGE_TIME_H ((MTK_HW_LRO_AGE_TIME >> 10) & 0x3f)
developer18f46a82021-07-20 21:08:21 +0800374#define MTK_RING_PSE_MODE (1 << 6)
developerfd40db22021-04-29 10:08:25 +0800375#define MTK_RING_AUTO_LERAN_MODE (3 << 6)
376#define MTK_RING_VLD BIT(8)
377#define MTK_RING_MAX_AGG_TIME ((MTK_HW_LRO_AGG_TIME & 0xffff) << 10)
378#define MTK_RING_MAX_AGG_CNT_L ((MTK_HW_LRO_MAX_AGG_CNT & 0x3f) << 26)
379#define MTK_RING_MAX_AGG_CNT_H ((MTK_HW_LRO_MAX_AGG_CNT >> 6) & 0x3)
380
developer77d03a72021-06-06 00:06:00 +0800381/* LRO_RX_RING_CTRL_DW masks */
382#define MTK_LRO_RING_AGG_TIME_MASK BITS(10, 25)
383#define MTK_LRO_RING_AGG_CNT_L_MASK BITS(26, 31)
384#define MTK_LRO_RING_AGG_CNT_H_MASK BITS(0, 1)
385#define MTK_LRO_RING_AGE_TIME_L_MASK BITS(22, 31)
386#define MTK_LRO_RING_AGE_TIME_H_MASK BITS(0, 5)
387
388/* LRO_RX_RING_CTRL_DW0 offsets */
389#define MTK_RX_IPV6_FORCE_OFFSET (0)
390#define MTK_RX_IPV4_FORCE_OFFSET (1)
391
392/* LRO_RX_RING_CTRL_DW1 offsets */
393#define MTK_LRO_RING_AGE_TIME_L_OFFSET (22)
394
395/* LRO_RX_RING_CTRL_DW2 offsets */
396#define MTK_LRO_RING_AGE_TIME_H_OFFSET (0)
397#define MTK_RX_MODE_OFFSET (6)
398#define MTK_RX_PORT_VALID_OFFSET (8)
399#define MTK_RX_MYIP_VALID_OFFSET (9)
400#define MTK_LRO_RING_AGG_TIME_OFFSET (10)
401#define MTK_LRO_RING_AGG_CNT_L_OFFSET (26)
402
403/* LRO_RX_RING_CTRL_DW3 offsets */
404#define MTK_LRO_RING_AGG_CNT_H_OFFSET (0)
405
406/* LRO_RX_RING_STP_DTP_DW offsets */
407#define MTK_RX_TCP_DEST_PORT_OFFSET (0)
408#define MTK_RX_TCP_SRC_PORT_OFFSET (16)
409
developerfd40db22021-04-29 10:08:25 +0800410/* QDMA TX Queue Configuration Registers */
developer90270572024-01-30 09:26:15 +0800411#define MTK_QTX_CFG(x) (QDMA_BASE + (x * 0x10))
412#define MTK_QTX_CFG_HW_RESV_CNT_OFFSET GENMASK(15, 8)
413#define MTK_QTX_CFG_SW_RESV_CNT_OFFSET GENMASK(7, 0)
414#define QDMA_RES_THRES 4
developerfd40db22021-04-29 10:08:25 +0800415
416/* QDMA TX Queue Scheduler Registers */
developer90270572024-01-30 09:26:15 +0800417#define MTK_QTX_SCH(x) (QDMA_BASE + 4 + (x * 0x10))
418#define MTK_QTX_SCH_TX_SEL BIT(31)
419#define MTK_QTX_SCH_TX_SEL_V2 GENMASK(31, 30)
420#define MTK_QTX_SCH_LEAKY_BUCKET_EN BIT(30)
421#define MTK_QTX_SCH_LEAKY_BUCKET_SIZE GENMASK(29, 28)
422#define MTK_QTX_SCH_MIN_RATE_EN BIT(27)
423#define MTK_QTX_SCH_MIN_RATE_MAN GENMASK(26, 20)
424#define MTK_QTX_SCH_MIN_RATE_EXP GENMASK(19, 16)
425#define MTK_QTX_SCH_MAX_RATE_WEIGHT GENMASK(15, 12)
426#define MTK_QTX_SCH_MAX_RATE_EN BIT(11)
427#define MTK_QTX_SCH_MAX_RATE_MAN GENMASK(10, 4)
428#define MTK_QTX_SCH_MAX_RATE_EXP GENMASK(3, 0)
developerfd40db22021-04-29 10:08:25 +0800429
430/* QDMA RX Base Pointer Register */
431#define MTK_QRX_BASE_PTR0 (QDMA_BASE + 0x100)
432#define MTK_QRX_BASE_PTR_CFG(x) (MTK_QRX_BASE_PTR0 + ((x) * 0x10))
433
434/* QDMA RX Maximum Count Register */
435#define MTK_QRX_MAX_CNT0 (QDMA_BASE + 0x104)
436#define MTK_QRX_MAX_CNT_CFG(x) (MTK_QRX_MAX_CNT0 + ((x) * 0x10))
437
438/* QDMA RX CPU Pointer Register */
439#define MTK_QRX_CRX_IDX0 (QDMA_BASE + 0x108)
440#define MTK_QRX_CRX_IDX_CFG(x) (MTK_QRX_CRX_IDX0 + ((x) * 0x10))
441
442/* QDMA RX DMA Pointer Register */
443#define MTK_QRX_DRX_IDX0 (QDMA_BASE + 0x10c)
444
developer329d8ee2022-08-02 08:49:42 +0800445/* QDMA Page Configuration Register */
developer90270572024-01-30 09:26:15 +0800446#define MTK_QDMA_PAGE (QDMA_BASE + 0x1f0)
447#define MTK_QTX_CFG_PAGE GENMASK(3, 0)
448#define MTK_QTX_PER_PAGE (16)
developer329d8ee2022-08-02 08:49:42 +0800449
developerfd40db22021-04-29 10:08:25 +0800450/* QDMA Global Configuration Register */
451#define MTK_QDMA_GLO_CFG (QDMA_BASE + 0x204)
452#define MTK_RX_2B_OFFSET BIT(31)
developer58ab5842022-06-01 15:10:25 +0800453#define MTK_PKT_RX_WDONE BIT(27)
developerfd40db22021-04-29 10:08:25 +0800454#define MTK_RX_BT_32DWORDS (3 << 11)
455#define MTK_NDP_CO_PRO BIT(10)
456#define MTK_TX_WB_DDONE BIT(6)
457#define MTK_DMA_SIZE_16DWORDS (2 << 4)
458#define MTK_DMA_SIZE_32DWORDS (3 << 4)
459#define MTK_RX_DMA_BUSY BIT(3)
460#define MTK_TX_DMA_BUSY BIT(1)
461#define MTK_RX_DMA_EN BIT(2)
462#define MTK_TX_DMA_EN BIT(0)
463#define MTK_DMA_BUSY_TIMEOUT HZ
464
465/* QDMA V2 Global Configuration Register */
466#define MTK_CHK_DDONE_EN BIT(28)
467#define MTK_DMAD_WR_WDONE BIT(26)
468#define MTK_WCOMP_EN BIT(24)
developer2cdef092022-04-15 17:27:55 +0800469#define MTK_RESV_BUF (0x80 << 16)
developerfd40db22021-04-29 10:08:25 +0800470#define MTK_MUTLI_CNT (0x4 << 12)
developer19d84562022-04-21 17:01:06 +0800471#define MTK_RESV_BUF_MASK (0xff << 16)
developerfd40db22021-04-29 10:08:25 +0800472
473/* QDMA Reset Index Register */
474#define MTK_QDMA_RST_IDX (QDMA_BASE + 0x208)
475
476/* QDMA Delay Interrupt Register */
477#define MTK_QDMA_DELAY_INT (QDMA_BASE + 0x20c)
478
479/* QDMA Flow Control Register */
480#define MTK_QDMA_FC_THRES (QDMA_BASE + 0x210)
481#define FC_THRES_DROP_MODE BIT(20)
482#define FC_THRES_DROP_EN (7 << 16)
483#define FC_THRES_MIN 0x4444
484
485/* QDMA Interrupt Status Register */
486#define MTK_QDMA_INT_STATUS (QDMA_BASE + 0x218)
developer8ecd51b2023-03-13 11:28:28 +0800487#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer94806ec2023-05-19 14:16:44 +0800488#define MTK_RX_DONE_INT(ring_no) \
developer089e8852022-09-28 14:43:46 +0800489 (MTK_HAS_CAPS(eth->soc->caps, MTK_RSS) ? (BIT(24 + (ring_no))) : \
490 ((ring_no) ? BIT(16 + (ring_no)) : BIT(14)))
developerfd40db22021-04-29 10:08:25 +0800491#else
developer94806ec2023-05-19 14:16:44 +0800492#define MTK_RX_DONE_INT(ring_no) \
developer849af362023-09-28 17:11:43 +0800493 (MTK_HAS_CAPS(eth->soc->caps, MTK_RSS) ? ((ring_no) ? BIT(24 + (ring_no)) : BIT(30)) : \
494 (BIT(16 + (ring_no))))
developerfd40db22021-04-29 10:08:25 +0800495#endif
496#define MTK_RX_DONE_INT3 BIT(19)
497#define MTK_RX_DONE_INT2 BIT(18)
498#define MTK_RX_DONE_INT1 BIT(17)
499#define MTK_RX_DONE_INT0 BIT(16)
500#define MTK_TX_DONE_INT3 BIT(3)
501#define MTK_TX_DONE_INT2 BIT(2)
502#define MTK_TX_DONE_INT1 BIT(1)
503#define MTK_TX_DONE_INT0 BIT(0)
developera7fbeec2024-02-02 13:56:07 +0800504#if defined(CONFIG_MEDIATEK_NETSYS_V3)
505#define MTK_TX_DONE_INT(ring_no) \
506 (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA) ? BIT(28) : \
507 BIT(4 + (ring_no)))
508#else
509#define MTK_TX_DONE_INT(ring_no) \
510 (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA) ? BIT(28) : \
511 BIT((ring_no)))
512#endif
developerfd40db22021-04-29 10:08:25 +0800513
514/* QDMA Interrupt grouping registers */
515#define MTK_QDMA_INT_GRP1 (QDMA_BASE + 0x220)
516#define MTK_QDMA_INT_GRP2 (QDMA_BASE + 0x224)
517#define MTK_RLS_DONE_INT BIT(0)
518
519/* QDMA Interrupt Status Register */
520#define MTK_QDMA_INT_MASK (QDMA_BASE + 0x21c)
521
developer8051e042022-04-08 13:26:36 +0800522/* QDMA DMA FSM */
523#define MTK_QDMA_FSM (QDMA_BASE + 0x234)
524
developerfd40db22021-04-29 10:08:25 +0800525/* QDMA Interrupt Mask Register */
526#define MTK_QDMA_HRED2 (QDMA_BASE + 0x244)
527
528/* QDMA TX Forward CPU Pointer Register */
529#define MTK_QTX_CTX_PTR (QDMA_BASE +0x300)
530
531/* QDMA TX Forward DMA Pointer Register */
532#define MTK_QTX_DTX_PTR (QDMA_BASE +0x304)
533
developer8051e042022-04-08 13:26:36 +0800534/* QDMA TX Forward DMA Counter */
535#define MTK_QDMA_FWD_CNT (QDMA_BASE + 0x308)
536
developerfd40db22021-04-29 10:08:25 +0800537/* QDMA TX Release CPU Pointer Register */
538#define MTK_QTX_CRX_PTR (QDMA_BASE +0x310)
539
540/* QDMA TX Release DMA Pointer Register */
541#define MTK_QTX_DRX_PTR (QDMA_BASE +0x314)
542
543/* QDMA FQ Head Pointer Register */
544#define MTK_QDMA_FQ_HEAD (QDMA_BASE +0x320)
545
546/* QDMA FQ Head Pointer Register */
547#define MTK_QDMA_FQ_TAIL (QDMA_BASE +0x324)
548
549/* QDMA FQ Free Page Counter Register */
550#define MTK_QDMA_FQ_CNT (QDMA_BASE +0x328)
551
552/* QDMA FQ Free Page Buffer Length Register */
553#define MTK_QDMA_FQ_BLEN (QDMA_BASE +0x32c)
554
developer8051e042022-04-08 13:26:36 +0800555/* WDMA Registers */
developer37482a42022-12-26 13:31:13 +0800556#define MTK_WDMA_CTX_PTR(x) (WDMA_BASE(x) + 0x8)
developer8051e042022-04-08 13:26:36 +0800557#define MTK_WDMA_DTX_PTR(x) (WDMA_BASE(x) + 0xC)
558#define MTK_WDMA_GLO_CFG(x) (WDMA_BASE(x) + 0x204)
559#define MTK_WDMA_TX_DBG_MON0(x) (WDMA_BASE(x) + 0x230)
developer37482a42022-12-26 13:31:13 +0800560#define MTK_WDMA_RX_DBG_MON1(x) (WDMA_BASE(x) + 0x3c4)
561#define MTK_WDMA_CRX_PTR(x) (WDMA_BASE(x) + 0x108)
562#define MTK_WDMA_DRX_PTR(x) (WDMA_BASE(x) + 0x10C)
developer8051e042022-04-08 13:26:36 +0800563#define MTK_CDM_TXFIFO_RDY BIT(7)
564
developer37482a42022-12-26 13:31:13 +0800565/*TDMA Register*/
566#define MTK_TDMA_GLO_CFG (0x6204)
567
developerfd40db22021-04-29 10:08:25 +0800568/* GMA1 Received Good Byte Count Register */
developer089e8852022-09-28 14:43:46 +0800569#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developerfd40db22021-04-29 10:08:25 +0800570#define MTK_GDM1_TX_GBCNT 0x1C00
571#else
572#define MTK_GDM1_TX_GBCNT 0x2400
573#endif
developer089e8852022-09-28 14:43:46 +0800574
575#if defined(CONFIG_MEDIATEK_NETSYS_V3)
576#define MTK_STAT_OFFSET 0x80
577#else
developerfd40db22021-04-29 10:08:25 +0800578#define MTK_STAT_OFFSET 0x40
developer089e8852022-09-28 14:43:46 +0800579#endif
developerfd40db22021-04-29 10:08:25 +0800580
581/* QDMA TX NUM */
582#define MTK_QDMA_TX_NUM 16
developer797e46c2022-07-29 12:05:32 +0800583#define MTK_QDMA_PAGE_NUM 8
developerfd40db22021-04-29 10:08:25 +0800584#define MTK_QDMA_TX_MASK ((MTK_QDMA_TX_NUM) - 1)
585#define QID_LOW_BITS(x) ((x) & 0xf)
586#define QID_HIGH_BITS(x) ((((x) >> 4) & 0x3) << 20)
587#define QID_BITS_V2(x) (((x) & 0x3f) << 16)
588
developerdc0d45f2021-12-27 13:01:22 +0800589#define MTK_QDMA_GMAC2_QID 8
developer90270572024-01-30 09:26:15 +0800590#define MTK_QDMA_GMAC3_QID 6
developerdc0d45f2021-12-27 13:01:22 +0800591
developerfd40db22021-04-29 10:08:25 +0800592/* QDMA V2 descriptor txd6 */
593#define TX_DMA_INS_VLAN_V2 BIT(16)
594
595/* QDMA V2 descriptor txd5 */
596#define TX_DMA_CHKSUM_V2 (0x7 << 28)
597#define TX_DMA_TSO_V2 BIT(31)
developer089e8852022-09-28 14:43:46 +0800598#define TX_DMA_SPTAG_V3 BIT(27)
developerfd40db22021-04-29 10:08:25 +0800599
600/* QDMA V2 descriptor txd4 */
601#define TX_DMA_FPORT_SHIFT_V2 8
602#define TX_DMA_FPORT_MASK_V2 0xf
603#define TX_DMA_SWC_V2 BIT(30)
604
developerfd40db22021-04-29 10:08:25 +0800605#define MTK_TX_DMA_BUF_LEN 0x3fff
developere9356982022-07-04 09:03:20 +0800606#define MTK_TX_DMA_BUF_LEN_V2 0xffff
developerfd40db22021-04-29 10:08:25 +0800607#define MTK_TX_DMA_BUF_SHIFT 16
developere9356982022-07-04 09:03:20 +0800608#define MTK_TX_DMA_BUF_SHIFT_V2 8
developerfd40db22021-04-29 10:08:25 +0800609
developer8ecd51b2023-03-13 11:28:28 +0800610#define MTK_RX_DMA_BUF_LEN 0x3fff
611#define MTK_RX_DMA_BUF_SHIFT 16
612
developerfd40db22021-04-29 10:08:25 +0800613#define RX_DMA_SPORT_SHIFT 19
developere9356982022-07-04 09:03:20 +0800614#define RX_DMA_SPORT_SHIFT_V2 26
developerfd40db22021-04-29 10:08:25 +0800615#define RX_DMA_SPORT_MASK 0x7
developere9356982022-07-04 09:03:20 +0800616#define RX_DMA_SPORT_MASK_V2 0xf
developerfd40db22021-04-29 10:08:25 +0800617
618/* QDMA descriptor txd4 */
619#define TX_DMA_CHKSUM (0x7 << 29)
620#define TX_DMA_TSO BIT(28)
621#define TX_DMA_FPORT_SHIFT 25
622#define TX_DMA_FPORT_MASK 0x7
623#define TX_DMA_INS_VLAN BIT(16)
624
625/* QDMA descriptor txd3 */
626#define TX_DMA_OWNER_CPU BIT(31)
627#define TX_DMA_LS0 BIT(30)
developera7fbeec2024-02-02 13:56:07 +0800628#define TX_DMA_PLEN0(_x) (((_x) & eth->soc->txrx.dma_max_len) << \
629 eth->soc->txrx.dma_len_offset)
630#if defined(CONFIG_MEDIATEK_NETSYS_V3)
631#define TX_DMA_PLEN1(_x) (((_x) & eth->soc->txrx.dma_max_len) << \
632 eth->soc->txrx.dma_len_offset)
633#else
developere9356982022-07-04 09:03:20 +0800634#define TX_DMA_PLEN1(_x) ((_x) & eth->soc->txrx.dma_max_len)
developera7fbeec2024-02-02 13:56:07 +0800635#endif
developerfd40db22021-04-29 10:08:25 +0800636#define TX_DMA_SWC BIT(14)
developer089e8852022-09-28 14:43:46 +0800637#define TX_DMA_SDP1(_x) ((((u64)(_x)) >> 32) & 0xf)
developerfd40db22021-04-29 10:08:25 +0800638
639/* PDMA on MT7628 */
640#define TX_DMA_DONE BIT(31)
641#define TX_DMA_LS1 BIT(14)
642#define TX_DMA_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE)
643
644/* QDMA descriptor rxd2 */
645#define RX_DMA_DONE BIT(31)
646#define RX_DMA_LSO BIT(30)
developer8ecd51b2023-03-13 11:28:28 +0800647#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developere9356982022-07-04 09:03:20 +0800648#define RX_DMA_PLEN0(_x) (((_x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
649#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 +0800650#else
651#define RX_DMA_PLEN0(_x) \
652 (((_x) & MTK_RX_DMA_BUF_LEN) << MTK_RX_DMA_BUF_SHIFT)
653#define RX_DMA_GET_PLEN0(_x) \
654 (((_x) >> MTK_RX_DMA_BUF_SHIFT) & MTK_RX_DMA_BUF_LEN)
655#endif
656
developer77d03a72021-06-06 00:06:00 +0800657#define RX_DMA_GET_AGG_CNT(_x) (((_x) >> 2) & 0xff)
658#define RX_DMA_GET_REV(_x) (((_x) >> 10) & 0x1f)
developerfd40db22021-04-29 10:08:25 +0800659#define RX_DMA_VTAG BIT(15)
developer089e8852022-09-28 14:43:46 +0800660#define RX_DMA_SDP1(_x) ((((u64)(_x)) >> 32) & 0xf)
developer8e12a952023-12-27 16:14:05 +0800661#define RX_DMA_GET_SDP1(_x) ((_x) & 0xf)
developerfd40db22021-04-29 10:08:25 +0800662
663/* QDMA descriptor rxd3 */
664#define RX_DMA_VID(_x) ((_x) & VLAN_VID_MASK)
665#define RX_DMA_TCI(_x) ((_x) & (VLAN_PRIO_MASK | VLAN_VID_MASK))
666#define RX_DMA_VPID(_x) (((_x) >> 16) & 0xffff)
667
668/* QDMA descriptor rxd4 */
669#define RX_DMA_L4_VALID BIT(24)
670#define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
671#define RX_DMA_SPECIAL_TAG BIT(22) /* switch header in packet */
672
673#define RX_DMA_GET_SPORT(_x) (((_x) >> RX_DMA_SPORT_SHIFT) & RX_DMA_SPORT_MASK)
developere9356982022-07-04 09:03:20 +0800674#define RX_DMA_GET_SPORT_V2(_x) (((_x) >> RX_DMA_SPORT_SHIFT_V2) & RX_DMA_SPORT_MASK_V2)
developerfd40db22021-04-29 10:08:25 +0800675
developera7fbeec2024-02-02 13:56:07 +0800676/* PDMA V2 descriptor txd4 */
677#define TX_DMA_LS1_V2 BIT(30)
678
679/* PDMA V2 descriptor txd5 */
680#define TX_DMA_FPORT_SHIFT_PDMA 16
681
developerfd40db22021-04-29 10:08:25 +0800682/* PDMA V2 descriptor rxd3 */
683#define RX_DMA_VTAG_V2 BIT(0)
684#define RX_DMA_L4_VALID_V2 BIT(2)
685
686/* PDMA V2 descriptor rxd4 */
687#define RX_DMA_VID_V2(_x) RX_DMA_VID(_x)
developer255bba22021-07-27 15:16:33 +0800688#define RX_DMA_TCI_V2(_x) RX_DMA_TCI(_x)
689#define RX_DMA_VPID_V2(_x) RX_DMA_VPID(_x)
developerfd40db22021-04-29 10:08:25 +0800690
developer77d03a72021-06-06 00:06:00 +0800691/* PDMA V2 descriptor rxd6 */
692#define RX_DMA_GET_FLUSH_RSN_V2(_x) ((_x) & 0x7)
693#define RX_DMA_GET_AGG_CNT_V2(_x) (((_x) >> 16) & 0xff)
developer006325c2022-10-06 16:39:50 +0800694#define RX_DMA_GET_TOPS_CRSN(_x) (((_x) >> 24) & 0xff)
developer77d03a72021-06-06 00:06:00 +0800695
developerc8acd8d2022-11-10 09:07:10 +0800696/* PHY Polling and SMI Master Control registers */
697#define MTK_PPSC 0x10000
698#define PPSC_MDC_CFG GENMASK(29, 24)
699#define PPSC_MDC_TURBO BIT(20)
developerc4d8da72023-03-16 14:37:28 +0800700#define MDC_MAX_FREQ 25000000
701#define MDC_MAX_DIVIDER 63
developerc8acd8d2022-11-10 09:07:10 +0800702
developerfd40db22021-04-29 10:08:25 +0800703/* PHY Indirect Access Control registers */
704#define MTK_PHY_IAC 0x10004
705#define PHY_IAC_ACCESS BIT(31)
706#define PHY_IAC_READ BIT(19)
developer599cda42022-05-24 15:13:31 +0800707#define PHY_IAC_READ_C45 (3 << 18)
708#define PHY_IAC_ADDR_C45 (0 << 18)
developerfd40db22021-04-29 10:08:25 +0800709#define PHY_IAC_WRITE BIT(18)
710#define PHY_IAC_START BIT(16)
developer599cda42022-05-24 15:13:31 +0800711#define PHY_IAC_START_C45 (0 << 16)
developerfd40db22021-04-29 10:08:25 +0800712#define PHY_IAC_ADDR_SHIFT 20
713#define PHY_IAC_REG_SHIFT 25
714#define PHY_IAC_TIMEOUT HZ
715
developerc8acd8d2022-11-10 09:07:10 +0800716#if defined(CONFIG_MEDIATEK_NETSYS_V3)
717#define MTK_MAC_MISC 0x10010
718#else
developerfd40db22021-04-29 10:08:25 +0800719#define MTK_MAC_MISC 0x1000c
developerc8acd8d2022-11-10 09:07:10 +0800720#endif
721#define MISC_MDC_TURBO BIT(4)
developerfd40db22021-04-29 10:08:25 +0800722#define MTK_MUX_TO_ESW BIT(0)
723
developer089e8852022-09-28 14:43:46 +0800724/* XMAC status registers */
725#define MTK_XGMAC_STS(x) ((x == MTK_GMAC3_ID) ? 0x1001C : 0x1000C)
developer9a3fcc82023-11-18 10:44:34 +0800726#define MTK_XGMAC_FORCE_MODE(x) ((x == MTK_GMAC2_ID) ? BIT(31) : BIT(15))
727#define MTK_XGMAC_FORCE_LINK(x) ((x == MTK_GMAC2_ID) ? BIT(27) : BIT(11))
developer089e8852022-09-28 14:43:46 +0800728#define MTK_USXGMII_PCS_LINK BIT(8)
729#define MTK_XGMAC_RX_FC BIT(5)
730#define MTK_XGMAC_TX_FC BIT(4)
731#define MTK_USXGMII_PCS_MODE GENMASK(3, 1)
732#define MTK_XGMAC_LINK_STS BIT(0)
733
734/* GSW bridge registers */
735#define MTK_GSW_CFG (0x10080)
736#define GSWTX_IPG_MASK GENMASK(19, 16)
737#define GSWTX_IPG_SHIFT 16
738#define GSWRX_IPG_MASK GENMASK(3, 0)
739#define GSWRX_IPG_SHIFT 0
740#define GSW_IPG_11 11
741
developerfd40db22021-04-29 10:08:25 +0800742/* Mac control registers */
743#define MTK_MAC_MCR(x) (0x10100 + (x * 0x100))
744#define MAC_MCR_MAX_RX_1536 BIT(24)
developerd8a29752022-08-19 13:32:03 +0800745#define MAC_MCR_IPG_CFG (BIT(18) | BIT(16) | BIT(12))
developerfd40db22021-04-29 10:08:25 +0800746#define MAC_MCR_FORCE_MODE BIT(15)
747#define MAC_MCR_TX_EN BIT(14)
748#define MAC_MCR_RX_EN BIT(13)
developer2cd8fe82024-03-19 23:10:37 +0800749#define MAC_MCR_PRMBL_LMT_EN BIT(10)
developerfd40db22021-04-29 10:08:25 +0800750#define MAC_MCR_BACKOFF_EN BIT(9)
751#define MAC_MCR_BACKPR_EN BIT(8)
developer9b725932022-11-24 16:25:56 +0800752#define MAC_MCR_FORCE_EEE1000 BIT(7)
753#define MAC_MCR_FORCE_EEE100 BIT(6)
developerfd40db22021-04-29 10:08:25 +0800754#define MAC_MCR_FORCE_RX_FC BIT(5)
755#define MAC_MCR_FORCE_TX_FC BIT(4)
756#define MAC_MCR_SPEED_1000 BIT(3)
757#define MAC_MCR_SPEED_100 BIT(2)
758#define MAC_MCR_FORCE_DPX BIT(1)
759#define MAC_MCR_FORCE_LINK BIT(0)
760#define MAC_MCR_FORCE_LINK_DOWN (MAC_MCR_FORCE_MODE)
761
developer089e8852022-09-28 14:43:46 +0800762/* XFI Mac control registers */
developerff5e5092023-07-25 15:55:28 +0800763#define MTK_XMAC_BASE(x) (0x12000 + ((x - 1) * 0x1000))
764#define MTK_XMAC_MCR(x) (MTK_XMAC_BASE(x))
developer089e8852022-09-28 14:43:46 +0800765#define XMAC_MCR_TRX_DISABLE 0xf
766#define XMAC_MCR_FORCE_TX_FC BIT(5)
767#define XMAC_MCR_FORCE_RX_FC BIT(4)
768
developerff5e5092023-07-25 15:55:28 +0800769/* XFI Mac logic reset registers */
770#define MTK_XMAC_LOGIC_RST(x) (MTK_XMAC_BASE(x) + 0x10)
771#define XMAC_LOGIC_RST BIT(0)
772
773/* XFI Mac count global control */
774#define MTK_XMAC_CNT_CTRL(x) (MTK_XMAC_BASE(x) + 0x100)
775#define XMAC_GLB_CNTCLR BIT(0)
776
developer9b725932022-11-24 16:25:56 +0800777/* Mac EEE control registers */
778#define MTK_MAC_EEE(x) (0x10104 + (x * 0x100))
779#define MAC_EEE_WAKEUP_TIME_1000 GENMASK(31, 24)
780#define MAC_EEE_WAKEUP_TIME_100 GENMASK(23, 16)
781#define MAC_EEE_LPI_TXIDLE_THD GENMASK(15, 8)
782#define MAC_EEE_RESV0 GENMASK(7, 4)
783#define MAC_EEE_CKG_TXILDE BIT(3)
784#define MAC_EEE_CKG_RXLPI BIT(2)
785#define MAC_EEE_TX_DOWN_REQ BIT(1)
786#define MAC_EEE_LPI_MODE BIT(0)
787
developerfd40db22021-04-29 10:08:25 +0800788/* Mac status registers */
789#define MTK_MAC_MSR(x) (0x10108 + (x * 0x100))
790#define MAC_MSR_EEE1G BIT(7)
791#define MAC_MSR_EEE100M BIT(6)
792#define MAC_MSR_RX_FC BIT(5)
793#define MAC_MSR_TX_FC BIT(4)
794#define MAC_MSR_SPEED_1000 BIT(3)
795#define MAC_MSR_SPEED_100 BIT(2)
796#define MAC_MSR_SPEED_MASK (MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100)
797#define MAC_MSR_DPX BIT(1)
798#define MAC_MSR_LINK BIT(0)
799
800/* TRGMII RXC control register */
801#define TRGMII_RCK_CTRL 0x10300
802#define DQSI0(x) ((x << 0) & GENMASK(6, 0))
803#define DQSI1(x) ((x << 8) & GENMASK(14, 8))
804#define RXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
805#define RXC_RST BIT(31)
806#define RXC_DQSISEL BIT(30)
807#define RCK_CTRL_RGMII_1000 (RXC_DQSISEL | RXCTL_DMWTLAT(2) | DQSI1(16))
808#define RCK_CTRL_RGMII_10_100 RXCTL_DMWTLAT(2)
809
810#define NUM_TRGMII_CTRL 5
811
812/* TRGMII RXC control register */
813#define TRGMII_TCK_CTRL 0x10340
814#define TXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
815#define TXC_INV BIT(30)
816#define TCK_CTRL_RGMII_1000 TXCTL_DMWTLAT(2)
817#define TCK_CTRL_RGMII_10_100 (TXC_INV | TXCTL_DMWTLAT(2))
818
819/* TRGMII TX Drive Strength */
820#define TRGMII_TD_ODT(i) (0x10354 + 8 * (i))
821#define TD_DM_DRVP(x) ((x) & 0xf)
822#define TD_DM_DRVN(x) (((x) & 0xf) << 4)
823
824/* TRGMII Interface mode register */
825#define INTF_MODE 0x10390
826#define TRGMII_INTF_DIS BIT(0)
827#define TRGMII_MODE BIT(1)
828#define TRGMII_CENTRAL_ALIGNED BIT(2)
829#define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
830#define INTF_MODE_RGMII_10_100 0
831
832/* GPIO port control registers for GMAC 2*/
833#define GPIO_OD33_CTRL8 0x4c0
834#define GPIO_BIAS_CTRL 0xed0
835#define GPIO_DRV_SEL10 0xf00
836
developer0fef5222023-04-26 14:48:31 +0800837/* SoC hardware version register */
838#define HWVER_BIT_NETSYS_1_2 BIT(0)
839#define HWVER_BIT_NETSYS_3 BIT(8)
840
developerfd40db22021-04-29 10:08:25 +0800841/* ethernet subsystem chip id register */
842#define ETHSYS_CHIPID0_3 0x0
843#define ETHSYS_CHIPID4_7 0x4
844#define MT7623_ETH 7623
845#define MT7622_ETH 7622
846#define MT7621_ETH 7621
847
848/* ethernet system control register */
849#define ETHSYS_SYSCFG 0x10
850#define SYSCFG_DRAM_TYPE_DDR2 BIT(4)
851
852/* ethernet subsystem config register */
853#define ETHSYS_SYSCFG0 0x14
854#define SYSCFG0_GE_MASK 0x3
855#define SYSCFG0_GE_MODE(x, y) (x << (12 + (y * 2)))
developer089e8852022-09-28 14:43:46 +0800856#define SYSCFG0_SGMII_MASK GENMASK(9, 7)
developerfd40db22021-04-29 10:08:25 +0800857#define SYSCFG0_SGMII_GMAC1 ((2 << 8) & SYSCFG0_SGMII_MASK)
858#define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK)
859#define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
860#define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
developer089e8852022-09-28 14:43:46 +0800861#define SYSCFG0_SGMII_GMAC3_V2 BIT(7)
developerfd40db22021-04-29 10:08:25 +0800862
863
864/* ethernet subsystem clock register */
865#define ETHSYS_CLKCFG0 0x2c
866#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
867#define ETHSYS_TRGMII_MT7621_MASK (BIT(5) | BIT(6))
868#define ETHSYS_TRGMII_MT7621_APLL BIT(6)
869#define ETHSYS_TRGMII_MT7621_DDR_PLL BIT(5)
870
871/* ethernet reset control register */
developer545abf02021-07-15 17:47:01 +0800872#define ETHSYS_RSTCTRL 0x34
873#define RSTCTRL_FE BIT(6)
developer545abf02021-07-15 17:47:01 +0800874#define RSTCTRL_ETH BIT(23)
developer8051e042022-04-08 13:26:36 +0800875#if defined(CONFIG_MEDIATEK_NETSYS_V2)
876#define RSTCTRL_PPE0 BIT(30)
877#define RSTCTRL_PPE1 BIT(31)
developer37482a42022-12-26 13:31:13 +0800878#elif defined(CONFIG_MEDIATEK_NETSYS_V3)
879#define RSTCTRL_PPE0 BIT(29)
880#define RSTCTRL_PPE1 BIT(30)
881#define RSTCTRL_PPE2 BIT(31)
882#define RSTCTRL_WDMA0 BIT(24)
883#define RSTCTRL_WDMA1 BIT(25)
884#define RSTCTRL_WDMA2 BIT(26)
developera5eb8d62022-04-22 15:42:20 +0800885#else
developer8051e042022-04-08 13:26:36 +0800886#define RSTCTRL_PPE0 BIT(31)
developer37482a42022-12-26 13:31:13 +0800887#define RSTCTRL_PPE1 0
developer8051e042022-04-08 13:26:36 +0800888#endif
developer545abf02021-07-15 17:47:01 +0800889
890/* ethernet reset check idle register */
891#define ETHSYS_FE_RST_CHK_IDLE_EN 0x28
892
developer3f28d382023-03-07 16:06:30 +0800893/* ethernet dma channel agent map */
894#define ETHSYS_DMA_AG_MAP 0x408
895#define ETHSYS_DMA_AG_MAP_PDMA BIT(0)
896#define ETHSYS_DMA_AG_MAP_QDMA BIT(1)
897#define ETHSYS_DMA_AG_MAP_PPE BIT(2)
developerfd40db22021-04-29 10:08:25 +0800898
899/* SGMII subsystem config registers */
developerfd40db22021-04-29 10:08:25 +0800900#define SGMSYS_PCS_CONTROL_1 0x0
developer38afb1a2023-04-17 09:57:27 +0800901#define SGMII_BMSR GENMASK(31, 16)
developerfd40db22021-04-29 10:08:25 +0800902#define SGMII_AN_RESTART BIT(9)
903#define SGMII_ISOLATE BIT(10)
904#define SGMII_AN_ENABLE BIT(12)
905#define SGMII_LINK_STATYS BIT(18)
906#define SGMII_AN_ABILITY BIT(19)
907#define SGMII_AN_COMPLETE BIT(21)
908#define SGMII_PCS_FAULT BIT(23)
909#define SGMII_AN_EXPANSION_CLR BIT(30)
910
developer089e8852022-09-28 14:43:46 +0800911/* Register to set SGMII speed */
developer38afb1a2023-04-17 09:57:27 +0800912#define SGMSYS_PCS_ADVERTISE 0x08
913#define SGMII_ADVERTISE GENMASK(15, 0)
914#define SGMII_LPA GENMASK(31, 16)
915#define SGMII_LPA_SPEED_MASK GENMASK(11, 10)
916#define SGMII_LPA_SPEED_10 0
917#define SGMII_LPA_SPEED_100 1
918#define SGMII_LPA_SPEED_1000 2
919#define SGMII_LPA_DUPLEX BIT(12)
920#define SGMII_LPA_LINK BIT(15)
developer089e8852022-09-28 14:43:46 +0800921
developerfd40db22021-04-29 10:08:25 +0800922/* Register to programmable link timer, the unit in 2 * 8ns */
923#define SGMSYS_PCS_LINK_TIMER 0x18
924#define SGMII_LINK_TIMER_DEFAULT (0x186a0 & GENMASK(19, 0))
925
926/* Register to control remote fault */
927#define SGMSYS_SGMII_MODE 0x20
developer38afb1a2023-04-17 09:57:27 +0800928#define SGMII_IF_MODE_SGMII BIT(0)
developerfd40db22021-04-29 10:08:25 +0800929#define SGMII_SPEED_DUPLEX_AN BIT(1)
developer089e8852022-09-28 14:43:46 +0800930#define SGMII_SPEED_MASK GENMASK(3, 2)
developerfd40db22021-04-29 10:08:25 +0800931#define SGMII_SPEED_10 0x0
932#define SGMII_SPEED_100 BIT(2)
933#define SGMII_SPEED_1000 BIT(3)
developer4e8a3fd2023-04-10 18:05:44 +0800934#define SGMII_DUPLEX_HALF BIT(4)
developerfd40db22021-04-29 10:08:25 +0800935#define SGMII_IF_MODE_BIT5 BIT(5)
936#define SGMII_REMOTE_FAULT_DIS BIT(8)
937#define SGMII_CODE_SYNC_SET_VAL BIT(9)
938#define SGMII_CODE_SYNC_SET_EN BIT(10)
939#define SGMII_SEND_AN_ERROR_EN BIT(11)
940#define SGMII_IF_MODE_MASK GENMASK(5, 1)
941
developer2b76a9d2022-09-20 14:59:45 +0800942/* Register to reset SGMII design */
943#define SGMII_RESERVED_0 0x34
944#define SGMII_SW_RESET BIT(0)
945
developerfd40db22021-04-29 10:08:25 +0800946/* Register to set SGMII speed, ANA RG_ Control Signals III*/
947#define SGMSYS_ANA_RG_CS3 0x2028
948#define RG_PHY_SPEED_MASK (BIT(2) | BIT(3))
949#define RG_PHY_SPEED_1_25G 0x0
950#define RG_PHY_SPEED_3_125G BIT(2)
951
952/* Register to power up QPHY */
953#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
954#define SGMII_PHYA_PWD BIT(4)
955
developerf8ac94a2021-07-29 16:40:01 +0800956/* Register to QPHY wrapper control */
957#define SGMSYS_QPHY_WRAP_CTRL 0xec
958#define SGMII_PN_SWAP_MASK GENMASK(1, 0)
959#define SGMII_PN_SWAP_TX_RX (BIT(0) | BIT(1))
960
developer089e8852022-09-28 14:43:46 +0800961/* USXGMII subsystem config registers */
962/* Register to control speed */
963#define RG_PHY_TOP_SPEED_CTRL1 0x80C
developer95169b62023-05-12 17:58:58 +0800964#define USXGMII_RATE_UPDATE_MODE BIT(31)
965#define USXGMII_MAC_CK_GATED BIT(29)
966#define USXGMII_IF_FORCE_EN BIT(28)
967#define USXGMII_RATE_ADAPT_MODE GENMASK(10, 8)
968#define USXGMII_RATE_ADAPT_MODE_X1 0
969#define USXGMII_RATE_ADAPT_MODE_X2 1
970#define USXGMII_RATE_ADAPT_MODE_X4 2
971#define USXGMII_RATE_ADAPT_MODE_X10 3
972#define USXGMII_RATE_ADAPT_MODE_X100 4
973#define USXGMII_RATE_ADAPT_MODE_X5 5
974#define USXGMII_RATE_ADAPT_MODE_X50 6
975#define USXGMII_XFI_RX_MODE GENMASK(6, 4)
976#define USXGMII_XFI_RX_MODE_10G 0
977#define USXGMII_XFI_RX_MODE_5G 1
978#define USXGMII_XFI_TX_MODE GENMASK(2, 0)
979#define USXGMII_XFI_TX_MODE_10G 0
980#define USXGMII_XFI_TX_MODE_5G 1
developer089e8852022-09-28 14:43:46 +0800981
982/* Register to control PCS AN */
983#define RG_PCS_AN_CTRL0 0x810
developer4e8a3fd2023-04-10 18:05:44 +0800984#define USXGMII_AN_RESTART BIT(31)
developer95169b62023-05-12 17:58:58 +0800985#define USXGMII_AN_SYNC_CNT GENMASK(30, 11)
developer4e8a3fd2023-04-10 18:05:44 +0800986#define USXGMII_AN_ENABLE BIT(0)
987
developer95169b62023-05-12 17:58:58 +0800988#define RG_PCS_AN_CTRL2 0x818
989#define USXGMII_LINK_TIMER_IDLE_DETECT GENMASK(29, 20)
990#define USXGMII_LINK_TIMER_COMP_ACK_DETECT GENMASK(19, 10)
991#define USXGMII_LINK_TIMER_AN_RESTART GENMASK(9, 0)
992
993/* Register to read PCS AN status */
developer4e8a3fd2023-04-10 18:05:44 +0800994#define RG_PCS_AN_STS0 0x81C
995#define USXGMII_LPA_SPEED_MASK GENMASK(11, 9)
996#define USXGMII_LPA_SPEED_10 0
997#define USXGMII_LPA_SPEED_100 1
998#define USXGMII_LPA_SPEED_1000 2
999#define USXGMII_LPA_SPEED_10000 3
1000#define USXGMII_LPA_SPEED_2500 4
1001#define USXGMII_LPA_SPEED_5000 5
1002#define USXGMII_LPA_DUPLEX BIT(12)
1003#define USXGMII_LPA_LINK BIT(15)
1004#define USXGMII_LPA_LATCH BIT(31)
developer089e8852022-09-28 14:43:46 +08001005
developer21260d02023-09-04 11:29:04 +08001006/* Register to read PCS Link status */
1007#define RG_PCS_RX_STATUS0 0x904
1008#define RG_PCS_RX_STATUS_UPDATE BIT(16)
1009#define RG_PCS_RX_LINK_STATUS BIT(2)
1010
developer089e8852022-09-28 14:43:46 +08001011/* Register to control USXGMII XFI PLL digital */
1012#define XFI_PLL_DIG_GLB8 0x08
1013#define RG_XFI_PLL_EN BIT(31)
1014
1015/* Register to control USXGMII XFI PLL analog */
1016#define XFI_PLL_ANA_GLB8 0x108
1017#define RG_XFI_PLL_ANA_SWWA 0x02283248
1018
developerfd40db22021-04-29 10:08:25 +08001019/* Infrasys subsystem config registers */
1020#define INFRA_MISC2 0x70c
1021#define CO_QPHY_SEL BIT(0)
1022#define GEPHY_MAC_SEL BIT(1)
1023
developer024387a2022-12-07 22:18:27 +08001024/* Toprgu subsystem config registers */
1025#define TOPRGU_SWSYSRST 0x18
1026#define SWSYSRST_UNLOCK_KEY GENMASK(31, 24)
1027#define SWSYSRST_XFI_PLL_GRST BIT(16)
1028#define SWSYSRST_XFI_PEXPT1_GRST BIT(15)
1029#define SWSYSRST_XFI_PEXPT0_GRST BIT(14)
developer6aa00162023-03-20 11:56:51 +08001030#define SWSYSRST_XFI1_GRST BIT(13)
1031#define SWSYSRST_XFI0_GRST BIT(12)
developer024387a2022-12-07 22:18:27 +08001032#define SWSYSRST_SGMII1_GRST BIT(2)
1033#define SWSYSRST_SGMII0_GRST BIT(1)
1034#define TOPRGU_SWSYSRST_EN 0xFC
1035
developer255bba22021-07-27 15:16:33 +08001036/* Top misc registers */
developer089e8852022-09-28 14:43:46 +08001037#define TOP_MISC_NETSYS_PCS_MUX 0x84
1038#define NETSYS_PCS_MUX_MASK GENMASK(1, 0)
1039#define MUX_G2_USXGMII_SEL BIT(1)
1040#define MUX_HSGMII1_G1_SEL BIT(0)
developer255bba22021-07-27 15:16:33 +08001041#define USB_PHY_SWITCH_REG 0x218
1042#define QPHY_SEL_MASK GENMASK(1, 0)
developerf1816a92021-11-15 12:18:02 +08001043#define SGMII_QPHY_SEL 0x2
developer255bba22021-07-27 15:16:33 +08001044
developerfd40db22021-04-29 10:08:25 +08001045/*MDIO control*/
1046#define MII_MMD_ACC_CTL_REG 0x0d
1047#define MII_MMD_ADDR_DATA_REG 0x0e
1048#define MMD_OP_MODE_DATA BIT(14)
1049
1050/* MT7628/88 specific stuff */
1051#define MT7628_PDMA_OFFSET 0x0800
1052#define MT7628_SDM_OFFSET 0x0c00
1053
1054#define MT7628_TX_BASE_PTR0 (MT7628_PDMA_OFFSET + 0x00)
1055#define MT7628_TX_MAX_CNT0 (MT7628_PDMA_OFFSET + 0x04)
1056#define MT7628_TX_CTX_IDX0 (MT7628_PDMA_OFFSET + 0x08)
1057#define MT7628_TX_DTX_IDX0 (MT7628_PDMA_OFFSET + 0x0c)
1058#define MT7628_PST_DTX_IDX0 BIT(0)
1059
1060#define MT7628_SDM_MAC_ADRL (MT7628_SDM_OFFSET + 0x0c)
1061#define MT7628_SDM_MAC_ADRH (MT7628_SDM_OFFSET + 0x10)
1062
1063struct mtk_rx_dma {
1064 unsigned int rxd1;
1065 unsigned int rxd2;
1066 unsigned int rxd3;
1067 unsigned int rxd4;
developere9356982022-07-04 09:03:20 +08001068} __packed __aligned(4);
1069
1070struct mtk_rx_dma_v2 {
1071 unsigned int rxd1;
1072 unsigned int rxd2;
1073 unsigned int rxd3;
1074 unsigned int rxd4;
developerfd40db22021-04-29 10:08:25 +08001075 unsigned int rxd5;
1076 unsigned int rxd6;
1077 unsigned int rxd7;
1078 unsigned int rxd8;
developerfd40db22021-04-29 10:08:25 +08001079} __packed __aligned(4);
1080
1081struct mtk_tx_dma {
1082 unsigned int txd1;
1083 unsigned int txd2;
1084 unsigned int txd3;
1085 unsigned int txd4;
developere9356982022-07-04 09:03:20 +08001086} __packed __aligned(4);
1087
1088struct mtk_tx_dma_v2 {
1089 unsigned int txd1;
1090 unsigned int txd2;
1091 unsigned int txd3;
1092 unsigned int txd4;
developerfd40db22021-04-29 10:08:25 +08001093 unsigned int txd5;
1094 unsigned int txd6;
1095 unsigned int txd7;
1096 unsigned int txd8;
developerfd40db22021-04-29 10:08:25 +08001097} __packed __aligned(4);
1098
1099struct mtk_eth;
1100struct mtk_mac;
developerb6c36bf2023-09-07 12:05:01 +08001101struct mtk_mux;
developerfd40db22021-04-29 10:08:25 +08001102
1103/* struct mtk_hw_stats - the structure that holds the traffic statistics.
1104 * @stats_lock: make sure that stats operations are atomic
1105 * @reg_offset: the status register offset of the SoC
1106 * @syncp: the refcount
1107 *
1108 * All of the supported SoCs have hardware counters for traffic statistics.
1109 * Whenever the status IRQ triggers we can read the latest stats from these
1110 * counters and store them in this struct.
1111 */
1112struct mtk_hw_stats {
1113 u64 tx_bytes;
1114 u64 tx_packets;
1115 u64 tx_skip;
1116 u64 tx_collisions;
1117 u64 rx_bytes;
1118 u64 rx_packets;
1119 u64 rx_overflow;
1120 u64 rx_fcs_errors;
1121 u64 rx_short_errors;
1122 u64 rx_long_errors;
1123 u64 rx_checksum_errors;
1124 u64 rx_flow_control_packets;
1125
1126 spinlock_t stats_lock;
1127 u32 reg_offset;
1128 struct u64_stats_sync syncp;
1129};
1130
1131enum mtk_tx_flags {
1132 /* PDMA descriptor can point at 1-2 segments. This enum allows us to
1133 * track how memory was allocated so that it can be freed properly.
1134 */
1135 MTK_TX_FLAGS_SINGLE0 = 0x01,
1136 MTK_TX_FLAGS_PAGE0 = 0x02,
1137
1138 /* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted
1139 * SKB out instead of looking up through hardware TX descriptor.
1140 */
1141 MTK_TX_FLAGS_FPORT0 = 0x04,
1142 MTK_TX_FLAGS_FPORT1 = 0x08,
developer089e8852022-09-28 14:43:46 +08001143 MTK_TX_FLAGS_FPORT2 = 0x10,
developerfd40db22021-04-29 10:08:25 +08001144};
1145
1146/* This enum allows us to identify how the clock is defined on the array of the
1147 * clock in the order
1148 */
1149enum mtk_clks_map {
1150 MTK_CLK_ETHIF,
1151 MTK_CLK_SGMIITOP,
1152 MTK_CLK_ESW,
1153 MTK_CLK_GP0,
1154 MTK_CLK_GP1,
1155 MTK_CLK_GP2,
developer1bbcf512022-11-18 16:09:33 +08001156 MTK_CLK_GP3,
1157 MTK_CLK_XGP1,
1158 MTK_CLK_XGP2,
1159 MTK_CLK_XGP3,
1160 MTK_CLK_CRYPTO,
developerfd40db22021-04-29 10:08:25 +08001161 MTK_CLK_FE,
1162 MTK_CLK_TRGPLL,
1163 MTK_CLK_SGMII_TX_250M,
1164 MTK_CLK_SGMII_RX_250M,
1165 MTK_CLK_SGMII_CDR_REF,
1166 MTK_CLK_SGMII_CDR_FB,
1167 MTK_CLK_SGMII2_TX_250M,
1168 MTK_CLK_SGMII2_RX_250M,
1169 MTK_CLK_SGMII2_CDR_REF,
1170 MTK_CLK_SGMII2_CDR_FB,
1171 MTK_CLK_SGMII_CK,
1172 MTK_CLK_ETH2PLL,
1173 MTK_CLK_WOCPU0,
1174 MTK_CLK_WOCPU1,
developer5cfc67a2022-12-29 19:06:51 +08001175 MTK_CLK_ETHWARP_WOCPU2,
1176 MTK_CLK_ETHWARP_WOCPU1,
1177 MTK_CLK_ETHWARP_WOCPU0,
1178 MTK_CLK_TOP_USXGMII_SBUS_0_SEL,
1179 MTK_CLK_TOP_USXGMII_SBUS_1_SEL,
1180 MTK_CLK_TOP_SGM_0_SEL,
1181 MTK_CLK_TOP_SGM_1_SEL,
1182 MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL,
1183 MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL,
1184 MTK_CLK_TOP_ETH_GMII_SEL,
1185 MTK_CLK_TOP_ETH_REFCK_50M_SEL,
1186 MTK_CLK_TOP_ETH_SYS_200M_SEL,
1187 MTK_CLK_TOP_ETH_SYS_SEL,
1188 MTK_CLK_TOP_ETH_XGMII_SEL,
1189 MTK_CLK_TOP_ETH_MII_SEL,
1190 MTK_CLK_TOP_NETSYS_SEL,
1191 MTK_CLK_TOP_NETSYS_500M_SEL,
1192 MTK_CLK_TOP_NETSYS_PAO_2X_SEL,
1193 MTK_CLK_TOP_NETSYS_SYNC_250M_SEL,
1194 MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL,
1195 MTK_CLK_TOP_NETSYS_WARP_SEL,
developer0e362982024-01-04 11:04:10 +08001196 MTK_CLK_TOP_MACSEC_SEL,
developerfd40db22021-04-29 10:08:25 +08001197 MTK_CLK_MAX
1198};
1199
1200#define MT7623_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1201 BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
1202 BIT(MTK_CLK_TRGPLL))
1203#define MT7622_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1204 BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
1205 BIT(MTK_CLK_GP2) | \
1206 BIT(MTK_CLK_SGMII_TX_250M) | \
1207 BIT(MTK_CLK_SGMII_RX_250M) | \
1208 BIT(MTK_CLK_SGMII_CDR_REF) | \
1209 BIT(MTK_CLK_SGMII_CDR_FB) | \
1210 BIT(MTK_CLK_SGMII_CK) | \
1211 BIT(MTK_CLK_ETH2PLL))
1212#define MT7621_CLKS_BITMAP (0)
1213#define MT7628_CLKS_BITMAP (0)
1214#define MT7629_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1215 BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
1216 BIT(MTK_CLK_GP2) | BIT(MTK_CLK_FE) | \
1217 BIT(MTK_CLK_SGMII_TX_250M) | \
1218 BIT(MTK_CLK_SGMII_RX_250M) | \
1219 BIT(MTK_CLK_SGMII_CDR_REF) | \
1220 BIT(MTK_CLK_SGMII_CDR_FB) | \
1221 BIT(MTK_CLK_SGMII2_TX_250M) | \
1222 BIT(MTK_CLK_SGMII2_RX_250M) | \
1223 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1224 BIT(MTK_CLK_SGMII2_CDR_FB) | \
1225 BIT(MTK_CLK_SGMII_CK) | \
1226 BIT(MTK_CLK_ETH2PLL) | BIT(MTK_CLK_SGMIITOP))
1227
1228#define MT7986_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
1229 BIT(MTK_CLK_WOCPU1) | BIT(MTK_CLK_WOCPU0) | \
1230 BIT(MTK_CLK_SGMII_TX_250M) | \
1231 BIT(MTK_CLK_SGMII_RX_250M) | \
1232 BIT(MTK_CLK_SGMII_CDR_REF) | \
1233 BIT(MTK_CLK_SGMII_CDR_FB) | \
1234 BIT(MTK_CLK_SGMII2_TX_250M) | \
1235 BIT(MTK_CLK_SGMII2_RX_250M) | \
1236 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1237 BIT(MTK_CLK_SGMII2_CDR_FB))
1238
developer255bba22021-07-27 15:16:33 +08001239
developer9e9fb4c2021-11-30 17:33:04 +08001240#define MT7981_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
1241 BIT(MTK_CLK_WOCPU0) | \
1242 BIT(MTK_CLK_SGMII_TX_250M) | \
1243 BIT(MTK_CLK_SGMII_RX_250M) | \
1244 BIT(MTK_CLK_SGMII_CDR_REF) | \
1245 BIT(MTK_CLK_SGMII_CDR_FB) | \
1246 BIT(MTK_CLK_SGMII2_TX_250M) | \
1247 BIT(MTK_CLK_SGMII2_RX_250M) | \
1248 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1249 BIT(MTK_CLK_SGMII2_CDR_FB))
developer089e8852022-09-28 14:43:46 +08001250
developer1bbcf512022-11-18 16:09:33 +08001251#define MT7988_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_ESW) | \
1252 BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
1253 BIT(MTK_CLK_GP3) | BIT(MTK_CLK_XGP1) | \
1254 BIT(MTK_CLK_XGP2) | BIT(MTK_CLK_XGP3) | \
1255 BIT(MTK_CLK_CRYPTO) | \
developer089e8852022-09-28 14:43:46 +08001256 BIT(MTK_CLK_SGMII_TX_250M) | \
1257 BIT(MTK_CLK_SGMII_RX_250M) | \
developer089e8852022-09-28 14:43:46 +08001258 BIT(MTK_CLK_SGMII2_TX_250M) | \
1259 BIT(MTK_CLK_SGMII2_RX_250M) | \
developer5cfc67a2022-12-29 19:06:51 +08001260 BIT(MTK_CLK_ETHWARP_WOCPU2) | \
1261 BIT(MTK_CLK_ETHWARP_WOCPU1) | \
1262 BIT(MTK_CLK_ETHWARP_WOCPU0) | \
1263 BIT(MTK_CLK_TOP_USXGMII_SBUS_0_SEL) | \
1264 BIT(MTK_CLK_TOP_USXGMII_SBUS_1_SEL) | \
1265 BIT(MTK_CLK_TOP_SGM_0_SEL) | \
1266 BIT(MTK_CLK_TOP_SGM_1_SEL) | \
1267 BIT(MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL) | \
1268 BIT(MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL) | \
1269 BIT(MTK_CLK_TOP_ETH_GMII_SEL) | \
1270 BIT(MTK_CLK_TOP_ETH_REFCK_50M_SEL) | \
1271 BIT(MTK_CLK_TOP_ETH_SYS_200M_SEL) | \
1272 BIT(MTK_CLK_TOP_ETH_SYS_SEL) | \
1273 BIT(MTK_CLK_TOP_ETH_XGMII_SEL) | \
1274 BIT(MTK_CLK_TOP_ETH_MII_SEL) | \
1275 BIT(MTK_CLK_TOP_NETSYS_SEL) | \
1276 BIT(MTK_CLK_TOP_NETSYS_500M_SEL) | \
1277 BIT(MTK_CLK_TOP_NETSYS_PAO_2X_SEL) | \
1278 BIT(MTK_CLK_TOP_NETSYS_SYNC_250M_SEL) | \
1279 BIT(MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL) | \
developer0e362982024-01-04 11:04:10 +08001280 BIT(MTK_CLK_TOP_NETSYS_WARP_SEL) | \
developera4f52192024-02-26 15:31:13 +08001281 BIT(MTK_CLK_TOP_MACSEC_SEL))
developer089e8852022-09-28 14:43:46 +08001282
developerfd40db22021-04-29 10:08:25 +08001283enum mtk_dev_state {
1284 MTK_HW_INIT,
1285 MTK_RESETTING
1286};
1287
developer089e8852022-09-28 14:43:46 +08001288/* PSE Port Definition */
1289enum mtk_pse_port {
1290 PSE_ADMA_PORT = 0,
1291 PSE_GDM1_PORT,
1292 PSE_GDM2_PORT,
1293 PSE_PPE0_PORT,
1294 PSE_PPE1_PORT,
1295 PSE_QDMA_TX_PORT,
1296 PSE_QDMA_RX_PORT,
1297 PSE_DROP_PORT,
1298 PSE_WDMA0_PORT,
1299 PSE_WDMA1_PORT,
1300 PSE_TDMA_PORT,
1301 PSE_NONE_PORT,
1302 PSE_PPE2_PORT,
1303 PSE_WDMA2_PORT,
1304 PSE_EIP197_PORT,
1305 PSE_GDM3_PORT,
1306 PSE_PORT_MAX
1307};
1308
1309/* GMAC Identifier */
1310enum mtk_gmac_id {
1311 MTK_GMAC1_ID = 0,
1312 MTK_GMAC2_ID,
1313 MTK_GMAC3_ID,
1314 MTK_GMAC_ID_MAX
1315};
1316
1317/* GDM Type */
1318enum mtk_gdm_type {
1319 MTK_GDM_TYPE = 0,
1320 MTK_XGDM_TYPE,
1321 MTK_GDM_TYPE_MAX
1322};
1323
developer0fef5222023-04-26 14:48:31 +08001324enum mtk_hw_id {
1325 MTK_HWID_V1 = 0,
1326 MTK_HWID_V2,
1327 MTK_HWID_MAX
1328};
1329
developer30e13e72022-11-03 10:21:24 +08001330static inline const char *gdm_type(int type)
1331{
1332 switch (type) {
1333 case MTK_GDM_TYPE:
1334 return "gdm";
1335 case MTK_XGDM_TYPE:
1336 return "xgdm";
1337 default:
1338 return "unkown";
1339 }
1340}
1341
developerfd40db22021-04-29 10:08:25 +08001342/* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at
1343 * by the TX descriptor s
1344 * @skb: The SKB pointer of the packet being sent
1345 * @dma_addr0: The base addr of the first segment
1346 * @dma_len0: The length of the first segment
1347 * @dma_addr1: The base addr of the second segment
1348 * @dma_len1: The length of the second segment
1349 */
1350struct mtk_tx_buf {
1351 struct sk_buff *skb;
1352 u32 flags;
1353 DEFINE_DMA_UNMAP_ADDR(dma_addr0);
1354 DEFINE_DMA_UNMAP_LEN(dma_len0);
1355 DEFINE_DMA_UNMAP_ADDR(dma_addr1);
1356 DEFINE_DMA_UNMAP_LEN(dma_len1);
1357};
1358
1359/* struct mtk_tx_ring - This struct holds info describing a TX ring
1360 * @dma: The descriptor ring
1361 * @buf: The memory pointed at by the ring
1362 * @phys: The physical addr of tx_buf
1363 * @next_free: Pointer to the next free descriptor
1364 * @last_free: Pointer to the last free descriptor
developerc4671b22021-05-28 13:16:42 +08001365 * @last_free_ptr: Hardware pointer value of the last free descriptor
developerfd40db22021-04-29 10:08:25 +08001366 * @thresh: The threshold of minimum amount of free descriptors
1367 * @free_count: QDMA uses a linked list. Track how many free descriptors
1368 * are present
1369 */
1370struct mtk_tx_ring {
developere9356982022-07-04 09:03:20 +08001371 void *dma;
developerfd40db22021-04-29 10:08:25 +08001372 struct mtk_tx_buf *buf;
1373 dma_addr_t phys;
developere9356982022-07-04 09:03:20 +08001374 void *next_free;
1375 void *last_free;
developerc4671b22021-05-28 13:16:42 +08001376 u32 last_free_ptr;
developerfd40db22021-04-29 10:08:25 +08001377 u16 thresh;
1378 atomic_t free_count;
1379 int dma_size;
developere9356982022-07-04 09:03:20 +08001380 void *dma_pdma; /* For MT7628/88 PDMA handling */
developerfd40db22021-04-29 10:08:25 +08001381 dma_addr_t phys_pdma;
1382 int cpu_idx;
1383};
1384
1385/* PDMA rx ring mode */
1386enum mtk_rx_flags {
1387 MTK_RX_FLAGS_NORMAL = 0,
1388 MTK_RX_FLAGS_HWLRO,
1389 MTK_RX_FLAGS_QDMA,
1390};
1391
1392/* struct mtk_rx_ring - This struct holds info describing a RX ring
1393 * @dma: The descriptor ring
1394 * @data: The memory pointed at by the ring
1395 * @phys: The physical addr of rx_buf
1396 * @frag_size: How big can each fragment be
1397 * @buf_size: The size of each packet buffer
1398 * @calc_idx: The current head of ring
developer77d03a72021-06-06 00:06:00 +08001399 * @ring_no: The index of ring
developerfd40db22021-04-29 10:08:25 +08001400 */
1401struct mtk_rx_ring {
developere9356982022-07-04 09:03:20 +08001402 void *dma;
developerfd40db22021-04-29 10:08:25 +08001403 u8 **data;
1404 dma_addr_t phys;
1405 u16 frag_size;
1406 u16 buf_size;
1407 u16 dma_size;
1408 bool calc_idx_update;
1409 u16 calc_idx;
1410 u32 crx_idx_reg;
developer77d03a72021-06-06 00:06:00 +08001411 u32 ring_no;
developerfd40db22021-04-29 10:08:25 +08001412};
1413
developerea49c302023-06-27 16:06:41 +08001414/* struct mtk_rss_params - This is the structure holding parameters
1415 for the RSS ring
1416 * @hash_key The element is used to record the
1417 secret key for the RSS ring
1418 * indirection_table The element is used to record the
1419 indirection table for the RSS ring
1420 */
1421struct mtk_rss_params {
1422 u32 hash_key[MTK_RSS_HASH_KEYSIZE / sizeof(u32)];
1423 u8 indirection_table[MTK_RSS_MAX_INDIRECTION_TABLE];
1424};
1425
developer18f46a82021-07-20 21:08:21 +08001426/* struct mtk_napi - This is the structure holding NAPI-related information,
1427 * and a mtk_napi struct is binding to one interrupt group
1428 * @napi: The NAPI struct
1429 * @rx_ring: Pointer to the memory holding info about the RX ring
1430 * @irq_grp_idx: The index indicates which interrupt group that this
1431 * mtk_napi is binding to
1432 */
1433struct mtk_napi {
1434 struct napi_struct napi;
1435 struct mtk_eth *eth;
1436 struct mtk_rx_ring *rx_ring;
1437 u32 irq_grp_no;
1438};
1439
developerfd40db22021-04-29 10:08:25 +08001440enum mkt_eth_capabilities {
1441 MTK_RGMII_BIT = 0,
1442 MTK_TRGMII_BIT,
1443 MTK_SGMII_BIT,
developer30e13e72022-11-03 10:21:24 +08001444 MTK_XGMII_BIT,
developer089e8852022-09-28 14:43:46 +08001445 MTK_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001446 MTK_ESW_BIT,
1447 MTK_GEPHY_BIT,
1448 MTK_MUX_BIT,
1449 MTK_INFRA_BIT,
1450 MTK_SHARED_SGMII_BIT,
1451 MTK_HWLRO_BIT,
developer18f46a82021-07-20 21:08:21 +08001452 MTK_RSS_BIT,
developerfd40db22021-04-29 10:08:25 +08001453 MTK_SHARED_INT_BIT,
developer46ed9492023-10-31 15:19:05 +08001454 MTK_PDMA_INT_BIT,
developerfd40db22021-04-29 10:08:25 +08001455 MTK_TRGMII_MT7621_CLK_BIT,
1456 MTK_QDMA_BIT,
developer089e8852022-09-28 14:43:46 +08001457 MTK_NETSYS_V1_BIT,
developera2bdbd52021-05-31 19:10:17 +08001458 MTK_NETSYS_V2_BIT,
developer8ecd51b2023-03-13 11:28:28 +08001459 MTK_NETSYS_RX_V2_BIT,
developer089e8852022-09-28 14:43:46 +08001460 MTK_NETSYS_V3_BIT,
developerfd40db22021-04-29 10:08:25 +08001461 MTK_SOC_MT7628_BIT,
developer545abf02021-07-15 17:47:01 +08001462 MTK_RSTCTRL_PPE1_BIT,
developer37482a42022-12-26 13:31:13 +08001463 MTK_RSTCTRL_PPE2_BIT,
developer255bba22021-07-27 15:16:33 +08001464 MTK_U3_COPHY_V2_BIT,
developer089e8852022-09-28 14:43:46 +08001465 MTK_8GB_ADDRESSING_BIT,
developerfd40db22021-04-29 10:08:25 +08001466
1467 /* MUX BITS*/
1468 MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
1469 MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
1470 MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
developer30e13e72022-11-03 10:21:24 +08001471 MTK_ETH_MUX_GMAC2_TO_XGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001472 MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
1473 MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
developer089e8852022-09-28 14:43:46 +08001474 MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT,
1475 MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001476
1477 /* PATH BITS */
1478 MTK_ETH_PATH_GMAC1_RGMII_BIT,
1479 MTK_ETH_PATH_GMAC1_TRGMII_BIT,
1480 MTK_ETH_PATH_GMAC1_SGMII_BIT,
1481 MTK_ETH_PATH_GMAC2_RGMII_BIT,
1482 MTK_ETH_PATH_GMAC2_SGMII_BIT,
developer30e13e72022-11-03 10:21:24 +08001483 MTK_ETH_PATH_GMAC2_XGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001484 MTK_ETH_PATH_GMAC2_GEPHY_BIT,
developer089e8852022-09-28 14:43:46 +08001485 MTK_ETH_PATH_GMAC3_SGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001486 MTK_ETH_PATH_GDM1_ESW_BIT,
developer089e8852022-09-28 14:43:46 +08001487 MTK_ETH_PATH_GMAC1_USXGMII_BIT,
1488 MTK_ETH_PATH_GMAC2_USXGMII_BIT,
1489 MTK_ETH_PATH_GMAC3_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001490};
1491
1492/* Supported hardware group on SoCs */
developer425b23a2022-10-12 16:00:41 +08001493#define MTK_RGMII BIT_ULL(MTK_RGMII_BIT)
1494#define MTK_TRGMII BIT_ULL(MTK_TRGMII_BIT)
1495#define MTK_SGMII BIT_ULL(MTK_SGMII_BIT)
developer30e13e72022-11-03 10:21:24 +08001496#define MTK_XGMII BIT_ULL(MTK_XGMII_BIT)
developer425b23a2022-10-12 16:00:41 +08001497#define MTK_USXGMII BIT_ULL(MTK_USXGMII_BIT)
1498#define MTK_ESW BIT_ULL(MTK_ESW_BIT)
1499#define MTK_GEPHY BIT_ULL(MTK_GEPHY_BIT)
1500#define MTK_MUX BIT_ULL(MTK_MUX_BIT)
1501#define MTK_INFRA BIT_ULL(MTK_INFRA_BIT)
1502#define MTK_SHARED_SGMII BIT_ULL(MTK_SHARED_SGMII_BIT)
1503#define MTK_HWLRO BIT_ULL(MTK_HWLRO_BIT)
1504#define MTK_RSS BIT_ULL(MTK_RSS_BIT)
1505#define MTK_SHARED_INT BIT_ULL(MTK_SHARED_INT_BIT)
developer46ed9492023-10-31 15:19:05 +08001506#define MTK_PDMA_INT BIT_ULL(MTK_PDMA_INT_BIT)
developer425b23a2022-10-12 16:00:41 +08001507#define MTK_TRGMII_MT7621_CLK BIT_ULL(MTK_TRGMII_MT7621_CLK_BIT)
1508#define MTK_QDMA BIT_ULL(MTK_QDMA_BIT)
1509#define MTK_NETSYS_V1 BIT_ULL(MTK_NETSYS_V1_BIT)
1510#define MTK_NETSYS_V2 BIT_ULL(MTK_NETSYS_V2_BIT)
developer8ecd51b2023-03-13 11:28:28 +08001511#define MTK_NETSYS_RX_V2 BIT(MTK_NETSYS_RX_V2_BIT)
developer425b23a2022-10-12 16:00:41 +08001512#define MTK_NETSYS_V3 BIT_ULL(MTK_NETSYS_V3_BIT)
1513#define MTK_SOC_MT7628 BIT_ULL(MTK_SOC_MT7628_BIT)
1514#define MTK_RSTCTRL_PPE1 BIT_ULL(MTK_RSTCTRL_PPE1_BIT)
developer37482a42022-12-26 13:31:13 +08001515#define MTK_RSTCTRL_PPE2 BIT_ULL(MTK_RSTCTRL_PPE2_BIT)
developer425b23a2022-10-12 16:00:41 +08001516#define MTK_U3_COPHY_V2 BIT_ULL(MTK_U3_COPHY_V2_BIT)
1517#define MTK_8GB_ADDRESSING BIT_ULL(MTK_8GB_ADDRESSING_BIT)
developerfd40db22021-04-29 10:08:25 +08001518
1519#define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \
developer425b23a2022-10-12 16:00:41 +08001520 BIT_ULL(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
developerfd40db22021-04-29 10:08:25 +08001521#define MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY \
developer425b23a2022-10-12 16:00:41 +08001522 BIT_ULL(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
developerfd40db22021-04-29 10:08:25 +08001523#define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \
developer425b23a2022-10-12 16:00:41 +08001524 BIT_ULL(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
developer30e13e72022-11-03 10:21:24 +08001525#define MTK_ETH_MUX_GMAC2_TO_XGMII \
1526 BIT_ULL(MTK_ETH_MUX_GMAC2_TO_XGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001527#define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
developer425b23a2022-10-12 16:00:41 +08001528 BIT_ULL(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001529#define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \
developer425b23a2022-10-12 16:00:41 +08001530 BIT_ULL(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
developer089e8852022-09-28 14:43:46 +08001531#define MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII \
developer425b23a2022-10-12 16:00:41 +08001532 BIT_ULL(MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT)
developer089e8852022-09-28 14:43:46 +08001533#define MTK_ETH_MUX_GMAC123_TO_USXGMII \
developer425b23a2022-10-12 16:00:41 +08001534 BIT_ULL(MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001535
1536/* Supported path present on SoCs */
developer425b23a2022-10-12 16:00:41 +08001537#define MTK_ETH_PATH_GMAC1_RGMII BIT_ULL(MTK_ETH_PATH_GMAC1_RGMII_BIT)
1538#define MTK_ETH_PATH_GMAC1_TRGMII BIT_ULL(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
1539#define MTK_ETH_PATH_GMAC1_SGMII BIT_ULL(MTK_ETH_PATH_GMAC1_SGMII_BIT)
1540#define MTK_ETH_PATH_GMAC2_RGMII BIT_ULL(MTK_ETH_PATH_GMAC2_RGMII_BIT)
1541#define MTK_ETH_PATH_GMAC2_SGMII BIT_ULL(MTK_ETH_PATH_GMAC2_SGMII_BIT)
developer30e13e72022-11-03 10:21:24 +08001542#define MTK_ETH_PATH_GMAC2_XGMII BIT_ULL(MTK_ETH_PATH_GMAC2_XGMII_BIT)
developer425b23a2022-10-12 16:00:41 +08001543#define MTK_ETH_PATH_GMAC2_GEPHY BIT_ULL(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
1544#define MTK_ETH_PATH_GMAC3_SGMII BIT_ULL(MTK_ETH_PATH_GMAC3_SGMII_BIT)
1545#define MTK_ETH_PATH_GDM1_ESW BIT_ULL(MTK_ETH_PATH_GDM1_ESW_BIT)
1546#define MTK_ETH_PATH_GMAC1_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC1_USXGMII_BIT)
1547#define MTK_ETH_PATH_GMAC2_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC2_USXGMII_BIT)
1548#define MTK_ETH_PATH_GMAC3_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC3_USXGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001549
1550#define MTK_GMAC1_RGMII (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
1551#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
1552#define MTK_GMAC1_SGMII (MTK_ETH_PATH_GMAC1_SGMII | MTK_SGMII)
1553#define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
1554#define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
developer30e13e72022-11-03 10:21:24 +08001555#define MTK_GMAC2_XGMII (MTK_ETH_PATH_GMAC2_XGMII | MTK_XGMII)
developerfd40db22021-04-29 10:08:25 +08001556#define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
developer089e8852022-09-28 14:43:46 +08001557#define MTK_GMAC3_SGMII (MTK_ETH_PATH_GMAC3_SGMII | MTK_SGMII)
developerfd40db22021-04-29 10:08:25 +08001558#define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
developer089e8852022-09-28 14:43:46 +08001559#define MTK_GMAC1_USXGMII (MTK_ETH_PATH_GMAC1_USXGMII | MTK_USXGMII)
1560#define MTK_GMAC2_USXGMII (MTK_ETH_PATH_GMAC2_USXGMII | MTK_USXGMII)
1561#define MTK_GMAC3_USXGMII (MTK_ETH_PATH_GMAC3_USXGMII | MTK_USXGMII)
developerfd40db22021-04-29 10:08:25 +08001562
1563/* MUXes present on SoCs */
1564/* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
1565#define MTK_MUX_GDM1_TO_GMAC1_ESW (MTK_ETH_MUX_GDM1_TO_GMAC1_ESW | MTK_MUX)
1566
1567/* 0: GMAC2 -> GEPHY, 1: GMAC0 -> GePHY */
1568#define MTK_MUX_GMAC2_GMAC0_TO_GEPHY \
1569 (MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY | MTK_MUX | MTK_INFRA)
1570
1571/* 0: U3 -> QPHY, 1: GMAC2 -> QPHY */
1572#define MTK_MUX_U3_GMAC2_TO_QPHY \
1573 (MTK_ETH_MUX_U3_GMAC2_TO_QPHY | MTK_MUX | MTK_INFRA)
1574
1575/* 2: GMAC1 -> SGMII, 3: GMAC2 -> SGMII */
1576#define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
1577 (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
1578 MTK_SHARED_SGMII)
1579
developer30e13e72022-11-03 10:21:24 +08001580/* 2: GMAC2 -> XGMII */
1581#define MTK_MUX_GMAC2_TO_XGMII \
1582 (MTK_ETH_MUX_GMAC2_TO_XGMII | MTK_MUX | MTK_INFRA)
1583
developerfd40db22021-04-29 10:08:25 +08001584/* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
1585#define MTK_MUX_GMAC12_TO_GEPHY_SGMII \
1586 (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
1587
developer089e8852022-09-28 14:43:46 +08001588#define MTK_MUX_GMAC123_TO_GEPHY_SGMII \
1589 (MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII | MTK_MUX)
1590
1591#define MTK_MUX_GMAC123_TO_USXGMII \
1592 (MTK_ETH_MUX_GMAC123_TO_USXGMII | MTK_MUX | MTK_INFRA)
1593
developerfd40db22021-04-29 10:08:25 +08001594#define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
1595
1596#define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
1597 MTK_GMAC2_RGMII | MTK_SHARED_INT | \
developer089e8852022-09-28 14:43:46 +08001598 MTK_TRGMII_MT7621_CLK | MTK_QDMA | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001599
1600#define MT7622_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_SGMII | MTK_GMAC2_RGMII | \
1601 MTK_GMAC2_SGMII | MTK_GDM1_ESW | \
developer089e8852022-09-28 14:43:46 +08001602 MTK_MUX_GDM1_TO_GMAC1_ESW | MTK_NETSYS_V1 | \
developerfd40db22021-04-29 10:08:25 +08001603 MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_QDMA)
1604
1605#define MT7623_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | MTK_GMAC2_RGMII | \
developer089e8852022-09-28 14:43:46 +08001606 MTK_QDMA | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001607
developer089e8852022-09-28 14:43:46 +08001608#define MT7628_CAPS (MTK_SHARED_INT | MTK_SOC_MT7628 | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001609
1610#define MT7629_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
1611 MTK_GDM1_ESW | MTK_MUX_GDM1_TO_GMAC1_ESW | \
1612 MTK_MUX_GMAC2_GMAC0_TO_GEPHY | \
developer089e8852022-09-28 14:43:46 +08001613 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_NETSYS_V1 | \
developerfd40db22021-04-29 10:08:25 +08001614 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA)
1615
developer46ed9492023-10-31 15:19:05 +08001616#define MT7986_CAPS (MTK_PDMA_INT | MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \
developerfd40db22021-04-29 10:08:25 +08001617 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
developer46ed9492023-10-31 15:19:05 +08001618 MTK_NETSYS_V2 | MTK_RSS)
developerfd40db22021-04-29 10:08:25 +08001619
developer46ed9492023-10-31 15:19:05 +08001620#define MT7981_CAPS (MTK_PDMA_INT | MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \
1621 MTK_GMAC2_GEPHY | MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
1622 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_U3_COPHY_V2 | \
1623 MTK_NETSYS_V2 | MTK_RSS)
developer255bba22021-07-27 15:16:33 +08001624
developer089e8852022-09-28 14:43:46 +08001625#define MT7988_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC3_SGMII | \
developer46ed9492023-10-31 15:19:05 +08001626 MTK_PDMA_INT | MTK_MUX_GMAC123_TO_GEPHY_SGMII | MTK_QDMA | \
developer37482a42022-12-26 13:31:13 +08001627 MTK_NETSYS_V3 | MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | \
developer089e8852022-09-28 14:43:46 +08001628 MTK_GMAC1_USXGMII | MTK_GMAC2_USXGMII | \
developer30e13e72022-11-03 10:21:24 +08001629 MTK_GMAC3_USXGMII | MTK_MUX_GMAC123_TO_USXGMII | \
developer8ecd51b2023-03-13 11:28:28 +08001630 MTK_GMAC2_XGMII | MTK_MUX_GMAC2_TO_XGMII | MTK_RSS | \
developerd0e67bd2023-06-14 11:34:36 +08001631 MTK_NETSYS_RX_V2 | MTK_8GB_ADDRESSING)
developer089e8852022-09-28 14:43:46 +08001632
developere9356982022-07-04 09:03:20 +08001633struct mtk_tx_dma_desc_info {
1634 dma_addr_t addr;
1635 u32 size;
1636 u16 vlan_tci;
1637 u16 qid;
1638 u8 gso:1;
1639 u8 csum:1;
1640 u8 vlan:1;
1641 u8 first:1;
1642 u8 last:1;
1643};
1644
developer68ce74f2023-01-03 16:11:57 +08001645struct mtk_reg_map {
1646 u32 tx_irq_mask;
1647 u32 tx_irq_status;
1648 struct {
developera7fbeec2024-02-02 13:56:07 +08001649 u32 tx_ptr; /* tx base pointer */
1650 u32 tx_cnt_cfg; /* tx max count configuration */
1651 u32 pctx_ptr; /* tx cpu pointer */
1652 u32 pdtx_ptr; /* tx dma pointer */
developer68ce74f2023-01-03 16:11:57 +08001653 u32 rx_ptr; /* rx base pointer */
1654 u32 rx_cnt_cfg; /* rx max count configuration */
1655 u32 pcrx_ptr; /* rx cpu pointer */
1656 u32 glo_cfg; /* global configuration */
1657 u32 rst_idx; /* reset index */
1658 u32 delay_irq; /* delay interrupt */
1659 u32 irq_status; /* interrupt status */
1660 u32 irq_mask; /* interrupt mask */
1661 u32 int_grp; /* interrupt group1 */
1662 u32 int_grp2; /* interrupt group2 */
1663 } pdma;
1664 struct {
1665 u32 qtx_cfg; /* tx queue configuration */
1666 u32 qtx_sch; /* tx queue scheduler configuration */
1667 u32 rx_ptr; /* rx base pointer */
1668 u32 rx_cnt_cfg; /* rx max count configuration */
1669 u32 qcrx_ptr; /* rx cpu pointer */
1670 u32 glo_cfg; /* global configuration */
1671 u32 rst_idx; /* reset index */
1672 u32 delay_irq; /* delay interrupt */
1673 u32 fc_th; /* flow control */
1674 u32 int_grp; /* interrupt group1 */
1675 u32 int_grp2; /* interrupt group2 */
1676 u32 hred2; /* interrupt mask */
1677 u32 ctx_ptr; /* tx acquire cpu pointer */
1678 u32 dtx_ptr; /* tx acquire dma pointer */
1679 u32 crx_ptr; /* tx release cpu pointer */
1680 u32 drx_ptr; /* tx release dma pointer */
1681 u32 fq_head; /* fq head pointer */
1682 u32 fq_tail; /* fq tail pointer */
1683 u32 fq_count; /* fq free page count */
1684 u32 fq_blen; /* fq free page buffer length */
1685 u32 tx_sch_rate; /* tx scheduler rate control
1686 registers */
1687 } qdma;
1688 u32 gdm1_cnt;
1689 u32 gdma_to_ppe0;
1690 u32 ppe_base[3];
1691 u32 wdma_base[3];
1692};
1693
developerfd40db22021-04-29 10:08:25 +08001694/* struct mtk_eth_data - This is the structure holding all differences
1695 * among various plaforms
developer68ce74f2023-01-03 16:11:57 +08001696 * @reg_map Soc register map.
1697 * @ana_rgc3: The offset for register ANA_RGC3 related to
developerfd40db22021-04-29 10:08:25 +08001698 * sgmiisys syscon
1699 * @caps Flags shown the extra capability for the SoC
1700 * @hw_features Flags shown HW features
1701 * @required_clks Flags shown the bitmap for required clocks on
1702 * the target SoC
1703 * @required_pctl A bool value to show whether the SoC requires
1704 * the extra setup for those pins used by GMAC.
developere9356982022-07-04 09:03:20 +08001705 * @txd_size Tx DMA descriptor size.
1706 * @rxd_size Rx DMA descriptor size.
developer68ce74f2023-01-03 16:11:57 +08001707 * @rx_dma_l4_valid Rx DMA valid register mask.
developere9356982022-07-04 09:03:20 +08001708 * @dma_max_len Max DMA tx/rx buffer length.
1709 * @dma_len_offset Tx/Rx DMA length field offset.
developerfd40db22021-04-29 10:08:25 +08001710 */
1711struct mtk_soc_data {
developer68ce74f2023-01-03 16:11:57 +08001712 const struct mtk_reg_map *reg_map;
1713 u32 ana_rgc3;
developere3d0de22023-05-30 17:45:00 +08001714 u32 rss_num;
developer089e8852022-09-28 14:43:46 +08001715 u64 caps;
developer5cfc67a2022-12-29 19:06:51 +08001716 u64 required_clks;
developerfd40db22021-04-29 10:08:25 +08001717 bool required_pctl;
1718 netdev_features_t hw_features;
1719 bool has_sram;
developere9356982022-07-04 09:03:20 +08001720 struct {
1721 u32 txd_size;
1722 u32 rxd_size;
developer68ce74f2023-01-03 16:11:57 +08001723 u32 rx_dma_l4_valid;
developere9356982022-07-04 09:03:20 +08001724 u32 dma_max_len;
1725 u32 dma_len_offset;
1726 } txrx;
developerfd40db22021-04-29 10:08:25 +08001727};
1728
developer089e8852022-09-28 14:43:46 +08001729/* currently no SoC has more than 3 macs */
1730#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1731#define MTK_MAX_DEVS 3
1732#else
1733#define MTK_MAX_DEVS 2
1734#endif
developerfd40db22021-04-29 10:08:25 +08001735
1736#define MTK_SGMII_PHYSPEED_AN BIT(31)
1737#define MTK_SGMII_PHYSPEED_MASK GENMASK(2, 0)
1738#define MTK_SGMII_PHYSPEED_1000 BIT(0)
1739#define MTK_SGMII_PHYSPEED_2500 BIT(1)
developer089e8852022-09-28 14:43:46 +08001740#define MTK_SGMII_PHYSPEED_5000 BIT(2)
1741#define MTK_SGMII_PHYSPEED_10000 BIT(3)
developerf8ac94a2021-07-29 16:40:01 +08001742#define MTK_SGMII_PN_SWAP BIT(16)
developerfd40db22021-04-29 10:08:25 +08001743#define MTK_HAS_FLAGS(flags, _x) (((flags) & (_x)) == (_x))
1744
developer4e8a3fd2023-04-10 18:05:44 +08001745/* struct mtk_sgmii_pcs - This structure holds each sgmii regmap and associated
1746 * data
1747 * @regmap: The register map pointing at the range used to setup
1748 * SGMII modes
1749 * @regmap_pextp: The register map pointing at the range used to setup
1750 * PHYA
1751 * @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap
1752 * @id: The element is used to record the index of PCS
1753 * @pcs: Phylink PCS structure
developerfd40db22021-04-29 10:08:25 +08001754 */
developer4e8a3fd2023-04-10 18:05:44 +08001755struct mtk_sgmii_pcs {
1756 struct mtk_eth *eth;
1757 struct regmap *regmap;
1758 struct regmap *regmap_pextp;
developer86526452023-12-26 12:12:52 +08001759 spinlock_t regmap_lock;
developer4e8a3fd2023-04-10 18:05:44 +08001760 phy_interface_t interface;
developer86526452023-12-26 12:12:52 +08001761 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
developer4e8a3fd2023-04-10 18:05:44 +08001762 u32 flags;
1763 u32 ana_rgc3;
1764 u8 id;
1765 struct phylink_pcs pcs;
1766};
developerfd40db22021-04-29 10:08:25 +08001767
developer4e8a3fd2023-04-10 18:05:44 +08001768/* struct mtk_sgmii - This is the structure holding sgmii regmap and its
1769 * characteristics
1770 * @pll: The register map pointing at the range used to setup
1771 * PLL
1772 * @pcs Array of individual PCS structures
1773 */
1774struct mtk_sgmii {
1775 struct mtk_sgmii_pcs pcs[MTK_MAX_DEVS];
1776 struct regmap *pll;
developerfd40db22021-04-29 10:08:25 +08001777};
1778
developer4e8a3fd2023-04-10 18:05:44 +08001779/* struct mtk_usxgmii_pcs - This structure holds each usxgmii regmap and
1780 * associated data
1781 * @regmap: The register map pointing at the range used to setup
1782 * USXGMII modes
1783 * @regmap_pextp: The register map pointing at the range used to setup
1784 * PHYA
1785 * @id: The element is used to record the index of PCS
1786 * @pcs: Phylink PCS structure
1787 */
1788struct mtk_usxgmii_pcs {
1789 struct mtk_eth *eth;
1790 struct regmap *regmap;
1791 struct regmap *regmap_pextp;
developerd9d75ef2023-12-13 09:34:47 +08001792 spinlock_t regmap_lock;
developer4e8a3fd2023-04-10 18:05:44 +08001793 phy_interface_t interface;
developer21260d02023-09-04 11:29:04 +08001794 unsigned int mode;
developer4e8a3fd2023-04-10 18:05:44 +08001795 u8 id;
1796 struct phylink_pcs pcs;
1797};
1798
1799/* struct mtk_usxgmii - This is the structure holding usxgmii regmap and its
1800 * characteristics
1801 * @pll: The register map pointing at the range used to setup
1802 * PLL
1803 * @pcs Array of individual PCS structures
1804 */
1805struct mtk_usxgmii {
1806 struct mtk_usxgmii_pcs pcs[MTK_MAX_DEVS];
1807 struct regmap *pll;
1808};
developer8051e042022-04-08 13:26:36 +08001809
1810/* struct mtk_reset_event - This is the structure holding statistics counters
1811 * for reset events
1812 * @count: The counter is used to record the number of events
1813 */
1814struct mtk_reset_event {
1815 u32 count[32];
1816};
1817
developera2613e62022-07-01 18:29:37 +08001818/* struct mtk_phylink_priv - This is the structure holding private data for phylink
1819 * @desc: Pointer to the memory holding info about the phylink gpio
1820 * @id: The element is used to record the phy index of phylink
1821 * @phyaddr: The element is used to record the phy address of phylink
1822 * @link: The element is used to record the phy link status of phylink
1823 */
1824struct mtk_phylink_priv {
1825 struct net_device *dev;
1826 struct gpio_desc *desc;
1827 char label[16];
1828 int id;
1829 int phyaddr;
1830 int link;
1831};
1832
developerfd40db22021-04-29 10:08:25 +08001833/* struct mtk_eth - This is the main datasructure for holding the state
1834 * of the driver
1835 * @dev: The device pointer
developer3f28d382023-03-07 16:06:30 +08001836 * @dma_dev: The device pointer used for dma mapping/alloc
developerfd40db22021-04-29 10:08:25 +08001837 * @base: The mapped register i/o base
1838 * @page_lock: Make sure that register operations are atomic
1839 * @tx_irq__lock: Make sure that IRQ register operations are atomic
1840 * @rx_irq__lock: Make sure that IRQ register operations are atomic
1841 * @dummy_dev: we run 2 netdevs on 1 physical DMA ring and need a
1842 * dummy for NAPI to work
1843 * @netdev: The netdev instances
1844 * @mac: Each netdev is linked to a physical MAC
1845 * @irq: The IRQ that we are using
1846 * @msg_enable: Ethtool msg level
1847 * @ethsys: The register map pointing at the range used to setup
1848 * MII modes
1849 * @infra: The register map pointing at the range used to setup
1850 * SGMII and GePHY path
1851 * @pctl: The register map pointing at the range used to setup
1852 * GMAC port drive/slew values
1853 * @dma_refcnt: track how many netdevs are using the DMA engine
1854 * @tx_ring: Pointer to the memory holding info about the TX ring
1855 * @rx_ring: Pointer to the memory holding info about the RX ring
1856 * @rx_ring_qdma: Pointer to the memory holding info about the QDMA RX ring
1857 * @tx_napi: The TX NAPI struct
1858 * @rx_napi: The RX NAPI struct
1859 * @scratch_ring: Newer SoCs need memory for a second HW managed TX ring
1860 * @phy_scratch_ring: physical address of scratch_ring
1861 * @scratch_head: The scratch memory that scratch_ring points to.
1862 * @clks: clock array for all clocks required
1863 * @mii_bus: If there is a bus we need to create an instance for it
1864 * @pending_work: The workqueue used to reset the dma ring
1865 * @state: Initialization and runtime state of the device
1866 * @soc: Holding specific data among vaious SoCs
1867 */
1868
1869struct mtk_eth {
1870 struct device *dev;
developer3f28d382023-03-07 16:06:30 +08001871 struct device *dma_dev;
developerfd40db22021-04-29 10:08:25 +08001872 void __iomem *base;
developer089e8852022-09-28 14:43:46 +08001873 void __iomem *sram_base;
developerfd40db22021-04-29 10:08:25 +08001874 spinlock_t page_lock;
1875 spinlock_t tx_irq_lock;
1876 spinlock_t rx_irq_lock;
developera7fbeec2024-02-02 13:56:07 +08001877 spinlock_t txrx_irq_lock;
developerfd40db22021-04-29 10:08:25 +08001878 struct net_device dummy_dev;
1879 struct net_device *netdev[MTK_MAX_DEVS];
1880 struct mtk_mac *mac[MTK_MAX_DEVS];
developerb6c36bf2023-09-07 12:05:01 +08001881 struct mtk_mux *mux[MTK_MAX_DEVS];
developer94806ec2023-05-19 14:16:44 +08001882 int irq_fe[MTK_FE_IRQ_NUM];
1883 int irq_pdma[MTK_PDMA_IRQ_NUM];
developer0fef5222023-04-26 14:48:31 +08001884 u8 hwver;
developerfd40db22021-04-29 10:08:25 +08001885 u32 msg_enable;
developer90270572024-01-30 09:26:15 +08001886 u32 pppq_toggle;
developerfd40db22021-04-29 10:08:25 +08001887 unsigned long sysclk;
1888 struct regmap *ethsys;
1889 struct regmap *infra;
developer089e8852022-09-28 14:43:46 +08001890 struct regmap *toprgu;
developer4e8a3fd2023-04-10 18:05:44 +08001891 struct mtk_sgmii *sgmii;
1892 struct mtk_usxgmii *usxgmii;
developerfd40db22021-04-29 10:08:25 +08001893 struct regmap *pctl;
1894 bool hwlro;
1895 refcount_t dma_refcnt;
1896 struct mtk_tx_ring tx_ring;
1897 struct mtk_rx_ring rx_ring[MTK_MAX_RX_RING_NUM];
1898 struct mtk_rx_ring rx_ring_qdma;
1899 struct napi_struct tx_napi;
developer18f46a82021-07-20 21:08:21 +08001900 struct mtk_napi rx_napi[MTK_RX_NAPI_NUM];
developerea49c302023-06-27 16:06:41 +08001901 struct mtk_rss_params rss_params;
developere9356982022-07-04 09:03:20 +08001902 void *scratch_ring;
developer8051e042022-04-08 13:26:36 +08001903 struct mtk_reset_event reset_event;
developerfd40db22021-04-29 10:08:25 +08001904 dma_addr_t phy_scratch_ring;
1905 void *scratch_head;
1906 struct clk *clks[MTK_CLK_MAX];
1907
1908 struct mii_bus *mii_bus;
1909 struct work_struct pending_work;
1910 unsigned long state;
1911
1912 const struct mtk_soc_data *soc;
1913
developerfd40db22021-04-29 10:08:25 +08001914 u32 rx_dma_l4_valid;
1915 int ip_align;
developerd82e8372022-02-09 15:00:09 +08001916 spinlock_t syscfg0_lock;
developer8051e042022-04-08 13:26:36 +08001917 struct timer_list mtk_dma_monitor_timer;
developerfd40db22021-04-29 10:08:25 +08001918};
1919
1920/* struct mtk_mac - the structure that holds the info about the MACs of the
1921 * SoC
1922 * @id: The number of the MAC
1923 * @interface: Interface mode kept for detecting change in hw settings
1924 * @of_node: Our devicetree node
1925 * @hw: Backpointer to our main datastruture
1926 * @hw_stats: Packet statistics counter
1927 */
1928struct mtk_mac {
developerfb556ca2021-10-13 10:52:09 +08001929 unsigned int id;
developerfd40db22021-04-29 10:08:25 +08001930 phy_interface_t interface;
1931 unsigned int mode;
developer089e8852022-09-28 14:43:46 +08001932 unsigned int type;
developerfd40db22021-04-29 10:08:25 +08001933 int speed;
1934 struct device_node *of_node;
1935 struct phylink *phylink;
1936 struct phylink_config phylink_config;
developera2613e62022-07-01 18:29:37 +08001937 struct mtk_phylink_priv phylink_priv;
developerfd40db22021-04-29 10:08:25 +08001938 struct mtk_eth *hw;
1939 struct mtk_hw_stats *hw_stats;
1940 __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT];
1941 int hwlro_ip_cnt;
developer4e8a3fd2023-04-10 18:05:44 +08001942 unsigned int syscfg0;
developer9b725932022-11-24 16:25:56 +08001943 bool tx_lpi_enabled;
1944 u32 tx_lpi_timer;
developer90270572024-01-30 09:26:15 +08001945 struct notifier_block device_notifier;
developerfd40db22021-04-29 10:08:25 +08001946};
1947
developerb6c36bf2023-09-07 12:05:01 +08001948/* struct mtk_mux_data - the structure that holds the private data about the
1949 * Passive MUXs of the SoC
1950 */
1951struct mtk_mux_data {
1952 struct device_node *of_node;
1953 struct phylink *phylink;
1954};
1955
1956/* struct mtk_mux - the structure that holds the info about the Passive MUXs of the
1957 * SoC
1958 */
1959struct mtk_mux {
1960 struct delayed_work poll;
1961 struct gpio_desc *gpio[2];
1962 struct mtk_mux_data *data[2];
1963 struct mtk_mac *mac;
1964 unsigned int channel;
1965};
1966
developerfd40db22021-04-29 10:08:25 +08001967/* the struct describing the SoC. these are declared in the soc_xyz.c files */
developer7cd7e5e2022-11-17 13:57:32 +08001968extern struct mtk_eth *g_eth;
developerfd40db22021-04-29 10:08:25 +08001969extern const struct of_device_id of_mtk_match[];
developer77d03a72021-06-06 00:06:00 +08001970extern u32 mtk_hwlro_stats_ebl;
developer7979ddb2023-04-24 17:19:21 +08001971extern u32 dbg_show_level;
developerfd40db22021-04-29 10:08:25 +08001972
1973/* read the hardware status register */
1974void mtk_stats_update_mac(struct mtk_mac *mac);
1975
1976void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
1977u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
developer8051e042022-04-08 13:26:36 +08001978u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned reg);
developerfd40db22021-04-29 10:08:25 +08001979
developer4e8a3fd2023-04-10 18:05:44 +08001980struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id);
1981int mtk_sgmii_init(struct mtk_eth *eth, struct device_node *np,
developerfd40db22021-04-29 10:08:25 +08001982 u32 ana_rgc3);
developerfd40db22021-04-29 10:08:25 +08001983
1984int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
developer30e13e72022-11-03 10:21:24 +08001985int mtk_gmac_xgmii_path_setup(struct mtk_eth *eth, int mac_id);
developerfd40db22021-04-29 10:08:25 +08001986int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
1987int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
developer089e8852022-09-28 14:43:46 +08001988int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id);
developerdca0fde2022-12-14 11:40:35 +08001989void mtk_gdm_config(struct mtk_eth *eth, u32 id, u32 config);
developer8051e042022-04-08 13:26:36 +08001990void ethsys_reset(struct mtk_eth *eth, u32 reset_bits);
developerfd40db22021-04-29 10:08:25 +08001991
developer089e8852022-09-28 14:43:46 +08001992int mtk_mac2xgmii_id(struct mtk_eth *eth, int mac_id);
developer4e8a3fd2023-04-10 18:05:44 +08001993struct phylink_pcs *mtk_usxgmii_select_pcs(struct mtk_usxgmii *ss, int id);
1994int mtk_usxgmii_init(struct mtk_eth *eth, struct device_node *r);
developer089e8852022-09-28 14:43:46 +08001995int mtk_toprgu_init(struct mtk_eth *eth, struct device_node *r);
developer0baa6962023-01-31 14:25:23 +08001996int mtk_dump_usxgmii(struct regmap *pmap, char *name, u32 offset, u32 range);
developer21260d02023-09-04 11:29:04 +08001997void mtk_usxgmii_link_poll(struct work_struct *work);
developer3f28d382023-03-07 16:06:30 +08001998
1999void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
developerea49c302023-06-27 16:06:41 +08002000u32 mtk_rss_indr_table(struct mtk_rss_params *rss_params, int index);
developerfd40db22021-04-29 10:08:25 +08002001#endif /* MTK_ETH_H */