linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support
@ 2025-06-03 20:48 Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365 Álvaro Fernández Rojas
                   ` (9 more replies)
  0 siblings, 10 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

These patches get the BCM5325 switch working with b53.

I'm not really sure that everything here is correct since I don't work for
Broadcom and all this is based on the public datasheet available for the
BCM5325 and my own experiments with a Huawei HG556a (BCM6358).

 v2: introduce changes requested by Jonas, Florian and Vladimir:
  - Add b53_arl_to_entry_25 function.
  - Add b53_arl_from_entry_25 function.
  - Add b53_arl_read_25 function, fixing usage of ARLTBL_VALID_25 and
    ARLTBL_VID_MASK_25.
  - Change b53_set_forwarding function flow.
  - Disallow BR_LEARNING on b53_br_flags_pre() for BCM5325.
  - Drop rate control registers.
  - Move B53_PD_MODE_CTRL_25 to b53_setup_port().

Florian Fainelli (1):
  net: dsa: b53: add support for FDB operations on 5325/5365

Álvaro Fernández Rojas (9):
  net: dsa: b53: prevent FAST_AGE access on BCM5325
  net: dsa: b53: prevent SWITCH_CTRL access on BCM5325
  net: dsa: b53: fix IP_MULTICAST_CTRL on BCM5325
  net: dsa: b53: prevent DIS_LEARNING access on BCM5325
  net: dsa: b53: prevent BRCM_HDR access on BCM5325
  net: dsa: b53: prevent GMII_PORT_OVERRIDE_CTRL access on BCM5325
  net: dsa: b53: fix unicast/multicast flooding on BCM5325
  net: dsa: b53: fix b53_imp_vlan_setup for BCM5325
  net: dsa: b53: ensure BCM5325 PHYs are enabled

 drivers/net/dsa/b53/b53_common.c | 255 ++++++++++++++++++++++++-------
 drivers/net/dsa/b53/b53_priv.h   |  29 ++++
 drivers/net/dsa/b53/b53_regs.h   |  24 ++-
 3 files changed, 250 insertions(+), 58 deletions(-)

-- 
2.39.5


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-03 22:10   ` Florian Fainelli
  2025-06-03 20:48 ` [RFC PATCH net-next v2 02/10] net: dsa: b53: prevent FAST_AGE access on BCM5325 Álvaro Fernández Rojas
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Florian Fainelli, Álvaro Fernández Rojas

From: Florian Fainelli <f.fainelli@gmail.com>

BCM5325 and BCM5365 are part of a much older generation of switches which,
due to their limited number of ports and VLAN entries (up to 256) allowed
a single 64-bit register to hold a full ARL entry.
This requires a little bit of massaging when reading, writing and
converting ARL entries in both directions.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 104 +++++++++++++++++++++++++------
 drivers/net/dsa/b53/b53_priv.h   |  29 +++++++++
 drivers/net/dsa/b53/b53_regs.h   |   7 ++-
 3 files changed, 117 insertions(+), 23 deletions(-)

 v2: add changes requested by Jonas and fix proposed by Florian:
  - Add b53_arl_to_entry_25 function.
  - Add b53_arl_from_entry_25 function.
  - Add b53_arl_read_25 function, fixing usage of ARLTBL_VALID_25 and
    ARLTBL_VID_MASK_25.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 132683ed3abe6..feea531732c7b 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1781,6 +1781,45 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,
 	return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT;
 }
 
+static int b53_arl_read_25(struct b53_device *dev, u64 mac,
+			   u16 vid, struct b53_arl_entry *ent, u8 *idx)
+{
+	DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES);
+	unsigned int i;
+	int ret;
+
+	ret = b53_arl_op_wait(dev);
+	if (ret)
+		return ret;
+
+	bitmap_zero(free_bins, dev->num_arl_bins);
+
+	/* Read the bins */
+	for (i = 0; i < dev->num_arl_bins; i++) {
+		u64 mac_vid;
+
+		b53_read64(dev, B53_ARLIO_PAGE,
+			   B53_ARLTBL_MAC_VID_ENTRY(i), &mac_vid);
+
+		b53_arl_to_entry_25(ent, mac_vid);
+
+		if (!(mac_vid & ARLTBL_VALID_25)) {
+			set_bit(i, free_bins);
+			continue;
+		}
+		if ((mac_vid & ARLTBL_MAC_MASK) != mac)
+			continue;
+		if (dev->vlan_enabled &&
+		    ((mac_vid >> ARLTBL_VID_S_65) & ARLTBL_VID_MASK_25) != vid)
+			continue;
+		*idx = i;
+		return 0;
+	}
+
+	*idx = find_first_bit(free_bins, dev->num_arl_bins);
+	return *idx >= dev->num_arl_bins ? -ENOSPC : -ENOENT;
+}
+
 static int b53_arl_op(struct b53_device *dev, int op, int port,
 		      const unsigned char *addr, u16 vid, bool is_valid)
 {
@@ -1795,14 +1834,18 @@ 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 (!is5325(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);
 	if (ret)
 		return ret;
 
-	ret = b53_arl_read(dev, mac, vid, &ent, &idx);
+	if (is5325(dev) || is5365(dev))
+		ret = b53_arl_read_25(dev, mac, vid, &ent, &idx);
+	else
+		ret = b53_arl_read(dev, mac, vid, &ent, &idx);
 
 	/* If this is a read, just finish now */
 	if (op)
@@ -1846,12 +1889,17 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
 	ent.is_static = true;
 	ent.is_age = false;
 	memcpy(ent.mac, addr, ETH_ALEN);
-	b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
+	if (is5325(dev) || is5365(dev))
+		b53_arl_from_entry_25(&mac_vid, &ent);
+	else
+		b53_arl_from_entry(&mac_vid, &fwd_entry, &ent);
 
 	b53_write64(dev, B53_ARLIO_PAGE,
 		    B53_ARLTBL_MAC_VID_ENTRY(idx), mac_vid);
-	b53_write32(dev, B53_ARLIO_PAGE,
-		    B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
+
+	if (!is5325(dev) && !is5365(dev))
+		b53_write32(dev, B53_ARLIO_PAGE,
+			    B53_ARLTBL_DATA_ENTRY(idx), fwd_entry);
 
 	return b53_arl_rw_op(dev, 0);
 }
@@ -1863,12 +1911,6 @@ int b53_fdb_add(struct dsa_switch *ds, int port,
 	struct b53_device *priv = ds->priv;
 	int ret;
 
-	/* 5325 and 5365 require some more massaging, but could
-	 * be supported eventually
-	 */
-	if (is5325(priv) || is5365(priv))
-		return -EOPNOTSUPP;
-
 	mutex_lock(&priv->arl_mutex);
 	ret = b53_arl_op(priv, 0, port, addr, vid, true);
 	mutex_unlock(&priv->arl_mutex);
@@ -1895,10 +1937,15 @@ EXPORT_SYMBOL(b53_fdb_del);
 static int b53_arl_search_wait(struct b53_device *dev)
 {
 	unsigned int timeout = 1000;
-	u8 reg;
+	u8 reg, offset;
+
+	if (is5325(dev) || is5365(dev))
+		offset = B53_ARL_SRCH_CTL_25;
+	else
+		offset = B53_ARL_SRCH_CTL;
 
 	do {
-		b53_read8(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, &reg);
+		b53_read8(dev, B53_ARLIO_PAGE, offset, &reg);
 		if (!(reg & ARL_SRCH_STDN))
 			return 0;
 
@@ -1915,13 +1962,24 @@ static void b53_arl_search_rd(struct b53_device *dev, u8 idx,
 			      struct b53_arl_entry *ent)
 {
 	u64 mac_vid;
-	u32 fwd_entry;
 
-	b53_read64(dev, B53_ARLIO_PAGE,
-		   B53_ARL_SRCH_RSTL_MACVID(idx), &mac_vid);
-	b53_read32(dev, B53_ARLIO_PAGE,
-		   B53_ARL_SRCH_RSTL(idx), &fwd_entry);
-	b53_arl_to_entry(ent, mac_vid, fwd_entry);
+	if (is5325(dev)) {
+		b53_read64(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_RSTL_0_MACVID_25,
+			   &mac_vid);
+		b53_arl_to_entry_25(ent, mac_vid);
+	} else if (is5365(dev)) {
+		b53_read64(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_RSTL_0_MACVID_65,
+			   &mac_vid);
+		b53_arl_to_entry_25(ent, mac_vid);
+	} else {
+		u32 fwd_entry;
+
+		b53_read64(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_RSTL_MACVID(idx),
+			   &mac_vid);
+		b53_read32(dev, B53_ARLIO_PAGE, B53_ARL_SRCH_RSTL(idx),
+			   &fwd_entry);
+		b53_arl_to_entry(ent, mac_vid, fwd_entry);
+	}
 }
 
 static int b53_fdb_copy(int port, const struct b53_arl_entry *ent,
@@ -1942,14 +2000,20 @@ int b53_fdb_dump(struct dsa_switch *ds, int port,
 	struct b53_device *priv = ds->priv;
 	struct b53_arl_entry results[2];
 	unsigned int count = 0;
+	u8 offset;
 	int ret;
 	u8 reg;
 
 	mutex_lock(&priv->arl_mutex);
 
+	if (is5325(priv) || is5365(priv))
+		offset = B53_ARL_SRCH_CTL_25;
+	else
+		offset = B53_ARL_SRCH_CTL;
+
 	/* Start search operation */
 	reg = ARL_SRCH_STDN;
-	b53_write8(priv, B53_ARLIO_PAGE, B53_ARL_SRCH_CTL, reg);
+	b53_write8(priv, offset, B53_ARL_SRCH_CTL, reg);
 
 	do {
 		ret = b53_arl_search_wait(priv);
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index a5ef7071ba07b..2238eef2a8771 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h
@@ -298,6 +298,19 @@ static inline void b53_arl_to_entry(struct b53_arl_entry *ent,
 	ent->vid = mac_vid >> ARLTBL_VID_S;
 }
 
+static inline void b53_arl_to_entry_25(struct b53_arl_entry *ent,
+				       u64 mac_vid)
+{
+	memset(ent, 0, sizeof(*ent));
+	ent->port = (mac_vid >> ARLTBL_DATA_PORT_ID_S_25) &
+		     ARLTBL_DATA_PORT_ID_MASK_25;
+	ent->is_valid = !!(mac_vid & ARLTBL_VALID_25);
+	ent->is_age = !!(mac_vid & ARLTBL_AGE_25);
+	ent->is_static = !!(mac_vid & ARLTBL_STATIC_25);
+	u64_to_ether_addr(mac_vid, ent->mac);
+	ent->vid = mac_vid >> ARLTBL_VID_S_65;
+}
+
 static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
 				      const struct b53_arl_entry *ent)
 {
@@ -312,6 +325,22 @@ static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
 		*fwd_entry |= ARLTBL_AGE;
 }
 
+static inline void b53_arl_from_entry_25(u64 *mac_vid,
+					 const struct b53_arl_entry *ent)
+{
+	*mac_vid = ether_addr_to_u64(ent->mac);
+	*mac_vid |= (u64)(ent->port & ARLTBL_DATA_PORT_ID_MASK_25) <<
+			  ARLTBL_DATA_PORT_ID_S_25;
+	*mac_vid |= (u64)(ent->vid & ARLTBL_VID_MASK_25) <<
+			  ARLTBL_VID_S_65;
+	if (ent->is_valid)
+		*mac_vid |= ARLTBL_VALID_25;
+	if (ent->is_static)
+		*mac_vid |= ARLTBL_STATIC_25;
+	if (ent->is_age)
+		*mac_vid |= ARLTBL_AGE_25;
+}
+
 #ifdef CONFIG_BCM47XX
 
 #include <linux/bcm47xx_nvram.h>
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index 1fbc5a204bc72..1f15332fb2a7c 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -324,9 +324,10 @@
 #define   ARLTBL_VID_MASK		0xfff
 #define   ARLTBL_DATA_PORT_ID_S_25	48
 #define   ARLTBL_DATA_PORT_ID_MASK_25	0xf
-#define   ARLTBL_AGE_25			BIT(61)
-#define   ARLTBL_STATIC_25		BIT(62)
-#define   ARLTBL_VALID_25		BIT(63)
+#define   ARLTBL_VID_S_65		53
+#define   ARLTBL_AGE_25			BIT_ULL(61)
+#define   ARLTBL_STATIC_25		BIT_ULL(62)
+#define   ARLTBL_VALID_25		BIT_ULL(63)
 
 /* ARL Table Data Entry N Registers (32 bit) */
 #define B53_ARLTBL_DATA_ENTRY(n)	((0x10 * (n)) + 0x18)
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 02/10] net: dsa: b53: prevent FAST_AGE access on BCM5325
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365 Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 03/10] net: dsa: b53: prevent SWITCH_CTRL " Álvaro Fernández Rojas
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

BCM5325 doesn't implement FAST_AGE registers so we should avoid reading or
writing them.

Fixes: 967dd82ffc52 ("net: dsa: b53: Add support for Broadcom RoboSwitch")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 9 +++++++++
 1 file changed, 9 insertions(+)

 v2: no changes.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index feea531732c7b..525306193f80e 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -486,6 +486,9 @@ static int b53_flush_arl(struct b53_device *dev, u8 mask)
 {
 	unsigned int i;
 
+	if (is5325(dev))
+		return 0;
+
 	b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_CTRL,
 		   FAST_AGE_DONE | FAST_AGE_DYNAMIC | mask);
 
@@ -510,6 +513,9 @@ static int b53_flush_arl(struct b53_device *dev, u8 mask)
 
 static int b53_fast_age_port(struct b53_device *dev, int port)
 {
+	if (is5325(dev))
+		return 0;
+
 	b53_write8(dev, B53_CTRL_PAGE, B53_FAST_AGE_PORT_CTRL, port);
 
 	return b53_flush_arl(dev, FAST_AGE_PORT);
@@ -517,6 +523,9 @@ static int b53_fast_age_port(struct b53_device *dev, int port)
 
 static int b53_fast_age_vlan(struct b53_device *dev, u16 vid)
 {
+	if (is5325(dev))
+		return 0;
+
 	b53_write16(dev, B53_CTRL_PAGE, B53_FAST_AGE_VID_CTRL, vid);
 
 	return b53_flush_arl(dev, FAST_AGE_VLAN);
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 03/10] net: dsa: b53: prevent SWITCH_CTRL access on BCM5325
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365 Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 02/10] net: dsa: b53: prevent FAST_AGE access on BCM5325 Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 04/10] net: dsa: b53: fix IP_MULTICAST_CTRL " Álvaro Fernández Rojas
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

BCM5325 doesn't implement SWITCH_CTRL register so we should avoid reading
or writing it.

Fixes: a424f0de6163 ("net: dsa: b53: Include IMP/CPU port in dumb forwarding mode")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 drivers/net/dsa/b53/b53_common.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

 v2: no changes

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 525306193f80e..1e47ef9f6fb88 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -360,11 +360,12 @@ static void b53_set_forwarding(struct b53_device *dev, int enable)
 
 	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_MODE, mgmt);
 
-	/* Include IMP port in dumb forwarding mode
-	 */
-	b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt);
-	mgmt |= B53_MII_DUMB_FWDG_EN;
-	b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
+	if (!is5325(dev)) {
+		/* Include IMP port in dumb forwarding mode */
+		b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt);
+		mgmt |= B53_MII_DUMB_FWDG_EN;
+		b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
+	}
 
 	/* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether
 	 * frames should be flooded or not.
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 04/10] net: dsa: b53: fix IP_MULTICAST_CTRL on BCM5325
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
                   ` (2 preceding siblings ...)
  2025-06-03 20:48 ` [RFC PATCH net-next v2 03/10] net: dsa: b53: prevent SWITCH_CTRL " Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 05/10] net: dsa: b53: prevent DIS_LEARNING access " Álvaro Fernández Rojas
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

BCM5325 doesn't implement B53_UC_FWD_EN, B53_MC_FWD_EN or B53_IPMC_FWD_EN.

Fixes: 53568438e381 ("net: dsa: b53: Add support for port_egress_floods callback")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 18 +++++++++++-------
 drivers/net/dsa/b53/b53_regs.h   |  1 +
 2 files changed, 12 insertions(+), 7 deletions(-)

 v2: add changes proposed by Jonas:
  - Change b53_set_forwarding function flow.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 1e47ef9f6fb88..f1e82a0e84ea9 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -365,14 +365,18 @@ static void b53_set_forwarding(struct b53_device *dev, int enable)
 		b53_read8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, &mgmt);
 		mgmt |= B53_MII_DUMB_FWDG_EN;
 		b53_write8(dev, B53_CTRL_PAGE, B53_SWITCH_CTRL, mgmt);
-	}
 
-	/* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether
-	 * frames should be flooded or not.
-	 */
-	b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt);
-	mgmt |= B53_UC_FWD_EN | B53_MC_FWD_EN | B53_IPMC_FWD_EN;
-	b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt);
+		/* Look at B53_UC_FWD_EN and B53_MC_FWD_EN to decide whether
+		 * frames should be flooded or not.
+		 */
+		b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt);
+		mgmt |= B53_UC_FWD_EN | B53_MC_FWD_EN | B53_IPMC_FWD_EN;
+		b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt);
+	} else {
+		b53_read8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, &mgmt);
+		mgmt |= B53_IP_MCAST_25;
+		b53_write8(dev, B53_CTRL_PAGE, B53_IP_MULTICAST_CTRL, mgmt);
+	}
 }
 
 static void b53_enable_vlan(struct b53_device *dev, int port, bool enable,
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index 1f15332fb2a7c..896684d7f5947 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -106,6 +106,7 @@
 
 /* IP Multicast control (8 bit) */
 #define B53_IP_MULTICAST_CTRL		0x21
+#define  B53_IP_MCAST_25		BIT(0)
 #define  B53_IPMC_FWD_EN		BIT(1)
 #define  B53_UC_FWD_EN			BIT(6)
 #define  B53_MC_FWD_EN			BIT(7)
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 05/10] net: dsa: b53: prevent DIS_LEARNING access on BCM5325
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
                   ` (3 preceding siblings ...)
  2025-06-03 20:48 ` [RFC PATCH net-next v2 04/10] net: dsa: b53: fix IP_MULTICAST_CTRL " Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 06/10] net: dsa: b53: prevent BRCM_HDR " Álvaro Fernández Rojas
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

BCM5325 doesn't implement DIS_LEARNING register so we should avoid reading
or writing it.

Fixes: f9b3827ee66c ("net: dsa: b53: Support setting learning on port")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

 v2: add changes proposed by Vladimir:
  - Disallow BR_LEARNING on b53_br_flags_pre() for BCM5325.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index f1e82a0e84ea9..143c213a1992c 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -592,6 +592,9 @@ static void b53_port_set_learning(struct b53_device *dev, int port,
 {
 	u16 reg;
 
+	if (is5325(dev))
+		return;
+
 	b53_read16(dev, B53_CTRL_PAGE, B53_DIS_LEARNING, &reg);
 	if (learning)
 		reg &= ~BIT(port);
@@ -2264,7 +2267,13 @@ int b53_br_flags_pre(struct dsa_switch *ds, int port,
 		     struct switchdev_brport_flags flags,
 		     struct netlink_ext_ack *extack)
 {
-	if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_LEARNING))
+	struct b53_device *dev = ds->priv;
+	unsigned long mask = (BR_FLOOD | BR_MCAST_FLOOD);
+
+	if (!is5325(dev))
+		mask |= BR_LEARNING;
+
+	if (flags.mask & ~mask)
 		return -EINVAL;
 
 	return 0;
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 06/10] net: dsa: b53: prevent BRCM_HDR access on BCM5325
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
                   ` (4 preceding siblings ...)
  2025-06-03 20:48 ` [RFC PATCH net-next v2 05/10] net: dsa: b53: prevent DIS_LEARNING access " Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-04 18:05   ` Jonas Gorski
  2025-06-03 20:48 ` [RFC PATCH net-next v2 07/10] net: dsa: b53: prevent GMII_PORT_OVERRIDE_CTRL " Álvaro Fernández Rojas
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

BCM5325 doesn't implement BRCM_HDR register so we should avoid reading or
writing it.

Fixes: b409a9efa183 ("net: dsa: b53: Move Broadcom header setup to b53")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 drivers/net/dsa/b53/b53_common.c | 4 ++++
 1 file changed, 4 insertions(+)

 v2: no changes.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 143c213a1992c..693a44150395e 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -729,6 +729,10 @@ void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
 		hdr_ctl |= GC_FRM_MGMT_PORT_M;
 	b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl);
 
+	/* B53_BRCM_HDR not present on BCM5325 */
+	if (is5325(dev))
+		return;
+
 	/* Enable Broadcom tags for IMP port */
 	b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl);
 	if (tag_en)
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 07/10] net: dsa: b53: prevent GMII_PORT_OVERRIDE_CTRL access on BCM5325
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
                   ` (5 preceding siblings ...)
  2025-06-03 20:48 ` [RFC PATCH net-next v2 06/10] net: dsa: b53: prevent BRCM_HDR " Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 08/10] net: dsa: b53: fix unicast/multicast flooding " Álvaro Fernández Rojas
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

BCM5325 doesn't implement GMII_PORT_OVERRIDE_CTRL register so we should
avoid reading or writing it.
PORT_OVERRIDE_RX_FLOW and PORT_OVERRIDE_TX_FLOW aren't defined on BCM5325
and we should use PORT_OVERRIDE_LP_FLOW_25 instead.

Fixes: 5e004460f874 ("net: dsa: b53: Add helper to set link parameters")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 drivers/net/dsa/b53/b53_common.c | 21 +++++++++++++++++----
 drivers/net/dsa/b53/b53_regs.h   |  1 +
 2 files changed, 18 insertions(+), 4 deletions(-)

 v2: no changes.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 693a44150395e..4cee69f29cf8d 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1277,6 +1277,8 @@ static void b53_force_link(struct b53_device *dev, int port, int link)
 	if (port == dev->imp_port) {
 		off = B53_PORT_OVERRIDE_CTRL;
 		val = PORT_OVERRIDE_EN;
+	} else if (is5325(dev)) {
+		return;
 	} else {
 		off = B53_GMII_PORT_OVERRIDE_CTRL(port);
 		val = GMII_PO_EN;
@@ -1301,6 +1303,8 @@ static void b53_force_port_config(struct b53_device *dev, int port,
 	if (port == dev->imp_port) {
 		off = B53_PORT_OVERRIDE_CTRL;
 		val = PORT_OVERRIDE_EN;
+	} else if (is5325(dev)) {
+		return;
 	} else {
 		off = B53_GMII_PORT_OVERRIDE_CTRL(port);
 		val = GMII_PO_EN;
@@ -1331,10 +1335,19 @@ static void b53_force_port_config(struct b53_device *dev, int port,
 		return;
 	}
 
-	if (rx_pause)
-		reg |= PORT_OVERRIDE_RX_FLOW;
-	if (tx_pause)
-		reg |= PORT_OVERRIDE_TX_FLOW;
+	if (rx_pause) {
+		if (is5325(dev))
+			reg |= PORT_OVERRIDE_LP_FLOW_25;
+		else
+			reg |= PORT_OVERRIDE_RX_FLOW;
+	}
+
+	if (tx_pause) {
+		if (is5325(dev))
+			reg |= PORT_OVERRIDE_LP_FLOW_25;
+		else
+			reg |= PORT_OVERRIDE_TX_FLOW;
+	}
 
 	b53_write8(dev, B53_CTRL_PAGE, off, reg);
 }
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index 896684d7f5947..ab15f36a135a8 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -95,6 +95,7 @@
 #define   PORT_OVERRIDE_SPEED_10M	(0 << PORT_OVERRIDE_SPEED_S)
 #define   PORT_OVERRIDE_SPEED_100M	(1 << PORT_OVERRIDE_SPEED_S)
 #define   PORT_OVERRIDE_SPEED_1000M	(2 << PORT_OVERRIDE_SPEED_S)
+#define   PORT_OVERRIDE_LP_FLOW_25	BIT(3) /* BCM5325 only */
 #define   PORT_OVERRIDE_RV_MII_25	BIT(4) /* BCM5325 only */
 #define   PORT_OVERRIDE_RX_FLOW		BIT(4)
 #define   PORT_OVERRIDE_TX_FLOW		BIT(5)
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 08/10] net: dsa: b53: fix unicast/multicast flooding on BCM5325
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
                   ` (6 preceding siblings ...)
  2025-06-03 20:48 ` [RFC PATCH net-next v2 07/10] net: dsa: b53: prevent GMII_PORT_OVERRIDE_CTRL " Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 09/10] net: dsa: b53: fix b53_imp_vlan_setup for BCM5325 Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 10/10] net: dsa: b53: ensure BCM5325 PHYs are enabled Álvaro Fernández Rojas
  9 siblings, 0 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

BCM5325 doesn't implement UC_FLOOD_MASK, MC_FLOOD_MASK and IPMC_FLOOD_MASK
registers.
This has to be handled differently with other pages and registers.

Fixes: a8b659e7ff75 ("net: dsa: act as passthrough for bridge port flags")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 60 ++++++++++++++++++++++----------
 drivers/net/dsa/b53/b53_regs.h   | 13 +++++++
 2 files changed, 55 insertions(+), 18 deletions(-)

 v2: add changes proposed by Jonas:
  - Drop rate control registers.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 4cee69f29cf8d..d7148f0657563 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -559,12 +559,24 @@ static void b53_port_set_ucast_flood(struct b53_device *dev, int port,
 {
 	u16 uc;
 
-	b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc);
-	if (unicast)
-		uc |= BIT(port);
-	else
-		uc &= ~BIT(port);
-	b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc);
+	if (is5325(dev)) {
+		if (port == B53_CPU_PORT_25)
+			port = B53_CPU_PORT;
+
+		b53_read16(dev, B53_IEEE_PAGE, B53_IEEE_UCAST_DLF, &uc);
+		if (unicast)
+			uc |= BIT(port) | B53_IEEE_UCAST_DROP_EN;
+		else
+			uc &= ~BIT(port);
+		b53_write16(dev, B53_IEEE_PAGE, B53_IEEE_UCAST_DLF, uc);
+	} else {
+		b53_read16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, &uc);
+		if (unicast)
+			uc |= BIT(port);
+		else
+			uc &= ~BIT(port);
+		b53_write16(dev, B53_CTRL_PAGE, B53_UC_FLOOD_MASK, uc);
+	}
 }
 
 static void b53_port_set_mcast_flood(struct b53_device *dev, int port,
@@ -572,19 +584,31 @@ static void b53_port_set_mcast_flood(struct b53_device *dev, int port,
 {
 	u16 mc;
 
-	b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc);
-	if (multicast)
-		mc |= BIT(port);
-	else
-		mc &= ~BIT(port);
-	b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc);
+	if (is5325(dev)) {
+		if (port == B53_CPU_PORT_25)
+			port = B53_CPU_PORT;
 
-	b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc);
-	if (multicast)
-		mc |= BIT(port);
-	else
-		mc &= ~BIT(port);
-	b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc);
+		b53_read16(dev, B53_IEEE_PAGE, B53_IEEE_MCAST_DLF, &mc);
+		if (multicast)
+			mc |= BIT(port) | B53_IEEE_MCAST_DROP_EN;
+		else
+			mc &= ~BIT(port);
+		b53_write16(dev, B53_IEEE_PAGE, B53_IEEE_MCAST_DLF, mc);
+	} else {
+		b53_read16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, &mc);
+		if (multicast)
+			mc |= BIT(port);
+		else
+			mc &= ~BIT(port);
+		b53_write16(dev, B53_CTRL_PAGE, B53_MC_FLOOD_MASK, mc);
+
+		b53_read16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, &mc);
+		if (multicast)
+			mc |= BIT(port);
+		else
+			mc &= ~BIT(port);
+		b53_write16(dev, B53_CTRL_PAGE, B53_IPMC_FLOOD_MASK, mc);
+	}
 }
 
 static void b53_port_set_learning(struct b53_device *dev, int port,
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index ab15f36a135a8..d6849cf6b0a3a 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -29,6 +29,7 @@
 #define B53_ARLIO_PAGE			0x05 /* ARL Access */
 #define B53_FRAMEBUF_PAGE		0x06 /* Management frame access */
 #define B53_MEM_ACCESS_PAGE		0x08 /* Memory access */
+#define B53_IEEE_PAGE			0x0a /* IEEE 802.1X */
 
 /* PHY Registers */
 #define B53_PORT_MII_PAGE(i)		(0x10 + (i)) /* Port i MII Registers */
@@ -368,6 +369,18 @@
 #define B53_ARL_SRCH_RSTL_MACVID(x)	(B53_ARL_SRCH_RSTL_0_MACVID + ((x) * 0x10))
 #define B53_ARL_SRCH_RSTL(x)		(B53_ARL_SRCH_RSTL_0 + ((x) * 0x10))
 
+/*************************************************************************
+ * IEEE 802.1X Registers
+ *************************************************************************/
+
+/* Multicast DLF Drop Control register (16 bit) */
+#define B53_IEEE_MCAST_DLF		0x94
+#define B53_IEEE_MCAST_DROP_EN		BIT(11)
+
+/* Unicast DLF Drop Control register (16 bit) */
+#define B53_IEEE_UCAST_DLF		0x96
+#define B53_IEEE_UCAST_DROP_EN		BIT(11)
+
 /*************************************************************************
  * Port VLAN Registers
  *************************************************************************/
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 09/10] net: dsa: b53: fix b53_imp_vlan_setup for BCM5325
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
                   ` (7 preceding siblings ...)
  2025-06-03 20:48 ` [RFC PATCH net-next v2 08/10] net: dsa: b53: fix unicast/multicast flooding " Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-03 20:48 ` [RFC PATCH net-next v2 10/10] net: dsa: b53: ensure BCM5325 PHYs are enabled Álvaro Fernández Rojas
  9 siblings, 0 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

CPU port should be B53_CPU_PORT instead of B53_CPU_PORT_25 for
B53_PVLAN_PORT_MASK register.

Fixes: ff39c2d68679 ("net: dsa: b53: Add bridge support")
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 4 ++++
 1 file changed, 4 insertions(+)

 v2: no changes.

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index d7148f0657563..a9b19451ffb30 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -542,6 +542,10 @@ void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
 	unsigned int i;
 	u16 pvlan;
 
+	/* BCM5325 CPU port is at 8 */
+	if ((is5325(dev) || is5365(dev)) && cpu_port == B53_CPU_PORT_25)
+		cpu_port = B53_CPU_PORT;
+
 	/* Enable the IMP port to be in the same VLAN as the other ports
 	 * on a per-port basis such that we only have Port i and IMP in
 	 * the same VLAN.
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH net-next v2 10/10] net: dsa: b53: ensure BCM5325 PHYs are enabled
  2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
                   ` (8 preceding siblings ...)
  2025-06-03 20:48 ` [RFC PATCH net-next v2 09/10] net: dsa: b53: fix b53_imp_vlan_setup for BCM5325 Álvaro Fernández Rojas
@ 2025-06-03 20:48 ` Álvaro Fernández Rojas
  2025-06-04 18:20   ` Florian Fainelli
  9 siblings, 1 reply; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-03 20:48 UTC (permalink / raw)
  To: jonas.gorski, florian.fainelli, andrew, olteanv, davem, edumazet,
	kuba, pabeni, vivien.didelot, netdev, linux-kernel, dgcbueu
  Cc: Álvaro Fernández Rojas

According to the datasheet, BCM5325 uses B53_PD_MODE_CTRL_25 register to
disable clocking to individual PHYs.
Only ports 1-4 can be enabled or disabled and the datasheet is explicit
about not toggling BIT(0) since it disables the PLL power and the switch.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 13 +++++++++++++
 drivers/net/dsa/b53/b53_regs.h   |  2 ++
 2 files changed, 15 insertions(+)

 v2: add changes requested by Florian:
  - Move B53_PD_MODE_CTRL_25 to b53_setup_port().

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index a9b19451ffb30..38c08f6278d27 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -659,6 +659,19 @@ int b53_setup_port(struct dsa_switch *ds, int port)
 	if (dsa_is_user_port(ds, port))
 		b53_set_eap_mode(dev, port, EAP_MODE_SIMPLIFIED);
 
+	if (is5325(dev) &&
+	    (port >= B53_PD_MODE_PORT_MIN) &&
+	    (port <= B53_PD_MODE_PORT_MAX)) {
+		u8 reg;
+
+		b53_read8(dev, B53_CTRL_PAGE, B53_PD_MODE_CTRL_25, &reg);
+		if (dsa_is_unused_port(ds, port))
+			reg |= BIT(port);
+		else
+			reg &= ~BIT(port);
+		b53_write8(dev, B53_CTRL_PAGE, B53_PD_MODE_CTRL_25, reg);
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL(b53_setup_port);
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index d6849cf6b0a3a..880c67130a9fc 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -105,6 +105,8 @@
 
 /* Power-down mode control */
 #define B53_PD_MODE_CTRL_25		0x0f
+#define  B53_PD_MODE_PORT_MIN		1
+#define  B53_PD_MODE_PORT_MAX		4
 
 /* IP Multicast control (8 bit) */
 #define B53_IP_MULTICAST_CTRL		0x21
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365
  2025-06-03 20:48 ` [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365 Álvaro Fernández Rojas
@ 2025-06-03 22:10   ` Florian Fainelli
  2025-06-04  6:32     ` Jonas Gorski
  0 siblings, 1 reply; 16+ messages in thread
From: Florian Fainelli @ 2025-06-03 22:10 UTC (permalink / raw)
  To: Álvaro Fernández Rojas, jonas.gorski, florian.fainelli,
	andrew, olteanv, davem, edumazet, kuba, pabeni, vivien.didelot,
	netdev, linux-kernel, dgcbueu

On 6/3/25 13:48, Álvaro Fernández Rojas wrote:
> From: Florian Fainelli <f.fainelli@gmail.com>
> 
> BCM5325 and BCM5365 are part of a much older generation of switches which,
> due to their limited number of ports and VLAN entries (up to 256) allowed
> a single 64-bit register to hold a full ARL entry.
> This requires a little bit of massaging when reading, writing and
> converting ARL entries in both directions.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> ---

[snip]

>   static int b53_arl_op(struct b53_device *dev, int op, int port,
>   		      const unsigned char *addr, u16 vid, bool is_valid)
>   {
> @@ -1795,14 +1834,18 @@ 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 (!is5325(dev))
> +		b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);

I used the 5325M-DS113-RDS datasheet for this code initially but the 
5325E-DS14-R datasheet shows that this register is defined. It's not 
clear to me how to differentiate the two kinds of switches. The 5325M 
would report itself as:

0x00406330

in the integrated PHY PHYSID1/2 registers, whereas a 5325E would report 
itself as 0x0143bc30. Maybe we can use that to key off the very first 
generation 5325 switches?
-- 
Florian


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365
  2025-06-03 22:10   ` Florian Fainelli
@ 2025-06-04  6:32     ` Jonas Gorski
  2025-06-11  7:55       ` Álvaro Fernández Rojas
  0 siblings, 1 reply; 16+ messages in thread
From: Jonas Gorski @ 2025-06-04  6:32 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Álvaro Fernández Rojas, andrew, olteanv, davem,
	edumazet, kuba, pabeni, vivien.didelot, netdev, linux-kernel,
	dgcbueu

On Wed, Jun 4, 2025 at 12:10 AM Florian Fainelli
<florian.fainelli@broadcom.com> wrote:
>
> On 6/3/25 13:48, Álvaro Fernández Rojas wrote:
> > From: Florian Fainelli <f.fainelli@gmail.com>
> >
> > BCM5325 and BCM5365 are part of a much older generation of switches which,
> > due to their limited number of ports and VLAN entries (up to 256) allowed
> > a single 64-bit register to hold a full ARL entry.
> > This requires a little bit of massaging when reading, writing and
> > converting ARL entries in both directions.
> >
> > Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> > Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> > ---
>
> [snip]
>
> >   static int b53_arl_op(struct b53_device *dev, int op, int port,
> >                     const unsigned char *addr, u16 vid, bool is_valid)
> >   {
> > @@ -1795,14 +1834,18 @@ 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 (!is5325(dev))
> > +             b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
>
> I used the 5325M-DS113-RDS datasheet for this code initially but the
> 5325E-DS14-R datasheet shows that this register is defined. It's not
> clear to me how to differentiate the two kinds of switches. The 5325M
> would report itself as:
>
> 0x00406330
>
> in the integrated PHY PHYSID1/2 registers, whereas a 5325E would report
> itself as 0x0143bc30. Maybe we can use that to key off the very first
> generation 5325 switches?

According to the product brief and other documents BCM5325M does not
support 802.1Q VLANs, which would explain the missing register
descriptions. It does have 2k ARL entries compared to 1k for the 5325E
though, so I now see where that value comes from.

If it really doesn't support 802.1Q, then checking if related
registers are writable might also work.

Jonas

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC PATCH net-next v2 06/10] net: dsa: b53: prevent BRCM_HDR access on BCM5325
  2025-06-03 20:48 ` [RFC PATCH net-next v2 06/10] net: dsa: b53: prevent BRCM_HDR " Álvaro Fernández Rojas
@ 2025-06-04 18:05   ` Jonas Gorski
  0 siblings, 0 replies; 16+ messages in thread
From: Jonas Gorski @ 2025-06-04 18:05 UTC (permalink / raw)
  To: Álvaro Fernández Rojas
  Cc: florian.fainelli, andrew, olteanv, davem, edumazet, kuba, pabeni,
	vivien.didelot, netdev, linux-kernel, dgcbueu

On Tue, Jun 3, 2025 at 10:49 PM Álvaro Fernández Rojas
<noltari@gmail.com> wrote:
>
> BCM5325 doesn't implement BRCM_HDR register so we should avoid reading or
> writing it.
>
> Fixes: b409a9efa183 ("net: dsa: b53: Move Broadcom header setup to b53")
> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
> ---
>  drivers/net/dsa/b53/b53_common.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
>  v2: no changes.
>
> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index 143c213a1992c..693a44150395e 100644
> --- a/drivers/net/dsa/b53/b53_common.c
> +++ b/drivers/net/dsa/b53/b53_common.c
> @@ -729,6 +729,10 @@ void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
>                 hdr_ctl |= GC_FRM_MGMT_PORT_M;
>         b53_write8(dev, B53_MGMT_PAGE, B53_GLOBAL_CONFIG, hdr_ctl);
>
> +       /* B53_BRCM_HDR not present on BCM5325 */
> +       if (is5325(dev))

I think this can/should be replaced with a check for dev->tag_protocol
being DSA_TAG_PROTO_BRCM_LEGACY, as there is AFAICT a strong
correlation between the legacy header being used and the B53_BRCM_HDR
register not existing.

Regards,
Jonas

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC PATCH net-next v2 10/10] net: dsa: b53: ensure BCM5325 PHYs are enabled
  2025-06-03 20:48 ` [RFC PATCH net-next v2 10/10] net: dsa: b53: ensure BCM5325 PHYs are enabled Álvaro Fernández Rojas
@ 2025-06-04 18:20   ` Florian Fainelli
  0 siblings, 0 replies; 16+ messages in thread
From: Florian Fainelli @ 2025-06-04 18:20 UTC (permalink / raw)
  To: Álvaro Fernández Rojas, jonas.gorski, florian.fainelli,
	andrew, olteanv, davem, edumazet, kuba, pabeni, vivien.didelot,
	netdev, linux-kernel, dgcbueu

On 6/3/25 13:48, Álvaro Fernández Rojas wrote:
> According to the datasheet, BCM5325 uses B53_PD_MODE_CTRL_25 register to
> disable clocking to individual PHYs.
> Only ports 1-4 can be enabled or disabled and the datasheet is explicit
> about not toggling BIT(0) since it disables the PLL power and the switch.
 > > Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> ---
>   drivers/net/dsa/b53/b53_common.c | 13 +++++++++++++
>   drivers/net/dsa/b53/b53_regs.h   |  2 ++
>   2 files changed, 15 insertions(+)
> 
>   v2: add changes requested by Florian:
>    - Move B53_PD_MODE_CTRL_25 to b53_setup_port().
> 
> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index a9b19451ffb30..38c08f6278d27 100644
> --- a/drivers/net/dsa/b53/b53_common.c
> +++ b/drivers/net/dsa/b53/b53_common.c
> @@ -659,6 +659,19 @@ int b53_setup_port(struct dsa_switch *ds, int port)
>   	if (dsa_is_user_port(ds, port))
>   		b53_set_eap_mode(dev, port, EAP_MODE_SIMPLIFIED);
>   
> +	if (is5325(dev) &&
> +	    (port >= B53_PD_MODE_PORT_MIN) &&
> +	    (port <= B53_PD_MODE_PORT_MAX)) {

This would be a candidate for the in_range() helper?
-- 
Florian


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365
  2025-06-04  6:32     ` Jonas Gorski
@ 2025-06-11  7:55       ` Álvaro Fernández Rojas
  0 siblings, 0 replies; 16+ messages in thread
From: Álvaro Fernández Rojas @ 2025-06-11  7:55 UTC (permalink / raw)
  To: Jonas Gorski
  Cc: Florian Fainelli, andrew, olteanv, davem, edumazet, kuba, pabeni,
	vivien.didelot, netdev, linux-kernel, dgcbueu

El mié, 4 jun 2025 a las 8:32, Jonas Gorski (<jonas.gorski@gmail.com>) escribió:
>
> On Wed, Jun 4, 2025 at 12:10 AM Florian Fainelli
> <florian.fainelli@broadcom.com> wrote:
> >
> > On 6/3/25 13:48, Álvaro Fernández Rojas wrote:
> > > From: Florian Fainelli <f.fainelli@gmail.com>
> > >
> > > BCM5325 and BCM5365 are part of a much older generation of switches which,
> > > due to their limited number of ports and VLAN entries (up to 256) allowed
> > > a single 64-bit register to hold a full ARL entry.
> > > This requires a little bit of massaging when reading, writing and
> > > converting ARL entries in both directions.
> > >
> > > Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> > > Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
> > > ---
> >
> > [snip]
> >
> > >   static int b53_arl_op(struct b53_device *dev, int op, int port,
> > >                     const unsigned char *addr, u16 vid, bool is_valid)
> > >   {
> > > @@ -1795,14 +1834,18 @@ 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 (!is5325(dev))
> > > +             b53_write16(dev, B53_ARLIO_PAGE, B53_VLAN_ID_IDX, vid);
> >
> > I used the 5325M-DS113-RDS datasheet for this code initially but the
> > 5325E-DS14-R datasheet shows that this register is defined. It's not
> > clear to me how to differentiate the two kinds of switches. The 5325M
> > would report itself as:
> >
> > 0x00406330
> >
> > in the integrated PHY PHYSID1/2 registers, whereas a 5325E would report
> > itself as 0x0143bc30. Maybe we can use that to key off the very first
> > generation 5325 switches?
>
> According to the product brief and other documents BCM5325M does not
> support 802.1Q VLANs, which would explain the missing register
> descriptions. It does have 2k ARL entries compared to 1k for the 5325E
> though, so I now see where that value comes from.
>
> If it really doesn't support 802.1Q, then checking if related
> registers are writable might also work.

Considering that I don't have access to a 5325M in order to properly
test it, I prefer the solution proposed by Florian.

I've implemented it in the following branch:
https://github.com/Noltari/linux/commits/b53-bcm5325-v3/
https://github.com/Noltari/linux/commit/e2d3d541ac421bbb5d2fc783e07fda26b105d1a5

I will wait a bit just in case there are some comments for the
recently submitted v2 of the dsa tag patches and then I will merge
both sets of patches into one since your proposed change of checking
the tag protocol for the BRCM_HDR register access requires having the
new legacy FCS tag.

>
> Jonas

Best regards,
Álvaro.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-06-11  7:56 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-03 20:48 [RFC PATCH net-next v2 00/10] net: dsa: b53: fix BCM5325 support Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 01/10] net: dsa: b53: add support for FDB operations on 5325/5365 Álvaro Fernández Rojas
2025-06-03 22:10   ` Florian Fainelli
2025-06-04  6:32     ` Jonas Gorski
2025-06-11  7:55       ` Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 02/10] net: dsa: b53: prevent FAST_AGE access on BCM5325 Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 03/10] net: dsa: b53: prevent SWITCH_CTRL " Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 04/10] net: dsa: b53: fix IP_MULTICAST_CTRL " Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 05/10] net: dsa: b53: prevent DIS_LEARNING access " Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 06/10] net: dsa: b53: prevent BRCM_HDR " Álvaro Fernández Rojas
2025-06-04 18:05   ` Jonas Gorski
2025-06-03 20:48 ` [RFC PATCH net-next v2 07/10] net: dsa: b53: prevent GMII_PORT_OVERRIDE_CTRL " Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 08/10] net: dsa: b53: fix unicast/multicast flooding " Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 09/10] net: dsa: b53: fix b53_imp_vlan_setup for BCM5325 Álvaro Fernández Rojas
2025-06-03 20:48 ` [RFC PATCH net-next v2 10/10] net: dsa: b53: ensure BCM5325 PHYs are enabled Álvaro Fernández Rojas
2025-06-04 18:20   ` Florian Fainelli

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).