From: Xu Liang <lxu@maxlinear.com>
To: <andrew@lunn.ch>, <hkallweit1@gmail.com>,
<netdev@vger.kernel.org>, <davem@davemloft.net>,
<kuba@kernel.org>
Cc: <linux@armlinux.org.uk>, <hmehrtens@maxlinear.com>,
<tmohren@maxlinear.com>, <rtanwar@maxlinear.com>,
<mohammad.athari.ismail@intel.com>, <edumazet@google.com>,
<michael@walle.cc>, <pabeni@redhat.com>,
Xu Liang <lxu@maxlinear.com>
Subject: [PATCH net-next v5] net: phy: mxl-gpy: enhance delay time required by loopback disable function
Date: Wed, 15 Mar 2023 00:30:23 +0800 [thread overview]
Message-ID: <20230314163023.36637-1-lxu@maxlinear.com> (raw)
GPY2xx devices need 3 seconds to fully switch out of loopback mode
before it can safely re-enter loopback mode. Implement timeout mechanism
to guarantee 3 seconds waited before re-enter loopback mode.
Signed-off-by: Xu Liang <lxu@maxlinear.com>
---
v2 changes:
Update comments.
v3 changes:
Submit for net-next.
v4 changes:
Implement timeout mechanism as re-enter loopback mode is quite rare use case.
The delay is not required to resume normal function.
v5 changes:
Fix race condition introduced in v4.
Remove the bool variable lb_dis_chk added in v4.
drivers/net/phy/mxl-gpy.c | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c
index e5972b4ef6e8..8e6bb97b5f85 100644
--- a/drivers/net/phy/mxl-gpy.c
+++ b/drivers/net/phy/mxl-gpy.c
@@ -107,6 +107,13 @@ struct gpy_priv {
u8 fw_major;
u8 fw_minor;
+
+ /* It takes 3 seconds to fully switch out of loopback mode before
+ * it can safely re-enter loopback mode. Record the time when
+ * loopback is disabled. Check and wait if necessary before loopback
+ * is enabled.
+ */
+ u64 lb_dis_to;
};
static const struct {
@@ -769,18 +776,34 @@ static void gpy_get_wol(struct phy_device *phydev,
static int gpy_loopback(struct phy_device *phydev, bool enable)
{
+ struct gpy_priv *priv = phydev->priv;
+ u16 set = 0;
int ret;
- ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
- enable ? BMCR_LOOPBACK : 0);
- if (!ret) {
- /* It takes some time for PHY device to switch
- * into/out-of loopback mode.
+ if (enable) {
+ u64 now = get_jiffies_64();
+
+ /* wait until 3 seconds from last disable */
+ if (time_before64(now, priv->lb_dis_to))
+ msleep(jiffies64_to_msecs(priv->lb_dis_to - now));
+
+ set = BMCR_LOOPBACK;
+ }
+
+ ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, set);
+ if (ret <= 0)
+ return ret;
+
+ if (enable) {
+ /* It takes some time for PHY device to switch into
+ * loopback mode.
*/
msleep(100);
+ } else {
+ priv->lb_dis_to = get_jiffies_64() + HZ * 3;
}
- return ret;
+ return 0;
}
static int gpy115_loopback(struct phy_device *phydev, bool enable)
--
2.17.1
next reply other threads:[~2023-03-14 16:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-14 16:30 Xu Liang [this message]
2023-03-16 17:40 ` [PATCH net-next v5] net: phy: mxl-gpy: enhance delay time required by loopback disable function patchwork-bot+netdevbpf
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=20230314163023.36637-1-lxu@maxlinear.com \
--to=lxu@maxlinear.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=hmehrtens@maxlinear.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=michael@walle.cc \
--cc=mohammad.athari.ismail@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rtanwar@maxlinear.com \
--cc=tmohren@maxlinear.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).