net: phy: mxl-gpy: enhance delay time required by loopback disable function
Subsystems (4)
Xu Liang
maintainerPATCH v4 1/1 net: phy: mxl-gpy: enhance delay time required by loopback disable function
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.
---
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.
drivers/net/phy/mxl-gpy.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-)
drivers/net/phy/mxl-gpy.c +30 -6
@@ -107,6 +107,14 @@ 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. +*/ +bool lb_dis_chk; +u64 lb_dis_to; }; static const struct {
@@ -769,18 +777,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) { +/* wait until 3 seconds from last disable */ +if (priv->lb_dis_chk &&time_is_after_jiffies64 (priv->lb_dis_to)) +msleep (jiffies64_to_msecs (priv->lb_dis_to -get_jiffies_64 ())); + + priv->lb_dis_chk = false; + set =BMCR_LOOPBACK ; + } + + ret =phy_modify (phydev,MII_BMCR ,BMCR_LOOPBACK , set); +if (ret) +return ret; + +if (enable) { +/* It takes some time for PHY device to switch into +* loopback mode. */ msleep (100 ); + }else { + priv->lb_dis_chk = true; + priv->lb_dis_to =get_jiffies_64 () +HZ *3 ; } -return ret; +return 0 ; }static int gpy115_loopback (struct phy_device *phydev,bool enable)
Signature · 1 line
2.17.1
Andrew Lunn
maintainerdrivers/net/phy/mxl-gpy.c struct gpy_priv { · line 115
Quoted 5 lines
drivers/net/phy/mxl-gpy.c +5
-0+/* 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. +*/
Is there are restriction about entering loopback mode within the first 3 seconds after power on?
Quoted 15 lines
drivers/net/phy/mxl-gpy.c +4
-2+bool lb_dis_chk; +u64 lb_dis_to; }; static const struct {@@ -769,18 +777,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 );
drivers/net/phy/mxl-gpy.c static void gpy_get_wol(struct phy_device *phydev, · line 790
Quoted 10 lines
drivers/net/phy/mxl-gpy.c +7
-3-if (!ret) { -/* It takes some time for PHY device to switch -* into/out-of loopback mode. +if (enable) { +/* wait until 3 seconds from last disable */ +if (priv->lb_dis_chk &&time_is_after_jiffies64 (priv->lb_dis_to)) +msleep (jiffies64_to_msecs (priv->lb_dis_to -get_jiffies_64 ())); + + priv->lb_dis_chk = false; + set =BMCR_LOOPBACK ;
Maybe this can be simplified by setting priv->lb_dis_to = get_jiffies_64() + HZ * 3 in _probe(). Then you don't need priv->lb_dis_chk.
Andrew
Am 2023-03-14 14:50, schrieb Andrew Lunn:
Quoted 23 lines
drivers/net/phy/mxl-gpy.c struct gpy_priv { · line 115
Quoted 5 lines
drivers/net/phy/mxl-gpy.c +5
-0+/* 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. +*/ Is there are restriction about entering loopback mode within the first 3 seconds after power on?
Quoted 14 lines
drivers/net/phy/mxl-gpy.c +4
-0+bool lb_dis_chk; +u64 lb_dis_to; }; static const struct {@@ -769,18 +777,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;
Quoted 16 lines
drivers/net/phy/mxl-gpy.c static void gpy_get_wol(struct phy_device *phydev, · line 790
Quoted 12 lines
drivers/net/phy/mxl-gpy.c +7
-5- 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) { +/* wait until 3 seconds from last disable */ +if (priv->lb_dis_chk &&time_is_after_jiffies64 (priv->lb_dis_to)) +msleep (jiffies64_to_msecs (priv->lb_dis_to -get_jiffies_64 ())); + + priv->lb_dis_chk = false; + set =BMCR_LOOPBACK ;Maybe this can be simplified by setting
priv->lb_dis_to=get_jiffies_64()+ HZ * 3 in_probe(). Then you don't needpriv->lb_dis_chk.
First, I wonder if this is worth the effort and code complications. phy_loopback() seem to be used very seldom. Anyway.
Can't we just save the jiffies on last enable as kind of a timestamp. If it's 0 you know it wasn't called yet and if it's set, you have to at least wait for until it is after "jiffies + HZ*3".
Also isn't that racy right now? "priv->lb_dis_to - get_jiffies_64())" can get negative, no?
-michael
Liang Xu
maintainerQuoted 49 lines · Michael Walle
This email was sent from outside of MaxLinear.
Am 2023-03-14 14:50, schrieb Andrew Lunn:
Quoted 33 lines
Quoted 6 lines
+ /* 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.
+ */Is there are restriction about entering loopback mode within the first 3 seconds after power on?
Quoted 23 lines
+ bool
lb_dis_chk;
+ u64lb_dis_to;
};static const struct {
drivers/net/phy/mxl-gpy.c +5
-5@@ -769,18 +777,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) { + /* wait until 3 seconds from last disable */ + if (priv->lb_dis_chk &&time_is_after_jiffies64 (priv->lb_dis_to))Quoted 8 lines
drivers/net/phy/mxl-gpy.c static void gpy_get_wol(struct phy_device *phydev, · line 790
Quoted 4 lines
drivers/net/phy/mxl-gpy.c +4
-0+msleep (jiffies64_to_msecs (priv->lb_dis_to -get_jiffies_64 ())); + + priv->lb_dis_chk = false; + set = BMCR_LOOPBACK;Maybe this can be simplified by setting
priv->lb_dis_to=get_jiffies_64()+ HZ * 3 in_probe(). Then you don't needpriv->lb_dis_chk.First, I wonder if this is worth the effort and code complications.
phy_loopback()seem to be used very seldom. Anyway.
Quoted 8 lines
Can't we just save the jiffies on last enable as kind of a timestamp. If it's 0 you know it wasn't called yet and if it's set, you have to at least wait for until it is after "jiffies + HZ*3".
Also isn't that racy right now? "
priv->lb_dis_to-get_jiffies_64())" can
get negative, no?
Yes, this is a bug. I will fix.
Also use jiffies only.
There is no restriction to enter loopback mode for first 3 seconds.
Quoted 2 lines
-michael