da8d5b346212a5ed056c7e1ac44958e09f3f12f0
[openwrt/staging/blocktrron.git] /
1 From b7ebac354d54f1657bb89b7a7ca149db50203e6a Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Fri, 14 May 2021 23:00:12 +0200
4 Subject: [PATCH] net: dsa: qca8k: improve internal mdio read/write bus access
5
6 Improve the internal mdio read/write bus access by caching the value
7 without accessing it for every read/write.
8
9 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
10 Signed-off-by: David S. Miller <davem@davemloft.net>
11 ---
12 drivers/net/dsa/qca8k.c | 28 +++++++++++++++-------------
13 1 file changed, 15 insertions(+), 13 deletions(-)
14
15 --- a/drivers/net/dsa/qca8k.c
16 +++ b/drivers/net/dsa/qca8k.c
17 @@ -655,6 +655,7 @@ static int
18 qca8k_mdio_write(struct mii_bus *salve_bus, int phy, int regnum, u16 data)
19 {
20 struct qca8k_priv *priv = salve_bus->priv;
21 + struct mii_bus *bus = priv->bus;
22 u16 r1, r2, page;
23 u32 val;
24 int ret;
25 @@ -669,22 +670,22 @@ qca8k_mdio_write(struct mii_bus *salve_b
26
27 qca8k_split_addr(QCA8K_MDIO_MASTER_CTRL, &r1, &r2, &page);
28
29 - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
30 + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
31
32 - ret = qca8k_set_page(priv->bus, page);
33 + ret = qca8k_set_page(bus, page);
34 if (ret)
35 goto exit;
36
37 - qca8k_mii_write32(priv->bus, 0x10 | r2, r1, val);
38 + qca8k_mii_write32(bus, 0x10 | r2, r1, val);
39
40 - ret = qca8k_mdio_busy_wait(priv->bus, QCA8K_MDIO_MASTER_CTRL,
41 + ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL,
42 QCA8K_MDIO_MASTER_BUSY);
43
44 exit:
45 /* even if the busy_wait timeouts try to clear the MASTER_EN */
46 - qca8k_mii_write32(priv->bus, 0x10 | r2, r1, 0);
47 + qca8k_mii_write32(bus, 0x10 | r2, r1, 0);
48
49 - mutex_unlock(&priv->bus->mdio_lock);
50 + mutex_unlock(&bus->mdio_lock);
51
52 return ret;
53 }
54 @@ -693,6 +694,7 @@ static int
55 qca8k_mdio_read(struct mii_bus *salve_bus, int phy, int regnum)
56 {
57 struct qca8k_priv *priv = salve_bus->priv;
58 + struct mii_bus *bus = priv->bus;
59 u16 r1, r2, page;
60 u32 val;
61 int ret;
62 @@ -706,26 +708,26 @@ qca8k_mdio_read(struct mii_bus *salve_bu
63
64 qca8k_split_addr(QCA8K_MDIO_MASTER_CTRL, &r1, &r2, &page);
65
66 - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
67 + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
68
69 - ret = qca8k_set_page(priv->bus, page);
70 + ret = qca8k_set_page(bus, page);
71 if (ret)
72 goto exit;
73
74 - qca8k_mii_write32(priv->bus, 0x10 | r2, r1, val);
75 + qca8k_mii_write32(bus, 0x10 | r2, r1, val);
76
77 - ret = qca8k_mdio_busy_wait(priv->bus, QCA8K_MDIO_MASTER_CTRL,
78 + ret = qca8k_mdio_busy_wait(bus, QCA8K_MDIO_MASTER_CTRL,
79 QCA8K_MDIO_MASTER_BUSY);
80 if (ret)
81 goto exit;
82
83 - val = qca8k_mii_read32(priv->bus, 0x10 | r2, r1);
84 + val = qca8k_mii_read32(bus, 0x10 | r2, r1);
85
86 exit:
87 /* even if the busy_wait timeouts try to clear the MASTER_EN */
88 - qca8k_mii_write32(priv->bus, 0x10 | r2, r1, 0);
89 + qca8k_mii_write32(bus, 0x10 | r2, r1, 0);
90
91 - mutex_unlock(&priv->bus->mdio_lock);
92 + mutex_unlock(&bus->mdio_lock);
93
94 if (val >= 0)
95 val &= QCA8K_MDIO_MASTER_DATA_MASK;