334661dd964fd0a5d64b9eba04b629d446113193
[openwrt/staging/thess.git] /
1 From a869d3a5eb011a9cf9bd864f31f5cf27362de8c7 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Mon, 2 Jun 2025 12:55:37 +0200
4 Subject: [PATCH 1/3] net: airoha: Initialize PPE UPDMEM source-mac table
5
6 UPDMEM source-mac table is a key-value map used to store devices mac
7 addresses according to the port identifier. UPDMEM source mac table is
8 used during IPv6 traffic hw acceleration since PPE entries, for space
9 constraints, do not contain the full source mac address but just the
10 identifier in the UPDMEM source-mac table.
11 Configure UPDMEM source-mac table with device mac addresses and set
12 the source-mac ID field for PPE IPv6 entries in order to select the
13 proper device mac address as source mac for L3 IPv6 hw accelerated traffic.
14
15 Fixes: 00a7678310fe ("net: airoha: Introduce flowtable offload support")
16 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
17 Reviewed-by: Simon Horman <horms@kernel.org>
18 Link: https://patch.msgid.link/20250602-airoha-flowtable-ipv6-fix-v2-1-3287f8b55214@kernel.org
19 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
20 ---
21 drivers/net/ethernet/airoha/airoha_eth.c | 2 ++
22 drivers/net/ethernet/airoha/airoha_eth.h | 1 +
23 drivers/net/ethernet/airoha/airoha_ppe.c | 26 ++++++++++++++++++++++-
24 drivers/net/ethernet/airoha/airoha_regs.h | 10 +++++++++
25 4 files changed, 38 insertions(+), 1 deletion(-)
26
27 --- a/drivers/net/ethernet/airoha/airoha_eth.c
28 +++ b/drivers/net/ethernet/airoha/airoha_eth.c
29 @@ -84,6 +84,8 @@ static void airoha_set_macaddr(struct ai
30 val = (addr[3] << 16) | (addr[4] << 8) | addr[5];
31 airoha_fe_wr(eth, REG_FE_MAC_LMIN(reg), val);
32 airoha_fe_wr(eth, REG_FE_MAC_LMAX(reg), val);
33 +
34 + airoha_ppe_init_upd_mem(port);
35 }
36
37 static void airoha_set_gdm_port_fwd_cfg(struct airoha_eth *eth, u32 addr,
38 --- a/drivers/net/ethernet/airoha/airoha_eth.h
39 +++ b/drivers/net/ethernet/airoha/airoha_eth.h
40 @@ -614,6 +614,7 @@ void airoha_ppe_check_skb(struct airoha_
41 int airoha_ppe_setup_tc_block_cb(struct net_device *dev, void *type_data);
42 int airoha_ppe_init(struct airoha_eth *eth);
43 void airoha_ppe_deinit(struct airoha_eth *eth);
44 +void airoha_ppe_init_upd_mem(struct airoha_gdm_port *port);
45 struct airoha_foe_entry *airoha_ppe_foe_get_entry(struct airoha_ppe *ppe,
46 u32 hash);
47 void airoha_ppe_foe_entry_get_stats(struct airoha_ppe *ppe, u32 hash,
48 --- a/drivers/net/ethernet/airoha/airoha_ppe.c
49 +++ b/drivers/net/ethernet/airoha/airoha_ppe.c
50 @@ -223,6 +223,7 @@ static int airoha_ppe_foe_entry_prepare(
51 int dsa_port = airoha_get_dsa_port(&dev);
52 struct airoha_foe_mac_info_common *l2;
53 u32 qdata, ports_pad, val;
54 + u8 smac_id = 0xf;
55
56 memset(hwe, 0, sizeof(*hwe));
57
58 @@ -257,6 +258,8 @@ static int airoha_ppe_foe_entry_prepare(
59 */
60 if (airhoa_is_lan_gdm_port(port))
61 val |= AIROHA_FOE_IB2_FAST_PATH;
62 +
63 + smac_id = port->id;
64 }
65
66 if (is_multicast_ether_addr(data->eth.h_dest))
67 @@ -291,7 +294,7 @@ static int airoha_ppe_foe_entry_prepare(
68 hwe->ipv4.l2.src_mac_lo =
69 get_unaligned_be16(data->eth.h_source + 4);
70 } else {
71 - l2->src_mac_hi = FIELD_PREP(AIROHA_FOE_MAC_SMAC_ID, 0xf);
72 + l2->src_mac_hi = FIELD_PREP(AIROHA_FOE_MAC_SMAC_ID, smac_id);
73 }
74
75 if (data->vlan.num) {
76 @@ -1238,6 +1241,27 @@ void airoha_ppe_check_skb(struct airoha_
77 airoha_ppe_foe_insert_entry(ppe, skb, hash);
78 }
79
80 +void airoha_ppe_init_upd_mem(struct airoha_gdm_port *port)
81 +{
82 + struct airoha_eth *eth = port->qdma->eth;
83 + struct net_device *dev = port->dev;
84 + const u8 *addr = dev->dev_addr;
85 + u32 val;
86 +
87 + val = (addr[2] << 24) | (addr[3] << 16) | (addr[4] << 8) | addr[5];
88 + airoha_fe_wr(eth, REG_UPDMEM_DATA(0), val);
89 + airoha_fe_wr(eth, REG_UPDMEM_CTRL(0),
90 + FIELD_PREP(PPE_UPDMEM_ADDR_MASK, port->id) |
91 + PPE_UPDMEM_WR_MASK | PPE_UPDMEM_REQ_MASK);
92 +
93 + val = (addr[0] << 8) | addr[1];
94 + airoha_fe_wr(eth, REG_UPDMEM_DATA(0), val);
95 + airoha_fe_wr(eth, REG_UPDMEM_CTRL(0),
96 + FIELD_PREP(PPE_UPDMEM_ADDR_MASK, port->id) |
97 + FIELD_PREP(PPE_UPDMEM_OFFSET_MASK, 1) |
98 + PPE_UPDMEM_WR_MASK | PPE_UPDMEM_REQ_MASK);
99 +}
100 +
101 int airoha_ppe_init(struct airoha_eth *eth)
102 {
103 struct airoha_ppe *ppe;
104 --- a/drivers/net/ethernet/airoha/airoha_regs.h
105 +++ b/drivers/net/ethernet/airoha/airoha_regs.h
106 @@ -313,6 +313,16 @@
107 #define REG_PPE_RAM_BASE(_n) (((_n) ? PPE2_BASE : PPE1_BASE) + 0x320)
108 #define REG_PPE_RAM_ENTRY(_m, _n) (REG_PPE_RAM_BASE(_m) + ((_n) << 2))
109
110 +#define REG_UPDMEM_CTRL(_n) (((_n) ? PPE2_BASE : PPE1_BASE) + 0x370)
111 +#define PPE_UPDMEM_ACK_MASK BIT(31)
112 +#define PPE_UPDMEM_ADDR_MASK GENMASK(11, 8)
113 +#define PPE_UPDMEM_OFFSET_MASK GENMASK(7, 4)
114 +#define PPE_UPDMEM_SEL_MASK GENMASK(3, 2)
115 +#define PPE_UPDMEM_WR_MASK BIT(1)
116 +#define PPE_UPDMEM_REQ_MASK BIT(0)
117 +
118 +#define REG_UPDMEM_DATA(_n) (((_n) ? PPE2_BASE : PPE1_BASE) + 0x374)
119 +
120 #define REG_FE_GDM_TX_OK_PKT_CNT_H(_n) (GDM_BASE(_n) + 0x280)
121 #define REG_FE_GDM_TX_OK_BYTE_CNT_H(_n) (GDM_BASE(_n) + 0x284)
122 #define REG_FE_GDM_TX_ETH_PKT_CNT_H(_n) (GDM_BASE(_n) + 0x288)