xref: /openbmc/linux/drivers/net/ethernet/mediatek/mtk_ppe.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1ba37b7caSFelix Fietkau // SPDX-License-Identifier: GPL-2.0-only
2ba37b7caSFelix Fietkau /* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
3ba37b7caSFelix Fietkau 
4ba37b7caSFelix Fietkau #ifndef __MTK_PPE_H
5ba37b7caSFelix Fietkau #define __MTK_PPE_H
6ba37b7caSFelix Fietkau 
7ba37b7caSFelix Fietkau #include <linux/kernel.h>
8ba37b7caSFelix Fietkau #include <linux/bitfield.h>
933fc42deSFelix Fietkau #include <linux/rhashtable.h>
10ba37b7caSFelix Fietkau 
11ba37b7caSFelix Fietkau #define MTK_PPE_ENTRIES_SHIFT		3
12ba37b7caSFelix Fietkau #define MTK_PPE_ENTRIES			(1024 << MTK_PPE_ENTRIES_SHIFT)
13ba37b7caSFelix Fietkau #define MTK_PPE_HASH_MASK		(MTK_PPE_ENTRIES - 1)
14c5d66587SIlya Lipnitskiy #define MTK_PPE_WAIT_TIMEOUT_US		1000000
15ba37b7caSFelix Fietkau 
16ba37b7caSFelix Fietkau #define MTK_FOE_IB1_UNBIND_TIMESTAMP	GENMASK(7, 0)
17ba37b7caSFelix Fietkau #define MTK_FOE_IB1_UNBIND_PACKETS	GENMASK(23, 8)
18ba37b7caSFelix Fietkau #define MTK_FOE_IB1_UNBIND_PREBIND	BIT(24)
19ba37b7caSFelix Fietkau 
20ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_TIMESTAMP	GENMASK(14, 0)
21ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_KEEPALIVE	BIT(15)
22ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_VLAN_LAYER	GENMASK(18, 16)
23ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_PPPOE		BIT(19)
24ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_VLAN_TAG	BIT(20)
25ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_PKT_SAMPLE	BIT(21)
26ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_CACHE		BIT(22)
27ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_TUNNEL_DECAP	BIT(23)
28ba37b7caSFelix Fietkau #define MTK_FOE_IB1_BIND_TTL		BIT(24)
29ba37b7caSFelix Fietkau 
30ba37b7caSFelix Fietkau #define MTK_FOE_IB1_PACKET_TYPE		GENMASK(27, 25)
31ba37b7caSFelix Fietkau #define MTK_FOE_IB1_STATE		GENMASK(29, 28)
32ba37b7caSFelix Fietkau #define MTK_FOE_IB1_UDP			BIT(30)
33ba37b7caSFelix Fietkau #define MTK_FOE_IB1_STATIC		BIT(31)
34ba37b7caSFelix Fietkau 
3503a3180eSLorenzo Bianconi /* CONFIG_MEDIATEK_NETSYS_V2 */
3603a3180eSLorenzo Bianconi #define MTK_FOE_IB1_BIND_TIMESTAMP_V2	GENMASK(7, 0)
3703a3180eSLorenzo Bianconi #define MTK_FOE_IB1_BIND_VLAN_LAYER_V2	GENMASK(16, 14)
3803a3180eSLorenzo Bianconi #define MTK_FOE_IB1_BIND_PPPOE_V2	BIT(17)
3903a3180eSLorenzo Bianconi #define MTK_FOE_IB1_BIND_VLAN_TAG_V2	BIT(18)
4003a3180eSLorenzo Bianconi #define MTK_FOE_IB1_BIND_CACHE_V2	BIT(20)
4103a3180eSLorenzo Bianconi #define MTK_FOE_IB1_BIND_TTL_V2		BIT(22)
4203a3180eSLorenzo Bianconi #define MTK_FOE_IB1_PACKET_TYPE_V2	GENMASK(27, 23)
4303a3180eSLorenzo Bianconi 
44ba37b7caSFelix Fietkau enum {
45ba37b7caSFelix Fietkau 	MTK_PPE_PKT_TYPE_IPV4_HNAPT = 0,
46ba37b7caSFelix Fietkau 	MTK_PPE_PKT_TYPE_IPV4_ROUTE = 1,
47ba37b7caSFelix Fietkau 	MTK_PPE_PKT_TYPE_BRIDGE = 2,
48ba37b7caSFelix Fietkau 	MTK_PPE_PKT_TYPE_IPV4_DSLITE = 3,
49ba37b7caSFelix Fietkau 	MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T = 4,
50ba37b7caSFelix Fietkau 	MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T = 5,
51ba37b7caSFelix Fietkau 	MTK_PPE_PKT_TYPE_IPV6_6RD = 7,
52ba37b7caSFelix Fietkau };
53ba37b7caSFelix Fietkau 
54ba37b7caSFelix Fietkau #define MTK_FOE_IB2_QID			GENMASK(3, 0)
55ba37b7caSFelix Fietkau #define MTK_FOE_IB2_PSE_QOS		BIT(4)
56ba37b7caSFelix Fietkau #define MTK_FOE_IB2_DEST_PORT		GENMASK(7, 5)
57ba37b7caSFelix Fietkau #define MTK_FOE_IB2_MULTICAST		BIT(8)
584eaeca1fSFelix Fietkau #define MTK_FOE_IB2_MIB_CNT		BIT(10)
59ba37b7caSFelix Fietkau 
60a333215eSFelix Fietkau #define MTK_FOE_IB2_WDMA_QID2		GENMASK(13, 12)
614eaeca1fSFelix Fietkau #define MTK_FOE_IB2_MIB_CNT_V2		BIT(15)
62a333215eSFelix Fietkau #define MTK_FOE_IB2_WDMA_DEVIDX		BIT(16)
63a333215eSFelix Fietkau #define MTK_FOE_IB2_WDMA_WINFO		BIT(17)
64ba37b7caSFelix Fietkau 
65ba37b7caSFelix Fietkau #define MTK_FOE_IB2_PORT_MG		GENMASK(17, 12)
66ba37b7caSFelix Fietkau 
6703a3180eSLorenzo Bianconi #define MTK_FOE_IB2_RX_IDX		GENMASK(18, 17)
68ba37b7caSFelix Fietkau #define MTK_FOE_IB2_PORT_AG		GENMASK(23, 18)
69ba37b7caSFelix Fietkau 
70ba37b7caSFelix Fietkau #define MTK_FOE_IB2_DSCP		GENMASK(31, 24)
71ba37b7caSFelix Fietkau 
7203a3180eSLorenzo Bianconi /* CONFIG_MEDIATEK_NETSYS_V2 */
738bd8dcc5SFelix Fietkau #define MTK_FOE_IB2_QID_V2			GENMASK(6, 0)
7403a3180eSLorenzo Bianconi #define MTK_FOE_IB2_PORT_MG_V2		BIT(7)
758bd8dcc5SFelix Fietkau #define MTK_FOE_IB2_PSE_QOS_V2		BIT(8)
7603a3180eSLorenzo Bianconi #define MTK_FOE_IB2_DEST_PORT_V2	GENMASK(12, 9)
7703a3180eSLorenzo Bianconi #define MTK_FOE_IB2_MULTICAST_V2	BIT(13)
7803a3180eSLorenzo Bianconi #define MTK_FOE_IB2_WDMA_WINFO_V2	BIT(19)
7903a3180eSLorenzo Bianconi #define MTK_FOE_IB2_PORT_AG_V2		GENMASK(23, 20)
8003a3180eSLorenzo Bianconi 
81a333215eSFelix Fietkau #define MTK_FOE_VLAN2_WINFO_BSS		GENMASK(5, 0)
82a333215eSFelix Fietkau #define MTK_FOE_VLAN2_WINFO_WCID	GENMASK(13, 6)
83a333215eSFelix Fietkau #define MTK_FOE_VLAN2_WINFO_RING	GENMASK(15, 14)
84ba37b7caSFelix Fietkau 
8503a3180eSLorenzo Bianconi #define MTK_FOE_WINFO_BSS		GENMASK(5, 0)
8603a3180eSLorenzo Bianconi #define MTK_FOE_WINFO_WCID		GENMASK(15, 6)
8703a3180eSLorenzo Bianconi 
88*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_BSS_V3		GENMASK(23, 16)
89*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_WCID_V3		GENMASK(15, 0)
90*88efedf5SLorenzo Bianconi 
91*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_PAO_USR_INFO	GENMASK(15, 0)
92*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_PAO_TID		GENMASK(19, 16)
93*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_PAO_IS_FIXEDRATE	BIT(20)
94*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_PAO_IS_PRIOR	BIT(21)
95*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_PAO_IS_SP		BIT(22)
96*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_PAO_HF		BIT(23)
97*88efedf5SLorenzo Bianconi #define MTK_FOE_WINFO_PAO_AMSDU_EN	BIT(24)
98*88efedf5SLorenzo Bianconi 
99ba37b7caSFelix Fietkau enum {
100ba37b7caSFelix Fietkau 	MTK_FOE_STATE_INVALID,
101ba37b7caSFelix Fietkau 	MTK_FOE_STATE_UNBIND,
102ba37b7caSFelix Fietkau 	MTK_FOE_STATE_BIND,
103ba37b7caSFelix Fietkau 	MTK_FOE_STATE_FIN
104ba37b7caSFelix Fietkau };
105ba37b7caSFelix Fietkau 
106ba37b7caSFelix Fietkau struct mtk_foe_mac_info {
107ba37b7caSFelix Fietkau 	u16 vlan1;
108ba37b7caSFelix Fietkau 	u16 etype;
109ba37b7caSFelix Fietkau 
110ba37b7caSFelix Fietkau 	u32 dest_mac_hi;
111ba37b7caSFelix Fietkau 
112ba37b7caSFelix Fietkau 	u16 vlan2;
113ba37b7caSFelix Fietkau 	u16 dest_mac_lo;
114ba37b7caSFelix Fietkau 
115ba37b7caSFelix Fietkau 	u32 src_mac_hi;
116ba37b7caSFelix Fietkau 
117ba37b7caSFelix Fietkau 	u16 pppoe_id;
118ba37b7caSFelix Fietkau 	u16 src_mac_lo;
11903a3180eSLorenzo Bianconi 
120*88efedf5SLorenzo Bianconi 	/* netsys_v2 */
12103a3180eSLorenzo Bianconi 	u16 minfo;
12203a3180eSLorenzo Bianconi 	u16 winfo;
123*88efedf5SLorenzo Bianconi 
124*88efedf5SLorenzo Bianconi 	/* netsys_v3 */
125*88efedf5SLorenzo Bianconi 	u32 w3info;
126*88efedf5SLorenzo Bianconi 	u32 wpao;
127ba37b7caSFelix Fietkau };
128ba37b7caSFelix Fietkau 
12933fc42deSFelix Fietkau /* software-only entry type */
130ba37b7caSFelix Fietkau struct mtk_foe_bridge {
13133fc42deSFelix Fietkau 	u8 dest_mac[ETH_ALEN];
13233fc42deSFelix Fietkau 	u8 src_mac[ETH_ALEN];
13333fc42deSFelix Fietkau 	u16 vlan;
134ba37b7caSFelix Fietkau 
13533fc42deSFelix Fietkau 	struct {} key_end;
136ba37b7caSFelix Fietkau 
137ba37b7caSFelix Fietkau 	u32 ib2;
138ba37b7caSFelix Fietkau 
139ba37b7caSFelix Fietkau 	struct mtk_foe_mac_info l2;
140ba37b7caSFelix Fietkau };
141ba37b7caSFelix Fietkau 
142ba37b7caSFelix Fietkau struct mtk_ipv4_tuple {
143ba37b7caSFelix Fietkau 	u32 src_ip;
144ba37b7caSFelix Fietkau 	u32 dest_ip;
145ba37b7caSFelix Fietkau 	union {
146ba37b7caSFelix Fietkau 		struct {
147ba37b7caSFelix Fietkau 			u16 dest_port;
148ba37b7caSFelix Fietkau 			u16 src_port;
149ba37b7caSFelix Fietkau 		};
150ba37b7caSFelix Fietkau 		struct {
151ba37b7caSFelix Fietkau 			u8 protocol;
152ba37b7caSFelix Fietkau 			u8 _pad[3]; /* fill with 0xa5a5a5 */
153ba37b7caSFelix Fietkau 		};
154ba37b7caSFelix Fietkau 		u32 ports;
155ba37b7caSFelix Fietkau 	};
156ba37b7caSFelix Fietkau };
157ba37b7caSFelix Fietkau 
158ba37b7caSFelix Fietkau struct mtk_foe_ipv4 {
159ba37b7caSFelix Fietkau 	struct mtk_ipv4_tuple orig;
160ba37b7caSFelix Fietkau 
161ba37b7caSFelix Fietkau 	u32 ib2;
162ba37b7caSFelix Fietkau 
163ba37b7caSFelix Fietkau 	struct mtk_ipv4_tuple new;
164ba37b7caSFelix Fietkau 
165ba37b7caSFelix Fietkau 	u16 timestamp;
166ba37b7caSFelix Fietkau 	u16 _rsv0[3];
167ba37b7caSFelix Fietkau 
168ba37b7caSFelix Fietkau 	u32 udf_tsid;
169ba37b7caSFelix Fietkau 
170ba37b7caSFelix Fietkau 	struct mtk_foe_mac_info l2;
171ba37b7caSFelix Fietkau };
172ba37b7caSFelix Fietkau 
173ba37b7caSFelix Fietkau struct mtk_foe_ipv4_dslite {
174ba37b7caSFelix Fietkau 	struct mtk_ipv4_tuple ip4;
175ba37b7caSFelix Fietkau 
176ba37b7caSFelix Fietkau 	u32 tunnel_src_ip[4];
177ba37b7caSFelix Fietkau 	u32 tunnel_dest_ip[4];
178ba37b7caSFelix Fietkau 
179ba37b7caSFelix Fietkau 	u8 flow_label[3];
180ba37b7caSFelix Fietkau 	u8 priority;
181ba37b7caSFelix Fietkau 
182ba37b7caSFelix Fietkau 	u32 udf_tsid;
183ba37b7caSFelix Fietkau 
184ba37b7caSFelix Fietkau 	u32 ib2;
185ba37b7caSFelix Fietkau 
186ba37b7caSFelix Fietkau 	struct mtk_foe_mac_info l2;
187ba37b7caSFelix Fietkau };
188ba37b7caSFelix Fietkau 
189ba37b7caSFelix Fietkau struct mtk_foe_ipv6 {
190ba37b7caSFelix Fietkau 	u32 src_ip[4];
191ba37b7caSFelix Fietkau 	u32 dest_ip[4];
192ba37b7caSFelix Fietkau 
193ba37b7caSFelix Fietkau 	union {
194ba37b7caSFelix Fietkau 		struct {
195ba37b7caSFelix Fietkau 			u8 protocol;
196ba37b7caSFelix Fietkau 			u8 _pad[3]; /* fill with 0xa5a5a5 */
197ba37b7caSFelix Fietkau 		}; /* 3-tuple */
198ba37b7caSFelix Fietkau 		struct {
199ba37b7caSFelix Fietkau 			u16 dest_port;
200ba37b7caSFelix Fietkau 			u16 src_port;
201ba37b7caSFelix Fietkau 		}; /* 5-tuple */
202ba37b7caSFelix Fietkau 		u32 ports;
203ba37b7caSFelix Fietkau 	};
204ba37b7caSFelix Fietkau 
205ba37b7caSFelix Fietkau 	u32 _rsv[3];
206ba37b7caSFelix Fietkau 
207ba37b7caSFelix Fietkau 	u32 udf;
208ba37b7caSFelix Fietkau 
209ba37b7caSFelix Fietkau 	u32 ib2;
210ba37b7caSFelix Fietkau 	struct mtk_foe_mac_info l2;
211ba37b7caSFelix Fietkau };
212ba37b7caSFelix Fietkau 
213ba37b7caSFelix Fietkau struct mtk_foe_ipv6_6rd {
214ba37b7caSFelix Fietkau 	u32 src_ip[4];
215ba37b7caSFelix Fietkau 	u32 dest_ip[4];
216ba37b7caSFelix Fietkau 	u16 dest_port;
217ba37b7caSFelix Fietkau 	u16 src_port;
218ba37b7caSFelix Fietkau 
219ba37b7caSFelix Fietkau 	u32 tunnel_src_ip;
220ba37b7caSFelix Fietkau 	u32 tunnel_dest_ip;
221ba37b7caSFelix Fietkau 
222ba37b7caSFelix Fietkau 	u16 hdr_csum;
223ba37b7caSFelix Fietkau 	u8 dscp;
224ba37b7caSFelix Fietkau 	u8 ttl;
225ba37b7caSFelix Fietkau 
226ba37b7caSFelix Fietkau 	u8 flag;
227ba37b7caSFelix Fietkau 	u8 pad;
228ba37b7caSFelix Fietkau 	u8 per_flow_6rd_id;
229ba37b7caSFelix Fietkau 	u8 pad2;
230ba37b7caSFelix Fietkau 
231ba37b7caSFelix Fietkau 	u32 ib2;
232ba37b7caSFelix Fietkau 	struct mtk_foe_mac_info l2;
233ba37b7caSFelix Fietkau };
234ba37b7caSFelix Fietkau 
235a5dc694eSLorenzo Bianconi #define MTK_FOE_ENTRY_V1_SIZE	80
236a5dc694eSLorenzo Bianconi #define MTK_FOE_ENTRY_V2_SIZE	96
237*88efedf5SLorenzo Bianconi #define MTK_FOE_ENTRY_V3_SIZE	128
238a5dc694eSLorenzo Bianconi 
239ba37b7caSFelix Fietkau struct mtk_foe_entry {
240ba37b7caSFelix Fietkau 	u32 ib1;
241ba37b7caSFelix Fietkau 
242ba37b7caSFelix Fietkau 	union {
243ba37b7caSFelix Fietkau 		struct mtk_foe_bridge bridge;
244ba37b7caSFelix Fietkau 		struct mtk_foe_ipv4 ipv4;
245ba37b7caSFelix Fietkau 		struct mtk_foe_ipv4_dslite dslite;
246ba37b7caSFelix Fietkau 		struct mtk_foe_ipv6 ipv6;
247ba37b7caSFelix Fietkau 		struct mtk_foe_ipv6_6rd ipv6_6rd;
248*88efedf5SLorenzo Bianconi 		u32 data[31];
249ba37b7caSFelix Fietkau 	};
250ba37b7caSFelix Fietkau };
251ba37b7caSFelix Fietkau 
252ba37b7caSFelix Fietkau enum {
253ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_TTL_EXCEEDED			= 0x02,
254ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_OPTION_HEADER		= 0x03,
255ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_NO_FLOW			= 0x07,
256ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_IPV4_FRAG			= 0x08,
257ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_IPV4_DSLITE_FRAG		= 0x09,
258ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_IPV4_DSLITE_NO_TCP_UDP	= 0x0a,
259ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_IPV6_6RD_NO_TCP_UDP		= 0x0b,
260ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_TCP_FIN_SYN_RST		= 0x0c,
261ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_UN_HIT			= 0x0d,
262ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_HIT_UNBIND			= 0x0e,
263ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED	= 0x0f,
264ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_HIT_BIND_TCP_FIN		= 0x10,
265ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_HIT_TTL_1			= 0x11,
266ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_HIT_BIND_VLAN_VIOLATION	= 0x12,
267ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_KEEPALIVE_UC_OLD_HDR		= 0x13,
268ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_KEEPALIVE_MC_NEW_HDR		= 0x14,
269ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_KEEPALIVE_DUP_OLD_HDR	= 0x15,
270ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_HIT_BIND_FORCE_CPU		= 0x16,
271ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_TUNNEL_OPTION_HEADER		= 0x17,
272ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_MULTICAST_TO_CPU		= 0x18,
273ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_MULTICAST_TO_GMAC1_CPU	= 0x19,
274ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_HIT_PRE_BIND			= 0x1a,
275ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_PACKET_SAMPLING		= 0x1b,
276ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_EXCEED_MTU			= 0x1c,
277ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_PPE_BYPASS			= 0x1e,
278ba37b7caSFelix Fietkau 	MTK_PPE_CPU_REASON_INVALID			= 0x1f,
279ba37b7caSFelix Fietkau };
280ba37b7caSFelix Fietkau 
28133fc42deSFelix Fietkau enum {
28233fc42deSFelix Fietkau 	MTK_FLOW_TYPE_L4,
28333fc42deSFelix Fietkau 	MTK_FLOW_TYPE_L2,
28433fc42deSFelix Fietkau 	MTK_FLOW_TYPE_L2_SUBFLOW,
28533fc42deSFelix Fietkau };
28633fc42deSFelix Fietkau 
287c4f033d9SFelix Fietkau struct mtk_flow_entry {
28833fc42deSFelix Fietkau 	union {
289c4f033d9SFelix Fietkau 		struct hlist_node list;
29033fc42deSFelix Fietkau 		struct {
29133fc42deSFelix Fietkau 			struct rhash_head l2_node;
29233fc42deSFelix Fietkau 			struct hlist_head l2_flows;
29333fc42deSFelix Fietkau 		};
29433fc42deSFelix Fietkau 	};
29533fc42deSFelix Fietkau 	u8 type;
296c4f033d9SFelix Fietkau 	s8 wed_index;
2974ff1a3fcSLorenzo Bianconi 	u8 ppe_index;
29833fc42deSFelix Fietkau 	u16 hash;
29933fc42deSFelix Fietkau 	union {
30033fc42deSFelix Fietkau 		struct mtk_foe_entry data;
30133fc42deSFelix Fietkau 		struct {
30233fc42deSFelix Fietkau 			struct mtk_flow_entry *base_flow;
30333fc42deSFelix Fietkau 			struct hlist_node list;
30433fc42deSFelix Fietkau 		} l2_data;
30533fc42deSFelix Fietkau 	};
30633fc42deSFelix Fietkau 	struct rhash_head node;
30733fc42deSFelix Fietkau 	unsigned long cookie;
308c4f033d9SFelix Fietkau };
309c4f033d9SFelix Fietkau 
3103fbe4d8cSDaniel Golle struct mtk_mib_entry {
3113fbe4d8cSDaniel Golle 	u32	byt_cnt_l;
3123fbe4d8cSDaniel Golle 	u16	byt_cnt_h;
3133fbe4d8cSDaniel Golle 	u32	pkt_cnt_l;
3143fbe4d8cSDaniel Golle 	u8	pkt_cnt_h;
3153fbe4d8cSDaniel Golle 	u8	_rsv0;
3163fbe4d8cSDaniel Golle 	u32	_rsv1;
3173fbe4d8cSDaniel Golle } __packed;
3183fbe4d8cSDaniel Golle 
3193fbe4d8cSDaniel Golle struct mtk_foe_accounting {
3203fbe4d8cSDaniel Golle 	u64	bytes;
3213fbe4d8cSDaniel Golle 	u64	packets;
3223fbe4d8cSDaniel Golle };
3233fbe4d8cSDaniel Golle 
324ba37b7caSFelix Fietkau struct mtk_ppe {
325c4f033d9SFelix Fietkau 	struct mtk_eth *eth;
326ba37b7caSFelix Fietkau 	struct device *dev;
327ba37b7caSFelix Fietkau 	void __iomem *base;
328ba37b7caSFelix Fietkau 	int version;
3294ff1a3fcSLorenzo Bianconi 	char dirname[5];
3303fbe4d8cSDaniel Golle 	bool accounting;
331ba37b7caSFelix Fietkau 
3329d8cb4c0SLorenzo Bianconi 	void *foe_table;
333ba37b7caSFelix Fietkau 	dma_addr_t foe_phys;
334ba37b7caSFelix Fietkau 
3353fbe4d8cSDaniel Golle 	struct mtk_mib_entry *mib_table;
3363fbe4d8cSDaniel Golle 	dma_addr_t mib_phys;
3373fbe4d8cSDaniel Golle 
338c4f033d9SFelix Fietkau 	u16 foe_check_time[MTK_PPE_ENTRIES];
339ba2fc48cSLorenzo Bianconi 	struct hlist_head *foe_flow;
340c4f033d9SFelix Fietkau 
34133fc42deSFelix Fietkau 	struct rhashtable l2_flows;
34233fc42deSFelix Fietkau 
343ba37b7caSFelix Fietkau 	void *acct_table;
344ba37b7caSFelix Fietkau };
345ba37b7caSFelix Fietkau 
3463fbe4d8cSDaniel Golle struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int index);
3473fbe4d8cSDaniel Golle 
348603ea5e7SYan Cangang void mtk_ppe_deinit(struct mtk_eth *eth);
3494ff1a3fcSLorenzo Bianconi void mtk_ppe_start(struct mtk_ppe *ppe);
350ba37b7caSFelix Fietkau int mtk_ppe_stop(struct mtk_ppe *ppe);
35106127504SLorenzo Bianconi int mtk_ppe_prepare_reset(struct mtk_ppe *ppe);
352ba37b7caSFelix Fietkau 
353c4f033d9SFelix Fietkau void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash);
354c4f033d9SFelix Fietkau 
355ba37b7caSFelix Fietkau static inline void
mtk_ppe_check_skb(struct mtk_ppe * ppe,struct sk_buff * skb,u16 hash)356c4f033d9SFelix Fietkau mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
357ba37b7caSFelix Fietkau {
358c4f033d9SFelix Fietkau 	u16 now, diff;
359c4f033d9SFelix Fietkau 
360c4f033d9SFelix Fietkau 	if (!ppe)
361c4f033d9SFelix Fietkau 		return;
362c4f033d9SFelix Fietkau 
363f27b405eSLorenzo Bianconi 	if (hash > MTK_PPE_HASH_MASK)
364f27b405eSLorenzo Bianconi 		return;
365f27b405eSLorenzo Bianconi 
366c4f033d9SFelix Fietkau 	now = (u16)jiffies;
367c4f033d9SFelix Fietkau 	diff = now - ppe->foe_check_time[hash];
368c4f033d9SFelix Fietkau 	if (diff < HZ / 10)
369c4f033d9SFelix Fietkau 		return;
370c4f033d9SFelix Fietkau 
371c4f033d9SFelix Fietkau 	ppe->foe_check_time[hash] = now;
372c4f033d9SFelix Fietkau 	__mtk_ppe_check_skb(ppe, skb, hash);
373ba37b7caSFelix Fietkau }
374ba37b7caSFelix Fietkau 
37503a3180eSLorenzo Bianconi int mtk_foe_entry_prepare(struct mtk_eth *eth, struct mtk_foe_entry *entry,
37603a3180eSLorenzo Bianconi 			  int type, int l4proto, u8 pse_port, u8 *src_mac,
37703a3180eSLorenzo Bianconi 			  u8 *dest_mac);
37803a3180eSLorenzo Bianconi int mtk_foe_entry_set_pse_port(struct mtk_eth *eth,
37903a3180eSLorenzo Bianconi 			       struct mtk_foe_entry *entry, u8 port);
38003a3180eSLorenzo Bianconi int mtk_foe_entry_set_ipv4_tuple(struct mtk_eth *eth,
38103a3180eSLorenzo Bianconi 				 struct mtk_foe_entry *entry, bool orig,
382ba37b7caSFelix Fietkau 				 __be32 src_addr, __be16 src_port,
383ba37b7caSFelix Fietkau 				 __be32 dest_addr, __be16 dest_port);
38403a3180eSLorenzo Bianconi int mtk_foe_entry_set_ipv6_tuple(struct mtk_eth *eth,
38503a3180eSLorenzo Bianconi 				 struct mtk_foe_entry *entry,
386ba37b7caSFelix Fietkau 				 __be32 *src_addr, __be16 src_port,
387ba37b7caSFelix Fietkau 				 __be32 *dest_addr, __be16 dest_port);
38803a3180eSLorenzo Bianconi int mtk_foe_entry_set_dsa(struct mtk_eth *eth, struct mtk_foe_entry *entry,
38903a3180eSLorenzo Bianconi 			  int port);
39003a3180eSLorenzo Bianconi int mtk_foe_entry_set_vlan(struct mtk_eth *eth, struct mtk_foe_entry *entry,
39103a3180eSLorenzo Bianconi 			   int vid);
39203a3180eSLorenzo Bianconi int mtk_foe_entry_set_pppoe(struct mtk_eth *eth, struct mtk_foe_entry *entry,
39303a3180eSLorenzo Bianconi 			    int sid);
39403a3180eSLorenzo Bianconi int mtk_foe_entry_set_wdma(struct mtk_eth *eth, struct mtk_foe_entry *entry,
39503a3180eSLorenzo Bianconi 			   int wdma_idx, int txq, int bss, int wcid);
3968bd8dcc5SFelix Fietkau int mtk_foe_entry_set_queue(struct mtk_eth *eth, struct mtk_foe_entry *entry,
3978bd8dcc5SFelix Fietkau 			    unsigned int queue);
398c4f033d9SFelix Fietkau int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
399c4f033d9SFelix Fietkau void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
400c4f033d9SFelix Fietkau int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
4014ff1a3fcSLorenzo Bianconi int mtk_ppe_debugfs_init(struct mtk_ppe *ppe, int index);
4023fbe4d8cSDaniel Golle struct mtk_foe_accounting *mtk_foe_entry_get_mib(struct mtk_ppe *ppe, u32 index,
4033fbe4d8cSDaniel Golle 						 struct mtk_foe_accounting *diff);
404ba37b7caSFelix Fietkau 
405ba37b7caSFelix Fietkau #endif
406