mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Álvaro Fernández Rojas" <noltari@gmail.com>
To: jonas.gorski@gmail.com, florian.fainelli@broadcom.com,
	andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	horms@kernel.org, vivien.didelot@gmail.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	dgcbueu@gmail.com
Cc: "Álvaro Fernández Rojas" <noltari@gmail.com>
Subject: [PATCH net-next v4 04/14] net: dsa: b53: detect BCM5325 variants
Date: Sat, 14 Jun 2025 09:59:50 +0200	[thread overview]
Message-ID: <20250614080000.1884236-5-noltari@gmail.com> (raw)
In-Reply-To: <20250614080000.1884236-1-noltari@gmail.com>

We need to be able to differentiate the BCM5325 variants because:
- BCM5325M switches lack the ARLIO_PAGE->VLAN_ID_IDX register.
- BCM5325E have less 512 ARL buckets instead of 1024.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 24 +++++++++++++++++++++---
 drivers/net/dsa/b53/b53_priv.h   | 19 +++++++++++++++++++
 2 files changed, 40 insertions(+), 3 deletions(-)

 v4: add changes requested by Jonas and other improvements:
  - Introduce variant_id field in b53_device.
  - Reduce number of ARL buckets for BCM5325E.
  - Disable ARLIO_PAGE->VLAN_ID_IDX access for BCM5325M.

 v3: detect BCM5325 variants as requested by Florian.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 9a038992f043..a7c75f44369a 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1778,7 +1778,8 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
 
 	/* Perform a read for the given MAC and VID */
 	b53_write48(dev, B53_ARLIO_PAGE, B53_MAC_ADDR_IDX, mac);
-	b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
+	if (!is5325m(dev))
+		b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
 
 	/* Issue a read operation for this MAC */
 	ret = b53_arl_rw_op(dev, 1);
@@ -2833,6 +2834,9 @@ static int b53_switch_init(struct b53_device *dev)
 		}
 	}
 
+	if (is5325e(dev))
+		dev->num_arl_buckets = 512;
+
 	dev->num_ports = fls(dev->enabled_ports);
 
 	dev->ds->num_ports = min_t(unsigned int, dev->num_ports, DSA_MAX_PORTS);
@@ -2934,10 +2938,24 @@ int b53_switch_detect(struct b53_device *dev)
 		b53_write16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, 0xf);
 		b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_TABLE_ACCESS_25, &tmp);
 
-		if (tmp == 0xf)
+		if (tmp == 0xf) {
+			u32 phy_id;
+			int val;
+
 			dev->chip_id = BCM5325_DEVICE_ID;
-		else
+
+			val = b53_phy_read16(dev->ds, 0, MII_PHYSID1);
+			phy_id = (val & 0xffff) << 16;
+			val = b53_phy_read16(dev->ds, 0, MII_PHYSID2);
+			phy_id |= (val & 0xfff0);
+
+			if (phy_id == 0x00406330)
+				dev->variant_id = B53_VARIANT_5325M;
+			else if (phy_id == 0x0143bc30)
+				dev->variant_id = B53_VARIANT_5325E;
+		} else {
 			dev->chip_id = BCM5365_DEVICE_ID;
+		}
 		break;
 	case BCM5389_DEVICE_ID:
 	case BCM5395_DEVICE_ID:
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index a5ef7071ba07..e8689410b5d0 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h
@@ -84,6 +84,12 @@ enum {
 	BCM53134_DEVICE_ID = 0x5075,
 };
 
+enum b53_variant_id {
+	B53_VARIANT_NONE = 0,
+	B53_VARIANT_5325E,
+	B53_VARIANT_5325M,
+};
+
 struct b53_pcs {
 	struct phylink_pcs pcs;
 	struct b53_device *dev;
@@ -118,6 +124,7 @@ struct b53_device {
 
 	/* chip specific data */
 	u32 chip_id;
+	enum b53_variant_id variant_id;
 	u8 core_rev;
 	u8 vta_regs[3];
 	u8 duplex_reg;
@@ -165,6 +172,18 @@ static inline int is5325(struct b53_device *dev)
 	return dev->chip_id == BCM5325_DEVICE_ID;
 }
 
+static inline int is5325e(struct b53_device *dev)
+{
+	return is5325(dev) &&
+		dev->variant_id == B53_VARIANT_5325E;
+}
+
+static inline int is5325m(struct b53_device *dev)
+{
+	return is5325(dev) &&
+		dev->variant_id == B53_VARIANT_5325M;
+}
+
 static inline int is5365(struct b53_device *dev)
 {
 #ifdef CONFIG_BCM47XX
-- 
2.39.5


  parent reply	other threads:[~2025-06-14  8:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-14  7:59 [PATCH net-next v4 00/14] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
2025-06-14  7:59 ` [PATCH net-next v4 01/14] net: dsa: tag_brcm: legacy: reorganize functions Álvaro Fernández Rojas
2025-06-14  7:59 ` [PATCH net-next v4 02/14] net: dsa: tag_brcm: add support for legacy FCS tags Álvaro Fernández Rojas
2025-06-17 16:09   ` Florian Fainelli
2025-06-14  7:59 ` [PATCH net-next v4 03/14] net: dsa: b53: support " Álvaro Fernández Rojas
2025-06-14  7:59 ` Álvaro Fernández Rojas [this message]
2025-06-17 16:10   ` [PATCH net-next v4 04/14] net: dsa: b53: detect BCM5325 variants Florian Fainelli
2025-06-14  7:59 ` [PATCH net-next v4 05/14] net: dsa: b53: add support for FDB operations on 5325/5365 Álvaro Fernández Rojas
2025-06-14  7:59 ` [PATCH net-next v4 06/14] net: dsa: b53: prevent FAST_AGE access on BCM5325 Álvaro Fernández Rojas
2025-06-17 16:10   ` Florian Fainelli
2025-06-14  7:59 ` [PATCH net-next v4 07/14] net: dsa: b53: prevent SWITCH_CTRL " Álvaro Fernández Rojas
2025-06-14  7:59 ` [PATCH net-next v4 08/14] net: dsa: b53: fix IP_MULTICAST_CTRL " Álvaro Fernández Rojas
2025-06-14  7:59 ` [PATCH net-next v4 09/14] net: dsa: b53: prevent DIS_LEARNING access " Álvaro Fernández Rojas
2025-06-14  7:59 ` [PATCH net-next v4 10/14] net: dsa: b53: prevent BRCM_HDR access on older devices Álvaro Fernández Rojas
2025-06-14  7:59 ` [PATCH net-next v4 11/14] net: dsa: b53: prevent GMII_PORT_OVERRIDE_CTRL access on BCM5325 Álvaro Fernández Rojas
2025-06-14  7:59 ` [PATCH net-next v4 12/14] net: dsa: b53: fix unicast/multicast flooding " Álvaro Fernández Rojas
2025-06-17 16:18   ` Florian Fainelli
2025-06-14  7:59 ` [PATCH net-next v4 13/14] net: dsa: b53: fix b53_imp_vlan_setup for BCM5325 Álvaro Fernández Rojas
2025-06-14  8:00 ` [PATCH net-next v4 14/14] net: dsa: b53: ensure BCM5325 PHYs are enabled Álvaro Fernández Rojas
2025-06-17 16:11   ` Florian Fainelli
2025-06-18  0:56 ` [PATCH net-next v4 00/14] net: dsa: b53: fix BCM5325 support Jakub Kicinski
2025-06-18  1:00 ` 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=20250614080000.1884236-5-noltari@gmail.com \
    --to=noltari@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dgcbueu@gmail.com \
    --cc=edumazet@google.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=horms@kernel.org \
    --cc=jonas.gorski@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=vivien.didelot@gmail.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

all inboxes | Powered by JetHome®