1 From ce062a0adbfe933b1932235fdfd874c4c91d1bb0 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Sat, 11 Sep 2021 17:50:09 +0200
4 Subject: net: dsa: qca8k: fix kernel panic with legacy mdio mapping
6 When the mdio legacy mapping is used the mii_bus priv registered by DSA
7 refer to the dsa switch struct instead of the qca8k_priv struct and
8 causes a kernel panic. Create dedicated function when the internal
9 dedicated mdio driver is used to properly handle the 2 different
12 Fixes: 759bafb8a322 ("net: dsa: qca8k: add support for internal phy and internal mdio")
13 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
16 drivers/net/dsa/qca8k.c | 30 ++++++++++++++++++++++--------
17 1 file changed, 22 insertions(+), 8 deletions(-)
19 --- a/drivers/net/dsa/qca8k.c
20 +++ b/drivers/net/dsa/qca8k.c
21 @@ -643,10 +643,8 @@ qca8k_mdio_busy_wait(struct mii_bus *bus
25 -qca8k_mdio_write(struct mii_bus *salve_bus, int phy, int regnum, u16 data)
26 +qca8k_mdio_write(struct mii_bus *bus, int phy, int regnum, u16 data)
28 - struct qca8k_priv *priv = salve_bus->priv;
29 - struct mii_bus *bus = priv->bus;
33 @@ -682,10 +680,8 @@ exit:
37 -qca8k_mdio_read(struct mii_bus *salve_bus, int phy, int regnum)
38 +qca8k_mdio_read(struct mii_bus *bus, int phy, int regnum)
40 - struct qca8k_priv *priv = salve_bus->priv;
41 - struct mii_bus *bus = priv->bus;
45 @@ -727,6 +723,24 @@ exit:
49 +qca8k_internal_mdio_write(struct mii_bus *slave_bus, int phy, int regnum, u16 data)
51 + struct qca8k_priv *priv = slave_bus->priv;
52 + struct mii_bus *bus = priv->bus;
54 + return qca8k_mdio_write(bus, phy, regnum, data);
58 +qca8k_internal_mdio_read(struct mii_bus *slave_bus, int phy, int regnum)
60 + struct qca8k_priv *priv = slave_bus->priv;
61 + struct mii_bus *bus = priv->bus;
63 + return qca8k_mdio_read(bus, phy, regnum);
67 qca8k_phy_write(struct dsa_switch *ds, int port, int regnum, u16 data)
69 struct qca8k_priv *priv = ds->priv;
70 @@ -775,8 +789,8 @@ qca8k_mdio_register(struct qca8k_priv *p
72 bus->priv = (void *)priv;
73 bus->name = "qca8k slave mii";
74 - bus->read = qca8k_mdio_read;
75 - bus->write = qca8k_mdio_write;
76 + bus->read = qca8k_internal_mdio_read;
77 + bus->write = qca8k_internal_mdio_write;
78 snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d",