>From 85766c0ab77750faa4488ca7018784e3e8e9eba0 Mon Sep 17 00:00:00 2001 From: Lauri Jakku Date: Mon, 13 Apr 2020 13:18:35 +0300 Subject: [PATCH] NET: r8168/r8169 identifying fix The driver installation determination made properly by checking PHY vs DRIVER id's. --- drivers/net/ethernet/realtek/r8169_main.c | 47 +++++++++++++++++++---- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index bf5bf05970a2..da08b1b1047c 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -5149,6 +5149,9 @@ static int r8169_mdio_register(struct rtl8169_private *tp) { struct pci_dev *pdev = tp->pci_dev; struct mii_bus *new_bus; + u32 phydev_id = 0; + u32 phydrv_id = 0; + u32 phydrv_id_mask = 0; int ret; new_bus = devm_mdiobus_alloc(&pdev->dev); @@ -5172,13 +5175,43 @@ static int r8169_mdio_register(struct rtl8169_private *tp) if (!tp->phydev) { mdiobus_unregister(new_bus); return -ENODEV; - } else if (!tp->phydev->drv) { - /* Most chip versions fail with the genphy driver. - * Therefore ensure that the dedicated PHY driver is loaded. - */ - dev_err(&pdev->dev, "realtek.ko not loaded, maybe it needs to be added to initramfs?\n"); - mdiobus_unregister(new_bus); - return -EUNATCH; + } else { + /* tp -> phydev ok */ + int everything_OK = 0; + + /* Check driver id versus phy */ + + if (tp->phydev->drv) { + u32 phydev_masked = 0xBEEFDEAD; + u32 drv_masked = ~0; + u32 phydev_match = ~0; + u32 drv_match = 0xDEADBEEF; + + phydev_id = tp->phydev->phy_id; + phydrv_id = tp->phydev->drv->phy_id; + phydrv_id_mask = tp->phydev->drv->phy_id_mask; + + drv_masked = phydrv_id & phydrv_id_mask; + phydev_masked = phydev_id & phydrv_id_mask; + + phydev_match = phydev_masked & drv_masked; + phydev_match = phydev_match == phydev_masked; + + drv_match = phydev_masked & drv_masked; + drv_match = drv_match == drv_masked; + + everything_OK = (phydev_match == drv_match); + } + + if (!everything_OK) { + /* Most chip versions fail with the genphy driver. + * Therefore ensure that the dedicated PHY driver + * is loaded. + */ + dev_err(&pdev->dev, "realtek.ko not loaded, maybe it needs to be added to initramfs?\n"); + mdiobus_unregister(new_bus); + return -EUNATCH; + } } /* PHY will be woken up in rtl_open() */ -- 2.26.0