From: Daniel Golle <daniel@makrotopia.org>
To: Hauke Mehrtens <hauke@hauke-m.de>, Andrew Lunn <andrew@lunn.ch>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Arkadi Sharshevsky <arkadis@mellanox.com>,
Florian Fainelli <f.fainelli@gmail.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Andreas Schirm <andreas.schirm@siemens.com>,
Alexander Sverdlin <alexander.sverdlin@siemens.com>,
Lukas Stockmann <lukas.stockmann@siemens.com>,
John Crispin <john@phrozen.org>
Subject: [PATCH/RFC net] net: dsa: lantiq_gswip: honor dsa_db passed to port_fdb_{add,del}
Date: Sat, 9 Aug 2025 23:35:28 +0100 [thread overview]
Message-ID: <aJfNMLNoi1VOsPrN@pidgin.makrotopia.org> (raw)
Commit c9eb3e0f8701 ("net: dsa: Add support for learning FDB through
notification") added a dev_close() call "to indicate inconsistent
situation" when we could not delete an FDB entry from the port. In case
of the lantiq_gswip driver this is problematic on standalone ports for
which all calls to either .port_fdb_add() or .port_fdb_del() would just
always return -EINVAL as adding or removing FDB entries is currently
only supported for ports which are a member of a bridge.
As since commit c26933639b54 ("net: dsa: request drivers to perform FDB
isolation") the dsa_db is passed to the .port_fdb_add() or
.port_fdb_del() calls we can use that to set the FID accordingly,
similar to how it was for bridge ports, and to FID 0 for standalone
ports. In order for FID 0 to work at all we also need to set bit 1 in
val[1], so always set it.
This solution was found in a downstream driver provided by MaxLinear
(which is the current owner of the former Lantiq switch IP) under
GPL-2.0. Import the implementation and the copyright headers from that
driver.
Fixes: c9eb3e0f8701 ("net: dsa: Add support for learning FDB through notification")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/net/dsa/lantiq_gswip.c | 55 ++++++++++++++++++++--------------
1 file changed, 33 insertions(+), 22 deletions(-)
diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 6eb3140d4044..fed86b2d78fc 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -2,9 +2,11 @@
/*
* Lantiq / Intel GSWIP switch driver for VRX200, xRX300 and xRX330 SoCs
*
- * Copyright (C) 2010 Lantiq Deutschland
- * Copyright (C) 2012 John Crispin <john@phrozen.org>
+ * Copyright (C) 2023 - 2024 MaxLinear Inc.
+ * Copyright (C) 2022 Snap One, LLC. All rights reserved.
* Copyright (C) 2017 - 2019 Hauke Mehrtens <hauke@hauke-m.de>
+ * Copyright (C) 2012 John Crispin <john@phrozen.org>
+ * Copyright (C) 2010 Lantiq Deutschland
*
* The VLAN and bridge model the GSWIP hardware uses does not directly
* matches the model DSA uses.
@@ -239,6 +241,7 @@
#define GSWIP_TABLE_MAC_BRIDGE_KEY3_FID GENMASK(5, 0) /* Filtering identifier */
#define GSWIP_TABLE_MAC_BRIDGE_VAL0_PORT GENMASK(7, 4) /* Port on learned entries */
#define GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC BIT(0) /* Static, non-aging entry */
+#define GSWIP_TABLE_MAC_BRIDGE_VAL1_VALID BIT(1) /* Valid bit */
#define XRX200_GPHY_FW_ALIGN (16 * 1024)
@@ -1349,30 +1352,37 @@ static void gswip_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
}
static int gswip_port_fdb(struct dsa_switch *ds, int port,
- const unsigned char *addr, u16 vid, bool add)
+ const unsigned char *addr, u16 vid, struct dsa_db db,
+ bool add)
{
- struct net_device *bridge = dsa_port_bridge_dev_get(dsa_to_port(ds, port));
struct gswip_priv *priv = ds->priv;
struct gswip_pce_table_entry mac_bridge = {0,};
- unsigned int max_ports = priv->hw_info->max_ports;
int fid = -1;
- int i;
int err;
+ int i;
- if (!bridge)
- return -EINVAL;
-
- for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
- if (priv->vlans[i].bridge == bridge) {
- fid = priv->vlans[i].fid;
- break;
+ switch (db.type) {
+ case DSA_DB_BRIDGE:
+ for (i = 0; i < ARRAY_SIZE(priv->vlans); i++) {
+ if (priv->vlans[i].bridge == db.bridge.dev) {
+ fid = priv->vlans[i].fid;
+ break;
+ }
}
- }
-
- if (fid == -1) {
- dev_err(priv->dev, "no FID found for bridge %s\n",
- bridge->name);
- return -EINVAL;
+ if (fid == -1) {
+ dev_err(priv->dev, "Port %d not part of a bridge\n", port);
+ return -EINVAL;
+ }
+ break;
+ case DSA_DB_PORT:
+ if (dsa_is_cpu_port(ds, port) &&
+ dsa_fdb_present_in_other_db(ds, port, addr, vid, db))
+ return 0;
+ /* FID of a standalone / single port bridge */
+ fid = 0;
+ break;
+ default:
+ return -EOPNOTSUPP;
}
mac_bridge.table = GSWIP_TABLE_MAC_BRIDGE;
@@ -1382,7 +1392,8 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port,
mac_bridge.key[2] = addr[1] | (addr[0] << 8);
mac_bridge.key[3] = FIELD_PREP(GSWIP_TABLE_MAC_BRIDGE_KEY3_FID, fid);
mac_bridge.val[0] = add ? BIT(port) : 0; /* port map */
- mac_bridge.val[1] = GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC;
+ mac_bridge.val[1] = add ? (GSWIP_TABLE_MAC_BRIDGE_VAL1_STATIC |
+ GSWIP_TABLE_MAC_BRIDGE_VAL1_VALID) : 0;
mac_bridge.valid = add;
err = gswip_pce_table_entry_write(priv, &mac_bridge);
@@ -1396,14 +1407,14 @@ static int gswip_port_fdb_add(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid,
struct dsa_db db)
{
- return gswip_port_fdb(ds, port, addr, vid, true);
+ return gswip_port_fdb(ds, port, addr, vid, db, true);
}
static int gswip_port_fdb_del(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid,
struct dsa_db db)
{
- return gswip_port_fdb(ds, port, addr, vid, false);
+ return gswip_port_fdb(ds, port, addr, vid, db, false);
}
static int gswip_port_fdb_dump(struct dsa_switch *ds, int port,
--
2.50.1
next reply other threads:[~2025-08-09 23:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-09 22:35 Daniel Golle [this message]
2025-08-10 13:06 ` [PATCH/RFC net] net: dsa: lantiq_gswip: honor dsa_db passed to port_fdb_{add,del} Vladimir Oltean
2025-08-10 14:48 ` Daniel Golle
2025-08-10 16:32 ` Vladimir Oltean
2025-08-10 16:54 ` Daniel Golle
2025-08-10 21:02 ` Vladimir Oltean
2025-08-11 15:32 ` Vladimir Oltean
2025-08-12 1:23 ` Daniel Golle
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=aJfNMLNoi1VOsPrN@pidgin.makrotopia.org \
--to=daniel@makrotopia.org \
--cc=alexander.sverdlin@siemens.com \
--cc=andreas.schirm@siemens.com \
--cc=andrew@lunn.ch \
--cc=arkadis@mellanox.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hauke@hauke-m.de \
--cc=john@phrozen.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.stockmann@siemens.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).