From patchwork Sat Apr 13 22:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QXLEsW7DpyDDnE5BTCB2aWEgQjQgUmVsYXk=?= X-Patchwork-Id: 13628817 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B91F756B64; Sat, 13 Apr 2024 22:08:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713046138; cv=none; b=SBAuzvfmTh7gaCf5wa5NIk5TyFGDcVjIAOIhD5vfCUUCeW3HvkPWbikG+gs+xegxUQTviTWBu2as5u3vSMDh50iNcqnXy+gVHAOH8Wn4KWvePJHRYreF1XEFqoh8bekq8G381aye4QgAjIwapDfmhCZ9ez7nE19igZ5JMlfSDBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713046138; c=relaxed/simple; bh=VxogV0yej40FmW+ihYscQHWcN9o7MWNL8mWC4P/lBH4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DA2JXFV01sX/7HQEwWSJsDYWOTQqZmFzizQgGdhNCxHZ2OuTSmww1YlQqnxIEdjesUizauoNknVs1Q6ImrDegyqZ7/q8vWlaMVN3pD6w1HkO1I7IgXgvJejoIrHOSqkY9qpwhg/zlsXonGBsLHRCFQ5kJfUFeo7dlX44KcTvEX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lvCh3Zx3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lvCh3Zx3" Received: by smtp.kernel.org (Postfix) with ESMTPS id 392D6C3277B; Sat, 13 Apr 2024 22:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713046138; bh=VxogV0yej40FmW+ihYscQHWcN9o7MWNL8mWC4P/lBH4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=lvCh3Zx3L5oEb3YWbl0xyy9hWZb96N35vx/xbyU9qH3S0BtC6S7feSohnfhlxtICt SKS0b943VX0KS1C0MONVUQmIosyJFqse/C7kHsxaGEJ/37ZVKxuVhilWgvyXXZQAr2 iMllvi7+4QDS+IbnL813YSbhnhXcj4xP/nk8hTABqsomvhpe6D0uouTciNW4WcFuNu +17YccKmx3AnVPhveAb6Ju1ULUKdxzjtHChDw0bFOz1Z8zr2o2mDDAWIfx0XCTKWZV 7hVo3YEX7IklLhdQX1zhHjJeSXOZNN61t5I7O/KFdEFIAOCkcAYGuwMqRuC78mnr2p 68sudnP+BFxiQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25E81C04FFF; Sat, 13 Apr 2024 22:08:58 +0000 (UTC) From: =?utf-8?b?QXLEsW7DpyDDnE5BTCB2aWEgQjQgUmVsYXk=?= Date: Sun, 14 Apr 2024 01:08:20 +0300 Subject: [PATCH net-next 2/2] net: dsa: mt7530: simplify core operations Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240414-b4-for-netnext-mt7530-phy-addr-from-dt-and-simplify-core-ops-v1-2-b08936df2770@arinc9.com> References: <20240414-b4-for-netnext-mt7530-phy-addr-from-dt-and-simplify-core-ops-v1-0-b08936df2770@arinc9.com> In-Reply-To: <20240414-b4-for-netnext-mt7530-phy-addr-from-dt-and-simplify-core-ops-v1-0-b08936df2770@arinc9.com> To: Daniel Golle , DENG Qingfang , Sean Wang , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno Cc: Bartel Eerdekens , 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, =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1713046128; l=5138; i=arinc.unal@arinc9.com; s=arinc9-patatt; h=from:subject:message-id; bh=o4RCzhO0kgaRNXzb5/selbFyHUCLAME8PrfFOQLNkbw=; b=YgnI3He1W+EzOP8bvrmuaBZ3xJ8neD+fuPbDkiAXdS2V8tarzTVqicDpGkmMpeKkn17HZMNGA tU++ojNrcp6AQgGw4+x9fsRpWpe1x7Th2yod930BouoLjfCGnb0sS1K X-Developer-Key: i=arinc.unal@arinc9.com; a=ed25519; pk=VmvgMWwm73yVIrlyJYvGtnXkQJy9CvbaeEqPQO9Z4kA= X-Endpoint-Received: by B4 Relay for arinc.unal@arinc9.com/arinc9-patatt with auth_id=115 X-Original-From: =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= Reply-To: arinc.unal@arinc9.com X-Patchwork-Delegate: kuba@kernel.org From: Arınç ÜNAL 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 Reviewed-by: Daniel Golle Tested-by: Daniel Golle --- 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); }