From: Daniel Zahka <daniel.zahka@gmail.com>
To: Alexander Duyck <alexanderduyck@fb.com>,
Jakub Kicinski <kuba@kernel.org>,
kernel-team@meta.com, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Dimitri Daskalakis <dimitri.daskalakis1@gmail.com>,
Mohsin Bashir <mohsin.bashr@gmail.com>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
Daniel Zahka <daniel.zahka@gmail.com>
Subject: [PATCH net-next 3/4] eth: mpnic: sync unicast and multicast address lists
Date: Mon, 16 Nov 2026 13:11:21 -0800 [thread overview]
Message-ID: <20261116-mpnic-l2-oot-v1-3-8dc6eb3582b0@gmail.com> (raw)
In-Reply-To: <20261116-mpnic-l2-oot-v1-0-8dc6eb3582b0@gmail.com>
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
next prev parent reply other threads:[~2026-11-16 21:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-16 21:11 ` [PATCH net-next 4/4] eth: mpnic: support changing the MAC address Daniel Zahka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116-mpnic-l2-oot-v1-3-8dc6eb3582b0@gmail.com \
--to=daniel.zahka@gmail.com \
--cc=alexanderduyck@fb.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dimitri.daskalakis1@gmail.com \
--cc=edumazet@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mohsin.bashr@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®