* [PATCH net-next 0/4] eth: mpnic: L2 address filtering
@ 2026-11-16 21:11 Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 1/4] eth: mpnic: add filters for dev_addr and broadcast address Daniel Zahka
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Daniel Zahka @ 2026-11-16 21:11 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
David S. Miller, Eric Dumazet, Paolo Abeni, Dimitri Daskalakis,
Mohsin Bashir
Cc: linux-kernel, netdev, Daniel Zahka
The mpnic device has a TCAM that is keyed on DMAC addresses in the Rx
path. Up to this point, the TCAM was unprogrammed, and the default
action was set to pass all traffic to the host. This series programs the
TCAM to filter Rx packets based on DMAC address.
The device, broadcast, sencondary unicast and multicast addresses are
added to the DMAC filter. Promiscuous and all-multicast modes are also
supported by reserving the last entry in the TCAM for inexact matches.
The overall design is similar to fbnic. For each entry in the TCAM, the
driver tracks the lookup key, mask, state, and users of the entry.
Addresses are synced to HW in the ndo_open path, and unsynced in the
ndo_stop path. ndo_set_rx_mode_async and ndo_set_mac_address are
implemented, so the filtered addresses and promiscuity modes can be
updated.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
Daniel Zahka (4):
eth: mpnic: add filters for dev_addr and broadcast address
eth: mpnic: add promiscuous and all-multicast filters
eth: mpnic: sync unicast and multicast address lists
eth: mpnic: support changing the MAC address
drivers/net/ethernet/meta/mpnic/Makefile | 1 +
drivers/net/ethernet/meta/mpnic/mpnic.h | 3 +
drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 10 ++
drivers/net/ethernet/meta/mpnic/mpnic_init.c | 15 ++-
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 116 ++++++++++++++++++++++
drivers/net/ethernet/meta/mpnic/mpnic_rpc.c | 129 +++++++++++++++++++++++++
drivers/net/ethernet/meta/mpnic/mpnic_rpc.h | 51 ++++++++++
7 files changed, 321 insertions(+), 4 deletions(-)
---
base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
change-id: 20261112-mpnic-l2-oot-2a185cd5f9bd
Best regards,
--
Daniel Zahka <daniel.zahka@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/4] eth: mpnic: add filters for dev_addr and broadcast address
2026-11-16 21:11 [PATCH net-next 0/4] eth: mpnic: L2 address filtering Daniel Zahka
@ 2026-11-16 21:11 ` Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 2/4] eth: mpnic: add promiscuous and all-multicast filters Daniel Zahka
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Zahka @ 2026-11-16 21:11 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
David S. Miller, Eric Dumazet, Paolo Abeni, Dimitri Daskalakis,
Mohsin Bashir
Cc: linux-kernel, netdev, Daniel Zahka
The device checks the destination MAC of every frame against a
1024 entry TCAM in order to select a pass or drop action. Up to this
point, no addresses have been programmed into the TCAM, and the default
action is set to pass.
Program the dev_addr and ethernet broadcast address into the TCAM. At
init, all TCAM entries are set to invalid, and all match actions are set
to pass. This means adding an address and making the entry valid will
result in pass action being taken for that address. When we no longer
want to filter for that address, the entry is simply invalidated. We
never change the per-entry match actions after initialization.
Because the default action on TCAM miss is still set to pass, the device
is still effectively in promiscuous mode even after this commit.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
drivers/net/ethernet/meta/mpnic/Makefile | 1 +
drivers/net/ethernet/meta/mpnic/mpnic.h | 3 ++
drivers/net/ethernet/meta/mpnic/mpnic_csr.h | 10 ++++++
drivers/net/ethernet/meta/mpnic/mpnic_init.c | 10 ++++++
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 49 ++++++++++++++++++++++++++
drivers/net/ethernet/meta/mpnic/mpnic_rpc.c | 42 ++++++++++++++++++++++
drivers/net/ethernet/meta/mpnic/mpnic_rpc.h | 43 ++++++++++++++++++++++
7 files changed, 158 insertions(+)
diff --git a/drivers/net/ethernet/meta/mpnic/Makefile b/drivers/net/ethernet/meta/mpnic/Makefile
index d5bdbd5bd1c7..1910df806d77 100644
--- a/drivers/net/ethernet/meta/mpnic/Makefile
+++ b/drivers/net/ethernet/meta/mpnic/Makefile
@@ -12,5 +12,6 @@ mpnic-y := \
mpnic_irq.o \
mpnic_netdev.o \
mpnic_pci.o \
+ mpnic_rpc.o \
mpnic_txrx.o \
# End of mpnic-y
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic.h b/drivers/net/ethernet/meta/mpnic/mpnic.h
index 8b08af0fadcc..9e31bb71aa94 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic.h
+++ b/drivers/net/ethernet/meta/mpnic/mpnic.h
@@ -10,6 +10,7 @@
#include <linux/workqueue.h>
#include "mpnic_csr.h"
+#include "mpnic_rpc.h"
#define MPNIC_DRV_NAME "mpnic"
@@ -36,6 +37,8 @@ struct mpnic_dev {
u32 mps;
u32 readrq;
u8 relaxed_ord;
+
+ struct mpnic_mac_addr mac_addr[MPNIC_RXB_DMAC_TCAM_CNT];
};
u64 mpnic_rd64(struct mpnic_dev *mpd, u32 reg);
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
index 03304e22d6ce..94733b40a96f 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_csr.h
@@ -311,6 +311,8 @@ enum {
MPNIC_L2_ACTION_PASS = 1,
};
+#define MPNIC_RXB_DMAC_ACTION(i) (0x62002a + 2 * (i)) /* 0x18800a8 */
+#define MPNIC_RXB_DMAC_ACTION_CNT 16
#define MPNIC_RXB_TC_CRDTS(i) (0x620418 + 2 * (i)) /* 0x1881060 */
#define MPNIC_RXB_POOL_COMMON_CRDTS(i) (0x620458 + 2 * (i)) /* 0x1881160 */
#define MPNIC_RXB_COMMON_CRDT_CTRL_TC(i) \
@@ -320,6 +322,14 @@ enum {
#define MPNIC_RXB_COMMON_CRDT_CTRL_TC_MAX_CRDTS CSR_GENMASK(47, 32)
#define MPNIC_RXB_HOST_DROP_THRESH(i) (0x6205b0 + 2 * (i)) /* 0x18816c0 */
#define MPNIC_RXB_BMC_CRDTS(i) (0x6205d0 + 2 * (i)) /* 0x1881740 */
+#define MPNIC_RXB_DMAC_TCAM(i) (0x620e5e + 4 * (i)) /* 0x1883978 */
+#define MPNIC_RXB_DMAC_TCAM_MASK(i) (0x620e60 + 4 * (i)) /* 0x1883980 */
+#define MPNIC_RXB_DMAC_TCAM_CNT 1024
+#define MPNIC_RXB_DMAC_TCAM_DMAC CSR_GENMASK(47, 0)
+#define MPNIC_RXB_DMAC_TCAM_OP 0x622f60 /* 0x188bd80 */
+#define MPNIC_RXB_DMAC_TCAM_OP_RELOAD_TRIG CSR_BIT(0)
+#define MPNIC_RXB_DMAC_TCAM_OP_UNLOAD_TRIG CSR_BIT(1)
+#define MPNIC_RXB_DMAC_TCAM_OP_TCAM_ENTRY CSR_GENMASK(11, 2)
/* NIC_CORE_RPC */
#define MPNIC_RPC_MEM_INIT_REQ 0x780440 /* 0x1e01100 */
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_init.c b/drivers/net/ethernet/meta/mpnic/mpnic_init.c
index ab832ec5de0e..889555eb4790 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_init.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_init.c
@@ -227,6 +227,16 @@ static void mpnic_rxb_init(struct mpnic_dev *mpd)
mpnic_wr64(mpd, MPNIC_RXB_BMC_CRDTS(0), MPNIC_RXB_INIT_BMC_CRDTS);
+ /* One bit per DMAC TCAM entry, set means pass on hit */
+ for (int i = 0; i < MPNIC_RXB_DMAC_ACTION_CNT; i++)
+ mpnic_wr64(mpd, MPNIC_RXB_DMAC_ACTION(i), ~0ULL);
+
+ /* Start with all DMAC TCAM entries disabled */
+ for (int i = 0; i < MPNIC_RXB_DMAC_TCAM_CNT; i++)
+ mpnic_wr64(mpd, MPNIC_RXB_DMAC_TCAM_OP,
+ FIELD_PREP(MPNIC_RXB_DMAC_TCAM_OP_TCAM_ENTRY, i) |
+ MPNIC_RXB_DMAC_TCAM_OP_UNLOAD_TRIG);
+
mpnic_wr64(mpd, MPNIC_RXB_MEM_INIT_REQ, MPNIC_MEM_INIT_RXB_VAL);
}
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
index 198aad631c65..16611813db55 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
@@ -12,6 +12,52 @@
#include "mpnic_netdev.h"
#include "mpnic_txrx.h"
+static void __mpnic_set_rx_mode(struct mpnic_dev *mpd)
+{
+ struct net_device *netdev = mpd->netdev;
+ struct mpnic_mac_addr *mac_addr;
+
+ mac_addr = &mpd->mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX];
+ if (!ether_addr_equal(mac_addr->value, netdev->dev_addr) ||
+ mac_addr->state != MPNIC_TCAM_S_VALID) {
+ ether_addr_copy(mac_addr->value, netdev->dev_addr);
+ eth_broadcast_addr(mac_addr->mask);
+ mac_addr->state = MPNIC_TCAM_S_ADD;
+ }
+
+ mac_addr = &mpd->mac_addr[MPNIC_TCAM_MACDA_BROADCAST_IDX];
+ if (!is_broadcast_ether_addr(mac_addr->value) ||
+ mac_addr->state != MPNIC_TCAM_S_VALID) {
+ eth_broadcast_addr(mac_addr->value);
+ eth_broadcast_addr(mac_addr->mask);
+ mac_addr->state = MPNIC_TCAM_S_ADD;
+ }
+
+ mpnic_write_macda(mpd);
+}
+
+static int mpnic_set_rx_mode(struct net_device *netdev,
+ struct netdev_hw_addr_list *uc,
+ struct netdev_hw_addr_list *mc)
+{
+ struct mpnic_net *mpn = netdev_priv(netdev);
+
+ if (netif_running(netdev))
+ __mpnic_set_rx_mode(mpn->mpd);
+
+ return 0;
+}
+
+static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
+{
+ struct mpnic_mac_addr *mac_addr = mpd->mac_addr;
+
+ mac_addr[MPNIC_TCAM_MACDA_BROADCAST_IDX].state = MPNIC_TCAM_S_DELETE;
+ mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX].state = MPNIC_TCAM_S_DELETE;
+
+ mpnic_write_macda(mpd);
+}
+
static int mpnic_open(struct net_device *netdev)
{
struct mpnic_net *mpn = netdev_priv(netdev);
@@ -33,6 +79,7 @@ static int mpnic_open(struct net_device *netdev)
mpnic_enable(mpn);
mpnic_fill(mpn);
+ __mpnic_set_rx_mode(mpn->mpd);
mpnic_napi_enable(mpn);
netif_tx_wake_all_queues(netdev);
@@ -59,6 +106,7 @@ static int mpnic_stop(struct net_device *netdev)
mpnic_napi_disable(mpn);
netif_tx_disable(netdev);
+ mpnic_clear_rx_mode(mpn->mpd);
mpnic_disable(mpn);
mpnic_wait_all_queues_idle(mpn->mpd);
mpnic_flush(mpn);
@@ -145,6 +193,7 @@ static const struct net_device_ops mpnic_netdev_ops = {
.ndo_validate_addr = eth_validate_addr,
.ndo_start_xmit = mpnic_xmit_frame,
.ndo_features_check = mpnic_features_check,
+ .ndo_set_rx_mode_async = mpnic_set_rx_mode,
.ndo_get_stats64 = mpnic_get_stats64,
};
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c
new file mode 100644
index 000000000000..c96aec4de3e4
--- /dev/null
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) Meta Platforms, Inc. and affiliates. */
+
+#include <linux/bitfield.h>
+#include <linux/etherdevice.h>
+
+#include "mpnic.h"
+#include "mpnic_rpc.h"
+
+static void mpnic_write_macda_entry(struct mpnic_dev *mpd, unsigned int idx,
+ struct mpnic_mac_addr *mac_addr)
+{
+ mpnic_wr64(mpd, MPNIC_RXB_DMAC_TCAM(idx),
+ FIELD_PREP(MPNIC_RXB_DMAC_TCAM_DMAC,
+ ether_addr_to_u64(mac_addr->value)));
+ mpnic_wr64(mpd, MPNIC_RXB_DMAC_TCAM_MASK(idx),
+ FIELD_PREP(MPNIC_RXB_DMAC_TCAM_DMAC,
+ ether_addr_to_u64(mac_addr->mask)));
+}
+
+void mpnic_write_macda(struct mpnic_dev *mpd)
+{
+ for (int i = 0; i < ARRAY_SIZE(mpd->mac_addr); i++) {
+ u64 tcam_op = FIELD_PREP(MPNIC_RXB_DMAC_TCAM_OP_TCAM_ENTRY, i);
+ struct mpnic_mac_addr *mac_addr = &mpd->mac_addr[i];
+
+ if (mac_addr->state != MPNIC_TCAM_S_ADD &&
+ mac_addr->state != MPNIC_TCAM_S_DELETE)
+ continue;
+
+ if (mac_addr->state == MPNIC_TCAM_S_DELETE) {
+ memset(mac_addr, 0, sizeof(*mac_addr));
+ tcam_op |= MPNIC_RXB_DMAC_TCAM_OP_UNLOAD_TRIG;
+ } else {
+ mpnic_write_macda_entry(mpd, i, mac_addr);
+ mac_addr->state = MPNIC_TCAM_S_VALID;
+ tcam_op |= MPNIC_RXB_DMAC_TCAM_OP_RELOAD_TRIG;
+ }
+
+ mpnic_wr64(mpd, MPNIC_RXB_DMAC_TCAM_OP, tcam_op);
+ }
+}
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h
new file mode 100644
index 000000000000..f6e4f60180d6
--- /dev/null
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) Meta Platforms, Inc. and affiliates. */
+
+#ifndef _MPNIC_RPC_H_
+#define _MPNIC_RPC_H_
+
+#include <linux/if_ether.h>
+#include <linux/types.h>
+
+#include "mpnic_csr.h"
+
+struct mpnic_dev;
+
+/* The TCAM state definitions follow an expected ordering.
+ * They start out disabled, then move through the following states:
+ * Disabled 0 -> Add 2
+ * Add 2 -> Valid 1
+ *
+ * Valid 1 -> Add 2
+ * Add 2 -> Valid 1
+ *
+ * Valid 1 -> Delete 3
+ * Delete 3 -> Disabled 0
+ */
+enum {
+ MPNIC_TCAM_S_DISABLED = 0,
+ MPNIC_TCAM_S_VALID = 1,
+ MPNIC_TCAM_S_ADD = 2,
+ MPNIC_TCAM_S_DELETE = 3,
+};
+
+#define MPNIC_TCAM_MACDA_BROADCAST_IDX 0
+#define MPNIC_TCAM_MACDA_HOST_ADDR_IDX (MPNIC_RXB_DMAC_TCAM_CNT - 2)
+
+struct mpnic_mac_addr {
+ u8 mask[ETH_ALEN];
+ u8 value[ETH_ALEN];
+ u8 state;
+} __aligned(2);
+
+void mpnic_write_macda(struct mpnic_dev *mpd);
+
+#endif /* _MPNIC_RPC_H_ */
--
2.52.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 2/4] eth: mpnic: add promiscuous and all-multicast filters
2026-11-16 21:11 [PATCH net-next 0/4] eth: mpnic: L2 address filtering Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 1/4] eth: mpnic: add filters for dev_addr and broadcast address Daniel Zahka
@ 2026-11-16 21:11 ` Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 4/4] eth: mpnic: support changing the MAC address Daniel Zahka
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Zahka @ 2026-11-16 21:11 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
David S. Miller, Eric Dumazet, Paolo Abeni, Dimitri Daskalakis,
Mohsin Bashir
Cc: linux-kernel, netdev, Daniel Zahka
Implement IFF_PROMISC and IFF_ALLMULTI with the last TCAM entry, which
matches either every address or only the multicast bit.
Change the default action on TCAM misses to drop frames. With the
device, broadcast and promiscuous entries in place, frames that miss the
TCAM can be dropped instead of delivered to the stack to drop.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
drivers/net/ethernet/meta/mpnic/mpnic_init.c | 5 +----
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 21 +++++++++++++++++---
drivers/net/ethernet/meta/mpnic/mpnic_rpc.c | 27 ++++++++++++++++++++++++++
drivers/net/ethernet/meta/mpnic/mpnic_rpc.h | 3 +++
4 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_init.c b/drivers/net/ethernet/meta/mpnic/mpnic_init.c
index 889555eb4790..0c2878c18c54 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_init.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_init.c
@@ -199,12 +199,9 @@ static void mpnic_txb_init(struct mpnic_dev *mpd)
static void mpnic_rxb_init(struct mpnic_dev *mpd)
{
- /* Accept all packets that miss dmac tcam, until l2 filtering is
- * implemented.
- */
mpnic_wr64(mpd, MPNIC_RXB_PORT_CLASS_CFG(0),
FIELD_PREP(MPNIC_RXB_PORT_CLASS_CFG_DEFAULT_L2_ACTION,
- MPNIC_L2_ACTION_PASS));
+ MPNIC_L2_ACTION_DROP));
mpnic_wr64(mpd, MPNIC_RXB_PORT_CFG(0),
FIELD_PREP(MPNIC_RXB_PORT_CFG_FCS_STRIP_MODE,
MPNIC_FCS_MODE_STRIP));
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
index 16611813db55..43547a7d6e5c 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
@@ -12,8 +12,10 @@
#include "mpnic_netdev.h"
#include "mpnic_txrx.h"
-static void __mpnic_set_rx_mode(struct mpnic_dev *mpd)
+static void __mpnic_set_rx_mode(struct mpnic_dev *mpd,
+ struct netdev_hw_addr_list *mc)
{
+ bool uc_promisc = false, mc_promisc = false;
struct net_device *netdev = mpd->netdev;
struct mpnic_mac_addr *mac_addr;
@@ -33,6 +35,14 @@ static void __mpnic_set_rx_mode(struct mpnic_dev *mpd)
mac_addr->state = MPNIC_TCAM_S_ADD;
}
+ if (!netdev_hw_addr_list_empty(mc))
+ mc_promisc = true;
+
+ uc_promisc |= netdev->flags & IFF_PROMISC;
+ mc_promisc |= netdev->flags & IFF_ALLMULTI;
+
+ mpnic_promisc_sync(mpd, uc_promisc, mc_promisc);
+
mpnic_write_macda(mpd);
}
@@ -43,7 +53,7 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
struct mpnic_net *mpn = netdev_priv(netdev);
if (netif_running(netdev))
- __mpnic_set_rx_mode(mpn->mpd);
+ __mpnic_set_rx_mode(mpn->mpd, mc);
return 0;
}
@@ -54,6 +64,7 @@ static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
mac_addr[MPNIC_TCAM_MACDA_BROADCAST_IDX].state = MPNIC_TCAM_S_DELETE;
mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX].state = MPNIC_TCAM_S_DELETE;
+ mac_addr[MPNIC_TCAM_MACDA_PROMISC_IDX].state = MPNIC_TCAM_S_DELETE;
mpnic_write_macda(mpd);
}
@@ -79,7 +90,11 @@ static int mpnic_open(struct net_device *netdev)
mpnic_enable(mpn);
mpnic_fill(mpn);
- __mpnic_set_rx_mode(mpn->mpd);
+
+ netif_addr_lock_bh(netdev);
+ __mpnic_set_rx_mode(mpn->mpd, &netdev->mc);
+ netif_addr_unlock_bh(netdev);
+
mpnic_napi_enable(mpn);
netif_tx_wake_all_queues(netdev);
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c
index c96aec4de3e4..ebbccf8ec723 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c
@@ -7,6 +7,33 @@
#include "mpnic.h"
#include "mpnic_rpc.h"
+void mpnic_promisc_sync(struct mpnic_dev *mpd, bool uc_promisc,
+ bool mc_promisc)
+{
+ struct mpnic_mac_addr *mac_addr;
+
+ mac_addr = &mpd->mac_addr[MPNIC_TCAM_MACDA_PROMISC_IDX];
+ if (uc_promisc) {
+ if (!is_zero_ether_addr(mac_addr->value) ||
+ mac_addr->state != MPNIC_TCAM_S_VALID) {
+ eth_zero_addr(mac_addr->value);
+ eth_zero_addr(mac_addr->mask);
+ mac_addr->state = MPNIC_TCAM_S_ADD;
+ }
+ } else if (mc_promisc) {
+ if (!is_multicast_ether_addr(mac_addr->value) ||
+ mac_addr->state != MPNIC_TCAM_S_VALID) {
+ eth_zero_addr(mac_addr->value);
+ eth_zero_addr(mac_addr->mask);
+ mac_addr->value[0] ^= 1;
+ mac_addr->mask[0] ^= 1;
+ mac_addr->state = MPNIC_TCAM_S_ADD;
+ }
+ } else if (mac_addr->state == MPNIC_TCAM_S_VALID) {
+ mac_addr->state = MPNIC_TCAM_S_DELETE;
+ }
+}
+
static void mpnic_write_macda_entry(struct mpnic_dev *mpd, unsigned int idx,
struct mpnic_mac_addr *mac_addr)
{
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h
index f6e4f60180d6..0eec09df7642 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h
@@ -31,6 +31,7 @@ enum {
#define MPNIC_TCAM_MACDA_BROADCAST_IDX 0
#define MPNIC_TCAM_MACDA_HOST_ADDR_IDX (MPNIC_RXB_DMAC_TCAM_CNT - 2)
+#define MPNIC_TCAM_MACDA_PROMISC_IDX (MPNIC_RXB_DMAC_TCAM_CNT - 1)
struct mpnic_mac_addr {
u8 mask[ETH_ALEN];
@@ -38,6 +39,8 @@ struct mpnic_mac_addr {
u8 state;
} __aligned(2);
+void mpnic_promisc_sync(struct mpnic_dev *mpd, bool uc_promisc,
+ bool mc_promisc);
void mpnic_write_macda(struct mpnic_dev *mpd);
#endif /* _MPNIC_RPC_H_ */
--
2.52.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists
2026-11-16 21:11 [PATCH net-next 0/4] eth: mpnic: L2 address filtering Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 1/4] eth: mpnic: add filters for dev_addr and broadcast address Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 2/4] eth: mpnic: add promiscuous and all-multicast filters Daniel Zahka
@ 2026-11-16 21:11 ` Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 4/4] eth: mpnic: support changing the MAC address Daniel Zahka
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Zahka @ 2026-11-16 21:11 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
David S. Miller, Eric Dumazet, Paolo Abeni, Dimitri Daskalakis,
Mohsin Bashir
Cc: linux-kernel, netdev, Daniel Zahka
Add the secondary unicast and multicast addresses to the MACDA TCAM.
Advertise IFF_UNICAST_FLT so we don't need to use promiscuous mode to
handle extra unicast addresses.
When the unicast or multicast list outgrows the table, fall back to
promiscuous or all-multicast mode respectively.
Track the number of users of a HW filter, because the same address can
be used in the dev->uc and dev->mc lists.
Allow a filter slot pending deletion to be reused during
mpnic_macda_sync(). Document this transition in the state machine
comment.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 38 ++++++++++++++--
drivers/net/ethernet/meta/mpnic/mpnic_rpc.c | 60 ++++++++++++++++++++++++++
drivers/net/ethernet/meta/mpnic/mpnic_rpc.h | 5 +++
3 files changed, 100 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
index 43547a7d6e5c..c01e276c4a74 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
@@ -12,12 +12,30 @@
#include "mpnic_netdev.h"
#include "mpnic_txrx.h"
+static int mpnic_addr_sync(struct net_device *netdev,
+ const unsigned char *addr)
+{
+ struct mpnic_net *mpn = netdev_priv(netdev);
+
+ return mpnic_macda_sync(mpn->mpd, addr);
+}
+
+static int mpnic_addr_unsync(struct net_device *netdev,
+ const unsigned char *addr)
+{
+ struct mpnic_net *mpn = netdev_priv(netdev);
+
+ return mpnic_macda_unsync(mpn->mpd, addr);
+}
+
static void __mpnic_set_rx_mode(struct mpnic_dev *mpd,
+ struct netdev_hw_addr_list *uc,
struct netdev_hw_addr_list *mc)
{
bool uc_promisc = false, mc_promisc = false;
struct net_device *netdev = mpd->netdev;
struct mpnic_mac_addr *mac_addr;
+ int err;
mac_addr = &mpd->mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX];
if (!ether_addr_equal(mac_addr->value, netdev->dev_addr) ||
@@ -35,7 +53,14 @@ static void __mpnic_set_rx_mode(struct mpnic_dev *mpd,
mac_addr->state = MPNIC_TCAM_S_ADD;
}
- if (!netdev_hw_addr_list_empty(mc))
+ err = __hw_addr_sync_dev(uc, netdev, mpnic_addr_sync,
+ mpnic_addr_unsync);
+ if (err == -ENOSPC)
+ uc_promisc = true;
+
+ err = __hw_addr_sync_dev(mc, netdev, mpnic_addr_sync,
+ mpnic_addr_unsync);
+ if (err == -ENOSPC)
mc_promisc = true;
uc_promisc |= netdev->flags & IFF_PROMISC;
@@ -53,7 +78,7 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
struct mpnic_net *mpn = netdev_priv(netdev);
if (netif_running(netdev))
- __mpnic_set_rx_mode(mpn->mpd, mc);
+ __mpnic_set_rx_mode(mpn->mpd, uc, mc);
return 0;
}
@@ -61,6 +86,12 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
{
struct mpnic_mac_addr *mac_addr = mpd->mac_addr;
+ struct net_device *netdev = mpd->netdev;
+
+ netif_addr_lock_bh(netdev);
+ __dev_uc_unsync(netdev, mpnic_addr_unsync);
+ __dev_mc_unsync(netdev, mpnic_addr_unsync);
+ netif_addr_unlock_bh(netdev);
mac_addr[MPNIC_TCAM_MACDA_BROADCAST_IDX].state = MPNIC_TCAM_S_DELETE;
mac_addr[MPNIC_TCAM_MACDA_HOST_ADDR_IDX].state = MPNIC_TCAM_S_DELETE;
@@ -92,7 +123,7 @@ static int mpnic_open(struct net_device *netdev)
mpnic_fill(mpn);
netif_addr_lock_bh(netdev);
- __mpnic_set_rx_mode(mpn->mpd, &netdev->mc);
+ __mpnic_set_rx_mode(mpn->mpd, &netdev->uc, &netdev->mc);
netif_addr_unlock_bh(netdev);
mpnic_napi_enable(mpn);
@@ -366,6 +397,7 @@ struct net_device *mpnic_netdev_alloc(struct mpnic_dev *mpd)
netdev->netdev_ops = &mpnic_netdev_ops;
netdev->stat_ops = &mpnic_stat_ops;
netdev->request_ops_lock = true;
+ netdev->priv_flags |= IFF_UNICAST_FLT;
mpn = netdev_priv(netdev);
mpn->netdev = netdev;
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c
index ebbccf8ec723..509a63c271cd 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.c
@@ -7,6 +7,66 @@
#include "mpnic.h"
#include "mpnic_rpc.h"
+static bool mpnic_macda_free(struct mpnic_mac_addr *mac_addr)
+{
+ return mac_addr->state == MPNIC_TCAM_S_DISABLED ||
+ mac_addr->state == MPNIC_TCAM_S_DELETE;
+}
+
+int mpnic_macda_sync(struct mpnic_dev *mpd, const u8 *addr)
+{
+ struct mpnic_mac_addr *avail_addr = NULL;
+ unsigned int i;
+
+ for (i = MPNIC_TCAM_MACDA_BROADCAST_IDX + 1;
+ i < MPNIC_TCAM_MACDA_HOST_ADDR_IDX; i++) {
+ struct mpnic_mac_addr *mac_addr = &mpd->mac_addr[i];
+
+ if (mac_addr->state != MPNIC_TCAM_S_DISABLED &&
+ ether_addr_equal(mac_addr->value, addr)) {
+ avail_addr = mac_addr;
+ break;
+ }
+
+ if (!avail_addr && mpnic_macda_free(mac_addr))
+ avail_addr = mac_addr;
+ }
+
+ if (!avail_addr)
+ return -ENOSPC;
+
+ if (mpnic_macda_free(avail_addr)) {
+ ether_addr_copy(avail_addr->value, addr);
+ eth_broadcast_addr(avail_addr->mask);
+ avail_addr->state = MPNIC_TCAM_S_ADD;
+ }
+
+ avail_addr->users++;
+
+ return 0;
+}
+
+int mpnic_macda_unsync(struct mpnic_dev *mpd, const u8 *addr)
+{
+ unsigned int i;
+
+ for (i = MPNIC_TCAM_MACDA_BROADCAST_IDX + 1;
+ i < MPNIC_TCAM_MACDA_HOST_ADDR_IDX; i++) {
+ struct mpnic_mac_addr *mac_addr = &mpd->mac_addr[i];
+
+ if (mpnic_macda_free(mac_addr) ||
+ !ether_addr_equal(mac_addr->value, addr))
+ continue;
+
+ if (!--mac_addr->users)
+ mac_addr->state = MPNIC_TCAM_S_DELETE;
+
+ return 0;
+ }
+
+ return -ENOENT;
+}
+
void mpnic_promisc_sync(struct mpnic_dev *mpd, bool uc_promisc,
bool mc_promisc)
{
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h
index 0eec09df7642..8ed507daaf6f 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_rpc.h
@@ -21,6 +21,8 @@ struct mpnic_dev;
*
* Valid 1 -> Delete 3
* Delete 3 -> Disabled 0
+ *
+ * Delete 3 -> Add 2
*/
enum {
MPNIC_TCAM_S_DISABLED = 0,
@@ -37,8 +39,11 @@ struct mpnic_mac_addr {
u8 mask[ETH_ALEN];
u8 value[ETH_ALEN];
u8 state;
+ u8 users;
} __aligned(2);
+int mpnic_macda_sync(struct mpnic_dev *mpd, const u8 *addr);
+int mpnic_macda_unsync(struct mpnic_dev *mpd, const u8 *addr);
void mpnic_promisc_sync(struct mpnic_dev *mpd, bool uc_promisc,
bool mc_promisc);
void mpnic_write_macda(struct mpnic_dev *mpd);
--
2.52.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 4/4] eth: mpnic: support changing the MAC address
2026-11-16 21:11 [PATCH net-next 0/4] eth: mpnic: L2 address filtering Daniel Zahka
` (2 preceding siblings ...)
2026-11-16 21:11 ` [PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists Daniel Zahka
@ 2026-11-16 21:11 ` Daniel Zahka
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Zahka @ 2026-11-16 21:11 UTC (permalink / raw)
To: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
David S. Miller, Eric Dumazet, Paolo Abeni, Dimitri Daskalakis,
Mohsin Bashir
Cc: linux-kernel, netdev, Daniel Zahka
Let the user change the primary dev_addr used by the device. Core
doesn't schedule an rx mode update for an address change, so the TCAM is
updated inline. The device address entry is rewritten in place, so
frames to the old address stop matching once the new one is written.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
drivers/net/ethernet/meta/mpnic/mpnic_netdev.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
index c01e276c4a74..fff35d150572 100644
--- a/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
+++ b/drivers/net/ethernet/meta/mpnic/mpnic_netdev.c
@@ -83,6 +83,25 @@ static int mpnic_set_rx_mode(struct net_device *netdev,
return 0;
}
+static int mpnic_set_mac(struct net_device *netdev, void *p)
+{
+ struct mpnic_net *mpn = netdev_priv(netdev);
+ struct sockaddr *addr = p;
+
+ if (!is_valid_ether_addr(addr->sa_data))
+ return -EADDRNOTAVAIL;
+
+ eth_hw_addr_set(netdev, addr->sa_data);
+
+ if (netif_running(netdev)) {
+ netif_addr_lock_bh(netdev);
+ __mpnic_set_rx_mode(mpn->mpd, &netdev->uc, &netdev->mc);
+ netif_addr_unlock_bh(netdev);
+ }
+
+ return 0;
+}
+
static void mpnic_clear_rx_mode(struct mpnic_dev *mpd)
{
struct mpnic_mac_addr *mac_addr = mpd->mac_addr;
@@ -237,6 +256,7 @@ static const struct net_device_ops mpnic_netdev_ops = {
.ndo_open = mpnic_open,
.ndo_stop = mpnic_stop,
.ndo_validate_addr = eth_validate_addr,
+ .ndo_set_mac_address = mpnic_set_mac,
.ndo_start_xmit = mpnic_xmit_frame,
.ndo_features_check = mpnic_features_check,
.ndo_set_rx_mode_async = mpnic_set_rx_mode,
--
2.52.1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-16 21:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 21:11 [PATCH net-next 0/4] eth: mpnic: L2 address filtering Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 1/4] eth: mpnic: add filters for dev_addr and broadcast address Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 2/4] eth: mpnic: add promiscuous and all-multicast filters Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists Daniel Zahka
2026-11-16 21:11 ` [PATCH net-next 4/4] eth: mpnic: support changing the MAC address Daniel Zahka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®