blob: f87635c29bcd277a4f7d0ea74a34bb3a1920e937 [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
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)
developer94806ec2023-05-19 14:16:44 +080095#define MTK_FE_IRQ_NUM (4)
96#define MTK_PDMA_IRQ_NUM (4)
97#define MTK_MAX_IRQ_NUM (MTK_FE_IRQ_NUM + MTK_PDMA_IRQ_NUM)
developerfd40db22021-04-29 10:08:25 +080098
99/* PDMA HW LRO Alter Flow Timer Register */
100#define MTK_PDMA_LRO_ALT_REFRESH_TIMER 0x1c
101
102/* Frame Engine Interrupt Grouping Register */
103#define MTK_FE_INT_GRP 0x20
104
developer77d03a72021-06-06 00:06:00 +0800105/* Frame Engine LRO auto-learn table info */
106#define MTK_FE_ALT_CF8 0x300
107#define MTK_FE_ALT_SGL_CFC 0x304
108#define MTK_FE_ALT_SEQ_CFC 0x308
109
developerfd40db22021-04-29 10:08:25 +0800110/* CDMP Ingress Control Register */
111#define MTK_CDMQ_IG_CTRL 0x1400
112#define MTK_CDMQ_STAG_EN BIT(0)
113
114/* CDMP Ingress Control Register */
115#define MTK_CDMP_IG_CTRL 0x400
116#define MTK_CDMP_STAG_EN BIT(0)
117
118/* CDMP Exgress Control Register */
119#define MTK_CDMP_EG_CTRL 0x404
120
developer089e8852022-09-28 14:43:46 +0800121/* GDM Ingress Control Register */
122#define MTK_GDMA_FWD_CFG(x) ((x == MTK_GMAC3_ID) ? \
123 0x540 : 0x500 + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800124#define MTK_GDMA_SPECIAL_TAG BIT(24)
125#define MTK_GDMA_ICS_EN BIT(22)
126#define MTK_GDMA_TCS_EN BIT(21)
127#define MTK_GDMA_UCS_EN BIT(20)
developer089e8852022-09-28 14:43:46 +0800128#define MTK_GDMA_STRP_CRC BIT(16)
developerfd40db22021-04-29 10:08:25 +0800129#define MTK_GDMA_TO_PDMA 0x0
130#define MTK_GDMA_DROP_ALL 0x7777
131
developer089e8852022-09-28 14:43:46 +0800132/* GDM Egress Control Register */
133#define MTK_GDMA_EG_CTRL(x) ((x == MTK_GMAC3_ID) ? \
134 0x544 : 0x504 + (x * 0x1000))
135#define MTK_GDMA_XGDM_SEL BIT(31)
136
developerfd40db22021-04-29 10:08:25 +0800137/* Unicast Filter MAC Address Register - Low */
developer089e8852022-09-28 14:43:46 +0800138#define MTK_GDMA_MAC_ADRL(x) ((x == MTK_GMAC3_ID) ? \
139 0x548 : 0x508 + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800140
141/* Unicast Filter MAC Address Register - High */
developer089e8852022-09-28 14:43:46 +0800142#define MTK_GDMA_MAC_ADRH(x) ((x == MTK_GMAC3_ID) ? \
143 0x54C : 0x50C + (x * 0x1000))
developerfd40db22021-04-29 10:08:25 +0800144
145/* Internal SRAM offset */
developer089e8852022-09-28 14:43:46 +0800146#if defined(CONFIG_MEDIATEK_NETSYS_V3)
147#define MTK_ETH_SRAM_OFFSET 0x300000
148#else
developerfd40db22021-04-29 10:08:25 +0800149#define MTK_ETH_SRAM_OFFSET 0x40000
developer089e8852022-09-28 14:43:46 +0800150#endif
developerfd40db22021-04-29 10:08:25 +0800151
152/* FE global misc reg*/
153#define MTK_FE_GLO_MISC 0x124
154
developerfef9efd2021-06-16 18:28:09 +0800155/* PSE Free Queue Flow Control */
156#define PSE_FQFC_CFG1 0x100
157#define PSE_FQFC_CFG2 0x104
developer459b78e2022-07-01 17:25:10 +0800158#define PSE_NO_DROP_CFG 0x108
159#define PSE_PPE0_DROP 0x110
developerfef9efd2021-06-16 18:28:09 +0800160
developer15f760a2022-10-12 15:57:21 +0800161/* PSE Last FreeQ Page Request Control */
162#define PSE_DUMY_REQ 0x10C
163#define PSE_DUMMY_WORK_GDM(x) BIT(16 + (x))
164#define DUMMY_PAGE_THR 0x151
165
developerfd40db22021-04-29 10:08:25 +0800166/* PSE Input Queue Reservation Register*/
167#define PSE_IQ_REV(x) (0x140 + ((x - 1) * 0x4))
168
169/* PSE Output Queue Threshold Register*/
170#define PSE_OQ_TH(x) (0x160 + ((x - 1) * 0x4))
171
developerfef9efd2021-06-16 18:28:09 +0800172/* GDM and CDM Threshold */
173#define MTK_GDM2_THRES 0x1530
174#define MTK_CDMW0_THRES 0x164c
175#define MTK_CDMW1_THRES 0x1650
176#define MTK_CDME0_THRES 0x1654
177#define MTK_CDME1_THRES 0x1658
178#define MTK_CDMM_THRES 0x165c
179
developerfd40db22021-04-29 10:08:25 +0800180#define MTK_PDMA_V2 BIT(4)
developerfd40db22021-04-29 10:08:25 +0800181
developer089e8852022-09-28 14:43:46 +0800182#if defined(CONFIG_MEDIATEK_NETSYS_V3)
183#define PDMA_BASE 0x6800
184#define QDMA_BASE 0x4400
185#define WDMA_BASE(x) (0x4800 + ((x) * 0x400))
developer2a050ba2022-12-01 16:11:06 +0800186#define PPE_BASE(x) ((x == 2) ? 0x2E00 : 0x2200 + ((x) * 0x400))
developer089e8852022-09-28 14:43:46 +0800187#elif defined(CONFIG_MEDIATEK_NETSYS_V2)
developer8ecd51b2023-03-13 11:28:28 +0800188#ifdef CONFIG_MEDIATEK_NETSYS_RX_V2
developerfd40db22021-04-29 10:08:25 +0800189#define PDMA_BASE 0x6000
developer8ecd51b2023-03-13 11:28:28 +0800190#else
191#define PDMA_BASE 0x4000
192#endif
developerfd40db22021-04-29 10:08:25 +0800193#define QDMA_BASE 0x4400
developer8051e042022-04-08 13:26:36 +0800194#define WDMA_BASE(x) (0x4800 + ((x) * 0x400))
195#define PPE_BASE(x) (0x2200 + ((x) * 0x400))
developerfd40db22021-04-29 10:08:25 +0800196#else
197#define PDMA_BASE 0x0800
198#define QDMA_BASE 0x1800
developer8051e042022-04-08 13:26:36 +0800199#define WDMA_BASE(x) (0x2800 + ((x) * 0x400))
200#define PPE_BASE(x) (0xE00 + ((x) * 0x400))
developerfd40db22021-04-29 10:08:25 +0800201#endif
202/* PDMA RX Base Pointer Register */
203#define MTK_PRX_BASE_PTR0 (PDMA_BASE + 0x100)
204#define MTK_PRX_BASE_PTR_CFG(x) (MTK_PRX_BASE_PTR0 + (x * 0x10))
205
206/* PDMA RX Maximum Count Register */
207#define MTK_PRX_MAX_CNT0 (MTK_PRX_BASE_PTR0 + 0x04)
208#define MTK_PRX_MAX_CNT_CFG(x) (MTK_PRX_MAX_CNT0 + (x * 0x10))
209
210/* PDMA RX CPU Pointer Register */
211#define MTK_PRX_CRX_IDX0 (MTK_PRX_BASE_PTR0 + 0x08)
212#define MTK_PRX_CRX_IDX_CFG(x) (MTK_PRX_CRX_IDX0 + (x * 0x10))
213
developer77f3fd42021-10-05 15:16:05 +0800214/* PDMA RX DMA Pointer Register */
215#define MTK_PRX_DRX_IDX0 (MTK_PRX_BASE_PTR0 + 0x0c)
216#define MTK_PRX_DRX_IDX_CFG(x) (MTK_PRX_DRX_IDX0 + (x * 0x10))
217
developerfd40db22021-04-29 10:08:25 +0800218/* PDMA HW LRO Control Registers */
developer77d03a72021-06-06 00:06:00 +0800219#define BITS(m, n) (~(BIT(m) - 1) & ((BIT(n) - 1) | BIT(n)))
developer8ecd51b2023-03-13 11:28:28 +0800220#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer77d03a72021-06-06 00:06:00 +0800221#define MTK_MAX_RX_RING_NUM (8)
222#define MTK_HW_LRO_RING_NUM (4)
223#define IS_HW_LRO_RING(ring_no) (((ring_no) > 3) && ((ring_no) < 8))
224#define MTK_PDMA_LRO_CTRL_DW0 (PDMA_BASE + 0x408)
225#define MTK_LRO_ALT_SCORE_DELTA (PDMA_BASE + 0x41c)
226#define MTK_LRO_RX_RING0_CTRL_DW1 (PDMA_BASE + 0x438)
227#define MTK_LRO_RX_RING0_CTRL_DW2 (PDMA_BASE + 0x43c)
228#define MTK_LRO_RX_RING0_CTRL_DW3 (PDMA_BASE + 0x440)
229#define MTK_L3_CKS_UPD_EN BIT(19)
230#define MTK_LRO_CRSN_BNW BIT(22)
231#define MTK_LRO_RING_RELINGUISH_REQ (0xf << 24)
232#define MTK_LRO_RING_RELINGUISH_DONE (0xf << 28)
233#else
234#define MTK_MAX_RX_RING_NUM (4)
235#define MTK_HW_LRO_RING_NUM (3)
236#define IS_HW_LRO_RING(ring_no) (((ring_no) > 0) && ((ring_no) < 4))
237#define MTK_PDMA_LRO_CTRL_DW0 (PDMA_BASE + 0x180)
238#define MTK_LRO_ALT_SCORE_DELTA (PDMA_BASE + 0x24c)
239#define MTK_LRO_RX_RING0_CTRL_DW1 (PDMA_BASE + 0x328)
240#define MTK_LRO_RX_RING0_CTRL_DW2 (PDMA_BASE + 0x32c)
241#define MTK_LRO_RX_RING0_CTRL_DW3 (PDMA_BASE + 0x330)
242#define MTK_LRO_CRSN_BNW BIT(6)
developerfd40db22021-04-29 10:08:25 +0800243#define MTK_L3_CKS_UPD_EN BIT(7)
developer77d03a72021-06-06 00:06:00 +0800244#define MTK_LRO_RING_RELINGUISH_REQ (0x7 << 26)
245#define MTK_LRO_RING_RELINGUISH_DONE (0x7 << 29)
246#endif
247
248#define IS_NORMAL_RING(ring_no) ((ring_no) == 0)
249#define MTK_LRO_EN BIT(0)
developer18f46a82021-07-20 21:08:21 +0800250#define MTK_NON_LRO_MULTI_EN BIT(2)
251#define MTK_LRO_DLY_INT_EN BIT(5)
developerfd40db22021-04-29 10:08:25 +0800252#define MTK_LRO_ALT_PKT_CNT_MODE BIT(21)
developer77d03a72021-06-06 00:06:00 +0800253#define MTK_LRO_L4_CTRL_PSH_EN BIT(23)
254#define MTK_CTRL_DW0_SDL_OFFSET (3)
255#define MTK_CTRL_DW0_SDL_MASK BITS(3, 18)
developerfd40db22021-04-29 10:08:25 +0800256
257#define MTK_PDMA_LRO_CTRL_DW1 (MTK_PDMA_LRO_CTRL_DW0 + 0x04)
258#define MTK_PDMA_LRO_CTRL_DW2 (MTK_PDMA_LRO_CTRL_DW0 + 0x08)
259#define MTK_PDMA_LRO_CTRL_DW3 (MTK_PDMA_LRO_CTRL_DW0 + 0x0c)
260#define MTK_ADMA_MODE BIT(15)
261#define MTK_LRO_MIN_RXD_SDL (MTK_HW_LRO_SDL_REMAIN_ROOM << 16)
262
developer18f46a82021-07-20 21:08:21 +0800263/* PDMA RSS Control Registers */
developer8ecd51b2023-03-13 11:28:28 +0800264#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer18f46a82021-07-20 21:08:21 +0800265#define MTK_PDMA_RSS_GLO_CFG (PDMA_BASE + 0x800)
developer94806ec2023-05-19 14:16:44 +0800266#define MTK_RX_NAPI_NUM (4)
developer18f46a82021-07-20 21:08:21 +0800267#else
developer8ecd51b2023-03-13 11:28:28 +0800268#define MTK_PDMA_RSS_GLO_CFG 0x2800
developeredb02af2023-03-31 13:31:28 +0800269#define MTK_RX_NAPI_NUM (1)
developer18f46a82021-07-20 21:08:21 +0800270#endif
developer94806ec2023-05-19 14:16:44 +0800271#define MTK_RSS_RING(x) (x)
developer18f46a82021-07-20 21:08:21 +0800272#define MTK_RSS_EN BIT(0)
273#define MTK_RSS_CFG_REQ BIT(2)
274#define MTK_RSS_IPV6_STATIC_HASH (0x7 << 8)
275#define MTK_RSS_IPV4_STATIC_HASH (0x7 << 12)
developerea49c302023-06-27 16:06:41 +0800276#define MTK_RSS_HASH_KEY_DW(x) (MTK_PDMA_RSS_GLO_CFG + 0x20 + \
277 ((x) * 0x4))
developere3d0de22023-05-30 17:45:00 +0800278#define MTK_RSS_INDR_TABLE_DW(x) (MTK_PDMA_RSS_GLO_CFG + 0x50 + \
279 ((x) * 0x4))
developer18f46a82021-07-20 21:08:21 +0800280
developerfd40db22021-04-29 10:08:25 +0800281/* PDMA Global Configuration Register */
282#define MTK_PDMA_GLO_CFG (PDMA_BASE + 0x204)
developer77d03a72021-06-06 00:06:00 +0800283#define MTK_RX_DMA_LRO_EN BIT(8)
developerfd40db22021-04-29 10:08:25 +0800284#define MTK_MULTI_EN BIT(10)
285#define MTK_PDMA_SIZE_8DWORDS (1 << 4)
286
developer77d03a72021-06-06 00:06:00 +0800287/* PDMA Global Configuration Register */
288#define MTK_PDMA_RX_CFG (PDMA_BASE + 0x210)
289#define MTK_PDMA_LRO_SDL (0x3000)
290#define MTK_RX_CFG_SDL_OFFSET (16)
291
developerfd40db22021-04-29 10:08:25 +0800292/* PDMA Reset Index Register */
293#define MTK_PDMA_RST_IDX (PDMA_BASE + 0x208)
294#define MTK_PST_DRX_IDX0 BIT(16)
295#define MTK_PST_DRX_IDX_CFG(x) (MTK_PST_DRX_IDX0 << (x))
296
developerd2fb0622023-07-20 17:11:42 +0800297/*PDMA HW RX Index Register*/
298#define MTK_ADMA_DRX_PTR (PDMA_BASE + 0x10C)
299
developerfd40db22021-04-29 10:08:25 +0800300/* PDMA Delay Interrupt Register */
301#define MTK_PDMA_DELAY_INT (PDMA_BASE + 0x20c)
developer8ecd51b2023-03-13 11:28:28 +0800302#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer089e8852022-09-28 14:43:46 +0800303#define MTK_PDMA_RSS_DELAY_INT (PDMA_BASE + 0x2c0)
developer8ecd51b2023-03-13 11:28:28 +0800304#else
305#define MTK_PDMA_RSS_DELAY_INT (PDMA_BASE + 0x270)
306#endif
developerfd40db22021-04-29 10:08:25 +0800307#define MTK_PDMA_DELAY_RX_EN BIT(15)
308#define MTK_PDMA_DELAY_RX_PINT 4
309#define MTK_PDMA_DELAY_RX_PINT_SHIFT 8
310#define MTK_PDMA_DELAY_RX_PTIME 4
311#define MTK_PDMA_DELAY_RX_DELAY \
312 (MTK_PDMA_DELAY_RX_EN | MTK_PDMA_DELAY_RX_PTIME | \
313 (MTK_PDMA_DELAY_RX_PINT << MTK_PDMA_DELAY_RX_PINT_SHIFT))
314
315/* PDMA Interrupt Status Register */
316#define MTK_PDMA_INT_STATUS (PDMA_BASE + 0x220)
317
318/* PDMA Interrupt Mask Register */
319#define MTK_PDMA_INT_MASK (PDMA_BASE + 0x228)
320
developerfd40db22021-04-29 10:08:25 +0800321/* PDMA Interrupt grouping registers */
322#define MTK_PDMA_INT_GRP1 (PDMA_BASE + 0x250)
323#define MTK_PDMA_INT_GRP2 (PDMA_BASE + 0x254)
developer8ecd51b2023-03-13 11:28:28 +0800324#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer18f46a82021-07-20 21:08:21 +0800325#define MTK_PDMA_INT_GRP3 (PDMA_BASE + 0x258)
326#else
327#define MTK_PDMA_INT_GRP3 (PDMA_BASE + 0x22c)
328#endif
329#define MTK_LRO_RX1_DLY_INT 0xa70
330#define MTK_MAX_DELAY_INT 0x8f0f8f0f
developerfd40db22021-04-29 10:08:25 +0800331
332/* PDMA HW LRO IP Setting Registers */
developer8ecd51b2023-03-13 11:28:28 +0800333#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer77d03a72021-06-06 00:06:00 +0800334#define MTK_LRO_RX_RING0_DIP_DW0 (PDMA_BASE + 0x414)
335#else
developerfd40db22021-04-29 10:08:25 +0800336#define MTK_LRO_RX_RING0_DIP_DW0 (PDMA_BASE + 0x304)
developer77d03a72021-06-06 00:06:00 +0800337#endif
developerfd40db22021-04-29 10:08:25 +0800338#define MTK_LRO_DIP_DW0_CFG(x) (MTK_LRO_RX_RING0_DIP_DW0 + (x * 0x40))
339#define MTK_RING_MYIP_VLD BIT(9)
340
developer77d03a72021-06-06 00:06:00 +0800341/* PDMA HW LRO ALT Debug Registers */
342#define MTK_LRO_ALT_DBG (PDMA_BASE + 0x440)
343#define MTK_LRO_ALT_INDEX_OFFSET (8)
344
345/* PDMA HW LRO ALT Data Registers */
346#define MTK_LRO_ALT_DBG_DATA (PDMA_BASE + 0x444)
347
developerfd40db22021-04-29 10:08:25 +0800348/* PDMA HW LRO Ring Control Registers */
developerfd40db22021-04-29 10:08:25 +0800349#define MTK_LRO_CTRL_DW1_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW1 + (x * 0x40))
350#define MTK_LRO_CTRL_DW2_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW2 + (x * 0x40))
351#define MTK_LRO_CTRL_DW3_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW3 + (x * 0x40))
352#define MTK_RING_AGE_TIME_L ((MTK_HW_LRO_AGE_TIME & 0x3ff) << 22)
353#define MTK_RING_AGE_TIME_H ((MTK_HW_LRO_AGE_TIME >> 10) & 0x3f)
developer18f46a82021-07-20 21:08:21 +0800354#define MTK_RING_PSE_MODE (1 << 6)
developerfd40db22021-04-29 10:08:25 +0800355#define MTK_RING_AUTO_LERAN_MODE (3 << 6)
356#define MTK_RING_VLD BIT(8)
357#define MTK_RING_MAX_AGG_TIME ((MTK_HW_LRO_AGG_TIME & 0xffff) << 10)
358#define MTK_RING_MAX_AGG_CNT_L ((MTK_HW_LRO_MAX_AGG_CNT & 0x3f) << 26)
359#define MTK_RING_MAX_AGG_CNT_H ((MTK_HW_LRO_MAX_AGG_CNT >> 6) & 0x3)
360
developer77d03a72021-06-06 00:06:00 +0800361/* LRO_RX_RING_CTRL_DW masks */
362#define MTK_LRO_RING_AGG_TIME_MASK BITS(10, 25)
363#define MTK_LRO_RING_AGG_CNT_L_MASK BITS(26, 31)
364#define MTK_LRO_RING_AGG_CNT_H_MASK BITS(0, 1)
365#define MTK_LRO_RING_AGE_TIME_L_MASK BITS(22, 31)
366#define MTK_LRO_RING_AGE_TIME_H_MASK BITS(0, 5)
367
368/* LRO_RX_RING_CTRL_DW0 offsets */
369#define MTK_RX_IPV6_FORCE_OFFSET (0)
370#define MTK_RX_IPV4_FORCE_OFFSET (1)
371
372/* LRO_RX_RING_CTRL_DW1 offsets */
373#define MTK_LRO_RING_AGE_TIME_L_OFFSET (22)
374
375/* LRO_RX_RING_CTRL_DW2 offsets */
376#define MTK_LRO_RING_AGE_TIME_H_OFFSET (0)
377#define MTK_RX_MODE_OFFSET (6)
378#define MTK_RX_PORT_VALID_OFFSET (8)
379#define MTK_RX_MYIP_VALID_OFFSET (9)
380#define MTK_LRO_RING_AGG_TIME_OFFSET (10)
381#define MTK_LRO_RING_AGG_CNT_L_OFFSET (26)
382
383/* LRO_RX_RING_CTRL_DW3 offsets */
384#define MTK_LRO_RING_AGG_CNT_H_OFFSET (0)
385
386/* LRO_RX_RING_STP_DTP_DW offsets */
387#define MTK_RX_TCP_DEST_PORT_OFFSET (0)
388#define MTK_RX_TCP_SRC_PORT_OFFSET (16)
389
developerfd40db22021-04-29 10:08:25 +0800390/* QDMA TX Queue Configuration Registers */
391#define MTK_QTX_CFG(x) (QDMA_BASE + (x * 0x10))
392#define QDMA_RES_THRES 4
393
394/* QDMA TX Queue Scheduler Registers */
395#define MTK_QTX_SCH(x) (QDMA_BASE + 4 + (x * 0x10))
396
397/* QDMA RX Base Pointer Register */
398#define MTK_QRX_BASE_PTR0 (QDMA_BASE + 0x100)
399#define MTK_QRX_BASE_PTR_CFG(x) (MTK_QRX_BASE_PTR0 + ((x) * 0x10))
400
401/* QDMA RX Maximum Count Register */
402#define MTK_QRX_MAX_CNT0 (QDMA_BASE + 0x104)
403#define MTK_QRX_MAX_CNT_CFG(x) (MTK_QRX_MAX_CNT0 + ((x) * 0x10))
404
405/* QDMA RX CPU Pointer Register */
406#define MTK_QRX_CRX_IDX0 (QDMA_BASE + 0x108)
407#define MTK_QRX_CRX_IDX_CFG(x) (MTK_QRX_CRX_IDX0 + ((x) * 0x10))
408
409/* QDMA RX DMA Pointer Register */
410#define MTK_QRX_DRX_IDX0 (QDMA_BASE + 0x10c)
411
developer329d8ee2022-08-02 08:49:42 +0800412/* QDMA Page Configuration Register */
413#define MTK_QDMA_PAGE (QDMA_BASE + 0x1f0)
414
developerfd40db22021-04-29 10:08:25 +0800415/* QDMA Global Configuration Register */
416#define MTK_QDMA_GLO_CFG (QDMA_BASE + 0x204)
417#define MTK_RX_2B_OFFSET BIT(31)
developer58ab5842022-06-01 15:10:25 +0800418#define MTK_PKT_RX_WDONE BIT(27)
developerfd40db22021-04-29 10:08:25 +0800419#define MTK_RX_BT_32DWORDS (3 << 11)
420#define MTK_NDP_CO_PRO BIT(10)
421#define MTK_TX_WB_DDONE BIT(6)
422#define MTK_DMA_SIZE_16DWORDS (2 << 4)
423#define MTK_DMA_SIZE_32DWORDS (3 << 4)
424#define MTK_RX_DMA_BUSY BIT(3)
425#define MTK_TX_DMA_BUSY BIT(1)
426#define MTK_RX_DMA_EN BIT(2)
427#define MTK_TX_DMA_EN BIT(0)
428#define MTK_DMA_BUSY_TIMEOUT HZ
429
430/* QDMA V2 Global Configuration Register */
431#define MTK_CHK_DDONE_EN BIT(28)
432#define MTK_DMAD_WR_WDONE BIT(26)
433#define MTK_WCOMP_EN BIT(24)
developer2cdef092022-04-15 17:27:55 +0800434#define MTK_RESV_BUF (0x80 << 16)
developerfd40db22021-04-29 10:08:25 +0800435#define MTK_MUTLI_CNT (0x4 << 12)
developer19d84562022-04-21 17:01:06 +0800436#define MTK_RESV_BUF_MASK (0xff << 16)
developerfd40db22021-04-29 10:08:25 +0800437
438/* QDMA Reset Index Register */
439#define MTK_QDMA_RST_IDX (QDMA_BASE + 0x208)
440
441/* QDMA Delay Interrupt Register */
442#define MTK_QDMA_DELAY_INT (QDMA_BASE + 0x20c)
443
444/* QDMA Flow Control Register */
445#define MTK_QDMA_FC_THRES (QDMA_BASE + 0x210)
446#define FC_THRES_DROP_MODE BIT(20)
447#define FC_THRES_DROP_EN (7 << 16)
448#define FC_THRES_MIN 0x4444
449
450/* QDMA Interrupt Status Register */
451#define MTK_QDMA_INT_STATUS (QDMA_BASE + 0x218)
developer8ecd51b2023-03-13 11:28:28 +0800452#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developer94806ec2023-05-19 14:16:44 +0800453#define MTK_RX_DONE_INT(ring_no) \
developer089e8852022-09-28 14:43:46 +0800454 (MTK_HAS_CAPS(eth->soc->caps, MTK_RSS) ? (BIT(24 + (ring_no))) : \
455 ((ring_no) ? BIT(16 + (ring_no)) : BIT(14)))
developerfd40db22021-04-29 10:08:25 +0800456#else
developer94806ec2023-05-19 14:16:44 +0800457#define MTK_RX_DONE_INT(ring_no) \
458 (MTK_HAS_CAPS(eth->soc->caps, MTK_RSS) ? (BIT(16 + (ring_no))) : \
459 ((ring_no) ? BIT(24 + (ring_no)) : BIT(30)))
developerfd40db22021-04-29 10:08:25 +0800460#endif
461#define MTK_RX_DONE_INT3 BIT(19)
462#define MTK_RX_DONE_INT2 BIT(18)
463#define MTK_RX_DONE_INT1 BIT(17)
464#define MTK_RX_DONE_INT0 BIT(16)
465#define MTK_TX_DONE_INT3 BIT(3)
466#define MTK_TX_DONE_INT2 BIT(2)
467#define MTK_TX_DONE_INT1 BIT(1)
468#define MTK_TX_DONE_INT0 BIT(0)
developerfd40db22021-04-29 10:08:25 +0800469#define MTK_TX_DONE_DLY BIT(28)
470#define MTK_TX_DONE_INT MTK_TX_DONE_DLY
471
472/* QDMA Interrupt grouping registers */
473#define MTK_QDMA_INT_GRP1 (QDMA_BASE + 0x220)
474#define MTK_QDMA_INT_GRP2 (QDMA_BASE + 0x224)
475#define MTK_RLS_DONE_INT BIT(0)
476
477/* QDMA Interrupt Status Register */
478#define MTK_QDMA_INT_MASK (QDMA_BASE + 0x21c)
479
developer8051e042022-04-08 13:26:36 +0800480/* QDMA DMA FSM */
481#define MTK_QDMA_FSM (QDMA_BASE + 0x234)
482
developerfd40db22021-04-29 10:08:25 +0800483/* QDMA Interrupt Mask Register */
484#define MTK_QDMA_HRED2 (QDMA_BASE + 0x244)
485
486/* QDMA TX Forward CPU Pointer Register */
487#define MTK_QTX_CTX_PTR (QDMA_BASE +0x300)
488
489/* QDMA TX Forward DMA Pointer Register */
490#define MTK_QTX_DTX_PTR (QDMA_BASE +0x304)
491
developer8051e042022-04-08 13:26:36 +0800492/* QDMA TX Forward DMA Counter */
493#define MTK_QDMA_FWD_CNT (QDMA_BASE + 0x308)
494
developerfd40db22021-04-29 10:08:25 +0800495/* QDMA TX Release CPU Pointer Register */
496#define MTK_QTX_CRX_PTR (QDMA_BASE +0x310)
497
498/* QDMA TX Release DMA Pointer Register */
499#define MTK_QTX_DRX_PTR (QDMA_BASE +0x314)
500
501/* QDMA FQ Head Pointer Register */
502#define MTK_QDMA_FQ_HEAD (QDMA_BASE +0x320)
503
504/* QDMA FQ Head Pointer Register */
505#define MTK_QDMA_FQ_TAIL (QDMA_BASE +0x324)
506
507/* QDMA FQ Free Page Counter Register */
508#define MTK_QDMA_FQ_CNT (QDMA_BASE +0x328)
509
510/* QDMA FQ Free Page Buffer Length Register */
511#define MTK_QDMA_FQ_BLEN (QDMA_BASE +0x32c)
512
developer8051e042022-04-08 13:26:36 +0800513/* WDMA Registers */
developer37482a42022-12-26 13:31:13 +0800514#define MTK_WDMA_CTX_PTR(x) (WDMA_BASE(x) + 0x8)
developer8051e042022-04-08 13:26:36 +0800515#define MTK_WDMA_DTX_PTR(x) (WDMA_BASE(x) + 0xC)
516#define MTK_WDMA_GLO_CFG(x) (WDMA_BASE(x) + 0x204)
517#define MTK_WDMA_TX_DBG_MON0(x) (WDMA_BASE(x) + 0x230)
developer37482a42022-12-26 13:31:13 +0800518#define MTK_WDMA_RX_DBG_MON1(x) (WDMA_BASE(x) + 0x3c4)
519#define MTK_WDMA_CRX_PTR(x) (WDMA_BASE(x) + 0x108)
520#define MTK_WDMA_DRX_PTR(x) (WDMA_BASE(x) + 0x10C)
developer8051e042022-04-08 13:26:36 +0800521#define MTK_CDM_TXFIFO_RDY BIT(7)
522
developer37482a42022-12-26 13:31:13 +0800523/*TDMA Register*/
524#define MTK_TDMA_GLO_CFG (0x6204)
525
developerfd40db22021-04-29 10:08:25 +0800526/* GMA1 Received Good Byte Count Register */
developer089e8852022-09-28 14:43:46 +0800527#if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developerfd40db22021-04-29 10:08:25 +0800528#define MTK_GDM1_TX_GBCNT 0x1C00
529#else
530#define MTK_GDM1_TX_GBCNT 0x2400
531#endif
developer089e8852022-09-28 14:43:46 +0800532
533#if defined(CONFIG_MEDIATEK_NETSYS_V3)
534#define MTK_STAT_OFFSET 0x80
535#else
developerfd40db22021-04-29 10:08:25 +0800536#define MTK_STAT_OFFSET 0x40
developer089e8852022-09-28 14:43:46 +0800537#endif
developerfd40db22021-04-29 10:08:25 +0800538
539/* QDMA TX NUM */
540#define MTK_QDMA_TX_NUM 16
developer797e46c2022-07-29 12:05:32 +0800541#define MTK_QDMA_PAGE_NUM 8
developerfd40db22021-04-29 10:08:25 +0800542#define MTK_QDMA_TX_MASK ((MTK_QDMA_TX_NUM) - 1)
543#define QID_LOW_BITS(x) ((x) & 0xf)
544#define QID_HIGH_BITS(x) ((((x) >> 4) & 0x3) << 20)
545#define QID_BITS_V2(x) (((x) & 0x3f) << 16)
546
developerdc0d45f2021-12-27 13:01:22 +0800547#define MTK_QDMA_GMAC2_QID 8
548
developerfd40db22021-04-29 10:08:25 +0800549/* QDMA V2 descriptor txd6 */
550#define TX_DMA_INS_VLAN_V2 BIT(16)
551
552/* QDMA V2 descriptor txd5 */
553#define TX_DMA_CHKSUM_V2 (0x7 << 28)
554#define TX_DMA_TSO_V2 BIT(31)
developer089e8852022-09-28 14:43:46 +0800555#define TX_DMA_SPTAG_V3 BIT(27)
developerfd40db22021-04-29 10:08:25 +0800556
557/* QDMA V2 descriptor txd4 */
558#define TX_DMA_FPORT_SHIFT_V2 8
559#define TX_DMA_FPORT_MASK_V2 0xf
560#define TX_DMA_SWC_V2 BIT(30)
561
developerfd40db22021-04-29 10:08:25 +0800562#define MTK_TX_DMA_BUF_LEN 0x3fff
developere9356982022-07-04 09:03:20 +0800563#define MTK_TX_DMA_BUF_LEN_V2 0xffff
developerfd40db22021-04-29 10:08:25 +0800564#define MTK_TX_DMA_BUF_SHIFT 16
developere9356982022-07-04 09:03:20 +0800565#define MTK_TX_DMA_BUF_SHIFT_V2 8
developerfd40db22021-04-29 10:08:25 +0800566
developer8ecd51b2023-03-13 11:28:28 +0800567#define MTK_RX_DMA_BUF_LEN 0x3fff
568#define MTK_RX_DMA_BUF_SHIFT 16
569
developerfd40db22021-04-29 10:08:25 +0800570#define RX_DMA_SPORT_SHIFT 19
developere9356982022-07-04 09:03:20 +0800571#define RX_DMA_SPORT_SHIFT_V2 26
developerfd40db22021-04-29 10:08:25 +0800572#define RX_DMA_SPORT_MASK 0x7
developere9356982022-07-04 09:03:20 +0800573#define RX_DMA_SPORT_MASK_V2 0xf
developerfd40db22021-04-29 10:08:25 +0800574
575/* QDMA descriptor txd4 */
576#define TX_DMA_CHKSUM (0x7 << 29)
577#define TX_DMA_TSO BIT(28)
578#define TX_DMA_FPORT_SHIFT 25
579#define TX_DMA_FPORT_MASK 0x7
580#define TX_DMA_INS_VLAN BIT(16)
581
582/* QDMA descriptor txd3 */
583#define TX_DMA_OWNER_CPU BIT(31)
584#define TX_DMA_LS0 BIT(30)
developere9356982022-07-04 09:03:20 +0800585#define TX_DMA_PLEN0(_x) (((_x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
586#define TX_DMA_PLEN1(_x) ((_x) & eth->soc->txrx.dma_max_len)
developerfd40db22021-04-29 10:08:25 +0800587#define TX_DMA_SWC BIT(14)
developer089e8852022-09-28 14:43:46 +0800588#define TX_DMA_SDP1(_x) ((((u64)(_x)) >> 32) & 0xf)
developerfd40db22021-04-29 10:08:25 +0800589
590/* PDMA on MT7628 */
591#define TX_DMA_DONE BIT(31)
592#define TX_DMA_LS1 BIT(14)
593#define TX_DMA_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE)
594
595/* QDMA descriptor rxd2 */
596#define RX_DMA_DONE BIT(31)
597#define RX_DMA_LSO BIT(30)
developer8ecd51b2023-03-13 11:28:28 +0800598#if defined(CONFIG_MEDIATEK_NETSYS_RX_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
developere9356982022-07-04 09:03:20 +0800599#define RX_DMA_PLEN0(_x) (((_x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
600#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 +0800601#else
602#define RX_DMA_PLEN0(_x) \
603 (((_x) & MTK_RX_DMA_BUF_LEN) << MTK_RX_DMA_BUF_SHIFT)
604#define RX_DMA_GET_PLEN0(_x) \
605 (((_x) >> MTK_RX_DMA_BUF_SHIFT) & MTK_RX_DMA_BUF_LEN)
606#endif
607
developer77d03a72021-06-06 00:06:00 +0800608#define RX_DMA_GET_AGG_CNT(_x) (((_x) >> 2) & 0xff)
609#define RX_DMA_GET_REV(_x) (((_x) >> 10) & 0x1f)
developerfd40db22021-04-29 10:08:25 +0800610#define RX_DMA_VTAG BIT(15)
developer089e8852022-09-28 14:43:46 +0800611#define RX_DMA_SDP1(_x) ((((u64)(_x)) >> 32) & 0xf)
developerfd40db22021-04-29 10:08:25 +0800612
613/* QDMA descriptor rxd3 */
614#define RX_DMA_VID(_x) ((_x) & VLAN_VID_MASK)
615#define RX_DMA_TCI(_x) ((_x) & (VLAN_PRIO_MASK | VLAN_VID_MASK))
616#define RX_DMA_VPID(_x) (((_x) >> 16) & 0xffff)
617
618/* QDMA descriptor rxd4 */
619#define RX_DMA_L4_VALID BIT(24)
620#define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
621#define RX_DMA_SPECIAL_TAG BIT(22) /* switch header in packet */
622
623#define RX_DMA_GET_SPORT(_x) (((_x) >> RX_DMA_SPORT_SHIFT) & RX_DMA_SPORT_MASK)
developere9356982022-07-04 09:03:20 +0800624#define RX_DMA_GET_SPORT_V2(_x) (((_x) >> RX_DMA_SPORT_SHIFT_V2) & RX_DMA_SPORT_MASK_V2)
developerfd40db22021-04-29 10:08:25 +0800625
626/* PDMA V2 descriptor rxd3 */
627#define RX_DMA_VTAG_V2 BIT(0)
628#define RX_DMA_L4_VALID_V2 BIT(2)
629
630/* PDMA V2 descriptor rxd4 */
631#define RX_DMA_VID_V2(_x) RX_DMA_VID(_x)
developer255bba22021-07-27 15:16:33 +0800632#define RX_DMA_TCI_V2(_x) RX_DMA_TCI(_x)
633#define RX_DMA_VPID_V2(_x) RX_DMA_VPID(_x)
developerfd40db22021-04-29 10:08:25 +0800634
developer77d03a72021-06-06 00:06:00 +0800635/* PDMA V2 descriptor rxd6 */
636#define RX_DMA_GET_FLUSH_RSN_V2(_x) ((_x) & 0x7)
637#define RX_DMA_GET_AGG_CNT_V2(_x) (((_x) >> 16) & 0xff)
developer006325c2022-10-06 16:39:50 +0800638#define RX_DMA_GET_TOPS_CRSN(_x) (((_x) >> 24) & 0xff)
developer77d03a72021-06-06 00:06:00 +0800639
developerc8acd8d2022-11-10 09:07:10 +0800640/* PHY Polling and SMI Master Control registers */
641#define MTK_PPSC 0x10000
642#define PPSC_MDC_CFG GENMASK(29, 24)
643#define PPSC_MDC_TURBO BIT(20)
developerc4d8da72023-03-16 14:37:28 +0800644#define MDC_MAX_FREQ 25000000
645#define MDC_MAX_DIVIDER 63
developerc8acd8d2022-11-10 09:07:10 +0800646
developerfd40db22021-04-29 10:08:25 +0800647/* PHY Indirect Access Control registers */
648#define MTK_PHY_IAC 0x10004
649#define PHY_IAC_ACCESS BIT(31)
650#define PHY_IAC_READ BIT(19)
developer599cda42022-05-24 15:13:31 +0800651#define PHY_IAC_READ_C45 (3 << 18)
652#define PHY_IAC_ADDR_C45 (0 << 18)
developerfd40db22021-04-29 10:08:25 +0800653#define PHY_IAC_WRITE BIT(18)
654#define PHY_IAC_START BIT(16)
developer599cda42022-05-24 15:13:31 +0800655#define PHY_IAC_START_C45 (0 << 16)
developerfd40db22021-04-29 10:08:25 +0800656#define PHY_IAC_ADDR_SHIFT 20
657#define PHY_IAC_REG_SHIFT 25
658#define PHY_IAC_TIMEOUT HZ
659
developerc8acd8d2022-11-10 09:07:10 +0800660#if defined(CONFIG_MEDIATEK_NETSYS_V3)
661#define MTK_MAC_MISC 0x10010
662#else
developerfd40db22021-04-29 10:08:25 +0800663#define MTK_MAC_MISC 0x1000c
developerc8acd8d2022-11-10 09:07:10 +0800664#endif
665#define MISC_MDC_TURBO BIT(4)
developerfd40db22021-04-29 10:08:25 +0800666#define MTK_MUX_TO_ESW BIT(0)
667
developer089e8852022-09-28 14:43:46 +0800668/* XMAC status registers */
669#define MTK_XGMAC_STS(x) ((x == MTK_GMAC3_ID) ? 0x1001C : 0x1000C)
developer2b9bc722023-03-09 11:48:44 +0800670#define MTK_XGMAC_FORCE_LINK(x) ((x == MTK_GMAC2_ID) ? BIT(31) : BIT(15))
developer089e8852022-09-28 14:43:46 +0800671#define MTK_USXGMII_PCS_LINK BIT(8)
672#define MTK_XGMAC_RX_FC BIT(5)
673#define MTK_XGMAC_TX_FC BIT(4)
674#define MTK_USXGMII_PCS_MODE GENMASK(3, 1)
675#define MTK_XGMAC_LINK_STS BIT(0)
676
677/* GSW bridge registers */
678#define MTK_GSW_CFG (0x10080)
679#define GSWTX_IPG_MASK GENMASK(19, 16)
680#define GSWTX_IPG_SHIFT 16
681#define GSWRX_IPG_MASK GENMASK(3, 0)
682#define GSWRX_IPG_SHIFT 0
683#define GSW_IPG_11 11
684
developerfd40db22021-04-29 10:08:25 +0800685/* Mac control registers */
686#define MTK_MAC_MCR(x) (0x10100 + (x * 0x100))
687#define MAC_MCR_MAX_RX_1536 BIT(24)
developerd8a29752022-08-19 13:32:03 +0800688#define MAC_MCR_IPG_CFG (BIT(18) | BIT(16) | BIT(12))
developerfd40db22021-04-29 10:08:25 +0800689#define MAC_MCR_FORCE_MODE BIT(15)
690#define MAC_MCR_TX_EN BIT(14)
691#define MAC_MCR_RX_EN BIT(13)
692#define MAC_MCR_BACKOFF_EN BIT(9)
693#define MAC_MCR_BACKPR_EN BIT(8)
developer9b725932022-11-24 16:25:56 +0800694#define MAC_MCR_FORCE_EEE1000 BIT(7)
695#define MAC_MCR_FORCE_EEE100 BIT(6)
developerfd40db22021-04-29 10:08:25 +0800696#define MAC_MCR_FORCE_RX_FC BIT(5)
697#define MAC_MCR_FORCE_TX_FC BIT(4)
698#define MAC_MCR_SPEED_1000 BIT(3)
699#define MAC_MCR_SPEED_100 BIT(2)
700#define MAC_MCR_FORCE_DPX BIT(1)
701#define MAC_MCR_FORCE_LINK BIT(0)
702#define MAC_MCR_FORCE_LINK_DOWN (MAC_MCR_FORCE_MODE)
703
developer089e8852022-09-28 14:43:46 +0800704/* XFI Mac control registers */
developerff5e5092023-07-25 15:55:28 +0800705#define MTK_XMAC_BASE(x) (0x12000 + ((x - 1) * 0x1000))
706#define MTK_XMAC_MCR(x) (MTK_XMAC_BASE(x))
developer089e8852022-09-28 14:43:46 +0800707#define XMAC_MCR_TRX_DISABLE 0xf
708#define XMAC_MCR_FORCE_TX_FC BIT(5)
709#define XMAC_MCR_FORCE_RX_FC BIT(4)
710
developerff5e5092023-07-25 15:55:28 +0800711/* XFI Mac logic reset registers */
712#define MTK_XMAC_LOGIC_RST(x) (MTK_XMAC_BASE(x) + 0x10)
713#define XMAC_LOGIC_RST BIT(0)
714
715/* XFI Mac count global control */
716#define MTK_XMAC_CNT_CTRL(x) (MTK_XMAC_BASE(x) + 0x100)
717#define XMAC_GLB_CNTCLR BIT(0)
718
developer9b725932022-11-24 16:25:56 +0800719/* Mac EEE control registers */
720#define MTK_MAC_EEE(x) (0x10104 + (x * 0x100))
721#define MAC_EEE_WAKEUP_TIME_1000 GENMASK(31, 24)
722#define MAC_EEE_WAKEUP_TIME_100 GENMASK(23, 16)
723#define MAC_EEE_LPI_TXIDLE_THD GENMASK(15, 8)
724#define MAC_EEE_RESV0 GENMASK(7, 4)
725#define MAC_EEE_CKG_TXILDE BIT(3)
726#define MAC_EEE_CKG_RXLPI BIT(2)
727#define MAC_EEE_TX_DOWN_REQ BIT(1)
728#define MAC_EEE_LPI_MODE BIT(0)
729
developerfd40db22021-04-29 10:08:25 +0800730/* Mac status registers */
731#define MTK_MAC_MSR(x) (0x10108 + (x * 0x100))
732#define MAC_MSR_EEE1G BIT(7)
733#define MAC_MSR_EEE100M BIT(6)
734#define MAC_MSR_RX_FC BIT(5)
735#define MAC_MSR_TX_FC BIT(4)
736#define MAC_MSR_SPEED_1000 BIT(3)
737#define MAC_MSR_SPEED_100 BIT(2)
738#define MAC_MSR_SPEED_MASK (MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100)
739#define MAC_MSR_DPX BIT(1)
740#define MAC_MSR_LINK BIT(0)
741
742/* TRGMII RXC control register */
743#define TRGMII_RCK_CTRL 0x10300
744#define DQSI0(x) ((x << 0) & GENMASK(6, 0))
745#define DQSI1(x) ((x << 8) & GENMASK(14, 8))
746#define RXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
747#define RXC_RST BIT(31)
748#define RXC_DQSISEL BIT(30)
749#define RCK_CTRL_RGMII_1000 (RXC_DQSISEL | RXCTL_DMWTLAT(2) | DQSI1(16))
750#define RCK_CTRL_RGMII_10_100 RXCTL_DMWTLAT(2)
751
752#define NUM_TRGMII_CTRL 5
753
754/* TRGMII RXC control register */
755#define TRGMII_TCK_CTRL 0x10340
756#define TXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16))
757#define TXC_INV BIT(30)
758#define TCK_CTRL_RGMII_1000 TXCTL_DMWTLAT(2)
759#define TCK_CTRL_RGMII_10_100 (TXC_INV | TXCTL_DMWTLAT(2))
760
761/* TRGMII TX Drive Strength */
762#define TRGMII_TD_ODT(i) (0x10354 + 8 * (i))
763#define TD_DM_DRVP(x) ((x) & 0xf)
764#define TD_DM_DRVN(x) (((x) & 0xf) << 4)
765
766/* TRGMII Interface mode register */
767#define INTF_MODE 0x10390
768#define TRGMII_INTF_DIS BIT(0)
769#define TRGMII_MODE BIT(1)
770#define TRGMII_CENTRAL_ALIGNED BIT(2)
771#define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
772#define INTF_MODE_RGMII_10_100 0
773
774/* GPIO port control registers for GMAC 2*/
775#define GPIO_OD33_CTRL8 0x4c0
776#define GPIO_BIAS_CTRL 0xed0
777#define GPIO_DRV_SEL10 0xf00
778
developer0fef5222023-04-26 14:48:31 +0800779/* SoC hardware version register */
780#define HWVER_BIT_NETSYS_1_2 BIT(0)
781#define HWVER_BIT_NETSYS_3 BIT(8)
782
developerfd40db22021-04-29 10:08:25 +0800783/* ethernet subsystem chip id register */
784#define ETHSYS_CHIPID0_3 0x0
785#define ETHSYS_CHIPID4_7 0x4
786#define MT7623_ETH 7623
787#define MT7622_ETH 7622
788#define MT7621_ETH 7621
789
790/* ethernet system control register */
791#define ETHSYS_SYSCFG 0x10
792#define SYSCFG_DRAM_TYPE_DDR2 BIT(4)
793
794/* ethernet subsystem config register */
795#define ETHSYS_SYSCFG0 0x14
796#define SYSCFG0_GE_MASK 0x3
797#define SYSCFG0_GE_MODE(x, y) (x << (12 + (y * 2)))
developer089e8852022-09-28 14:43:46 +0800798#define SYSCFG0_SGMII_MASK GENMASK(9, 7)
developerfd40db22021-04-29 10:08:25 +0800799#define SYSCFG0_SGMII_GMAC1 ((2 << 8) & SYSCFG0_SGMII_MASK)
800#define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK)
801#define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
802#define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
developer089e8852022-09-28 14:43:46 +0800803#define SYSCFG0_SGMII_GMAC3_V2 BIT(7)
developerfd40db22021-04-29 10:08:25 +0800804
805
806/* ethernet subsystem clock register */
807#define ETHSYS_CLKCFG0 0x2c
808#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11)
809#define ETHSYS_TRGMII_MT7621_MASK (BIT(5) | BIT(6))
810#define ETHSYS_TRGMII_MT7621_APLL BIT(6)
811#define ETHSYS_TRGMII_MT7621_DDR_PLL BIT(5)
812
813/* ethernet reset control register */
developer545abf02021-07-15 17:47:01 +0800814#define ETHSYS_RSTCTRL 0x34
815#define RSTCTRL_FE BIT(6)
developer545abf02021-07-15 17:47:01 +0800816#define RSTCTRL_ETH BIT(23)
developer8051e042022-04-08 13:26:36 +0800817#if defined(CONFIG_MEDIATEK_NETSYS_V2)
818#define RSTCTRL_PPE0 BIT(30)
819#define RSTCTRL_PPE1 BIT(31)
developer37482a42022-12-26 13:31:13 +0800820#elif defined(CONFIG_MEDIATEK_NETSYS_V3)
821#define RSTCTRL_PPE0 BIT(29)
822#define RSTCTRL_PPE1 BIT(30)
823#define RSTCTRL_PPE2 BIT(31)
824#define RSTCTRL_WDMA0 BIT(24)
825#define RSTCTRL_WDMA1 BIT(25)
826#define RSTCTRL_WDMA2 BIT(26)
developera5eb8d62022-04-22 15:42:20 +0800827#else
developer8051e042022-04-08 13:26:36 +0800828#define RSTCTRL_PPE0 BIT(31)
developer37482a42022-12-26 13:31:13 +0800829#define RSTCTRL_PPE1 0
developer8051e042022-04-08 13:26:36 +0800830#endif
developer545abf02021-07-15 17:47:01 +0800831
832/* ethernet reset check idle register */
833#define ETHSYS_FE_RST_CHK_IDLE_EN 0x28
834
developer3f28d382023-03-07 16:06:30 +0800835/* ethernet dma channel agent map */
836#define ETHSYS_DMA_AG_MAP 0x408
837#define ETHSYS_DMA_AG_MAP_PDMA BIT(0)
838#define ETHSYS_DMA_AG_MAP_QDMA BIT(1)
839#define ETHSYS_DMA_AG_MAP_PPE BIT(2)
developerfd40db22021-04-29 10:08:25 +0800840
841/* SGMII subsystem config registers */
developerfd40db22021-04-29 10:08:25 +0800842#define SGMSYS_PCS_CONTROL_1 0x0
developer38afb1a2023-04-17 09:57:27 +0800843#define SGMII_BMSR GENMASK(31, 16)
developerfd40db22021-04-29 10:08:25 +0800844#define SGMII_AN_RESTART BIT(9)
845#define SGMII_ISOLATE BIT(10)
846#define SGMII_AN_ENABLE BIT(12)
847#define SGMII_LINK_STATYS BIT(18)
848#define SGMII_AN_ABILITY BIT(19)
849#define SGMII_AN_COMPLETE BIT(21)
850#define SGMII_PCS_FAULT BIT(23)
851#define SGMII_AN_EXPANSION_CLR BIT(30)
852
developer089e8852022-09-28 14:43:46 +0800853/* Register to set SGMII speed */
developer38afb1a2023-04-17 09:57:27 +0800854#define SGMSYS_PCS_ADVERTISE 0x08
855#define SGMII_ADVERTISE GENMASK(15, 0)
856#define SGMII_LPA GENMASK(31, 16)
857#define SGMII_LPA_SPEED_MASK GENMASK(11, 10)
858#define SGMII_LPA_SPEED_10 0
859#define SGMII_LPA_SPEED_100 1
860#define SGMII_LPA_SPEED_1000 2
861#define SGMII_LPA_DUPLEX BIT(12)
862#define SGMII_LPA_LINK BIT(15)
developer089e8852022-09-28 14:43:46 +0800863
developerfd40db22021-04-29 10:08:25 +0800864/* Register to programmable link timer, the unit in 2 * 8ns */
865#define SGMSYS_PCS_LINK_TIMER 0x18
866#define SGMII_LINK_TIMER_DEFAULT (0x186a0 & GENMASK(19, 0))
867
868/* Register to control remote fault */
869#define SGMSYS_SGMII_MODE 0x20
developer38afb1a2023-04-17 09:57:27 +0800870#define SGMII_IF_MODE_SGMII BIT(0)
developerfd40db22021-04-29 10:08:25 +0800871#define SGMII_SPEED_DUPLEX_AN BIT(1)
developer089e8852022-09-28 14:43:46 +0800872#define SGMII_SPEED_MASK GENMASK(3, 2)
developerfd40db22021-04-29 10:08:25 +0800873#define SGMII_SPEED_10 0x0
874#define SGMII_SPEED_100 BIT(2)
875#define SGMII_SPEED_1000 BIT(3)
developer4e8a3fd2023-04-10 18:05:44 +0800876#define SGMII_DUPLEX_HALF BIT(4)
developerfd40db22021-04-29 10:08:25 +0800877#define SGMII_IF_MODE_BIT5 BIT(5)
878#define SGMII_REMOTE_FAULT_DIS BIT(8)
879#define SGMII_CODE_SYNC_SET_VAL BIT(9)
880#define SGMII_CODE_SYNC_SET_EN BIT(10)
881#define SGMII_SEND_AN_ERROR_EN BIT(11)
882#define SGMII_IF_MODE_MASK GENMASK(5, 1)
883
developer2b76a9d2022-09-20 14:59:45 +0800884/* Register to reset SGMII design */
885#define SGMII_RESERVED_0 0x34
886#define SGMII_SW_RESET BIT(0)
887
developerfd40db22021-04-29 10:08:25 +0800888/* Register to set SGMII speed, ANA RG_ Control Signals III*/
889#define SGMSYS_ANA_RG_CS3 0x2028
890#define RG_PHY_SPEED_MASK (BIT(2) | BIT(3))
891#define RG_PHY_SPEED_1_25G 0x0
892#define RG_PHY_SPEED_3_125G BIT(2)
893
894/* Register to power up QPHY */
895#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8
896#define SGMII_PHYA_PWD BIT(4)
897
developerf8ac94a2021-07-29 16:40:01 +0800898/* Register to QPHY wrapper control */
899#define SGMSYS_QPHY_WRAP_CTRL 0xec
900#define SGMII_PN_SWAP_MASK GENMASK(1, 0)
901#define SGMII_PN_SWAP_TX_RX (BIT(0) | BIT(1))
902
developer089e8852022-09-28 14:43:46 +0800903/* USXGMII subsystem config registers */
904/* Register to control speed */
905#define RG_PHY_TOP_SPEED_CTRL1 0x80C
developer95169b62023-05-12 17:58:58 +0800906#define USXGMII_RATE_UPDATE_MODE BIT(31)
907#define USXGMII_MAC_CK_GATED BIT(29)
908#define USXGMII_IF_FORCE_EN BIT(28)
909#define USXGMII_RATE_ADAPT_MODE GENMASK(10, 8)
910#define USXGMII_RATE_ADAPT_MODE_X1 0
911#define USXGMII_RATE_ADAPT_MODE_X2 1
912#define USXGMII_RATE_ADAPT_MODE_X4 2
913#define USXGMII_RATE_ADAPT_MODE_X10 3
914#define USXGMII_RATE_ADAPT_MODE_X100 4
915#define USXGMII_RATE_ADAPT_MODE_X5 5
916#define USXGMII_RATE_ADAPT_MODE_X50 6
917#define USXGMII_XFI_RX_MODE GENMASK(6, 4)
918#define USXGMII_XFI_RX_MODE_10G 0
919#define USXGMII_XFI_RX_MODE_5G 1
920#define USXGMII_XFI_TX_MODE GENMASK(2, 0)
921#define USXGMII_XFI_TX_MODE_10G 0
922#define USXGMII_XFI_TX_MODE_5G 1
developer089e8852022-09-28 14:43:46 +0800923
924/* Register to control PCS AN */
925#define RG_PCS_AN_CTRL0 0x810
developer4e8a3fd2023-04-10 18:05:44 +0800926#define USXGMII_AN_RESTART BIT(31)
developer95169b62023-05-12 17:58:58 +0800927#define USXGMII_AN_SYNC_CNT GENMASK(30, 11)
developer4e8a3fd2023-04-10 18:05:44 +0800928#define USXGMII_AN_ENABLE BIT(0)
929
developer95169b62023-05-12 17:58:58 +0800930#define RG_PCS_AN_CTRL2 0x818
931#define USXGMII_LINK_TIMER_IDLE_DETECT GENMASK(29, 20)
932#define USXGMII_LINK_TIMER_COMP_ACK_DETECT GENMASK(19, 10)
933#define USXGMII_LINK_TIMER_AN_RESTART GENMASK(9, 0)
934
935/* Register to read PCS AN status */
developer4e8a3fd2023-04-10 18:05:44 +0800936#define RG_PCS_AN_STS0 0x81C
937#define USXGMII_LPA_SPEED_MASK GENMASK(11, 9)
938#define USXGMII_LPA_SPEED_10 0
939#define USXGMII_LPA_SPEED_100 1
940#define USXGMII_LPA_SPEED_1000 2
941#define USXGMII_LPA_SPEED_10000 3
942#define USXGMII_LPA_SPEED_2500 4
943#define USXGMII_LPA_SPEED_5000 5
944#define USXGMII_LPA_DUPLEX BIT(12)
945#define USXGMII_LPA_LINK BIT(15)
946#define USXGMII_LPA_LATCH BIT(31)
developer089e8852022-09-28 14:43:46 +0800947
948/* Register to control USXGMII XFI PLL digital */
949#define XFI_PLL_DIG_GLB8 0x08
950#define RG_XFI_PLL_EN BIT(31)
951
952/* Register to control USXGMII XFI PLL analog */
953#define XFI_PLL_ANA_GLB8 0x108
954#define RG_XFI_PLL_ANA_SWWA 0x02283248
955
developerfd40db22021-04-29 10:08:25 +0800956/* Infrasys subsystem config registers */
957#define INFRA_MISC2 0x70c
958#define CO_QPHY_SEL BIT(0)
959#define GEPHY_MAC_SEL BIT(1)
960
developer024387a2022-12-07 22:18:27 +0800961/* Toprgu subsystem config registers */
962#define TOPRGU_SWSYSRST 0x18
963#define SWSYSRST_UNLOCK_KEY GENMASK(31, 24)
964#define SWSYSRST_XFI_PLL_GRST BIT(16)
965#define SWSYSRST_XFI_PEXPT1_GRST BIT(15)
966#define SWSYSRST_XFI_PEXPT0_GRST BIT(14)
developer6aa00162023-03-20 11:56:51 +0800967#define SWSYSRST_XFI1_GRST BIT(13)
968#define SWSYSRST_XFI0_GRST BIT(12)
developer024387a2022-12-07 22:18:27 +0800969#define SWSYSRST_SGMII1_GRST BIT(2)
970#define SWSYSRST_SGMII0_GRST BIT(1)
971#define TOPRGU_SWSYSRST_EN 0xFC
972
developer255bba22021-07-27 15:16:33 +0800973/* Top misc registers */
developer089e8852022-09-28 14:43:46 +0800974#define TOP_MISC_NETSYS_PCS_MUX 0x84
975#define NETSYS_PCS_MUX_MASK GENMASK(1, 0)
976#define MUX_G2_USXGMII_SEL BIT(1)
977#define MUX_HSGMII1_G1_SEL BIT(0)
developer255bba22021-07-27 15:16:33 +0800978#define USB_PHY_SWITCH_REG 0x218
979#define QPHY_SEL_MASK GENMASK(1, 0)
developerf1816a92021-11-15 12:18:02 +0800980#define SGMII_QPHY_SEL 0x2
developer255bba22021-07-27 15:16:33 +0800981
developerfd40db22021-04-29 10:08:25 +0800982/*MDIO control*/
983#define MII_MMD_ACC_CTL_REG 0x0d
984#define MII_MMD_ADDR_DATA_REG 0x0e
985#define MMD_OP_MODE_DATA BIT(14)
986
987/* MT7628/88 specific stuff */
988#define MT7628_PDMA_OFFSET 0x0800
989#define MT7628_SDM_OFFSET 0x0c00
990
991#define MT7628_TX_BASE_PTR0 (MT7628_PDMA_OFFSET + 0x00)
992#define MT7628_TX_MAX_CNT0 (MT7628_PDMA_OFFSET + 0x04)
993#define MT7628_TX_CTX_IDX0 (MT7628_PDMA_OFFSET + 0x08)
994#define MT7628_TX_DTX_IDX0 (MT7628_PDMA_OFFSET + 0x0c)
995#define MT7628_PST_DTX_IDX0 BIT(0)
996
997#define MT7628_SDM_MAC_ADRL (MT7628_SDM_OFFSET + 0x0c)
998#define MT7628_SDM_MAC_ADRH (MT7628_SDM_OFFSET + 0x10)
999
1000struct mtk_rx_dma {
1001 unsigned int rxd1;
1002 unsigned int rxd2;
1003 unsigned int rxd3;
1004 unsigned int rxd4;
developere9356982022-07-04 09:03:20 +08001005} __packed __aligned(4);
1006
1007struct mtk_rx_dma_v2 {
1008 unsigned int rxd1;
1009 unsigned int rxd2;
1010 unsigned int rxd3;
1011 unsigned int rxd4;
developerfd40db22021-04-29 10:08:25 +08001012 unsigned int rxd5;
1013 unsigned int rxd6;
1014 unsigned int rxd7;
1015 unsigned int rxd8;
developerfd40db22021-04-29 10:08:25 +08001016} __packed __aligned(4);
1017
1018struct mtk_tx_dma {
1019 unsigned int txd1;
1020 unsigned int txd2;
1021 unsigned int txd3;
1022 unsigned int txd4;
developere9356982022-07-04 09:03:20 +08001023} __packed __aligned(4);
1024
1025struct mtk_tx_dma_v2 {
1026 unsigned int txd1;
1027 unsigned int txd2;
1028 unsigned int txd3;
1029 unsigned int txd4;
developerfd40db22021-04-29 10:08:25 +08001030 unsigned int txd5;
1031 unsigned int txd6;
1032 unsigned int txd7;
1033 unsigned int txd8;
developerfd40db22021-04-29 10:08:25 +08001034} __packed __aligned(4);
1035
1036struct mtk_eth;
1037struct mtk_mac;
1038
1039/* struct mtk_hw_stats - the structure that holds the traffic statistics.
1040 * @stats_lock: make sure that stats operations are atomic
1041 * @reg_offset: the status register offset of the SoC
1042 * @syncp: the refcount
1043 *
1044 * All of the supported SoCs have hardware counters for traffic statistics.
1045 * Whenever the status IRQ triggers we can read the latest stats from these
1046 * counters and store them in this struct.
1047 */
1048struct mtk_hw_stats {
1049 u64 tx_bytes;
1050 u64 tx_packets;
1051 u64 tx_skip;
1052 u64 tx_collisions;
1053 u64 rx_bytes;
1054 u64 rx_packets;
1055 u64 rx_overflow;
1056 u64 rx_fcs_errors;
1057 u64 rx_short_errors;
1058 u64 rx_long_errors;
1059 u64 rx_checksum_errors;
1060 u64 rx_flow_control_packets;
1061
1062 spinlock_t stats_lock;
1063 u32 reg_offset;
1064 struct u64_stats_sync syncp;
1065};
1066
1067enum mtk_tx_flags {
1068 /* PDMA descriptor can point at 1-2 segments. This enum allows us to
1069 * track how memory was allocated so that it can be freed properly.
1070 */
1071 MTK_TX_FLAGS_SINGLE0 = 0x01,
1072 MTK_TX_FLAGS_PAGE0 = 0x02,
1073
1074 /* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted
1075 * SKB out instead of looking up through hardware TX descriptor.
1076 */
1077 MTK_TX_FLAGS_FPORT0 = 0x04,
1078 MTK_TX_FLAGS_FPORT1 = 0x08,
developer089e8852022-09-28 14:43:46 +08001079 MTK_TX_FLAGS_FPORT2 = 0x10,
developerfd40db22021-04-29 10:08:25 +08001080};
1081
1082/* This enum allows us to identify how the clock is defined on the array of the
1083 * clock in the order
1084 */
1085enum mtk_clks_map {
1086 MTK_CLK_ETHIF,
1087 MTK_CLK_SGMIITOP,
1088 MTK_CLK_ESW,
1089 MTK_CLK_GP0,
1090 MTK_CLK_GP1,
1091 MTK_CLK_GP2,
developer1bbcf512022-11-18 16:09:33 +08001092 MTK_CLK_GP3,
1093 MTK_CLK_XGP1,
1094 MTK_CLK_XGP2,
1095 MTK_CLK_XGP3,
1096 MTK_CLK_CRYPTO,
developerfd40db22021-04-29 10:08:25 +08001097 MTK_CLK_FE,
1098 MTK_CLK_TRGPLL,
1099 MTK_CLK_SGMII_TX_250M,
1100 MTK_CLK_SGMII_RX_250M,
1101 MTK_CLK_SGMII_CDR_REF,
1102 MTK_CLK_SGMII_CDR_FB,
1103 MTK_CLK_SGMII2_TX_250M,
1104 MTK_CLK_SGMII2_RX_250M,
1105 MTK_CLK_SGMII2_CDR_REF,
1106 MTK_CLK_SGMII2_CDR_FB,
1107 MTK_CLK_SGMII_CK,
1108 MTK_CLK_ETH2PLL,
1109 MTK_CLK_WOCPU0,
1110 MTK_CLK_WOCPU1,
developer5cfc67a2022-12-29 19:06:51 +08001111 MTK_CLK_ETHWARP_WOCPU2,
1112 MTK_CLK_ETHWARP_WOCPU1,
1113 MTK_CLK_ETHWARP_WOCPU0,
1114 MTK_CLK_TOP_USXGMII_SBUS_0_SEL,
1115 MTK_CLK_TOP_USXGMII_SBUS_1_SEL,
1116 MTK_CLK_TOP_SGM_0_SEL,
1117 MTK_CLK_TOP_SGM_1_SEL,
1118 MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL,
1119 MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL,
1120 MTK_CLK_TOP_ETH_GMII_SEL,
1121 MTK_CLK_TOP_ETH_REFCK_50M_SEL,
1122 MTK_CLK_TOP_ETH_SYS_200M_SEL,
1123 MTK_CLK_TOP_ETH_SYS_SEL,
1124 MTK_CLK_TOP_ETH_XGMII_SEL,
1125 MTK_CLK_TOP_ETH_MII_SEL,
1126 MTK_CLK_TOP_NETSYS_SEL,
1127 MTK_CLK_TOP_NETSYS_500M_SEL,
1128 MTK_CLK_TOP_NETSYS_PAO_2X_SEL,
1129 MTK_CLK_TOP_NETSYS_SYNC_250M_SEL,
1130 MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL,
1131 MTK_CLK_TOP_NETSYS_WARP_SEL,
developerfd40db22021-04-29 10:08:25 +08001132 MTK_CLK_MAX
1133};
1134
1135#define MT7623_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1136 BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
1137 BIT(MTK_CLK_TRGPLL))
1138#define MT7622_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1139 BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
1140 BIT(MTK_CLK_GP2) | \
1141 BIT(MTK_CLK_SGMII_TX_250M) | \
1142 BIT(MTK_CLK_SGMII_RX_250M) | \
1143 BIT(MTK_CLK_SGMII_CDR_REF) | \
1144 BIT(MTK_CLK_SGMII_CDR_FB) | \
1145 BIT(MTK_CLK_SGMII_CK) | \
1146 BIT(MTK_CLK_ETH2PLL))
1147#define MT7621_CLKS_BITMAP (0)
1148#define MT7628_CLKS_BITMAP (0)
1149#define MT7629_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \
1150 BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \
1151 BIT(MTK_CLK_GP2) | BIT(MTK_CLK_FE) | \
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 BIT(MTK_CLK_SGMII_CK) | \
1161 BIT(MTK_CLK_ETH2PLL) | BIT(MTK_CLK_SGMIITOP))
1162
1163#define MT7986_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
1164 BIT(MTK_CLK_WOCPU1) | BIT(MTK_CLK_WOCPU0) | \
1165 BIT(MTK_CLK_SGMII_TX_250M) | \
1166 BIT(MTK_CLK_SGMII_RX_250M) | \
1167 BIT(MTK_CLK_SGMII_CDR_REF) | \
1168 BIT(MTK_CLK_SGMII_CDR_FB) | \
1169 BIT(MTK_CLK_SGMII2_TX_250M) | \
1170 BIT(MTK_CLK_SGMII2_RX_250M) | \
1171 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1172 BIT(MTK_CLK_SGMII2_CDR_FB))
1173
developer255bba22021-07-27 15:16:33 +08001174
developer9e9fb4c2021-11-30 17:33:04 +08001175#define MT7981_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_GP2) | BIT(MTK_CLK_GP1) | \
1176 BIT(MTK_CLK_WOCPU0) | \
1177 BIT(MTK_CLK_SGMII_TX_250M) | \
1178 BIT(MTK_CLK_SGMII_RX_250M) | \
1179 BIT(MTK_CLK_SGMII_CDR_REF) | \
1180 BIT(MTK_CLK_SGMII_CDR_FB) | \
1181 BIT(MTK_CLK_SGMII2_TX_250M) | \
1182 BIT(MTK_CLK_SGMII2_RX_250M) | \
1183 BIT(MTK_CLK_SGMII2_CDR_REF) | \
1184 BIT(MTK_CLK_SGMII2_CDR_FB))
developer089e8852022-09-28 14:43:46 +08001185
developer1bbcf512022-11-18 16:09:33 +08001186#define MT7988_CLKS_BITMAP (BIT(MTK_CLK_FE) | BIT(MTK_CLK_ESW) | \
1187 BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \
1188 BIT(MTK_CLK_GP3) | BIT(MTK_CLK_XGP1) | \
1189 BIT(MTK_CLK_XGP2) | BIT(MTK_CLK_XGP3) | \
1190 BIT(MTK_CLK_CRYPTO) | \
developer089e8852022-09-28 14:43:46 +08001191 BIT(MTK_CLK_SGMII_TX_250M) | \
1192 BIT(MTK_CLK_SGMII_RX_250M) | \
developer089e8852022-09-28 14:43:46 +08001193 BIT(MTK_CLK_SGMII2_TX_250M) | \
1194 BIT(MTK_CLK_SGMII2_RX_250M) | \
developer5cfc67a2022-12-29 19:06:51 +08001195 BIT(MTK_CLK_ETHWARP_WOCPU2) | \
1196 BIT(MTK_CLK_ETHWARP_WOCPU1) | \
1197 BIT(MTK_CLK_ETHWARP_WOCPU0) | \
1198 BIT(MTK_CLK_TOP_USXGMII_SBUS_0_SEL) | \
1199 BIT(MTK_CLK_TOP_USXGMII_SBUS_1_SEL) | \
1200 BIT(MTK_CLK_TOP_SGM_0_SEL) | \
1201 BIT(MTK_CLK_TOP_SGM_1_SEL) | \
1202 BIT(MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL) | \
1203 BIT(MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL) | \
1204 BIT(MTK_CLK_TOP_ETH_GMII_SEL) | \
1205 BIT(MTK_CLK_TOP_ETH_REFCK_50M_SEL) | \
1206 BIT(MTK_CLK_TOP_ETH_SYS_200M_SEL) | \
1207 BIT(MTK_CLK_TOP_ETH_SYS_SEL) | \
1208 BIT(MTK_CLK_TOP_ETH_XGMII_SEL) | \
1209 BIT(MTK_CLK_TOP_ETH_MII_SEL) | \
1210 BIT(MTK_CLK_TOP_NETSYS_SEL) | \
1211 BIT(MTK_CLK_TOP_NETSYS_500M_SEL) | \
1212 BIT(MTK_CLK_TOP_NETSYS_PAO_2X_SEL) | \
1213 BIT(MTK_CLK_TOP_NETSYS_SYNC_250M_SEL) | \
1214 BIT(MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL) | \
1215 BIT(MTK_CLK_TOP_NETSYS_WARP_SEL))
developer089e8852022-09-28 14:43:46 +08001216
developerfd40db22021-04-29 10:08:25 +08001217enum mtk_dev_state {
1218 MTK_HW_INIT,
1219 MTK_RESETTING
1220};
1221
developer089e8852022-09-28 14:43:46 +08001222/* PSE Port Definition */
1223enum mtk_pse_port {
1224 PSE_ADMA_PORT = 0,
1225 PSE_GDM1_PORT,
1226 PSE_GDM2_PORT,
1227 PSE_PPE0_PORT,
1228 PSE_PPE1_PORT,
1229 PSE_QDMA_TX_PORT,
1230 PSE_QDMA_RX_PORT,
1231 PSE_DROP_PORT,
1232 PSE_WDMA0_PORT,
1233 PSE_WDMA1_PORT,
1234 PSE_TDMA_PORT,
1235 PSE_NONE_PORT,
1236 PSE_PPE2_PORT,
1237 PSE_WDMA2_PORT,
1238 PSE_EIP197_PORT,
1239 PSE_GDM3_PORT,
1240 PSE_PORT_MAX
1241};
1242
1243/* GMAC Identifier */
1244enum mtk_gmac_id {
1245 MTK_GMAC1_ID = 0,
1246 MTK_GMAC2_ID,
1247 MTK_GMAC3_ID,
1248 MTK_GMAC_ID_MAX
1249};
1250
1251/* GDM Type */
1252enum mtk_gdm_type {
1253 MTK_GDM_TYPE = 0,
1254 MTK_XGDM_TYPE,
1255 MTK_GDM_TYPE_MAX
1256};
1257
developer0fef5222023-04-26 14:48:31 +08001258enum mtk_hw_id {
1259 MTK_HWID_V1 = 0,
1260 MTK_HWID_V2,
1261 MTK_HWID_MAX
1262};
1263
developer30e13e72022-11-03 10:21:24 +08001264static inline const char *gdm_type(int type)
1265{
1266 switch (type) {
1267 case MTK_GDM_TYPE:
1268 return "gdm";
1269 case MTK_XGDM_TYPE:
1270 return "xgdm";
1271 default:
1272 return "unkown";
1273 }
1274}
1275
developerfd40db22021-04-29 10:08:25 +08001276/* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at
1277 * by the TX descriptor s
1278 * @skb: The SKB pointer of the packet being sent
1279 * @dma_addr0: The base addr of the first segment
1280 * @dma_len0: The length of the first segment
1281 * @dma_addr1: The base addr of the second segment
1282 * @dma_len1: The length of the second segment
1283 */
1284struct mtk_tx_buf {
1285 struct sk_buff *skb;
1286 u32 flags;
1287 DEFINE_DMA_UNMAP_ADDR(dma_addr0);
1288 DEFINE_DMA_UNMAP_LEN(dma_len0);
1289 DEFINE_DMA_UNMAP_ADDR(dma_addr1);
1290 DEFINE_DMA_UNMAP_LEN(dma_len1);
1291};
1292
1293/* struct mtk_tx_ring - This struct holds info describing a TX ring
1294 * @dma: The descriptor ring
1295 * @buf: The memory pointed at by the ring
1296 * @phys: The physical addr of tx_buf
1297 * @next_free: Pointer to the next free descriptor
1298 * @last_free: Pointer to the last free descriptor
developerc4671b22021-05-28 13:16:42 +08001299 * @last_free_ptr: Hardware pointer value of the last free descriptor
developerfd40db22021-04-29 10:08:25 +08001300 * @thresh: The threshold of minimum amount of free descriptors
1301 * @free_count: QDMA uses a linked list. Track how many free descriptors
1302 * are present
1303 */
1304struct mtk_tx_ring {
developere9356982022-07-04 09:03:20 +08001305 void *dma;
developerfd40db22021-04-29 10:08:25 +08001306 struct mtk_tx_buf *buf;
1307 dma_addr_t phys;
developere9356982022-07-04 09:03:20 +08001308 void *next_free;
1309 void *last_free;
developerc4671b22021-05-28 13:16:42 +08001310 u32 last_free_ptr;
developerfd40db22021-04-29 10:08:25 +08001311 u16 thresh;
1312 atomic_t free_count;
1313 int dma_size;
developere9356982022-07-04 09:03:20 +08001314 void *dma_pdma; /* For MT7628/88 PDMA handling */
developerfd40db22021-04-29 10:08:25 +08001315 dma_addr_t phys_pdma;
1316 int cpu_idx;
1317};
1318
1319/* PDMA rx ring mode */
1320enum mtk_rx_flags {
1321 MTK_RX_FLAGS_NORMAL = 0,
1322 MTK_RX_FLAGS_HWLRO,
1323 MTK_RX_FLAGS_QDMA,
1324};
1325
1326/* struct mtk_rx_ring - This struct holds info describing a RX ring
1327 * @dma: The descriptor ring
1328 * @data: The memory pointed at by the ring
1329 * @phys: The physical addr of rx_buf
1330 * @frag_size: How big can each fragment be
1331 * @buf_size: The size of each packet buffer
1332 * @calc_idx: The current head of ring
developer77d03a72021-06-06 00:06:00 +08001333 * @ring_no: The index of ring
developerfd40db22021-04-29 10:08:25 +08001334 */
1335struct mtk_rx_ring {
developere9356982022-07-04 09:03:20 +08001336 void *dma;
developerfd40db22021-04-29 10:08:25 +08001337 u8 **data;
1338 dma_addr_t phys;
1339 u16 frag_size;
1340 u16 buf_size;
1341 u16 dma_size;
1342 bool calc_idx_update;
1343 u16 calc_idx;
1344 u32 crx_idx_reg;
developer77d03a72021-06-06 00:06:00 +08001345 u32 ring_no;
developerfd40db22021-04-29 10:08:25 +08001346};
1347
developerea49c302023-06-27 16:06:41 +08001348/* struct mtk_rss_params - This is the structure holding parameters
1349 for the RSS ring
1350 * @hash_key The element is used to record the
1351 secret key for the RSS ring
1352 * indirection_table The element is used to record the
1353 indirection table for the RSS ring
1354 */
1355struct mtk_rss_params {
1356 u32 hash_key[MTK_RSS_HASH_KEYSIZE / sizeof(u32)];
1357 u8 indirection_table[MTK_RSS_MAX_INDIRECTION_TABLE];
1358};
1359
developer18f46a82021-07-20 21:08:21 +08001360/* struct mtk_napi - This is the structure holding NAPI-related information,
1361 * and a mtk_napi struct is binding to one interrupt group
1362 * @napi: The NAPI struct
1363 * @rx_ring: Pointer to the memory holding info about the RX ring
1364 * @irq_grp_idx: The index indicates which interrupt group that this
1365 * mtk_napi is binding to
1366 */
1367struct mtk_napi {
1368 struct napi_struct napi;
1369 struct mtk_eth *eth;
1370 struct mtk_rx_ring *rx_ring;
1371 u32 irq_grp_no;
1372};
1373
developerfd40db22021-04-29 10:08:25 +08001374enum mkt_eth_capabilities {
1375 MTK_RGMII_BIT = 0,
1376 MTK_TRGMII_BIT,
1377 MTK_SGMII_BIT,
developer30e13e72022-11-03 10:21:24 +08001378 MTK_XGMII_BIT,
developer089e8852022-09-28 14:43:46 +08001379 MTK_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001380 MTK_ESW_BIT,
1381 MTK_GEPHY_BIT,
1382 MTK_MUX_BIT,
1383 MTK_INFRA_BIT,
1384 MTK_SHARED_SGMII_BIT,
1385 MTK_HWLRO_BIT,
developer18f46a82021-07-20 21:08:21 +08001386 MTK_RSS_BIT,
developerfd40db22021-04-29 10:08:25 +08001387 MTK_SHARED_INT_BIT,
1388 MTK_TRGMII_MT7621_CLK_BIT,
1389 MTK_QDMA_BIT,
developer089e8852022-09-28 14:43:46 +08001390 MTK_NETSYS_V1_BIT,
developera2bdbd52021-05-31 19:10:17 +08001391 MTK_NETSYS_V2_BIT,
developer8ecd51b2023-03-13 11:28:28 +08001392 MTK_NETSYS_RX_V2_BIT,
developer089e8852022-09-28 14:43:46 +08001393 MTK_NETSYS_V3_BIT,
developerfd40db22021-04-29 10:08:25 +08001394 MTK_SOC_MT7628_BIT,
developer545abf02021-07-15 17:47:01 +08001395 MTK_RSTCTRL_PPE1_BIT,
developer37482a42022-12-26 13:31:13 +08001396 MTK_RSTCTRL_PPE2_BIT,
developer255bba22021-07-27 15:16:33 +08001397 MTK_U3_COPHY_V2_BIT,
developer089e8852022-09-28 14:43:46 +08001398 MTK_8GB_ADDRESSING_BIT,
developerfd40db22021-04-29 10:08:25 +08001399
1400 /* MUX BITS*/
1401 MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
1402 MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
1403 MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
developer30e13e72022-11-03 10:21:24 +08001404 MTK_ETH_MUX_GMAC2_TO_XGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001405 MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
1406 MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
developer089e8852022-09-28 14:43:46 +08001407 MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT,
1408 MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001409
1410 /* PATH BITS */
1411 MTK_ETH_PATH_GMAC1_RGMII_BIT,
1412 MTK_ETH_PATH_GMAC1_TRGMII_BIT,
1413 MTK_ETH_PATH_GMAC1_SGMII_BIT,
1414 MTK_ETH_PATH_GMAC2_RGMII_BIT,
1415 MTK_ETH_PATH_GMAC2_SGMII_BIT,
developer30e13e72022-11-03 10:21:24 +08001416 MTK_ETH_PATH_GMAC2_XGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001417 MTK_ETH_PATH_GMAC2_GEPHY_BIT,
developer089e8852022-09-28 14:43:46 +08001418 MTK_ETH_PATH_GMAC3_SGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001419 MTK_ETH_PATH_GDM1_ESW_BIT,
developer089e8852022-09-28 14:43:46 +08001420 MTK_ETH_PATH_GMAC1_USXGMII_BIT,
1421 MTK_ETH_PATH_GMAC2_USXGMII_BIT,
1422 MTK_ETH_PATH_GMAC3_USXGMII_BIT,
developerfd40db22021-04-29 10:08:25 +08001423};
1424
1425/* Supported hardware group on SoCs */
developer425b23a2022-10-12 16:00:41 +08001426#define MTK_RGMII BIT_ULL(MTK_RGMII_BIT)
1427#define MTK_TRGMII BIT_ULL(MTK_TRGMII_BIT)
1428#define MTK_SGMII BIT_ULL(MTK_SGMII_BIT)
developer30e13e72022-11-03 10:21:24 +08001429#define MTK_XGMII BIT_ULL(MTK_XGMII_BIT)
developer425b23a2022-10-12 16:00:41 +08001430#define MTK_USXGMII BIT_ULL(MTK_USXGMII_BIT)
1431#define MTK_ESW BIT_ULL(MTK_ESW_BIT)
1432#define MTK_GEPHY BIT_ULL(MTK_GEPHY_BIT)
1433#define MTK_MUX BIT_ULL(MTK_MUX_BIT)
1434#define MTK_INFRA BIT_ULL(MTK_INFRA_BIT)
1435#define MTK_SHARED_SGMII BIT_ULL(MTK_SHARED_SGMII_BIT)
1436#define MTK_HWLRO BIT_ULL(MTK_HWLRO_BIT)
1437#define MTK_RSS BIT_ULL(MTK_RSS_BIT)
1438#define MTK_SHARED_INT BIT_ULL(MTK_SHARED_INT_BIT)
1439#define MTK_TRGMII_MT7621_CLK BIT_ULL(MTK_TRGMII_MT7621_CLK_BIT)
1440#define MTK_QDMA BIT_ULL(MTK_QDMA_BIT)
1441#define MTK_NETSYS_V1 BIT_ULL(MTK_NETSYS_V1_BIT)
1442#define MTK_NETSYS_V2 BIT_ULL(MTK_NETSYS_V2_BIT)
developer8ecd51b2023-03-13 11:28:28 +08001443#define MTK_NETSYS_RX_V2 BIT(MTK_NETSYS_RX_V2_BIT)
developer425b23a2022-10-12 16:00:41 +08001444#define MTK_NETSYS_V3 BIT_ULL(MTK_NETSYS_V3_BIT)
1445#define MTK_SOC_MT7628 BIT_ULL(MTK_SOC_MT7628_BIT)
1446#define MTK_RSTCTRL_PPE1 BIT_ULL(MTK_RSTCTRL_PPE1_BIT)
developer37482a42022-12-26 13:31:13 +08001447#define MTK_RSTCTRL_PPE2 BIT_ULL(MTK_RSTCTRL_PPE2_BIT)
developer425b23a2022-10-12 16:00:41 +08001448#define MTK_U3_COPHY_V2 BIT_ULL(MTK_U3_COPHY_V2_BIT)
1449#define MTK_8GB_ADDRESSING BIT_ULL(MTK_8GB_ADDRESSING_BIT)
developerfd40db22021-04-29 10:08:25 +08001450
1451#define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \
developer425b23a2022-10-12 16:00:41 +08001452 BIT_ULL(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
developerfd40db22021-04-29 10:08:25 +08001453#define MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY \
developer425b23a2022-10-12 16:00:41 +08001454 BIT_ULL(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
developerfd40db22021-04-29 10:08:25 +08001455#define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \
developer425b23a2022-10-12 16:00:41 +08001456 BIT_ULL(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
developer30e13e72022-11-03 10:21:24 +08001457#define MTK_ETH_MUX_GMAC2_TO_XGMII \
1458 BIT_ULL(MTK_ETH_MUX_GMAC2_TO_XGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001459#define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
developer425b23a2022-10-12 16:00:41 +08001460 BIT_ULL(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001461#define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \
developer425b23a2022-10-12 16:00:41 +08001462 BIT_ULL(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
developer089e8852022-09-28 14:43:46 +08001463#define MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII \
developer425b23a2022-10-12 16:00:41 +08001464 BIT_ULL(MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII_BIT)
developer089e8852022-09-28 14:43:46 +08001465#define MTK_ETH_MUX_GMAC123_TO_USXGMII \
developer425b23a2022-10-12 16:00:41 +08001466 BIT_ULL(MTK_ETH_MUX_GMAC123_TO_USXGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001467
1468/* Supported path present on SoCs */
developer425b23a2022-10-12 16:00:41 +08001469#define MTK_ETH_PATH_GMAC1_RGMII BIT_ULL(MTK_ETH_PATH_GMAC1_RGMII_BIT)
1470#define MTK_ETH_PATH_GMAC1_TRGMII BIT_ULL(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
1471#define MTK_ETH_PATH_GMAC1_SGMII BIT_ULL(MTK_ETH_PATH_GMAC1_SGMII_BIT)
1472#define MTK_ETH_PATH_GMAC2_RGMII BIT_ULL(MTK_ETH_PATH_GMAC2_RGMII_BIT)
1473#define MTK_ETH_PATH_GMAC2_SGMII BIT_ULL(MTK_ETH_PATH_GMAC2_SGMII_BIT)
developer30e13e72022-11-03 10:21:24 +08001474#define MTK_ETH_PATH_GMAC2_XGMII BIT_ULL(MTK_ETH_PATH_GMAC2_XGMII_BIT)
developer425b23a2022-10-12 16:00:41 +08001475#define MTK_ETH_PATH_GMAC2_GEPHY BIT_ULL(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
1476#define MTK_ETH_PATH_GMAC3_SGMII BIT_ULL(MTK_ETH_PATH_GMAC3_SGMII_BIT)
1477#define MTK_ETH_PATH_GDM1_ESW BIT_ULL(MTK_ETH_PATH_GDM1_ESW_BIT)
1478#define MTK_ETH_PATH_GMAC1_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC1_USXGMII_BIT)
1479#define MTK_ETH_PATH_GMAC2_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC2_USXGMII_BIT)
1480#define MTK_ETH_PATH_GMAC3_USXGMII BIT_ULL(MTK_ETH_PATH_GMAC3_USXGMII_BIT)
developerfd40db22021-04-29 10:08:25 +08001481
1482#define MTK_GMAC1_RGMII (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
1483#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
1484#define MTK_GMAC1_SGMII (MTK_ETH_PATH_GMAC1_SGMII | MTK_SGMII)
1485#define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
1486#define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
developer30e13e72022-11-03 10:21:24 +08001487#define MTK_GMAC2_XGMII (MTK_ETH_PATH_GMAC2_XGMII | MTK_XGMII)
developerfd40db22021-04-29 10:08:25 +08001488#define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
developer089e8852022-09-28 14:43:46 +08001489#define MTK_GMAC3_SGMII (MTK_ETH_PATH_GMAC3_SGMII | MTK_SGMII)
developerfd40db22021-04-29 10:08:25 +08001490#define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
developer089e8852022-09-28 14:43:46 +08001491#define MTK_GMAC1_USXGMII (MTK_ETH_PATH_GMAC1_USXGMII | MTK_USXGMII)
1492#define MTK_GMAC2_USXGMII (MTK_ETH_PATH_GMAC2_USXGMII | MTK_USXGMII)
1493#define MTK_GMAC3_USXGMII (MTK_ETH_PATH_GMAC3_USXGMII | MTK_USXGMII)
developerfd40db22021-04-29 10:08:25 +08001494
1495/* MUXes present on SoCs */
1496/* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
1497#define MTK_MUX_GDM1_TO_GMAC1_ESW (MTK_ETH_MUX_GDM1_TO_GMAC1_ESW | MTK_MUX)
1498
1499/* 0: GMAC2 -> GEPHY, 1: GMAC0 -> GePHY */
1500#define MTK_MUX_GMAC2_GMAC0_TO_GEPHY \
1501 (MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY | MTK_MUX | MTK_INFRA)
1502
1503/* 0: U3 -> QPHY, 1: GMAC2 -> QPHY */
1504#define MTK_MUX_U3_GMAC2_TO_QPHY \
1505 (MTK_ETH_MUX_U3_GMAC2_TO_QPHY | MTK_MUX | MTK_INFRA)
1506
1507/* 2: GMAC1 -> SGMII, 3: GMAC2 -> SGMII */
1508#define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \
1509 (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
1510 MTK_SHARED_SGMII)
1511
developer30e13e72022-11-03 10:21:24 +08001512/* 2: GMAC2 -> XGMII */
1513#define MTK_MUX_GMAC2_TO_XGMII \
1514 (MTK_ETH_MUX_GMAC2_TO_XGMII | MTK_MUX | MTK_INFRA)
1515
developerfd40db22021-04-29 10:08:25 +08001516/* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
1517#define MTK_MUX_GMAC12_TO_GEPHY_SGMII \
1518 (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
1519
developer089e8852022-09-28 14:43:46 +08001520#define MTK_MUX_GMAC123_TO_GEPHY_SGMII \
1521 (MTK_ETH_MUX_GMAC123_TO_GEPHY_SGMII | MTK_MUX)
1522
1523#define MTK_MUX_GMAC123_TO_USXGMII \
1524 (MTK_ETH_MUX_GMAC123_TO_USXGMII | MTK_MUX | MTK_INFRA)
1525
developerfd40db22021-04-29 10:08:25 +08001526#define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x))
1527
1528#define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
1529 MTK_GMAC2_RGMII | MTK_SHARED_INT | \
developer089e8852022-09-28 14:43:46 +08001530 MTK_TRGMII_MT7621_CLK | MTK_QDMA | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001531
1532#define MT7622_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_SGMII | MTK_GMAC2_RGMII | \
1533 MTK_GMAC2_SGMII | MTK_GDM1_ESW | \
developer089e8852022-09-28 14:43:46 +08001534 MTK_MUX_GDM1_TO_GMAC1_ESW | MTK_NETSYS_V1 | \
developerfd40db22021-04-29 10:08:25 +08001535 MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_QDMA)
1536
1537#define MT7623_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | MTK_GMAC2_RGMII | \
developer089e8852022-09-28 14:43:46 +08001538 MTK_QDMA | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001539
developer089e8852022-09-28 14:43:46 +08001540#define MT7628_CAPS (MTK_SHARED_INT | MTK_SOC_MT7628 | MTK_NETSYS_V1)
developerfd40db22021-04-29 10:08:25 +08001541
1542#define MT7629_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
1543 MTK_GDM1_ESW | MTK_MUX_GDM1_TO_GMAC1_ESW | \
1544 MTK_MUX_GMAC2_GMAC0_TO_GEPHY | \
developer089e8852022-09-28 14:43:46 +08001545 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_NETSYS_V1 | \
developerfd40db22021-04-29 10:08:25 +08001546 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA)
1547
developerfd40db22021-04-29 10:08:25 +08001548#define MT7986_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \
1549 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
developer8ecd51b2023-03-13 11:28:28 +08001550 MTK_NETSYS_V2)
developerfd40db22021-04-29 10:08:25 +08001551
developer255bba22021-07-27 15:16:33 +08001552#define MT7981_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
1553 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
1554 MTK_MUX_U3_GMAC2_TO_QPHY | MTK_U3_COPHY_V2 | \
1555 MTK_NETSYS_V2)
1556
developer089e8852022-09-28 14:43:46 +08001557#define MT7988_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC3_SGMII | \
1558 MTK_MUX_GMAC123_TO_GEPHY_SGMII | MTK_QDMA | \
developer37482a42022-12-26 13:31:13 +08001559 MTK_NETSYS_V3 | MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | \
developer089e8852022-09-28 14:43:46 +08001560 MTK_GMAC1_USXGMII | MTK_GMAC2_USXGMII | \
developer30e13e72022-11-03 10:21:24 +08001561 MTK_GMAC3_USXGMII | MTK_MUX_GMAC123_TO_USXGMII | \
developer8ecd51b2023-03-13 11:28:28 +08001562 MTK_GMAC2_XGMII | MTK_MUX_GMAC2_TO_XGMII | MTK_RSS | \
developerd0e67bd2023-06-14 11:34:36 +08001563 MTK_NETSYS_RX_V2 | MTK_8GB_ADDRESSING)
developer089e8852022-09-28 14:43:46 +08001564
developere9356982022-07-04 09:03:20 +08001565struct mtk_tx_dma_desc_info {
1566 dma_addr_t addr;
1567 u32 size;
1568 u16 vlan_tci;
1569 u16 qid;
1570 u8 gso:1;
1571 u8 csum:1;
1572 u8 vlan:1;
1573 u8 first:1;
1574 u8 last:1;
1575};
1576
developer68ce74f2023-01-03 16:11:57 +08001577struct mtk_reg_map {
1578 u32 tx_irq_mask;
1579 u32 tx_irq_status;
1580 struct {
1581 u32 rx_ptr; /* rx base pointer */
1582 u32 rx_cnt_cfg; /* rx max count configuration */
1583 u32 pcrx_ptr; /* rx cpu pointer */
1584 u32 glo_cfg; /* global configuration */
1585 u32 rst_idx; /* reset index */
1586 u32 delay_irq; /* delay interrupt */
1587 u32 irq_status; /* interrupt status */
1588 u32 irq_mask; /* interrupt mask */
1589 u32 int_grp; /* interrupt group1 */
1590 u32 int_grp2; /* interrupt group2 */
1591 } pdma;
1592 struct {
1593 u32 qtx_cfg; /* tx queue configuration */
1594 u32 qtx_sch; /* tx queue scheduler configuration */
1595 u32 rx_ptr; /* rx base pointer */
1596 u32 rx_cnt_cfg; /* rx max count configuration */
1597 u32 qcrx_ptr; /* rx cpu pointer */
1598 u32 glo_cfg; /* global configuration */
1599 u32 rst_idx; /* reset index */
1600 u32 delay_irq; /* delay interrupt */
1601 u32 fc_th; /* flow control */
1602 u32 int_grp; /* interrupt group1 */
1603 u32 int_grp2; /* interrupt group2 */
1604 u32 hred2; /* interrupt mask */
1605 u32 ctx_ptr; /* tx acquire cpu pointer */
1606 u32 dtx_ptr; /* tx acquire dma pointer */
1607 u32 crx_ptr; /* tx release cpu pointer */
1608 u32 drx_ptr; /* tx release dma pointer */
1609 u32 fq_head; /* fq head pointer */
1610 u32 fq_tail; /* fq tail pointer */
1611 u32 fq_count; /* fq free page count */
1612 u32 fq_blen; /* fq free page buffer length */
1613 u32 tx_sch_rate; /* tx scheduler rate control
1614 registers */
1615 } qdma;
1616 u32 gdm1_cnt;
1617 u32 gdma_to_ppe0;
1618 u32 ppe_base[3];
1619 u32 wdma_base[3];
1620};
1621
developerfd40db22021-04-29 10:08:25 +08001622/* struct mtk_eth_data - This is the structure holding all differences
1623 * among various plaforms
developer68ce74f2023-01-03 16:11:57 +08001624 * @reg_map Soc register map.
1625 * @ana_rgc3: The offset for register ANA_RGC3 related to
developerfd40db22021-04-29 10:08:25 +08001626 * sgmiisys syscon
1627 * @caps Flags shown the extra capability for the SoC
1628 * @hw_features Flags shown HW features
1629 * @required_clks Flags shown the bitmap for required clocks on
1630 * the target SoC
1631 * @required_pctl A bool value to show whether the SoC requires
1632 * the extra setup for those pins used by GMAC.
developere9356982022-07-04 09:03:20 +08001633 * @txd_size Tx DMA descriptor size.
1634 * @rxd_size Rx DMA descriptor size.
developer68ce74f2023-01-03 16:11:57 +08001635 * @rx_dma_l4_valid Rx DMA valid register mask.
developere9356982022-07-04 09:03:20 +08001636 * @dma_max_len Max DMA tx/rx buffer length.
1637 * @dma_len_offset Tx/Rx DMA length field offset.
developerfd40db22021-04-29 10:08:25 +08001638 */
1639struct mtk_soc_data {
developer68ce74f2023-01-03 16:11:57 +08001640 const struct mtk_reg_map *reg_map;
1641 u32 ana_rgc3;
developere3d0de22023-05-30 17:45:00 +08001642 u32 rss_num;
developer089e8852022-09-28 14:43:46 +08001643 u64 caps;
developer5cfc67a2022-12-29 19:06:51 +08001644 u64 required_clks;
developerfd40db22021-04-29 10:08:25 +08001645 bool required_pctl;
1646 netdev_features_t hw_features;
1647 bool has_sram;
developere9356982022-07-04 09:03:20 +08001648 struct {
1649 u32 txd_size;
1650 u32 rxd_size;
developer68ce74f2023-01-03 16:11:57 +08001651 u32 rx_dma_l4_valid;
developere9356982022-07-04 09:03:20 +08001652 u32 dma_max_len;
1653 u32 dma_len_offset;
1654 } txrx;
developerfd40db22021-04-29 10:08:25 +08001655};
1656
developer089e8852022-09-28 14:43:46 +08001657/* currently no SoC has more than 3 macs */
1658#if defined(CONFIG_MEDIATEK_NETSYS_V3)
1659#define MTK_MAX_DEVS 3
1660#else
1661#define MTK_MAX_DEVS 2
1662#endif
developerfd40db22021-04-29 10:08:25 +08001663
1664#define MTK_SGMII_PHYSPEED_AN BIT(31)
1665#define MTK_SGMII_PHYSPEED_MASK GENMASK(2, 0)
1666#define MTK_SGMII_PHYSPEED_1000 BIT(0)
1667#define MTK_SGMII_PHYSPEED_2500 BIT(1)
developer089e8852022-09-28 14:43:46 +08001668#define MTK_SGMII_PHYSPEED_5000 BIT(2)
1669#define MTK_SGMII_PHYSPEED_10000 BIT(3)
developerf8ac94a2021-07-29 16:40:01 +08001670#define MTK_SGMII_PN_SWAP BIT(16)
developerfd40db22021-04-29 10:08:25 +08001671#define MTK_HAS_FLAGS(flags, _x) (((flags) & (_x)) == (_x))
1672
developer4e8a3fd2023-04-10 18:05:44 +08001673/* struct mtk_sgmii_pcs - This structure holds each sgmii regmap and associated
1674 * data
1675 * @regmap: The register map pointing at the range used to setup
1676 * SGMII modes
1677 * @regmap_pextp: The register map pointing at the range used to setup
1678 * PHYA
1679 * @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap
1680 * @id: The element is used to record the index of PCS
1681 * @pcs: Phylink PCS structure
developerfd40db22021-04-29 10:08:25 +08001682 */
developer4e8a3fd2023-04-10 18:05:44 +08001683struct mtk_sgmii_pcs {
1684 struct mtk_eth *eth;
1685 struct regmap *regmap;
1686 struct regmap *regmap_pextp;
1687 phy_interface_t interface;
1688 u32 flags;
1689 u32 ana_rgc3;
1690 u8 id;
1691 struct phylink_pcs pcs;
1692};
developerfd40db22021-04-29 10:08:25 +08001693
developer4e8a3fd2023-04-10 18:05:44 +08001694/* struct mtk_sgmii - This is the structure holding sgmii regmap and its
1695 * characteristics
1696 * @pll: The register map pointing at the range used to setup
1697 * PLL
1698 * @pcs Array of individual PCS structures
1699 */
1700struct mtk_sgmii {
1701 struct mtk_sgmii_pcs pcs[MTK_MAX_DEVS];
1702 struct regmap *pll;
developerfd40db22021-04-29 10:08:25 +08001703};
1704
developer4e8a3fd2023-04-10 18:05:44 +08001705/* struct mtk_usxgmii_pcs - This structure holds each usxgmii regmap and
1706 * associated data
1707 * @regmap: The register map pointing at the range used to setup
1708 * USXGMII modes
1709 * @regmap_pextp: The register map pointing at the range used to setup
1710 * PHYA
1711 * @id: The element is used to record the index of PCS
1712 * @pcs: Phylink PCS structure
1713 */
1714struct mtk_usxgmii_pcs {
1715 struct mtk_eth *eth;
1716 struct regmap *regmap;
1717 struct regmap *regmap_pextp;
1718 phy_interface_t interface;
1719 u8 id;
1720 struct phylink_pcs pcs;
1721};
1722
1723/* struct mtk_usxgmii - This is the structure holding usxgmii regmap and its
1724 * characteristics
1725 * @pll: The register map pointing at the range used to setup
1726 * PLL
1727 * @pcs Array of individual PCS structures
1728 */
1729struct mtk_usxgmii {
1730 struct mtk_usxgmii_pcs pcs[MTK_MAX_DEVS];
1731 struct regmap *pll;
1732};
developer8051e042022-04-08 13:26:36 +08001733
1734/* struct mtk_reset_event - This is the structure holding statistics counters
1735 * for reset events
1736 * @count: The counter is used to record the number of events
1737 */
1738struct mtk_reset_event {
1739 u32 count[32];
1740};
1741
developera2613e62022-07-01 18:29:37 +08001742/* struct mtk_phylink_priv - This is the structure holding private data for phylink
1743 * @desc: Pointer to the memory holding info about the phylink gpio
1744 * @id: The element is used to record the phy index of phylink
1745 * @phyaddr: The element is used to record the phy address of phylink
1746 * @link: The element is used to record the phy link status of phylink
1747 */
1748struct mtk_phylink_priv {
1749 struct net_device *dev;
1750 struct gpio_desc *desc;
1751 char label[16];
1752 int id;
1753 int phyaddr;
1754 int link;
1755};
1756
developerfd40db22021-04-29 10:08:25 +08001757/* struct mtk_eth - This is the main datasructure for holding the state
1758 * of the driver
1759 * @dev: The device pointer
developer3f28d382023-03-07 16:06:30 +08001760 * @dma_dev: The device pointer used for dma mapping/alloc
developerfd40db22021-04-29 10:08:25 +08001761 * @base: The mapped register i/o base
1762 * @page_lock: Make sure that register operations are atomic
1763 * @tx_irq__lock: Make sure that IRQ register operations are atomic
1764 * @rx_irq__lock: Make sure that IRQ register operations are atomic
1765 * @dummy_dev: we run 2 netdevs on 1 physical DMA ring and need a
1766 * dummy for NAPI to work
1767 * @netdev: The netdev instances
1768 * @mac: Each netdev is linked to a physical MAC
1769 * @irq: The IRQ that we are using
1770 * @msg_enable: Ethtool msg level
1771 * @ethsys: The register map pointing at the range used to setup
1772 * MII modes
1773 * @infra: The register map pointing at the range used to setup
1774 * SGMII and GePHY path
1775 * @pctl: The register map pointing at the range used to setup
1776 * GMAC port drive/slew values
1777 * @dma_refcnt: track how many netdevs are using the DMA engine
1778 * @tx_ring: Pointer to the memory holding info about the TX ring
1779 * @rx_ring: Pointer to the memory holding info about the RX ring
1780 * @rx_ring_qdma: Pointer to the memory holding info about the QDMA RX ring
1781 * @tx_napi: The TX NAPI struct
1782 * @rx_napi: The RX NAPI struct
1783 * @scratch_ring: Newer SoCs need memory for a second HW managed TX ring
1784 * @phy_scratch_ring: physical address of scratch_ring
1785 * @scratch_head: The scratch memory that scratch_ring points to.
1786 * @clks: clock array for all clocks required
1787 * @mii_bus: If there is a bus we need to create an instance for it
1788 * @pending_work: The workqueue used to reset the dma ring
1789 * @state: Initialization and runtime state of the device
1790 * @soc: Holding specific data among vaious SoCs
1791 */
1792
1793struct mtk_eth {
1794 struct device *dev;
developer3f28d382023-03-07 16:06:30 +08001795 struct device *dma_dev;
developerfd40db22021-04-29 10:08:25 +08001796 void __iomem *base;
developer089e8852022-09-28 14:43:46 +08001797 void __iomem *sram_base;
developerfd40db22021-04-29 10:08:25 +08001798 spinlock_t page_lock;
1799 spinlock_t tx_irq_lock;
1800 spinlock_t rx_irq_lock;
1801 struct net_device dummy_dev;
1802 struct net_device *netdev[MTK_MAX_DEVS];
1803 struct mtk_mac *mac[MTK_MAX_DEVS];
developer94806ec2023-05-19 14:16:44 +08001804 int irq_fe[MTK_FE_IRQ_NUM];
1805 int irq_pdma[MTK_PDMA_IRQ_NUM];
developer0fef5222023-04-26 14:48:31 +08001806 u8 hwver;
developerfd40db22021-04-29 10:08:25 +08001807 u32 msg_enable;
1808 unsigned long sysclk;
1809 struct regmap *ethsys;
1810 struct regmap *infra;
developer089e8852022-09-28 14:43:46 +08001811 struct regmap *toprgu;
developer4e8a3fd2023-04-10 18:05:44 +08001812 struct mtk_sgmii *sgmii;
1813 struct mtk_usxgmii *usxgmii;
developerfd40db22021-04-29 10:08:25 +08001814 struct regmap *pctl;
1815 bool hwlro;
1816 refcount_t dma_refcnt;
1817 struct mtk_tx_ring tx_ring;
1818 struct mtk_rx_ring rx_ring[MTK_MAX_RX_RING_NUM];
1819 struct mtk_rx_ring rx_ring_qdma;
1820 struct napi_struct tx_napi;
developer18f46a82021-07-20 21:08:21 +08001821 struct mtk_napi rx_napi[MTK_RX_NAPI_NUM];
developerea49c302023-06-27 16:06:41 +08001822 struct mtk_rss_params rss_params;
developere9356982022-07-04 09:03:20 +08001823 void *scratch_ring;
developer8051e042022-04-08 13:26:36 +08001824 struct mtk_reset_event reset_event;
developerfd40db22021-04-29 10:08:25 +08001825 dma_addr_t phy_scratch_ring;
1826 void *scratch_head;
1827 struct clk *clks[MTK_CLK_MAX];
1828
1829 struct mii_bus *mii_bus;
1830 struct work_struct pending_work;
1831 unsigned long state;
1832
1833 const struct mtk_soc_data *soc;
1834
developerfd40db22021-04-29 10:08:25 +08001835 u32 rx_dma_l4_valid;
1836 int ip_align;
developerd82e8372022-02-09 15:00:09 +08001837 spinlock_t syscfg0_lock;
developer8051e042022-04-08 13:26:36 +08001838 struct timer_list mtk_dma_monitor_timer;
developerfd40db22021-04-29 10:08:25 +08001839};
1840
1841/* struct mtk_mac - the structure that holds the info about the MACs of the
1842 * SoC
1843 * @id: The number of the MAC
1844 * @interface: Interface mode kept for detecting change in hw settings
1845 * @of_node: Our devicetree node
1846 * @hw: Backpointer to our main datastruture
1847 * @hw_stats: Packet statistics counter
1848 */
1849struct mtk_mac {
developerfb556ca2021-10-13 10:52:09 +08001850 unsigned int id;
developerfd40db22021-04-29 10:08:25 +08001851 phy_interface_t interface;
1852 unsigned int mode;
developer089e8852022-09-28 14:43:46 +08001853 unsigned int type;
developerfd40db22021-04-29 10:08:25 +08001854 int speed;
1855 struct device_node *of_node;
1856 struct phylink *phylink;
1857 struct phylink_config phylink_config;
developera2613e62022-07-01 18:29:37 +08001858 struct mtk_phylink_priv phylink_priv;
developerfd40db22021-04-29 10:08:25 +08001859 struct mtk_eth *hw;
1860 struct mtk_hw_stats *hw_stats;
1861 __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT];
1862 int hwlro_ip_cnt;
developer4e8a3fd2023-04-10 18:05:44 +08001863 unsigned int syscfg0;
developer9b725932022-11-24 16:25:56 +08001864 bool tx_lpi_enabled;
1865 u32 tx_lpi_timer;
developerfd40db22021-04-29 10:08:25 +08001866};
1867
1868/* the struct describing the SoC. these are declared in the soc_xyz.c files */
developer7cd7e5e2022-11-17 13:57:32 +08001869extern struct mtk_eth *g_eth;
developerfd40db22021-04-29 10:08:25 +08001870extern const struct of_device_id of_mtk_match[];
developer77d03a72021-06-06 00:06:00 +08001871extern u32 mtk_hwlro_stats_ebl;
developer7979ddb2023-04-24 17:19:21 +08001872extern u32 dbg_show_level;
developerfd40db22021-04-29 10:08:25 +08001873
1874/* read the hardware status register */
1875void mtk_stats_update_mac(struct mtk_mac *mac);
1876
1877void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
1878u32 mtk_r32(struct mtk_eth *eth, unsigned reg);
developer8051e042022-04-08 13:26:36 +08001879u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned reg);
developerfd40db22021-04-29 10:08:25 +08001880
developer4e8a3fd2023-04-10 18:05:44 +08001881struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id);
1882int mtk_sgmii_init(struct mtk_eth *eth, struct device_node *np,
developerfd40db22021-04-29 10:08:25 +08001883 u32 ana_rgc3);
developerfd40db22021-04-29 10:08:25 +08001884
1885int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
developer30e13e72022-11-03 10:21:24 +08001886int mtk_gmac_xgmii_path_setup(struct mtk_eth *eth, int mac_id);
developerfd40db22021-04-29 10:08:25 +08001887int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
1888int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
developer089e8852022-09-28 14:43:46 +08001889int mtk_gmac_usxgmii_path_setup(struct mtk_eth *eth, int mac_id);
developerdca0fde2022-12-14 11:40:35 +08001890void mtk_gdm_config(struct mtk_eth *eth, u32 id, u32 config);
developer8051e042022-04-08 13:26:36 +08001891void ethsys_reset(struct mtk_eth *eth, u32 reset_bits);
developerfd40db22021-04-29 10:08:25 +08001892
developer089e8852022-09-28 14:43:46 +08001893int mtk_mac2xgmii_id(struct mtk_eth *eth, int mac_id);
developer4e8a3fd2023-04-10 18:05:44 +08001894struct phylink_pcs *mtk_usxgmii_select_pcs(struct mtk_usxgmii *ss, int id);
1895int mtk_usxgmii_init(struct mtk_eth *eth, struct device_node *r);
developer089e8852022-09-28 14:43:46 +08001896int mtk_toprgu_init(struct mtk_eth *eth, struct device_node *r);
developer0baa6962023-01-31 14:25:23 +08001897int mtk_dump_usxgmii(struct regmap *pmap, char *name, u32 offset, u32 range);
developer3f28d382023-03-07 16:06:30 +08001898
1899void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
developerea49c302023-06-27 16:06:41 +08001900u32 mtk_rss_indr_table(struct mtk_rss_params *rss_params, int index);
developerfd40db22021-04-29 10:08:25 +08001901#endif /* MTK_ETH_H */