* [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later
@ 2025-08-16 19:53 Daniel Golle
2025-08-21 16:40 ` Sverdlin, Alexander
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Golle @ 2025-08-16 19:53 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Hauke Mehrtens, Simon Horman,
Russell King, Florian Fainelli, Arkadi Sharshevsky, linux-kernel,
netdev
Cc: Andreas Schirm, Lukas Stockmann, Alexander Sverdlin,
Peter Christen, Avinash Jayaraman, Bing tao Xu, Liang Xu,
Juraj Povazanec, Fanni (Fang-Yi) Chan, Benny (Ying-Tsan) Weng,
Livia M. Rosu, John Crispin
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@makrotopia.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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later
2025-08-16 19:53 [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later Daniel Golle
@ 2025-08-21 16:40 ` Sverdlin, Alexander
2025-08-21 17:03 ` Andrew Lunn
0 siblings, 1 reply; 4+ messages in thread
From: Sverdlin, Alexander @ 2025-08-21 16:40 UTC (permalink / raw)
To: hauke@hauke-m.de, olteanv@gmail.com, davem@davemloft.net,
andrew@lunn.ch, linux@armlinux.org.uk,
linux-kernel@vger.kernel.org, arkadis@mellanox.com,
daniel@makrotopia.org, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, f.fainelli@gmail.com, horms@kernel.org,
netdev@vger.kernel.org
Cc: john@phrozen.org, Stockmann, Lukas, yweng@maxlinear.com,
fchan@maxlinear.com, lxu@maxlinear.com, jpovazanec@maxlinear.com,
Schirm, Andreas, Christen, Peter, ajayaraman@maxlinear.com,
bxu@maxlinear.com, lrosu@maxlinear.com
Hi Daniel,
On Sat, 2025-08-16 at 20:53 +0100, Daniel Golle wrote:
> 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.
...
> @@ -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;
Would it be possible to leave this chunk unchanged (and all array
dereferencing in the driver as well)?
> @@ -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);
maybe sizeof(*priv->vlans) or sizeof(priv->vlans[0])?
> --- a/drivers/net/dsa/lantiq_gswip.h
> +++ b/drivers/net/dsa/lantiq_gswip.h
> @@ -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)[];
... if this would be just "struct gswip_vlan *vlans;"?
> + unsigned int num_vlans;
> int num_gphy_fw;
> struct gswip_gphy_fw *gphy_fw;
> u32 port_vlan_filter;
--
Alexander Sverdlin
Siemens AG
www.siemens.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later
2025-08-21 16:40 ` Sverdlin, Alexander
@ 2025-08-21 17:03 ` Andrew Lunn
2025-08-21 17:43 ` Daniel Golle
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2025-08-21 17:03 UTC (permalink / raw)
To: Sverdlin, Alexander
Cc: hauke@hauke-m.de, olteanv@gmail.com, davem@davemloft.net,
linux@armlinux.org.uk, linux-kernel@vger.kernel.org,
arkadis@mellanox.com, daniel@makrotopia.org, kuba@kernel.org,
pabeni@redhat.com, edumazet@google.com, f.fainelli@gmail.com,
horms@kernel.org, netdev@vger.kernel.org, john@phrozen.org,
Stockmann, Lukas, yweng@maxlinear.com, fchan@maxlinear.com,
lxu@maxlinear.com, jpovazanec@maxlinear.com, Schirm, Andreas,
Christen, Peter, ajayaraman@maxlinear.com, bxu@maxlinear.com,
lrosu@maxlinear.com
> > @@ -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)[];
>
> ... if this would be just "struct gswip_vlan *vlans;"?
Could it be moved to the end of the structure and made into an
flexible array?
Andrew
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later
2025-08-21 17:03 ` Andrew Lunn
@ 2025-08-21 17:43 ` Daniel Golle
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Golle @ 2025-08-21 17:43 UTC (permalink / raw)
To: Andrew Lunn
Cc: Sverdlin, Alexander, hauke@hauke-m.de, olteanv@gmail.com,
davem@davemloft.net, linux@armlinux.org.uk,
linux-kernel@vger.kernel.org, arkadis@mellanox.com,
kuba@kernel.org, pabeni@redhat.com, edumazet@google.com,
f.fainelli@gmail.com, horms@kernel.org, netdev@vger.kernel.org,
john@phrozen.org, Stockmann, Lukas, yweng@maxlinear.com,
fchan@maxlinear.com, lxu@maxlinear.com, jpovazanec@maxlinear.com,
Schirm, Andreas, Christen, Peter, ajayaraman@maxlinear.com,
bxu@maxlinear.com, lrosu@maxlinear.com
On Thu, Aug 21, 2025 at 07:03:35PM +0200, Andrew Lunn wrote:
> > > @@ -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)[];
> >
> > ... if this would be just "struct gswip_vlan *vlans;"?
>
> Could it be moved to the end of the structure and made into an
> flexible array?
I agree that it would be nice to get rid of the additional indirection,
I will implement it as flexible array when we arrive there (ie. after
both series of preparations have been merged).
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-08-21 17:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-16 19:53 [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later Daniel Golle
2025-08-21 16:40 ` Sverdlin, Alexander
2025-08-21 17:03 ` Andrew Lunn
2025-08-21 17:43 ` Daniel Golle
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).