[PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists

From: Daniel Zahka

Date: Mon Nov 16 2026 - 16:11:53 EST


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@xxxxxxxxx>
---
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