From: Lad Prabhakar <prab…@bp.renesas.com>
The RZ/T2H and RZ/N2H hardware manual requires
COMMAND_CONFIG_Pn.TX_ENA to remain set. Clearing this bit during
link-down handling or indirectly through CMD_CFG.SW_RESET during
setup violates this restriction.
Keep the MAC TX enable bit set and use PORT_ENA.TXENA to gate port
transmission instead. During setup, explicitly set TX_ENA while
disabling RX_ENA, so the invariant does not depend on the hardware
reset value. Account for both the administrative/STP state and link
state when updating PORT_ENA.TXENA, so that a link-up event does not
re-enable transmission on a port blocked by STP. Keep the CPU port
independent of link state.
Avoid CMD_CFG.SW_RESET during setup, as it also clears TX_ENA.
Since SW_RESET is also responsible for clearing the statistics
counters, pulse the switch reset line during probe to ensure the
hardware starts from a clean state.
Signed-off-by: Lad Prabhakar <prab…@bp.renesas.com>
---
v6:
- Added comment about TX_ENA being kept set on RZ/T2H
of patches
- In a5psw_setup, explicitly set TX_ENA while disabling RX_ENA
v5: https://lore.kernel.org/all/2026…@bp.renesas.com/
- New patch
---
drivers/net/dsa/rzn1_a5psw.c | 87 +++++++++++++++++++++++++++++++-----
drivers/net/dsa/rzn1_a5psw.h | 8 ++++
2 files changed, 83 insertions(+), 12 deletions(-)
diff --git a/drivers/net/dsa/rzn1_a5psw.c b/drivers/net/dsa/rzn1_a5psw.c
index 03d7f928e3e6..e4fd4425f52e 100644
--- a/drivers/net/dsa/rzn1_a5psw.c
+++ b/drivers/net/dsa/rzn1_a5psw.c
@@ -133,11 +133,20 @@ static void a5psw_set_learncount(struct a5psw *a5psw, u32 mode)
FIELD_PREP(A5PSW_LK_LEARNCOUNT_MODE, mode));
}
-static void a5psw_port_tx_enable(struct a5psw *a5psw, int port, bool enable)
+/* Must be called with reg_lock held */
+static void a5psw_port_tx_update(struct a5psw *a5psw, int port)
{
u32 mask = A5PSW_PORT_ENA_TX(port);
- u32 reg = enable ? mask : 0;
+ u32 reg;
+ reg = a5psw_reg_readl(a5psw, A5PSW_PORT_ENA) & ~mask;
+ if (a5psw->tx_allowed & a5psw->link_up & BIT(port))
+ reg |= mask;
+ a5psw_reg_writel(a5psw, A5PSW_PORT_ENA, reg);
+}
+
+static void a5psw_port_tx_enable(struct a5psw *a5psw, int port, bool enable)
+{
/* Even though the port TX is disabled through TXENA bit in the
* PORT_ENA register, it can still send BPDUs. This depends on the tag
* configuration added when sending packets from the CPU port to the
@@ -146,18 +155,38 @@ static void a5psw_port_tx_enable(struct a5psw *a5psw, int port, bool enable)
* This allows to implement STP support when ports are in a state where
* forwarding traffic should be stopped but BPDUs should still be sent.
*/
- a5psw_reg_rmw(a5psw, A5PSW_PORT_ENA, mask, reg);
+ spin_lock(&a5psw->reg_lock);
+
+ if (enable)
+ a5psw->tx_allowed |= BIT(port);
+ else
+ a5psw->tx_allowed &= ~BIT(port);
+
+ a5psw_port_tx_update(a5psw, port);
+
+ spin_unlock(&a5psw->reg_lock);
}
-static void a5psw_port_enable_set(struct a5psw *a5psw, int port, bool enable)
+static void a5psw_port_link_set(struct a5psw *a5psw, int port, bool up)
{
- u32 port_ena = 0;
+ spin_lock(&a5psw->reg_lock);
- if (enable)
- port_ena |= A5PSW_PORT_ENA_TX_RX(port);
+ if (up)
+ a5psw->link_up |= BIT(port);
+ else
+ a5psw->link_up &= ~BIT(port);
+
+ a5psw_port_tx_update(a5psw, port);
- a5psw_reg_rmw(a5psw, A5PSW_PORT_ENA, A5PSW_PORT_ENA_TX_RX(port),
- port_ena);
+ spin_unlock(&a5psw->reg_lock);
+}
+
+static void a5psw_port_enable_set(struct a5psw *a5psw, int port, bool enable)
+{
+ u32 rx_mask = BIT(port + A5PSW_PORT_ENA_RX_SHIFT);
+
+ a5psw_reg_rmw(a5psw, A5PSW_PORT_ENA, rx_mask, enable ? rx_mask : 0);
+ a5psw_port_tx_enable(a5psw, port, enable);
}
static int a5psw_lk_execute_ctrl(struct a5psw *a5psw, u32 *ctrl)
@@ -283,6 +312,15 @@ static void a5psw_phylink_mac_link_down(struct phylink_config *config,
int port = dp->index;
u32 cmd_cfg;
+ if (a5psw->of_data->keep_mac_tx_enabled) {
+ if (dsa_port_is_user(dp))
+ a5psw_port_link_set(a5psw, port, false);
+
+ a5psw_reg_rmw(a5psw, A5PSW_CMD_CFG(port),
+ A5PSW_CMD_CFG_RX_ENA, 0);
+ return;
+ }
+
cmd_cfg = a5psw_reg_readl(a5psw, A5PSW_CMD_CFG(port));
cmd_cfg &= ~(A5PSW_CMD_CFG_RX_ENA | A5PSW_CMD_CFG_TX_ENA);
a5psw_reg_writel(a5psw, A5PSW_CMD_CFG(port), cmd_cfg);
@@ -312,6 +350,9 @@ static void a5psw_phylink_mac_link_up(struct phylink_config *config,
cmd_cfg &= ~A5PSW_CMD_CFG_PAUSE_IGNORE;
a5psw_reg_writel(a5psw, A5PSW_CMD_CFG(dp->index), cmd_cfg);
+
+ if (a5psw->of_data->keep_mac_tx_enabled && dsa_port_is_user(dp))
+ a5psw_port_link_set(a5psw, dp->index, true);
}
static int a5psw_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
@@ -993,9 +1034,24 @@ static int a5psw_setup(struct dsa_switch *ds)
dsa_switch_for_each_port(dp, ds) {
port = dp->index;
- /* Reset the port */
- a5psw_reg_writel(a5psw, A5PSW_CMD_CFG(port),
- A5PSW_CMD_CFG_SW_RESET);
+ /* Gate TX on link state only for user ports */
+ if (!a5psw->of_data->keep_mac_tx_enabled || !dsa_port_is_user(dp))
+ a5psw->link_up |= BIT(port);
+
+ /*
+ * Writing CMD_CFG = SW_RESET also writes TX_ENA as 0, which
+ * must never happen on some SoCs. Their switch is reset through
+ * its reset line in probe, so the statistics are already
+ * cleared; only disable the MAC receive path and make sure
+ * TX_ENA is set.
+ */
+ if (a5psw->of_data->keep_mac_tx_enabled)
+ a5psw_reg_rmw(a5psw, A5PSW_CMD_CFG(port),
+ A5PSW_CMD_CFG_RX_ENA | A5PSW_CMD_CFG_TX_ENA,
+ A5PSW_CMD_CFG_TX_ENA);
+ else
+ a5psw_reg_writel(a5psw, A5PSW_CMD_CFG(port),
+ A5PSW_CMD_CFG_SW_RESET);
/* Enable only CPU port */
a5psw_port_enable_set(a5psw, port, dsa_port_is_cpu(dp));
@@ -1293,6 +1349,13 @@ static int a5psw_probe(struct platform_device *pdev)
goto free_pcs;
}
+ /* The bootloader may have used the switch, start from reset state */
+ ret = reset_control_reset(reset);
+ if (ret) {
+ dev_err(dev, "Failed to reset switch: %d\n", ret);
+ goto free_pcs;
+ }
+
mdio = of_get_available_child_by_name(dev->of_node, "mdio");
if (mdio) {
ret = a5psw_probe_mdio(a5psw, mdio);
diff --git a/drivers/net/dsa/rzn1_a5psw.h b/drivers/net/dsa/rzn1_a5psw.h
index fd523fe7bf47..3ff76c32e5a4 100644
--- a/drivers/net/dsa/rzn1_a5psw.h
+++ b/drivers/net/dsa/rzn1_a5psw.h
@@ -240,6 +240,9 @@ union lk_data {
* @vlan_res_vlanid: VLANID field mask of the VLAN_RES registers
* @vlan_res_portmask: PORTMASK field mask of the VLAN_RES registers
* @lk_table_entries: Number of entries in the lookup table (power of 2)
+ * @keep_mac_tx_enabled: The MAC transmit path (CMD_CFG.TX_ENA) must never be
+ * disabled, so ports are not reset with CMD_CFG.SW_RESET. Port transmission
+ * is instead gated through PORT_ENA on link down.
*/
struct a5psw_of_data {
unsigned int nports;
@@ -252,6 +255,7 @@ struct a5psw_of_data {
u32 vlan_res_vlanid;
u32 vlan_res_portmask;
unsigned int lk_table_entries;
+ bool keep_mac_tx_enabled;
};
/**
@@ -268,6 +272,8 @@ struct a5psw_of_data {
* @stats_lock: lock to access statistics (shared HI counter)
* @lk_lock: Lock for the lookup table
* @reg_lock: Lock for register read-modify-write operation
+ * @tx_allowed: Mask of ports with TX allowed by the port and STP state
+ * @link_up: Mask of ports whose link is up, or which are not link gated
* @bridged_ports: Mask of ports that are bridged and should be flooded
* @br_dev: Bridge net device
*/
@@ -282,6 +288,8 @@ struct a5psw {
struct dsa_switch ds;
struct mutex lk_lock;
spinlock_t reg_lock;
+ u32 tx_allowed;
+ u32 link_up;
u32 bridged_ports;
struct net_device *br_dev;
};
--
2.56.1