1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 24 Mar 2021 02:30:53 +0100
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: add support for
6 The PPE (packet processing engine) is used to offload NAT/routed or even
7 bridged flows. This patch brings up the PPE and uses it to get a packet
8 hash. It also contains some functionality that will be used to bring up
11 Signed-off-by: Felix Fietkau <nbd@nbd.name>
12 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
14 create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe.c
15 create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe.h
16 create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
17 create mode 100644 drivers/net/ethernet/mediatek/mtk_ppe_regs.h
19 --- a/drivers/net/ethernet/mediatek/Makefile
20 +++ b/drivers/net/ethernet/mediatek/Makefile
24 obj-$(CONFIG_NET_MEDIATEK_SOC) += mtk_eth.o
25 -mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o
26 +mtk_eth-y := mtk_eth_soc.o mtk_sgmii.o mtk_eth_path.o mtk_ppe.o mtk_ppe_debugfs.o
27 obj-$(CONFIG_NET_MEDIATEK_STAR_EMAC) += mtk_star_emac.o
28 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
29 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
30 @@ -2282,12 +2282,17 @@ static int mtk_open(struct net_device *d
32 /* we run 2 netdevs on the same dma ring so we only bring it up once */
33 if (!refcount_read(ð->dma_refcnt)) {
34 - int err = mtk_start_dma(eth);
35 + u32 gdm_config = MTK_GDMA_TO_PDMA;
38 + err = mtk_start_dma(eth);
42 - mtk_gdm_config(eth, MTK_GDMA_TO_PDMA);
43 + if (eth->soc->offload_version && mtk_ppe_start(ð->ppe) == 0)
44 + gdm_config = MTK_GDMA_TO_PPE;
46 + mtk_gdm_config(eth, gdm_config);
48 napi_enable(ð->tx_napi);
49 napi_enable(ð->rx_napi);
50 @@ -2354,6 +2359,9 @@ static int mtk_stop(struct net_device *d
54 + if (eth->soc->offload_version)
55 + mtk_ppe_stop(ð->ppe);
60 @@ -3082,6 +3090,13 @@ static int mtk_probe(struct platform_dev
64 + if (eth->soc->offload_version) {
65 + err = mtk_ppe_init(ð->ppe, eth->dev,
66 + eth->base + MTK_ETH_PPE_BASE, 2);
71 for (i = 0; i < MTK_MAX_DEVS; i++) {
74 @@ -3156,6 +3171,7 @@ static const struct mtk_soc_data mt7621_
75 .hw_features = MTK_HW_FEATURES,
76 .required_clks = MT7621_CLKS_BITMAP,
77 .required_pctl = false,
78 + .offload_version = 2,
81 static const struct mtk_soc_data mt7622_data = {
82 @@ -3164,6 +3180,7 @@ static const struct mtk_soc_data mt7622_
83 .hw_features = MTK_HW_FEATURES,
84 .required_clks = MT7622_CLKS_BITMAP,
85 .required_pctl = false,
86 + .offload_version = 2,
89 static const struct mtk_soc_data mt7623_data = {
90 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
91 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
93 #include <linux/u64_stats_sync.h>
94 #include <linux/refcount.h>
95 #include <linux/phylink.h>
98 #define MTK_QDMA_PAGE_SIZE 2048
99 #define MTK_MAX_RX_LENGTH 1536
101 #define MTK_GDMA_TCS_EN BIT(21)
102 #define MTK_GDMA_UCS_EN BIT(20)
103 #define MTK_GDMA_TO_PDMA 0x0
104 +#define MTK_GDMA_TO_PPE 0x4444
105 #define MTK_GDMA_DROP_ALL 0x7777
107 /* Unicast Filter MAC Address Register - Low */
109 #define RX_DMA_VID(_x) ((_x) & 0xfff)
111 /* QDMA descriptor rxd4 */
112 +#define MTK_RXD4_FOE_ENTRY GENMASK(13, 0)
113 +#define MTK_RXD4_PPE_CPU_REASON GENMASK(18, 14)
114 +#define MTK_RXD4_SRC_PORT GENMASK(21, 19)
115 +#define MTK_RXD4_ALG GENMASK(31, 22)
117 +/* QDMA descriptor rxd4 */
118 #define RX_DMA_L4_VALID BIT(24)
119 #define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */
120 #define RX_DMA_FPORT_SHIFT 19
121 @@ -819,6 +827,7 @@ struct mtk_soc_data {
125 + u8 offload_version;
126 netdev_features_t hw_features;
129 @@ -918,6 +927,8 @@ struct mtk_eth {
130 u32 tx_int_status_reg;
134 + struct mtk_ppe ppe;
137 /* struct mtk_mac - the structure that holds the info about the MACs of the
139 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
141 +// SPDX-License-Identifier: GPL-2.0-only
142 +/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
144 +#include <linux/kernel.h>
145 +#include <linux/jiffies.h>
146 +#include <linux/delay.h>
147 +#include <linux/io.h>
148 +#include <linux/etherdevice.h>
149 +#include <linux/platform_device.h>
150 +#include "mtk_ppe.h"
151 +#include "mtk_ppe_regs.h"
153 +static void ppe_w32(struct mtk_ppe *ppe, u32 reg, u32 val)
155 + writel(val, ppe->base + reg);
158 +static u32 ppe_r32(struct mtk_ppe *ppe, u32 reg)
160 + return readl(ppe->base + reg);
163 +static u32 ppe_m32(struct mtk_ppe *ppe, u32 reg, u32 mask, u32 set)
167 + val = ppe_r32(ppe, reg);
170 + ppe_w32(ppe, reg, val);
175 +static u32 ppe_set(struct mtk_ppe *ppe, u32 reg, u32 val)
177 + return ppe_m32(ppe, reg, 0, val);
180 +static u32 ppe_clear(struct mtk_ppe *ppe, u32 reg, u32 val)
182 + return ppe_m32(ppe, reg, val, 0);
185 +static int mtk_ppe_wait_busy(struct mtk_ppe *ppe)
187 + unsigned long timeout = jiffies + HZ;
189 + while (time_is_before_jiffies(timeout)) {
190 + if (!(ppe_r32(ppe, MTK_PPE_GLO_CFG) & MTK_PPE_GLO_CFG_BUSY))
193 + usleep_range(10, 20);
196 + dev_err(ppe->dev, "PPE table busy");
201 +static void mtk_ppe_cache_clear(struct mtk_ppe *ppe)
203 + ppe_set(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_CLEAR);
204 + ppe_clear(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_CLEAR);
207 +static void mtk_ppe_cache_enable(struct mtk_ppe *ppe, bool enable)
209 + mtk_ppe_cache_clear(ppe);
211 + ppe_m32(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_EN,
212 + enable * MTK_PPE_CACHE_CTL_EN);
215 +static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
220 + switch (FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, e->ib1)) {
221 + case MTK_PPE_PKT_TYPE_BRIDGE:
222 + hv1 = e->bridge.src_mac_lo;
223 + hv1 ^= ((e->bridge.src_mac_hi & 0xffff) << 16);
224 + hv2 = e->bridge.src_mac_hi >> 16;
225 + hv2 ^= e->bridge.dest_mac_lo;
226 + hv3 = e->bridge.dest_mac_hi;
228 + case MTK_PPE_PKT_TYPE_IPV4_ROUTE:
229 + case MTK_PPE_PKT_TYPE_IPV4_HNAPT:
230 + hv1 = e->ipv4.orig.ports;
231 + hv2 = e->ipv4.orig.dest_ip;
232 + hv3 = e->ipv4.orig.src_ip;
234 + case MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T:
235 + case MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T:
236 + hv1 = e->ipv6.src_ip[3] ^ e->ipv6.dest_ip[3];
237 + hv1 ^= e->ipv6.ports;
239 + hv2 = e->ipv6.src_ip[2] ^ e->ipv6.dest_ip[2];
240 + hv2 ^= e->ipv6.dest_ip[0];
242 + hv3 = e->ipv6.src_ip[1] ^ e->ipv6.dest_ip[1];
243 + hv3 ^= e->ipv6.src_ip[0];
245 + case MTK_PPE_PKT_TYPE_IPV4_DSLITE:
246 + case MTK_PPE_PKT_TYPE_IPV6_6RD:
249 + return MTK_PPE_HASH_MASK;
252 + hash = (hv1 & hv2) | ((~hv1) & hv3);
253 + hash = (hash >> 24) | ((hash & 0xffffff) << 8);
254 + hash ^= hv1 ^ hv2 ^ hv3;
255 + hash ^= hash >> 16;
257 + hash &= MTK_PPE_ENTRIES - 1;
262 +static inline struct mtk_foe_mac_info *
263 +mtk_foe_entry_l2(struct mtk_foe_entry *entry)
265 + int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
267 + if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE)
268 + return &entry->ipv6.l2;
270 + return &entry->ipv4.l2;
274 +mtk_foe_entry_ib2(struct mtk_foe_entry *entry)
276 + int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
278 + if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE)
279 + return &entry->ipv6.ib2;
281 + return &entry->ipv4.ib2;
284 +int mtk_foe_entry_prepare(struct mtk_foe_entry *entry, int type, int l4proto,
285 + u8 pse_port, u8 *src_mac, u8 *dest_mac)
287 + struct mtk_foe_mac_info *l2;
288 + u32 ports_pad, val;
290 + memset(entry, 0, sizeof(*entry));
292 + val = FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_BIND) |
293 + FIELD_PREP(MTK_FOE_IB1_PACKET_TYPE, type) |
294 + FIELD_PREP(MTK_FOE_IB1_UDP, l4proto == IPPROTO_UDP) |
295 + MTK_FOE_IB1_BIND_TTL |
296 + MTK_FOE_IB1_BIND_CACHE;
299 + val = FIELD_PREP(MTK_FOE_IB2_PORT_MG, 0x3f) |
300 + FIELD_PREP(MTK_FOE_IB2_PORT_AG, 0x1f) |
301 + FIELD_PREP(MTK_FOE_IB2_DEST_PORT, pse_port);
303 + if (is_multicast_ether_addr(dest_mac))
304 + val |= MTK_FOE_IB2_MULTICAST;
306 + ports_pad = 0xa5a5a500 | (l4proto & 0xff);
307 + if (type == MTK_PPE_PKT_TYPE_IPV4_ROUTE)
308 + entry->ipv4.orig.ports = ports_pad;
309 + if (type == MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T)
310 + entry->ipv6.ports = ports_pad;
312 + if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE) {
313 + entry->ipv6.ib2 = val;
314 + l2 = &entry->ipv6.l2;
316 + entry->ipv4.ib2 = val;
317 + l2 = &entry->ipv4.l2;
320 + l2->dest_mac_hi = get_unaligned_be32(dest_mac);
321 + l2->dest_mac_lo = get_unaligned_be16(dest_mac + 4);
322 + l2->src_mac_hi = get_unaligned_be32(src_mac);
323 + l2->src_mac_lo = get_unaligned_be16(src_mac + 4);
325 + if (type >= MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T)
326 + l2->etype = ETH_P_IPV6;
328 + l2->etype = ETH_P_IP;
333 +int mtk_foe_entry_set_pse_port(struct mtk_foe_entry *entry, u8 port)
335 + u32 *ib2 = mtk_foe_entry_ib2(entry);
339 + val &= ~MTK_FOE_IB2_DEST_PORT;
340 + val |= FIELD_PREP(MTK_FOE_IB2_DEST_PORT, port);
346 +int mtk_foe_entry_set_ipv4_tuple(struct mtk_foe_entry *entry, bool egress,
347 + __be32 src_addr, __be16 src_port,
348 + __be32 dest_addr, __be16 dest_port)
350 + int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
351 + struct mtk_ipv4_tuple *t;
354 + case MTK_PPE_PKT_TYPE_IPV4_HNAPT:
356 + t = &entry->ipv4.new;
360 + case MTK_PPE_PKT_TYPE_IPV4_DSLITE:
361 + case MTK_PPE_PKT_TYPE_IPV4_ROUTE:
362 + t = &entry->ipv4.orig;
364 + case MTK_PPE_PKT_TYPE_IPV6_6RD:
365 + entry->ipv6_6rd.tunnel_src_ip = be32_to_cpu(src_addr);
366 + entry->ipv6_6rd.tunnel_dest_ip = be32_to_cpu(dest_addr);
373 + t->src_ip = be32_to_cpu(src_addr);
374 + t->dest_ip = be32_to_cpu(dest_addr);
376 + if (type == MTK_PPE_PKT_TYPE_IPV4_ROUTE)
379 + t->src_port = be16_to_cpu(src_port);
380 + t->dest_port = be16_to_cpu(dest_port);
385 +int mtk_foe_entry_set_ipv6_tuple(struct mtk_foe_entry *entry,
386 + __be32 *src_addr, __be16 src_port,
387 + __be32 *dest_addr, __be16 dest_port)
389 + int type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
394 + case MTK_PPE_PKT_TYPE_IPV4_DSLITE:
395 + src = entry->dslite.tunnel_src_ip;
396 + dest = entry->dslite.tunnel_dest_ip;
398 + case MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T:
399 + case MTK_PPE_PKT_TYPE_IPV6_6RD:
400 + entry->ipv6.src_port = be16_to_cpu(src_port);
401 + entry->ipv6.dest_port = be16_to_cpu(dest_port);
403 + case MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T:
404 + src = entry->ipv6.src_ip;
405 + dest = entry->ipv6.dest_ip;
412 + for (i = 0; i < 4; i++)
413 + src[i] = be32_to_cpu(src_addr[i]);
414 + for (i = 0; i < 4; i++)
415 + dest[i] = be32_to_cpu(dest_addr[i]);
420 +int mtk_foe_entry_set_dsa(struct mtk_foe_entry *entry, int port)
422 + struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
424 + l2->etype = BIT(port);
426 + if (!(entry->ib1 & MTK_FOE_IB1_BIND_VLAN_LAYER))
427 + entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, 1);
429 + l2->etype |= BIT(8);
431 + entry->ib1 &= ~MTK_FOE_IB1_BIND_VLAN_TAG;
436 +int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid)
438 + struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
440 + switch (FIELD_GET(MTK_FOE_IB1_BIND_VLAN_LAYER, entry->ib1)) {
442 + entry->ib1 |= MTK_FOE_IB1_BIND_VLAN_TAG |
443 + FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, 1);
447 + if (!(entry->ib1 & MTK_FOE_IB1_BIND_VLAN_TAG)) {
449 + l2->etype |= BIT(8);
452 + entry->ib1 += FIELD_PREP(MTK_FOE_IB1_BIND_VLAN_LAYER, 1);
460 +int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid)
462 + struct mtk_foe_mac_info *l2 = mtk_foe_entry_l2(entry);
464 + if (!(entry->ib1 & MTK_FOE_IB1_BIND_VLAN_LAYER) ||
465 + (entry->ib1 & MTK_FOE_IB1_BIND_VLAN_TAG))
466 + l2->etype = ETH_P_PPP_SES;
468 + entry->ib1 |= MTK_FOE_IB1_BIND_PPPOE;
469 + l2->pppoe_id = sid;
474 +static inline bool mtk_foe_entry_usable(struct mtk_foe_entry *entry)
476 + return !(entry->ib1 & MTK_FOE_IB1_STATIC) &&
477 + FIELD_GET(MTK_FOE_IB1_STATE, entry->ib1) != MTK_FOE_STATE_BIND;
480 +int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
483 + struct mtk_foe_entry *hwe;
486 + timestamp &= MTK_FOE_IB1_BIND_TIMESTAMP;
487 + entry->ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP;
488 + entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_TIMESTAMP, timestamp);
490 + hash = mtk_ppe_hash_entry(entry);
491 + hwe = &ppe->foe_table[hash];
492 + if (!mtk_foe_entry_usable(hwe)) {
496 + if (!mtk_foe_entry_usable(hwe))
500 + memcpy(&hwe->data, &entry->data, sizeof(hwe->data));
502 + hwe->ib1 = entry->ib1;
506 + mtk_ppe_cache_clear(ppe);
511 +int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
514 + struct mtk_foe_entry *foe;
516 + /* need to allocate a separate device, since it PPE DMA access is
521 + ppe->version = version;
523 + foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
524 + &ppe->foe_phys, GFP_KERNEL);
528 + ppe->foe_table = foe;
530 + mtk_ppe_debugfs_init(ppe);
535 +static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
537 + static const u8 skip[] = { 12, 25, 38, 51, 76, 89, 102 };
540 + memset(ppe->foe_table, 0, MTK_PPE_ENTRIES * sizeof(ppe->foe_table));
542 + if (!IS_ENABLED(CONFIG_SOC_MT7621))
545 + /* skip all entries that cross the 1024 byte boundary */
546 + for (i = 0; i < MTK_PPE_ENTRIES; i += 128)
547 + for (k = 0; k < ARRAY_SIZE(skip); k++)
548 + ppe->foe_table[i + skip[k]].ib1 |= MTK_FOE_IB1_STATIC;
551 +int mtk_ppe_start(struct mtk_ppe *ppe)
555 + mtk_ppe_init_foe_table(ppe);
556 + ppe_w32(ppe, MTK_PPE_TB_BASE, ppe->foe_phys);
558 + val = MTK_PPE_TB_CFG_ENTRY_80B |
559 + MTK_PPE_TB_CFG_AGE_NON_L4 |
560 + MTK_PPE_TB_CFG_AGE_UNBIND |
561 + MTK_PPE_TB_CFG_AGE_TCP |
562 + MTK_PPE_TB_CFG_AGE_UDP |
563 + MTK_PPE_TB_CFG_AGE_TCP_FIN |
564 + FIELD_PREP(MTK_PPE_TB_CFG_SEARCH_MISS,
565 + MTK_PPE_SEARCH_MISS_ACTION_FORWARD_BUILD) |
566 + FIELD_PREP(MTK_PPE_TB_CFG_KEEPALIVE,
567 + MTK_PPE_KEEPALIVE_DISABLE) |
568 + FIELD_PREP(MTK_PPE_TB_CFG_HASH_MODE, 1) |
569 + FIELD_PREP(MTK_PPE_TB_CFG_SCAN_MODE,
570 + MTK_PPE_SCAN_MODE_KEEPALIVE_AGE) |
571 + FIELD_PREP(MTK_PPE_TB_CFG_ENTRY_NUM,
572 + MTK_PPE_ENTRIES_SHIFT);
573 + ppe_w32(ppe, MTK_PPE_TB_CFG, val);
575 + ppe_w32(ppe, MTK_PPE_IP_PROTO_CHK,
576 + MTK_PPE_IP_PROTO_CHK_IPV4 | MTK_PPE_IP_PROTO_CHK_IPV6);
578 + mtk_ppe_cache_enable(ppe, true);
580 + val = MTK_PPE_FLOW_CFG_IP4_TCP_FRAG |
581 + MTK_PPE_FLOW_CFG_IP4_UDP_FRAG |
582 + MTK_PPE_FLOW_CFG_IP6_3T_ROUTE |
583 + MTK_PPE_FLOW_CFG_IP6_5T_ROUTE |
584 + MTK_PPE_FLOW_CFG_IP6_6RD |
585 + MTK_PPE_FLOW_CFG_IP4_NAT |
586 + MTK_PPE_FLOW_CFG_IP4_NAPT |
587 + MTK_PPE_FLOW_CFG_IP4_DSLITE |
588 + MTK_PPE_FLOW_CFG_L2_BRIDGE |
589 + MTK_PPE_FLOW_CFG_IP4_NAT_FRAG;
590 + ppe_w32(ppe, MTK_PPE_FLOW_CFG, val);
592 + val = FIELD_PREP(MTK_PPE_UNBIND_AGE_MIN_PACKETS, 1000) |
593 + FIELD_PREP(MTK_PPE_UNBIND_AGE_DELTA, 3);
594 + ppe_w32(ppe, MTK_PPE_UNBIND_AGE, val);
596 + val = FIELD_PREP(MTK_PPE_BIND_AGE0_DELTA_UDP, 12) |
597 + FIELD_PREP(MTK_PPE_BIND_AGE0_DELTA_NON_L4, 1);
598 + ppe_w32(ppe, MTK_PPE_BIND_AGE0, val);
600 + val = FIELD_PREP(MTK_PPE_BIND_AGE1_DELTA_TCP_FIN, 1) |
601 + FIELD_PREP(MTK_PPE_BIND_AGE1_DELTA_TCP, 7);
602 + ppe_w32(ppe, MTK_PPE_BIND_AGE1, val);
604 + val = MTK_PPE_BIND_LIMIT0_QUARTER | MTK_PPE_BIND_LIMIT0_HALF;
605 + ppe_w32(ppe, MTK_PPE_BIND_LIMIT0, val);
607 + val = MTK_PPE_BIND_LIMIT1_FULL |
608 + FIELD_PREP(MTK_PPE_BIND_LIMIT1_NON_L4, 1);
609 + ppe_w32(ppe, MTK_PPE_BIND_LIMIT1, val);
611 + val = FIELD_PREP(MTK_PPE_BIND_RATE_BIND, 30) |
612 + FIELD_PREP(MTK_PPE_BIND_RATE_PREBIND, 1);
613 + ppe_w32(ppe, MTK_PPE_BIND_RATE, val);
616 + val = MTK_PPE_GLO_CFG_EN |
617 + MTK_PPE_GLO_CFG_IP4_L4_CS_DROP |
618 + MTK_PPE_GLO_CFG_IP4_CS_DROP |
619 + MTK_PPE_GLO_CFG_FLOW_DROP_UPDATE;
620 + ppe_w32(ppe, MTK_PPE_GLO_CFG, val);
622 + ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT, 0);
627 +int mtk_ppe_stop(struct mtk_ppe *ppe)
632 + for (i = 0; i < MTK_PPE_ENTRIES; i++)
633 + ppe->foe_table[i].ib1 = FIELD_PREP(MTK_FOE_IB1_STATE,
634 + MTK_FOE_STATE_INVALID);
636 + mtk_ppe_cache_enable(ppe, false);
638 + /* disable offload engine */
639 + ppe_clear(ppe, MTK_PPE_GLO_CFG, MTK_PPE_GLO_CFG_EN);
640 + ppe_w32(ppe, MTK_PPE_FLOW_CFG, 0);
642 + /* disable aging */
643 + val = MTK_PPE_TB_CFG_AGE_NON_L4 |
644 + MTK_PPE_TB_CFG_AGE_UNBIND |
645 + MTK_PPE_TB_CFG_AGE_TCP |
646 + MTK_PPE_TB_CFG_AGE_UDP |
647 + MTK_PPE_TB_CFG_AGE_TCP_FIN;
648 + ppe_clear(ppe, MTK_PPE_TB_CFG, val);
650 + return mtk_ppe_wait_busy(ppe);
653 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
655 +// SPDX-License-Identifier: GPL-2.0-only
656 +/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
661 +#include <linux/kernel.h>
662 +#include <linux/bitfield.h>
664 +#define MTK_ETH_PPE_BASE 0xc00
666 +#define MTK_PPE_ENTRIES_SHIFT 3
667 +#define MTK_PPE_ENTRIES (1024 << MTK_PPE_ENTRIES_SHIFT)
668 +#define MTK_PPE_HASH_MASK (MTK_PPE_ENTRIES - 1)
670 +#define MTK_FOE_IB1_UNBIND_TIMESTAMP GENMASK(7, 0)
671 +#define MTK_FOE_IB1_UNBIND_PACKETS GENMASK(23, 8)
672 +#define MTK_FOE_IB1_UNBIND_PREBIND BIT(24)
674 +#define MTK_FOE_IB1_BIND_TIMESTAMP GENMASK(14, 0)
675 +#define MTK_FOE_IB1_BIND_KEEPALIVE BIT(15)
676 +#define MTK_FOE_IB1_BIND_VLAN_LAYER GENMASK(18, 16)
677 +#define MTK_FOE_IB1_BIND_PPPOE BIT(19)
678 +#define MTK_FOE_IB1_BIND_VLAN_TAG BIT(20)
679 +#define MTK_FOE_IB1_BIND_PKT_SAMPLE BIT(21)
680 +#define MTK_FOE_IB1_BIND_CACHE BIT(22)
681 +#define MTK_FOE_IB1_BIND_TUNNEL_DECAP BIT(23)
682 +#define MTK_FOE_IB1_BIND_TTL BIT(24)
684 +#define MTK_FOE_IB1_PACKET_TYPE GENMASK(27, 25)
685 +#define MTK_FOE_IB1_STATE GENMASK(29, 28)
686 +#define MTK_FOE_IB1_UDP BIT(30)
687 +#define MTK_FOE_IB1_STATIC BIT(31)
690 + MTK_PPE_PKT_TYPE_IPV4_HNAPT = 0,
691 + MTK_PPE_PKT_TYPE_IPV4_ROUTE = 1,
692 + MTK_PPE_PKT_TYPE_BRIDGE = 2,
693 + MTK_PPE_PKT_TYPE_IPV4_DSLITE = 3,
694 + MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T = 4,
695 + MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T = 5,
696 + MTK_PPE_PKT_TYPE_IPV6_6RD = 7,
699 +#define MTK_FOE_IB2_QID GENMASK(3, 0)
700 +#define MTK_FOE_IB2_PSE_QOS BIT(4)
701 +#define MTK_FOE_IB2_DEST_PORT GENMASK(7, 5)
702 +#define MTK_FOE_IB2_MULTICAST BIT(8)
704 +#define MTK_FOE_IB2_WHNAT_QID2 GENMASK(13, 12)
705 +#define MTK_FOE_IB2_WHNAT_DEVIDX BIT(16)
706 +#define MTK_FOE_IB2_WHNAT_NAT BIT(17)
708 +#define MTK_FOE_IB2_PORT_MG GENMASK(17, 12)
710 +#define MTK_FOE_IB2_PORT_AG GENMASK(23, 18)
712 +#define MTK_FOE_IB2_DSCP GENMASK(31, 24)
714 +#define MTK_FOE_VLAN2_WHNAT_BSS GEMMASK(5, 0)
715 +#define MTK_FOE_VLAN2_WHNAT_WCID GENMASK(13, 6)
716 +#define MTK_FOE_VLAN2_WHNAT_RING GENMASK(15, 14)
719 + MTK_FOE_STATE_INVALID,
720 + MTK_FOE_STATE_UNBIND,
721 + MTK_FOE_STATE_BIND,
725 +struct mtk_foe_mac_info {
740 +struct mtk_foe_bridge {
753 + struct mtk_foe_mac_info l2;
756 +struct mtk_ipv4_tuple {
766 + u8 _pad[3]; /* fill with 0xa5a5a5 */
772 +struct mtk_foe_ipv4 {
773 + struct mtk_ipv4_tuple orig;
777 + struct mtk_ipv4_tuple new;
784 + struct mtk_foe_mac_info l2;
787 +struct mtk_foe_ipv4_dslite {
788 + struct mtk_ipv4_tuple ip4;
790 + u32 tunnel_src_ip[4];
791 + u32 tunnel_dest_ip[4];
800 + struct mtk_foe_mac_info l2;
803 +struct mtk_foe_ipv6 {
810 + u8 _pad[3]; /* fill with 0xa5a5a5 */
824 + struct mtk_foe_mac_info l2;
827 +struct mtk_foe_ipv6_6rd {
834 + u32 tunnel_dest_ip;
842 + u8 per_flow_6rd_id;
846 + struct mtk_foe_mac_info l2;
849 +struct mtk_foe_entry {
853 + struct mtk_foe_bridge bridge;
854 + struct mtk_foe_ipv4 ipv4;
855 + struct mtk_foe_ipv4_dslite dslite;
856 + struct mtk_foe_ipv6 ipv6;
857 + struct mtk_foe_ipv6_6rd ipv6_6rd;
863 + MTK_PPE_CPU_REASON_TTL_EXCEEDED = 0x02,
864 + MTK_PPE_CPU_REASON_OPTION_HEADER = 0x03,
865 + MTK_PPE_CPU_REASON_NO_FLOW = 0x07,
866 + MTK_PPE_CPU_REASON_IPV4_FRAG = 0x08,
867 + MTK_PPE_CPU_REASON_IPV4_DSLITE_FRAG = 0x09,
868 + MTK_PPE_CPU_REASON_IPV4_DSLITE_NO_TCP_UDP = 0x0a,
869 + MTK_PPE_CPU_REASON_IPV6_6RD_NO_TCP_UDP = 0x0b,
870 + MTK_PPE_CPU_REASON_TCP_FIN_SYN_RST = 0x0c,
871 + MTK_PPE_CPU_REASON_UN_HIT = 0x0d,
872 + MTK_PPE_CPU_REASON_HIT_UNBIND = 0x0e,
873 + MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED = 0x0f,
874 + MTK_PPE_CPU_REASON_HIT_BIND_TCP_FIN = 0x10,
875 + MTK_PPE_CPU_REASON_HIT_TTL_1 = 0x11,
876 + MTK_PPE_CPU_REASON_HIT_BIND_VLAN_VIOLATION = 0x12,
877 + MTK_PPE_CPU_REASON_KEEPALIVE_UC_OLD_HDR = 0x13,
878 + MTK_PPE_CPU_REASON_KEEPALIVE_MC_NEW_HDR = 0x14,
879 + MTK_PPE_CPU_REASON_KEEPALIVE_DUP_OLD_HDR = 0x15,
880 + MTK_PPE_CPU_REASON_HIT_BIND_FORCE_CPU = 0x16,
881 + MTK_PPE_CPU_REASON_TUNNEL_OPTION_HEADER = 0x17,
882 + MTK_PPE_CPU_REASON_MULTICAST_TO_CPU = 0x18,
883 + MTK_PPE_CPU_REASON_MULTICAST_TO_GMAC1_CPU = 0x19,
884 + MTK_PPE_CPU_REASON_HIT_PRE_BIND = 0x1a,
885 + MTK_PPE_CPU_REASON_PACKET_SAMPLING = 0x1b,
886 + MTK_PPE_CPU_REASON_EXCEED_MTU = 0x1c,
887 + MTK_PPE_CPU_REASON_PPE_BYPASS = 0x1e,
888 + MTK_PPE_CPU_REASON_INVALID = 0x1f,
892 + struct device *dev;
893 + void __iomem *base;
896 + struct mtk_foe_entry *foe_table;
897 + dma_addr_t foe_phys;
902 +int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
904 +int mtk_ppe_start(struct mtk_ppe *ppe);
905 +int mtk_ppe_stop(struct mtk_ppe *ppe);
908 +mtk_foe_entry_clear(struct mtk_ppe *ppe, u16 hash)
910 + ppe->foe_table[hash].ib1 = 0;
915 +mtk_foe_entry_timestamp(struct mtk_ppe *ppe, u16 hash)
917 + u32 ib1 = READ_ONCE(ppe->foe_table[hash].ib1);
919 + if (FIELD_GET(MTK_FOE_IB1_STATE, ib1) != MTK_FOE_STATE_BIND)
922 + return FIELD_GET(MTK_FOE_IB1_BIND_TIMESTAMP, ib1);
925 +int mtk_foe_entry_prepare(struct mtk_foe_entry *entry, int type, int l4proto,
926 + u8 pse_port, u8 *src_mac, u8 *dest_mac);
927 +int mtk_foe_entry_set_pse_port(struct mtk_foe_entry *entry, u8 port);
928 +int mtk_foe_entry_set_ipv4_tuple(struct mtk_foe_entry *entry, bool orig,
929 + __be32 src_addr, __be16 src_port,
930 + __be32 dest_addr, __be16 dest_port);
931 +int mtk_foe_entry_set_ipv6_tuple(struct mtk_foe_entry *entry,
932 + __be32 *src_addr, __be16 src_port,
933 + __be32 *dest_addr, __be16 dest_port);
934 +int mtk_foe_entry_set_dsa(struct mtk_foe_entry *entry, int port);
935 +int mtk_foe_entry_set_vlan(struct mtk_foe_entry *entry, int vid);
936 +int mtk_foe_entry_set_pppoe(struct mtk_foe_entry *entry, int sid);
937 +int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
939 +int mtk_ppe_debugfs_init(struct mtk_ppe *ppe);
943 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
945 +// SPDX-License-Identifier: GPL-2.0-only
946 +/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
948 +#include <linux/kernel.h>
949 +#include <linux/debugfs.h>
950 +#include "mtk_eth_soc.h"
952 +struct mtk_flow_addr_info
955 + u16 *src_port, *dest_port;
959 +static const char *mtk_foe_entry_state_str(int state)
961 + static const char * const state_str[] = {
962 + [MTK_FOE_STATE_INVALID] = "INV",
963 + [MTK_FOE_STATE_UNBIND] = "UNB",
964 + [MTK_FOE_STATE_BIND] = "BND",
965 + [MTK_FOE_STATE_FIN] = "FIN",
968 + if (state >= ARRAY_SIZE(state_str) || !state_str[state])
971 + return state_str[state];
974 +static const char *mtk_foe_pkt_type_str(int type)
976 + static const char * const type_str[] = {
977 + [MTK_PPE_PKT_TYPE_IPV4_HNAPT] = "IPv4 5T",
978 + [MTK_PPE_PKT_TYPE_IPV4_ROUTE] = "IPv4 3T",
979 + [MTK_PPE_PKT_TYPE_BRIDGE] = "L2",
980 + [MTK_PPE_PKT_TYPE_IPV4_DSLITE] = "DS-LITE",
981 + [MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T] = "IPv6 3T",
982 + [MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T] = "IPv6 5T",
983 + [MTK_PPE_PKT_TYPE_IPV6_6RD] = "6RD",
986 + if (type >= ARRAY_SIZE(type_str) || !type_str[type])
989 + return type_str[type];
993 +mtk_print_addr(struct seq_file *m, u32 *addr, bool ipv6)
999 + seq_printf(m, "%pI4h", addr);
1003 + for (i = 0; i < ARRAY_SIZE(n_addr); i++)
1004 + n_addr[i] = htonl(addr[i]);
1005 + seq_printf(m, "%pI6", n_addr);
1009 +mtk_print_addr_info(struct seq_file *m, struct mtk_flow_addr_info *ai)
1011 + mtk_print_addr(m, ai->src, ai->ipv6);
1013 + seq_printf(m, ":%d", *ai->src_port);
1014 + seq_printf(m, "->");
1015 + mtk_print_addr(m, ai->dest, ai->ipv6);
1016 + if (ai->dest_port)
1017 + seq_printf(m, ":%d", *ai->dest_port);
1021 +mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private, bool bind)
1023 + struct mtk_ppe *ppe = m->private;
1026 + for (i = 0, count = 0; i < MTK_PPE_ENTRIES; i++) {
1027 + struct mtk_foe_entry *entry = &ppe->foe_table[i];
1028 + struct mtk_foe_mac_info *l2;
1029 + struct mtk_flow_addr_info ai = {};
1030 + unsigned char h_source[ETH_ALEN];
1031 + unsigned char h_dest[ETH_ALEN];
1036 + state = FIELD_GET(MTK_FOE_IB1_STATE, entry->ib1);
1040 + if (bind && state != MTK_FOE_STATE_BIND)
1043 + type = FIELD_GET(MTK_FOE_IB1_PACKET_TYPE, entry->ib1);
1044 + seq_printf(m, "%05x %s %7s", i,
1045 + mtk_foe_entry_state_str(state),
1046 + mtk_foe_pkt_type_str(type));
1049 + case MTK_PPE_PKT_TYPE_IPV4_HNAPT:
1050 + case MTK_PPE_PKT_TYPE_IPV4_DSLITE:
1051 + ai.src_port = &entry->ipv4.orig.src_port;
1052 + ai.dest_port = &entry->ipv4.orig.dest_port;
1054 + case MTK_PPE_PKT_TYPE_IPV4_ROUTE:
1055 + ai.src = &entry->ipv4.orig.src_ip;
1056 + ai.dest = &entry->ipv4.orig.dest_ip;
1058 + case MTK_PPE_PKT_TYPE_IPV6_ROUTE_5T:
1059 + ai.src_port = &entry->ipv6.src_port;
1060 + ai.dest_port = &entry->ipv6.dest_port;
1062 + case MTK_PPE_PKT_TYPE_IPV6_ROUTE_3T:
1063 + case MTK_PPE_PKT_TYPE_IPV6_6RD:
1064 + ai.src = &entry->ipv6.src_ip;
1065 + ai.dest = &entry->ipv6.dest_ip;
1070 + seq_printf(m, " orig=");
1071 + mtk_print_addr_info(m, &ai);
1074 + case MTK_PPE_PKT_TYPE_IPV4_HNAPT:
1075 + case MTK_PPE_PKT_TYPE_IPV4_DSLITE:
1076 + ai.src_port = &entry->ipv4.new.src_port;
1077 + ai.dest_port = &entry->ipv4.new.dest_port;
1079 + case MTK_PPE_PKT_TYPE_IPV4_ROUTE:
1080 + ai.src = &entry->ipv4.new.src_ip;
1081 + ai.dest = &entry->ipv4.new.dest_ip;
1082 + seq_printf(m, " new=");
1083 + mtk_print_addr_info(m, &ai);
1087 + if (type >= MTK_PPE_PKT_TYPE_IPV4_DSLITE) {
1088 + l2 = &entry->ipv6.l2;
1089 + ib2 = entry->ipv6.ib2;
1091 + l2 = &entry->ipv4.l2;
1092 + ib2 = entry->ipv4.ib2;
1095 + *((__be32 *)h_source) = htonl(l2->src_mac_hi);
1096 + *((__be16 *)&h_source[4]) = htons(l2->src_mac_lo);
1097 + *((__be32 *)h_dest) = htonl(l2->dest_mac_hi);
1098 + *((__be16 *)&h_dest[4]) = htons(l2->dest_mac_lo);
1100 + seq_printf(m, " eth=%pM->%pM etype=%04x"
1101 + " vlan=%d,%d ib1=%08x ib2=%08x\n",
1102 + h_source, h_dest, ntohs(l2->etype),
1103 + l2->vlan1, l2->vlan2, entry->ib1, ib2);
1110 +mtk_ppe_debugfs_foe_show_all(struct seq_file *m, void *private)
1112 + return mtk_ppe_debugfs_foe_show(m, private, false);
1116 +mtk_ppe_debugfs_foe_show_bind(struct seq_file *m, void *private)
1118 + return mtk_ppe_debugfs_foe_show(m, private, true);
1122 +mtk_ppe_debugfs_foe_open_all(struct inode *inode, struct file *file)
1124 + return single_open(file, mtk_ppe_debugfs_foe_show_all,
1125 + inode->i_private);
1129 +mtk_ppe_debugfs_foe_open_bind(struct inode *inode, struct file *file)
1131 + return single_open(file, mtk_ppe_debugfs_foe_show_bind,
1132 + inode->i_private);
1135 +int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
1137 + static const struct file_operations fops_all = {
1138 + .open = mtk_ppe_debugfs_foe_open_all,
1140 + .llseek = seq_lseek,
1141 + .release = single_release,
1144 + static const struct file_operations fops_bind = {
1145 + .open = mtk_ppe_debugfs_foe_open_bind,
1147 + .llseek = seq_lseek,
1148 + .release = single_release,
1151 + struct dentry *root;
1153 + root = debugfs_create_dir("mtk_ppe", NULL);
1157 + debugfs_create_file("entries", S_IRUGO, root, ppe, &fops_all);
1158 + debugfs_create_file("bind", S_IRUGO, root, ppe, &fops_bind);
1163 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_regs.h
1165 +// SPDX-License-Identifier: GPL-2.0-only
1166 +/* Copyright (C) 2020 Felix Fietkau <nbd@nbd.name> */
1168 +#ifndef __MTK_PPE_REGS_H
1169 +#define __MTK_PPE_REGS_H
1171 +#define MTK_PPE_GLO_CFG 0x200
1172 +#define MTK_PPE_GLO_CFG_EN BIT(0)
1173 +#define MTK_PPE_GLO_CFG_TSID_EN BIT(1)
1174 +#define MTK_PPE_GLO_CFG_IP4_L4_CS_DROP BIT(2)
1175 +#define MTK_PPE_GLO_CFG_IP4_CS_DROP BIT(3)
1176 +#define MTK_PPE_GLO_CFG_TTL0_DROP BIT(4)
1177 +#define MTK_PPE_GLO_CFG_PPE_BSWAP BIT(5)
1178 +#define MTK_PPE_GLO_CFG_PSE_HASH_OFS BIT(6)
1179 +#define MTK_PPE_GLO_CFG_MCAST_TB_EN BIT(7)
1180 +#define MTK_PPE_GLO_CFG_FLOW_DROP_KA BIT(8)
1181 +#define MTK_PPE_GLO_CFG_FLOW_DROP_UPDATE BIT(9)
1182 +#define MTK_PPE_GLO_CFG_UDP_LITE_EN BIT(10)
1183 +#define MTK_PPE_GLO_CFG_UDP_LEN_DROP BIT(11)
1184 +#define MTK_PPE_GLO_CFG_MCAST_ENTRIES GNEMASK(13, 12)
1185 +#define MTK_PPE_GLO_CFG_BUSY BIT(31)
1187 +#define MTK_PPE_FLOW_CFG 0x204
1188 +#define MTK_PPE_FLOW_CFG_IP4_TCP_FRAG BIT(6)
1189 +#define MTK_PPE_FLOW_CFG_IP4_UDP_FRAG BIT(7)
1190 +#define MTK_PPE_FLOW_CFG_IP6_3T_ROUTE BIT(8)
1191 +#define MTK_PPE_FLOW_CFG_IP6_5T_ROUTE BIT(9)
1192 +#define MTK_PPE_FLOW_CFG_IP6_6RD BIT(10)
1193 +#define MTK_PPE_FLOW_CFG_IP4_NAT BIT(12)
1194 +#define MTK_PPE_FLOW_CFG_IP4_NAPT BIT(13)
1195 +#define MTK_PPE_FLOW_CFG_IP4_DSLITE BIT(14)
1196 +#define MTK_PPE_FLOW_CFG_L2_BRIDGE BIT(15)
1197 +#define MTK_PPE_FLOW_CFG_IP_PROTO_BLACKLIST BIT(16)
1198 +#define MTK_PPE_FLOW_CFG_IP4_NAT_FRAG BIT(17)
1199 +#define MTK_PPE_FLOW_CFG_IP4_HASH_FLOW_LABEL BIT(18)
1200 +#define MTK_PPE_FLOW_CFG_IP4_HASH_GRE_KEY BIT(19)
1201 +#define MTK_PPE_FLOW_CFG_IP6_HASH_GRE_KEY BIT(20)
1203 +#define MTK_PPE_IP_PROTO_CHK 0x208
1204 +#define MTK_PPE_IP_PROTO_CHK_IPV4 GENMASK(15, 0)
1205 +#define MTK_PPE_IP_PROTO_CHK_IPV6 GENMASK(31, 16)
1207 +#define MTK_PPE_TB_CFG 0x21c
1208 +#define MTK_PPE_TB_CFG_ENTRY_NUM GENMASK(2, 0)
1209 +#define MTK_PPE_TB_CFG_ENTRY_80B BIT(3)
1210 +#define MTK_PPE_TB_CFG_SEARCH_MISS GENMASK(5, 4)
1211 +#define MTK_PPE_TB_CFG_AGE_PREBIND BIT(6)
1212 +#define MTK_PPE_TB_CFG_AGE_NON_L4 BIT(7)
1213 +#define MTK_PPE_TB_CFG_AGE_UNBIND BIT(8)
1214 +#define MTK_PPE_TB_CFG_AGE_TCP BIT(9)
1215 +#define MTK_PPE_TB_CFG_AGE_UDP BIT(10)
1216 +#define MTK_PPE_TB_CFG_AGE_TCP_FIN BIT(11)
1217 +#define MTK_PPE_TB_CFG_KEEPALIVE GENMASK(13, 12)
1218 +#define MTK_PPE_TB_CFG_HASH_MODE GENMASK(15, 14)
1219 +#define MTK_PPE_TB_CFG_SCAN_MODE GENMASK(17, 16)
1220 +#define MTK_PPE_TB_CFG_HASH_DEBUG GENMASK(19, 18)
1223 + MTK_PPE_SCAN_MODE_DISABLED,
1224 + MTK_PPE_SCAN_MODE_CHECK_AGE,
1225 + MTK_PPE_SCAN_MODE_KEEPALIVE_AGE,
1229 + MTK_PPE_KEEPALIVE_DISABLE,
1230 + MTK_PPE_KEEPALIVE_UNICAST_CPU,
1231 + MTK_PPE_KEEPALIVE_DUP_CPU = 3,
1235 + MTK_PPE_SEARCH_MISS_ACTION_DROP,
1236 + MTK_PPE_SEARCH_MISS_ACTION_FORWARD = 2,
1237 + MTK_PPE_SEARCH_MISS_ACTION_FORWARD_BUILD = 3,
1240 +#define MTK_PPE_TB_BASE 0x220
1242 +#define MTK_PPE_TB_USED 0x224
1243 +#define MTK_PPE_TB_USED_NUM GENMASK(13, 0)
1245 +#define MTK_PPE_BIND_RATE 0x228
1246 +#define MTK_PPE_BIND_RATE_BIND GENMASK(15, 0)
1247 +#define MTK_PPE_BIND_RATE_PREBIND GENMASK(31, 16)
1249 +#define MTK_PPE_BIND_LIMIT0 0x22c
1250 +#define MTK_PPE_BIND_LIMIT0_QUARTER GENMASK(13, 0)
1251 +#define MTK_PPE_BIND_LIMIT0_HALF GENMASK(29, 16)
1253 +#define MTK_PPE_BIND_LIMIT1 0x230
1254 +#define MTK_PPE_BIND_LIMIT1_FULL GENMASK(13, 0)
1255 +#define MTK_PPE_BIND_LIMIT1_NON_L4 GENMASK(23, 16)
1257 +#define MTK_PPE_KEEPALIVE 0x234
1258 +#define MTK_PPE_KEEPALIVE_TIME GENMASK(15, 0)
1259 +#define MTK_PPE_KEEPALIVE_TIME_TCP GENMASK(23, 16)
1260 +#define MTK_PPE_KEEPALIVE_TIME_UDP GENMASK(31, 24)
1262 +#define MTK_PPE_UNBIND_AGE 0x238
1263 +#define MTK_PPE_UNBIND_AGE_MIN_PACKETS GENMASK(31, 16)
1264 +#define MTK_PPE_UNBIND_AGE_DELTA GENMASK(7, 0)
1266 +#define MTK_PPE_BIND_AGE0 0x23c
1267 +#define MTK_PPE_BIND_AGE0_DELTA_NON_L4 GENMASK(30, 16)
1268 +#define MTK_PPE_BIND_AGE0_DELTA_UDP GENMASK(14, 0)
1270 +#define MTK_PPE_BIND_AGE1 0x240
1271 +#define MTK_PPE_BIND_AGE1_DELTA_TCP_FIN GENMASK(30, 16)
1272 +#define MTK_PPE_BIND_AGE1_DELTA_TCP GENMASK(14, 0)
1274 +#define MTK_PPE_HASH_SEED 0x244
1276 +#define MTK_PPE_DEFAULT_CPU_PORT 0x248
1277 +#define MTK_PPE_DEFAULT_CPU_PORT_MASK(_n) (GENMASK(2, 0) << ((_n) * 4))
1279 +#define MTK_PPE_MTU_DROP 0x308
1281 +#define MTK_PPE_VLAN_MTU0 0x30c
1282 +#define MTK_PPE_VLAN_MTU0_NONE GENMASK(13, 0)
1283 +#define MTK_PPE_VLAN_MTU0_1TAG GENMASK(29, 16)
1285 +#define MTK_PPE_VLAN_MTU1 0x310
1286 +#define MTK_PPE_VLAN_MTU1_2TAG GENMASK(13, 0)
1287 +#define MTK_PPE_VLAN_MTU1_3TAG GENMASK(29, 16)
1289 +#define MTK_PPE_VPM_TPID 0x318
1291 +#define MTK_PPE_CACHE_CTL 0x320
1292 +#define MTK_PPE_CACHE_CTL_EN BIT(0)
1293 +#define MTK_PPE_CACHE_CTL_LOCK_CLR BIT(4)
1294 +#define MTK_PPE_CACHE_CTL_REQ BIT(8)
1295 +#define MTK_PPE_CACHE_CTL_CLEAR BIT(9)
1296 +#define MTK_PPE_CACHE_CTL_CMD GENMASK(13, 12)
1298 +#define MTK_PPE_MIB_CFG 0x334
1299 +#define MTK_PPE_MIB_CFG_EN BIT(0)
1300 +#define MTK_PPE_MIB_CFG_RD_CLR BIT(1)
1302 +#define MTK_PPE_MIB_TB_BASE 0x338
1304 +#define MTK_PPE_MIB_CACHE_CTL 0x350
1305 +#define MTK_PPE_MIB_CACHE_CTL_EN BIT(0)
1306 +#define MTK_PPE_MIB_CACHE_CTL_FLUSH BIT(2)