1 From 03cb9e6d0b32b768e3d9d473c5c4ca1100877664 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 29 Dec 2022 17:33:34 +0100
4 Subject: [PATCH 3/5] Revert "net: dsa: qca8k: cache lo and hi for mdio write"
6 This reverts commit 2481d206fae7884cd07014fd1318e63af35e99eb.
8 The Documentation is very confusing about the topic.
9 The cache logic for hi and lo is wrong and actually miss some regs to be
12 What the Documentation actually intended was that it's possible to skip
13 writing hi OR lo if half of the reg is not needed to be written or read.
15 Revert the change in favor of a better and correct implementation.
17 Reported-by: Ronald Wahl <ronald.wahl@raritan.com>
18 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
19 Cc: stable@vger.kernel.org # v5.18+
20 Signed-off-by: David S. Miller <davem@davemloft.net>
22 drivers/net/dsa/qca/qca8k-8xxx.c | 61 +++++++-------------------------
23 drivers/net/dsa/qca/qca8k.h | 5 ---
24 2 files changed, 12 insertions(+), 54 deletions(-)
26 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
27 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
28 @@ -37,44 +37,6 @@ qca8k_split_addr(u32 regaddr, u16 *r1, u
32 -qca8k_set_lo(struct qca8k_priv *priv, int phy_id, u32 regnum, u16 lo)
34 - u16 *cached_lo = &priv->mdio_cache.lo;
35 - struct mii_bus *bus = priv->bus;
38 - if (lo == *cached_lo)
41 - ret = bus->write(bus, phy_id, regnum, lo);
43 - dev_err_ratelimited(&bus->dev,
44 - "failed to write qca8k 32bit lo register\n");
51 -qca8k_set_hi(struct qca8k_priv *priv, int phy_id, u32 regnum, u16 hi)
53 - u16 *cached_hi = &priv->mdio_cache.hi;
54 - struct mii_bus *bus = priv->bus;
57 - if (hi == *cached_hi)
60 - ret = bus->write(bus, phy_id, regnum, hi);
62 - dev_err_ratelimited(&bus->dev,
63 - "failed to write qca8k 32bit hi register\n");
70 qca8k_mii_read32(struct mii_bus *bus, int phy_id, u32 regnum, u32 *val)
73 @@ -97,7 +59,7 @@ qca8k_mii_read32(struct mii_bus *bus, in
77 -qca8k_mii_write32(struct qca8k_priv *priv, int phy_id, u32 regnum, u32 val)
78 +qca8k_mii_write32(struct mii_bus *bus, int phy_id, u32 regnum, u32 val)
82 @@ -105,9 +67,12 @@ qca8k_mii_write32(struct qca8k_priv *pri
84 hi = (u16)(val >> 16);
86 - ret = qca8k_set_lo(priv, phy_id, regnum, lo);
87 + ret = bus->write(bus, phy_id, regnum, lo);
89 - ret = qca8k_set_hi(priv, phy_id, regnum + 1, hi);
90 + ret = bus->write(bus, phy_id, regnum + 1, hi);
92 + dev_err_ratelimited(&bus->dev,
93 + "failed to write qca8k 32bit register\n");
97 @@ -442,7 +407,7 @@ qca8k_regmap_write(void *ctx, uint32_t r
101 - qca8k_mii_write32(priv, 0x10 | r2, r1, val);
102 + qca8k_mii_write32(bus, 0x10 | r2, r1, val);
105 mutex_unlock(&bus->mdio_lock);
106 @@ -475,7 +440,7 @@ qca8k_regmap_update_bits(void *ctx, uint
110 - qca8k_mii_write32(priv, 0x10 | r2, r1, val);
111 + qca8k_mii_write32(bus, 0x10 | r2, r1, val);
114 mutex_unlock(&bus->mdio_lock);
115 @@ -750,14 +715,14 @@ qca8k_mdio_write(struct qca8k_priv *priv
119 - qca8k_mii_write32(priv, 0x10 | r2, r1, val);
120 + qca8k_mii_write32(bus, 0x10 | r2, r1, val);
122 ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL,
123 QCA8K_MDIO_MASTER_BUSY);
126 /* even if the busy_wait timeouts try to clear the MASTER_EN */
127 - qca8k_mii_write32(priv, 0x10 | r2, r1, 0);
128 + qca8k_mii_write32(bus, 0x10 | r2, r1, 0);
130 mutex_unlock(&bus->mdio_lock);
132 @@ -787,7 +752,7 @@ qca8k_mdio_read(struct qca8k_priv *priv,
136 - qca8k_mii_write32(priv, 0x10 | r2, r1, val);
137 + qca8k_mii_write32(bus, 0x10 | r2, r1, val);
139 ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL,
140 QCA8K_MDIO_MASTER_BUSY);
141 @@ -798,7 +763,7 @@ qca8k_mdio_read(struct qca8k_priv *priv,
144 /* even if the busy_wait timeouts try to clear the MASTER_EN */
145 - qca8k_mii_write32(priv, 0x10 | r2, r1, 0);
146 + qca8k_mii_write32(bus, 0x10 | r2, r1, 0);
148 mutex_unlock(&bus->mdio_lock);
150 @@ -1914,8 +1879,6 @@ qca8k_sw_probe(struct mdio_device *mdiod
153 priv->mdio_cache.page = 0xffff;
154 - priv->mdio_cache.lo = 0xffff;
155 - priv->mdio_cache.hi = 0xffff;
157 /* Check the detected switch id */
158 ret = qca8k_read_switch_id(priv);
159 --- a/drivers/net/dsa/qca/qca8k.h
160 +++ b/drivers/net/dsa/qca/qca8k.h
161 @@ -375,11 +375,6 @@ struct qca8k_mdio_cache {
165 -/* lo and hi can also be cached and from Documentation we can skip one
166 - * extra mdio write if lo or hi is didn't change.