Openwrt/target/linux/generic/backport-5.4/790-net-phy-at803x-select-correct-page-on-config-init.patch
David Bauer c44cefceb3 generic: kernel 5.4: fix probe error for AR803x PHYs
Atheros PHYs using the at803x driver apart from the AR8031/AR8033 fail
to probe with kernel 5.4, due to ret in at803x_probe being
uninitialized.

[    1.403461] Atheros 8035 ethernet: probe of 4ef600c00.ethernet:01
	       failed with error -1066114012

Initialize ret in order to successfully prove the PHYs on kernel 5.4.

Kernel 5.10 is not affected, as the ret is always assigned prior to
returning.

Tested on OCEDO Koala.

Reported-by: Russell Senior <russell@personaltelco.net>
Signed-off-by: David Bauer <mail@david-bauer.net>
2021-06-13 11:32:39 +02:00

105 lines
3.0 KiB
Diff

From c329e5afb42ff0a88285eb4d8a391a18793e4777 Mon Sep 17 00:00:00 2001
From: David Bauer <mail@david-bauer.net>
Date: Thu, 15 Apr 2021 03:26:50 +0200
Subject: [PATCH] net: phy: at803x: select correct page on config init
The Atheros AR8031 and AR8033 expose different registers for SGMII/Fiber
as well as the copper side of the PHY depending on the BT_BX_REG_SEL bit
in the chip configure register.
The driver assumes the copper side is selected on probe, but this might
not be the case depending which page was last selected by the
bootloader. Notably, Ubiquiti UniFi bootloaders show this behavior.
Select the copper page when probing to circumvent this.
Signed-off-by: David Bauer <mail@david-bauer.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
drivers/net/phy/at803x.c | 50 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
--- a/drivers/net/phy/at803x.c
+++ b/drivers/net/phy/at803x.c
@@ -67,6 +67,9 @@
#define ATH8035_PHY_ID 0x004dd072
#define AT803X_PHY_ID_MASK 0xffffffef
+#define AT803X_PAGE_FIBER 0
+#define AT803X_PAGE_COPPER 1
+
MODULE_DESCRIPTION("Atheros 803x PHY driver");
MODULE_AUTHOR("Matus Ujhelyi");
MODULE_LICENSE("GPL");
@@ -112,6 +115,35 @@ static int at803x_debug_reg_mask(struct
return phy_write(phydev, AT803X_DEBUG_DATA, val);
}
+static int at803x_write_page(struct phy_device *phydev, int page)
+{
+ int mask;
+ int set;
+
+ if (page == AT803X_PAGE_COPPER) {
+ set = AT803X_BT_BX_REG_SEL;
+ mask = 0;
+ } else {
+ set = 0;
+ mask = AT803X_BT_BX_REG_SEL;
+ }
+
+ return __phy_modify(phydev, AT803X_REG_CHIP_CONFIG, mask, set);
+}
+
+static int at803x_read_page(struct phy_device *phydev)
+{
+ int ccr = __phy_read(phydev, AT803X_REG_CHIP_CONFIG);
+
+ if (ccr < 0)
+ return ccr;
+
+ if (ccr & AT803X_BT_BX_REG_SEL)
+ return AT803X_PAGE_COPPER;
+
+ return AT803X_PAGE_FIBER;
+}
+
static int at803x_enable_rx_delay(struct phy_device *phydev)
{
return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0,
@@ -244,6 +276,7 @@ static int at803x_probe(struct phy_devic
{
struct device *dev = &phydev->mdio.dev;
struct at803x_priv *priv;
+ int ret = 0;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -251,7 +284,16 @@ static int at803x_probe(struct phy_devic
phydev->priv = priv;
- return 0;
+ /* Some bootloaders leave the fiber page selected.
+ * Switch to the copper page, as otherwise we read
+ * the PHY capabilities from the fiber side.
+ */
+ if ((phydev->phy_id & phydev->drv->phy_id_mask) == (ATH8031_PHY_ID & phydev->drv->phy_id_mask)) {
+ ret = phy_select_page(phydev, AT803X_PAGE_COPPER);
+ ret = phy_restore_page(phydev, AT803X_PAGE_COPPER, ret);
+ }
+
+ return ret;
}
static int at803x_config_init(struct phy_device *phydev)
@@ -466,6 +508,8 @@ static struct phy_driver at803x_driver[]
.get_wol = at803x_get_wol,
.suspend = at803x_suspend,
.resume = at803x_resume,
+ .read_page = at803x_read_page,
+ .write_page = at803x_write_page,
/* PHY_GBIT_FEATURES */
.read_status = at803x_read_status,
.aneg_done = at803x_aneg_done,