[PATCH net] net: stmmac: dwmac-socfpga: Don't access SGMII adapter when not available
Thomas Petazzoni
thomas.petazzoni at bootlin.com
Tue Nov 28 01:18:41 PST 2023
On Tue, 28 Nov 2023 10:45:37 +0100
Maxime Chevallier <maxime.chevallier at bootlin.com> wrote:
> The SGMII adapter isn't present on all dwmac-socfpga implementations.
> Make sure we don't try to configure it if we don't have this adapter.
>
> Fixes: 5d1f3fe7d2d5 ("net: stmmac: dwmac-sogfpga: use the lynx pcs driver")
> Signed-off-by: Maxime Chevallier <maxime.chevallier at bootlin.com>
> ---
> drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> index ba2ce776bd4d..ae120792e1b6 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c
> @@ -243,7 +243,8 @@ static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
> {
> u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE;
>
> - writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
> + if (dwmac->sgmii_adapter_base)
> + writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
> }
>
> static int socfpga_set_phy_mode_common(int phymode, u32 *val)
Reviewed-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
As a follow-up improvement, there's an open-coded version of
socfpga_sgmii_config() in socfpga_dwmac_fix_mac_speed(), which could be
rewritten as such:
socfpga_sgmii_config(dwmac, false);
if (splitter_base) {
val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG);
val &= ~EMAC_SPLITTER_CTRL_SPEED_MASK;
switch (speed) {
case 1000:
val |= EMAC_SPLITTER_CTRL_SPEED_1000;
break;
case 100:
val |= EMAC_SPLITTER_CTRL_SPEED_100;
break;
case 10:
val |= EMAC_SPLITTER_CTRL_SPEED_10;
break;
default:
return;
}
writel(val, splitter_base + EMAC_SPLITTER_CTRL_REG);
}
if (phy_dev)
socfpga_sgmii_config(dwmac, true);
But of course, that's not a fix so it should be a separate improvement.
Best regards,
Thomas
--
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
More information about the linux-arm-kernel
mailing list