From nobody Thu Nov 14 17:24:41 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADE9FC77B75 for ; Wed, 29 Mar 2023 16:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231368AbjC2P7l (ORCPT ); Wed, 29 Mar 2023 11:59:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbjC2P6x (ORCPT ); Wed, 29 Mar 2023 11:58:53 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64D3D6A40; Wed, 29 Mar 2023 08:58:29 -0700 (PDT) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1phYBu-0003My-26; Wed, 29 Mar 2023 17:58:26 +0200 Date: Wed, 29 Mar 2023 16:58:22 +0100 From: Daniel Golle To: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Sean Wang , Landen Chao , DENG Qingfang , Philipp Zabel Cc: Sam Shih , Lorenzo Bianconi , John Crispin , Felix Fietkau Subject: [RFC PATCH net-next v3 05/15] net: dsa: mt7530: introduce mutex helpers Message-ID: <118badcdd9741d21e3d367e10c34a2d66ae04f59.1680105013.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As the MDIO bus lock only needs to be involved if actually operating on an MDIO-connected switch we will need to skip locking for built-in switches which are accessed via MMIO. Create helper functions which simplify that upcoming change. Signed-off-by: Daniel Golle Reviewed-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 72 ++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 42c89d4863cd5..033e70b42b12a 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -143,31 +143,40 @@ core_write_mmd_indirect(struct mt7530_priv *priv, int= prtad, } =20 static void -core_write(struct mt7530_priv *priv, u32 reg, u32 val) +mt7530_mutex_lock(struct mt7530_priv *priv) { - struct mii_bus *bus =3D priv->bus; + mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); +} =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); +static void +mt7530_mutex_unlock(struct mt7530_priv *priv) +{ + mutex_unlock(&priv->bus->mdio_lock); +} + +static void +core_write(struct mt7530_priv *priv, u32 reg, u32 val) +{ + mt7530_mutex_lock(priv); =20 core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val); =20 - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); } =20 static void core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set) { - struct mii_bus *bus =3D priv->bus; u32 val; =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); =20 val =3D core_read_mmd_indirect(priv, reg, MDIO_MMD_VEND2); val &=3D ~mask; val |=3D set; core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val); =20 - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); } =20 static void @@ -262,13 +271,11 @@ mt7530_mii_read(struct mt7530_priv *priv, u32 reg) static void mt7530_write(struct mt7530_priv *priv, u32 reg, u32 val) { - struct mii_bus *bus =3D priv->bus; - - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); =20 mt7530_mii_write(priv, reg, val); =20 - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); } =20 static u32 @@ -280,14 +287,13 @@ _mt7530_unlocked_read(struct mt7530_dummy_poll *p) static u32 _mt7530_read(struct mt7530_dummy_poll *p) { - struct mii_bus *bus =3D p->priv->bus; u32 val; =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(p->priv); =20 val =3D mt7530_mii_read(p->priv, p->reg); =20 - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(p->priv); =20 return val; } @@ -305,17 +311,16 @@ static void mt7530_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set) { - struct mii_bus *bus =3D priv->bus; u32 val; =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); =20 val =3D mt7530_mii_read(priv, reg); val &=3D ~mask; val |=3D set; mt7530_mii_write(priv, reg, val); =20 - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); } =20 static void @@ -659,14 +664,13 @@ static int mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, int regnum) { - struct mii_bus *bus =3D priv->bus; struct mt7530_dummy_poll p; u32 reg, val; int ret; =20 INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); =20 ret =3D readx_poll_timeout(_mt7530_unlocked_read, &p, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -699,7 +703,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int p= ort, int devad, =20 ret =3D val & MT7531_MDIO_RW_DATA_MASK; out: - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); =20 return ret; } @@ -708,14 +712,13 @@ static int mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, int regnum, u16 data) { - struct mii_bus *bus =3D priv->bus; struct mt7530_dummy_poll p; u32 val, reg; int ret; =20 INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); =20 ret =3D readx_poll_timeout(_mt7530_unlocked_read, &p, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -747,7 +750,7 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int = port, int devad, } =20 out: - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); =20 return ret; } @@ -755,14 +758,13 @@ mt7531_ind_c45_phy_write(struct mt7530_priv *priv, in= t port, int devad, static int mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int port, int regnum) { - struct mii_bus *bus =3D priv->bus; struct mt7530_dummy_poll p; int ret; u32 val; =20 INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); =20 ret =3D readx_poll_timeout(_mt7530_unlocked_read, &p, val, !(val & MT7531_PHY_ACS_ST), 20, 100000); @@ -785,7 +787,7 @@ mt7531_ind_c22_phy_read(struct mt7530_priv *priv, int p= ort, int regnum) =20 ret =3D val & MT7531_MDIO_RW_DATA_MASK; out: - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); =20 return ret; } @@ -794,14 +796,13 @@ static int mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int port, int regnum, u16 data) { - struct mii_bus *bus =3D priv->bus; struct mt7530_dummy_poll p; int ret; u32 reg; =20 INIT_MT7530_DUMMY_POLL(&p, priv, MT7531_PHY_IAC); =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); =20 ret =3D readx_poll_timeout(_mt7530_unlocked_read, &p, reg, !(reg & MT7531_PHY_ACS_ST), 20, 100000); @@ -823,7 +824,7 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, int = port, int regnum, } =20 out: - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); =20 return ret; } @@ -1104,7 +1105,6 @@ static int mt7530_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu) { struct mt7530_priv *priv =3D ds->priv; - struct mii_bus *bus =3D priv->bus; int length; u32 val; =20 @@ -1115,7 +1115,7 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int por= t, int new_mtu) if (!dsa_is_cpu_port(ds, port)) return 0; =20 - mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); =20 val =3D mt7530_mii_read(priv, MT7530_GMACCR); val &=3D ~MAX_RX_PKT_LEN_MASK; @@ -1136,7 +1136,7 @@ mt7530_port_change_mtu(struct dsa_switch *ds, int por= t, int new_mtu) =20 mt7530_mii_write(priv, MT7530_GMACCR, val); =20 - mutex_unlock(&bus->mdio_lock); + mt7530_mutex_unlock(priv); =20 return 0; } @@ -1937,10 +1937,10 @@ mt7530_irq_thread_fn(int irq, void *dev_id) u32 val; int p; =20 - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); val =3D mt7530_mii_read(priv, MT7530_SYS_INT_STS); mt7530_mii_write(priv, MT7530_SYS_INT_STS, val); - mutex_unlock(&priv->bus->mdio_lock); + mt7530_mutex_unlock(priv); =20 for (p =3D 0; p < MT7530_NUM_PHYS; p++) { if (BIT(p) & val) { @@ -1976,7 +1976,7 @@ mt7530_irq_bus_lock(struct irq_data *d) { struct mt7530_priv *priv =3D irq_data_get_irq_chip_data(d); =20 - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED); + mt7530_mutex_lock(priv); } =20 static void @@ -1985,7 +1985,7 @@ mt7530_irq_bus_sync_unlock(struct irq_data *d) struct mt7530_priv *priv =3D irq_data_get_irq_chip_data(d); =20 mt7530_mii_write(priv, MT7530_SYS_INT_EN, priv->irq_enable); - mutex_unlock(&priv->bus->mdio_lock); + mt7530_mutex_unlock(priv); } =20 static struct irq_chip mt7530_irq_chip =3D { --=20 2.39.2