1 From 9764a08b3d260f4e7799d34bbfe64463db940d74 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <arinc.unal@arinc9.com>
3 Date: Thu, 18 Apr 2024 08:35:31 +0300
4 Subject: [PATCH 5/5] net: dsa: mt7530: simplify core operations
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 The core_rmw() function calls core_read_mmd_indirect() to read the
10 requested register, and then calls core_write_mmd_indirect() to write the
11 requested value to the register. Because Clause 22 is used to access Clause
12 45 registers, some operations on core_write_mmd_indirect() are
13 unnecessarily run. Get rid of core_read_mmd_indirect() and
14 core_write_mmd_indirect(), and run only the necessary operations on
15 core_write() and core_rmw().
17 Reviewed-by: Daniel Golle <daniel@makrotopia.org>
18 Tested-by: Daniel Golle <daniel@makrotopia.org>
19 Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
20 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
22 drivers/net/dsa/mt7530.c | 108 ++++++++++++++++-----------------------
23 1 file changed, 43 insertions(+), 65 deletions(-)
25 --- a/drivers/net/dsa/mt7530.c
26 +++ b/drivers/net/dsa/mt7530.c
27 @@ -74,116 +74,94 @@ static const struct mt7530_mib_desc mt75
28 MIB_DESC(1, 0xb8, "RxArlDrop"),
31 -/* Since phy_device has not yet been created and
32 - * phy_{read,write}_mmd_indirect is not available, we provide our own
33 - * core_{read,write}_mmd_indirect with core_{clear,write,set} wrappers
34 - * to complete this function.
37 -core_read_mmd_indirect(struct mt7530_priv *priv, int prtad, int devad)
39 +mt7530_mutex_lock(struct mt7530_priv *priv)
42 + mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
46 +mt7530_mutex_unlock(struct mt7530_priv *priv)
49 + mutex_unlock(&priv->bus->mdio_lock);
53 +core_write(struct mt7530_priv *priv, u32 reg, u32 val)
55 struct mii_bus *bus = priv->bus;
59 + mt7530_mutex_lock(priv);
61 /* Write the desired MMD Devad */
62 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
63 - MII_MMD_CTRL, devad);
64 + MII_MMD_CTRL, MDIO_MMD_VEND2);
68 /* Write the desired MMD register address */
69 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
70 - MII_MMD_DATA, prtad);
75 /* Select the Function : DATA with no post increment */
76 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
77 - MII_MMD_CTRL, devad | MII_MMD_CTRL_NOINCR);
78 + MII_MMD_CTRL, MDIO_MMD_VEND2 | MII_MMD_CTRL_NOINCR);
82 - /* Read the content of the MMD's selected register */
83 - value = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
87 + /* Write the data into MMD's selected register */
88 + ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
91 - dev_err(&bus->dev, "failed to read mmd register\n");
93 + dev_err(&bus->dev, "failed to write mmd register\n");
96 + mt7530_mutex_unlock(priv);
100 -core_write_mmd_indirect(struct mt7530_priv *priv, int prtad,
101 - int devad, u32 data)
103 +core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
105 struct mii_bus *bus = priv->bus;
109 + mt7530_mutex_lock(priv);
111 /* Write the desired MMD Devad */
112 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
113 - MII_MMD_CTRL, devad);
114 + MII_MMD_CTRL, MDIO_MMD_VEND2);
118 /* Write the desired MMD register address */
119 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
120 - MII_MMD_DATA, prtad);
121 + MII_MMD_DATA, reg);
125 /* Select the Function : DATA with no post increment */
126 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
127 - MII_MMD_CTRL, devad | MII_MMD_CTRL_NOINCR);
128 + MII_MMD_CTRL, MDIO_MMD_VEND2 | MII_MMD_CTRL_NOINCR);
132 + /* Read the content of the MMD's selected register */
133 + val = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
137 /* Write the data into MMD's selected register */
138 ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
139 - MII_MMD_DATA, data);
140 + MII_MMD_DATA, val);
144 - "failed to write mmd register\n");
149 -mt7530_mutex_lock(struct mt7530_priv *priv)
152 - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
156 -mt7530_mutex_unlock(struct mt7530_priv *priv)
159 - mutex_unlock(&priv->bus->mdio_lock);
163 -core_write(struct mt7530_priv *priv, u32 reg, u32 val)
165 - mt7530_mutex_lock(priv);
167 - core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
169 - mt7530_mutex_unlock(priv);
173 -core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
177 - mt7530_mutex_lock(priv);
179 - val = core_read_mmd_indirect(priv, reg, MDIO_MMD_VEND2);
182 - core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
183 + dev_err(&bus->dev, "failed to write mmd register\n");
185 mt7530_mutex_unlock(priv);