mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pawel Dembicki <paweldembicki@gmail.com>
To: netdev@vger.kernel.org
Cc: Pawel Dembicki <paweldembicki@gmail.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>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH net 4/6] net: dsa: vsc73xx: check busy flag in MDIO operations
Date: Fri,  2 Aug 2024 10:04:01 +0200	[thread overview]
Message-ID: <20240802080403.739509-5-paweldembicki@gmail.com> (raw)
In-Reply-To: <20240802080403.739509-1-paweldembicki@gmail.com>

The VSC73xx has a busy flag used during MDIO operations. It is raised
when MDIO read/write operations are in progress. Without it, PHYs are
misconfigured and bus operations do not work as expected.

Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>

---
This patch came from net-next series[0].
Changes since net-next:
  - removed mutex
  - used method poll.h to poll busy value in 'vsc73xx_mdio_busy_check'
  - use 'vsc73xx_mdio_busy_check' for control if mdio is ready

[0] https://patchwork.kernel.org/project/netdevbpf/patch/20240729210615.279952-6-paweldembicki@gmail.com/
---
 drivers/net/dsa/vitesse-vsc73xx-core.c | 33 ++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index b6c46a3da9a5..42b4f312c418 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -317,6 +317,7 @@
 #define IS_739X(a) (IS_7395(a) || IS_7398(a))
 
 #define VSC73XX_POLL_SLEEP_US		1000
+#define VSC73XX_MDIO_POLL_SLEEP_US	5
 #define VSC73XX_POLL_TIMEOUT_US		10000
 
 struct vsc73xx_counter {
@@ -545,6 +546,22 @@ static int vsc73xx_detect(struct vsc73xx *vsc)
 	return 0;
 }
 
+static int vsc73xx_mdio_busy_check(struct vsc73xx *vsc)
+{
+	int ret, err;
+	u32 val;
+
+	ret = read_poll_timeout(vsc73xx_read, err,
+				err < 0 || !(val & VSC73XX_MII_STAT_BUSY),
+				VSC73XX_MDIO_POLL_SLEEP_US,
+				VSC73XX_POLL_TIMEOUT_US, false, vsc,
+				VSC73XX_BLOCK_MII, VSC73XX_BLOCK_MII_INTERNAL,
+				VSC73XX_MII_STAT, &val);
+	if (ret)
+		return ret;
+	return err;
+}
+
 static int vsc73xx_phy_read(struct dsa_switch *ds, int phy, int regnum)
 {
 	struct vsc73xx *vsc = ds->priv;
@@ -552,6 +569,10 @@ static int vsc73xx_phy_read(struct dsa_switch *ds, int phy, int regnum)
 	u32 val;
 	int ret;
 
+	ret = vsc73xx_mdio_busy_check(vsc);
+	if (ret)
+		return ret;
+
 	/* Setting bit 26 means "read" */
 	cmd = VSC73XX_MII_CMD_OPERATION |
 	      FIELD_PREP(VSC73XX_MII_CMD_PHY_ADDR, phy) |
@@ -560,7 +581,11 @@ static int vsc73xx_phy_read(struct dsa_switch *ds, int phy, int regnum)
 			    VSC73XX_MII_CMD, cmd);
 	if (ret)
 		return ret;
-	msleep(2);
+
+	ret = vsc73xx_mdio_busy_check(vsc);
+	if (ret)
+		return ret;
+
 	ret = vsc73xx_read(vsc, VSC73XX_BLOCK_MII, VSC73XX_BLOCK_MII_INTERNAL,
 			   VSC73XX_MII_DATA, &val);
 	if (ret)
@@ -583,7 +608,11 @@ static int vsc73xx_phy_write(struct dsa_switch *ds, int phy, int regnum,
 {
 	struct vsc73xx *vsc = ds->priv;
 	u32 cmd;
-	int ret;
+	int ret = 0;
+
+	ret = vsc73xx_mdio_busy_check(vsc);
+	if (ret)
+		return ret;
 
 	/* It was found through tedious experiments that this router
 	 * chip really hates to have it's PHYs reset. They
-- 
2.34.1


  parent reply	other threads:[~2024-08-02  8:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-02  8:03 [PATCH net 0/6] net: dsa: vsc73xx: fix MDIO bus access and PHY operations Pawel Dembicki
2024-08-02  8:03 ` [PATCH net 1/6] net: dsa: vsc73xx: fix port MAC configuration in full duplex mode Pawel Dembicki
2024-08-02 20:58   ` Linus Walleij
2024-08-02 21:54   ` Florian Fainelli
2024-08-02 23:12   ` Andrew Lunn
2024-08-02  8:03 ` [PATCH net 2/6] net: dsa: vsc73xx: pass value in phy_write operation Pawel Dembicki
2024-08-02 20:59   ` Linus Walleij
2024-08-02 21:02   ` Linus Walleij
2024-08-02 21:53   ` Florian Fainelli
2024-08-02  8:04 ` [PATCH net 3/6] net: dsa: vsc73xx: use defined values in phy operations Pawel Dembicki
2024-08-02 21:03   ` Linus Walleij
2024-08-02 21:57   ` Florian Fainelli
2024-08-02 22:15   ` Vladimir Oltean
2024-08-04 23:08     ` Paweł Dembicki
2024-08-02  8:04 ` Pawel Dembicki [this message]
2024-08-02 21:04   ` [PATCH net 4/6] net: dsa: vsc73xx: check busy flag in MDIO operations Linus Walleij
2024-08-02 21:54   ` Florian Fainelli
2024-08-02  8:04 ` [PATCH net 5/6] net: dsa: vsc73xx: allow phy resetting Pawel Dembicki
2024-08-02 13:01   ` Russell King (Oracle)
2024-08-02 21:07   ` Linus Walleij
2024-08-02 21:55   ` Florian Fainelli
2024-08-02  8:04 ` [PATCH net 6/6] net: phy: vitesse: repair vsc73xx autonegotiation Pawel Dembicki
2024-08-02 13:03   ` Russell King (Oracle)
2024-08-02 20:40     ` Paweł Dembicki
2024-08-02 21:08   ` Linus Walleij

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=20240802080403.739509-5-paweldembicki@gmail.com \
    --to=paweldembicki@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.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

all inboxes | Powered by JetHome®