From: Daniel Golle <daniel@makrotopia.org>
To: arinc.unal@arinc9.com
Cc: DENG Qingfang <dqfext@gmail.com>,
Sean Wang <sean.wang@mediatek.com>, Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Bartel Eerdekens <bartel.eerdekens@constell8.be>,
mithat.guner@xeront.com, erkin.bozoglu@xeront.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH net-next 2/2] net: dsa: mt7530: simplify core operations
Date: Sun, 14 Apr 2024 04:22:31 +0100 [thread overview]
Message-ID: <ZhtL9zAO83HJb_Jq@makrotopia.org> (raw)
In-Reply-To: <20240414-b4-for-netnext-mt7530-phy-addr-from-dt-and-simplify-core-ops-v1-2-b08936df2770@arinc9.com>
On Sun, Apr 14, 2024 at 01:08:20AM +0300, Arınç ÜNAL via B4 Relay wrote:
> From: Arınç ÜNAL <arinc.unal@arinc9.com>
>
> The core_rmw() function calls core_read_mmd_indirect() to read the
> requested register, and then calls core_write_mmd_indirect() to write the
> requested value to the register. Because Clause 22 is used to access Clause
> 45 registers, some operations on core_write_mmd_indirect() are
> unnecessarily run. Get rid of core_read_mmd_indirect() and
> core_write_mmd_indirect(), and run only the necessary operations on
> core_write() and core_rmw().
>
> Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com>
Reviewed-by: Daniel Golle <daniel@makrotopia.org>
Tested-by: Daniel Golle <daniel@makrotopia.org>
> ---
> drivers/net/dsa/mt7530.c | 108 +++++++++++++++++++----------------------------
> 1 file changed, 43 insertions(+), 65 deletions(-)
>
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index fefa6dd151fa..2650eacf87a7 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -74,116 +74,94 @@ static const struct mt7530_mib_desc mt7530_mib[] = {
> MIB_DESC(1, 0xb8, "RxArlDrop"),
> };
>
> -/* Since phy_device has not yet been created and
> - * phy_{read,write}_mmd_indirect is not available, we provide our own
> - * core_{read,write}_mmd_indirect with core_{clear,write,set} wrappers
> - * to complete this function.
> - */
> -static int
> -core_read_mmd_indirect(struct mt7530_priv *priv, int prtad, int devad)
> +static void
> +mt7530_mutex_lock(struct mt7530_priv *priv)
> +{
> + if (priv->bus)
> + mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
> +}
> +
> +static void
> +mt7530_mutex_unlock(struct mt7530_priv *priv)
> +{
> + if (priv->bus)
> + mutex_unlock(&priv->bus->mdio_lock);
> +}
> +
> +static void
> +core_write(struct mt7530_priv *priv, u32 reg, u32 val)
> {
> struct mii_bus *bus = priv->bus;
> - int value, ret;
> + int ret;
> +
> + mt7530_mutex_lock(priv);
>
> /* Write the desired MMD Devad */
> ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> - MII_MMD_CTRL, devad);
> + MII_MMD_CTRL, MDIO_MMD_VEND2);
> if (ret < 0)
> goto err;
>
> /* Write the desired MMD register address */
> ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> - MII_MMD_DATA, prtad);
> + MII_MMD_DATA, reg);
> if (ret < 0)
> goto err;
>
> /* Select the Function : DATA with no post increment */
> ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> - MII_MMD_CTRL, devad | MII_MMD_CTRL_NOINCR);
> + MII_MMD_CTRL, MDIO_MMD_VEND2 | MII_MMD_CTRL_NOINCR);
> if (ret < 0)
> goto err;
>
> - /* Read the content of the MMD's selected register */
> - value = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> - MII_MMD_DATA);
> -
> - return value;
> + /* Write the data into MMD's selected register */
> + ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> + MII_MMD_DATA, val);
> err:
> - dev_err(&bus->dev, "failed to read mmd register\n");
> + if (ret < 0)
> + dev_err(&bus->dev, "failed to write mmd register\n");
>
> - return ret;
> + mt7530_mutex_unlock(priv);
> }
>
> -static int
> -core_write_mmd_indirect(struct mt7530_priv *priv, int prtad,
> - int devad, u32 data)
> +static void
> +core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
> {
> struct mii_bus *bus = priv->bus;
> + u32 val;
> int ret;
>
> + mt7530_mutex_lock(priv);
> +
> /* Write the desired MMD Devad */
> ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> - MII_MMD_CTRL, devad);
> + MII_MMD_CTRL, MDIO_MMD_VEND2);
> if (ret < 0)
> goto err;
>
> /* Write the desired MMD register address */
> ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> - MII_MMD_DATA, prtad);
> + MII_MMD_DATA, reg);
> if (ret < 0)
> goto err;
>
> /* Select the Function : DATA with no post increment */
> ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> - MII_MMD_CTRL, devad | MII_MMD_CTRL_NOINCR);
> + MII_MMD_CTRL, MDIO_MMD_VEND2 | MII_MMD_CTRL_NOINCR);
> if (ret < 0)
> goto err;
>
> + /* Read the content of the MMD's selected register */
> + val = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> + MII_MMD_DATA);
> + val &= ~mask;
> + val |= set;
> /* Write the data into MMD's selected register */
> ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->phy_addr),
> - MII_MMD_DATA, data);
> + MII_MMD_DATA, val);
> err:
> if (ret < 0)
> - dev_err(&bus->dev,
> - "failed to write mmd register\n");
> - return ret;
> -}
> -
> -static void
> -mt7530_mutex_lock(struct mt7530_priv *priv)
> -{
> - if (priv->bus)
> - mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
> -}
> -
> -static void
> -mt7530_mutex_unlock(struct mt7530_priv *priv)
> -{
> - if (priv->bus)
> - mutex_unlock(&priv->bus->mdio_lock);
> -}
> -
> -static void
> -core_write(struct mt7530_priv *priv, u32 reg, u32 val)
> -{
> - mt7530_mutex_lock(priv);
> -
> - core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
> -
> - mt7530_mutex_unlock(priv);
> -}
> -
> -static void
> -core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
> -{
> - u32 val;
> -
> - mt7530_mutex_lock(priv);
> -
> - val = core_read_mmd_indirect(priv, reg, MDIO_MMD_VEND2);
> - val &= ~mask;
> - val |= set;
> - core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
> + dev_err(&bus->dev, "failed to write mmd register\n");
>
> mt7530_mutex_unlock(priv);
> }
>
> --
> 2.40.1
>
>
prev parent reply other threads:[~2024-04-14 3:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-13 22:08 [PATCH net-next 0/2] Read PHY address of switch from device tree on MT7530 DSA subdriver Arınç ÜNAL via B4 Relay
2024-04-13 22:08 ` [PATCH net-next 1/2] net: dsa: mt7530-mdio: read PHY address of switch from device tree Arınç ÜNAL via B4 Relay
2024-04-14 3:10 ` Daniel Golle
2024-04-14 5:59 ` Arınç ÜNAL
2024-04-14 8:06 ` Christophe JAILLET
2024-04-13 22:08 ` [PATCH net-next 2/2] net: dsa: mt7530: simplify core operations Arınç ÜNAL via B4 Relay
2024-04-14 3:22 ` Daniel Golle [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZhtL9zAO83HJb_Jq@makrotopia.org \
--to=daniel@makrotopia.org \
--cc=andrew@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=arinc.unal@arinc9.com \
--cc=bartel.eerdekens@constell8.be \
--cc=davem@davemloft.net \
--cc=dqfext@gmail.com \
--cc=edumazet@google.com \
--cc=erkin.bozoglu@xeront.com \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mithat.guner@xeront.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=sean.wang@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).