162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci *   Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org>
562306a36Sopenharmony_ci *   Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org>
662306a36Sopenharmony_ci *   Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef MTK_ETH_H
1062306a36Sopenharmony_ci#define MTK_ETH_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/dma-mapping.h>
1362306a36Sopenharmony_ci#include <linux/netdevice.h>
1462306a36Sopenharmony_ci#include <linux/of_net.h>
1562306a36Sopenharmony_ci#include <linux/u64_stats_sync.h>
1662306a36Sopenharmony_ci#include <linux/refcount.h>
1762306a36Sopenharmony_ci#include <linux/phylink.h>
1862306a36Sopenharmony_ci#include <linux/rhashtable.h>
1962306a36Sopenharmony_ci#include <linux/dim.h>
2062306a36Sopenharmony_ci#include <linux/bitfield.h>
2162306a36Sopenharmony_ci#include <net/page_pool/types.h>
2262306a36Sopenharmony_ci#include <linux/bpf_trace.h>
2362306a36Sopenharmony_ci#include "mtk_ppe.h"
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#define MTK_MAX_DSA_PORTS	7
2662306a36Sopenharmony_ci#define MTK_DSA_PORT_MASK	GENMASK(2, 0)
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define MTK_QDMA_NUM_QUEUES	16
2962306a36Sopenharmony_ci#define MTK_QDMA_PAGE_SIZE	2048
3062306a36Sopenharmony_ci#define MTK_MAX_RX_LENGTH	1536
3162306a36Sopenharmony_ci#define MTK_MAX_RX_LENGTH_2K	2048
3262306a36Sopenharmony_ci#define MTK_TX_DMA_BUF_LEN	0x3fff
3362306a36Sopenharmony_ci#define MTK_TX_DMA_BUF_LEN_V2	0xffff
3462306a36Sopenharmony_ci#define MTK_QDMA_RING_SIZE	2048
3562306a36Sopenharmony_ci#define MTK_DMA_SIZE		512
3662306a36Sopenharmony_ci#define MTK_RX_ETH_HLEN		(ETH_HLEN + ETH_FCS_LEN)
3762306a36Sopenharmony_ci#define MTK_RX_HLEN		(NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN)
3862306a36Sopenharmony_ci#define MTK_DMA_DUMMY_DESC	0xffffffff
3962306a36Sopenharmony_ci#define MTK_DEFAULT_MSG_ENABLE	(NETIF_MSG_DRV | \
4062306a36Sopenharmony_ci				 NETIF_MSG_PROBE | \
4162306a36Sopenharmony_ci				 NETIF_MSG_LINK | \
4262306a36Sopenharmony_ci				 NETIF_MSG_TIMER | \
4362306a36Sopenharmony_ci				 NETIF_MSG_IFDOWN | \
4462306a36Sopenharmony_ci				 NETIF_MSG_IFUP | \
4562306a36Sopenharmony_ci				 NETIF_MSG_RX_ERR | \
4662306a36Sopenharmony_ci				 NETIF_MSG_TX_ERR)
4762306a36Sopenharmony_ci#define MTK_HW_FEATURES		(NETIF_F_IP_CSUM | \
4862306a36Sopenharmony_ci				 NETIF_F_RXCSUM | \
4962306a36Sopenharmony_ci				 NETIF_F_HW_VLAN_CTAG_TX | \
5062306a36Sopenharmony_ci				 NETIF_F_SG | NETIF_F_TSO | \
5162306a36Sopenharmony_ci				 NETIF_F_TSO6 | \
5262306a36Sopenharmony_ci				 NETIF_F_IPV6_CSUM |\
5362306a36Sopenharmony_ci				 NETIF_F_HW_TC)
5462306a36Sopenharmony_ci#define MTK_HW_FEATURES_MT7628	(NETIF_F_SG | NETIF_F_RXCSUM)
5562306a36Sopenharmony_ci#define NEXT_DESP_IDX(X, Y)	(((X) + 1) & ((Y) - 1))
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define MTK_PP_HEADROOM		XDP_PACKET_HEADROOM
5862306a36Sopenharmony_ci#define MTK_PP_PAD		(MTK_PP_HEADROOM + \
5962306a36Sopenharmony_ci				 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
6062306a36Sopenharmony_ci#define MTK_PP_MAX_BUF_SIZE	(PAGE_SIZE - MTK_PP_PAD)
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#define MTK_QRX_OFFSET		0x10
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci#define MTK_MAX_RX_RING_NUM	4
6562306a36Sopenharmony_ci#define MTK_HW_LRO_DMA_SIZE	8
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define	MTK_MAX_LRO_RX_LENGTH		(4096 * 3)
6862306a36Sopenharmony_ci#define	MTK_MAX_LRO_IP_CNT		2
6962306a36Sopenharmony_ci#define	MTK_HW_LRO_TIMER_UNIT		1	/* 20 us */
7062306a36Sopenharmony_ci#define	MTK_HW_LRO_REFRESH_TIME		50000	/* 1 sec. */
7162306a36Sopenharmony_ci#define	MTK_HW_LRO_AGG_TIME		10	/* 200us */
7262306a36Sopenharmony_ci#define	MTK_HW_LRO_AGE_TIME		50	/* 1ms */
7362306a36Sopenharmony_ci#define	MTK_HW_LRO_MAX_AGG_CNT		64
7462306a36Sopenharmony_ci#define	MTK_HW_LRO_BW_THRE		3000
7562306a36Sopenharmony_ci#define	MTK_HW_LRO_REPLACE_DELTA	1000
7662306a36Sopenharmony_ci#define	MTK_HW_LRO_SDL_REMAIN_ROOM	1522
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/* Frame Engine Global Configuration */
7962306a36Sopenharmony_ci#define MTK_FE_GLO_CFG(x)	(((x) == MTK_GMAC3_ID) ? 0x24 : 0x00)
8062306a36Sopenharmony_ci#define MTK_FE_LINK_DOWN_P(x)	BIT(((x) + 8) % 16)
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci/* Frame Engine Global Reset Register */
8362306a36Sopenharmony_ci#define MTK_RST_GL		0x04
8462306a36Sopenharmony_ci#define RST_GL_PSE		BIT(0)
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* Frame Engine Interrupt Status Register */
8762306a36Sopenharmony_ci#define MTK_INT_STATUS2		0x08
8862306a36Sopenharmony_ci#define MTK_FE_INT_ENABLE	0x0c
8962306a36Sopenharmony_ci#define MTK_FE_INT_FQ_EMPTY	BIT(8)
9062306a36Sopenharmony_ci#define MTK_FE_INT_TSO_FAIL	BIT(12)
9162306a36Sopenharmony_ci#define MTK_FE_INT_TSO_ILLEGAL	BIT(13)
9262306a36Sopenharmony_ci#define MTK_FE_INT_TSO_ALIGN	BIT(14)
9362306a36Sopenharmony_ci#define MTK_FE_INT_RFIFO_OV	BIT(18)
9462306a36Sopenharmony_ci#define MTK_FE_INT_RFIFO_UF	BIT(19)
9562306a36Sopenharmony_ci#define MTK_GDM1_AF		BIT(28)
9662306a36Sopenharmony_ci#define MTK_GDM2_AF		BIT(29)
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci/* PDMA HW LRO Alter Flow Timer Register */
9962306a36Sopenharmony_ci#define MTK_PDMA_LRO_ALT_REFRESH_TIMER	0x1c
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/* Frame Engine Interrupt Grouping Register */
10262306a36Sopenharmony_ci#define MTK_FE_INT_GRP		0x20
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/* CDMP Ingress Control Register */
10562306a36Sopenharmony_ci#define MTK_CDMQ_IG_CTRL	0x1400
10662306a36Sopenharmony_ci#define MTK_CDMQ_STAG_EN	BIT(0)
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* CDMQ Exgress Control Register */
10962306a36Sopenharmony_ci#define MTK_CDMQ_EG_CTRL	0x1404
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci/* CDMP Ingress Control Register */
11262306a36Sopenharmony_ci#define MTK_CDMP_IG_CTRL	0x400
11362306a36Sopenharmony_ci#define MTK_CDMP_STAG_EN	BIT(0)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci/* CDMP Exgress Control Register */
11662306a36Sopenharmony_ci#define MTK_CDMP_EG_CTRL	0x404
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/* GDM Exgress Control Register */
11962306a36Sopenharmony_ci#define MTK_GDMA_FWD_CFG(x)	({ typeof(x) _x = (x); (_x == MTK_GMAC3_ID) ?	\
12062306a36Sopenharmony_ci				   0x540 : 0x500 + (_x * 0x1000); })
12162306a36Sopenharmony_ci#define MTK_GDMA_SPECIAL_TAG	BIT(24)
12262306a36Sopenharmony_ci#define MTK_GDMA_ICS_EN		BIT(22)
12362306a36Sopenharmony_ci#define MTK_GDMA_TCS_EN		BIT(21)
12462306a36Sopenharmony_ci#define MTK_GDMA_UCS_EN		BIT(20)
12562306a36Sopenharmony_ci#define MTK_GDMA_STRP_CRC	BIT(16)
12662306a36Sopenharmony_ci#define MTK_GDMA_TO_PDMA	0x0
12762306a36Sopenharmony_ci#define MTK_GDMA_DROP_ALL       0x7777
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci/* GDM Egress Control Register */
13062306a36Sopenharmony_ci#define MTK_GDMA_EG_CTRL(x)	({ typeof(x) _x = (x); (_x == MTK_GMAC3_ID) ?	\
13162306a36Sopenharmony_ci				   0x544 : 0x504 + (_x * 0x1000); })
13262306a36Sopenharmony_ci#define MTK_GDMA_XGDM_SEL	BIT(31)
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci/* Unicast Filter MAC Address Register - Low */
13562306a36Sopenharmony_ci#define MTK_GDMA_MAC_ADRL(x)	({ typeof(x) _x = (x); (_x == MTK_GMAC3_ID) ?	\
13662306a36Sopenharmony_ci				   0x548 : 0x508 + (_x * 0x1000); })
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci/* Unicast Filter MAC Address Register - High */
13962306a36Sopenharmony_ci#define MTK_GDMA_MAC_ADRH(x)	({ typeof(x) _x = (x); (_x == MTK_GMAC3_ID) ?	\
14062306a36Sopenharmony_ci				   0x54C : 0x50C + (_x * 0x1000); })
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/* Internal SRAM offset */
14362306a36Sopenharmony_ci#define MTK_ETH_SRAM_OFFSET	0x40000
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci/* FE global misc reg*/
14662306a36Sopenharmony_ci#define MTK_FE_GLO_MISC         0x124
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/* PSE Free Queue Flow Control  */
14962306a36Sopenharmony_ci#define PSE_FQFC_CFG1		0x100
15062306a36Sopenharmony_ci#define PSE_FQFC_CFG2		0x104
15162306a36Sopenharmony_ci#define PSE_DROP_CFG		0x108
15262306a36Sopenharmony_ci#define PSE_PPE0_DROP		0x110
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci/* PSE Input Queue Reservation Register*/
15562306a36Sopenharmony_ci#define PSE_IQ_REV(x)		(0x140 + (((x) - 1) << 2))
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci/* PSE Output Queue Threshold Register*/
15862306a36Sopenharmony_ci#define PSE_OQ_TH(x)		(0x160 + (((x) - 1) << 2))
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci/* GDM and CDM Threshold */
16162306a36Sopenharmony_ci#define MTK_GDM2_THRES		0x1530
16262306a36Sopenharmony_ci#define MTK_CDMW0_THRES		0x164c
16362306a36Sopenharmony_ci#define MTK_CDMW1_THRES		0x1650
16462306a36Sopenharmony_ci#define MTK_CDME0_THRES		0x1654
16562306a36Sopenharmony_ci#define MTK_CDME1_THRES		0x1658
16662306a36Sopenharmony_ci#define MTK_CDMM_THRES		0x165c
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci/* PDMA HW LRO Control Registers */
16962306a36Sopenharmony_ci#define MTK_PDMA_LRO_CTRL_DW0	0x980
17062306a36Sopenharmony_ci#define MTK_LRO_EN			BIT(0)
17162306a36Sopenharmony_ci#define MTK_L3_CKS_UPD_EN		BIT(7)
17262306a36Sopenharmony_ci#define MTK_L3_CKS_UPD_EN_V2		BIT(19)
17362306a36Sopenharmony_ci#define MTK_LRO_ALT_PKT_CNT_MODE	BIT(21)
17462306a36Sopenharmony_ci#define MTK_LRO_RING_RELINQUISH_REQ	(0x7 << 26)
17562306a36Sopenharmony_ci#define MTK_LRO_RING_RELINQUISH_REQ_V2	(0xf << 24)
17662306a36Sopenharmony_ci#define MTK_LRO_RING_RELINQUISH_DONE	(0x7 << 29)
17762306a36Sopenharmony_ci#define MTK_LRO_RING_RELINQUISH_DONE_V2	(0xf << 28)
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci#define MTK_PDMA_LRO_CTRL_DW1	0x984
18062306a36Sopenharmony_ci#define MTK_PDMA_LRO_CTRL_DW2	0x988
18162306a36Sopenharmony_ci#define MTK_PDMA_LRO_CTRL_DW3	0x98c
18262306a36Sopenharmony_ci#define MTK_ADMA_MODE		BIT(15)
18362306a36Sopenharmony_ci#define MTK_LRO_MIN_RXD_SDL	(MTK_HW_LRO_SDL_REMAIN_ROOM << 16)
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci#define MTK_RX_DMA_LRO_EN	BIT(8)
18662306a36Sopenharmony_ci#define MTK_MULTI_EN		BIT(10)
18762306a36Sopenharmony_ci#define MTK_PDMA_SIZE_8DWORDS	(1 << 4)
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci/* PDMA Global Configuration Register */
19062306a36Sopenharmony_ci#define MTK_PDMA_LRO_SDL	0x3000
19162306a36Sopenharmony_ci#define MTK_RX_CFG_SDL_OFFSET	16
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci/* PDMA Reset Index Register */
19462306a36Sopenharmony_ci#define MTK_PST_DRX_IDX0	BIT(16)
19562306a36Sopenharmony_ci#define MTK_PST_DRX_IDX_CFG(x)	(MTK_PST_DRX_IDX0 << (x))
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci/* PDMA Delay Interrupt Register */
19862306a36Sopenharmony_ci#define MTK_PDMA_DELAY_RX_MASK		GENMASK(15, 0)
19962306a36Sopenharmony_ci#define MTK_PDMA_DELAY_RX_EN		BIT(15)
20062306a36Sopenharmony_ci#define MTK_PDMA_DELAY_RX_PINT_SHIFT	8
20162306a36Sopenharmony_ci#define MTK_PDMA_DELAY_RX_PTIME_SHIFT	0
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci#define MTK_PDMA_DELAY_TX_MASK		GENMASK(31, 16)
20462306a36Sopenharmony_ci#define MTK_PDMA_DELAY_TX_EN		BIT(31)
20562306a36Sopenharmony_ci#define MTK_PDMA_DELAY_TX_PINT_SHIFT	24
20662306a36Sopenharmony_ci#define MTK_PDMA_DELAY_TX_PTIME_SHIFT	16
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci#define MTK_PDMA_DELAY_PINT_MASK	0x7f
20962306a36Sopenharmony_ci#define MTK_PDMA_DELAY_PTIME_MASK	0xff
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci/* PDMA HW LRO Alter Flow Delta Register */
21262306a36Sopenharmony_ci#define MTK_PDMA_LRO_ALT_SCORE_DELTA	0xa4c
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci/* PDMA HW LRO IP Setting Registers */
21562306a36Sopenharmony_ci#define MTK_LRO_RX_RING0_DIP_DW0	0xb04
21662306a36Sopenharmony_ci#define MTK_LRO_DIP_DW0_CFG(x)		(MTK_LRO_RX_RING0_DIP_DW0 + (x * 0x40))
21762306a36Sopenharmony_ci#define MTK_RING_MYIP_VLD		BIT(9)
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci/* PDMA HW LRO Ring Control Registers */
22062306a36Sopenharmony_ci#define MTK_LRO_RX_RING0_CTRL_DW1	0xb28
22162306a36Sopenharmony_ci#define MTK_LRO_RX_RING0_CTRL_DW2	0xb2c
22262306a36Sopenharmony_ci#define MTK_LRO_RX_RING0_CTRL_DW3	0xb30
22362306a36Sopenharmony_ci#define MTK_LRO_CTRL_DW1_CFG(x)		(MTK_LRO_RX_RING0_CTRL_DW1 + (x * 0x40))
22462306a36Sopenharmony_ci#define MTK_LRO_CTRL_DW2_CFG(x)		(MTK_LRO_RX_RING0_CTRL_DW2 + (x * 0x40))
22562306a36Sopenharmony_ci#define MTK_LRO_CTRL_DW3_CFG(x)		(MTK_LRO_RX_RING0_CTRL_DW3 + (x * 0x40))
22662306a36Sopenharmony_ci#define MTK_RING_AGE_TIME_L		((MTK_HW_LRO_AGE_TIME & 0x3ff) << 22)
22762306a36Sopenharmony_ci#define MTK_RING_AGE_TIME_H		((MTK_HW_LRO_AGE_TIME >> 10) & 0x3f)
22862306a36Sopenharmony_ci#define MTK_RING_AUTO_LERAN_MODE	(3 << 6)
22962306a36Sopenharmony_ci#define MTK_RING_VLD			BIT(8)
23062306a36Sopenharmony_ci#define MTK_RING_MAX_AGG_TIME		((MTK_HW_LRO_AGG_TIME & 0xffff) << 10)
23162306a36Sopenharmony_ci#define MTK_RING_MAX_AGG_CNT_L		((MTK_HW_LRO_MAX_AGG_CNT & 0x3f) << 26)
23262306a36Sopenharmony_ci#define MTK_RING_MAX_AGG_CNT_H		((MTK_HW_LRO_MAX_AGG_CNT >> 6) & 0x3)
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci/* QDMA TX Queue Configuration Registers */
23562306a36Sopenharmony_ci#define MTK_QTX_OFFSET		0x10
23662306a36Sopenharmony_ci#define QDMA_RES_THRES		4
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci/* QDMA Tx Queue Scheduler Configuration Registers */
23962306a36Sopenharmony_ci#define MTK_QTX_SCH_TX_SEL		BIT(31)
24062306a36Sopenharmony_ci#define MTK_QTX_SCH_TX_SEL_V2		GENMASK(31, 30)
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci#define MTK_QTX_SCH_LEAKY_BUCKET_EN	BIT(30)
24362306a36Sopenharmony_ci#define MTK_QTX_SCH_LEAKY_BUCKET_SIZE	GENMASK(29, 28)
24462306a36Sopenharmony_ci#define MTK_QTX_SCH_MIN_RATE_EN		BIT(27)
24562306a36Sopenharmony_ci#define MTK_QTX_SCH_MIN_RATE_MAN	GENMASK(26, 20)
24662306a36Sopenharmony_ci#define MTK_QTX_SCH_MIN_RATE_EXP	GENMASK(19, 16)
24762306a36Sopenharmony_ci#define MTK_QTX_SCH_MAX_RATE_WEIGHT	GENMASK(15, 12)
24862306a36Sopenharmony_ci#define MTK_QTX_SCH_MAX_RATE_EN		BIT(11)
24962306a36Sopenharmony_ci#define MTK_QTX_SCH_MAX_RATE_MAN	GENMASK(10, 4)
25062306a36Sopenharmony_ci#define MTK_QTX_SCH_MAX_RATE_EXP	GENMASK(3, 0)
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci/* QDMA TX Scheduler Rate Control Register */
25362306a36Sopenharmony_ci#define MTK_QDMA_TX_SCH_MAX_WFQ		BIT(15)
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci/* QDMA Global Configuration Register */
25662306a36Sopenharmony_ci#define MTK_RX_2B_OFFSET	BIT(31)
25762306a36Sopenharmony_ci#define MTK_RX_BT_32DWORDS	(3 << 11)
25862306a36Sopenharmony_ci#define MTK_NDP_CO_PRO		BIT(10)
25962306a36Sopenharmony_ci#define MTK_TX_WB_DDONE		BIT(6)
26062306a36Sopenharmony_ci#define MTK_TX_BT_32DWORDS	(3 << 4)
26162306a36Sopenharmony_ci#define MTK_RX_DMA_BUSY		BIT(3)
26262306a36Sopenharmony_ci#define MTK_TX_DMA_BUSY		BIT(1)
26362306a36Sopenharmony_ci#define MTK_RX_DMA_EN		BIT(2)
26462306a36Sopenharmony_ci#define MTK_TX_DMA_EN		BIT(0)
26562306a36Sopenharmony_ci#define MTK_DMA_BUSY_TIMEOUT_US	1000000
26662306a36Sopenharmony_ci
26762306a36Sopenharmony_ci/* QDMA V2 Global Configuration Register */
26862306a36Sopenharmony_ci#define MTK_CHK_DDONE_EN	BIT(28)
26962306a36Sopenharmony_ci#define MTK_DMAD_WR_WDONE	BIT(26)
27062306a36Sopenharmony_ci#define MTK_WCOMP_EN		BIT(24)
27162306a36Sopenharmony_ci#define MTK_RESV_BUF		(0x40 << 16)
27262306a36Sopenharmony_ci#define MTK_MUTLI_CNT		(0x4 << 12)
27362306a36Sopenharmony_ci#define MTK_LEAKY_BUCKET_EN	BIT(11)
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci/* QDMA Flow Control Register */
27662306a36Sopenharmony_ci#define FC_THRES_DROP_MODE	BIT(20)
27762306a36Sopenharmony_ci#define FC_THRES_DROP_EN	(7 << 16)
27862306a36Sopenharmony_ci#define FC_THRES_MIN		0x4444
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci/* QDMA Interrupt Status Register */
28162306a36Sopenharmony_ci#define MTK_RX_DONE_DLY		BIT(30)
28262306a36Sopenharmony_ci#define MTK_TX_DONE_DLY		BIT(28)
28362306a36Sopenharmony_ci#define MTK_RX_DONE_INT3	BIT(19)
28462306a36Sopenharmony_ci#define MTK_RX_DONE_INT2	BIT(18)
28562306a36Sopenharmony_ci#define MTK_RX_DONE_INT1	BIT(17)
28662306a36Sopenharmony_ci#define MTK_RX_DONE_INT0	BIT(16)
28762306a36Sopenharmony_ci#define MTK_TX_DONE_INT3	BIT(3)
28862306a36Sopenharmony_ci#define MTK_TX_DONE_INT2	BIT(2)
28962306a36Sopenharmony_ci#define MTK_TX_DONE_INT1	BIT(1)
29062306a36Sopenharmony_ci#define MTK_TX_DONE_INT0	BIT(0)
29162306a36Sopenharmony_ci#define MTK_RX_DONE_INT		MTK_RX_DONE_DLY
29262306a36Sopenharmony_ci#define MTK_TX_DONE_INT		MTK_TX_DONE_DLY
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ci#define MTK_RX_DONE_INT_V2	BIT(14)
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci#define MTK_CDM_TXFIFO_RDY	BIT(7)
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci/* QDMA Interrupt grouping registers */
29962306a36Sopenharmony_ci#define MTK_RLS_DONE_INT	BIT(0)
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ci/* QDMA TX NUM */
30262306a36Sopenharmony_ci#define QID_BITS_V2(x)		(((x) & 0x3f) << 16)
30362306a36Sopenharmony_ci#define MTK_QDMA_GMAC2_QID	8
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci#define MTK_TX_DMA_BUF_SHIFT	8
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci/* QDMA V2 descriptor txd6 */
30862306a36Sopenharmony_ci#define TX_DMA_INS_VLAN_V2	BIT(16)
30962306a36Sopenharmony_ci/* QDMA V2 descriptor txd5 */
31062306a36Sopenharmony_ci#define TX_DMA_CHKSUM_V2	(0x7 << 28)
31162306a36Sopenharmony_ci#define TX_DMA_TSO_V2		BIT(31)
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_ci#define TX_DMA_SPTAG_V3         BIT(27)
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci/* QDMA V2 descriptor txd4 */
31662306a36Sopenharmony_ci#define TX_DMA_FPORT_SHIFT_V2	8
31762306a36Sopenharmony_ci#define TX_DMA_FPORT_MASK_V2	0xf
31862306a36Sopenharmony_ci#define TX_DMA_SWC_V2		BIT(30)
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci/* QDMA descriptor txd4 */
32162306a36Sopenharmony_ci#define TX_DMA_CHKSUM		(0x7 << 29)
32262306a36Sopenharmony_ci#define TX_DMA_TSO		BIT(28)
32362306a36Sopenharmony_ci#define TX_DMA_FPORT_SHIFT	25
32462306a36Sopenharmony_ci#define TX_DMA_FPORT_MASK	0x7
32562306a36Sopenharmony_ci#define TX_DMA_INS_VLAN		BIT(16)
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci/* QDMA descriptor txd3 */
32862306a36Sopenharmony_ci#define TX_DMA_OWNER_CPU	BIT(31)
32962306a36Sopenharmony_ci#define TX_DMA_LS0		BIT(30)
33062306a36Sopenharmony_ci#define TX_DMA_PLEN0(x)		(((x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
33162306a36Sopenharmony_ci#define TX_DMA_PLEN1(x)		((x) & eth->soc->txrx.dma_max_len)
33262306a36Sopenharmony_ci#define TX_DMA_SWC		BIT(14)
33362306a36Sopenharmony_ci#define TX_DMA_PQID		GENMASK(3, 0)
33462306a36Sopenharmony_ci#define TX_DMA_ADDR64_MASK	GENMASK(3, 0)
33562306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_64BIT)
33662306a36Sopenharmony_ci# define TX_DMA_GET_ADDR64(x)	(((u64)FIELD_GET(TX_DMA_ADDR64_MASK, (x))) << 32)
33762306a36Sopenharmony_ci# define TX_DMA_PREP_ADDR64(x)	FIELD_PREP(TX_DMA_ADDR64_MASK, ((x) >> 32))
33862306a36Sopenharmony_ci#else
33962306a36Sopenharmony_ci# define TX_DMA_GET_ADDR64(x)	(0)
34062306a36Sopenharmony_ci# define TX_DMA_PREP_ADDR64(x)	(0)
34162306a36Sopenharmony_ci#endif
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci/* PDMA on MT7628 */
34462306a36Sopenharmony_ci#define TX_DMA_DONE		BIT(31)
34562306a36Sopenharmony_ci#define TX_DMA_LS1		BIT(14)
34662306a36Sopenharmony_ci#define TX_DMA_DESP2_DEF	(TX_DMA_LS0 | TX_DMA_DONE)
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_ci/* QDMA descriptor rxd2 */
34962306a36Sopenharmony_ci#define RX_DMA_DONE		BIT(31)
35062306a36Sopenharmony_ci#define RX_DMA_LSO		BIT(30)
35162306a36Sopenharmony_ci#define RX_DMA_PREP_PLEN0(x)	(((x) & eth->soc->txrx.dma_max_len) << eth->soc->txrx.dma_len_offset)
35262306a36Sopenharmony_ci#define RX_DMA_GET_PLEN0(x)	(((x) >> eth->soc->txrx.dma_len_offset) & eth->soc->txrx.dma_max_len)
35362306a36Sopenharmony_ci#define RX_DMA_VTAG		BIT(15)
35462306a36Sopenharmony_ci#define RX_DMA_ADDR64_MASK	GENMASK(3, 0)
35562306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_64BIT)
35662306a36Sopenharmony_ci# define RX_DMA_GET_ADDR64(x)	(((u64)FIELD_GET(RX_DMA_ADDR64_MASK, (x))) << 32)
35762306a36Sopenharmony_ci# define RX_DMA_PREP_ADDR64(x)	FIELD_PREP(RX_DMA_ADDR64_MASK, ((x) >> 32))
35862306a36Sopenharmony_ci#else
35962306a36Sopenharmony_ci# define RX_DMA_GET_ADDR64(x)	(0)
36062306a36Sopenharmony_ci# define RX_DMA_PREP_ADDR64(x)	(0)
36162306a36Sopenharmony_ci#endif
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci/* QDMA descriptor rxd3 */
36462306a36Sopenharmony_ci#define RX_DMA_VID(x)		((x) & VLAN_VID_MASK)
36562306a36Sopenharmony_ci#define RX_DMA_TCI(x)		((x) & (VLAN_PRIO_MASK | VLAN_VID_MASK))
36662306a36Sopenharmony_ci#define RX_DMA_VPID(x)		(((x) >> 16) & 0xffff)
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ci/* QDMA descriptor rxd4 */
36962306a36Sopenharmony_ci#define MTK_RXD4_FOE_ENTRY	GENMASK(13, 0)
37062306a36Sopenharmony_ci#define MTK_RXD4_PPE_CPU_REASON	GENMASK(18, 14)
37162306a36Sopenharmony_ci#define MTK_RXD4_SRC_PORT	GENMASK(21, 19)
37262306a36Sopenharmony_ci#define MTK_RXD4_ALG		GENMASK(31, 22)
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ci/* QDMA descriptor rxd4 */
37562306a36Sopenharmony_ci#define RX_DMA_L4_VALID		BIT(24)
37662306a36Sopenharmony_ci#define RX_DMA_L4_VALID_PDMA	BIT(30)		/* when PDMA is used */
37762306a36Sopenharmony_ci#define RX_DMA_SPECIAL_TAG	BIT(22)
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ci/* PDMA descriptor rxd5 */
38062306a36Sopenharmony_ci#define MTK_RXD5_FOE_ENTRY	GENMASK(14, 0)
38162306a36Sopenharmony_ci#define MTK_RXD5_PPE_CPU_REASON	GENMASK(22, 18)
38262306a36Sopenharmony_ci#define MTK_RXD5_SRC_PORT	GENMASK(29, 26)
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_ci#define RX_DMA_GET_SPORT(x)	(((x) >> 19) & 0x7)
38562306a36Sopenharmony_ci#define RX_DMA_GET_SPORT_V2(x)	(((x) >> 26) & 0xf)
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_ci/* PDMA V2 descriptor rxd3 */
38862306a36Sopenharmony_ci#define RX_DMA_VTAG_V2		BIT(0)
38962306a36Sopenharmony_ci#define RX_DMA_L4_VALID_V2	BIT(2)
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci/* PHY Polling and SMI Master Control registers */
39262306a36Sopenharmony_ci#define MTK_PPSC		0x10000
39362306a36Sopenharmony_ci#define PPSC_MDC_CFG		GENMASK(29, 24)
39462306a36Sopenharmony_ci#define PPSC_MDC_TURBO		BIT(20)
39562306a36Sopenharmony_ci#define MDC_MAX_FREQ		25000000
39662306a36Sopenharmony_ci#define MDC_MAX_DIVIDER		63
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci/* PHY Indirect Access Control registers */
39962306a36Sopenharmony_ci#define MTK_PHY_IAC		0x10004
40062306a36Sopenharmony_ci#define PHY_IAC_ACCESS		BIT(31)
40162306a36Sopenharmony_ci#define PHY_IAC_REG_MASK	GENMASK(29, 25)
40262306a36Sopenharmony_ci#define PHY_IAC_REG(x)		FIELD_PREP(PHY_IAC_REG_MASK, (x))
40362306a36Sopenharmony_ci#define PHY_IAC_ADDR_MASK	GENMASK(24, 20)
40462306a36Sopenharmony_ci#define PHY_IAC_ADDR(x)		FIELD_PREP(PHY_IAC_ADDR_MASK, (x))
40562306a36Sopenharmony_ci#define PHY_IAC_CMD_MASK	GENMASK(19, 18)
40662306a36Sopenharmony_ci#define PHY_IAC_CMD_C45_ADDR	FIELD_PREP(PHY_IAC_CMD_MASK, 0)
40762306a36Sopenharmony_ci#define PHY_IAC_CMD_WRITE	FIELD_PREP(PHY_IAC_CMD_MASK, 1)
40862306a36Sopenharmony_ci#define PHY_IAC_CMD_C22_READ	FIELD_PREP(PHY_IAC_CMD_MASK, 2)
40962306a36Sopenharmony_ci#define PHY_IAC_CMD_C45_READ	FIELD_PREP(PHY_IAC_CMD_MASK, 3)
41062306a36Sopenharmony_ci#define PHY_IAC_START_MASK	GENMASK(17, 16)
41162306a36Sopenharmony_ci#define PHY_IAC_START_C45	FIELD_PREP(PHY_IAC_START_MASK, 0)
41262306a36Sopenharmony_ci#define PHY_IAC_START_C22	FIELD_PREP(PHY_IAC_START_MASK, 1)
41362306a36Sopenharmony_ci#define PHY_IAC_DATA_MASK	GENMASK(15, 0)
41462306a36Sopenharmony_ci#define PHY_IAC_DATA(x)		FIELD_PREP(PHY_IAC_DATA_MASK, (x))
41562306a36Sopenharmony_ci#define PHY_IAC_TIMEOUT		HZ
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_ci#define MTK_MAC_MISC		0x1000c
41862306a36Sopenharmony_ci#define MTK_MAC_MISC_V3		0x10010
41962306a36Sopenharmony_ci#define MTK_MUX_TO_ESW		BIT(0)
42062306a36Sopenharmony_ci#define MISC_MDC_TURBO		BIT(4)
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci/* XMAC status registers */
42362306a36Sopenharmony_ci#define MTK_XGMAC_STS(x)	(((x) == MTK_GMAC3_ID) ? 0x1001C : 0x1000C)
42462306a36Sopenharmony_ci#define MTK_XGMAC_FORCE_LINK(x)	(((x) == MTK_GMAC2_ID) ? BIT(31) : BIT(15))
42562306a36Sopenharmony_ci#define MTK_USXGMII_PCS_LINK	BIT(8)
42662306a36Sopenharmony_ci#define MTK_XGMAC_RX_FC		BIT(5)
42762306a36Sopenharmony_ci#define MTK_XGMAC_TX_FC		BIT(4)
42862306a36Sopenharmony_ci#define MTK_USXGMII_PCS_MODE	GENMASK(3, 1)
42962306a36Sopenharmony_ci#define MTK_XGMAC_LINK_STS	BIT(0)
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ci/* GSW bridge registers */
43262306a36Sopenharmony_ci#define MTK_GSW_CFG		(0x10080)
43362306a36Sopenharmony_ci#define GSWTX_IPG_MASK		GENMASK(19, 16)
43462306a36Sopenharmony_ci#define GSWTX_IPG_SHIFT		16
43562306a36Sopenharmony_ci#define GSWRX_IPG_MASK		GENMASK(3, 0)
43662306a36Sopenharmony_ci#define GSWRX_IPG_SHIFT		0
43762306a36Sopenharmony_ci#define GSW_IPG_11		11
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_ci/* Mac control registers */
44062306a36Sopenharmony_ci#define MTK_MAC_MCR(x)		(0x10100 + (x * 0x100))
44162306a36Sopenharmony_ci#define MAC_MCR_MAX_RX_MASK	GENMASK(25, 24)
44262306a36Sopenharmony_ci#define MAC_MCR_MAX_RX(_x)	(MAC_MCR_MAX_RX_MASK & ((_x) << 24))
44362306a36Sopenharmony_ci#define MAC_MCR_MAX_RX_1518	0x0
44462306a36Sopenharmony_ci#define MAC_MCR_MAX_RX_1536	0x1
44562306a36Sopenharmony_ci#define MAC_MCR_MAX_RX_1552	0x2
44662306a36Sopenharmony_ci#define MAC_MCR_MAX_RX_2048	0x3
44762306a36Sopenharmony_ci#define MAC_MCR_IPG_CFG		(BIT(18) | BIT(16))
44862306a36Sopenharmony_ci#define MAC_MCR_FORCE_MODE	BIT(15)
44962306a36Sopenharmony_ci#define MAC_MCR_TX_EN		BIT(14)
45062306a36Sopenharmony_ci#define MAC_MCR_RX_EN		BIT(13)
45162306a36Sopenharmony_ci#define MAC_MCR_RX_FIFO_CLR_DIS	BIT(12)
45262306a36Sopenharmony_ci#define MAC_MCR_BACKOFF_EN	BIT(9)
45362306a36Sopenharmony_ci#define MAC_MCR_BACKPR_EN	BIT(8)
45462306a36Sopenharmony_ci#define MAC_MCR_FORCE_RX_FC	BIT(5)
45562306a36Sopenharmony_ci#define MAC_MCR_FORCE_TX_FC	BIT(4)
45662306a36Sopenharmony_ci#define MAC_MCR_SPEED_1000	BIT(3)
45762306a36Sopenharmony_ci#define MAC_MCR_SPEED_100	BIT(2)
45862306a36Sopenharmony_ci#define MAC_MCR_FORCE_DPX	BIT(1)
45962306a36Sopenharmony_ci#define MAC_MCR_FORCE_LINK	BIT(0)
46062306a36Sopenharmony_ci#define MAC_MCR_FORCE_LINK_DOWN	(MAC_MCR_FORCE_MODE)
46162306a36Sopenharmony_ci
46262306a36Sopenharmony_ci/* Mac status registers */
46362306a36Sopenharmony_ci#define MTK_MAC_MSR(x)		(0x10108 + (x * 0x100))
46462306a36Sopenharmony_ci#define MAC_MSR_EEE1G		BIT(7)
46562306a36Sopenharmony_ci#define MAC_MSR_EEE100M		BIT(6)
46662306a36Sopenharmony_ci#define MAC_MSR_RX_FC		BIT(5)
46762306a36Sopenharmony_ci#define MAC_MSR_TX_FC		BIT(4)
46862306a36Sopenharmony_ci#define MAC_MSR_SPEED_1000	BIT(3)
46962306a36Sopenharmony_ci#define MAC_MSR_SPEED_100	BIT(2)
47062306a36Sopenharmony_ci#define MAC_MSR_SPEED_MASK	(MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100)
47162306a36Sopenharmony_ci#define MAC_MSR_DPX		BIT(1)
47262306a36Sopenharmony_ci#define MAC_MSR_LINK		BIT(0)
47362306a36Sopenharmony_ci
47462306a36Sopenharmony_ci/* TRGMII RXC control register */
47562306a36Sopenharmony_ci#define TRGMII_RCK_CTRL		0x10300
47662306a36Sopenharmony_ci#define DQSI0(x)		((x << 0) & GENMASK(6, 0))
47762306a36Sopenharmony_ci#define DQSI1(x)		((x << 8) & GENMASK(14, 8))
47862306a36Sopenharmony_ci#define RXCTL_DMWTLAT(x)	((x << 16) & GENMASK(18, 16))
47962306a36Sopenharmony_ci#define RXC_RST			BIT(31)
48062306a36Sopenharmony_ci#define RXC_DQSISEL		BIT(30)
48162306a36Sopenharmony_ci#define RCK_CTRL_RGMII_1000	(RXC_DQSISEL | RXCTL_DMWTLAT(2) | DQSI1(16))
48262306a36Sopenharmony_ci#define RCK_CTRL_RGMII_10_100	RXCTL_DMWTLAT(2)
48362306a36Sopenharmony_ci
48462306a36Sopenharmony_ci#define NUM_TRGMII_CTRL		5
48562306a36Sopenharmony_ci
48662306a36Sopenharmony_ci/* TRGMII RXC control register */
48762306a36Sopenharmony_ci#define TRGMII_TCK_CTRL		0x10340
48862306a36Sopenharmony_ci#define TXCTL_DMWTLAT(x)	((x << 16) & GENMASK(18, 16))
48962306a36Sopenharmony_ci#define TXC_INV			BIT(30)
49062306a36Sopenharmony_ci#define TCK_CTRL_RGMII_1000	TXCTL_DMWTLAT(2)
49162306a36Sopenharmony_ci#define TCK_CTRL_RGMII_10_100	(TXC_INV | TXCTL_DMWTLAT(2))
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ci/* TRGMII TX Drive Strength */
49462306a36Sopenharmony_ci#define TRGMII_TD_ODT(i)	(0x10354 + 8 * (i))
49562306a36Sopenharmony_ci#define  TD_DM_DRVP(x)		((x) & 0xf)
49662306a36Sopenharmony_ci#define  TD_DM_DRVN(x)		(((x) & 0xf) << 4)
49762306a36Sopenharmony_ci
49862306a36Sopenharmony_ci/* TRGMII Interface mode register */
49962306a36Sopenharmony_ci#define INTF_MODE		0x10390
50062306a36Sopenharmony_ci#define TRGMII_INTF_DIS		BIT(0)
50162306a36Sopenharmony_ci#define TRGMII_MODE		BIT(1)
50262306a36Sopenharmony_ci#define TRGMII_CENTRAL_ALIGNED	BIT(2)
50362306a36Sopenharmony_ci#define INTF_MODE_RGMII_1000    (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED)
50462306a36Sopenharmony_ci#define INTF_MODE_RGMII_10_100  0
50562306a36Sopenharmony_ci
50662306a36Sopenharmony_ci/* GPIO port control registers for GMAC 2*/
50762306a36Sopenharmony_ci#define GPIO_OD33_CTRL8		0x4c0
50862306a36Sopenharmony_ci#define GPIO_BIAS_CTRL		0xed0
50962306a36Sopenharmony_ci#define GPIO_DRV_SEL10		0xf00
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci/* ethernet subsystem chip id register */
51262306a36Sopenharmony_ci#define ETHSYS_CHIPID0_3	0x0
51362306a36Sopenharmony_ci#define ETHSYS_CHIPID4_7	0x4
51462306a36Sopenharmony_ci#define MT7623_ETH		7623
51562306a36Sopenharmony_ci#define MT7622_ETH		7622
51662306a36Sopenharmony_ci#define MT7621_ETH		7621
51762306a36Sopenharmony_ci
51862306a36Sopenharmony_ci/* ethernet system control register */
51962306a36Sopenharmony_ci#define ETHSYS_SYSCFG		0x10
52062306a36Sopenharmony_ci#define SYSCFG_DRAM_TYPE_DDR2	BIT(4)
52162306a36Sopenharmony_ci
52262306a36Sopenharmony_ci/* ethernet subsystem config register */
52362306a36Sopenharmony_ci#define ETHSYS_SYSCFG0		0x14
52462306a36Sopenharmony_ci#define SYSCFG0_GE_MASK		0x3
52562306a36Sopenharmony_ci#define SYSCFG0_GE_MODE(x, y)	(x << (12 + (y * 2)))
52662306a36Sopenharmony_ci#define SYSCFG0_SGMII_MASK     GENMASK(9, 7)
52762306a36Sopenharmony_ci#define SYSCFG0_SGMII_GMAC1    ((2 << 8) & SYSCFG0_SGMII_MASK)
52862306a36Sopenharmony_ci#define SYSCFG0_SGMII_GMAC2    ((3 << 8) & SYSCFG0_SGMII_MASK)
52962306a36Sopenharmony_ci#define SYSCFG0_SGMII_GMAC1_V2 BIT(9)
53062306a36Sopenharmony_ci#define SYSCFG0_SGMII_GMAC2_V2 BIT(8)
53162306a36Sopenharmony_ci
53262306a36Sopenharmony_ci
53362306a36Sopenharmony_ci/* ethernet subsystem clock register */
53462306a36Sopenharmony_ci#define ETHSYS_CLKCFG0		0x2c
53562306a36Sopenharmony_ci#define ETHSYS_TRGMII_CLK_SEL362_5	BIT(11)
53662306a36Sopenharmony_ci#define ETHSYS_TRGMII_MT7621_MASK	(BIT(5) | BIT(6))
53762306a36Sopenharmony_ci#define ETHSYS_TRGMII_MT7621_APLL	BIT(6)
53862306a36Sopenharmony_ci#define ETHSYS_TRGMII_MT7621_DDR_PLL	BIT(5)
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_ci/* ethernet reset control register */
54162306a36Sopenharmony_ci#define ETHSYS_RSTCTRL			0x34
54262306a36Sopenharmony_ci#define RSTCTRL_FE			BIT(6)
54362306a36Sopenharmony_ci#define RSTCTRL_WDMA0			BIT(24)
54462306a36Sopenharmony_ci#define RSTCTRL_WDMA1			BIT(25)
54562306a36Sopenharmony_ci#define RSTCTRL_WDMA2			BIT(26)
54662306a36Sopenharmony_ci#define RSTCTRL_PPE0			BIT(31)
54762306a36Sopenharmony_ci#define RSTCTRL_PPE0_V2			BIT(30)
54862306a36Sopenharmony_ci#define RSTCTRL_PPE1			BIT(31)
54962306a36Sopenharmony_ci#define RSTCTRL_PPE0_V3			BIT(29)
55062306a36Sopenharmony_ci#define RSTCTRL_PPE1_V3			BIT(30)
55162306a36Sopenharmony_ci#define RSTCTRL_PPE2			BIT(31)
55262306a36Sopenharmony_ci#define RSTCTRL_ETH			BIT(23)
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci/* ethernet reset check idle register */
55562306a36Sopenharmony_ci#define ETHSYS_FE_RST_CHK_IDLE_EN	0x28
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ci/* ethernet dma channel agent map */
55862306a36Sopenharmony_ci#define ETHSYS_DMA_AG_MAP	0x408
55962306a36Sopenharmony_ci#define ETHSYS_DMA_AG_MAP_PDMA	BIT(0)
56062306a36Sopenharmony_ci#define ETHSYS_DMA_AG_MAP_QDMA	BIT(1)
56162306a36Sopenharmony_ci#define ETHSYS_DMA_AG_MAP_PPE	BIT(2)
56262306a36Sopenharmony_ci
56362306a36Sopenharmony_ci/* Infrasys subsystem config registers */
56462306a36Sopenharmony_ci#define INFRA_MISC2            0x70c
56562306a36Sopenharmony_ci#define CO_QPHY_SEL            BIT(0)
56662306a36Sopenharmony_ci#define GEPHY_MAC_SEL          BIT(1)
56762306a36Sopenharmony_ci
56862306a36Sopenharmony_ci/* Top misc registers */
56962306a36Sopenharmony_ci#define USB_PHY_SWITCH_REG	0x218
57062306a36Sopenharmony_ci#define QPHY_SEL_MASK		GENMASK(1, 0)
57162306a36Sopenharmony_ci#define SGMII_QPHY_SEL		0x2
57262306a36Sopenharmony_ci
57362306a36Sopenharmony_ci/* MT7628/88 specific stuff */
57462306a36Sopenharmony_ci#define MT7628_PDMA_OFFSET	0x0800
57562306a36Sopenharmony_ci#define MT7628_SDM_OFFSET	0x0c00
57662306a36Sopenharmony_ci
57762306a36Sopenharmony_ci#define MT7628_TX_BASE_PTR0	(MT7628_PDMA_OFFSET + 0x00)
57862306a36Sopenharmony_ci#define MT7628_TX_MAX_CNT0	(MT7628_PDMA_OFFSET + 0x04)
57962306a36Sopenharmony_ci#define MT7628_TX_CTX_IDX0	(MT7628_PDMA_OFFSET + 0x08)
58062306a36Sopenharmony_ci#define MT7628_TX_DTX_IDX0	(MT7628_PDMA_OFFSET + 0x0c)
58162306a36Sopenharmony_ci#define MT7628_PST_DTX_IDX0	BIT(0)
58262306a36Sopenharmony_ci
58362306a36Sopenharmony_ci#define MT7628_SDM_MAC_ADRL	(MT7628_SDM_OFFSET + 0x0c)
58462306a36Sopenharmony_ci#define MT7628_SDM_MAC_ADRH	(MT7628_SDM_OFFSET + 0x10)
58562306a36Sopenharmony_ci
58662306a36Sopenharmony_ci/* Counter / stat register */
58762306a36Sopenharmony_ci#define MT7628_SDM_TPCNT	(MT7628_SDM_OFFSET + 0x100)
58862306a36Sopenharmony_ci#define MT7628_SDM_TBCNT	(MT7628_SDM_OFFSET + 0x104)
58962306a36Sopenharmony_ci#define MT7628_SDM_RPCNT	(MT7628_SDM_OFFSET + 0x108)
59062306a36Sopenharmony_ci#define MT7628_SDM_RBCNT	(MT7628_SDM_OFFSET + 0x10c)
59162306a36Sopenharmony_ci#define MT7628_SDM_CS_ERR	(MT7628_SDM_OFFSET + 0x110)
59262306a36Sopenharmony_ci
59362306a36Sopenharmony_ci#define MTK_FE_CDM1_FSM		0x220
59462306a36Sopenharmony_ci#define MTK_FE_CDM2_FSM		0x224
59562306a36Sopenharmony_ci#define MTK_FE_CDM3_FSM		0x238
59662306a36Sopenharmony_ci#define MTK_FE_CDM4_FSM		0x298
59762306a36Sopenharmony_ci#define MTK_FE_CDM5_FSM		0x318
59862306a36Sopenharmony_ci#define MTK_FE_CDM6_FSM		0x328
59962306a36Sopenharmony_ci#define MTK_FE_GDM1_FSM		0x228
60062306a36Sopenharmony_ci#define MTK_FE_GDM2_FSM		0x22C
60162306a36Sopenharmony_ci
60262306a36Sopenharmony_ci#define MTK_MAC_FSM(x)		(0x1010C + ((x) * 0x100))
60362306a36Sopenharmony_ci
60462306a36Sopenharmony_cistruct mtk_rx_dma {
60562306a36Sopenharmony_ci	unsigned int rxd1;
60662306a36Sopenharmony_ci	unsigned int rxd2;
60762306a36Sopenharmony_ci	unsigned int rxd3;
60862306a36Sopenharmony_ci	unsigned int rxd4;
60962306a36Sopenharmony_ci} __packed __aligned(4);
61062306a36Sopenharmony_ci
61162306a36Sopenharmony_cistruct mtk_rx_dma_v2 {
61262306a36Sopenharmony_ci	unsigned int rxd1;
61362306a36Sopenharmony_ci	unsigned int rxd2;
61462306a36Sopenharmony_ci	unsigned int rxd3;
61562306a36Sopenharmony_ci	unsigned int rxd4;
61662306a36Sopenharmony_ci	unsigned int rxd5;
61762306a36Sopenharmony_ci	unsigned int rxd6;
61862306a36Sopenharmony_ci	unsigned int rxd7;
61962306a36Sopenharmony_ci	unsigned int rxd8;
62062306a36Sopenharmony_ci} __packed __aligned(4);
62162306a36Sopenharmony_ci
62262306a36Sopenharmony_cistruct mtk_tx_dma {
62362306a36Sopenharmony_ci	unsigned int txd1;
62462306a36Sopenharmony_ci	unsigned int txd2;
62562306a36Sopenharmony_ci	unsigned int txd3;
62662306a36Sopenharmony_ci	unsigned int txd4;
62762306a36Sopenharmony_ci} __packed __aligned(4);
62862306a36Sopenharmony_ci
62962306a36Sopenharmony_cistruct mtk_tx_dma_v2 {
63062306a36Sopenharmony_ci	unsigned int txd1;
63162306a36Sopenharmony_ci	unsigned int txd2;
63262306a36Sopenharmony_ci	unsigned int txd3;
63362306a36Sopenharmony_ci	unsigned int txd4;
63462306a36Sopenharmony_ci	unsigned int txd5;
63562306a36Sopenharmony_ci	unsigned int txd6;
63662306a36Sopenharmony_ci	unsigned int txd7;
63762306a36Sopenharmony_ci	unsigned int txd8;
63862306a36Sopenharmony_ci} __packed __aligned(4);
63962306a36Sopenharmony_ci
64062306a36Sopenharmony_cistruct mtk_eth;
64162306a36Sopenharmony_cistruct mtk_mac;
64262306a36Sopenharmony_ci
64362306a36Sopenharmony_cistruct mtk_xdp_stats {
64462306a36Sopenharmony_ci	u64 rx_xdp_redirect;
64562306a36Sopenharmony_ci	u64 rx_xdp_pass;
64662306a36Sopenharmony_ci	u64 rx_xdp_drop;
64762306a36Sopenharmony_ci	u64 rx_xdp_tx;
64862306a36Sopenharmony_ci	u64 rx_xdp_tx_errors;
64962306a36Sopenharmony_ci	u64 tx_xdp_xmit;
65062306a36Sopenharmony_ci	u64 tx_xdp_xmit_errors;
65162306a36Sopenharmony_ci};
65262306a36Sopenharmony_ci
65362306a36Sopenharmony_ci/* struct mtk_hw_stats - the structure that holds the traffic statistics.
65462306a36Sopenharmony_ci * @stats_lock:		make sure that stats operations are atomic
65562306a36Sopenharmony_ci * @reg_offset:		the status register offset of the SoC
65662306a36Sopenharmony_ci * @syncp:		the refcount
65762306a36Sopenharmony_ci *
65862306a36Sopenharmony_ci * All of the supported SoCs have hardware counters for traffic statistics.
65962306a36Sopenharmony_ci * Whenever the status IRQ triggers we can read the latest stats from these
66062306a36Sopenharmony_ci * counters and store them in this struct.
66162306a36Sopenharmony_ci */
66262306a36Sopenharmony_cistruct mtk_hw_stats {
66362306a36Sopenharmony_ci	u64 tx_bytes;
66462306a36Sopenharmony_ci	u64 tx_packets;
66562306a36Sopenharmony_ci	u64 tx_skip;
66662306a36Sopenharmony_ci	u64 tx_collisions;
66762306a36Sopenharmony_ci	u64 rx_bytes;
66862306a36Sopenharmony_ci	u64 rx_packets;
66962306a36Sopenharmony_ci	u64 rx_overflow;
67062306a36Sopenharmony_ci	u64 rx_fcs_errors;
67162306a36Sopenharmony_ci	u64 rx_short_errors;
67262306a36Sopenharmony_ci	u64 rx_long_errors;
67362306a36Sopenharmony_ci	u64 rx_checksum_errors;
67462306a36Sopenharmony_ci	u64 rx_flow_control_packets;
67562306a36Sopenharmony_ci
67662306a36Sopenharmony_ci	struct mtk_xdp_stats	xdp_stats;
67762306a36Sopenharmony_ci
67862306a36Sopenharmony_ci	spinlock_t		stats_lock;
67962306a36Sopenharmony_ci	u32			reg_offset;
68062306a36Sopenharmony_ci	struct u64_stats_sync	syncp;
68162306a36Sopenharmony_ci};
68262306a36Sopenharmony_ci
68362306a36Sopenharmony_cienum mtk_tx_flags {
68462306a36Sopenharmony_ci	/* PDMA descriptor can point at 1-2 segments. This enum allows us to
68562306a36Sopenharmony_ci	 * track how memory was allocated so that it can be freed properly.
68662306a36Sopenharmony_ci	 */
68762306a36Sopenharmony_ci	MTK_TX_FLAGS_SINGLE0	= 0x01,
68862306a36Sopenharmony_ci	MTK_TX_FLAGS_PAGE0	= 0x02,
68962306a36Sopenharmony_ci};
69062306a36Sopenharmony_ci
69162306a36Sopenharmony_ci/* This enum allows us to identify how the clock is defined on the array of the
69262306a36Sopenharmony_ci * clock in the order
69362306a36Sopenharmony_ci */
69462306a36Sopenharmony_cienum mtk_clks_map {
69562306a36Sopenharmony_ci	MTK_CLK_ETHIF,
69662306a36Sopenharmony_ci	MTK_CLK_SGMIITOP,
69762306a36Sopenharmony_ci	MTK_CLK_ESW,
69862306a36Sopenharmony_ci	MTK_CLK_GP0,
69962306a36Sopenharmony_ci	MTK_CLK_GP1,
70062306a36Sopenharmony_ci	MTK_CLK_GP2,
70162306a36Sopenharmony_ci	MTK_CLK_GP3,
70262306a36Sopenharmony_ci	MTK_CLK_XGP1,
70362306a36Sopenharmony_ci	MTK_CLK_XGP2,
70462306a36Sopenharmony_ci	MTK_CLK_XGP3,
70562306a36Sopenharmony_ci	MTK_CLK_CRYPTO,
70662306a36Sopenharmony_ci	MTK_CLK_FE,
70762306a36Sopenharmony_ci	MTK_CLK_TRGPLL,
70862306a36Sopenharmony_ci	MTK_CLK_SGMII_TX_250M,
70962306a36Sopenharmony_ci	MTK_CLK_SGMII_RX_250M,
71062306a36Sopenharmony_ci	MTK_CLK_SGMII_CDR_REF,
71162306a36Sopenharmony_ci	MTK_CLK_SGMII_CDR_FB,
71262306a36Sopenharmony_ci	MTK_CLK_SGMII2_TX_250M,
71362306a36Sopenharmony_ci	MTK_CLK_SGMII2_RX_250M,
71462306a36Sopenharmony_ci	MTK_CLK_SGMII2_CDR_REF,
71562306a36Sopenharmony_ci	MTK_CLK_SGMII2_CDR_FB,
71662306a36Sopenharmony_ci	MTK_CLK_SGMII_CK,
71762306a36Sopenharmony_ci	MTK_CLK_ETH2PLL,
71862306a36Sopenharmony_ci	MTK_CLK_WOCPU0,
71962306a36Sopenharmony_ci	MTK_CLK_WOCPU1,
72062306a36Sopenharmony_ci	MTK_CLK_NETSYS0,
72162306a36Sopenharmony_ci	MTK_CLK_NETSYS1,
72262306a36Sopenharmony_ci	MTK_CLK_ETHWARP_WOCPU2,
72362306a36Sopenharmony_ci	MTK_CLK_ETHWARP_WOCPU1,
72462306a36Sopenharmony_ci	MTK_CLK_ETHWARP_WOCPU0,
72562306a36Sopenharmony_ci	MTK_CLK_TOP_USXGMII_SBUS_0_SEL,
72662306a36Sopenharmony_ci	MTK_CLK_TOP_USXGMII_SBUS_1_SEL,
72762306a36Sopenharmony_ci	MTK_CLK_TOP_SGM_0_SEL,
72862306a36Sopenharmony_ci	MTK_CLK_TOP_SGM_1_SEL,
72962306a36Sopenharmony_ci	MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL,
73062306a36Sopenharmony_ci	MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL,
73162306a36Sopenharmony_ci	MTK_CLK_TOP_ETH_GMII_SEL,
73262306a36Sopenharmony_ci	MTK_CLK_TOP_ETH_REFCK_50M_SEL,
73362306a36Sopenharmony_ci	MTK_CLK_TOP_ETH_SYS_200M_SEL,
73462306a36Sopenharmony_ci	MTK_CLK_TOP_ETH_SYS_SEL,
73562306a36Sopenharmony_ci	MTK_CLK_TOP_ETH_XGMII_SEL,
73662306a36Sopenharmony_ci	MTK_CLK_TOP_ETH_MII_SEL,
73762306a36Sopenharmony_ci	MTK_CLK_TOP_NETSYS_SEL,
73862306a36Sopenharmony_ci	MTK_CLK_TOP_NETSYS_500M_SEL,
73962306a36Sopenharmony_ci	MTK_CLK_TOP_NETSYS_PAO_2X_SEL,
74062306a36Sopenharmony_ci	MTK_CLK_TOP_NETSYS_SYNC_250M_SEL,
74162306a36Sopenharmony_ci	MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL,
74262306a36Sopenharmony_ci	MTK_CLK_TOP_NETSYS_WARP_SEL,
74362306a36Sopenharmony_ci	MTK_CLK_MAX
74462306a36Sopenharmony_ci};
74562306a36Sopenharmony_ci
74662306a36Sopenharmony_ci#define MT7623_CLKS_BITMAP	(BIT_ULL(MTK_CLK_ETHIF) | BIT_ULL(MTK_CLK_ESW) |  \
74762306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP1) | BIT_ULL(MTK_CLK_GP2) | \
74862306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TRGPLL))
74962306a36Sopenharmony_ci#define MT7622_CLKS_BITMAP	(BIT_ULL(MTK_CLK_ETHIF) | BIT_ULL(MTK_CLK_ESW) |  \
75062306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP0) | BIT_ULL(MTK_CLK_GP1) | \
75162306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP2) | \
75262306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_TX_250M) | \
75362306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_RX_250M) | \
75462306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CDR_REF) | \
75562306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CDR_FB) | \
75662306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CK) | \
75762306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_ETH2PLL))
75862306a36Sopenharmony_ci#define MT7621_CLKS_BITMAP	(0)
75962306a36Sopenharmony_ci#define MT7628_CLKS_BITMAP	(0)
76062306a36Sopenharmony_ci#define MT7629_CLKS_BITMAP	(BIT_ULL(MTK_CLK_ETHIF) | BIT_ULL(MTK_CLK_ESW) |  \
76162306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP0) | BIT_ULL(MTK_CLK_GP1) | \
76262306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP2) | BIT_ULL(MTK_CLK_FE) | \
76362306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_TX_250M) | \
76462306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_RX_250M) | \
76562306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CDR_REF) | \
76662306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CDR_FB) | \
76762306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_TX_250M) | \
76862306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_RX_250M) | \
76962306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_CDR_REF) | \
77062306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_CDR_FB) | \
77162306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CK) | \
77262306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_ETH2PLL) | BIT_ULL(MTK_CLK_SGMIITOP))
77362306a36Sopenharmony_ci#define MT7981_CLKS_BITMAP	(BIT_ULL(MTK_CLK_FE) | BIT_ULL(MTK_CLK_GP2) | \
77462306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP1) | \
77562306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_WOCPU0) | \
77662306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_TX_250M) | \
77762306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_RX_250M) | \
77862306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CDR_REF) | \
77962306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CDR_FB) | \
78062306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_TX_250M) | \
78162306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_RX_250M) | \
78262306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_CDR_REF) | \
78362306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_CDR_FB) | \
78462306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CK))
78562306a36Sopenharmony_ci#define MT7986_CLKS_BITMAP	(BIT_ULL(MTK_CLK_FE) | BIT_ULL(MTK_CLK_GP2) | \
78662306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP1) | \
78762306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_WOCPU1) | BIT_ULL(MTK_CLK_WOCPU0) | \
78862306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_TX_250M) | \
78962306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_RX_250M) | \
79062306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CDR_REF) | \
79162306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_CDR_FB) | \
79262306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_TX_250M) | \
79362306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_RX_250M) | \
79462306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_CDR_REF) | \
79562306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_CDR_FB))
79662306a36Sopenharmony_ci#define MT7988_CLKS_BITMAP	(BIT_ULL(MTK_CLK_FE) | BIT_ULL(MTK_CLK_ESW) | \
79762306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP1) | BIT_ULL(MTK_CLK_GP2) | \
79862306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_GP3) | BIT_ULL(MTK_CLK_XGP1) | \
79962306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_XGP2) | BIT_ULL(MTK_CLK_XGP3) | \
80062306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_CRYPTO) | \
80162306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_TX_250M) | \
80262306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII_RX_250M) | \
80362306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_TX_250M) | \
80462306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_SGMII2_RX_250M) | \
80562306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_ETHWARP_WOCPU2) | \
80662306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_ETHWARP_WOCPU1) | \
80762306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_ETHWARP_WOCPU0) | \
80862306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_USXGMII_SBUS_0_SEL) | \
80962306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_USXGMII_SBUS_1_SEL) | \
81062306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_SGM_0_SEL) | \
81162306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_SGM_1_SEL) | \
81262306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_XFI_PHY_0_XTAL_SEL) | \
81362306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_XFI_PHY_1_XTAL_SEL) | \
81462306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_ETH_GMII_SEL) | \
81562306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_ETH_REFCK_50M_SEL) | \
81662306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_ETH_SYS_200M_SEL) | \
81762306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_ETH_SYS_SEL) | \
81862306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_ETH_XGMII_SEL) | \
81962306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_ETH_MII_SEL) | \
82062306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_NETSYS_SEL) | \
82162306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_NETSYS_500M_SEL) | \
82262306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_NETSYS_PAO_2X_SEL) | \
82362306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_NETSYS_SYNC_250M_SEL) | \
82462306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL) | \
82562306a36Sopenharmony_ci				 BIT_ULL(MTK_CLK_TOP_NETSYS_WARP_SEL))
82662306a36Sopenharmony_ci
82762306a36Sopenharmony_cienum mtk_dev_state {
82862306a36Sopenharmony_ci	MTK_HW_INIT,
82962306a36Sopenharmony_ci	MTK_RESETTING
83062306a36Sopenharmony_ci};
83162306a36Sopenharmony_ci
83262306a36Sopenharmony_ci/* PSE Port Definition */
83362306a36Sopenharmony_cienum mtk_pse_port {
83462306a36Sopenharmony_ci	PSE_ADMA_PORT = 0,
83562306a36Sopenharmony_ci	PSE_GDM1_PORT,
83662306a36Sopenharmony_ci	PSE_GDM2_PORT,
83762306a36Sopenharmony_ci	PSE_PPE0_PORT,
83862306a36Sopenharmony_ci	PSE_PPE1_PORT,
83962306a36Sopenharmony_ci	PSE_QDMA_TX_PORT,
84062306a36Sopenharmony_ci	PSE_QDMA_RX_PORT,
84162306a36Sopenharmony_ci	PSE_DROP_PORT,
84262306a36Sopenharmony_ci	PSE_WDMA0_PORT,
84362306a36Sopenharmony_ci	PSE_WDMA1_PORT,
84462306a36Sopenharmony_ci	PSE_TDMA_PORT,
84562306a36Sopenharmony_ci	PSE_NONE_PORT,
84662306a36Sopenharmony_ci	PSE_PPE2_PORT,
84762306a36Sopenharmony_ci	PSE_WDMA2_PORT,
84862306a36Sopenharmony_ci	PSE_EIP197_PORT,
84962306a36Sopenharmony_ci	PSE_GDM3_PORT,
85062306a36Sopenharmony_ci	PSE_PORT_MAX
85162306a36Sopenharmony_ci};
85262306a36Sopenharmony_ci
85362306a36Sopenharmony_ci/* GMAC Identifier */
85462306a36Sopenharmony_cienum mtk_gmac_id {
85562306a36Sopenharmony_ci	MTK_GMAC1_ID = 0,
85662306a36Sopenharmony_ci	MTK_GMAC2_ID,
85762306a36Sopenharmony_ci	MTK_GMAC3_ID,
85862306a36Sopenharmony_ci	MTK_GMAC_ID_MAX
85962306a36Sopenharmony_ci};
86062306a36Sopenharmony_ci
86162306a36Sopenharmony_cienum mtk_tx_buf_type {
86262306a36Sopenharmony_ci	MTK_TYPE_SKB,
86362306a36Sopenharmony_ci	MTK_TYPE_XDP_TX,
86462306a36Sopenharmony_ci	MTK_TYPE_XDP_NDO,
86562306a36Sopenharmony_ci};
86662306a36Sopenharmony_ci
86762306a36Sopenharmony_ci/* struct mtk_tx_buf -	This struct holds the pointers to the memory pointed at
86862306a36Sopenharmony_ci *			by the TX descriptor	s
86962306a36Sopenharmony_ci * @skb:		The SKB pointer of the packet being sent
87062306a36Sopenharmony_ci * @dma_addr0:		The base addr of the first segment
87162306a36Sopenharmony_ci * @dma_len0:		The length of the first segment
87262306a36Sopenharmony_ci * @dma_addr1:		The base addr of the second segment
87362306a36Sopenharmony_ci * @dma_len1:		The length of the second segment
87462306a36Sopenharmony_ci */
87562306a36Sopenharmony_cistruct mtk_tx_buf {
87662306a36Sopenharmony_ci	enum mtk_tx_buf_type type;
87762306a36Sopenharmony_ci	void *data;
87862306a36Sopenharmony_ci
87962306a36Sopenharmony_ci	u16 mac_id;
88062306a36Sopenharmony_ci	u16 flags;
88162306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_ADDR(dma_addr0);
88262306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_LEN(dma_len0);
88362306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_ADDR(dma_addr1);
88462306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_LEN(dma_len1);
88562306a36Sopenharmony_ci};
88662306a36Sopenharmony_ci
88762306a36Sopenharmony_ci/* struct mtk_tx_ring -	This struct holds info describing a TX ring
88862306a36Sopenharmony_ci * @dma:		The descriptor ring
88962306a36Sopenharmony_ci * @buf:		The memory pointed at by the ring
89062306a36Sopenharmony_ci * @phys:		The physical addr of tx_buf
89162306a36Sopenharmony_ci * @next_free:		Pointer to the next free descriptor
89262306a36Sopenharmony_ci * @last_free:		Pointer to the last free descriptor
89362306a36Sopenharmony_ci * @last_free_ptr:	Hardware pointer value of the last free descriptor
89462306a36Sopenharmony_ci * @thresh:		The threshold of minimum amount of free descriptors
89562306a36Sopenharmony_ci * @free_count:		QDMA uses a linked list. Track how many free descriptors
89662306a36Sopenharmony_ci *			are present
89762306a36Sopenharmony_ci */
89862306a36Sopenharmony_cistruct mtk_tx_ring {
89962306a36Sopenharmony_ci	void *dma;
90062306a36Sopenharmony_ci	struct mtk_tx_buf *buf;
90162306a36Sopenharmony_ci	dma_addr_t phys;
90262306a36Sopenharmony_ci	struct mtk_tx_dma *next_free;
90362306a36Sopenharmony_ci	struct mtk_tx_dma *last_free;
90462306a36Sopenharmony_ci	u32 last_free_ptr;
90562306a36Sopenharmony_ci	u16 thresh;
90662306a36Sopenharmony_ci	atomic_t free_count;
90762306a36Sopenharmony_ci	int dma_size;
90862306a36Sopenharmony_ci	struct mtk_tx_dma *dma_pdma;	/* For MT7628/88 PDMA handling */
90962306a36Sopenharmony_ci	dma_addr_t phys_pdma;
91062306a36Sopenharmony_ci	int cpu_idx;
91162306a36Sopenharmony_ci};
91262306a36Sopenharmony_ci
91362306a36Sopenharmony_ci/* PDMA rx ring mode */
91462306a36Sopenharmony_cienum mtk_rx_flags {
91562306a36Sopenharmony_ci	MTK_RX_FLAGS_NORMAL = 0,
91662306a36Sopenharmony_ci	MTK_RX_FLAGS_HWLRO,
91762306a36Sopenharmony_ci	MTK_RX_FLAGS_QDMA,
91862306a36Sopenharmony_ci};
91962306a36Sopenharmony_ci
92062306a36Sopenharmony_ci/* struct mtk_rx_ring -	This struct holds info describing a RX ring
92162306a36Sopenharmony_ci * @dma:		The descriptor ring
92262306a36Sopenharmony_ci * @data:		The memory pointed at by the ring
92362306a36Sopenharmony_ci * @phys:		The physical addr of rx_buf
92462306a36Sopenharmony_ci * @frag_size:		How big can each fragment be
92562306a36Sopenharmony_ci * @buf_size:		The size of each packet buffer
92662306a36Sopenharmony_ci * @calc_idx:		The current head of ring
92762306a36Sopenharmony_ci */
92862306a36Sopenharmony_cistruct mtk_rx_ring {
92962306a36Sopenharmony_ci	void *dma;
93062306a36Sopenharmony_ci	u8 **data;
93162306a36Sopenharmony_ci	dma_addr_t phys;
93262306a36Sopenharmony_ci	u16 frag_size;
93362306a36Sopenharmony_ci	u16 buf_size;
93462306a36Sopenharmony_ci	u16 dma_size;
93562306a36Sopenharmony_ci	bool calc_idx_update;
93662306a36Sopenharmony_ci	u16 calc_idx;
93762306a36Sopenharmony_ci	u32 crx_idx_reg;
93862306a36Sopenharmony_ci	/* page_pool */
93962306a36Sopenharmony_ci	struct page_pool *page_pool;
94062306a36Sopenharmony_ci	struct xdp_rxq_info xdp_q;
94162306a36Sopenharmony_ci};
94262306a36Sopenharmony_ci
94362306a36Sopenharmony_cienum mkt_eth_capabilities {
94462306a36Sopenharmony_ci	MTK_RGMII_BIT = 0,
94562306a36Sopenharmony_ci	MTK_TRGMII_BIT,
94662306a36Sopenharmony_ci	MTK_SGMII_BIT,
94762306a36Sopenharmony_ci	MTK_ESW_BIT,
94862306a36Sopenharmony_ci	MTK_GEPHY_BIT,
94962306a36Sopenharmony_ci	MTK_MUX_BIT,
95062306a36Sopenharmony_ci	MTK_INFRA_BIT,
95162306a36Sopenharmony_ci	MTK_SHARED_SGMII_BIT,
95262306a36Sopenharmony_ci	MTK_HWLRO_BIT,
95362306a36Sopenharmony_ci	MTK_SHARED_INT_BIT,
95462306a36Sopenharmony_ci	MTK_TRGMII_MT7621_CLK_BIT,
95562306a36Sopenharmony_ci	MTK_QDMA_BIT,
95662306a36Sopenharmony_ci	MTK_SOC_MT7628_BIT,
95762306a36Sopenharmony_ci	MTK_RSTCTRL_PPE1_BIT,
95862306a36Sopenharmony_ci	MTK_RSTCTRL_PPE2_BIT,
95962306a36Sopenharmony_ci	MTK_U3_COPHY_V2_BIT,
96062306a36Sopenharmony_ci	MTK_SRAM_BIT,
96162306a36Sopenharmony_ci	MTK_36BIT_DMA_BIT,
96262306a36Sopenharmony_ci
96362306a36Sopenharmony_ci	/* MUX BITS*/
96462306a36Sopenharmony_ci	MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT,
96562306a36Sopenharmony_ci	MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT,
96662306a36Sopenharmony_ci	MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT,
96762306a36Sopenharmony_ci	MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT,
96862306a36Sopenharmony_ci	MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT,
96962306a36Sopenharmony_ci
97062306a36Sopenharmony_ci	/* PATH BITS */
97162306a36Sopenharmony_ci	MTK_ETH_PATH_GMAC1_RGMII_BIT,
97262306a36Sopenharmony_ci	MTK_ETH_PATH_GMAC1_TRGMII_BIT,
97362306a36Sopenharmony_ci	MTK_ETH_PATH_GMAC1_SGMII_BIT,
97462306a36Sopenharmony_ci	MTK_ETH_PATH_GMAC2_RGMII_BIT,
97562306a36Sopenharmony_ci	MTK_ETH_PATH_GMAC2_SGMII_BIT,
97662306a36Sopenharmony_ci	MTK_ETH_PATH_GMAC2_GEPHY_BIT,
97762306a36Sopenharmony_ci	MTK_ETH_PATH_GDM1_ESW_BIT,
97862306a36Sopenharmony_ci};
97962306a36Sopenharmony_ci
98062306a36Sopenharmony_ci/* Supported hardware group on SoCs */
98162306a36Sopenharmony_ci#define MTK_RGMII		BIT_ULL(MTK_RGMII_BIT)
98262306a36Sopenharmony_ci#define MTK_TRGMII		BIT_ULL(MTK_TRGMII_BIT)
98362306a36Sopenharmony_ci#define MTK_SGMII		BIT_ULL(MTK_SGMII_BIT)
98462306a36Sopenharmony_ci#define MTK_ESW			BIT_ULL(MTK_ESW_BIT)
98562306a36Sopenharmony_ci#define MTK_GEPHY		BIT_ULL(MTK_GEPHY_BIT)
98662306a36Sopenharmony_ci#define MTK_MUX			BIT_ULL(MTK_MUX_BIT)
98762306a36Sopenharmony_ci#define MTK_INFRA		BIT_ULL(MTK_INFRA_BIT)
98862306a36Sopenharmony_ci#define MTK_SHARED_SGMII	BIT_ULL(MTK_SHARED_SGMII_BIT)
98962306a36Sopenharmony_ci#define MTK_HWLRO		BIT_ULL(MTK_HWLRO_BIT)
99062306a36Sopenharmony_ci#define MTK_SHARED_INT		BIT_ULL(MTK_SHARED_INT_BIT)
99162306a36Sopenharmony_ci#define MTK_TRGMII_MT7621_CLK	BIT_ULL(MTK_TRGMII_MT7621_CLK_BIT)
99262306a36Sopenharmony_ci#define MTK_QDMA		BIT_ULL(MTK_QDMA_BIT)
99362306a36Sopenharmony_ci#define MTK_SOC_MT7628		BIT_ULL(MTK_SOC_MT7628_BIT)
99462306a36Sopenharmony_ci#define MTK_RSTCTRL_PPE1	BIT_ULL(MTK_RSTCTRL_PPE1_BIT)
99562306a36Sopenharmony_ci#define MTK_RSTCTRL_PPE2	BIT_ULL(MTK_RSTCTRL_PPE2_BIT)
99662306a36Sopenharmony_ci#define MTK_U3_COPHY_V2		BIT_ULL(MTK_U3_COPHY_V2_BIT)
99762306a36Sopenharmony_ci#define MTK_SRAM		BIT_ULL(MTK_SRAM_BIT)
99862306a36Sopenharmony_ci#define MTK_36BIT_DMA	BIT_ULL(MTK_36BIT_DMA_BIT)
99962306a36Sopenharmony_ci
100062306a36Sopenharmony_ci#define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW		\
100162306a36Sopenharmony_ci	BIT_ULL(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT)
100262306a36Sopenharmony_ci#define MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY	\
100362306a36Sopenharmony_ci	BIT_ULL(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT)
100462306a36Sopenharmony_ci#define MTK_ETH_MUX_U3_GMAC2_TO_QPHY		\
100562306a36Sopenharmony_ci	BIT_ULL(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT)
100662306a36Sopenharmony_ci#define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII	\
100762306a36Sopenharmony_ci	BIT_ULL(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT)
100862306a36Sopenharmony_ci#define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII	\
100962306a36Sopenharmony_ci	BIT_ULL(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT)
101062306a36Sopenharmony_ci
101162306a36Sopenharmony_ci/* Supported path present on SoCs */
101262306a36Sopenharmony_ci#define MTK_ETH_PATH_GMAC1_RGMII	BIT_ULL(MTK_ETH_PATH_GMAC1_RGMII_BIT)
101362306a36Sopenharmony_ci#define MTK_ETH_PATH_GMAC1_TRGMII	BIT_ULL(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
101462306a36Sopenharmony_ci#define MTK_ETH_PATH_GMAC1_SGMII	BIT_ULL(MTK_ETH_PATH_GMAC1_SGMII_BIT)
101562306a36Sopenharmony_ci#define MTK_ETH_PATH_GMAC2_RGMII	BIT_ULL(MTK_ETH_PATH_GMAC2_RGMII_BIT)
101662306a36Sopenharmony_ci#define MTK_ETH_PATH_GMAC2_SGMII	BIT_ULL(MTK_ETH_PATH_GMAC2_SGMII_BIT)
101762306a36Sopenharmony_ci#define MTK_ETH_PATH_GMAC2_GEPHY	BIT_ULL(MTK_ETH_PATH_GMAC2_GEPHY_BIT)
101862306a36Sopenharmony_ci#define MTK_ETH_PATH_GDM1_ESW		BIT_ULL(MTK_ETH_PATH_GDM1_ESW_BIT)
101962306a36Sopenharmony_ci
102062306a36Sopenharmony_ci#define MTK_GMAC1_RGMII		(MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII)
102162306a36Sopenharmony_ci#define MTK_GMAC1_TRGMII	(MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
102262306a36Sopenharmony_ci#define MTK_GMAC1_SGMII		(MTK_ETH_PATH_GMAC1_SGMII | MTK_SGMII)
102362306a36Sopenharmony_ci#define MTK_GMAC2_RGMII		(MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII)
102462306a36Sopenharmony_ci#define MTK_GMAC2_SGMII		(MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII)
102562306a36Sopenharmony_ci#define MTK_GMAC2_GEPHY		(MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY)
102662306a36Sopenharmony_ci#define MTK_GDM1_ESW		(MTK_ETH_PATH_GDM1_ESW | MTK_ESW)
102762306a36Sopenharmony_ci
102862306a36Sopenharmony_ci/* MUXes present on SoCs */
102962306a36Sopenharmony_ci/* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */
103062306a36Sopenharmony_ci#define MTK_MUX_GDM1_TO_GMAC1_ESW (MTK_ETH_MUX_GDM1_TO_GMAC1_ESW | MTK_MUX)
103162306a36Sopenharmony_ci
103262306a36Sopenharmony_ci/* 0: GMAC2 -> GEPHY, 1: GMAC0 -> GePHY */
103362306a36Sopenharmony_ci#define MTK_MUX_GMAC2_GMAC0_TO_GEPHY    \
103462306a36Sopenharmony_ci	(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY | MTK_MUX | MTK_INFRA)
103562306a36Sopenharmony_ci
103662306a36Sopenharmony_ci/* 0: U3 -> QPHY, 1: GMAC2 -> QPHY */
103762306a36Sopenharmony_ci#define MTK_MUX_U3_GMAC2_TO_QPHY        \
103862306a36Sopenharmony_ci	(MTK_ETH_MUX_U3_GMAC2_TO_QPHY | MTK_MUX | MTK_INFRA)
103962306a36Sopenharmony_ci
104062306a36Sopenharmony_ci/* 2: GMAC1 -> SGMII, 3: GMAC2 -> SGMII */
104162306a36Sopenharmony_ci#define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII      \
104262306a36Sopenharmony_ci	(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \
104362306a36Sopenharmony_ci	MTK_SHARED_SGMII)
104462306a36Sopenharmony_ci
104562306a36Sopenharmony_ci/* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */
104662306a36Sopenharmony_ci#define MTK_MUX_GMAC12_TO_GEPHY_SGMII   \
104762306a36Sopenharmony_ci	(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX)
104862306a36Sopenharmony_ci
104962306a36Sopenharmony_ci#define MTK_HAS_CAPS(caps, _x)		(((caps) & (_x)) == (_x))
105062306a36Sopenharmony_ci
105162306a36Sopenharmony_ci#define MT7621_CAPS  (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \
105262306a36Sopenharmony_ci		      MTK_GMAC2_RGMII | MTK_SHARED_INT | \
105362306a36Sopenharmony_ci		      MTK_TRGMII_MT7621_CLK | MTK_QDMA)
105462306a36Sopenharmony_ci
105562306a36Sopenharmony_ci#define MT7622_CAPS  (MTK_GMAC1_RGMII | MTK_GMAC1_SGMII | MTK_GMAC2_RGMII | \
105662306a36Sopenharmony_ci		      MTK_GMAC2_SGMII | MTK_GDM1_ESW | \
105762306a36Sopenharmony_ci		      MTK_MUX_GDM1_TO_GMAC1_ESW | \
105862306a36Sopenharmony_ci		      MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_QDMA)
105962306a36Sopenharmony_ci
106062306a36Sopenharmony_ci#define MT7623_CAPS  (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | MTK_GMAC2_RGMII | \
106162306a36Sopenharmony_ci		      MTK_QDMA)
106262306a36Sopenharmony_ci
106362306a36Sopenharmony_ci#define MT7628_CAPS  (MTK_SHARED_INT | MTK_SOC_MT7628)
106462306a36Sopenharmony_ci
106562306a36Sopenharmony_ci#define MT7629_CAPS  (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
106662306a36Sopenharmony_ci		      MTK_GDM1_ESW | MTK_MUX_GDM1_TO_GMAC1_ESW | \
106762306a36Sopenharmony_ci		      MTK_MUX_GMAC2_GMAC0_TO_GEPHY | \
106862306a36Sopenharmony_ci		      MTK_MUX_U3_GMAC2_TO_QPHY | \
106962306a36Sopenharmony_ci		      MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA)
107062306a36Sopenharmony_ci
107162306a36Sopenharmony_ci#define MT7981_CAPS  (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \
107262306a36Sopenharmony_ci		      MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
107362306a36Sopenharmony_ci		      MTK_MUX_U3_GMAC2_TO_QPHY | MTK_U3_COPHY_V2 | \
107462306a36Sopenharmony_ci		      MTK_RSTCTRL_PPE1 | MTK_SRAM)
107562306a36Sopenharmony_ci
107662306a36Sopenharmony_ci#define MT7986_CAPS  (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | \
107762306a36Sopenharmony_ci		      MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \
107862306a36Sopenharmony_ci		      MTK_RSTCTRL_PPE1 | MTK_SRAM)
107962306a36Sopenharmony_ci
108062306a36Sopenharmony_ci#define MT7988_CAPS  (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_QDMA | \
108162306a36Sopenharmony_ci		      MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | MTK_SRAM)
108262306a36Sopenharmony_ci
108362306a36Sopenharmony_cistruct mtk_tx_dma_desc_info {
108462306a36Sopenharmony_ci	dma_addr_t	addr;
108562306a36Sopenharmony_ci	u32		size;
108662306a36Sopenharmony_ci	u16		vlan_tci;
108762306a36Sopenharmony_ci	u16		qid;
108862306a36Sopenharmony_ci	u8		gso:1;
108962306a36Sopenharmony_ci	u8		csum:1;
109062306a36Sopenharmony_ci	u8		vlan:1;
109162306a36Sopenharmony_ci	u8		first:1;
109262306a36Sopenharmony_ci	u8		last:1;
109362306a36Sopenharmony_ci};
109462306a36Sopenharmony_ci
109562306a36Sopenharmony_cistruct mtk_reg_map {
109662306a36Sopenharmony_ci	u32	tx_irq_mask;
109762306a36Sopenharmony_ci	u32	tx_irq_status;
109862306a36Sopenharmony_ci	struct {
109962306a36Sopenharmony_ci		u32	rx_ptr;		/* rx base pointer */
110062306a36Sopenharmony_ci		u32	rx_cnt_cfg;	/* rx max count configuration */
110162306a36Sopenharmony_ci		u32	pcrx_ptr;	/* rx cpu pointer */
110262306a36Sopenharmony_ci		u32	glo_cfg;	/* global configuration */
110362306a36Sopenharmony_ci		u32	rst_idx;	/* reset index */
110462306a36Sopenharmony_ci		u32	delay_irq;	/* delay interrupt */
110562306a36Sopenharmony_ci		u32	irq_status;	/* interrupt status */
110662306a36Sopenharmony_ci		u32	irq_mask;	/* interrupt mask */
110762306a36Sopenharmony_ci		u32	adma_rx_dbg0;
110862306a36Sopenharmony_ci		u32	int_grp;
110962306a36Sopenharmony_ci	} pdma;
111062306a36Sopenharmony_ci	struct {
111162306a36Sopenharmony_ci		u32	qtx_cfg;	/* tx queue configuration */
111262306a36Sopenharmony_ci		u32	qtx_sch;	/* tx queue scheduler configuration */
111362306a36Sopenharmony_ci		u32	rx_ptr;		/* rx base pointer */
111462306a36Sopenharmony_ci		u32	rx_cnt_cfg;	/* rx max count configuration */
111562306a36Sopenharmony_ci		u32	qcrx_ptr;	/* rx cpu pointer */
111662306a36Sopenharmony_ci		u32	glo_cfg;	/* global configuration */
111762306a36Sopenharmony_ci		u32	rst_idx;	/* reset index */
111862306a36Sopenharmony_ci		u32	delay_irq;	/* delay interrupt */
111962306a36Sopenharmony_ci		u32	fc_th;		/* flow control */
112062306a36Sopenharmony_ci		u32	int_grp;
112162306a36Sopenharmony_ci		u32	hred;		/* interrupt mask */
112262306a36Sopenharmony_ci		u32	ctx_ptr;	/* tx acquire cpu pointer */
112362306a36Sopenharmony_ci		u32	dtx_ptr;	/* tx acquire dma pointer */
112462306a36Sopenharmony_ci		u32	crx_ptr;	/* tx release cpu pointer */
112562306a36Sopenharmony_ci		u32	drx_ptr;	/* tx release dma pointer */
112662306a36Sopenharmony_ci		u32	fq_head;	/* fq head pointer */
112762306a36Sopenharmony_ci		u32	fq_tail;	/* fq tail pointer */
112862306a36Sopenharmony_ci		u32	fq_count;	/* fq free page count */
112962306a36Sopenharmony_ci		u32	fq_blen;	/* fq free page buffer length */
113062306a36Sopenharmony_ci		u32	tx_sch_rate;	/* tx scheduler rate control registers */
113162306a36Sopenharmony_ci	} qdma;
113262306a36Sopenharmony_ci	u32	gdm1_cnt;
113362306a36Sopenharmony_ci	u32	gdma_to_ppe;
113462306a36Sopenharmony_ci	u32	ppe_base;
113562306a36Sopenharmony_ci	u32	wdma_base[2];
113662306a36Sopenharmony_ci	u32	pse_iq_sta;
113762306a36Sopenharmony_ci	u32	pse_oq_sta;
113862306a36Sopenharmony_ci};
113962306a36Sopenharmony_ci
114062306a36Sopenharmony_ci/* struct mtk_eth_data -	This is the structure holding all differences
114162306a36Sopenharmony_ci *				among various plaforms
114262306a36Sopenharmony_ci * @reg_map			Soc register map.
114362306a36Sopenharmony_ci * @ana_rgc3:                   The offset for register ANA_RGC3 related to
114462306a36Sopenharmony_ci *				sgmiisys syscon
114562306a36Sopenharmony_ci * @caps			Flags shown the extra capability for the SoC
114662306a36Sopenharmony_ci * @hw_features			Flags shown HW features
114762306a36Sopenharmony_ci * @required_clks		Flags shown the bitmap for required clocks on
114862306a36Sopenharmony_ci *				the target SoC
114962306a36Sopenharmony_ci * @required_pctl		A bool value to show whether the SoC requires
115062306a36Sopenharmony_ci *				the extra setup for those pins used by GMAC.
115162306a36Sopenharmony_ci * @hash_offset			Flow table hash offset.
115262306a36Sopenharmony_ci * @version			SoC version.
115362306a36Sopenharmony_ci * @foe_entry_size		Foe table entry size.
115462306a36Sopenharmony_ci * @has_accounting		Bool indicating support for accounting of
115562306a36Sopenharmony_ci *				offloaded flows.
115662306a36Sopenharmony_ci * @txd_size			Tx DMA descriptor size.
115762306a36Sopenharmony_ci * @rxd_size			Rx DMA descriptor size.
115862306a36Sopenharmony_ci * @rx_irq_done_mask		Rx irq done register mask.
115962306a36Sopenharmony_ci * @rx_dma_l4_valid		Rx DMA valid register mask.
116062306a36Sopenharmony_ci * @dma_max_len			Max DMA tx/rx buffer length.
116162306a36Sopenharmony_ci * @dma_len_offset		Tx/Rx DMA length field offset.
116262306a36Sopenharmony_ci */
116362306a36Sopenharmony_cistruct mtk_soc_data {
116462306a36Sopenharmony_ci	const struct mtk_reg_map *reg_map;
116562306a36Sopenharmony_ci	u32             ana_rgc3;
116662306a36Sopenharmony_ci	u64		caps;
116762306a36Sopenharmony_ci	u64		required_clks;
116862306a36Sopenharmony_ci	bool		required_pctl;
116962306a36Sopenharmony_ci	u8		offload_version;
117062306a36Sopenharmony_ci	u8		hash_offset;
117162306a36Sopenharmony_ci	u8		version;
117262306a36Sopenharmony_ci	u16		foe_entry_size;
117362306a36Sopenharmony_ci	netdev_features_t hw_features;
117462306a36Sopenharmony_ci	bool		has_accounting;
117562306a36Sopenharmony_ci	bool		disable_pll_modes;
117662306a36Sopenharmony_ci	struct {
117762306a36Sopenharmony_ci		u32	txd_size;
117862306a36Sopenharmony_ci		u32	rxd_size;
117962306a36Sopenharmony_ci		u32	rx_irq_done_mask;
118062306a36Sopenharmony_ci		u32	rx_dma_l4_valid;
118162306a36Sopenharmony_ci		u32	dma_max_len;
118262306a36Sopenharmony_ci		u32	dma_len_offset;
118362306a36Sopenharmony_ci	} txrx;
118462306a36Sopenharmony_ci};
118562306a36Sopenharmony_ci
118662306a36Sopenharmony_ci#define MTK_DMA_MONITOR_TIMEOUT		msecs_to_jiffies(1000)
118762306a36Sopenharmony_ci
118862306a36Sopenharmony_ci/* currently no SoC has more than 3 macs */
118962306a36Sopenharmony_ci#define MTK_MAX_DEVS	3
119062306a36Sopenharmony_ci
119162306a36Sopenharmony_ci/* struct mtk_eth -	This is the main datasructure for holding the state
119262306a36Sopenharmony_ci *			of the driver
119362306a36Sopenharmony_ci * @dev:		The device pointer
119462306a36Sopenharmony_ci * @dev:		The device pointer used for dma mapping/alloc
119562306a36Sopenharmony_ci * @base:		The mapped register i/o base
119662306a36Sopenharmony_ci * @page_lock:		Make sure that register operations are atomic
119762306a36Sopenharmony_ci * @tx_irq__lock:	Make sure that IRQ register operations are atomic
119862306a36Sopenharmony_ci * @rx_irq__lock:	Make sure that IRQ register operations are atomic
119962306a36Sopenharmony_ci * @dim_lock:		Make sure that Net DIM operations are atomic
120062306a36Sopenharmony_ci * @dummy_dev:		we run 2 netdevs on 1 physical DMA ring and need a
120162306a36Sopenharmony_ci *			dummy for NAPI to work
120262306a36Sopenharmony_ci * @netdev:		The netdev instances
120362306a36Sopenharmony_ci * @mac:		Each netdev is linked to a physical MAC
120462306a36Sopenharmony_ci * @irq:		The IRQ that we are using
120562306a36Sopenharmony_ci * @msg_enable:		Ethtool msg level
120662306a36Sopenharmony_ci * @ethsys:		The register map pointing at the range used to setup
120762306a36Sopenharmony_ci *			MII modes
120862306a36Sopenharmony_ci * @infra:              The register map pointing at the range used to setup
120962306a36Sopenharmony_ci *                      SGMII and GePHY path
121062306a36Sopenharmony_ci * @sgmii_pcs:		Pointers to mtk-pcs-lynxi phylink_pcs instances
121162306a36Sopenharmony_ci * @pctl:		The register map pointing at the range used to setup
121262306a36Sopenharmony_ci *			GMAC port drive/slew values
121362306a36Sopenharmony_ci * @dma_refcnt:		track how many netdevs are using the DMA engine
121462306a36Sopenharmony_ci * @tx_ring:		Pointer to the memory holding info about the TX ring
121562306a36Sopenharmony_ci * @rx_ring:		Pointer to the memory holding info about the RX ring
121662306a36Sopenharmony_ci * @rx_ring_qdma:	Pointer to the memory holding info about the QDMA RX ring
121762306a36Sopenharmony_ci * @tx_napi:		The TX NAPI struct
121862306a36Sopenharmony_ci * @rx_napi:		The RX NAPI struct
121962306a36Sopenharmony_ci * @rx_events:		Net DIM RX event counter
122062306a36Sopenharmony_ci * @rx_packets:		Net DIM RX packet counter
122162306a36Sopenharmony_ci * @rx_bytes:		Net DIM RX byte counter
122262306a36Sopenharmony_ci * @rx_dim:		Net DIM RX context
122362306a36Sopenharmony_ci * @tx_events:		Net DIM TX event counter
122462306a36Sopenharmony_ci * @tx_packets:		Net DIM TX packet counter
122562306a36Sopenharmony_ci * @tx_bytes:		Net DIM TX byte counter
122662306a36Sopenharmony_ci * @tx_dim:		Net DIM TX context
122762306a36Sopenharmony_ci * @scratch_ring:	Newer SoCs need memory for a second HW managed TX ring
122862306a36Sopenharmony_ci * @phy_scratch_ring:	physical address of scratch_ring
122962306a36Sopenharmony_ci * @scratch_head:	The scratch memory that scratch_ring points to.
123062306a36Sopenharmony_ci * @clks:		clock array for all clocks required
123162306a36Sopenharmony_ci * @mii_bus:		If there is a bus we need to create an instance for it
123262306a36Sopenharmony_ci * @pending_work:	The workqueue used to reset the dma ring
123362306a36Sopenharmony_ci * @state:		Initialization and runtime state of the device
123462306a36Sopenharmony_ci * @soc:		Holding specific data among vaious SoCs
123562306a36Sopenharmony_ci */
123662306a36Sopenharmony_ci
123762306a36Sopenharmony_cistruct mtk_eth {
123862306a36Sopenharmony_ci	struct device			*dev;
123962306a36Sopenharmony_ci	struct device			*dma_dev;
124062306a36Sopenharmony_ci	void __iomem			*base;
124162306a36Sopenharmony_ci	void				*sram_base;
124262306a36Sopenharmony_ci	spinlock_t			page_lock;
124362306a36Sopenharmony_ci	spinlock_t			tx_irq_lock;
124462306a36Sopenharmony_ci	spinlock_t			rx_irq_lock;
124562306a36Sopenharmony_ci	struct net_device		dummy_dev;
124662306a36Sopenharmony_ci	struct net_device		*netdev[MTK_MAX_DEVS];
124762306a36Sopenharmony_ci	struct mtk_mac			*mac[MTK_MAX_DEVS];
124862306a36Sopenharmony_ci	int				irq[3];
124962306a36Sopenharmony_ci	u32				msg_enable;
125062306a36Sopenharmony_ci	unsigned long			sysclk;
125162306a36Sopenharmony_ci	struct regmap			*ethsys;
125262306a36Sopenharmony_ci	struct regmap			*infra;
125362306a36Sopenharmony_ci	struct phylink_pcs		*sgmii_pcs[MTK_MAX_DEVS];
125462306a36Sopenharmony_ci	struct regmap			*pctl;
125562306a36Sopenharmony_ci	bool				hwlro;
125662306a36Sopenharmony_ci	refcount_t			dma_refcnt;
125762306a36Sopenharmony_ci	struct mtk_tx_ring		tx_ring;
125862306a36Sopenharmony_ci	struct mtk_rx_ring		rx_ring[MTK_MAX_RX_RING_NUM];
125962306a36Sopenharmony_ci	struct mtk_rx_ring		rx_ring_qdma;
126062306a36Sopenharmony_ci	struct napi_struct		tx_napi;
126162306a36Sopenharmony_ci	struct napi_struct		rx_napi;
126262306a36Sopenharmony_ci	void				*scratch_ring;
126362306a36Sopenharmony_ci	dma_addr_t			phy_scratch_ring;
126462306a36Sopenharmony_ci	void				*scratch_head;
126562306a36Sopenharmony_ci	struct clk			*clks[MTK_CLK_MAX];
126662306a36Sopenharmony_ci
126762306a36Sopenharmony_ci	struct mii_bus			*mii_bus;
126862306a36Sopenharmony_ci	struct work_struct		pending_work;
126962306a36Sopenharmony_ci	unsigned long			state;
127062306a36Sopenharmony_ci
127162306a36Sopenharmony_ci	const struct mtk_soc_data	*soc;
127262306a36Sopenharmony_ci
127362306a36Sopenharmony_ci	spinlock_t			dim_lock;
127462306a36Sopenharmony_ci
127562306a36Sopenharmony_ci	u32				rx_events;
127662306a36Sopenharmony_ci	u32				rx_packets;
127762306a36Sopenharmony_ci	u32				rx_bytes;
127862306a36Sopenharmony_ci	struct dim			rx_dim;
127962306a36Sopenharmony_ci
128062306a36Sopenharmony_ci	u32				tx_events;
128162306a36Sopenharmony_ci	u32				tx_packets;
128262306a36Sopenharmony_ci	u32				tx_bytes;
128362306a36Sopenharmony_ci	struct dim			tx_dim;
128462306a36Sopenharmony_ci
128562306a36Sopenharmony_ci	int				ip_align;
128662306a36Sopenharmony_ci
128762306a36Sopenharmony_ci	struct metadata_dst		*dsa_meta[MTK_MAX_DSA_PORTS];
128862306a36Sopenharmony_ci
128962306a36Sopenharmony_ci	struct mtk_ppe			*ppe[2];
129062306a36Sopenharmony_ci	struct rhashtable		flow_table;
129162306a36Sopenharmony_ci
129262306a36Sopenharmony_ci	struct bpf_prog			__rcu *prog;
129362306a36Sopenharmony_ci
129462306a36Sopenharmony_ci	struct {
129562306a36Sopenharmony_ci		struct delayed_work monitor_work;
129662306a36Sopenharmony_ci		u32 wdidx;
129762306a36Sopenharmony_ci		u8 wdma_hang_count;
129862306a36Sopenharmony_ci		u8 qdma_hang_count;
129962306a36Sopenharmony_ci		u8 adma_hang_count;
130062306a36Sopenharmony_ci	} reset;
130162306a36Sopenharmony_ci};
130262306a36Sopenharmony_ci
130362306a36Sopenharmony_ci/* struct mtk_mac -	the structure that holds the info about the MACs of the
130462306a36Sopenharmony_ci *			SoC
130562306a36Sopenharmony_ci * @id:			The number of the MAC
130662306a36Sopenharmony_ci * @interface:		Interface mode kept for detecting change in hw settings
130762306a36Sopenharmony_ci * @of_node:		Our devicetree node
130862306a36Sopenharmony_ci * @hw:			Backpointer to our main datastruture
130962306a36Sopenharmony_ci * @hw_stats:		Packet statistics counter
131062306a36Sopenharmony_ci */
131162306a36Sopenharmony_cistruct mtk_mac {
131262306a36Sopenharmony_ci	int				id;
131362306a36Sopenharmony_ci	phy_interface_t			interface;
131462306a36Sopenharmony_ci	int				speed;
131562306a36Sopenharmony_ci	struct device_node		*of_node;
131662306a36Sopenharmony_ci	struct phylink			*phylink;
131762306a36Sopenharmony_ci	struct phylink_config		phylink_config;
131862306a36Sopenharmony_ci	struct mtk_eth			*hw;
131962306a36Sopenharmony_ci	struct mtk_hw_stats		*hw_stats;
132062306a36Sopenharmony_ci	__be32				hwlro_ip[MTK_MAX_LRO_IP_CNT];
132162306a36Sopenharmony_ci	int				hwlro_ip_cnt;
132262306a36Sopenharmony_ci	unsigned int			syscfg0;
132362306a36Sopenharmony_ci	struct notifier_block		device_notifier;
132462306a36Sopenharmony_ci};
132562306a36Sopenharmony_ci
132662306a36Sopenharmony_ci/* the struct describing the SoC. these are declared in the soc_xyz.c files */
132762306a36Sopenharmony_ciextern const struct of_device_id of_mtk_match[];
132862306a36Sopenharmony_ci
132962306a36Sopenharmony_cistatic inline bool mtk_is_netsys_v1(struct mtk_eth *eth)
133062306a36Sopenharmony_ci{
133162306a36Sopenharmony_ci	return eth->soc->version == 1;
133262306a36Sopenharmony_ci}
133362306a36Sopenharmony_ci
133462306a36Sopenharmony_cistatic inline bool mtk_is_netsys_v2_or_greater(struct mtk_eth *eth)
133562306a36Sopenharmony_ci{
133662306a36Sopenharmony_ci	return eth->soc->version > 1;
133762306a36Sopenharmony_ci}
133862306a36Sopenharmony_ci
133962306a36Sopenharmony_cistatic inline bool mtk_is_netsys_v3_or_greater(struct mtk_eth *eth)
134062306a36Sopenharmony_ci{
134162306a36Sopenharmony_ci	return eth->soc->version > 2;
134262306a36Sopenharmony_ci}
134362306a36Sopenharmony_ci
134462306a36Sopenharmony_cistatic inline struct mtk_foe_entry *
134562306a36Sopenharmony_cimtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
134662306a36Sopenharmony_ci{
134762306a36Sopenharmony_ci	const struct mtk_soc_data *soc = ppe->eth->soc;
134862306a36Sopenharmony_ci
134962306a36Sopenharmony_ci	return ppe->foe_table + hash * soc->foe_entry_size;
135062306a36Sopenharmony_ci}
135162306a36Sopenharmony_ci
135262306a36Sopenharmony_cistatic inline u32 mtk_get_ib1_ts_mask(struct mtk_eth *eth)
135362306a36Sopenharmony_ci{
135462306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
135562306a36Sopenharmony_ci		return MTK_FOE_IB1_BIND_TIMESTAMP_V2;
135662306a36Sopenharmony_ci
135762306a36Sopenharmony_ci	return MTK_FOE_IB1_BIND_TIMESTAMP;
135862306a36Sopenharmony_ci}
135962306a36Sopenharmony_ci
136062306a36Sopenharmony_cistatic inline u32 mtk_get_ib1_ppoe_mask(struct mtk_eth *eth)
136162306a36Sopenharmony_ci{
136262306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
136362306a36Sopenharmony_ci		return MTK_FOE_IB1_BIND_PPPOE_V2;
136462306a36Sopenharmony_ci
136562306a36Sopenharmony_ci	return MTK_FOE_IB1_BIND_PPPOE;
136662306a36Sopenharmony_ci}
136762306a36Sopenharmony_ci
136862306a36Sopenharmony_cistatic inline u32 mtk_get_ib1_vlan_tag_mask(struct mtk_eth *eth)
136962306a36Sopenharmony_ci{
137062306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
137162306a36Sopenharmony_ci		return MTK_FOE_IB1_BIND_VLAN_TAG_V2;
137262306a36Sopenharmony_ci
137362306a36Sopenharmony_ci	return MTK_FOE_IB1_BIND_VLAN_TAG;
137462306a36Sopenharmony_ci}
137562306a36Sopenharmony_ci
137662306a36Sopenharmony_cistatic inline u32 mtk_get_ib1_vlan_layer_mask(struct mtk_eth *eth)
137762306a36Sopenharmony_ci{
137862306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
137962306a36Sopenharmony_ci		return MTK_FOE_IB1_BIND_VLAN_LAYER_V2;
138062306a36Sopenharmony_ci
138162306a36Sopenharmony_ci	return MTK_FOE_IB1_BIND_VLAN_LAYER;
138262306a36Sopenharmony_ci}
138362306a36Sopenharmony_ci
138462306a36Sopenharmony_cistatic inline u32 mtk_prep_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
138562306a36Sopenharmony_ci{
138662306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
138762306a36Sopenharmony_ci		return FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER_V2, val);
138862306a36Sopenharmony_ci
138962306a36Sopenharmony_ci	return FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, val);
139062306a36Sopenharmony_ci}
139162306a36Sopenharmony_ci
139262306a36Sopenharmony_cistatic inline u32 mtk_get_ib1_vlan_layer(struct mtk_eth *eth, u32 val)
139362306a36Sopenharmony_ci{
139462306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
139562306a36Sopenharmony_ci		return FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER_V2, val);
139662306a36Sopenharmony_ci
139762306a36Sopenharmony_ci	return FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER, val);
139862306a36Sopenharmony_ci}
139962306a36Sopenharmony_ci
140062306a36Sopenharmony_cistatic inline u32 mtk_get_ib1_pkt_type_mask(struct mtk_eth *eth)
140162306a36Sopenharmony_ci{
140262306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
140362306a36Sopenharmony_ci		return MTK_FOE_IB1_PACKET_TYPE_V2;
140462306a36Sopenharmony_ci
140562306a36Sopenharmony_ci	return MTK_FOE_IB1_PACKET_TYPE;
140662306a36Sopenharmony_ci}
140762306a36Sopenharmony_ci
140862306a36Sopenharmony_cistatic inline u32 mtk_get_ib1_pkt_type(struct mtk_eth *eth, u32 val)
140962306a36Sopenharmony_ci{
141062306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
141162306a36Sopenharmony_ci		return FIELD_GET(MTK_FOE_IB1_PACKET_TYPE_V2, val);
141262306a36Sopenharmony_ci
141362306a36Sopenharmony_ci	return FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, val);
141462306a36Sopenharmony_ci}
141562306a36Sopenharmony_ci
141662306a36Sopenharmony_cistatic inline u32 mtk_get_ib2_multicast_mask(struct mtk_eth *eth)
141762306a36Sopenharmony_ci{
141862306a36Sopenharmony_ci	if (mtk_is_netsys_v2_or_greater(eth))
141962306a36Sopenharmony_ci		return MTK_FOE_IB2_MULTICAST_V2;
142062306a36Sopenharmony_ci
142162306a36Sopenharmony_ci	return MTK_FOE_IB2_MULTICAST;
142262306a36Sopenharmony_ci}
142362306a36Sopenharmony_ci
142462306a36Sopenharmony_ci/* read the hardware status register */
142562306a36Sopenharmony_civoid mtk_stats_update_mac(struct mtk_mac *mac);
142662306a36Sopenharmony_ci
142762306a36Sopenharmony_civoid mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg);
142862306a36Sopenharmony_ciu32 mtk_r32(struct mtk_eth *eth, unsigned reg);
142962306a36Sopenharmony_ciu32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned int reg);
143062306a36Sopenharmony_ci
143162306a36Sopenharmony_ciint mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id);
143262306a36Sopenharmony_ciint mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
143362306a36Sopenharmony_ciint mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id);
143462306a36Sopenharmony_ci
143562306a36Sopenharmony_ciint mtk_eth_offload_init(struct mtk_eth *eth);
143662306a36Sopenharmony_ciint mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
143762306a36Sopenharmony_ci		     void *type_data);
143862306a36Sopenharmony_ciint mtk_flow_offload_cmd(struct mtk_eth *eth, struct flow_cls_offload *cls,
143962306a36Sopenharmony_ci			 int ppe_index);
144062306a36Sopenharmony_civoid mtk_flow_offload_cleanup(struct mtk_eth *eth, struct list_head *list);
144162306a36Sopenharmony_civoid mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
144262306a36Sopenharmony_ci
144362306a36Sopenharmony_ci
144462306a36Sopenharmony_ci#endif /* MTK_ETH_H */
1445