netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Golle <daniel@makrotopia.org>
To: 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>,
	Hauke Mehrtens <hauke@hauke-m.de>,
	Simon Horman <horms@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Arkadi Sharshevsky <arkadis@mellanox.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Andreas Schirm <andreas.schirm@siemens.com>,
	Lukas Stockmann <lukas.stockmann@siemens.com>,
	Alexander Sverdlin <alexander.sverdlin@siemens.com>,
	Peter Christen <peter.christen@siemens.com>,
	Avinash Jayaraman <ajayaraman@maxlinear.com>,
	Bing tao Xu <bxu@maxlinear.com>, Liang Xu <lxu@maxlinear.com>,
	Juraj Povazanec <jpovazanec@maxlinear.com>,
	"Fanni (Fang-Yi) Chan" <fchan@maxlinear.com>,
	"Benny (Ying-Tsan) Weng" <yweng@maxlinear.com>,
	"Livia M. Rosu" <lrosu@maxlinear.com>,
	John Crispin <john@phrozen.org>
Subject: [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later
Date: Sat, 16 Aug 2025 20:53:37 +0100	[thread overview]
Message-ID: <aKDhwYPptuC94u-f@pidgin.makrotopia.org> (raw)

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

             reply	other threads:[~2025-08-16 19:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-16 19:53 Daniel Golle [this message]
2025-08-21 16:40 ` [PATCH RFC net-next 12/23] net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later Sverdlin, Alexander
2025-08-21 17:03   ` Andrew Lunn
2025-08-21 17:43     ` 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=aKDhwYPptuC94u-f@pidgin.makrotopia.org \
    --to=daniel@makrotopia.org \
    --cc=ajayaraman@maxlinear.com \
    --cc=alexander.sverdlin@siemens.com \
    --cc=andreas.schirm@siemens.com \
    --cc=andrew@lunn.ch \
    --cc=arkadis@mellanox.com \
    --cc=bxu@maxlinear.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=fchan@maxlinear.com \
    --cc=hauke@hauke-m.de \
    --cc=horms@kernel.org \
    --cc=john@phrozen.org \
    --cc=jpovazanec@maxlinear.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=lrosu@maxlinear.com \
    --cc=lukas.stockmann@siemens.com \
    --cc=lxu@maxlinear.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=peter.christen@siemens.com \
    --cc=yweng@maxlinear.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).