From: Shannon Nelson <snelson@pensando.io>
To: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org
Cc: drivers@pensando.io, jtoppins@redhat.com,
Shannon Nelson <snelson@pensando.io>
Subject: [PATCH net-next 5/9] ionic: generic filter add
Date: Sat, 9 Oct 2021 11:45:19 -0700 [thread overview]
Message-ID: <20211009184523.73154-6-snelson@pensando.io> (raw)
In-Reply-To: <20211009184523.73154-1-snelson@pensando.io>
In preparation for adding vlan overflow management, rework
the ionic_lif_addr_add() function to something a little more
generic that can be used for other filter types.
Signed-off-by: Shannon Nelson <snelson@pensando.io>
---
.../ethernet/pensando/ionic/ionic_rx_filter.c | 68 +++++++++++++------
1 file changed, 46 insertions(+), 22 deletions(-)
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_rx_filter.c b/drivers/net/ethernet/pensando/ionic/ionic_rx_filter.c
index 38109244a722..10837e41f819 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_rx_filter.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_rx_filter.c
@@ -301,22 +301,19 @@ int ionic_lif_list_addr(struct ionic_lif *lif, const u8 *addr, bool mode)
return 0;
}
-int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr)
+static int ionic_lif_filter_add(struct ionic_lif *lif,
+ struct ionic_rx_filter_add_cmd *ac)
{
struct ionic_admin_ctx ctx = {
.work = COMPLETION_INITIALIZER_ONSTACK(ctx.work),
- .cmd.rx_filter_add = {
- .opcode = IONIC_CMD_RX_FILTER_ADD,
- .lif_index = cpu_to_le16(lif->index),
- .match = cpu_to_le16(IONIC_RX_FILTER_MATCH_MAC),
- },
};
- int nfilters = le32_to_cpu(lif->identity->eth.max_ucast_filters);
- bool mc = is_multicast_ether_addr(addr);
struct ionic_rx_filter *f;
+ int nfilters;
int err = 0;
- memcpy(ctx.cmd.rx_filter_add.mac.addr, addr, ETH_ALEN);
+ ctx.cmd.rx_filter_add = *ac;
+ ctx.cmd.rx_filter_add.opcode = IONIC_CMD_RX_FILTER_ADD,
+ ctx.cmd.rx_filter_add.lif_index = cpu_to_le16(lif->index),
spin_lock_bh(&lif->rx_filters.lock);
f = ionic_rx_filter_find(lif, &ctx.cmd.rx_filter_add);
@@ -338,37 +335,53 @@ int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr)
if (err)
return err;
- netdev_dbg(lif->netdev, "rx_filter add ADDR %pM\n", addr);
-
/* Don't bother with the write to FW if we know there's no room,
* we can try again on the next sync attempt.
*/
- if ((lif->nucast + lif->nmcast) >= nfilters)
- err = -ENOSPC;
- else
+ switch (le16_to_cpu(ctx.cmd.rx_filter_add.match)) {
+ case IONIC_RX_FILTER_MATCH_MAC:
+ netdev_dbg(lif->netdev, "%s: rx_filter add ADDR %pM\n",
+ __func__, ctx.cmd.rx_filter_add.mac.addr);
+ nfilters = le32_to_cpu(lif->identity->eth.max_ucast_filters);
+ if ((lif->nucast + lif->nmcast) >= nfilters)
+ err = -ENOSPC;
+ break;
+ }
+
+ if (err != -ENOSPC)
err = ionic_adminq_post_wait(lif, &ctx);
spin_lock_bh(&lif->rx_filters.lock);
+
if (err && err != -EEXIST) {
/* set the state back to NEW so we can try again later */
f = ionic_rx_filter_find(lif, &ctx.cmd.rx_filter_add);
if (f && f->state == IONIC_FILTER_STATE_SYNCED) {
f->state = IONIC_FILTER_STATE_NEW;
- set_bit(IONIC_LIF_F_FILTER_SYNC_NEEDED, lif->state);
+
+ /* If -ENOSPC we won't waste time trying to sync again
+ * until there is a delete that might make room
+ */
+ if (err != -ENOSPC)
+ set_bit(IONIC_LIF_F_FILTER_SYNC_NEEDED, lif->state);
}
spin_unlock_bh(&lif->rx_filters.lock);
if (err == -ENOSPC)
return 0;
- else
- return err;
+
+ return err;
}
- if (mc)
- lif->nmcast++;
- else
- lif->nucast++;
+ switch (le16_to_cpu(ctx.cmd.rx_filter_add.match)) {
+ case IONIC_RX_FILTER_MATCH_MAC:
+ if (is_multicast_ether_addr(ctx.cmd.rx_filter_add.mac.addr))
+ lif->nmcast++;
+ else
+ lif->nucast++;
+ break;
+ }
f = ionic_rx_filter_find(lif, &ctx.cmd.rx_filter_add);
if (f && f->state == IONIC_FILTER_STATE_OLD) {
@@ -389,6 +402,17 @@ int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr)
return err;
}
+int ionic_lif_addr_add(struct ionic_lif *lif, const u8 *addr)
+{
+ struct ionic_rx_filter_add_cmd ac = {
+ .match = cpu_to_le16(IONIC_RX_FILTER_MATCH_MAC),
+ };
+
+ memcpy(&ac.mac.addr, addr, ETH_ALEN);
+
+ return ionic_lif_filter_add(lif, &ac);
+}
+
int ionic_lif_addr_del(struct ionic_lif *lif, const u8 *addr)
{
struct ionic_admin_ctx ctx = {
@@ -493,7 +517,7 @@ void ionic_rx_filter_sync(struct ionic_lif *lif)
}
list_for_each_entry_safe(sync_item, spos, &sync_add_list, list) {
- (void)ionic_lif_addr_add(lif, sync_item->f.cmd.mac.addr);
+ (void)ionic_lif_filter_add(lif, &sync_item->f.cmd);
list_del(&sync_item->list);
devm_kfree(dev, sync_item);
--
2.17.1
next prev parent reply other threads:[~2021-10-09 18:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-09 18:45 [PATCH net-next 0/9] ionic: add vlanid overflow management Shannon Nelson
2021-10-09 18:45 ` [PATCH net-next 1/9] ionic: add filterlist to debugfs Shannon Nelson
2021-10-09 18:45 ` [PATCH net-next 2/9] ionic: move lif mac address functions Shannon Nelson
2021-10-09 18:45 ` [PATCH net-next 3/9] ionic: remove mac overflow flags Shannon Nelson
2021-10-09 18:45 ` [PATCH net-next 4/9] ionic: add generic filter search Shannon Nelson
2021-10-09 18:45 ` Shannon Nelson [this message]
2021-10-09 18:45 ` [PATCH net-next 6/9] ionic: generic filter delete Shannon Nelson
2021-10-09 18:45 ` [PATCH net-next 7/9] ionic: handle vlan id overflow Shannon Nelson
2021-10-09 18:45 ` [PATCH net-next 8/9] ionic: allow adminq requests to override default error message Shannon Nelson
2021-10-09 18:45 ` [PATCH net-next 9/9] ionic: tame the filter no space message Shannon Nelson
2021-10-10 9:50 ` [PATCH net-next 0/9] ionic: add vlanid overflow management patchwork-bot+netdevbpf
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=20211009184523.73154-6-snelson@pensando.io \
--to=snelson@pensando.io \
--cc=davem@davemloft.net \
--cc=drivers@pensando.io \
--cc=jtoppins@redhat.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).