[<prev] [next>] [day] [month] [year] [list]
Message-ID: <aKDhwYPptuC94u-f@pidgin.makrotopia.org>
Date: Sat, 16 Aug 2025 20:53:37 +0100
From: Daniel Golle <daniel@...rotopia.org>
To: Andrew Lunn <andrew@...n.ch>, Vladimir Oltean <olteanv@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Hauke Mehrtens <hauke@...ke-m.de>, Simon Horman <horms@...nel.org>,
Russell King <linux@...linux.org.uk>,
Florian Fainelli <f.fainelli@...il.com>,
Arkadi Sharshevsky <arkadis@...lanox.com>,
linux-kernel@...r.kernel.org, netdev@...r.kernel.org
Cc: Andreas Schirm <andreas.schirm@...mens.com>,
Lukas Stockmann <lukas.stockmann@...mens.com>,
Alexander Sverdlin <alexander.sverdlin@...mens.com>,
Peter Christen <peter.christen@...mens.com>,
Avinash Jayaraman <ajayaraman@...linear.com>,
Bing tao Xu <bxu@...linear.com>, Liang Xu <lxu@...linear.com>,
Juraj Povazanec <jpovazanec@...linear.com>,
"Fanni (Fang-Yi) Chan" <fchan@...linear.com>,
"Benny (Ying-Tsan) Weng" <yweng@...linear.com>,
"Livia M. Rosu" <lrosu@...linear.com>,
John Crispin <john@...ozen.org>
Subject: [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs
on API 2.2 or later
Dynamically allocate vlans array depending on the switch API version.
Versions less than 2.2 support 64 VLANs, versions 2.2 or later support
4096 VLANs.
Signed-off-by: Daniel Golle <daniel@...rotopia.org>
---
drivers/net/dsa/lantiq_gswip.c | 73 +++++++++++++++++++++++-----------
drivers/net/dsa/lantiq_gswip.h | 4 +-
2 files changed, 52 insertions(+), 25 deletions(-)
diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index cc8a65c173c9..5a5e85b1b32f 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -657,6 +657,11 @@ static int gswip_setup(struct dsa_switch *ds)
gswip_switch_mask(priv, 0, GSWIP_BM_QUEUE_GCTRL_GL_MOD,
GSWIP_BM_QUEUE_GCTRL);
+ if (GSWIP_VERSION_GE(priv, GSWIP_VERSION_2_2))
+ /* Enable VLANMD 2.2 for 4k VLANs entries */
+ gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_1_VLANMD,
+ GSWIP_PCE_GCTRL_1);
+
/* VLAN aware Switching */
gswip_switch_mask(priv, 0, GSWIP_PCE_GCTRL_0_VLAN, GSWIP_PCE_GCTRL_0);
@@ -700,8 +705,8 @@ static int gswip_vlan_active_create(struct gswip_priv *priv,
int i;
/* Look for a free slot */
- for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
- if (!priv->vlans[i].bridge) {
+ for (i = max_ports; i < priv->num_vlans; i++) {
+ if (!(*priv->vlans)[i].bridge) {
idx = i;
break;
}
@@ -725,9 +730,9 @@ static int gswip_vlan_active_create(struct gswip_priv *priv,
return err;
}
- priv->vlans[idx].bridge = bridge;
- priv->vlans[idx].vid = vid;
- priv->vlans[idx].fid = fid;
+ (*priv->vlans)[idx].bridge = bridge;
+ (*priv->vlans)[idx].vid = vid;
+ (*priv->vlans)[idx].fid = fid;
return idx;
}
@@ -743,7 +748,7 @@ static int gswip_vlan_active_remove(struct gswip_priv *priv, int idx)
err = gswip_pce_table_entry_write(priv, &vlan_active);
if (err)
dev_err(priv->dev, "failed to delete active VLAN: %d\n", err);
- priv->vlans[idx].bridge = NULL;
+ (*priv->vlans)[idx].bridge = NULL;
return err;
}
@@ -759,8 +764,8 @@ static int gswip_vlan_add_unaware(struct gswip_priv *priv,
int err;
/* Check if there is already a page for this bridge */
- for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
- if (priv->vlans[i].bridge == bridge) {
+ for (i = max_ports; i < priv->num_vlans; i++) {
+ if ((*priv->vlans)[i].bridge == bridge) {
idx = i;
break;
}
@@ -822,12 +827,12 @@ static int gswip_vlan_add_aware(struct gswip_priv *priv,
int err;
/* Check if there is already a page for this bridge */
- for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
- if (priv->vlans[i].bridge == bridge) {
- if (fid != -1 && fid != priv->vlans[i].fid)
+ for (i = max_ports; i < priv->num_vlans; i++) {
+ if ((*priv->vlans)[i].bridge == bridge) {
+ if (fid != -1 && fid != (*priv->vlans)[i].fid)
dev_err(priv->dev, "one bridge with multiple flow ids\n");
- fid = priv->vlans[i].fid;
- if (priv->vlans[i].vid == vid) {
+ fid = (*priv->vlans)[i].fid;
+ if ((*priv->vlans)[i].vid == vid) {
idx = i;
break;
}
@@ -894,9 +899,9 @@ static int gswip_vlan_remove(struct gswip_priv *priv,
int err;
/* Check if there is already a page for this bridge */
- for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
- if (priv->vlans[i].bridge == bridge &&
- (!vlan_aware || priv->vlans[i].vid == vid)) {
+ for (i = max_ports; i < priv->num_vlans; i++) {
+ if ((*priv->vlans)[i].bridge == bridge &&
+ (!vlan_aware || (*priv->vlans)[i].vid == vid)) {
idx = i;
break;
}
@@ -993,9 +998,9 @@ static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port,
return -EOPNOTSUPP;
/* Check if there is already a page for this VLAN */
- for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
- if (priv->vlans[i].bridge == bridge &&
- priv->vlans[i].vid == vlan->vid) {
+ for (i = max_ports; i < priv->num_vlans; i++) {
+ if ((*priv->vlans)[i].bridge == bridge &&
+ (*priv->vlans)[i].vid == vlan->vid) {
idx = i;
break;
}
@@ -1007,8 +1012,8 @@ static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port,
*/
if (idx == -1) {
/* Look for a free slot */
- for (; pos < ARRAY_SIZE(priv->vlans); pos++) {
- if (!priv->vlans[pos].bridge) {
+ for (; pos < priv->num_vlans; pos++) {
+ if (!(*priv->vlans)[pos].bridge) {
idx = pos;
pos++;
break;
@@ -1149,9 +1154,9 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port,
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;
+ for (i = 0; i < priv->num_vlans; i++) {
+ if ((*priv->vlans)[i].bridge == db.bridge.dev) {
+ fid = (*priv->vlans)[i].fid;
break;
}
}
@@ -1948,6 +1953,22 @@ static int gswip_validate_cpu_port(struct dsa_switch *ds)
return 0;
}
+static int gswip_allocate_vlans(struct gswip_priv *priv)
+{
+ if (GSWIP_VERSION_GE(priv, GSWIP_VERSION_2_2))
+ priv->num_vlans = 4096;
+ else
+ priv->num_vlans = 64;
+
+ priv->vlans = devm_kcalloc(priv->dev, priv->num_vlans,
+ sizeof((*priv->vlans)[0]), GFP_KERNEL);
+ if (!priv->vlans)
+ return dev_err_probe(priv->dev, -ENOMEM,
+ "VLAN allocation failed\n");
+
+ return 0;
+}
+
static int gswip_probe(struct platform_device *pdev)
{
struct device_node *np, *gphy_fw_np;
@@ -2024,6 +2045,10 @@ static int gswip_probe(struct platform_device *pdev)
goto gphy_fw_remove;
}
+ err = gswip_allocate_vlans(priv);
+ if (err)
+ goto gphy_fw_remove;
+
err = dsa_register_switch(priv->ds);
if (err) {
dev_err_probe(dev, err, "dsa switch registration failed\n");
diff --git a/drivers/net/dsa/lantiq_gswip.h b/drivers/net/dsa/lantiq_gswip.h
index 5c21618ca6f0..00a786d374b1 100644
--- a/drivers/net/dsa/lantiq_gswip.h
+++ b/drivers/net/dsa/lantiq_gswip.h
@@ -142,6 +142,7 @@
#define GSWIP_PCE_GCTRL_1 0x457
#define GSWIP_PCE_GCTRL_1_MAC_GLOCK BIT(2) /* MAC Address table lock */
#define GSWIP_PCE_GCTRL_1_MAC_GLOCK_MOD BIT(3) /* Mac address table lock forwarding mode */
+#define GSWIP_PCE_GCTRL_1_VLANMD BIT(9) /* VLAN MODE */
#define GSWIP_PCE_PCTRL_0p(p) (0x480 + ((p) * 0xA))
#define GSWIP_PCE_PCTRL_0_TVM BIT(5) /* Transparent VLAN mode */
#define GSWIP_PCE_PCTRL_0_VREP BIT(6) /* VLAN Replace Mode */
@@ -269,7 +270,8 @@ struct gswip_priv {
struct dsa_switch *ds;
struct device *dev;
struct regmap *rcu_regmap;
- struct gswip_vlan vlans[64];
+ struct gswip_vlan (*vlans)[];
+ unsigned int num_vlans;
int num_gphy_fw;
struct gswip_gphy_fw *gphy_fw;
u32 port_vlan_filter;
--
2.50.1
Powered by blists - more mailing lists