generic: copy backport, hack, pending patch and config from 6.1 to 6.6
[openwrt/openwrt.git] / target / linux / generic / backport-6.6 / 777-v6.2-05-net-dsa-qca8k-improve-mdio-master-read-write-by-usin.patch
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
5 single lo/hi
6
7 Improve mdio master read/write by using singe mii read/write lo/hi.
8
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.
13
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.
17
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.
21
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>
25 ---
26 drivers/net/dsa/qca/qca8k-8xxx.c | 12 ++++++------
27 1 file changed, 6 insertions(+), 6 deletions(-)
28
29 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
30 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
31 @@ -754,9 +754,9 @@ qca8k_mdio_busy_wait(struct mii_bus *bus
32
33 qca8k_split_addr(reg, &r1, &r2, &page);
34
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);
40
41 /* Check if qca8k_read has failed for a different reason
42 * before returnting -ETIMEDOUT
43 @@ -798,7 +798,7 @@ qca8k_mdio_write(struct qca8k_priv *priv
44
45 exit:
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);
49
50 mutex_unlock(&bus->mdio_lock);
51
52 @@ -828,18 +828,18 @@ qca8k_mdio_read(struct qca8k_priv *priv,
53 if (ret)
54 goto exit;
55
56 - qca8k_mii_write32(bus, 0x10 | r2, r1, val);
57 + qca8k_mii_write_hi(bus, 0x10 | r2, r1 + 1, val);
58
59 ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL,
60 QCA8K_MDIO_MASTER_BUSY);
61 if (ret)
62 goto exit;
63
64 - ret = qca8k_mii_read32(bus, 0x10 | r2, r1, &val);
65 + ret = qca8k_mii_read_lo(bus, 0x10 | r2, r1, &val);
66
67 exit:
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);
71
72 mutex_unlock(&bus->mdio_lock);
73