xref: /linux/drivers/net/ethernet/mediatek/airoha_eth.c (revision 6e7fd890f1d6ac83805409e9c346240de2705584)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2024 AIROHA Inc
4  * Author: Lorenzo Bianconi <lorenzo@kernel.org>
5  */
6 #include <linux/etherdevice.h>
7 #include <linux/iopoll.h>
8 #include <linux/kernel.h>
9 #include <linux/netdevice.h>
10 #include <linux/of.h>
11 #include <linux/of_net.h>
12 #include <linux/platform_device.h>
13 #include <linux/reset.h>
14 #include <linux/tcp.h>
15 #include <linux/u64_stats_sync.h>
16 #include <net/dsa.h>
17 #include <net/page_pool/helpers.h>
18 #include <uapi/linux/ppp_defs.h>
19 
20 #define AIROHA_MAX_NUM_GDM_PORTS	1
21 #define AIROHA_MAX_NUM_RSTS		3
22 #define AIROHA_MAX_NUM_XSI_RSTS		5
23 #define AIROHA_MAX_MTU			2000
24 #define AIROHA_MAX_PACKET_SIZE		2048
25 #define AIROHA_NUM_TX_RING		32
26 #define AIROHA_NUM_RX_RING		32
27 #define AIROHA_FE_MC_MAX_VLAN_TABLE	64
28 #define AIROHA_FE_MC_MAX_VLAN_PORT	16
29 #define AIROHA_NUM_TX_IRQ		2
30 #define HW_DSCP_NUM			2048
31 #define IRQ_QUEUE_LEN(_n)		((_n) ? 1024 : 2048)
32 #define TX_DSCP_NUM			1024
33 #define RX_DSCP_NUM(_n)			\
34 	((_n) ==  2 ? 128 :		\
35 	 (_n) == 11 ? 128 :		\
36 	 (_n) == 15 ? 128 :		\
37 	 (_n) ==  0 ? 1024 : 16)
38 
39 #define PSE_RSV_PAGES			128
40 #define PSE_QUEUE_RSV_PAGES		64
41 
42 /* FE */
43 #define PSE_BASE			0x0100
44 #define CSR_IFC_BASE			0x0200
45 #define CDM1_BASE			0x0400
46 #define GDM1_BASE			0x0500
47 #define PPE1_BASE			0x0c00
48 
49 #define CDM2_BASE			0x1400
50 #define GDM2_BASE			0x1500
51 
52 #define GDM3_BASE			0x1100
53 #define GDM4_BASE			0x2500
54 
55 #define GDM_BASE(_n)			\
56 	((_n) == 4 ? GDM4_BASE :	\
57 	 (_n) == 3 ? GDM3_BASE :	\
58 	 (_n) == 2 ? GDM2_BASE : GDM1_BASE)
59 
60 #define REG_FE_DMA_GLO_CFG		0x0000
61 #define FE_DMA_GLO_L2_SPACE_MASK	GENMASK(7, 4)
62 #define FE_DMA_GLO_PG_SZ_MASK		BIT(3)
63 
64 #define REG_FE_RST_GLO_CFG		0x0004
65 #define FE_RST_GDM4_MBI_ARB_MASK	BIT(3)
66 #define FE_RST_GDM3_MBI_ARB_MASK	BIT(2)
67 #define FE_RST_CORE_MASK		BIT(0)
68 
69 #define REG_FE_LAN_MAC_H		0x0040
70 #define REG_FE_LAN_MAC_LMIN		0x0044
71 #define REG_FE_LAN_MAC_LMAX		0x0048
72 
73 #define REG_FE_CDM1_OQ_MAP0		0x0050
74 #define REG_FE_CDM1_OQ_MAP1		0x0054
75 #define REG_FE_CDM1_OQ_MAP2		0x0058
76 #define REG_FE_CDM1_OQ_MAP3		0x005c
77 
78 #define REG_FE_PCE_CFG			0x0070
79 #define PCE_DPI_EN_MASK			BIT(2)
80 #define PCE_KA_EN_MASK			BIT(1)
81 #define PCE_MC_EN_MASK			BIT(0)
82 
83 #define REG_FE_PSE_QUEUE_CFG_WR		0x0080
84 #define PSE_CFG_PORT_ID_MASK		GENMASK(27, 24)
85 #define PSE_CFG_QUEUE_ID_MASK		GENMASK(20, 16)
86 #define PSE_CFG_WR_EN_MASK		BIT(8)
87 #define PSE_CFG_OQRSV_SEL_MASK		BIT(0)
88 
89 #define REG_FE_PSE_QUEUE_CFG_VAL	0x0084
90 #define PSE_CFG_OQ_RSV_MASK		GENMASK(13, 0)
91 
92 #define PSE_FQ_CFG			0x008c
93 #define PSE_FQ_LIMIT_MASK		GENMASK(14, 0)
94 
95 #define REG_FE_PSE_BUF_SET		0x0090
96 #define PSE_SHARE_USED_LTHD_MASK	GENMASK(31, 16)
97 #define PSE_ALLRSV_MASK			GENMASK(14, 0)
98 
99 #define REG_PSE_SHARE_USED_THD		0x0094
100 #define PSE_SHARE_USED_MTHD_MASK	GENMASK(31, 16)
101 #define PSE_SHARE_USED_HTHD_MASK	GENMASK(15, 0)
102 
103 #define REG_GDM_MISC_CFG		0x0148
104 #define GDM2_RDM_ACK_WAIT_PREF_MASK	BIT(9)
105 #define GDM2_CHN_VLD_MODE_MASK		BIT(5)
106 
107 #define REG_FE_CSR_IFC_CFG		CSR_IFC_BASE
108 #define FE_IFC_EN_MASK			BIT(0)
109 
110 #define REG_FE_VIP_PORT_EN		0x01f0
111 #define REG_FE_IFC_PORT_EN		0x01f4
112 
113 #define REG_PSE_IQ_REV1			(PSE_BASE + 0x08)
114 #define PSE_IQ_RES1_P2_MASK		GENMASK(23, 16)
115 
116 #define REG_PSE_IQ_REV2			(PSE_BASE + 0x0c)
117 #define PSE_IQ_RES2_P5_MASK		GENMASK(15, 8)
118 #define PSE_IQ_RES2_P4_MASK		GENMASK(7, 0)
119 
120 #define REG_FE_VIP_EN(_n)		(0x0300 + ((_n) << 3))
121 #define PATN_FCPU_EN_MASK		BIT(7)
122 #define PATN_SWP_EN_MASK		BIT(6)
123 #define PATN_DP_EN_MASK			BIT(5)
124 #define PATN_SP_EN_MASK			BIT(4)
125 #define PATN_TYPE_MASK			GENMASK(3, 1)
126 #define PATN_EN_MASK			BIT(0)
127 
128 #define REG_FE_VIP_PATN(_n)		(0x0304 + ((_n) << 3))
129 #define PATN_DP_MASK			GENMASK(31, 16)
130 #define PATN_SP_MASK			GENMASK(15, 0)
131 
132 #define REG_CDM1_VLAN_CTRL		CDM1_BASE
133 #define CDM1_VLAN_MASK			GENMASK(31, 16)
134 
135 #define REG_CDM1_FWD_CFG		(CDM1_BASE + 0x08)
136 #define CDM1_VIP_QSEL_MASK		GENMASK(24, 20)
137 
138 #define REG_CDM1_CRSN_QSEL(_n)		(CDM1_BASE + 0x10 + ((_n) << 2))
139 #define CDM1_CRSN_QSEL_REASON_MASK(_n)	\
140 	GENMASK(4 + (((_n) % 4) << 3),	(((_n) % 4) << 3))
141 
142 #define REG_CDM2_FWD_CFG		(CDM2_BASE + 0x08)
143 #define CDM2_OAM_QSEL_MASK		GENMASK(31, 27)
144 #define CDM2_VIP_QSEL_MASK		GENMASK(24, 20)
145 
146 #define REG_CDM2_CRSN_QSEL(_n)		(CDM2_BASE + 0x10 + ((_n) << 2))
147 #define CDM2_CRSN_QSEL_REASON_MASK(_n)	\
148 	GENMASK(4 + (((_n) % 4) << 3),	(((_n) % 4) << 3))
149 
150 #define REG_GDM_FWD_CFG(_n)		GDM_BASE(_n)
151 #define GDM_DROP_CRC_ERR		BIT(23)
152 #define GDM_IP4_CKSUM			BIT(22)
153 #define GDM_TCP_CKSUM			BIT(21)
154 #define GDM_UDP_CKSUM			BIT(20)
155 #define GDM_UCFQ_MASK			GENMASK(15, 12)
156 #define GDM_BCFQ_MASK			GENMASK(11, 8)
157 #define GDM_MCFQ_MASK			GENMASK(7, 4)
158 #define GDM_OCFQ_MASK			GENMASK(3, 0)
159 
160 #define REG_GDM_INGRESS_CFG(_n)		(GDM_BASE(_n) + 0x10)
161 #define GDM_INGRESS_FC_EN_MASK		BIT(1)
162 #define GDM_STAG_EN_MASK		BIT(0)
163 
164 #define REG_GDM_LEN_CFG(_n)		(GDM_BASE(_n) + 0x14)
165 #define GDM_SHORT_LEN_MASK		GENMASK(13, 0)
166 #define GDM_LONG_LEN_MASK		GENMASK(29, 16)
167 
168 #define REG_FE_CPORT_CFG		(GDM1_BASE + 0x40)
169 #define FE_CPORT_PAD			BIT(26)
170 #define FE_CPORT_PORT_XFC_MASK		BIT(25)
171 #define FE_CPORT_QUEUE_XFC_MASK		BIT(24)
172 
173 #define REG_FE_GDM_MIB_CLEAR(_n)	(GDM_BASE(_n) + 0xf0)
174 #define FE_GDM_MIB_RX_CLEAR_MASK	BIT(1)
175 #define FE_GDM_MIB_TX_CLEAR_MASK	BIT(0)
176 
177 #define REG_FE_GDM1_MIB_CFG		(GDM1_BASE + 0xf4)
178 #define FE_STRICT_RFC2819_MODE_MASK	BIT(31)
179 #define FE_GDM1_TX_MIB_SPLIT_EN_MASK	BIT(17)
180 #define FE_GDM1_RX_MIB_SPLIT_EN_MASK	BIT(16)
181 #define FE_TX_MIB_ID_MASK		GENMASK(15, 8)
182 #define FE_RX_MIB_ID_MASK		GENMASK(7, 0)
183 
184 #define REG_FE_GDM_TX_OK_PKT_CNT_L(_n)		(GDM_BASE(_n) + 0x104)
185 #define REG_FE_GDM_TX_OK_BYTE_CNT_L(_n)		(GDM_BASE(_n) + 0x10c)
186 #define REG_FE_GDM_TX_ETH_PKT_CNT_L(_n)		(GDM_BASE(_n) + 0x110)
187 #define REG_FE_GDM_TX_ETH_BYTE_CNT_L(_n)	(GDM_BASE(_n) + 0x114)
188 #define REG_FE_GDM_TX_ETH_DROP_CNT(_n)		(GDM_BASE(_n) + 0x118)
189 #define REG_FE_GDM_TX_ETH_BC_CNT(_n)		(GDM_BASE(_n) + 0x11c)
190 #define REG_FE_GDM_TX_ETH_MC_CNT(_n)		(GDM_BASE(_n) + 0x120)
191 #define REG_FE_GDM_TX_ETH_RUNT_CNT(_n)		(GDM_BASE(_n) + 0x124)
192 #define REG_FE_GDM_TX_ETH_LONG_CNT(_n)		(GDM_BASE(_n) + 0x128)
193 #define REG_FE_GDM_TX_ETH_E64_CNT_L(_n)		(GDM_BASE(_n) + 0x12c)
194 #define REG_FE_GDM_TX_ETH_L64_CNT_L(_n)		(GDM_BASE(_n) + 0x130)
195 #define REG_FE_GDM_TX_ETH_L127_CNT_L(_n)	(GDM_BASE(_n) + 0x134)
196 #define REG_FE_GDM_TX_ETH_L255_CNT_L(_n)	(GDM_BASE(_n) + 0x138)
197 #define REG_FE_GDM_TX_ETH_L511_CNT_L(_n)	(GDM_BASE(_n) + 0x13c)
198 #define REG_FE_GDM_TX_ETH_L1023_CNT_L(_n)	(GDM_BASE(_n) + 0x140)
199 
200 #define REG_FE_GDM_RX_OK_PKT_CNT_L(_n)		(GDM_BASE(_n) + 0x148)
201 #define REG_FE_GDM_RX_FC_DROP_CNT(_n)		(GDM_BASE(_n) + 0x14c)
202 #define REG_FE_GDM_RX_RC_DROP_CNT(_n)		(GDM_BASE(_n) + 0x150)
203 #define REG_FE_GDM_RX_OVERFLOW_DROP_CNT(_n)	(GDM_BASE(_n) + 0x154)
204 #define REG_FE_GDM_RX_ERROR_DROP_CNT(_n)	(GDM_BASE(_n) + 0x158)
205 #define REG_FE_GDM_RX_OK_BYTE_CNT_L(_n)		(GDM_BASE(_n) + 0x15c)
206 #define REG_FE_GDM_RX_ETH_PKT_CNT_L(_n)		(GDM_BASE(_n) + 0x160)
207 #define REG_FE_GDM_RX_ETH_BYTE_CNT_L(_n)	(GDM_BASE(_n) + 0x164)
208 #define REG_FE_GDM_RX_ETH_DROP_CNT(_n)		(GDM_BASE(_n) + 0x168)
209 #define REG_FE_GDM_RX_ETH_BC_CNT(_n)		(GDM_BASE(_n) + 0x16c)
210 #define REG_FE_GDM_RX_ETH_MC_CNT(_n)		(GDM_BASE(_n) + 0x170)
211 #define REG_FE_GDM_RX_ETH_CRC_ERR_CNT(_n)	(GDM_BASE(_n) + 0x174)
212 #define REG_FE_GDM_RX_ETH_FRAG_CNT(_n)		(GDM_BASE(_n) + 0x178)
213 #define REG_FE_GDM_RX_ETH_JABBER_CNT(_n)	(GDM_BASE(_n) + 0x17c)
214 #define REG_FE_GDM_RX_ETH_RUNT_CNT(_n)		(GDM_BASE(_n) + 0x180)
215 #define REG_FE_GDM_RX_ETH_LONG_CNT(_n)		(GDM_BASE(_n) + 0x184)
216 #define REG_FE_GDM_RX_ETH_E64_CNT_L(_n)		(GDM_BASE(_n) + 0x188)
217 #define REG_FE_GDM_RX_ETH_L64_CNT_L(_n)		(GDM_BASE(_n) + 0x18c)
218 #define REG_FE_GDM_RX_ETH_L127_CNT_L(_n)	(GDM_BASE(_n) + 0x190)
219 #define REG_FE_GDM_RX_ETH_L255_CNT_L(_n)	(GDM_BASE(_n) + 0x194)
220 #define REG_FE_GDM_RX_ETH_L511_CNT_L(_n)	(GDM_BASE(_n) + 0x198)
221 #define REG_FE_GDM_RX_ETH_L1023_CNT_L(_n)	(GDM_BASE(_n) + 0x19c)
222 
223 #define REG_PPE1_TB_HASH_CFG		(PPE1_BASE + 0x250)
224 #define PPE1_SRAM_TABLE_EN_MASK		BIT(0)
225 #define PPE1_SRAM_HASH1_EN_MASK		BIT(8)
226 #define PPE1_DRAM_TABLE_EN_MASK		BIT(16)
227 #define PPE1_DRAM_HASH1_EN_MASK		BIT(24)
228 
229 #define REG_FE_GDM_TX_OK_PKT_CNT_H(_n)		(GDM_BASE(_n) + 0x280)
230 #define REG_FE_GDM_TX_OK_BYTE_CNT_H(_n)		(GDM_BASE(_n) + 0x284)
231 #define REG_FE_GDM_TX_ETH_PKT_CNT_H(_n)		(GDM_BASE(_n) + 0x288)
232 #define REG_FE_GDM_TX_ETH_BYTE_CNT_H(_n)	(GDM_BASE(_n) + 0x28c)
233 
234 #define REG_FE_GDM_RX_OK_PKT_CNT_H(_n)		(GDM_BASE(_n) + 0x290)
235 #define REG_FE_GDM_RX_OK_BYTE_CNT_H(_n)		(GDM_BASE(_n) + 0x294)
236 #define REG_FE_GDM_RX_ETH_PKT_CNT_H(_n)		(GDM_BASE(_n) + 0x298)
237 #define REG_FE_GDM_RX_ETH_BYTE_CNT_H(_n)	(GDM_BASE(_n) + 0x29c)
238 #define REG_FE_GDM_TX_ETH_E64_CNT_H(_n)		(GDM_BASE(_n) + 0x2b8)
239 #define REG_FE_GDM_TX_ETH_L64_CNT_H(_n)		(GDM_BASE(_n) + 0x2bc)
240 #define REG_FE_GDM_TX_ETH_L127_CNT_H(_n)	(GDM_BASE(_n) + 0x2c0)
241 #define REG_FE_GDM_TX_ETH_L255_CNT_H(_n)	(GDM_BASE(_n) + 0x2c4)
242 #define REG_FE_GDM_TX_ETH_L511_CNT_H(_n)	(GDM_BASE(_n) + 0x2c8)
243 #define REG_FE_GDM_TX_ETH_L1023_CNT_H(_n)	(GDM_BASE(_n) + 0x2cc)
244 #define REG_FE_GDM_RX_ETH_E64_CNT_H(_n)		(GDM_BASE(_n) + 0x2e8)
245 #define REG_FE_GDM_RX_ETH_L64_CNT_H(_n)		(GDM_BASE(_n) + 0x2ec)
246 #define REG_FE_GDM_RX_ETH_L127_CNT_H(_n)	(GDM_BASE(_n) + 0x2f0)
247 #define REG_FE_GDM_RX_ETH_L255_CNT_H(_n)	(GDM_BASE(_n) + 0x2f4)
248 #define REG_FE_GDM_RX_ETH_L511_CNT_H(_n)	(GDM_BASE(_n) + 0x2f8)
249 #define REG_FE_GDM_RX_ETH_L1023_CNT_H(_n)	(GDM_BASE(_n) + 0x2fc)
250 
251 #define REG_GDM2_CHN_RLS		(GDM2_BASE + 0x20)
252 #define MBI_RX_AGE_SEL_MASK		GENMASK(26, 25)
253 #define MBI_TX_AGE_SEL_MASK		GENMASK(18, 17)
254 
255 #define REG_GDM3_FWD_CFG		GDM3_BASE
256 #define GDM3_PAD_EN_MASK		BIT(28)
257 
258 #define REG_GDM4_FWD_CFG		(GDM4_BASE + 0x100)
259 #define GDM4_PAD_EN_MASK		BIT(28)
260 #define GDM4_SPORT_OFFSET0_MASK		GENMASK(11, 8)
261 
262 #define REG_GDM4_SRC_PORT_SET		(GDM4_BASE + 0x33c)
263 #define GDM4_SPORT_OFF2_MASK		GENMASK(19, 16)
264 #define GDM4_SPORT_OFF1_MASK		GENMASK(15, 12)
265 #define GDM4_SPORT_OFF0_MASK		GENMASK(11, 8)
266 
267 #define REG_IP_FRAG_FP			0x2010
268 #define IP_ASSEMBLE_PORT_MASK		GENMASK(24, 21)
269 #define IP_ASSEMBLE_NBQ_MASK		GENMASK(20, 16)
270 #define IP_FRAGMENT_PORT_MASK		GENMASK(8, 5)
271 #define IP_FRAGMENT_NBQ_MASK		GENMASK(4, 0)
272 
273 #define REG_MC_VLAN_EN			0x2100
274 #define MC_VLAN_EN_MASK			BIT(0)
275 
276 #define REG_MC_VLAN_CFG			0x2104
277 #define MC_VLAN_CFG_CMD_DONE_MASK	BIT(31)
278 #define MC_VLAN_CFG_TABLE_ID_MASK	GENMASK(21, 16)
279 #define MC_VLAN_CFG_PORT_ID_MASK	GENMASK(11, 8)
280 #define MC_VLAN_CFG_TABLE_SEL_MASK	BIT(4)
281 #define MC_VLAN_CFG_RW_MASK		BIT(0)
282 
283 #define REG_MC_VLAN_DATA		0x2108
284 
285 #define REG_CDM5_RX_OQ1_DROP_CNT	0x29d4
286 
287 /* QDMA */
288 #define REG_QDMA_GLOBAL_CFG			0x0004
289 #define GLOBAL_CFG_RX_2B_OFFSET_MASK		BIT(31)
290 #define GLOBAL_CFG_DMA_PREFERENCE_MASK		GENMASK(30, 29)
291 #define GLOBAL_CFG_CPU_TXR_RR_MASK		BIT(28)
292 #define GLOBAL_CFG_DSCP_BYTE_SWAP_MASK		BIT(27)
293 #define GLOBAL_CFG_PAYLOAD_BYTE_SWAP_MASK	BIT(26)
294 #define GLOBAL_CFG_MULTICAST_MODIFY_FP_MASK	BIT(25)
295 #define GLOBAL_CFG_OAM_MODIFY_MASK		BIT(24)
296 #define GLOBAL_CFG_RESET_MASK			BIT(23)
297 #define GLOBAL_CFG_RESET_DONE_MASK		BIT(22)
298 #define GLOBAL_CFG_MULTICAST_EN_MASK		BIT(21)
299 #define GLOBAL_CFG_IRQ1_EN_MASK			BIT(20)
300 #define GLOBAL_CFG_IRQ0_EN_MASK			BIT(19)
301 #define GLOBAL_CFG_LOOPCNT_EN_MASK		BIT(18)
302 #define GLOBAL_CFG_RD_BYPASS_WR_MASK		BIT(17)
303 #define GLOBAL_CFG_QDMA_LOOPBACK_MASK		BIT(16)
304 #define GLOBAL_CFG_LPBK_RXQ_SEL_MASK		GENMASK(13, 8)
305 #define GLOBAL_CFG_CHECK_DONE_MASK		BIT(7)
306 #define GLOBAL_CFG_TX_WB_DONE_MASK		BIT(6)
307 #define GLOBAL_CFG_MAX_ISSUE_NUM_MASK		GENMASK(5, 4)
308 #define GLOBAL_CFG_RX_DMA_BUSY_MASK		BIT(3)
309 #define GLOBAL_CFG_RX_DMA_EN_MASK		BIT(2)
310 #define GLOBAL_CFG_TX_DMA_BUSY_MASK		BIT(1)
311 #define GLOBAL_CFG_TX_DMA_EN_MASK		BIT(0)
312 
313 #define REG_FWD_DSCP_BASE			0x0010
314 #define REG_FWD_BUF_BASE			0x0014
315 
316 #define REG_HW_FWD_DSCP_CFG			0x0018
317 #define HW_FWD_DSCP_PAYLOAD_SIZE_MASK		GENMASK(29, 28)
318 #define HW_FWD_DSCP_SCATTER_LEN_MASK		GENMASK(17, 16)
319 #define HW_FWD_DSCP_MIN_SCATTER_LEN_MASK	GENMASK(15, 0)
320 
321 #define REG_INT_STATUS(_n)		\
322 	(((_n) == 4) ? 0x0730 :		\
323 	 ((_n) == 3) ? 0x0724 :		\
324 	 ((_n) == 2) ? 0x0720 :		\
325 	 ((_n) == 1) ? 0x0024 : 0x0020)
326 
327 #define REG_INT_ENABLE(_n)		\
328 	(((_n) == 4) ? 0x0750 :		\
329 	 ((_n) == 3) ? 0x0744 :		\
330 	 ((_n) == 2) ? 0x0740 :		\
331 	 ((_n) == 1) ? 0x002c : 0x0028)
332 
333 /* QDMA_CSR_INT_ENABLE1 */
334 #define RX15_COHERENT_INT_MASK		BIT(31)
335 #define RX14_COHERENT_INT_MASK		BIT(30)
336 #define RX13_COHERENT_INT_MASK		BIT(29)
337 #define RX12_COHERENT_INT_MASK		BIT(28)
338 #define RX11_COHERENT_INT_MASK		BIT(27)
339 #define RX10_COHERENT_INT_MASK		BIT(26)
340 #define RX9_COHERENT_INT_MASK		BIT(25)
341 #define RX8_COHERENT_INT_MASK		BIT(24)
342 #define RX7_COHERENT_INT_MASK		BIT(23)
343 #define RX6_COHERENT_INT_MASK		BIT(22)
344 #define RX5_COHERENT_INT_MASK		BIT(21)
345 #define RX4_COHERENT_INT_MASK		BIT(20)
346 #define RX3_COHERENT_INT_MASK		BIT(19)
347 #define RX2_COHERENT_INT_MASK		BIT(18)
348 #define RX1_COHERENT_INT_MASK		BIT(17)
349 #define RX0_COHERENT_INT_MASK		BIT(16)
350 #define TX7_COHERENT_INT_MASK		BIT(15)
351 #define TX6_COHERENT_INT_MASK		BIT(14)
352 #define TX5_COHERENT_INT_MASK		BIT(13)
353 #define TX4_COHERENT_INT_MASK		BIT(12)
354 #define TX3_COHERENT_INT_MASK		BIT(11)
355 #define TX2_COHERENT_INT_MASK		BIT(10)
356 #define TX1_COHERENT_INT_MASK		BIT(9)
357 #define TX0_COHERENT_INT_MASK		BIT(8)
358 #define CNT_OVER_FLOW_INT_MASK		BIT(7)
359 #define IRQ1_FULL_INT_MASK		BIT(5)
360 #define IRQ1_INT_MASK			BIT(4)
361 #define HWFWD_DSCP_LOW_INT_MASK		BIT(3)
362 #define HWFWD_DSCP_EMPTY_INT_MASK	BIT(2)
363 #define IRQ0_FULL_INT_MASK		BIT(1)
364 #define IRQ0_INT_MASK			BIT(0)
365 
366 #define TX_DONE_INT_MASK(_n)					\
367 	((_n) ? IRQ1_INT_MASK | IRQ1_FULL_INT_MASK		\
368 	      : IRQ0_INT_MASK | IRQ0_FULL_INT_MASK)
369 
370 #define INT_TX_MASK						\
371 	(IRQ1_INT_MASK | IRQ1_FULL_INT_MASK |			\
372 	 IRQ0_INT_MASK | IRQ0_FULL_INT_MASK)
373 
374 #define INT_IDX0_MASK						\
375 	(TX0_COHERENT_INT_MASK | TX1_COHERENT_INT_MASK |	\
376 	 TX2_COHERENT_INT_MASK | TX3_COHERENT_INT_MASK |	\
377 	 TX4_COHERENT_INT_MASK | TX5_COHERENT_INT_MASK |	\
378 	 TX6_COHERENT_INT_MASK | TX7_COHERENT_INT_MASK |	\
379 	 RX0_COHERENT_INT_MASK | RX1_COHERENT_INT_MASK |	\
380 	 RX2_COHERENT_INT_MASK | RX3_COHERENT_INT_MASK |	\
381 	 RX4_COHERENT_INT_MASK | RX7_COHERENT_INT_MASK |	\
382 	 RX8_COHERENT_INT_MASK | RX9_COHERENT_INT_MASK |	\
383 	 RX15_COHERENT_INT_MASK | INT_TX_MASK)
384 
385 /* QDMA_CSR_INT_ENABLE2 */
386 #define RX15_NO_CPU_DSCP_INT_MASK	BIT(31)
387 #define RX14_NO_CPU_DSCP_INT_MASK	BIT(30)
388 #define RX13_NO_CPU_DSCP_INT_MASK	BIT(29)
389 #define RX12_NO_CPU_DSCP_INT_MASK	BIT(28)
390 #define RX11_NO_CPU_DSCP_INT_MASK	BIT(27)
391 #define RX10_NO_CPU_DSCP_INT_MASK	BIT(26)
392 #define RX9_NO_CPU_DSCP_INT_MASK	BIT(25)
393 #define RX8_NO_CPU_DSCP_INT_MASK	BIT(24)
394 #define RX7_NO_CPU_DSCP_INT_MASK	BIT(23)
395 #define RX6_NO_CPU_DSCP_INT_MASK	BIT(22)
396 #define RX5_NO_CPU_DSCP_INT_MASK	BIT(21)
397 #define RX4_NO_CPU_DSCP_INT_MASK	BIT(20)
398 #define RX3_NO_CPU_DSCP_INT_MASK	BIT(19)
399 #define RX2_NO_CPU_DSCP_INT_MASK	BIT(18)
400 #define RX1_NO_CPU_DSCP_INT_MASK	BIT(17)
401 #define RX0_NO_CPU_DSCP_INT_MASK	BIT(16)
402 #define RX15_DONE_INT_MASK		BIT(15)
403 #define RX14_DONE_INT_MASK		BIT(14)
404 #define RX13_DONE_INT_MASK		BIT(13)
405 #define RX12_DONE_INT_MASK		BIT(12)
406 #define RX11_DONE_INT_MASK		BIT(11)
407 #define RX10_DONE_INT_MASK		BIT(10)
408 #define RX9_DONE_INT_MASK		BIT(9)
409 #define RX8_DONE_INT_MASK		BIT(8)
410 #define RX7_DONE_INT_MASK		BIT(7)
411 #define RX6_DONE_INT_MASK		BIT(6)
412 #define RX5_DONE_INT_MASK		BIT(5)
413 #define RX4_DONE_INT_MASK		BIT(4)
414 #define RX3_DONE_INT_MASK		BIT(3)
415 #define RX2_DONE_INT_MASK		BIT(2)
416 #define RX1_DONE_INT_MASK		BIT(1)
417 #define RX0_DONE_INT_MASK		BIT(0)
418 
419 #define RX_DONE_INT_MASK					\
420 	(RX0_DONE_INT_MASK | RX1_DONE_INT_MASK |		\
421 	 RX2_DONE_INT_MASK | RX3_DONE_INT_MASK |		\
422 	 RX4_DONE_INT_MASK | RX7_DONE_INT_MASK |		\
423 	 RX8_DONE_INT_MASK | RX9_DONE_INT_MASK |		\
424 	 RX15_DONE_INT_MASK)
425 #define INT_IDX1_MASK						\
426 	(RX_DONE_INT_MASK |					\
427 	 RX0_NO_CPU_DSCP_INT_MASK | RX1_NO_CPU_DSCP_INT_MASK |	\
428 	 RX2_NO_CPU_DSCP_INT_MASK | RX3_NO_CPU_DSCP_INT_MASK |	\
429 	 RX4_NO_CPU_DSCP_INT_MASK | RX7_NO_CPU_DSCP_INT_MASK |	\
430 	 RX8_NO_CPU_DSCP_INT_MASK | RX9_NO_CPU_DSCP_INT_MASK |	\
431 	 RX15_NO_CPU_DSCP_INT_MASK)
432 
433 /* QDMA_CSR_INT_ENABLE5 */
434 #define TX31_COHERENT_INT_MASK		BIT(31)
435 #define TX30_COHERENT_INT_MASK		BIT(30)
436 #define TX29_COHERENT_INT_MASK		BIT(29)
437 #define TX28_COHERENT_INT_MASK		BIT(28)
438 #define TX27_COHERENT_INT_MASK		BIT(27)
439 #define TX26_COHERENT_INT_MASK		BIT(26)
440 #define TX25_COHERENT_INT_MASK		BIT(25)
441 #define TX24_COHERENT_INT_MASK		BIT(24)
442 #define TX23_COHERENT_INT_MASK		BIT(23)
443 #define TX22_COHERENT_INT_MASK		BIT(22)
444 #define TX21_COHERENT_INT_MASK		BIT(21)
445 #define TX20_COHERENT_INT_MASK		BIT(20)
446 #define TX19_COHERENT_INT_MASK		BIT(19)
447 #define TX18_COHERENT_INT_MASK		BIT(18)
448 #define TX17_COHERENT_INT_MASK		BIT(17)
449 #define TX16_COHERENT_INT_MASK		BIT(16)
450 #define TX15_COHERENT_INT_MASK		BIT(15)
451 #define TX14_COHERENT_INT_MASK		BIT(14)
452 #define TX13_COHERENT_INT_MASK		BIT(13)
453 #define TX12_COHERENT_INT_MASK		BIT(12)
454 #define TX11_COHERENT_INT_MASK		BIT(11)
455 #define TX10_COHERENT_INT_MASK		BIT(10)
456 #define TX9_COHERENT_INT_MASK		BIT(9)
457 #define TX8_COHERENT_INT_MASK		BIT(8)
458 
459 #define INT_IDX4_MASK						\
460 	(TX8_COHERENT_INT_MASK | TX9_COHERENT_INT_MASK |	\
461 	 TX10_COHERENT_INT_MASK | TX11_COHERENT_INT_MASK |	\
462 	 TX12_COHERENT_INT_MASK | TX13_COHERENT_INT_MASK |	\
463 	 TX14_COHERENT_INT_MASK | TX15_COHERENT_INT_MASK |	\
464 	 TX16_COHERENT_INT_MASK | TX17_COHERENT_INT_MASK |	\
465 	 TX18_COHERENT_INT_MASK | TX19_COHERENT_INT_MASK |	\
466 	 TX20_COHERENT_INT_MASK | TX21_COHERENT_INT_MASK |	\
467 	 TX22_COHERENT_INT_MASK | TX23_COHERENT_INT_MASK |	\
468 	 TX24_COHERENT_INT_MASK | TX25_COHERENT_INT_MASK |	\
469 	 TX26_COHERENT_INT_MASK | TX27_COHERENT_INT_MASK |	\
470 	 TX28_COHERENT_INT_MASK | TX29_COHERENT_INT_MASK |	\
471 	 TX30_COHERENT_INT_MASK | TX31_COHERENT_INT_MASK)
472 
473 #define REG_TX_IRQ_BASE(_n)		((_n) ? 0x0048 : 0x0050)
474 
475 #define REG_TX_IRQ_CFG(_n)		((_n) ? 0x004c : 0x0054)
476 #define TX_IRQ_THR_MASK			GENMASK(27, 16)
477 #define TX_IRQ_DEPTH_MASK		GENMASK(11, 0)
478 
479 #define REG_IRQ_CLEAR_LEN(_n)		((_n) ? 0x0064 : 0x0058)
480 #define IRQ_CLEAR_LEN_MASK		GENMASK(7, 0)
481 
482 #define REG_IRQ_STATUS(_n)		((_n) ? 0x0068 : 0x005c)
483 #define IRQ_ENTRY_LEN_MASK		GENMASK(27, 16)
484 #define IRQ_HEAD_IDX_MASK		GENMASK(11, 0)
485 
486 #define REG_TX_RING_BASE(_n)	\
487 	(((_n) < 8) ? 0x0100 + ((_n) << 5) : 0x0b00 + (((_n) - 8) << 5))
488 
489 #define REG_TX_RING_BLOCKING(_n)	\
490 	(((_n) < 8) ? 0x0104 + ((_n) << 5) : 0x0b04 + (((_n) - 8) << 5))
491 
492 #define TX_RING_IRQ_BLOCKING_MAP_MASK			BIT(6)
493 #define TX_RING_IRQ_BLOCKING_CFG_MASK			BIT(4)
494 #define TX_RING_IRQ_BLOCKING_TX_DROP_EN_MASK		BIT(2)
495 #define TX_RING_IRQ_BLOCKING_MAX_TH_TXRING_EN_MASK	BIT(1)
496 #define TX_RING_IRQ_BLOCKING_MIN_TH_TXRING_EN_MASK	BIT(0)
497 
498 #define REG_TX_CPU_IDX(_n)	\
499 	(((_n) < 8) ? 0x0108 + ((_n) << 5) : 0x0b08 + (((_n) - 8) << 5))
500 
501 #define TX_RING_CPU_IDX_MASK		GENMASK(15, 0)
502 
503 #define REG_TX_DMA_IDX(_n)	\
504 	(((_n) < 8) ? 0x010c + ((_n) << 5) : 0x0b0c + (((_n) - 8) << 5))
505 
506 #define TX_RING_DMA_IDX_MASK		GENMASK(15, 0)
507 
508 #define IRQ_RING_IDX_MASK		GENMASK(20, 16)
509 #define IRQ_DESC_IDX_MASK		GENMASK(15, 0)
510 
511 #define REG_RX_RING_BASE(_n)	\
512 	(((_n) < 16) ? 0x0200 + ((_n) << 5) : 0x0e00 + (((_n) - 16) << 5))
513 
514 #define REG_RX_RING_SIZE(_n)	\
515 	(((_n) < 16) ? 0x0204 + ((_n) << 5) : 0x0e04 + (((_n) - 16) << 5))
516 
517 #define RX_RING_THR_MASK		GENMASK(31, 16)
518 #define RX_RING_SIZE_MASK		GENMASK(15, 0)
519 
520 #define REG_RX_CPU_IDX(_n)	\
521 	(((_n) < 16) ? 0x0208 + ((_n) << 5) : 0x0e08 + (((_n) - 16) << 5))
522 
523 #define RX_RING_CPU_IDX_MASK		GENMASK(15, 0)
524 
525 #define REG_RX_DMA_IDX(_n)	\
526 	(((_n) < 16) ? 0x020c + ((_n) << 5) : 0x0e0c + (((_n) - 16) << 5))
527 
528 #define REG_RX_DELAY_INT_IDX(_n)	\
529 	(((_n) < 16) ? 0x0210 + ((_n) << 5) : 0x0e10 + (((_n) - 16) << 5))
530 
531 #define RX_DELAY_INT_MASK		GENMASK(15, 0)
532 
533 #define RX_RING_DMA_IDX_MASK		GENMASK(15, 0)
534 
535 #define REG_INGRESS_TRTCM_CFG		0x0070
536 #define INGRESS_TRTCM_EN_MASK		BIT(31)
537 #define INGRESS_TRTCM_MODE_MASK		BIT(30)
538 #define INGRESS_SLOW_TICK_RATIO_MASK	GENMASK(29, 16)
539 #define INGRESS_FAST_TICK_MASK		GENMASK(15, 0)
540 
541 #define REG_TXQ_DIS_CFG_BASE(_n)	((_n) ? 0x20a0 : 0x00a0)
542 #define REG_TXQ_DIS_CFG(_n, _m)		(REG_TXQ_DIS_CFG_BASE((_n)) + (_m) << 2)
543 
544 #define REG_LMGR_INIT_CFG		0x1000
545 #define LMGR_INIT_START			BIT(31)
546 #define LMGR_SRAM_MODE_MASK		BIT(30)
547 #define HW_FWD_PKTSIZE_OVERHEAD_MASK	GENMASK(27, 20)
548 #define HW_FWD_DESC_NUM_MASK		GENMASK(16, 0)
549 
550 #define REG_FWD_DSCP_LOW_THR		0x1004
551 #define FWD_DSCP_LOW_THR_MASK		GENMASK(17, 0)
552 
553 #define REG_EGRESS_RATE_METER_CFG		0x100c
554 #define EGRESS_RATE_METER_EN_MASK		BIT(29)
555 #define EGRESS_RATE_METER_EQ_RATE_EN_MASK	BIT(17)
556 #define EGRESS_RATE_METER_WINDOW_SZ_MASK	GENMASK(16, 12)
557 #define EGRESS_RATE_METER_TIMESLICE_MASK	GENMASK(10, 0)
558 
559 #define REG_EGRESS_TRTCM_CFG		0x1010
560 #define EGRESS_TRTCM_EN_MASK		BIT(31)
561 #define EGRESS_TRTCM_MODE_MASK		BIT(30)
562 #define EGRESS_SLOW_TICK_RATIO_MASK	GENMASK(29, 16)
563 #define EGRESS_FAST_TICK_MASK		GENMASK(15, 0)
564 
565 #define REG_TXWRR_MODE_CFG		0x1020
566 #define TWRR_WEIGHT_SCALE_MASK		BIT(31)
567 #define TWRR_WEIGHT_BASE_MASK		BIT(3)
568 
569 #define REG_PSE_BUF_USAGE_CFG		0x1028
570 #define PSE_BUF_ESTIMATE_EN_MASK	BIT(29)
571 
572 #define REG_GLB_TRTCM_CFG		0x1080
573 #define GLB_TRTCM_EN_MASK		BIT(31)
574 #define GLB_TRTCM_MODE_MASK		BIT(30)
575 #define GLB_SLOW_TICK_RATIO_MASK	GENMASK(29, 16)
576 #define GLB_FAST_TICK_MASK		GENMASK(15, 0)
577 
578 #define REG_TXQ_CNGST_CFG		0x10a0
579 #define TXQ_CNGST_DROP_EN		BIT(31)
580 #define TXQ_CNGST_DEI_DROP_EN		BIT(30)
581 
582 #define REG_SLA_TRTCM_CFG		0x1150
583 #define SLA_TRTCM_EN_MASK		BIT(31)
584 #define SLA_TRTCM_MODE_MASK		BIT(30)
585 #define SLA_SLOW_TICK_RATIO_MASK	GENMASK(29, 16)
586 #define SLA_FAST_TICK_MASK		GENMASK(15, 0)
587 
588 /* CTRL */
589 #define QDMA_DESC_DONE_MASK		BIT(31)
590 #define QDMA_DESC_DROP_MASK		BIT(30) /* tx: drop - rx: overflow */
591 #define QDMA_DESC_MORE_MASK		BIT(29) /* more SG elements */
592 #define QDMA_DESC_DEI_MASK		BIT(25)
593 #define QDMA_DESC_NO_DROP_MASK		BIT(24)
594 #define QDMA_DESC_LEN_MASK		GENMASK(15, 0)
595 /* DATA */
596 #define QDMA_DESC_NEXT_ID_MASK		GENMASK(15, 0)
597 /* TX MSG0 */
598 #define QDMA_ETH_TXMSG_MIC_IDX_MASK	BIT(30)
599 #define QDMA_ETH_TXMSG_SP_TAG_MASK	GENMASK(29, 14)
600 #define QDMA_ETH_TXMSG_ICO_MASK		BIT(13)
601 #define QDMA_ETH_TXMSG_UCO_MASK		BIT(12)
602 #define QDMA_ETH_TXMSG_TCO_MASK		BIT(11)
603 #define QDMA_ETH_TXMSG_TSO_MASK		BIT(10)
604 #define QDMA_ETH_TXMSG_FAST_MASK	BIT(9)
605 #define QDMA_ETH_TXMSG_OAM_MASK		BIT(8)
606 #define QDMA_ETH_TXMSG_CHAN_MASK	GENMASK(7, 3)
607 #define QDMA_ETH_TXMSG_QUEUE_MASK	GENMASK(2, 0)
608 /* TX MSG1 */
609 #define QDMA_ETH_TXMSG_NO_DROP		BIT(31)
610 #define QDMA_ETH_TXMSG_METER_MASK	GENMASK(30, 24)	/* 0x7f no meters */
611 #define QDMA_ETH_TXMSG_FPORT_MASK	GENMASK(23, 20)
612 #define QDMA_ETH_TXMSG_NBOQ_MASK	GENMASK(19, 15)
613 #define QDMA_ETH_TXMSG_HWF_MASK		BIT(14)
614 #define QDMA_ETH_TXMSG_HOP_MASK		BIT(13)
615 #define QDMA_ETH_TXMSG_PTP_MASK		BIT(12)
616 #define QDMA_ETH_TXMSG_ACNT_G1_MASK	GENMASK(10, 6)	/* 0x1f do not count */
617 #define QDMA_ETH_TXMSG_ACNT_G0_MASK	GENMASK(5, 0)	/* 0x3f do not count */
618 
619 /* RX MSG1 */
620 #define QDMA_ETH_RXMSG_DEI_MASK		BIT(31)
621 #define QDMA_ETH_RXMSG_IP6_MASK		BIT(30)
622 #define QDMA_ETH_RXMSG_IP4_MASK		BIT(29)
623 #define QDMA_ETH_RXMSG_IP4F_MASK	BIT(28)
624 #define QDMA_ETH_RXMSG_L4_VALID_MASK	BIT(27)
625 #define QDMA_ETH_RXMSG_L4F_MASK		BIT(26)
626 #define QDMA_ETH_RXMSG_SPORT_MASK	GENMASK(25, 21)
627 #define QDMA_ETH_RXMSG_CRSN_MASK	GENMASK(20, 16)
628 #define QDMA_ETH_RXMSG_PPE_ENTRY_MASK	GENMASK(15, 0)
629 
630 struct airoha_qdma_desc {
631 	__le32 rsv;
632 	__le32 ctrl;
633 	__le32 addr;
634 	__le32 data;
635 	__le32 msg0;
636 	__le32 msg1;
637 	__le32 msg2;
638 	__le32 msg3;
639 };
640 
641 /* CTRL0 */
642 #define QDMA_FWD_DESC_CTX_MASK		BIT(31)
643 #define QDMA_FWD_DESC_RING_MASK		GENMASK(30, 28)
644 #define QDMA_FWD_DESC_IDX_MASK		GENMASK(27, 16)
645 #define QDMA_FWD_DESC_LEN_MASK		GENMASK(15, 0)
646 /* CTRL1 */
647 #define QDMA_FWD_DESC_FIRST_IDX_MASK	GENMASK(15, 0)
648 /* CTRL2 */
649 #define QDMA_FWD_DESC_MORE_PKT_NUM_MASK	GENMASK(2, 0)
650 
651 struct airoha_qdma_fwd_desc {
652 	__le32 addr;
653 	__le32 ctrl0;
654 	__le32 ctrl1;
655 	__le32 ctrl2;
656 	__le32 msg0;
657 	__le32 msg1;
658 	__le32 rsv0;
659 	__le32 rsv1;
660 };
661 
662 enum {
663 	QDMA_INT_REG_IDX0,
664 	QDMA_INT_REG_IDX1,
665 	QDMA_INT_REG_IDX2,
666 	QDMA_INT_REG_IDX3,
667 	QDMA_INT_REG_IDX4,
668 	QDMA_INT_REG_MAX
669 };
670 
671 enum {
672 	XSI_PCIE0_PORT,
673 	XSI_PCIE1_PORT,
674 	XSI_USB_PORT,
675 	XSI_AE_PORT,
676 	XSI_ETH_PORT,
677 };
678 
679 enum {
680 	XSI_PCIE0_VIP_PORT_MASK	= BIT(22),
681 	XSI_PCIE1_VIP_PORT_MASK	= BIT(23),
682 	XSI_USB_VIP_PORT_MASK	= BIT(25),
683 	XSI_ETH_VIP_PORT_MASK	= BIT(24),
684 };
685 
686 enum {
687 	DEV_STATE_INITIALIZED,
688 };
689 
690 enum {
691 	CDM_CRSN_QSEL_Q1 = 1,
692 	CDM_CRSN_QSEL_Q5 = 5,
693 	CDM_CRSN_QSEL_Q6 = 6,
694 	CDM_CRSN_QSEL_Q15 = 15,
695 };
696 
697 enum {
698 	CRSN_08 = 0x8,
699 	CRSN_21 = 0x15, /* KA */
700 	CRSN_22 = 0x16, /* hit bind and force route to CPU */
701 	CRSN_24 = 0x18,
702 	CRSN_25 = 0x19,
703 };
704 
705 enum {
706 	FE_PSE_PORT_CDM1,
707 	FE_PSE_PORT_GDM1,
708 	FE_PSE_PORT_GDM2,
709 	FE_PSE_PORT_GDM3,
710 	FE_PSE_PORT_PPE1,
711 	FE_PSE_PORT_CDM2,
712 	FE_PSE_PORT_CDM3,
713 	FE_PSE_PORT_CDM4,
714 	FE_PSE_PORT_PPE2,
715 	FE_PSE_PORT_GDM4,
716 	FE_PSE_PORT_CDM5,
717 	FE_PSE_PORT_DROP = 0xf,
718 };
719 
720 struct airoha_queue_entry {
721 	union {
722 		void *buf;
723 		struct sk_buff *skb;
724 	};
725 	dma_addr_t dma_addr;
726 	u16 dma_len;
727 };
728 
729 struct airoha_queue {
730 	struct airoha_eth *eth;
731 
732 	/* protect concurrent queue accesses */
733 	spinlock_t lock;
734 	struct airoha_queue_entry *entry;
735 	struct airoha_qdma_desc *desc;
736 	u16 head;
737 	u16 tail;
738 
739 	int queued;
740 	int ndesc;
741 	int free_thr;
742 	int buf_size;
743 
744 	struct napi_struct napi;
745 	struct page_pool *page_pool;
746 };
747 
748 struct airoha_tx_irq_queue {
749 	struct airoha_eth *eth;
750 
751 	struct napi_struct napi;
752 	u32 *q;
753 
754 	int size;
755 	int queued;
756 	u16 head;
757 };
758 
759 struct airoha_hw_stats {
760 	/* protect concurrent hw_stats accesses */
761 	spinlock_t lock;
762 	struct u64_stats_sync syncp;
763 
764 	/* get_stats64 */
765 	u64 rx_ok_pkts;
766 	u64 tx_ok_pkts;
767 	u64 rx_ok_bytes;
768 	u64 tx_ok_bytes;
769 	u64 rx_multicast;
770 	u64 rx_errors;
771 	u64 rx_drops;
772 	u64 tx_drops;
773 	u64 rx_crc_error;
774 	u64 rx_over_errors;
775 	/* ethtool stats */
776 	u64 tx_broadcast;
777 	u64 tx_multicast;
778 	u64 tx_len[7];
779 	u64 rx_broadcast;
780 	u64 rx_fragment;
781 	u64 rx_jabber;
782 	u64 rx_len[7];
783 };
784 
785 struct airoha_gdm_port {
786 	struct net_device *dev;
787 	struct airoha_eth *eth;
788 	int id;
789 
790 	struct airoha_hw_stats stats;
791 };
792 
793 struct airoha_eth {
794 	struct device *dev;
795 
796 	unsigned long state;
797 
798 	void __iomem *qdma_regs;
799 	void __iomem *fe_regs;
800 
801 	/* protect concurrent irqmask accesses */
802 	spinlock_t irq_lock;
803 	u32 irqmask[QDMA_INT_REG_MAX];
804 	int irq;
805 
806 	struct reset_control_bulk_data rsts[AIROHA_MAX_NUM_RSTS];
807 	struct reset_control_bulk_data xsi_rsts[AIROHA_MAX_NUM_XSI_RSTS];
808 
809 	struct airoha_gdm_port *ports[AIROHA_MAX_NUM_GDM_PORTS];
810 
811 	struct net_device *napi_dev;
812 	struct airoha_queue q_tx[AIROHA_NUM_TX_RING];
813 	struct airoha_queue q_rx[AIROHA_NUM_RX_RING];
814 
815 	struct airoha_tx_irq_queue q_tx_irq[AIROHA_NUM_TX_IRQ];
816 
817 	/* descriptor and packet buffers for qdma hw forward */
818 	struct {
819 		void *desc;
820 		void *q;
821 	} hfwd;
822 };
823 
824 static u32 airoha_rr(void __iomem *base, u32 offset)
825 {
826 	return readl(base + offset);
827 }
828 
829 static void airoha_wr(void __iomem *base, u32 offset, u32 val)
830 {
831 	writel(val, base + offset);
832 }
833 
834 static u32 airoha_rmw(void __iomem *base, u32 offset, u32 mask, u32 val)
835 {
836 	val |= (airoha_rr(base, offset) & ~mask);
837 	airoha_wr(base, offset, val);
838 
839 	return val;
840 }
841 
842 #define airoha_fe_rr(eth, offset)				\
843 	airoha_rr((eth)->fe_regs, (offset))
844 #define airoha_fe_wr(eth, offset, val)				\
845 	airoha_wr((eth)->fe_regs, (offset), (val))
846 #define airoha_fe_rmw(eth, offset, mask, val)			\
847 	airoha_rmw((eth)->fe_regs, (offset), (mask), (val))
848 #define airoha_fe_set(eth, offset, val)				\
849 	airoha_rmw((eth)->fe_regs, (offset), 0, (val))
850 #define airoha_fe_clear(eth, offset, val)			\
851 	airoha_rmw((eth)->fe_regs, (offset), (val), 0)
852 
853 #define airoha_qdma_rr(eth, offset)				\
854 	airoha_rr((eth)->qdma_regs, (offset))
855 #define airoha_qdma_wr(eth, offset, val)			\
856 	airoha_wr((eth)->qdma_regs, (offset), (val))
857 #define airoha_qdma_rmw(eth, offset, mask, val)			\
858 	airoha_rmw((eth)->qdma_regs, (offset), (mask), (val))
859 #define airoha_qdma_set(eth, offset, val)			\
860 	airoha_rmw((eth)->qdma_regs, (offset), 0, (val))
861 #define airoha_qdma_clear(eth, offset, val)			\
862 	airoha_rmw((eth)->qdma_regs, (offset), (val), 0)
863 
864 static void airoha_qdma_set_irqmask(struct airoha_eth *eth, int index,
865 				    u32 clear, u32 set)
866 {
867 	unsigned long flags;
868 
869 	if (WARN_ON_ONCE(index >= ARRAY_SIZE(eth->irqmask)))
870 		return;
871 
872 	spin_lock_irqsave(&eth->irq_lock, flags);
873 
874 	eth->irqmask[index] &= ~clear;
875 	eth->irqmask[index] |= set;
876 	airoha_qdma_wr(eth, REG_INT_ENABLE(index), eth->irqmask[index]);
877 	/* Read irq_enable register in order to guarantee the update above
878 	 * completes in the spinlock critical section.
879 	 */
880 	airoha_qdma_rr(eth, REG_INT_ENABLE(index));
881 
882 	spin_unlock_irqrestore(&eth->irq_lock, flags);
883 }
884 
885 static void airoha_qdma_irq_enable(struct airoha_eth *eth, int index,
886 				   u32 mask)
887 {
888 	airoha_qdma_set_irqmask(eth, index, 0, mask);
889 }
890 
891 static void airoha_qdma_irq_disable(struct airoha_eth *eth, int index,
892 				    u32 mask)
893 {
894 	airoha_qdma_set_irqmask(eth, index, mask, 0);
895 }
896 
897 static void airoha_set_macaddr(struct airoha_eth *eth, const u8 *addr)
898 {
899 	u32 val;
900 
901 	val = (addr[0] << 16) | (addr[1] << 8) | addr[2];
902 	airoha_fe_wr(eth, REG_FE_LAN_MAC_H, val);
903 
904 	val = (addr[3] << 16) | (addr[4] << 8) | addr[5];
905 	airoha_fe_wr(eth, REG_FE_LAN_MAC_LMIN, val);
906 	airoha_fe_wr(eth, REG_FE_LAN_MAC_LMAX, val);
907 }
908 
909 static void airoha_set_gdm_port_fwd_cfg(struct airoha_eth *eth, u32 addr,
910 					u32 val)
911 {
912 	airoha_fe_rmw(eth, addr, GDM_OCFQ_MASK,
913 		      FIELD_PREP(GDM_OCFQ_MASK, val));
914 	airoha_fe_rmw(eth, addr, GDM_MCFQ_MASK,
915 		      FIELD_PREP(GDM_MCFQ_MASK, val));
916 	airoha_fe_rmw(eth, addr, GDM_BCFQ_MASK,
917 		      FIELD_PREP(GDM_BCFQ_MASK, val));
918 	airoha_fe_rmw(eth, addr, GDM_UCFQ_MASK,
919 		      FIELD_PREP(GDM_UCFQ_MASK, val));
920 }
921 
922 static int airoha_set_gdm_port(struct airoha_eth *eth, int port, bool enable)
923 {
924 	u32 val = enable ? FE_PSE_PORT_PPE1 : FE_PSE_PORT_DROP;
925 	u32 vip_port, cfg_addr;
926 
927 	switch (port) {
928 	case XSI_PCIE0_PORT:
929 		vip_port = XSI_PCIE0_VIP_PORT_MASK;
930 		cfg_addr = REG_GDM_FWD_CFG(3);
931 		break;
932 	case XSI_PCIE1_PORT:
933 		vip_port = XSI_PCIE1_VIP_PORT_MASK;
934 		cfg_addr = REG_GDM_FWD_CFG(3);
935 		break;
936 	case XSI_USB_PORT:
937 		vip_port = XSI_USB_VIP_PORT_MASK;
938 		cfg_addr = REG_GDM_FWD_CFG(4);
939 		break;
940 	case XSI_ETH_PORT:
941 		vip_port = XSI_ETH_VIP_PORT_MASK;
942 		cfg_addr = REG_GDM_FWD_CFG(4);
943 		break;
944 	default:
945 		return -EINVAL;
946 	}
947 
948 	if (enable) {
949 		airoha_fe_set(eth, REG_FE_VIP_PORT_EN, vip_port);
950 		airoha_fe_set(eth, REG_FE_IFC_PORT_EN, vip_port);
951 	} else {
952 		airoha_fe_clear(eth, REG_FE_VIP_PORT_EN, vip_port);
953 		airoha_fe_clear(eth, REG_FE_IFC_PORT_EN, vip_port);
954 	}
955 
956 	airoha_set_gdm_port_fwd_cfg(eth, cfg_addr, val);
957 
958 	return 0;
959 }
960 
961 static int airoha_set_gdm_ports(struct airoha_eth *eth, bool enable)
962 {
963 	const int port_list[] = {
964 		XSI_PCIE0_PORT,
965 		XSI_PCIE1_PORT,
966 		XSI_USB_PORT,
967 		XSI_ETH_PORT
968 	};
969 	int i, err;
970 
971 	for (i = 0; i < ARRAY_SIZE(port_list); i++) {
972 		err = airoha_set_gdm_port(eth, port_list[i], enable);
973 		if (err)
974 			goto error;
975 	}
976 
977 	return 0;
978 
979 error:
980 	for (i--; i >= 0; i--)
981 		airoha_set_gdm_port(eth, port_list[i], false);
982 
983 	return err;
984 }
985 
986 static void airoha_fe_maccr_init(struct airoha_eth *eth)
987 {
988 	int p;
989 
990 	for (p = 1; p <= ARRAY_SIZE(eth->ports); p++) {
991 		airoha_fe_set(eth, REG_GDM_FWD_CFG(p),
992 			      GDM_TCP_CKSUM | GDM_UDP_CKSUM | GDM_IP4_CKSUM |
993 			      GDM_DROP_CRC_ERR);
994 		airoha_set_gdm_port_fwd_cfg(eth, REG_GDM_FWD_CFG(p),
995 					    FE_PSE_PORT_CDM1);
996 		airoha_fe_rmw(eth, REG_GDM_LEN_CFG(p),
997 			      GDM_SHORT_LEN_MASK | GDM_LONG_LEN_MASK,
998 			      FIELD_PREP(GDM_SHORT_LEN_MASK, 60) |
999 			      FIELD_PREP(GDM_LONG_LEN_MASK, 4004));
1000 	}
1001 
1002 	airoha_fe_rmw(eth, REG_CDM1_VLAN_CTRL, CDM1_VLAN_MASK,
1003 		      FIELD_PREP(CDM1_VLAN_MASK, 0x8100));
1004 
1005 	airoha_fe_set(eth, REG_FE_CPORT_CFG, FE_CPORT_PAD);
1006 }
1007 
1008 static void airoha_fe_vip_setup(struct airoha_eth *eth)
1009 {
1010 	airoha_fe_wr(eth, REG_FE_VIP_PATN(3), ETH_P_PPP_DISC);
1011 	airoha_fe_wr(eth, REG_FE_VIP_EN(3), PATN_FCPU_EN_MASK | PATN_EN_MASK);
1012 
1013 	airoha_fe_wr(eth, REG_FE_VIP_PATN(4), PPP_LCP);
1014 	airoha_fe_wr(eth, REG_FE_VIP_EN(4),
1015 		     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |
1016 		     PATN_EN_MASK);
1017 
1018 	airoha_fe_wr(eth, REG_FE_VIP_PATN(6), PPP_IPCP);
1019 	airoha_fe_wr(eth, REG_FE_VIP_EN(6),
1020 		     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |
1021 		     PATN_EN_MASK);
1022 
1023 	airoha_fe_wr(eth, REG_FE_VIP_PATN(7), PPP_CHAP);
1024 	airoha_fe_wr(eth, REG_FE_VIP_EN(7),
1025 		     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |
1026 		     PATN_EN_MASK);
1027 
1028 	/* BOOTP (0x43) */
1029 	airoha_fe_wr(eth, REG_FE_VIP_PATN(8), 0x43);
1030 	airoha_fe_wr(eth, REG_FE_VIP_EN(8),
1031 		     PATN_FCPU_EN_MASK | PATN_SP_EN_MASK |
1032 		     FIELD_PREP(PATN_TYPE_MASK, 4) | PATN_EN_MASK);
1033 
1034 	/* BOOTP (0x44) */
1035 	airoha_fe_wr(eth, REG_FE_VIP_PATN(9), 0x44);
1036 	airoha_fe_wr(eth, REG_FE_VIP_EN(9),
1037 		     PATN_FCPU_EN_MASK | PATN_SP_EN_MASK |
1038 		     FIELD_PREP(PATN_TYPE_MASK, 4) | PATN_EN_MASK);
1039 
1040 	/* ISAKMP */
1041 	airoha_fe_wr(eth, REG_FE_VIP_PATN(10), 0x1f401f4);
1042 	airoha_fe_wr(eth, REG_FE_VIP_EN(10),
1043 		     PATN_FCPU_EN_MASK | PATN_DP_EN_MASK | PATN_SP_EN_MASK |
1044 		     FIELD_PREP(PATN_TYPE_MASK, 4) | PATN_EN_MASK);
1045 
1046 	airoha_fe_wr(eth, REG_FE_VIP_PATN(11), PPP_IPV6CP);
1047 	airoha_fe_wr(eth, REG_FE_VIP_EN(11),
1048 		     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |
1049 		     PATN_EN_MASK);
1050 
1051 	/* DHCPv6 */
1052 	airoha_fe_wr(eth, REG_FE_VIP_PATN(12), 0x2220223);
1053 	airoha_fe_wr(eth, REG_FE_VIP_EN(12),
1054 		     PATN_FCPU_EN_MASK | PATN_DP_EN_MASK | PATN_SP_EN_MASK |
1055 		     FIELD_PREP(PATN_TYPE_MASK, 4) | PATN_EN_MASK);
1056 
1057 	airoha_fe_wr(eth, REG_FE_VIP_PATN(19), PPP_PAP);
1058 	airoha_fe_wr(eth, REG_FE_VIP_EN(19),
1059 		     PATN_FCPU_EN_MASK | FIELD_PREP(PATN_TYPE_MASK, 1) |
1060 		     PATN_EN_MASK);
1061 
1062 	/* ETH->ETH_P_1905 (0x893a) */
1063 	airoha_fe_wr(eth, REG_FE_VIP_PATN(20), 0x893a);
1064 	airoha_fe_wr(eth, REG_FE_VIP_EN(20),
1065 		     PATN_FCPU_EN_MASK | PATN_EN_MASK);
1066 
1067 	airoha_fe_wr(eth, REG_FE_VIP_PATN(21), ETH_P_LLDP);
1068 	airoha_fe_wr(eth, REG_FE_VIP_EN(21),
1069 		     PATN_FCPU_EN_MASK | PATN_EN_MASK);
1070 }
1071 
1072 static u32 airoha_fe_get_pse_queue_rsv_pages(struct airoha_eth *eth,
1073 					     u32 port, u32 queue)
1074 {
1075 	u32 val;
1076 
1077 	airoha_fe_rmw(eth, REG_FE_PSE_QUEUE_CFG_WR,
1078 		      PSE_CFG_PORT_ID_MASK | PSE_CFG_QUEUE_ID_MASK,
1079 		      FIELD_PREP(PSE_CFG_PORT_ID_MASK, port) |
1080 		      FIELD_PREP(PSE_CFG_QUEUE_ID_MASK, queue));
1081 	val = airoha_fe_rr(eth, REG_FE_PSE_QUEUE_CFG_VAL);
1082 
1083 	return FIELD_GET(PSE_CFG_OQ_RSV_MASK, val);
1084 }
1085 
1086 static void airoha_fe_set_pse_queue_rsv_pages(struct airoha_eth *eth,
1087 					      u32 port, u32 queue, u32 val)
1088 {
1089 	airoha_fe_rmw(eth, REG_FE_PSE_QUEUE_CFG_VAL, PSE_CFG_OQ_RSV_MASK,
1090 		      FIELD_PREP(PSE_CFG_OQ_RSV_MASK, val));
1091 	airoha_fe_rmw(eth, REG_FE_PSE_QUEUE_CFG_WR,
1092 		      PSE_CFG_PORT_ID_MASK | PSE_CFG_QUEUE_ID_MASK |
1093 		      PSE_CFG_WR_EN_MASK | PSE_CFG_OQRSV_SEL_MASK,
1094 		      FIELD_PREP(PSE_CFG_PORT_ID_MASK, port) |
1095 		      FIELD_PREP(PSE_CFG_QUEUE_ID_MASK, queue) |
1096 		      PSE_CFG_WR_EN_MASK | PSE_CFG_OQRSV_SEL_MASK);
1097 }
1098 
1099 static int airoha_fe_set_pse_oq_rsv(struct airoha_eth *eth,
1100 				    u32 port, u32 queue, u32 val)
1101 {
1102 	u32 orig_val, tmp, all_rsv, fq_limit;
1103 
1104 	airoha_fe_set_pse_queue_rsv_pages(eth, port, queue, val);
1105 
1106 	/* modify all rsv */
1107 	orig_val = airoha_fe_get_pse_queue_rsv_pages(eth, port, queue);
1108 	tmp = airoha_fe_rr(eth, REG_FE_PSE_BUF_SET);
1109 	all_rsv = FIELD_GET(PSE_ALLRSV_MASK, tmp);
1110 	all_rsv += (val - orig_val);
1111 	airoha_fe_rmw(eth, REG_FE_PSE_BUF_SET, PSE_ALLRSV_MASK,
1112 		      FIELD_PREP(PSE_ALLRSV_MASK, all_rsv));
1113 
1114 	/* modify hthd */
1115 	tmp = airoha_fe_rr(eth, PSE_FQ_CFG);
1116 	fq_limit = FIELD_GET(PSE_FQ_LIMIT_MASK, tmp);
1117 	tmp = fq_limit - all_rsv - 0x20;
1118 	airoha_fe_rmw(eth, REG_PSE_SHARE_USED_THD,
1119 		      PSE_SHARE_USED_HTHD_MASK,
1120 		      FIELD_PREP(PSE_SHARE_USED_HTHD_MASK, tmp));
1121 
1122 	tmp = fq_limit - all_rsv - 0x100;
1123 	airoha_fe_rmw(eth, REG_PSE_SHARE_USED_THD,
1124 		      PSE_SHARE_USED_MTHD_MASK,
1125 		      FIELD_PREP(PSE_SHARE_USED_MTHD_MASK, tmp));
1126 	tmp = (3 * tmp) >> 2;
1127 	airoha_fe_rmw(eth, REG_FE_PSE_BUF_SET,
1128 		      PSE_SHARE_USED_LTHD_MASK,
1129 		      FIELD_PREP(PSE_SHARE_USED_LTHD_MASK, tmp));
1130 
1131 	return 0;
1132 }
1133 
1134 static void airoha_fe_pse_ports_init(struct airoha_eth *eth)
1135 {
1136 	const u32 pse_port_num_queues[] = {
1137 		[FE_PSE_PORT_CDM1] = 6,
1138 		[FE_PSE_PORT_GDM1] = 6,
1139 		[FE_PSE_PORT_GDM2] = 32,
1140 		[FE_PSE_PORT_GDM3] = 6,
1141 		[FE_PSE_PORT_PPE1] = 4,
1142 		[FE_PSE_PORT_CDM2] = 6,
1143 		[FE_PSE_PORT_CDM3] = 8,
1144 		[FE_PSE_PORT_CDM4] = 10,
1145 		[FE_PSE_PORT_PPE2] = 4,
1146 		[FE_PSE_PORT_GDM4] = 2,
1147 		[FE_PSE_PORT_CDM5] = 2,
1148 	};
1149 	int q;
1150 
1151 	/* hw misses PPE2 oq rsv */
1152 	airoha_fe_set(eth, REG_FE_PSE_BUF_SET,
1153 		      PSE_RSV_PAGES * pse_port_num_queues[FE_PSE_PORT_PPE2]);
1154 
1155 	/* CMD1 */
1156 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_CDM1]; q++)
1157 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_CDM1, q,
1158 					 PSE_QUEUE_RSV_PAGES);
1159 	/* GMD1 */
1160 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_GDM1]; q++)
1161 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_GDM1, q,
1162 					 PSE_QUEUE_RSV_PAGES);
1163 	/* GMD2 */
1164 	for (q = 6; q < pse_port_num_queues[FE_PSE_PORT_GDM2]; q++)
1165 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_GDM2, q, 0);
1166 	/* GMD3 */
1167 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_GDM3]; q++)
1168 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_GDM3, q,
1169 					 PSE_QUEUE_RSV_PAGES);
1170 	/* PPE1 */
1171 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_PPE1]; q++) {
1172 		if (q < pse_port_num_queues[FE_PSE_PORT_PPE1])
1173 			airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_PPE1, q,
1174 						 PSE_QUEUE_RSV_PAGES);
1175 		else
1176 			airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_PPE1, q, 0);
1177 	}
1178 	/* CDM2 */
1179 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_CDM2]; q++)
1180 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_CDM2, q,
1181 					 PSE_QUEUE_RSV_PAGES);
1182 	/* CDM3 */
1183 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_CDM3] - 1; q++)
1184 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_CDM3, q, 0);
1185 	/* CDM4 */
1186 	for (q = 4; q < pse_port_num_queues[FE_PSE_PORT_CDM4]; q++)
1187 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_CDM4, q,
1188 					 PSE_QUEUE_RSV_PAGES);
1189 	/* PPE2 */
1190 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_PPE2]; q++) {
1191 		if (q < pse_port_num_queues[FE_PSE_PORT_PPE2] / 2)
1192 			airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_PPE2, q,
1193 						 PSE_QUEUE_RSV_PAGES);
1194 		else
1195 			airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_PPE2, q, 0);
1196 	}
1197 	/* GMD4 */
1198 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_GDM4]; q++)
1199 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_GDM4, q,
1200 					 PSE_QUEUE_RSV_PAGES);
1201 	/* CDM5 */
1202 	for (q = 0; q < pse_port_num_queues[FE_PSE_PORT_CDM5]; q++)
1203 		airoha_fe_set_pse_oq_rsv(eth, FE_PSE_PORT_CDM5, q,
1204 					 PSE_QUEUE_RSV_PAGES);
1205 }
1206 
1207 static int airoha_fe_mc_vlan_clear(struct airoha_eth *eth)
1208 {
1209 	int i;
1210 
1211 	for (i = 0; i < AIROHA_FE_MC_MAX_VLAN_TABLE; i++) {
1212 		int err, j;
1213 		u32 val;
1214 
1215 		airoha_fe_wr(eth, REG_MC_VLAN_DATA, 0x0);
1216 
1217 		val = FIELD_PREP(MC_VLAN_CFG_TABLE_ID_MASK, i) |
1218 		      MC_VLAN_CFG_TABLE_SEL_MASK | MC_VLAN_CFG_RW_MASK;
1219 		airoha_fe_wr(eth, REG_MC_VLAN_CFG, val);
1220 		err = read_poll_timeout(airoha_fe_rr, val,
1221 					val & MC_VLAN_CFG_CMD_DONE_MASK,
1222 					USEC_PER_MSEC, 5 * USEC_PER_MSEC,
1223 					false, eth, REG_MC_VLAN_CFG);
1224 		if (err)
1225 			return err;
1226 
1227 		for (j = 0; j < AIROHA_FE_MC_MAX_VLAN_PORT; j++) {
1228 			airoha_fe_wr(eth, REG_MC_VLAN_DATA, 0x0);
1229 
1230 			val = FIELD_PREP(MC_VLAN_CFG_TABLE_ID_MASK, i) |
1231 			      FIELD_PREP(MC_VLAN_CFG_PORT_ID_MASK, j) |
1232 			      MC_VLAN_CFG_RW_MASK;
1233 			airoha_fe_wr(eth, REG_MC_VLAN_CFG, val);
1234 			err = read_poll_timeout(airoha_fe_rr, val,
1235 						val & MC_VLAN_CFG_CMD_DONE_MASK,
1236 						USEC_PER_MSEC,
1237 						5 * USEC_PER_MSEC, false, eth,
1238 						REG_MC_VLAN_CFG);
1239 			if (err)
1240 				return err;
1241 		}
1242 	}
1243 
1244 	return 0;
1245 }
1246 
1247 static void airoha_fe_crsn_qsel_init(struct airoha_eth *eth)
1248 {
1249 	/* CDM1_CRSN_QSEL */
1250 	airoha_fe_rmw(eth, REG_CDM1_CRSN_QSEL(CRSN_22 >> 2),
1251 		      CDM1_CRSN_QSEL_REASON_MASK(CRSN_22),
1252 		      FIELD_PREP(CDM1_CRSN_QSEL_REASON_MASK(CRSN_22),
1253 				 CDM_CRSN_QSEL_Q1));
1254 	airoha_fe_rmw(eth, REG_CDM1_CRSN_QSEL(CRSN_08 >> 2),
1255 		      CDM1_CRSN_QSEL_REASON_MASK(CRSN_08),
1256 		      FIELD_PREP(CDM1_CRSN_QSEL_REASON_MASK(CRSN_08),
1257 				 CDM_CRSN_QSEL_Q1));
1258 	airoha_fe_rmw(eth, REG_CDM1_CRSN_QSEL(CRSN_21 >> 2),
1259 		      CDM1_CRSN_QSEL_REASON_MASK(CRSN_21),
1260 		      FIELD_PREP(CDM1_CRSN_QSEL_REASON_MASK(CRSN_21),
1261 				 CDM_CRSN_QSEL_Q1));
1262 	airoha_fe_rmw(eth, REG_CDM1_CRSN_QSEL(CRSN_24 >> 2),
1263 		      CDM1_CRSN_QSEL_REASON_MASK(CRSN_24),
1264 		      FIELD_PREP(CDM1_CRSN_QSEL_REASON_MASK(CRSN_24),
1265 				 CDM_CRSN_QSEL_Q6));
1266 	airoha_fe_rmw(eth, REG_CDM1_CRSN_QSEL(CRSN_25 >> 2),
1267 		      CDM1_CRSN_QSEL_REASON_MASK(CRSN_25),
1268 		      FIELD_PREP(CDM1_CRSN_QSEL_REASON_MASK(CRSN_25),
1269 				 CDM_CRSN_QSEL_Q1));
1270 	/* CDM2_CRSN_QSEL */
1271 	airoha_fe_rmw(eth, REG_CDM2_CRSN_QSEL(CRSN_08 >> 2),
1272 		      CDM2_CRSN_QSEL_REASON_MASK(CRSN_08),
1273 		      FIELD_PREP(CDM2_CRSN_QSEL_REASON_MASK(CRSN_08),
1274 				 CDM_CRSN_QSEL_Q1));
1275 	airoha_fe_rmw(eth, REG_CDM2_CRSN_QSEL(CRSN_21 >> 2),
1276 		      CDM2_CRSN_QSEL_REASON_MASK(CRSN_21),
1277 		      FIELD_PREP(CDM2_CRSN_QSEL_REASON_MASK(CRSN_21),
1278 				 CDM_CRSN_QSEL_Q1));
1279 	airoha_fe_rmw(eth, REG_CDM2_CRSN_QSEL(CRSN_22 >> 2),
1280 		      CDM2_CRSN_QSEL_REASON_MASK(CRSN_22),
1281 		      FIELD_PREP(CDM2_CRSN_QSEL_REASON_MASK(CRSN_22),
1282 				 CDM_CRSN_QSEL_Q1));
1283 	airoha_fe_rmw(eth, REG_CDM2_CRSN_QSEL(CRSN_24 >> 2),
1284 		      CDM2_CRSN_QSEL_REASON_MASK(CRSN_24),
1285 		      FIELD_PREP(CDM2_CRSN_QSEL_REASON_MASK(CRSN_24),
1286 				 CDM_CRSN_QSEL_Q6));
1287 	airoha_fe_rmw(eth, REG_CDM2_CRSN_QSEL(CRSN_25 >> 2),
1288 		      CDM2_CRSN_QSEL_REASON_MASK(CRSN_25),
1289 		      FIELD_PREP(CDM2_CRSN_QSEL_REASON_MASK(CRSN_25),
1290 				 CDM_CRSN_QSEL_Q1));
1291 }
1292 
1293 static int airoha_fe_init(struct airoha_eth *eth)
1294 {
1295 	airoha_fe_maccr_init(eth);
1296 
1297 	/* PSE IQ reserve */
1298 	airoha_fe_rmw(eth, REG_PSE_IQ_REV1, PSE_IQ_RES1_P2_MASK,
1299 		      FIELD_PREP(PSE_IQ_RES1_P2_MASK, 0x10));
1300 	airoha_fe_rmw(eth, REG_PSE_IQ_REV2,
1301 		      PSE_IQ_RES2_P5_MASK | PSE_IQ_RES2_P4_MASK,
1302 		      FIELD_PREP(PSE_IQ_RES2_P5_MASK, 0x40) |
1303 		      FIELD_PREP(PSE_IQ_RES2_P4_MASK, 0x34));
1304 
1305 	/* enable FE copy engine for MC/KA/DPI */
1306 	airoha_fe_wr(eth, REG_FE_PCE_CFG,
1307 		     PCE_DPI_EN_MASK | PCE_KA_EN_MASK | PCE_MC_EN_MASK);
1308 	/* set vip queue selection to ring 1 */
1309 	airoha_fe_rmw(eth, REG_CDM1_FWD_CFG, CDM1_VIP_QSEL_MASK,
1310 		      FIELD_PREP(CDM1_VIP_QSEL_MASK, 0x4));
1311 	airoha_fe_rmw(eth, REG_CDM2_FWD_CFG, CDM2_VIP_QSEL_MASK,
1312 		      FIELD_PREP(CDM2_VIP_QSEL_MASK, 0x4));
1313 	/* set GDM4 source interface offset to 8 */
1314 	airoha_fe_rmw(eth, REG_GDM4_SRC_PORT_SET,
1315 		      GDM4_SPORT_OFF2_MASK |
1316 		      GDM4_SPORT_OFF1_MASK |
1317 		      GDM4_SPORT_OFF0_MASK,
1318 		      FIELD_PREP(GDM4_SPORT_OFF2_MASK, 8) |
1319 		      FIELD_PREP(GDM4_SPORT_OFF1_MASK, 8) |
1320 		      FIELD_PREP(GDM4_SPORT_OFF0_MASK, 8));
1321 
1322 	/* set PSE Page as 128B */
1323 	airoha_fe_rmw(eth, REG_FE_DMA_GLO_CFG,
1324 		      FE_DMA_GLO_L2_SPACE_MASK | FE_DMA_GLO_PG_SZ_MASK,
1325 		      FIELD_PREP(FE_DMA_GLO_L2_SPACE_MASK, 2) |
1326 		      FE_DMA_GLO_PG_SZ_MASK);
1327 	airoha_fe_wr(eth, REG_FE_RST_GLO_CFG,
1328 		     FE_RST_CORE_MASK | FE_RST_GDM3_MBI_ARB_MASK |
1329 		     FE_RST_GDM4_MBI_ARB_MASK);
1330 	usleep_range(1000, 2000);
1331 
1332 	/* connect RxRing1 and RxRing15 to PSE Port0 OQ-1
1333 	 * connect other rings to PSE Port0 OQ-0
1334 	 */
1335 	airoha_fe_wr(eth, REG_FE_CDM1_OQ_MAP0, BIT(4));
1336 	airoha_fe_wr(eth, REG_FE_CDM1_OQ_MAP1, BIT(28));
1337 	airoha_fe_wr(eth, REG_FE_CDM1_OQ_MAP2, BIT(4));
1338 	airoha_fe_wr(eth, REG_FE_CDM1_OQ_MAP3, BIT(28));
1339 
1340 	airoha_fe_vip_setup(eth);
1341 	airoha_fe_pse_ports_init(eth);
1342 
1343 	airoha_fe_set(eth, REG_GDM_MISC_CFG,
1344 		      GDM2_RDM_ACK_WAIT_PREF_MASK |
1345 		      GDM2_CHN_VLD_MODE_MASK);
1346 	airoha_fe_rmw(eth, REG_CDM2_FWD_CFG, CDM2_OAM_QSEL_MASK, 15);
1347 
1348 	/* init fragment and assemble Force Port */
1349 	/* NPU Core-3, NPU Bridge Channel-3 */
1350 	airoha_fe_rmw(eth, REG_IP_FRAG_FP,
1351 		      IP_FRAGMENT_PORT_MASK | IP_FRAGMENT_NBQ_MASK,
1352 		      FIELD_PREP(IP_FRAGMENT_PORT_MASK, 6) |
1353 		      FIELD_PREP(IP_FRAGMENT_NBQ_MASK, 3));
1354 	/* QDMA LAN, RX Ring-22 */
1355 	airoha_fe_rmw(eth, REG_IP_FRAG_FP,
1356 		      IP_ASSEMBLE_PORT_MASK | IP_ASSEMBLE_NBQ_MASK,
1357 		      FIELD_PREP(IP_ASSEMBLE_PORT_MASK, 0) |
1358 		      FIELD_PREP(IP_ASSEMBLE_NBQ_MASK, 22));
1359 
1360 	airoha_fe_set(eth, REG_GDM3_FWD_CFG, GDM3_PAD_EN_MASK);
1361 	airoha_fe_set(eth, REG_GDM4_FWD_CFG, GDM4_PAD_EN_MASK);
1362 
1363 	airoha_fe_crsn_qsel_init(eth);
1364 
1365 	airoha_fe_clear(eth, REG_FE_CPORT_CFG, FE_CPORT_QUEUE_XFC_MASK);
1366 	airoha_fe_set(eth, REG_FE_CPORT_CFG, FE_CPORT_PORT_XFC_MASK);
1367 
1368 	/* default aging mode for mbi unlock issue */
1369 	airoha_fe_rmw(eth, REG_GDM2_CHN_RLS,
1370 		      MBI_RX_AGE_SEL_MASK | MBI_TX_AGE_SEL_MASK,
1371 		      FIELD_PREP(MBI_RX_AGE_SEL_MASK, 3) |
1372 		      FIELD_PREP(MBI_TX_AGE_SEL_MASK, 3));
1373 
1374 	/* disable IFC by default */
1375 	airoha_fe_clear(eth, REG_FE_CSR_IFC_CFG, FE_IFC_EN_MASK);
1376 
1377 	/* enable 1:N vlan action, init vlan table */
1378 	airoha_fe_set(eth, REG_MC_VLAN_EN, MC_VLAN_EN_MASK);
1379 
1380 	return airoha_fe_mc_vlan_clear(eth);
1381 }
1382 
1383 static int airoha_qdma_fill_rx_queue(struct airoha_queue *q)
1384 {
1385 	enum dma_data_direction dir = page_pool_get_dma_dir(q->page_pool);
1386 	struct airoha_eth *eth = q->eth;
1387 	int qid = q - &eth->q_rx[0];
1388 	int nframes = 0;
1389 
1390 	while (q->queued < q->ndesc - 1) {
1391 		struct airoha_queue_entry *e = &q->entry[q->head];
1392 		struct airoha_qdma_desc *desc = &q->desc[q->head];
1393 		struct page *page;
1394 		int offset;
1395 		u32 val;
1396 
1397 		page = page_pool_dev_alloc_frag(q->page_pool, &offset,
1398 						q->buf_size);
1399 		if (!page)
1400 			break;
1401 
1402 		q->head = (q->head + 1) % q->ndesc;
1403 		q->queued++;
1404 		nframes++;
1405 
1406 		e->buf = page_address(page) + offset;
1407 		e->dma_addr = page_pool_get_dma_addr(page) + offset;
1408 		e->dma_len = SKB_WITH_OVERHEAD(q->buf_size);
1409 
1410 		dma_sync_single_for_device(eth->dev, e->dma_addr, e->dma_len,
1411 					   dir);
1412 
1413 		val = FIELD_PREP(QDMA_DESC_LEN_MASK, e->dma_len);
1414 		WRITE_ONCE(desc->ctrl, cpu_to_le32(val));
1415 		WRITE_ONCE(desc->addr, cpu_to_le32(e->dma_addr));
1416 		val = FIELD_PREP(QDMA_DESC_NEXT_ID_MASK, q->head);
1417 		WRITE_ONCE(desc->data, cpu_to_le32(val));
1418 		WRITE_ONCE(desc->msg0, 0);
1419 		WRITE_ONCE(desc->msg1, 0);
1420 		WRITE_ONCE(desc->msg2, 0);
1421 		WRITE_ONCE(desc->msg3, 0);
1422 
1423 		airoha_qdma_rmw(eth, REG_RX_CPU_IDX(qid), RX_RING_CPU_IDX_MASK,
1424 				FIELD_PREP(RX_RING_CPU_IDX_MASK, q->head));
1425 	}
1426 
1427 	return nframes;
1428 }
1429 
1430 static int airoha_qdma_get_gdm_port(struct airoha_eth *eth,
1431 				    struct airoha_qdma_desc *desc)
1432 {
1433 	u32 port, sport, msg1 = le32_to_cpu(desc->msg1);
1434 
1435 	sport = FIELD_GET(QDMA_ETH_RXMSG_SPORT_MASK, msg1);
1436 	switch (sport) {
1437 	case 0x10 ... 0x13:
1438 		port = 0;
1439 		break;
1440 	case 0x2 ... 0x4:
1441 		port = sport - 1;
1442 		break;
1443 	default:
1444 		return -EINVAL;
1445 	}
1446 
1447 	return port >= ARRAY_SIZE(eth->ports) ? -EINVAL : port;
1448 }
1449 
1450 static int airoha_qdma_rx_process(struct airoha_queue *q, int budget)
1451 {
1452 	enum dma_data_direction dir = page_pool_get_dma_dir(q->page_pool);
1453 	struct airoha_eth *eth = q->eth;
1454 	int qid = q - &eth->q_rx[0];
1455 	int done = 0;
1456 
1457 	while (done < budget) {
1458 		struct airoha_queue_entry *e = &q->entry[q->tail];
1459 		struct airoha_qdma_desc *desc = &q->desc[q->tail];
1460 		dma_addr_t dma_addr = le32_to_cpu(desc->addr);
1461 		u32 desc_ctrl = le32_to_cpu(desc->ctrl);
1462 		struct sk_buff *skb;
1463 		int len, p;
1464 
1465 		if (!(desc_ctrl & QDMA_DESC_DONE_MASK))
1466 			break;
1467 
1468 		if (!dma_addr)
1469 			break;
1470 
1471 		len = FIELD_GET(QDMA_DESC_LEN_MASK, desc_ctrl);
1472 		if (!len)
1473 			break;
1474 
1475 		q->tail = (q->tail + 1) % q->ndesc;
1476 		q->queued--;
1477 
1478 		dma_sync_single_for_cpu(eth->dev, dma_addr,
1479 					SKB_WITH_OVERHEAD(q->buf_size), dir);
1480 
1481 		p = airoha_qdma_get_gdm_port(eth, desc);
1482 		if (p < 0 || !eth->ports[p]) {
1483 			page_pool_put_full_page(q->page_pool,
1484 						virt_to_head_page(e->buf),
1485 						true);
1486 			continue;
1487 		}
1488 
1489 		skb = napi_build_skb(e->buf, q->buf_size);
1490 		if (!skb) {
1491 			page_pool_put_full_page(q->page_pool,
1492 						virt_to_head_page(e->buf),
1493 						true);
1494 			break;
1495 		}
1496 
1497 		skb_reserve(skb, 2);
1498 		__skb_put(skb, len);
1499 		skb_mark_for_recycle(skb);
1500 		skb->dev = eth->ports[p]->dev;
1501 		skb->protocol = eth_type_trans(skb, skb->dev);
1502 		skb->ip_summed = CHECKSUM_UNNECESSARY;
1503 		skb_record_rx_queue(skb, qid);
1504 		napi_gro_receive(&q->napi, skb);
1505 
1506 		done++;
1507 	}
1508 	airoha_qdma_fill_rx_queue(q);
1509 
1510 	return done;
1511 }
1512 
1513 static int airoha_qdma_rx_napi_poll(struct napi_struct *napi, int budget)
1514 {
1515 	struct airoha_queue *q = container_of(napi, struct airoha_queue, napi);
1516 	struct airoha_eth *eth = q->eth;
1517 	int cur, done = 0;
1518 
1519 	do {
1520 		cur = airoha_qdma_rx_process(q, budget - done);
1521 		done += cur;
1522 	} while (cur && done < budget);
1523 
1524 	if (done < budget && napi_complete(napi))
1525 		airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX1,
1526 				       RX_DONE_INT_MASK);
1527 
1528 	return done;
1529 }
1530 
1531 static int airoha_qdma_init_rx_queue(struct airoha_eth *eth,
1532 				     struct airoha_queue *q, int ndesc)
1533 {
1534 	const struct page_pool_params pp_params = {
1535 		.order = 0,
1536 		.pool_size = 256,
1537 		.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
1538 		.dma_dir = DMA_FROM_DEVICE,
1539 		.max_len = PAGE_SIZE,
1540 		.nid = NUMA_NO_NODE,
1541 		.dev = eth->dev,
1542 		.napi = &q->napi,
1543 	};
1544 	int qid = q - &eth->q_rx[0], thr;
1545 	dma_addr_t dma_addr;
1546 
1547 	q->buf_size = PAGE_SIZE / 2;
1548 	q->ndesc = ndesc;
1549 	q->eth = eth;
1550 
1551 	q->entry = devm_kzalloc(eth->dev, q->ndesc * sizeof(*q->entry),
1552 				GFP_KERNEL);
1553 	if (!q->entry)
1554 		return -ENOMEM;
1555 
1556 	q->page_pool = page_pool_create(&pp_params);
1557 	if (IS_ERR(q->page_pool)) {
1558 		int err = PTR_ERR(q->page_pool);
1559 
1560 		q->page_pool = NULL;
1561 		return err;
1562 	}
1563 
1564 	q->desc = dmam_alloc_coherent(eth->dev, q->ndesc * sizeof(*q->desc),
1565 				      &dma_addr, GFP_KERNEL);
1566 	if (!q->desc)
1567 		return -ENOMEM;
1568 
1569 	netif_napi_add(eth->napi_dev, &q->napi, airoha_qdma_rx_napi_poll);
1570 
1571 	airoha_qdma_wr(eth, REG_RX_RING_BASE(qid), dma_addr);
1572 	airoha_qdma_rmw(eth, REG_RX_RING_SIZE(qid), RX_RING_SIZE_MASK,
1573 			FIELD_PREP(RX_RING_SIZE_MASK, ndesc));
1574 
1575 	thr = clamp(ndesc >> 3, 1, 32);
1576 	airoha_qdma_rmw(eth, REG_RX_RING_SIZE(qid), RX_RING_THR_MASK,
1577 			FIELD_PREP(RX_RING_THR_MASK, thr));
1578 	airoha_qdma_rmw(eth, REG_RX_DMA_IDX(qid), RX_RING_DMA_IDX_MASK,
1579 			FIELD_PREP(RX_RING_DMA_IDX_MASK, q->head));
1580 
1581 	airoha_qdma_fill_rx_queue(q);
1582 
1583 	return 0;
1584 }
1585 
1586 static void airoha_qdma_cleanup_rx_queue(struct airoha_queue *q)
1587 {
1588 	struct airoha_eth *eth = q->eth;
1589 
1590 	while (q->queued) {
1591 		struct airoha_queue_entry *e = &q->entry[q->tail];
1592 		struct page *page = virt_to_head_page(e->buf);
1593 
1594 		dma_sync_single_for_cpu(eth->dev, e->dma_addr, e->dma_len,
1595 					page_pool_get_dma_dir(q->page_pool));
1596 		page_pool_put_full_page(q->page_pool, page, false);
1597 		q->tail = (q->tail + 1) % q->ndesc;
1598 		q->queued--;
1599 	}
1600 }
1601 
1602 static int airoha_qdma_init_rx(struct airoha_eth *eth)
1603 {
1604 	int i;
1605 
1606 	for (i = 0; i < ARRAY_SIZE(eth->q_rx); i++) {
1607 		int err;
1608 
1609 		if (!(RX_DONE_INT_MASK & BIT(i))) {
1610 			/* rx-queue not binded to irq */
1611 			continue;
1612 		}
1613 
1614 		err = airoha_qdma_init_rx_queue(eth, &eth->q_rx[i],
1615 						RX_DSCP_NUM(i));
1616 		if (err)
1617 			return err;
1618 	}
1619 
1620 	return 0;
1621 }
1622 
1623 static int airoha_qdma_tx_napi_poll(struct napi_struct *napi, int budget)
1624 {
1625 	struct airoha_tx_irq_queue *irq_q;
1626 	struct airoha_eth *eth;
1627 	int id, done = 0;
1628 
1629 	irq_q = container_of(napi, struct airoha_tx_irq_queue, napi);
1630 	eth = irq_q->eth;
1631 	id = irq_q - &eth->q_tx_irq[0];
1632 
1633 	while (irq_q->queued > 0 && done < budget) {
1634 		u32 qid, last, val = irq_q->q[irq_q->head];
1635 		struct airoha_queue *q;
1636 
1637 		if (val == 0xff)
1638 			break;
1639 
1640 		irq_q->q[irq_q->head] = 0xff; /* mark as done */
1641 		irq_q->head = (irq_q->head + 1) % irq_q->size;
1642 		irq_q->queued--;
1643 		done++;
1644 
1645 		last = FIELD_GET(IRQ_DESC_IDX_MASK, val);
1646 		qid = FIELD_GET(IRQ_RING_IDX_MASK, val);
1647 
1648 		if (qid >= ARRAY_SIZE(eth->q_tx))
1649 			continue;
1650 
1651 		q = &eth->q_tx[qid];
1652 		if (!q->ndesc)
1653 			continue;
1654 
1655 		spin_lock_bh(&q->lock);
1656 
1657 		while (q->queued > 0) {
1658 			struct airoha_qdma_desc *desc = &q->desc[q->tail];
1659 			struct airoha_queue_entry *e = &q->entry[q->tail];
1660 			u32 desc_ctrl = le32_to_cpu(desc->ctrl);
1661 			struct sk_buff *skb = e->skb;
1662 			u16 index = q->tail;
1663 
1664 			if (!(desc_ctrl & QDMA_DESC_DONE_MASK) &&
1665 			    !(desc_ctrl & QDMA_DESC_DROP_MASK))
1666 				break;
1667 
1668 			q->tail = (q->tail + 1) % q->ndesc;
1669 			q->queued--;
1670 
1671 			dma_unmap_single(eth->dev, e->dma_addr, e->dma_len,
1672 					 DMA_TO_DEVICE);
1673 
1674 			WRITE_ONCE(desc->msg0, 0);
1675 			WRITE_ONCE(desc->msg1, 0);
1676 
1677 			if (skb) {
1678 				struct netdev_queue *txq;
1679 
1680 				txq = netdev_get_tx_queue(skb->dev, qid);
1681 				if (netif_tx_queue_stopped(txq) &&
1682 				    q->ndesc - q->queued >= q->free_thr)
1683 					netif_tx_wake_queue(txq);
1684 
1685 				dev_kfree_skb_any(skb);
1686 				e->skb = NULL;
1687 			}
1688 
1689 			if (index == last)
1690 				break;
1691 		}
1692 
1693 		spin_unlock_bh(&q->lock);
1694 	}
1695 
1696 	if (done) {
1697 		int i, len = done >> 7;
1698 
1699 		for (i = 0; i < len; i++)
1700 			airoha_qdma_rmw(eth, REG_IRQ_CLEAR_LEN(id),
1701 					IRQ_CLEAR_LEN_MASK, 0x80);
1702 		airoha_qdma_rmw(eth, REG_IRQ_CLEAR_LEN(id),
1703 				IRQ_CLEAR_LEN_MASK, (done & 0x7f));
1704 	}
1705 
1706 	if (done < budget && napi_complete(napi))
1707 		airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX0,
1708 				       TX_DONE_INT_MASK(id));
1709 
1710 	return done;
1711 }
1712 
1713 static int airoha_qdma_init_tx_queue(struct airoha_eth *eth,
1714 				     struct airoha_queue *q, int size)
1715 {
1716 	int i, qid = q - &eth->q_tx[0];
1717 	dma_addr_t dma_addr;
1718 
1719 	spin_lock_init(&q->lock);
1720 	q->ndesc = size;
1721 	q->eth = eth;
1722 	q->free_thr = 1 + MAX_SKB_FRAGS;
1723 
1724 	q->entry = devm_kzalloc(eth->dev, q->ndesc * sizeof(*q->entry),
1725 				GFP_KERNEL);
1726 	if (!q->entry)
1727 		return -ENOMEM;
1728 
1729 	q->desc = dmam_alloc_coherent(eth->dev, q->ndesc * sizeof(*q->desc),
1730 				      &dma_addr, GFP_KERNEL);
1731 	if (!q->desc)
1732 		return -ENOMEM;
1733 
1734 	for (i = 0; i < q->ndesc; i++) {
1735 		u32 val;
1736 
1737 		val = FIELD_PREP(QDMA_DESC_DONE_MASK, 1);
1738 		WRITE_ONCE(q->desc[i].ctrl, cpu_to_le32(val));
1739 	}
1740 
1741 	airoha_qdma_wr(eth, REG_TX_RING_BASE(qid), dma_addr);
1742 	airoha_qdma_rmw(eth, REG_TX_CPU_IDX(qid), TX_RING_CPU_IDX_MASK,
1743 			FIELD_PREP(TX_RING_CPU_IDX_MASK, q->head));
1744 	airoha_qdma_rmw(eth, REG_TX_DMA_IDX(qid), TX_RING_DMA_IDX_MASK,
1745 			FIELD_PREP(TX_RING_DMA_IDX_MASK, q->head));
1746 
1747 	return 0;
1748 }
1749 
1750 static int airoha_qdma_tx_irq_init(struct airoha_eth *eth,
1751 				   struct airoha_tx_irq_queue *irq_q,
1752 				   int size)
1753 {
1754 	int id = irq_q - &eth->q_tx_irq[0];
1755 	dma_addr_t dma_addr;
1756 
1757 	netif_napi_add_tx(eth->napi_dev, &irq_q->napi,
1758 			  airoha_qdma_tx_napi_poll);
1759 	irq_q->q = dmam_alloc_coherent(eth->dev, size * sizeof(u32),
1760 				       &dma_addr, GFP_KERNEL);
1761 	if (!irq_q->q)
1762 		return -ENOMEM;
1763 
1764 	memset(irq_q->q, 0xff, size * sizeof(u32));
1765 	irq_q->size = size;
1766 	irq_q->eth = eth;
1767 
1768 	airoha_qdma_wr(eth, REG_TX_IRQ_BASE(id), dma_addr);
1769 	airoha_qdma_rmw(eth, REG_TX_IRQ_CFG(id), TX_IRQ_DEPTH_MASK,
1770 			FIELD_PREP(TX_IRQ_DEPTH_MASK, size));
1771 	airoha_qdma_rmw(eth, REG_TX_IRQ_CFG(id), TX_IRQ_THR_MASK,
1772 			FIELD_PREP(TX_IRQ_THR_MASK, 1));
1773 
1774 	return 0;
1775 }
1776 
1777 static int airoha_qdma_init_tx(struct airoha_eth *eth)
1778 {
1779 	int i, err;
1780 
1781 	for (i = 0; i < ARRAY_SIZE(eth->q_tx_irq); i++) {
1782 		err = airoha_qdma_tx_irq_init(eth, &eth->q_tx_irq[i],
1783 					      IRQ_QUEUE_LEN(i));
1784 		if (err)
1785 			return err;
1786 	}
1787 
1788 	for (i = 0; i < ARRAY_SIZE(eth->q_tx); i++) {
1789 		err = airoha_qdma_init_tx_queue(eth, &eth->q_tx[i],
1790 						TX_DSCP_NUM);
1791 		if (err)
1792 			return err;
1793 	}
1794 
1795 	return 0;
1796 }
1797 
1798 static void airoha_qdma_cleanup_tx_queue(struct airoha_queue *q)
1799 {
1800 	struct airoha_eth *eth = q->eth;
1801 
1802 	spin_lock_bh(&q->lock);
1803 	while (q->queued) {
1804 		struct airoha_queue_entry *e = &q->entry[q->tail];
1805 
1806 		dma_unmap_single(eth->dev, e->dma_addr, e->dma_len,
1807 				 DMA_TO_DEVICE);
1808 		dev_kfree_skb_any(e->skb);
1809 		e->skb = NULL;
1810 
1811 		q->tail = (q->tail + 1) % q->ndesc;
1812 		q->queued--;
1813 	}
1814 	spin_unlock_bh(&q->lock);
1815 }
1816 
1817 static int airoha_qdma_init_hfwd_queues(struct airoha_eth *eth)
1818 {
1819 	dma_addr_t dma_addr;
1820 	u32 status;
1821 	int size;
1822 
1823 	size = HW_DSCP_NUM * sizeof(struct airoha_qdma_fwd_desc);
1824 	eth->hfwd.desc = dmam_alloc_coherent(eth->dev, size, &dma_addr,
1825 					     GFP_KERNEL);
1826 	if (!eth->hfwd.desc)
1827 		return -ENOMEM;
1828 
1829 	airoha_qdma_wr(eth, REG_FWD_DSCP_BASE, dma_addr);
1830 
1831 	size = AIROHA_MAX_PACKET_SIZE * HW_DSCP_NUM;
1832 	eth->hfwd.q = dmam_alloc_coherent(eth->dev, size, &dma_addr,
1833 					  GFP_KERNEL);
1834 	if (!eth->hfwd.q)
1835 		return -ENOMEM;
1836 
1837 	airoha_qdma_wr(eth, REG_FWD_BUF_BASE, dma_addr);
1838 
1839 	airoha_qdma_rmw(eth, REG_HW_FWD_DSCP_CFG,
1840 			HW_FWD_DSCP_PAYLOAD_SIZE_MASK,
1841 			FIELD_PREP(HW_FWD_DSCP_PAYLOAD_SIZE_MASK, 0));
1842 	airoha_qdma_rmw(eth, REG_FWD_DSCP_LOW_THR, FWD_DSCP_LOW_THR_MASK,
1843 			FIELD_PREP(FWD_DSCP_LOW_THR_MASK, 128));
1844 	airoha_qdma_rmw(eth, REG_LMGR_INIT_CFG,
1845 			LMGR_INIT_START | LMGR_SRAM_MODE_MASK |
1846 			HW_FWD_DESC_NUM_MASK,
1847 			FIELD_PREP(HW_FWD_DESC_NUM_MASK, HW_DSCP_NUM) |
1848 			LMGR_INIT_START);
1849 
1850 	return read_poll_timeout(airoha_qdma_rr, status,
1851 				 !(status & LMGR_INIT_START), USEC_PER_MSEC,
1852 				 30 * USEC_PER_MSEC, true, eth,
1853 				 REG_LMGR_INIT_CFG);
1854 }
1855 
1856 static void airoha_qdma_init_qos(struct airoha_eth *eth)
1857 {
1858 	airoha_qdma_clear(eth, REG_TXWRR_MODE_CFG, TWRR_WEIGHT_SCALE_MASK);
1859 	airoha_qdma_set(eth, REG_TXWRR_MODE_CFG, TWRR_WEIGHT_BASE_MASK);
1860 
1861 	airoha_qdma_clear(eth, REG_PSE_BUF_USAGE_CFG,
1862 			  PSE_BUF_ESTIMATE_EN_MASK);
1863 
1864 	airoha_qdma_set(eth, REG_EGRESS_RATE_METER_CFG,
1865 			EGRESS_RATE_METER_EN_MASK |
1866 			EGRESS_RATE_METER_EQ_RATE_EN_MASK);
1867 	/* 2047us x 31 = 63.457ms */
1868 	airoha_qdma_rmw(eth, REG_EGRESS_RATE_METER_CFG,
1869 			EGRESS_RATE_METER_WINDOW_SZ_MASK,
1870 			FIELD_PREP(EGRESS_RATE_METER_WINDOW_SZ_MASK, 0x1f));
1871 	airoha_qdma_rmw(eth, REG_EGRESS_RATE_METER_CFG,
1872 			EGRESS_RATE_METER_TIMESLICE_MASK,
1873 			FIELD_PREP(EGRESS_RATE_METER_TIMESLICE_MASK, 0x7ff));
1874 
1875 	/* ratelimit init */
1876 	airoha_qdma_set(eth, REG_GLB_TRTCM_CFG, GLB_TRTCM_EN_MASK);
1877 	/* fast-tick 25us */
1878 	airoha_qdma_rmw(eth, REG_GLB_TRTCM_CFG, GLB_FAST_TICK_MASK,
1879 			FIELD_PREP(GLB_FAST_TICK_MASK, 25));
1880 	airoha_qdma_rmw(eth, REG_GLB_TRTCM_CFG, GLB_SLOW_TICK_RATIO_MASK,
1881 			FIELD_PREP(GLB_SLOW_TICK_RATIO_MASK, 40));
1882 
1883 	airoha_qdma_set(eth, REG_EGRESS_TRTCM_CFG, EGRESS_TRTCM_EN_MASK);
1884 	airoha_qdma_rmw(eth, REG_EGRESS_TRTCM_CFG, EGRESS_FAST_TICK_MASK,
1885 			FIELD_PREP(EGRESS_FAST_TICK_MASK, 25));
1886 	airoha_qdma_rmw(eth, REG_EGRESS_TRTCM_CFG,
1887 			EGRESS_SLOW_TICK_RATIO_MASK,
1888 			FIELD_PREP(EGRESS_SLOW_TICK_RATIO_MASK, 40));
1889 
1890 	airoha_qdma_set(eth, REG_INGRESS_TRTCM_CFG, INGRESS_TRTCM_EN_MASK);
1891 	airoha_qdma_clear(eth, REG_INGRESS_TRTCM_CFG,
1892 			  INGRESS_TRTCM_MODE_MASK);
1893 	airoha_qdma_rmw(eth, REG_INGRESS_TRTCM_CFG, INGRESS_FAST_TICK_MASK,
1894 			FIELD_PREP(INGRESS_FAST_TICK_MASK, 125));
1895 	airoha_qdma_rmw(eth, REG_INGRESS_TRTCM_CFG,
1896 			INGRESS_SLOW_TICK_RATIO_MASK,
1897 			FIELD_PREP(INGRESS_SLOW_TICK_RATIO_MASK, 8));
1898 
1899 	airoha_qdma_set(eth, REG_SLA_TRTCM_CFG, SLA_TRTCM_EN_MASK);
1900 	airoha_qdma_rmw(eth, REG_SLA_TRTCM_CFG, SLA_FAST_TICK_MASK,
1901 			FIELD_PREP(SLA_FAST_TICK_MASK, 25));
1902 	airoha_qdma_rmw(eth, REG_SLA_TRTCM_CFG, SLA_SLOW_TICK_RATIO_MASK,
1903 			FIELD_PREP(SLA_SLOW_TICK_RATIO_MASK, 40));
1904 }
1905 
1906 static int airoha_qdma_hw_init(struct airoha_eth *eth)
1907 {
1908 	int i;
1909 
1910 	/* clear pending irqs */
1911 	for (i = 0; i < ARRAY_SIZE(eth->irqmask); i++)
1912 		airoha_qdma_wr(eth, REG_INT_STATUS(i), 0xffffffff);
1913 
1914 	/* setup irqs */
1915 	airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX0, INT_IDX0_MASK);
1916 	airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX1, INT_IDX1_MASK);
1917 	airoha_qdma_irq_enable(eth, QDMA_INT_REG_IDX4, INT_IDX4_MASK);
1918 
1919 	/* setup irq binding */
1920 	for (i = 0; i < ARRAY_SIZE(eth->q_tx); i++) {
1921 		if (!eth->q_tx[i].ndesc)
1922 			continue;
1923 
1924 		if (TX_RING_IRQ_BLOCKING_MAP_MASK & BIT(i))
1925 			airoha_qdma_set(eth, REG_TX_RING_BLOCKING(i),
1926 					TX_RING_IRQ_BLOCKING_CFG_MASK);
1927 		else
1928 			airoha_qdma_clear(eth, REG_TX_RING_BLOCKING(i),
1929 					  TX_RING_IRQ_BLOCKING_CFG_MASK);
1930 	}
1931 
1932 	airoha_qdma_wr(eth, REG_QDMA_GLOBAL_CFG,
1933 		       GLOBAL_CFG_RX_2B_OFFSET_MASK |
1934 		       FIELD_PREP(GLOBAL_CFG_DMA_PREFERENCE_MASK, 3) |
1935 		       GLOBAL_CFG_CPU_TXR_RR_MASK |
1936 		       GLOBAL_CFG_PAYLOAD_BYTE_SWAP_MASK |
1937 		       GLOBAL_CFG_MULTICAST_MODIFY_FP_MASK |
1938 		       GLOBAL_CFG_MULTICAST_EN_MASK |
1939 		       GLOBAL_CFG_IRQ0_EN_MASK | GLOBAL_CFG_IRQ1_EN_MASK |
1940 		       GLOBAL_CFG_TX_WB_DONE_MASK |
1941 		       FIELD_PREP(GLOBAL_CFG_MAX_ISSUE_NUM_MASK, 2));
1942 
1943 	airoha_qdma_init_qos(eth);
1944 
1945 	/* disable qdma rx delay interrupt */
1946 	for (i = 0; i < ARRAY_SIZE(eth->q_rx); i++) {
1947 		if (!eth->q_rx[i].ndesc)
1948 			continue;
1949 
1950 		airoha_qdma_clear(eth, REG_RX_DELAY_INT_IDX(i),
1951 				  RX_DELAY_INT_MASK);
1952 	}
1953 
1954 	airoha_qdma_set(eth, REG_TXQ_CNGST_CFG,
1955 			TXQ_CNGST_DROP_EN | TXQ_CNGST_DEI_DROP_EN);
1956 
1957 	return 0;
1958 }
1959 
1960 static irqreturn_t airoha_irq_handler(int irq, void *dev_instance)
1961 {
1962 	struct airoha_eth *eth = dev_instance;
1963 	u32 intr[ARRAY_SIZE(eth->irqmask)];
1964 	int i;
1965 
1966 	for (i = 0; i < ARRAY_SIZE(eth->irqmask); i++) {
1967 		intr[i] = airoha_qdma_rr(eth, REG_INT_STATUS(i));
1968 		intr[i] &= eth->irqmask[i];
1969 		airoha_qdma_wr(eth, REG_INT_STATUS(i), intr[i]);
1970 	}
1971 
1972 	if (!test_bit(DEV_STATE_INITIALIZED, &eth->state))
1973 		return IRQ_NONE;
1974 
1975 	if (intr[1] & RX_DONE_INT_MASK) {
1976 		airoha_qdma_irq_disable(eth, QDMA_INT_REG_IDX1,
1977 					RX_DONE_INT_MASK);
1978 
1979 		for (i = 0; i < ARRAY_SIZE(eth->q_rx); i++) {
1980 			if (!eth->q_rx[i].ndesc)
1981 				continue;
1982 
1983 			if (intr[1] & BIT(i))
1984 				napi_schedule(&eth->q_rx[i].napi);
1985 		}
1986 	}
1987 
1988 	if (intr[0] & INT_TX_MASK) {
1989 		for (i = 0; i < ARRAY_SIZE(eth->q_tx_irq); i++) {
1990 			struct airoha_tx_irq_queue *irq_q = &eth->q_tx_irq[i];
1991 			u32 status, head;
1992 
1993 			if (!(intr[0] & TX_DONE_INT_MASK(i)))
1994 				continue;
1995 
1996 			airoha_qdma_irq_disable(eth, QDMA_INT_REG_IDX0,
1997 						TX_DONE_INT_MASK(i));
1998 
1999 			status = airoha_qdma_rr(eth, REG_IRQ_STATUS(i));
2000 			head = FIELD_GET(IRQ_HEAD_IDX_MASK, status);
2001 			irq_q->head = head % irq_q->size;
2002 			irq_q->queued = FIELD_GET(IRQ_ENTRY_LEN_MASK, status);
2003 
2004 			napi_schedule(&eth->q_tx_irq[i].napi);
2005 		}
2006 	}
2007 
2008 	return IRQ_HANDLED;
2009 }
2010 
2011 static int airoha_qdma_init(struct airoha_eth *eth)
2012 {
2013 	int err;
2014 
2015 	err = devm_request_irq(eth->dev, eth->irq, airoha_irq_handler,
2016 			       IRQF_SHARED, KBUILD_MODNAME, eth);
2017 	if (err)
2018 		return err;
2019 
2020 	err = airoha_qdma_init_rx(eth);
2021 	if (err)
2022 		return err;
2023 
2024 	err = airoha_qdma_init_tx(eth);
2025 	if (err)
2026 		return err;
2027 
2028 	err = airoha_qdma_init_hfwd_queues(eth);
2029 	if (err)
2030 		return err;
2031 
2032 	err = airoha_qdma_hw_init(eth);
2033 	if (err)
2034 		return err;
2035 
2036 	set_bit(DEV_STATE_INITIALIZED, &eth->state);
2037 
2038 	return 0;
2039 }
2040 
2041 static int airoha_hw_init(struct airoha_eth *eth)
2042 {
2043 	int err;
2044 
2045 	/* disable xsi */
2046 	reset_control_bulk_assert(ARRAY_SIZE(eth->xsi_rsts), eth->xsi_rsts);
2047 
2048 	reset_control_bulk_assert(ARRAY_SIZE(eth->rsts), eth->rsts);
2049 	msleep(20);
2050 	reset_control_bulk_deassert(ARRAY_SIZE(eth->rsts), eth->rsts);
2051 	msleep(20);
2052 
2053 	err = airoha_fe_init(eth);
2054 	if (err)
2055 		return err;
2056 
2057 	return airoha_qdma_init(eth);
2058 }
2059 
2060 static void airoha_hw_cleanup(struct airoha_eth *eth)
2061 {
2062 	int i;
2063 
2064 	for (i = 0; i < ARRAY_SIZE(eth->q_rx); i++) {
2065 		if (!eth->q_rx[i].ndesc)
2066 			continue;
2067 
2068 		napi_disable(&eth->q_rx[i].napi);
2069 		netif_napi_del(&eth->q_rx[i].napi);
2070 		airoha_qdma_cleanup_rx_queue(&eth->q_rx[i]);
2071 		if (eth->q_rx[i].page_pool)
2072 			page_pool_destroy(eth->q_rx[i].page_pool);
2073 	}
2074 
2075 	for (i = 0; i < ARRAY_SIZE(eth->q_tx_irq); i++) {
2076 		napi_disable(&eth->q_tx_irq[i].napi);
2077 		netif_napi_del(&eth->q_tx_irq[i].napi);
2078 	}
2079 
2080 	for (i = 0; i < ARRAY_SIZE(eth->q_tx); i++) {
2081 		if (!eth->q_tx[i].ndesc)
2082 			continue;
2083 
2084 		airoha_qdma_cleanup_tx_queue(&eth->q_tx[i]);
2085 	}
2086 }
2087 
2088 static void airoha_qdma_start_napi(struct airoha_eth *eth)
2089 {
2090 	int i;
2091 
2092 	for (i = 0; i < ARRAY_SIZE(eth->q_tx_irq); i++)
2093 		napi_enable(&eth->q_tx_irq[i].napi);
2094 
2095 	for (i = 0; i < ARRAY_SIZE(eth->q_rx); i++) {
2096 		if (!eth->q_rx[i].ndesc)
2097 			continue;
2098 
2099 		napi_enable(&eth->q_rx[i].napi);
2100 	}
2101 }
2102 
2103 static void airoha_update_hw_stats(struct airoha_gdm_port *port)
2104 {
2105 	struct airoha_eth *eth = port->eth;
2106 	u32 val, i = 0;
2107 
2108 	spin_lock(&port->stats.lock);
2109 	u64_stats_update_begin(&port->stats.syncp);
2110 
2111 	/* TX */
2112 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_OK_PKT_CNT_H(port->id));
2113 	port->stats.tx_ok_pkts += ((u64)val << 32);
2114 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_OK_PKT_CNT_L(port->id));
2115 	port->stats.tx_ok_pkts += val;
2116 
2117 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_OK_BYTE_CNT_H(port->id));
2118 	port->stats.tx_ok_bytes += ((u64)val << 32);
2119 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_OK_BYTE_CNT_L(port->id));
2120 	port->stats.tx_ok_bytes += val;
2121 
2122 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_DROP_CNT(port->id));
2123 	port->stats.tx_drops += val;
2124 
2125 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_BC_CNT(port->id));
2126 	port->stats.tx_broadcast += val;
2127 
2128 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_MC_CNT(port->id));
2129 	port->stats.tx_multicast += val;
2130 
2131 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_RUNT_CNT(port->id));
2132 	port->stats.tx_len[i] += val;
2133 
2134 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_E64_CNT_H(port->id));
2135 	port->stats.tx_len[i] += ((u64)val << 32);
2136 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_E64_CNT_L(port->id));
2137 	port->stats.tx_len[i++] += val;
2138 
2139 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L64_CNT_H(port->id));
2140 	port->stats.tx_len[i] += ((u64)val << 32);
2141 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L64_CNT_L(port->id));
2142 	port->stats.tx_len[i++] += val;
2143 
2144 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L127_CNT_H(port->id));
2145 	port->stats.tx_len[i] += ((u64)val << 32);
2146 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L127_CNT_L(port->id));
2147 	port->stats.tx_len[i++] += val;
2148 
2149 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L255_CNT_H(port->id));
2150 	port->stats.tx_len[i] += ((u64)val << 32);
2151 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L255_CNT_L(port->id));
2152 	port->stats.tx_len[i++] += val;
2153 
2154 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L511_CNT_H(port->id));
2155 	port->stats.tx_len[i] += ((u64)val << 32);
2156 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L511_CNT_L(port->id));
2157 	port->stats.tx_len[i++] += val;
2158 
2159 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L1023_CNT_H(port->id));
2160 	port->stats.tx_len[i] += ((u64)val << 32);
2161 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_L1023_CNT_L(port->id));
2162 	port->stats.tx_len[i++] += val;
2163 
2164 	val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_LONG_CNT(port->id));
2165 	port->stats.tx_len[i++] += val;
2166 
2167 	/* RX */
2168 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_OK_PKT_CNT_H(port->id));
2169 	port->stats.rx_ok_pkts += ((u64)val << 32);
2170 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_OK_PKT_CNT_L(port->id));
2171 	port->stats.rx_ok_pkts += val;
2172 
2173 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_OK_BYTE_CNT_H(port->id));
2174 	port->stats.rx_ok_bytes += ((u64)val << 32);
2175 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_OK_BYTE_CNT_L(port->id));
2176 	port->stats.rx_ok_bytes += val;
2177 
2178 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_DROP_CNT(port->id));
2179 	port->stats.rx_drops += val;
2180 
2181 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_BC_CNT(port->id));
2182 	port->stats.rx_broadcast += val;
2183 
2184 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_MC_CNT(port->id));
2185 	port->stats.rx_multicast += val;
2186 
2187 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ERROR_DROP_CNT(port->id));
2188 	port->stats.rx_errors += val;
2189 
2190 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_CRC_ERR_CNT(port->id));
2191 	port->stats.rx_crc_error += val;
2192 
2193 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_OVERFLOW_DROP_CNT(port->id));
2194 	port->stats.rx_over_errors += val;
2195 
2196 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_FRAG_CNT(port->id));
2197 	port->stats.rx_fragment += val;
2198 
2199 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_JABBER_CNT(port->id));
2200 	port->stats.rx_jabber += val;
2201 
2202 	i = 0;
2203 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_RUNT_CNT(port->id));
2204 	port->stats.rx_len[i] += val;
2205 
2206 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_E64_CNT_H(port->id));
2207 	port->stats.rx_len[i] += ((u64)val << 32);
2208 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_E64_CNT_L(port->id));
2209 	port->stats.rx_len[i++] += val;
2210 
2211 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L64_CNT_H(port->id));
2212 	port->stats.rx_len[i] += ((u64)val << 32);
2213 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L64_CNT_L(port->id));
2214 	port->stats.rx_len[i++] += val;
2215 
2216 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L127_CNT_H(port->id));
2217 	port->stats.rx_len[i] += ((u64)val << 32);
2218 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L127_CNT_L(port->id));
2219 	port->stats.rx_len[i++] += val;
2220 
2221 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L255_CNT_H(port->id));
2222 	port->stats.rx_len[i] += ((u64)val << 32);
2223 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L255_CNT_L(port->id));
2224 	port->stats.rx_len[i++] += val;
2225 
2226 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L511_CNT_H(port->id));
2227 	port->stats.rx_len[i] += ((u64)val << 32);
2228 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L511_CNT_L(port->id));
2229 	port->stats.rx_len[i++] += val;
2230 
2231 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L1023_CNT_H(port->id));
2232 	port->stats.rx_len[i] += ((u64)val << 32);
2233 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_L1023_CNT_L(port->id));
2234 	port->stats.rx_len[i++] += val;
2235 
2236 	val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_LONG_CNT(port->id));
2237 	port->stats.rx_len[i++] += val;
2238 
2239 	/* reset mib counters */
2240 	airoha_fe_set(eth, REG_FE_GDM_MIB_CLEAR(port->id),
2241 		      FE_GDM_MIB_RX_CLEAR_MASK | FE_GDM_MIB_TX_CLEAR_MASK);
2242 
2243 	u64_stats_update_end(&port->stats.syncp);
2244 	spin_unlock(&port->stats.lock);
2245 }
2246 
2247 static int airoha_dev_open(struct net_device *dev)
2248 {
2249 	struct airoha_gdm_port *port = netdev_priv(dev);
2250 	struct airoha_eth *eth = port->eth;
2251 	int err;
2252 
2253 	netif_tx_start_all_queues(dev);
2254 	err = airoha_set_gdm_ports(eth, true);
2255 	if (err)
2256 		return err;
2257 
2258 	if (netdev_uses_dsa(dev))
2259 		airoha_fe_set(eth, REG_GDM_INGRESS_CFG(port->id),
2260 			      GDM_STAG_EN_MASK);
2261 	else
2262 		airoha_fe_clear(eth, REG_GDM_INGRESS_CFG(port->id),
2263 				GDM_STAG_EN_MASK);
2264 
2265 	airoha_qdma_set(eth, REG_QDMA_GLOBAL_CFG, GLOBAL_CFG_TX_DMA_EN_MASK);
2266 	airoha_qdma_set(eth, REG_QDMA_GLOBAL_CFG, GLOBAL_CFG_RX_DMA_EN_MASK);
2267 
2268 	return 0;
2269 }
2270 
2271 static int airoha_dev_stop(struct net_device *dev)
2272 {
2273 	struct airoha_gdm_port *port = netdev_priv(dev);
2274 	struct airoha_eth *eth = port->eth;
2275 	int err;
2276 
2277 	netif_tx_disable(dev);
2278 	err = airoha_set_gdm_ports(eth, false);
2279 	if (err)
2280 		return err;
2281 
2282 	airoha_qdma_clear(eth, REG_QDMA_GLOBAL_CFG, GLOBAL_CFG_TX_DMA_EN_MASK);
2283 	airoha_qdma_clear(eth, REG_QDMA_GLOBAL_CFG, GLOBAL_CFG_RX_DMA_EN_MASK);
2284 
2285 	return 0;
2286 }
2287 
2288 static int airoha_dev_set_macaddr(struct net_device *dev, void *p)
2289 {
2290 	struct airoha_gdm_port *port = netdev_priv(dev);
2291 	int err;
2292 
2293 	err = eth_mac_addr(dev, p);
2294 	if (err)
2295 		return err;
2296 
2297 	airoha_set_macaddr(port->eth, dev->dev_addr);
2298 
2299 	return 0;
2300 }
2301 
2302 static int airoha_dev_init(struct net_device *dev)
2303 {
2304 	struct airoha_gdm_port *port = netdev_priv(dev);
2305 
2306 	airoha_set_macaddr(port->eth, dev->dev_addr);
2307 
2308 	return 0;
2309 }
2310 
2311 static void airoha_dev_get_stats64(struct net_device *dev,
2312 				   struct rtnl_link_stats64 *storage)
2313 {
2314 	struct airoha_gdm_port *port = netdev_priv(dev);
2315 	unsigned int start;
2316 
2317 	airoha_update_hw_stats(port);
2318 	do {
2319 		start = u64_stats_fetch_begin(&port->stats.syncp);
2320 		storage->rx_packets = port->stats.rx_ok_pkts;
2321 		storage->tx_packets = port->stats.tx_ok_pkts;
2322 		storage->rx_bytes = port->stats.rx_ok_bytes;
2323 		storage->tx_bytes = port->stats.tx_ok_bytes;
2324 		storage->multicast = port->stats.rx_multicast;
2325 		storage->rx_errors = port->stats.rx_errors;
2326 		storage->rx_dropped = port->stats.rx_drops;
2327 		storage->tx_dropped = port->stats.tx_drops;
2328 		storage->rx_crc_errors = port->stats.rx_crc_error;
2329 		storage->rx_over_errors = port->stats.rx_over_errors;
2330 	} while (u64_stats_fetch_retry(&port->stats.syncp, start));
2331 }
2332 
2333 static netdev_tx_t airoha_dev_xmit(struct sk_buff *skb,
2334 				   struct net_device *dev)
2335 {
2336 	struct skb_shared_info *sinfo = skb_shinfo(skb);
2337 	struct airoha_gdm_port *port = netdev_priv(dev);
2338 	u32 msg0 = 0, msg1, len = skb_headlen(skb);
2339 	int i, qid = skb_get_queue_mapping(skb);
2340 	struct airoha_eth *eth = port->eth;
2341 	u32 nr_frags = 1 + sinfo->nr_frags;
2342 	struct netdev_queue *txq;
2343 	struct airoha_queue *q;
2344 	void *data = skb->data;
2345 	u16 index;
2346 	u8 fport;
2347 
2348 	if (skb->ip_summed == CHECKSUM_PARTIAL)
2349 		msg0 |= FIELD_PREP(QDMA_ETH_TXMSG_TCO_MASK, 1) |
2350 			FIELD_PREP(QDMA_ETH_TXMSG_UCO_MASK, 1) |
2351 			FIELD_PREP(QDMA_ETH_TXMSG_ICO_MASK, 1);
2352 
2353 	/* TSO: fill MSS info in tcp checksum field */
2354 	if (skb_is_gso(skb)) {
2355 		if (skb_cow_head(skb, 0))
2356 			goto error;
2357 
2358 		if (sinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
2359 			__be16 csum = cpu_to_be16(sinfo->gso_size);
2360 
2361 			tcp_hdr(skb)->check = (__force __sum16)csum;
2362 			msg0 |= FIELD_PREP(QDMA_ETH_TXMSG_TSO_MASK, 1);
2363 		}
2364 	}
2365 
2366 	fport = port->id == 4 ? FE_PSE_PORT_GDM4 : port->id;
2367 	msg1 = FIELD_PREP(QDMA_ETH_TXMSG_FPORT_MASK, fport) |
2368 	       FIELD_PREP(QDMA_ETH_TXMSG_METER_MASK, 0x7f);
2369 
2370 	q = &eth->q_tx[qid];
2371 	if (WARN_ON_ONCE(!q->ndesc))
2372 		goto error;
2373 
2374 	spin_lock_bh(&q->lock);
2375 
2376 	txq = netdev_get_tx_queue(dev, qid);
2377 	if (q->queued + nr_frags > q->ndesc) {
2378 		/* not enough space in the queue */
2379 		netif_tx_stop_queue(txq);
2380 		spin_unlock_bh(&q->lock);
2381 		return NETDEV_TX_BUSY;
2382 	}
2383 
2384 	index = q->head;
2385 	for (i = 0; i < nr_frags; i++) {
2386 		struct airoha_qdma_desc *desc = &q->desc[index];
2387 		struct airoha_queue_entry *e = &q->entry[index];
2388 		skb_frag_t *frag = &sinfo->frags[i];
2389 		dma_addr_t addr;
2390 		u32 val;
2391 
2392 		addr = dma_map_single(dev->dev.parent, data, len,
2393 				      DMA_TO_DEVICE);
2394 		if (unlikely(dma_mapping_error(dev->dev.parent, addr)))
2395 			goto error_unmap;
2396 
2397 		index = (index + 1) % q->ndesc;
2398 
2399 		val = FIELD_PREP(QDMA_DESC_LEN_MASK, len);
2400 		if (i < nr_frags - 1)
2401 			val |= FIELD_PREP(QDMA_DESC_MORE_MASK, 1);
2402 		WRITE_ONCE(desc->ctrl, cpu_to_le32(val));
2403 		WRITE_ONCE(desc->addr, cpu_to_le32(addr));
2404 		val = FIELD_PREP(QDMA_DESC_NEXT_ID_MASK, index);
2405 		WRITE_ONCE(desc->data, cpu_to_le32(val));
2406 		WRITE_ONCE(desc->msg0, cpu_to_le32(msg0));
2407 		WRITE_ONCE(desc->msg1, cpu_to_le32(msg1));
2408 		WRITE_ONCE(desc->msg2, cpu_to_le32(0xffff));
2409 
2410 		e->skb = i ? NULL : skb;
2411 		e->dma_addr = addr;
2412 		e->dma_len = len;
2413 
2414 		airoha_qdma_rmw(eth, REG_TX_CPU_IDX(qid), TX_RING_CPU_IDX_MASK,
2415 				FIELD_PREP(TX_RING_CPU_IDX_MASK, index));
2416 
2417 		data = skb_frag_address(frag);
2418 		len = skb_frag_size(frag);
2419 	}
2420 
2421 	q->head = index;
2422 	q->queued += i;
2423 
2424 	skb_tx_timestamp(skb);
2425 	if (q->ndesc - q->queued < q->free_thr)
2426 		netif_tx_stop_queue(txq);
2427 
2428 	spin_unlock_bh(&q->lock);
2429 
2430 	return NETDEV_TX_OK;
2431 
2432 error_unmap:
2433 	for (i--; i >= 0; i--) {
2434 		index = (q->head + i) % q->ndesc;
2435 		dma_unmap_single(dev->dev.parent, q->entry[index].dma_addr,
2436 				 q->entry[index].dma_len, DMA_TO_DEVICE);
2437 	}
2438 
2439 	spin_unlock_bh(&q->lock);
2440 error:
2441 	dev_kfree_skb_any(skb);
2442 	dev->stats.tx_dropped++;
2443 
2444 	return NETDEV_TX_OK;
2445 }
2446 
2447 static void airoha_ethtool_get_drvinfo(struct net_device *dev,
2448 				       struct ethtool_drvinfo *info)
2449 {
2450 	struct airoha_gdm_port *port = netdev_priv(dev);
2451 	struct airoha_eth *eth = port->eth;
2452 
2453 	strscpy(info->driver, eth->dev->driver->name, sizeof(info->driver));
2454 	strscpy(info->bus_info, dev_name(eth->dev), sizeof(info->bus_info));
2455 }
2456 
2457 static void airoha_ethtool_get_mac_stats(struct net_device *dev,
2458 					 struct ethtool_eth_mac_stats *stats)
2459 {
2460 	struct airoha_gdm_port *port = netdev_priv(dev);
2461 	unsigned int start;
2462 
2463 	airoha_update_hw_stats(port);
2464 	do {
2465 		start = u64_stats_fetch_begin(&port->stats.syncp);
2466 		stats->MulticastFramesXmittedOK = port->stats.tx_multicast;
2467 		stats->BroadcastFramesXmittedOK = port->stats.tx_broadcast;
2468 		stats->BroadcastFramesReceivedOK = port->stats.rx_broadcast;
2469 	} while (u64_stats_fetch_retry(&port->stats.syncp, start));
2470 }
2471 
2472 static const struct ethtool_rmon_hist_range airoha_ethtool_rmon_ranges[] = {
2473 	{    0,    64 },
2474 	{   65,   127 },
2475 	{  128,   255 },
2476 	{  256,   511 },
2477 	{  512,  1023 },
2478 	{ 1024,  1518 },
2479 	{ 1519, 10239 },
2480 	{},
2481 };
2482 
2483 static void
2484 airoha_ethtool_get_rmon_stats(struct net_device *dev,
2485 			      struct ethtool_rmon_stats *stats,
2486 			      const struct ethtool_rmon_hist_range **ranges)
2487 {
2488 	struct airoha_gdm_port *port = netdev_priv(dev);
2489 	struct airoha_hw_stats *hw_stats = &port->stats;
2490 	unsigned int start;
2491 
2492 	BUILD_BUG_ON(ARRAY_SIZE(airoha_ethtool_rmon_ranges) !=
2493 		     ARRAY_SIZE(hw_stats->tx_len) + 1);
2494 	BUILD_BUG_ON(ARRAY_SIZE(airoha_ethtool_rmon_ranges) !=
2495 		     ARRAY_SIZE(hw_stats->rx_len) + 1);
2496 
2497 	*ranges = airoha_ethtool_rmon_ranges;
2498 	airoha_update_hw_stats(port);
2499 	do {
2500 		int i;
2501 
2502 		start = u64_stats_fetch_begin(&port->stats.syncp);
2503 		stats->fragments = hw_stats->rx_fragment;
2504 		stats->jabbers = hw_stats->rx_jabber;
2505 		for (i = 0; i < ARRAY_SIZE(airoha_ethtool_rmon_ranges) - 1;
2506 		     i++) {
2507 			stats->hist[i] = hw_stats->rx_len[i];
2508 			stats->hist_tx[i] = hw_stats->tx_len[i];
2509 		}
2510 	} while (u64_stats_fetch_retry(&port->stats.syncp, start));
2511 }
2512 
2513 static const struct net_device_ops airoha_netdev_ops = {
2514 	.ndo_init		= airoha_dev_init,
2515 	.ndo_open		= airoha_dev_open,
2516 	.ndo_stop		= airoha_dev_stop,
2517 	.ndo_start_xmit		= airoha_dev_xmit,
2518 	.ndo_get_stats64        = airoha_dev_get_stats64,
2519 	.ndo_set_mac_address	= airoha_dev_set_macaddr,
2520 };
2521 
2522 static const struct ethtool_ops airoha_ethtool_ops = {
2523 	.get_drvinfo		= airoha_ethtool_get_drvinfo,
2524 	.get_eth_mac_stats      = airoha_ethtool_get_mac_stats,
2525 	.get_rmon_stats		= airoha_ethtool_get_rmon_stats,
2526 };
2527 
2528 static int airoha_alloc_gdm_port(struct airoha_eth *eth, struct device_node *np)
2529 {
2530 	const __be32 *id_ptr = of_get_property(np, "reg", NULL);
2531 	struct airoha_gdm_port *port;
2532 	struct net_device *dev;
2533 	int err, index;
2534 	u32 id;
2535 
2536 	if (!id_ptr) {
2537 		dev_err(eth->dev, "missing gdm port id\n");
2538 		return -EINVAL;
2539 	}
2540 
2541 	id = be32_to_cpup(id_ptr);
2542 	index = id - 1;
2543 
2544 	if (!id || id > ARRAY_SIZE(eth->ports)) {
2545 		dev_err(eth->dev, "invalid gdm port id: %d\n", id);
2546 		return -EINVAL;
2547 	}
2548 
2549 	if (eth->ports[index]) {
2550 		dev_err(eth->dev, "duplicate gdm port id: %d\n", id);
2551 		return -EINVAL;
2552 	}
2553 
2554 	dev = devm_alloc_etherdev_mqs(eth->dev, sizeof(*port),
2555 				      AIROHA_NUM_TX_RING, AIROHA_NUM_RX_RING);
2556 	if (!dev) {
2557 		dev_err(eth->dev, "alloc_etherdev failed\n");
2558 		return -ENOMEM;
2559 	}
2560 
2561 	dev->netdev_ops = &airoha_netdev_ops;
2562 	dev->ethtool_ops = &airoha_ethtool_ops;
2563 	dev->max_mtu = AIROHA_MAX_MTU;
2564 	dev->watchdog_timeo = 5 * HZ;
2565 	dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2566 			   NETIF_F_TSO6 | NETIF_F_IPV6_CSUM |
2567 			   NETIF_F_SG | NETIF_F_TSO;
2568 	dev->features |= dev->hw_features;
2569 	dev->dev.of_node = np;
2570 	SET_NETDEV_DEV(dev, eth->dev);
2571 
2572 	err = of_get_ethdev_address(np, dev);
2573 	if (err) {
2574 		if (err == -EPROBE_DEFER)
2575 			return err;
2576 
2577 		eth_hw_addr_random(dev);
2578 		dev_info(eth->dev, "generated random MAC address %pM\n",
2579 			 dev->dev_addr);
2580 	}
2581 
2582 	port = netdev_priv(dev);
2583 	u64_stats_init(&port->stats.syncp);
2584 	spin_lock_init(&port->stats.lock);
2585 	port->dev = dev;
2586 	port->eth = eth;
2587 	port->id = id;
2588 	eth->ports[index] = port;
2589 
2590 	return register_netdev(dev);
2591 }
2592 
2593 static int airoha_probe(struct platform_device *pdev)
2594 {
2595 	struct device_node *np;
2596 	struct airoha_eth *eth;
2597 	int i, err;
2598 
2599 	eth = devm_kzalloc(&pdev->dev, sizeof(*eth), GFP_KERNEL);
2600 	if (!eth)
2601 		return -ENOMEM;
2602 
2603 	eth->dev = &pdev->dev;
2604 
2605 	err = dma_set_mask_and_coherent(eth->dev, DMA_BIT_MASK(32));
2606 	if (err) {
2607 		dev_err(eth->dev, "failed configuring DMA mask\n");
2608 		return err;
2609 	}
2610 
2611 	eth->fe_regs = devm_platform_ioremap_resource_byname(pdev, "fe");
2612 	if (IS_ERR(eth->fe_regs))
2613 		return dev_err_probe(eth->dev, PTR_ERR(eth->fe_regs),
2614 				     "failed to iomap fe regs\n");
2615 
2616 	eth->qdma_regs = devm_platform_ioremap_resource_byname(pdev, "qdma0");
2617 	if (IS_ERR(eth->qdma_regs))
2618 		return dev_err_probe(eth->dev, PTR_ERR(eth->qdma_regs),
2619 				     "failed to iomap qdma regs\n");
2620 
2621 	eth->rsts[0].id = "fe";
2622 	eth->rsts[1].id = "pdma";
2623 	eth->rsts[2].id = "qdma";
2624 	err = devm_reset_control_bulk_get_exclusive(eth->dev,
2625 						    ARRAY_SIZE(eth->rsts),
2626 						    eth->rsts);
2627 	if (err) {
2628 		dev_err(eth->dev, "failed to get bulk reset lines\n");
2629 		return err;
2630 	}
2631 
2632 	eth->xsi_rsts[0].id = "xsi-mac";
2633 	eth->xsi_rsts[1].id = "hsi0-mac";
2634 	eth->xsi_rsts[2].id = "hsi1-mac";
2635 	eth->xsi_rsts[3].id = "hsi-mac";
2636 	eth->xsi_rsts[4].id = "xfp-mac";
2637 	err = devm_reset_control_bulk_get_exclusive(eth->dev,
2638 						    ARRAY_SIZE(eth->xsi_rsts),
2639 						    eth->xsi_rsts);
2640 	if (err) {
2641 		dev_err(eth->dev, "failed to get bulk xsi reset lines\n");
2642 		return err;
2643 	}
2644 
2645 	spin_lock_init(&eth->irq_lock);
2646 	eth->irq = platform_get_irq(pdev, 0);
2647 	if (eth->irq < 0)
2648 		return eth->irq;
2649 
2650 	eth->napi_dev = alloc_netdev_dummy(0);
2651 	if (!eth->napi_dev)
2652 		return -ENOMEM;
2653 
2654 	/* Enable threaded NAPI by default */
2655 	eth->napi_dev->threaded = true;
2656 	strscpy(eth->napi_dev->name, "qdma_eth", sizeof(eth->napi_dev->name));
2657 	platform_set_drvdata(pdev, eth);
2658 
2659 	err = airoha_hw_init(eth);
2660 	if (err)
2661 		goto error;
2662 
2663 	airoha_qdma_start_napi(eth);
2664 	for_each_child_of_node(pdev->dev.of_node, np) {
2665 		if (!of_device_is_compatible(np, "airoha,eth-mac"))
2666 			continue;
2667 
2668 		if (!of_device_is_available(np))
2669 			continue;
2670 
2671 		err = airoha_alloc_gdm_port(eth, np);
2672 		if (err) {
2673 			of_node_put(np);
2674 			goto error;
2675 		}
2676 	}
2677 
2678 	return 0;
2679 
2680 error:
2681 	airoha_hw_cleanup(eth);
2682 	for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
2683 		struct airoha_gdm_port *port = eth->ports[i];
2684 
2685 		if (port && port->dev->reg_state == NETREG_REGISTERED)
2686 			unregister_netdev(port->dev);
2687 	}
2688 	free_netdev(eth->napi_dev);
2689 	platform_set_drvdata(pdev, NULL);
2690 
2691 	return err;
2692 }
2693 
2694 static void airoha_remove(struct platform_device *pdev)
2695 {
2696 	struct airoha_eth *eth = platform_get_drvdata(pdev);
2697 	int i;
2698 
2699 	airoha_hw_cleanup(eth);
2700 	for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
2701 		struct airoha_gdm_port *port = eth->ports[i];
2702 
2703 		if (!port)
2704 			continue;
2705 
2706 		airoha_dev_stop(port->dev);
2707 		unregister_netdev(port->dev);
2708 	}
2709 	free_netdev(eth->napi_dev);
2710 
2711 	platform_set_drvdata(pdev, NULL);
2712 }
2713 
2714 static const struct of_device_id of_airoha_match[] = {
2715 	{ .compatible = "airoha,en7581-eth" },
2716 	{ /* sentinel */ }
2717 };
2718 
2719 static struct platform_driver airoha_driver = {
2720 	.probe = airoha_probe,
2721 	.remove_new = airoha_remove,
2722 	.driver = {
2723 		.name = KBUILD_MODNAME,
2724 		.of_match_table = of_airoha_match,
2725 	},
2726 };
2727 module_platform_driver(airoha_driver);
2728 
2729 MODULE_LICENSE("GPL");
2730 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
2731 MODULE_DESCRIPTION("Ethernet driver for Airoha SoC");
2732