790-53-v6.10-net-dsa-mt7530-simplify-core-operations.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. From 9764a08b3d260f4e7799d34bbfe64463db940d74 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Ar=C4=B1n=C3=A7=20=C3=9CNAL?= <[email protected]>
  3. Date: Thu, 18 Apr 2024 08:35:31 +0300
  4. Subject: [PATCH 5/5] net: dsa: mt7530: simplify core operations
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. The core_rmw() function calls core_read_mmd_indirect() to read the
  9. requested register, and then calls core_write_mmd_indirect() to write the
  10. requested value to the register. Because Clause 22 is used to access Clause
  11. 45 registers, some operations on core_write_mmd_indirect() are
  12. unnecessarily run. Get rid of core_read_mmd_indirect() and
  13. core_write_mmd_indirect(), and run only the necessary operations on
  14. core_write() and core_rmw().
  15. Reviewed-by: Daniel Golle <[email protected]>
  16. Tested-by: Daniel Golle <[email protected]>
  17. Signed-off-by: Arınç ÜNAL <[email protected]>
  18. Signed-off-by: Paolo Abeni <[email protected]>
  19. ---
  20. drivers/net/dsa/mt7530.c | 108 ++++++++++++++++-----------------------
  21. 1 file changed, 43 insertions(+), 65 deletions(-)
  22. --- a/drivers/net/dsa/mt7530.c
  23. +++ b/drivers/net/dsa/mt7530.c
  24. @@ -74,116 +74,94 @@ static const struct mt7530_mib_desc mt75
  25. MIB_DESC(1, 0xb8, "RxArlDrop"),
  26. };
  27. -/* Since phy_device has not yet been created and
  28. - * phy_{read,write}_mmd_indirect is not available, we provide our own
  29. - * core_{read,write}_mmd_indirect with core_{clear,write,set} wrappers
  30. - * to complete this function.
  31. - */
  32. -static int
  33. -core_read_mmd_indirect(struct mt7530_priv *priv, int prtad, int devad)
  34. +static void
  35. +mt7530_mutex_lock(struct mt7530_priv *priv)
  36. +{
  37. + if (priv->bus)
  38. + mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
  39. +}
  40. +
  41. +static void
  42. +mt7530_mutex_unlock(struct mt7530_priv *priv)
  43. +{
  44. + if (priv->bus)
  45. + mutex_unlock(&priv->bus->mdio_lock);
  46. +}
  47. +
  48. +static void
  49. +core_write(struct mt7530_priv *priv, u32 reg, u32 val)
  50. {
  51. struct mii_bus *bus = priv->bus;
  52. - int value, ret;
  53. + int ret;
  54. +
  55. + mt7530_mutex_lock(priv);
  56. /* Write the desired MMD Devad */
  57. ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  58. - MII_MMD_CTRL, devad);
  59. + MII_MMD_CTRL, MDIO_MMD_VEND2);
  60. if (ret < 0)
  61. goto err;
  62. /* Write the desired MMD register address */
  63. ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  64. - MII_MMD_DATA, prtad);
  65. + MII_MMD_DATA, reg);
  66. if (ret < 0)
  67. goto err;
  68. /* Select the Function : DATA with no post increment */
  69. ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  70. - MII_MMD_CTRL, devad | MII_MMD_CTRL_NOINCR);
  71. + MII_MMD_CTRL, MDIO_MMD_VEND2 | MII_MMD_CTRL_NOINCR);
  72. if (ret < 0)
  73. goto err;
  74. - /* Read the content of the MMD's selected register */
  75. - value = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  76. - MII_MMD_DATA);
  77. -
  78. - return value;
  79. + /* Write the data into MMD's selected register */
  80. + ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  81. + MII_MMD_DATA, val);
  82. err:
  83. - dev_err(&bus->dev, "failed to read mmd register\n");
  84. + if (ret < 0)
  85. + dev_err(&bus->dev, "failed to write mmd register\n");
  86. - return ret;
  87. + mt7530_mutex_unlock(priv);
  88. }
  89. -static int
  90. -core_write_mmd_indirect(struct mt7530_priv *priv, int prtad,
  91. - int devad, u32 data)
  92. +static void
  93. +core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
  94. {
  95. struct mii_bus *bus = priv->bus;
  96. + u32 val;
  97. int ret;
  98. + mt7530_mutex_lock(priv);
  99. +
  100. /* Write the desired MMD Devad */
  101. ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  102. - MII_MMD_CTRL, devad);
  103. + MII_MMD_CTRL, MDIO_MMD_VEND2);
  104. if (ret < 0)
  105. goto err;
  106. /* Write the desired MMD register address */
  107. ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  108. - MII_MMD_DATA, prtad);
  109. + MII_MMD_DATA, reg);
  110. if (ret < 0)
  111. goto err;
  112. /* Select the Function : DATA with no post increment */
  113. ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  114. - MII_MMD_CTRL, devad | MII_MMD_CTRL_NOINCR);
  115. + MII_MMD_CTRL, MDIO_MMD_VEND2 | MII_MMD_CTRL_NOINCR);
  116. if (ret < 0)
  117. goto err;
  118. + /* Read the content of the MMD's selected register */
  119. + val = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  120. + MII_MMD_DATA);
  121. + val &= ~mask;
  122. + val |= set;
  123. /* Write the data into MMD's selected register */
  124. ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
  125. - MII_MMD_DATA, data);
  126. + MII_MMD_DATA, val);
  127. err:
  128. if (ret < 0)
  129. - dev_err(&bus->dev,
  130. - "failed to write mmd register\n");
  131. - return ret;
  132. -}
  133. -
  134. -static void
  135. -mt7530_mutex_lock(struct mt7530_priv *priv)
  136. -{
  137. - if (priv->bus)
  138. - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
  139. -}
  140. -
  141. -static void
  142. -mt7530_mutex_unlock(struct mt7530_priv *priv)
  143. -{
  144. - if (priv->bus)
  145. - mutex_unlock(&priv->bus->mdio_lock);
  146. -}
  147. -
  148. -static void
  149. -core_write(struct mt7530_priv *priv, u32 reg, u32 val)
  150. -{
  151. - mt7530_mutex_lock(priv);
  152. -
  153. - core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
  154. -
  155. - mt7530_mutex_unlock(priv);
  156. -}
  157. -
  158. -static void
  159. -core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
  160. -{
  161. - u32 val;
  162. -
  163. - mt7530_mutex_lock(priv);
  164. -
  165. - val = core_read_mmd_indirect(priv, reg, MDIO_MMD_VEND2);
  166. - val &= ~mask;
  167. - val |= set;
  168. - core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
  169. + dev_err(&bus->dev, "failed to write mmd register\n");
  170. mt7530_mutex_unlock(priv);
  171. }