Re: [net-next,PATCH 1/2] net: dsa: microchip: Add emulated MIIM access to switch LED config registers
From: Paolo Abeni
Date: Thu Jan 16 2025 - 04:33:25 EST
On 1/13/25 1:15 AM, Marek Vasut wrote:
> The KSZ87xx switch DSA driver binds a simplified KSZ8795 switch PHY driver to
> each port. The KSZ8795 switch PHY driver is part of drivers/net/phy/micrel.c
> and uses generic PHY register accessors to access MIIM registers 0x00..0x05,
> 0x1d and 0x1f . The MII access is implemented by the KSZ87xx switch DSA driver
> and internally done over whichever interface the KSZ87xx switch is connected
> to the SoC.
>
> In order to configure LEDs from the KSZ8795 switch PHY driver, it is necessary
> to expose the LED control registers to the PHY driver, however, the LED control
> registers are not part of the MIIM block, they are in Switch Config Registers
> block.
>
> This preparatory patch exposes the LED control bits in those Switch Config
> Registers by mapping them at high addresses in the MIIM space, so the PHY
> driver can access those registers and surely not collide with the existing
> MIIM block registers. The two registers which are exposed are the global
> Register 11 (0x0B): Global Control 9 as MIIM block register 0x0b00 and
> port specific Register 29/45/61 (0x1D/0x2D/0x3D): Port 1/2/3 Control 10
> as MIIM block register 0x0d00 . The access to those registers is further
> restricted only to the LED configuration bits to prevent the PHY driver
> or userspace tools like 'phytool' from tampering with any other switch
> configuration through this interface.
>
> Signed-off-by: Marek Vasut <marex@xxxxxxx>
> ---
> Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
> Cc: Andrew Lunn <andrew@xxxxxxx>
> Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
> Cc: Heiner Kallweit <hkallweit1@xxxxxxxxx>
> Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
> Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
> Cc: Russell King <linux@xxxxxxxxxxxxxxx>
> Cc: Tristram Ha <tristram.ha@xxxxxxxxxxxxx>
> Cc: UNGLinuxDriver@xxxxxxxxxxxxx
> Cc: Vladimir Oltean <olteanv@xxxxxxxxx>
> Cc: Woojung Huh <woojung.huh@xxxxxxxxxxxxx>
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Cc: netdev@xxxxxxxxxxxxxxx
> ---
> drivers/net/dsa/microchip/ksz8.c | 47 ++++++++++++++++++++++++++++++++
> 1 file changed, 47 insertions(+)
>
> diff --git a/drivers/net/dsa/microchip/ksz8.c b/drivers/net/dsa/microchip/ksz8.c
> index da7110d675583..9698bf53378af 100644
> --- a/drivers/net/dsa/microchip/ksz8.c
> +++ b/drivers/net/dsa/microchip/ksz8.c
> @@ -1044,6 +1044,22 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
> return ret;
>
> break;
> + /* Emulated access to Register 11 (0x0B): Global Control 9 */
> + case (REG_SW_CTRL_9 << 8):
I think it's better to add a macro for the new registers
> + ret = ksz_read8(dev, REG_SW_CTRL_9, &val1);
> + if (ret)
> + return ret;
> +
> + data = val1 & 0x30; /* LED Mode */
In a similar way, it's better to add meaningful macros for the relevant
register fields. You should consider using the *FIELD*() helpers, too.
/P