c4035898745edbdab123678e93d58940c67677b9
[openwrt/staging/981213.git] /
1 From 504bf65931824eda83494e5b5d75686e27ace03e Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Fri, 14 May 2021 22:59:53 +0200
4 Subject: [PATCH] net: dsa: qca8k: improve qca8k read/write/rmw bus access
5
6 Put bus in local variable to improve faster access to the mdio bus.
7
8 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
9 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
10 Signed-off-by: David S. Miller <davem@davemloft.net>
11 ---
12 drivers/net/dsa/qca8k.c | 29 ++++++++++++++++-------------
13 1 file changed, 16 insertions(+), 13 deletions(-)
14
15 --- a/drivers/net/dsa/qca8k.c
16 +++ b/drivers/net/dsa/qca8k.c
17 @@ -142,17 +142,18 @@ qca8k_set_page(struct mii_bus *bus, u16
18 static u32
19 qca8k_read(struct qca8k_priv *priv, u32 reg)
20 {
21 + struct mii_bus *bus = priv->bus;
22 u16 r1, r2, page;
23 u32 val;
24
25 qca8k_split_addr(reg, &r1, &r2, &page);
26
27 - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
28 + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
29
30 - qca8k_set_page(priv->bus, page);
31 - val = qca8k_mii_read32(priv->bus, 0x10 | r2, r1);
32 + qca8k_set_page(bus, page);
33 + val = qca8k_mii_read32(bus, 0x10 | r2, r1);
34
35 - mutex_unlock(&priv->bus->mdio_lock);
36 + mutex_unlock(&bus->mdio_lock);
37
38 return val;
39 }
40 @@ -160,35 +161,37 @@ qca8k_read(struct qca8k_priv *priv, u32
41 static void
42 qca8k_write(struct qca8k_priv *priv, u32 reg, u32 val)
43 {
44 + struct mii_bus *bus = priv->bus;
45 u16 r1, r2, page;
46
47 qca8k_split_addr(reg, &r1, &r2, &page);
48
49 - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
50 + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
51
52 - qca8k_set_page(priv->bus, page);
53 - qca8k_mii_write32(priv->bus, 0x10 | r2, r1, val);
54 + qca8k_set_page(bus, page);
55 + qca8k_mii_write32(bus, 0x10 | r2, r1, val);
56
57 - mutex_unlock(&priv->bus->mdio_lock);
58 + mutex_unlock(&bus->mdio_lock);
59 }
60
61 static u32
62 qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 val)
63 {
64 + struct mii_bus *bus = priv->bus;
65 u16 r1, r2, page;
66 u32 ret;
67
68 qca8k_split_addr(reg, &r1, &r2, &page);
69
70 - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
71 + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
72
73 - qca8k_set_page(priv->bus, page);
74 - ret = qca8k_mii_read32(priv->bus, 0x10 | r2, r1);
75 + qca8k_set_page(bus, page);
76 + ret = qca8k_mii_read32(bus, 0x10 | r2, r1);
77 ret &= ~mask;
78 ret |= val;
79 - qca8k_mii_write32(priv->bus, 0x10 | r2, r1, ret);
80 + qca8k_mii_write32(bus, 0x10 | r2, r1, ret);
81
82 - mutex_unlock(&priv->bus->mdio_lock);
83 + mutex_unlock(&bus->mdio_lock);
84
85 return ret;
86 }