From c2c17e16c90fe445db6a9fd07ae342041138ae8b Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Thu, 22 Jun 2023 14:14:22 +0100 Subject: [PATCH] net: nvethernet: Fix nvethernet for Linux v6.3 Commit db1a63aed89c ("net: phy: Remove fallback to old C45 method") removes a fallback C45 method in the MDIO bus driver. This breaks nvethernet support for Linux v6.3 and the following errors are observed. failed to register MDIO bus (nvethernet_mdio_bus) net eth0: failed to register MDIO bus Fix this by adding the necessary read/write_c45 callbacks in the nvethernet driver. Note these callbacks are only supported for Linux v6.3+ kernels. Bug 4014315 Change-Id: Ia6ab753941db0515799657da8522f32996d0852a Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2924619 GVS: Gerrit_Virtual_Submit Reviewed-by: Revanth Kumar Uppala Reviewed-by: Narayan Reddy --- .../ethernet/nvidia/nvethernet/ether_linux.c | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c index 7838fe97..6139e0d5 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c +++ b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c @@ -2408,6 +2408,11 @@ static int ether_update_mac_addr_filter(struct ether_priv_data *pdata, return osi_handle_ioctl(osi_core, ioctl_data); } +static u32 ether_mdio_c45_addr(int devad, u16 regnum) +{ + return OSI_MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum; +} + /** * @brief MII call back for MDIO register write. * @@ -2470,6 +2475,18 @@ static int ether_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg) (unsigned int)phyreg); } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) +static int ether_mdio_write_c45(struct mii_bus *bus, int phyaddr, int devad, int regnum, u16 val) +{ + return ether_mdio_write(bus, phyaddr, ether_mdio_c45_addr(devad, regnum), val); +} + +static int ether_mdio_read_c45(struct mii_bus *bus, int phyaddr, int devad, int regnum) +{ + return ether_mdio_read(bus, phyaddr, ether_mdio_c45_addr(devad, regnum)); +} +#endif + /** * @brief MDIO bus registration. * @@ -2502,6 +2519,10 @@ static int ether_mdio_register(struct ether_priv_data *pdata) new_bus->name = "nvethernet_mdio_bus"; new_bus->read = ether_mdio_read; new_bus->write = ether_mdio_write; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) + new_bus->read_c45 = ether_mdio_read_c45; + new_bus->write_c45 = ether_mdio_write_c45; +#endif ret = snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev)); if (ret < 0) { dev_err(dev, "%s:encoding error", __func__); @@ -3747,7 +3768,7 @@ static int ether_handle_priv_rmdio_ioctl(struct ether_priv_data *pdata, if (mdio_phy_id_is_c45(mii_data->phy_id)) { prtad = mdio_phy_id_prtad(mii_data->phy_id); devad = mdio_phy_id_devad(mii_data->phy_id); - devad = OSI_MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | mii_data->reg_num; + devad = ether_mdio_c45_addr(devad, mii_data->reg_num); } else { prtad = mii_data->phy_id; devad = mii_data->reg_num; @@ -3788,7 +3809,7 @@ static int ether_handle_priv_wmdio_ioctl(struct ether_priv_data *pdata, if (mdio_phy_id_is_c45(mii_data->phy_id)) { prtad = mdio_phy_id_prtad(mii_data->phy_id); devad = mdio_phy_id_devad(mii_data->phy_id); - devad = OSI_MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | mii_data->reg_num; + devad = ether_mdio_c45_addr(devad, mii_data->reg_num); } else { prtad = mii_data->phy_id; devad = mii_data->reg_num;