Re: [PATCH net-next V3] net: lan743x: Add support to SGMII register dump for PCI11010/PCI11414 chips
From: Andrew Lunn
Date: Mon Oct 10 2022 - 15:36:54 EST
> static int lan743x_get_regs_len(struct net_device *dev)
> {
> - return MAX_LAN743X_ETH_REGS * sizeof(u32);
> + struct lan743x_adapter *adapter = netdev_priv(dev);
> + u32 num_regs = MAX_LAN743X_ETH_COMMON_REGS;
> +
> + if (adapter->is_sgmii_en)
> + num_regs += MAX_LAN743X_ETH_SGMII_REGS;
> +
> + return num_regs * sizeof(u32);
> }
>
> static void lan743x_get_regs(struct net_device *dev,
> struct ethtool_regs *regs, void *p)
> {
> + struct lan743x_adapter *adapter = netdev_priv(dev);
> + int regs_len;
> +
> + regs_len = lan743x_get_regs_len(dev);
> + memset(p, 0, regs_len);
> +
> regs->version = LAN743X_ETH_REG_VERSION;
> + regs->len = regs_len;
> +
> + lan743x_common_regs(dev, p);
> + p = (u32 *)p + MAX_LAN743X_ETH_COMMON_REGS;
>
> - lan743x_common_regs(dev, regs, p);
> + if (adapter->is_sgmii_en) {
> + lan743x_sgmii_regs(dev, p);
> + p = (u32 *)p + MAX_LAN743X_ETH_SGMII_REGS;
> + }
This seems O.K. for the moment, but how does it work when you add the
next set of optional registers? Say you want to add the PTP registers?
One idea might be to use the LAN743X_ETH_REG_VERSION as a
bitfield. Bit 0 indicates the common registers are present. Bit 1
indicates the SGMII registers are present. Bit 2 is for whatever next
set of optional registers you add, say PTP.
Andrew