[RFC,net-next,v3,11/15] net: dsa: mt7530: skip locking if MDIO bus isn't present

Message ID 4e6d1cbba2ff16cad5b9ac48ccdf4407f45c7857.1680105013.git.daniel@makrotopia.org
State New
Headers
Series net: dsa: add support for MT7988 |

Commit Message

Daniel Golle March 29, 2023, 3:59 p.m. UTC
  As MT7530 and MT7531 internally use 32-bit wide registers, each access
to any register of the switch requires several operations on the MDIO
bus. Hence if there is congruent access, e.g. due to PCS or PHY
polling, this can mess up and interfere with another ongoing register
access sequence.

However, the MDIO bus mutex is only relevant for MDIO-connected
switches. Prepare switches which have there registers directly mapped
into the SoCs register space via MMIO which do not require such
locking. There we can simply use regmap's default locking mechanism.

Hence guard mutex operations to only be performed in case of MDIO
connected switches.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/net/dsa/mt7530.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Andrew Lunn March 29, 2023, 4:39 p.m. UTC | #1
On Wed, Mar 29, 2023 at 04:59:47PM +0100, Daniel Golle wrote:
> As MT7530 and MT7531 internally use 32-bit wide registers, each access
> to any register of the switch requires several operations on the MDIO
> bus. Hence if there is congruent access, e.g. due to PCS or PHY
> polling, this can mess up and interfere with another ongoing register
> access sequence.
> 
> However, the MDIO bus mutex is only relevant for MDIO-connected
> switches. Prepare switches which have there registers directly mapped
> into the SoCs register space via MMIO which do not require such
> locking. There we can simply use regmap's default locking mechanism.
> 
> Hence guard mutex operations to only be performed in case of MDIO
> connected switches.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
  

Patch

diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index ce2665abaaf57..c6fad2d156160 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -145,13 +145,15 @@  core_write_mmd_indirect(struct mt7530_priv *priv, int prtad,
 static void
 mt7530_mutex_lock(struct mt7530_priv *priv)
 {
-	mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
+	if (priv->bus)
+		mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
 }
 
 static void
 mt7530_mutex_unlock(struct mt7530_priv *priv)
 {
-	mutex_unlock(&priv->bus->mdio_lock);
+	if (priv->bus)
+		mutex_unlock(&priv->bus->mdio_lock);
 }
 
 static void