From: Lad Prabhakar On RZ/T2H and RZ/N2H, the ETHSW MAC speed is not fully controlled through the switch registers. COMMAND_CONFIG_Pn.ENA_10 has no effect on the actual MAC speed, and 10 Mbps and 1000 Mbps operation must instead be selected through SWCTRL.SET10 and SWCTRL.SET1000, respectively. Without updating SWCTRL when the link speed changes, ETHSW ports cannot operate correctly at 10 Mbps. Select the ETHSW port speed through SWCTRL when bringing up the link to ensure the MAC operates at the negotiated speed. Limit this behaviour to the converters routed to ETHSW ports so that RZ/N1 remains unaffected. Signed-off-by: Lad Prabhakar --- v6: - Updated the comment to clarify the SWCTRL port speed selection mechanism v5: https://lore.kernel.org/all/20261120002549.1908299-5-prabhakar.mahadev-lad.rj@bp.renesas.com/ - New patch --- drivers/net/pcs/pcs-rzn1-miic.c | 46 ++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c index 682a73cf5a87..47ca29084910 100644 --- a/drivers/net/pcs/pcs-rzn1-miic.c +++ b/drivers/net/pcs/pcs-rzn1-miic.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,10 @@ #define MIIC_CONVRST_PHYIF_RST_MASK GENMASK(4, 0) #define MIIC_SWCTRL 0x304 +#define MIIC_SWCTRL_SET_SPEED_10(x) (BIT(0) << (x)) +#define MIIC_SWCTRL_SET_SPEED_1000(x) (BIT(4) << (x)) +#define MIIC_SWCTRL_SET_SPEED_MASK(x) ((BIT(0) | BIT(4)) << (x)) + #define MIIC_SWDUPC 0x308 #define MIIC_MODCTRL_CONF_CONV_MAX 6 @@ -197,6 +202,7 @@ struct miic_phy_link_cfg { * @rsts: Reset controls for the MII converter * @of_data: Pointer to OF data * @link_cfg: MIIC PHY_LINK configuration + * @conv_conf: Matched MODCTRL configuration of the ethernet port muxes */ struct miic { void __iomem *base; @@ -205,6 +211,7 @@ struct miic { struct reset_control_bulk_data rsts[MIIC_MAX_NUM_RSTS]; const struct miic_of_data *of_data; struct miic_phy_link_cfg link_cfg; + const u8 *conv_conf; }; enum miic_type { @@ -230,6 +237,10 @@ enum miic_type { * before access. * @miic_write: Function pointer to write a value to a MIIC register * @type: Type of MIIC + * @swctrl_conf_start: First configuration value of the switch ports whose + * speed has to be selected through SWCTRL + * @swctrl_conf_count: Number of switch ports whose speed has to be selected + * through SWCTRL, 0 if not needed */ struct miic_of_data { struct modctrl_match *match_table; @@ -247,6 +258,8 @@ struct miic_of_data { bool init_unlock_lock_regs; void (*miic_write)(struct miic *miic, int offset, u32 value); enum miic_type type; + u8 swctrl_conf_start; + u8 swctrl_conf_count; }; /** @@ -383,6 +396,27 @@ static int miic_config(struct phylink_pcs *pcs, unsigned int neg_mode, return 0; } +static void miic_swctrl_set_speed(struct miic *miic, int port, int speed) +{ + const struct miic_of_data *of_data = miic->of_data; + u8 conf = miic->conv_conf[port + 1]; + u32 val = 0; + int sw_port; + + if (conf < of_data->swctrl_conf_start || + conf >= of_data->swctrl_conf_start + of_data->swctrl_conf_count) + return; + + sw_port = conf - of_data->swctrl_conf_start; + + if (speed == SPEED_1000) + val = MIIC_SWCTRL_SET_SPEED_1000(sw_port); + else if (speed == SPEED_10) + val = MIIC_SWCTRL_SET_SPEED_10(sw_port); + + miic_reg_rmw(miic, MIIC_SWCTRL, MIIC_SWCTRL_SET_SPEED_MASK(sw_port), val); +} + static void miic_link_up(struct phylink_pcs *pcs, unsigned int neg_mode, phy_interface_t interface, int speed, int duplex) { @@ -415,6 +449,8 @@ static void miic_link_up(struct phylink_pcs *pcs, unsigned int neg_mode, miic_reg_rmw(miic, MIIC_CONVCTRL(port), (MIIC_CONVCTRL_CONV_SPEED | MIIC_CONVCTRL_FULLD), val); + + miic_swctrl_set_speed(miic, port, speed); } static int miic_pre_init(struct phylink_pcs *pcs) @@ -544,9 +580,10 @@ static int miic_init_hw(struct miic *miic, u32 cfg_mode) for (port = 0; port < num_ports; port++) { miic_converter_enable(miic, port, 0); - /* Disable speed/duplex control from these registers, datasheet - * says switch registers should be used to setup switch port - * speed and duplex. + /* RZ/N1 port speed and duplex are configured through the + * switch registers. On RZ/T2H, SWCTRL selects port speed and + * is updated at link-up. Keep SWDUPC at 0 so duplex is + * controlled through COMMAND_CONFIG_Pn.HD_ENA. */ miic_reg_writel(miic, MIIC_SWCTRL, 0x0); miic_reg_writel(miic, MIIC_SWDUPC, 0x0); @@ -599,6 +636,7 @@ static int miic_match_dt_conf(struct miic *miic, s8 *dt_val, u32 *mode_cfg) if (miic_modctrl_match(table_entry->conv, dt_val, miic->of_data->conf_conv_count)) { *mode_cfg = table_entry->mode_cfg; + miic->conv_conf = table_entry->conv; return 0; } } @@ -875,6 +913,8 @@ static struct miic_of_data rzt2h_miic_of_data = { .reset_count = ARRAY_SIZE(rzt2h_reset_ids), .miic_write = miic_reg_writel_locked, .type = MIIC_TYPE_RZT2H, + .swctrl_conf_start = ETHSS_ETHSW_PORT0, + .swctrl_conf_count = 3, }; static const struct of_device_id miic_of_mtable[] = { -- 2.56.1