1e293d3a0befaaeef17e2031c7055947e5f7ee9c
[openwrt/staging/ldir.git] /
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
5
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
10 implementation.
11
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>
15 ---
16 drivers/net/dsa/qca8k.c | 30 ++++++++++++++++++++++--------
17 1 file changed, 22 insertions(+), 8 deletions(-)
18
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
22 }
23
24 static int
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)
27 {
28 - struct qca8k_priv *priv = salve_bus->priv;
29 - struct mii_bus *bus = priv->bus;
30 u16 r1, r2, page;
31 u32 val;
32 int ret;
33 @@ -682,10 +680,8 @@ exit:
34 }
35
36 static int
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)
39 {
40 - struct qca8k_priv *priv = salve_bus->priv;
41 - struct mii_bus *bus = priv->bus;
42 u16 r1, r2, page;
43 u32 val;
44 int ret;
45 @@ -727,6 +723,24 @@ exit:
46 }
47
48 static int
49 +qca8k_internal_mdio_write(struct mii_bus *slave_bus, int phy, int regnum, u16 data)
50 +{
51 + struct qca8k_priv *priv = slave_bus->priv;
52 + struct mii_bus *bus = priv->bus;
53 +
54 + return qca8k_mdio_write(bus, phy, regnum, data);
55 +}
56 +
57 +static int
58 +qca8k_internal_mdio_read(struct mii_bus *slave_bus, int phy, int regnum)
59 +{
60 + struct qca8k_priv *priv = slave_bus->priv;
61 + struct mii_bus *bus = priv->bus;
62 +
63 + return qca8k_mdio_read(bus, phy, regnum);
64 +}
65 +
66 +static int
67 qca8k_phy_write(struct dsa_switch *ds, int port, int regnum, u16 data)
68 {
69 struct qca8k_priv *priv = ds->priv;
70 @@ -775,8 +789,8 @@ qca8k_mdio_register(struct qca8k_priv *p
71
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",
79 ds->index);
80