1 From a4165830ca237f2b3318faf62562bce8ce12a389 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 29 Dec 2022 17:33:36 +0100
4 Subject: [PATCH 5/5] net: dsa: qca8k: improve mdio master read/write by using
7 Improve mdio master read/write by using singe mii read/write lo/hi.
9 In a read and write we need to poll the mdio master regs in a busy loop
10 to check for a specific bit present in the upper half of the reg. We can
11 ignore the other half since it won't contain useful data. This will save
12 an additional useless read for each read and write operation.
14 In a read operation the returned data is present in the mdio master reg
15 lower half. We can ignore the other half since it won't contain useful
16 data. This will save an additional useless read for each read operation.
18 In a read operation it's needed to just set the hi half of the mdio
19 master reg as the lo half will be replaced by the result. This will save
20 an additional useless write for each read operation.
22 Tested-by: Ronald Wahl <ronald.wahl@raritan.com>
23 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
24 Signed-off-by: David S. Miller <davem@davemloft.net>
26 drivers/net/dsa/qca/qca8k-8xxx.c | 12 ++++++------
27 1 file changed, 6 insertions(+), 6 deletions(-)
29 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
30 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
31 @@ -740,9 +740,9 @@ qca8k_mdio_busy_wait(struct mii_bus *bus
33 qca8k_split_addr(reg, &r1, &r2, &page);
35 - ret = read_poll_timeout(qca8k_mii_read32, ret1, !(val & mask), 0,
36 + ret = read_poll_timeout(qca8k_mii_read_hi, ret1, !(val & mask), 0,
37 QCA8K_BUSY_WAIT_TIMEOUT * USEC_PER_MSEC, false,
38 - bus, 0x10 | r2, r1, &val);
39 + bus, 0x10 | r2, r1 + 1, &val);
41 /* Check if qca8k_read has failed for a different reason
42 * before returnting -ETIMEDOUT
43 @@ -784,7 +784,7 @@ qca8k_mdio_write(struct qca8k_priv *priv
46 /* even if the busy_wait timeouts try to clear the MASTER_EN */
47 - qca8k_mii_write32(bus, 0x10 | r2, r1, 0);
48 + qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, 0);
50 mutex_unlock(&bus->mdio_lock);
52 @@ -814,18 +814,18 @@ qca8k_mdio_read(struct qca8k_priv *priv,
56 - qca8k_mii_write32(bus, 0x10 | r2, r1, val);
57 + qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, val);
59 ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL,
60 QCA8K_MDIO_MASTER_BUSY);
64 - ret = qca8k_mii_read32(bus, 0x10 | r2, r1, &val);
65 + ret = qca8k_mii_read_lo(bus, 0x10 | r2, r1, &val);
68 /* even if the busy_wait timeouts try to clear the MASTER_EN */
69 - qca8k_mii_write32(bus, 0x10 | r2, r1, 0);
70 + qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, 0);
72 mutex_unlock(&bus->mdio_lock);