* [PATCH net v2 1/5] net: dsa: vsc73xx: fix port MAC configuration in full duplex mode
2024-08-05 21:10 [PATCH net v2 0/5] net: dsa: vsc73xx: fix MDIO bus access and PHY operations Pawel Dembicki
@ 2024-08-05 21:10 ` Pawel Dembicki
2024-08-05 21:10 ` [PATCH net v2 2/5] net: dsa: vsc73xx: pass value in phy_write operation Pawel Dembicki
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Pawel Dembicki @ 2024-08-05 21:10 UTC (permalink / raw)
To: netdev
Cc: Pawel Dembicki, Linus Walleij, Florian Fainelli, Andrew Lunn,
Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Heiner Kallweit, Russell King,
linux-kernel
According to the datasheet description ("Port Mode Procedure" in 5.6.2),
the VSC73XX_MAC_CFG_WEXC_DIS bit is configured only for half duplex mode.
The WEXC_DIS bit is responsible for MAC behavior after an excessive
collision. Let's set it as described in the datasheet.
Fixes: 05bd97fc559d ("net: dsa: Add Vitesse VSC73xx DSA router driver")
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
---
v2:
- Added 'Fixes' and 'Reviewed-by' to commit message.
This patch came from net-next series[0].
Changes since net-next:
- rebased to netdev/main only
[0] https://patchwork.kernel.org/project/netdevbpf/patch/20240729210615.279952-6-paweldembicki@gmail.com/
---
drivers/net/dsa/vitesse-vsc73xx-core.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index d9d3e30fd47a..f548ed4cb23f 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -957,6 +957,11 @@ static void vsc73xx_mac_link_up(struct phylink_config *config,
if (duplex == DUPLEX_FULL)
val |= VSC73XX_MAC_CFG_FDX;
+ else
+ /* In datasheet description ("Port Mode Procedure" in 5.6.2)
+ * this bit is configured only for half duplex.
+ */
+ val |= VSC73XX_MAC_CFG_WEXC_DIS;
/* This routine is described in the datasheet (below ARBDISC register
* description)
@@ -967,7 +972,6 @@ static void vsc73xx_mac_link_up(struct phylink_config *config,
get_random_bytes(&seed, 1);
val |= seed << VSC73XX_MAC_CFG_SEED_OFFSET;
val |= VSC73XX_MAC_CFG_SEED_LOAD;
- val |= VSC73XX_MAC_CFG_WEXC_DIS;
/* Those bits are responsible for MTU only. Kernel takes care about MTU,
* let's enable +8 bytes frame length unconditionally.
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH net v2 2/5] net: dsa: vsc73xx: pass value in phy_write operation
2024-08-05 21:10 [PATCH net v2 0/5] net: dsa: vsc73xx: fix MDIO bus access and PHY operations Pawel Dembicki
2024-08-05 21:10 ` [PATCH net v2 1/5] net: dsa: vsc73xx: fix port MAC configuration in full duplex mode Pawel Dembicki
@ 2024-08-05 21:10 ` Pawel Dembicki
2024-08-05 21:10 ` [PATCH net v2 3/5] net: dsa: vsc73xx: check busy flag in MDIO operations Pawel Dembicki
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Pawel Dembicki @ 2024-08-05 21:10 UTC (permalink / raw)
To: netdev
Cc: Pawel Dembicki, Linus Walleij, Florian Fainelli, Andrew Lunn,
Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Heiner Kallweit, Russell King,
linux-kernel
In the 'vsc73xx_phy_write' function, the register value is missing,
and the phy write operation always sends zeros.
This commit passes the value variable into the proper register.
Fixes: 05bd97fc559d ("net: dsa: Add Vitesse VSC73xx DSA router driver")
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
---
v2:
- Fixed 'Fixes' and added 'Reviewed-by' to commit message
This patch came from net-next series[0].
Changes since net-next:
- rebased to netdev/main only
[0] https://patchwork.kernel.org/project/netdevbpf/patch/20240729210615.279952-6-paweldembicki@gmail.com/
---
drivers/net/dsa/vitesse-vsc73xx-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index f548ed4cb23f..4b300c293dec 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -574,7 +574,7 @@ static int vsc73xx_phy_write(struct dsa_switch *ds, int phy, int regnum,
return 0;
}
- cmd = (phy << 21) | (regnum << 16);
+ cmd = (phy << 21) | (regnum << 16) | val;
ret = vsc73xx_write(vsc, VSC73XX_BLOCK_MII, 0, 1, cmd);
if (ret)
return ret;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH net v2 3/5] net: dsa: vsc73xx: check busy flag in MDIO operations
2024-08-05 21:10 [PATCH net v2 0/5] net: dsa: vsc73xx: fix MDIO bus access and PHY operations Pawel Dembicki
2024-08-05 21:10 ` [PATCH net v2 1/5] net: dsa: vsc73xx: fix port MAC configuration in full duplex mode Pawel Dembicki
2024-08-05 21:10 ` [PATCH net v2 2/5] net: dsa: vsc73xx: pass value in phy_write operation Pawel Dembicki
@ 2024-08-05 21:10 ` Pawel Dembicki
2024-08-08 3:09 ` Jakub Kicinski
2024-08-05 21:10 ` [PATCH net v2 4/5] net: dsa: vsc73xx: allow phy resetting Pawel Dembicki
2024-08-05 21:10 ` [PATCH net v2 5/5] net: phy: vitesse: repair vsc73xx autonegotiation Pawel Dembicki
4 siblings, 1 reply; 8+ messages in thread
From: Pawel Dembicki @ 2024-08-05 21:10 UTC (permalink / raw)
To: netdev
Cc: Pawel Dembicki, Linus Walleij, Florian Fainelli, Andrew Lunn,
Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Heiner Kallweit, Russell King,
linux-kernel
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.
Fixes: 05bd97fc559d ("net: dsa: Add Vitesse VSC73xx DSA router driver")
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
---
v2:
- used defines from patch moved to net-next
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 | 40 ++++++++++++++++++++++++--
1 file changed, 38 insertions(+), 2 deletions(-)
diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index 4b300c293dec..a9378e0512d8 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -40,6 +40,10 @@
#define VSC73XX_BLOCK_ARBITER 0x5 /* Only subblock 0 */
#define VSC73XX_BLOCK_SYSTEM 0x7 /* Only subblock 0 */
+/* MII Block subblock */
+#define VSC73XX_BLOCK_MII_INTERNAL 0x0 /* Internal MDIO subblock */
+#define VSC73XX_BLOCK_MII_EXTERNAL 0x1 /* External MDIO subblock */
+
#define CPU_PORT 6 /* CPU port */
/* MAC Block registers */
@@ -225,6 +229,8 @@
#define VSC73XX_MII_CMD 0x1
#define VSC73XX_MII_DATA 0x2
+#define VSC73XX_MII_STAT_BUSY BIT(3)
+
/* Arbiter block 5 registers */
#define VSC73XX_ARBEMPTY 0x0c
#define VSC73XX_ARBDISC 0x0e
@@ -299,6 +305,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 {
@@ -527,6 +534,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;
@@ -534,13 +557,22 @@ 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 = BIT(26) | (phy << 21) | (regnum << 16);
ret = vsc73xx_write(vsc, VSC73XX_BLOCK_MII, 0, 1, cmd);
if (ret)
return ret;
- msleep(2);
+
+ ret = vsc73xx_mdio_busy_check(vsc);
+ if (ret)
+ return ret;
+
ret = vsc73xx_read(vsc, VSC73XX_BLOCK_MII, 0, 2, &val);
+
if (ret)
return ret;
if (val & BIT(16)) {
@@ -561,7 +593,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
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH net v2 3/5] net: dsa: vsc73xx: check busy flag in MDIO operations
2024-08-05 21:10 ` [PATCH net v2 3/5] net: dsa: vsc73xx: check busy flag in MDIO operations Pawel Dembicki
@ 2024-08-08 3:09 ` Jakub Kicinski
0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2024-08-08 3:09 UTC (permalink / raw)
To: Pawel Dembicki
Cc: netdev, Linus Walleij, Florian Fainelli, Andrew Lunn,
Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Paolo Abeni, Heiner Kallweit, Russell King, linux-kernel
On Mon, 5 Aug 2024 23:10:29 +0200 Pawel Dembicki wrote:
> - msleep(2);
> +
> + ret = vsc73xx_mdio_busy_check(vsc);
> + if (ret)
> + return ret;
> +
> ret = vsc73xx_read(vsc, VSC73XX_BLOCK_MII, 0, 2, &val);
> +
> if (ret)
nit: why the empty line between call and error check?
> return ret;
> if (val & BIT(16)) {
> @@ -561,7 +593,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);
nit: why init ret to 0 ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net v2 4/5] net: dsa: vsc73xx: allow phy resetting
2024-08-05 21:10 [PATCH net v2 0/5] net: dsa: vsc73xx: fix MDIO bus access and PHY operations Pawel Dembicki
` (2 preceding siblings ...)
2024-08-05 21:10 ` [PATCH net v2 3/5] net: dsa: vsc73xx: check busy flag in MDIO operations Pawel Dembicki
@ 2024-08-05 21:10 ` Pawel Dembicki
2024-08-05 21:10 ` [PATCH net v2 5/5] net: phy: vitesse: repair vsc73xx autonegotiation Pawel Dembicki
4 siblings, 0 replies; 8+ messages in thread
From: Pawel Dembicki @ 2024-08-05 21:10 UTC (permalink / raw)
To: netdev
Cc: Pawel Dembicki, Linus Walleij, Florian Fainelli, Andrew Lunn,
Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Heiner Kallweit, Russell King,
linux-kernel
Resetting the VSC73xx PHY was problematic because the MDIO bus, without
a busy check, read and wrote incorrect register values.
My investigation indicates that resetting the PHY only triggers changes
in configuration. However, improper register values written earlier
were only exposed after a soft reset.
The reset itself wasn't the issue; rather, the problem stemmed from
incorrect read and write operations.
A 'soft_reset' can now proceed normally. There are no reasons to keep
the VSC73xx from being reset.
This commit removes the reset blockade in the 'vsc73xx_phy_write'
function.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
---
v2:
- improved commit description
This patch came from net-next series[0].
Changes since net-next:
- rebased to netdev/main only
[0] https://patchwork.kernel.org/project/netdevbpf/patch/20240729210615.279952-6-paweldembicki@gmail.com/
---
drivers/net/dsa/vitesse-vsc73xx-core.c | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index a9378e0512d8..ac02927a153b 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -599,17 +599,6 @@ static int vsc73xx_phy_write(struct dsa_switch *ds, int phy, int regnum,
if (ret)
return ret;
- /* It was found through tedious experiments that this router
- * chip really hates to have it's PHYs reset. They
- * never recover if that happens: autonegotiation stops
- * working after a reset. Just filter out this command.
- * (Resetting the whole chip is OK.)
- */
- if (regnum == 0 && (val & BIT(15))) {
- dev_info(vsc->dev, "reset PHY - disallowed\n");
- return 0;
- }
-
cmd = (phy << 21) | (regnum << 16) | val;
ret = vsc73xx_write(vsc, VSC73XX_BLOCK_MII, 0, 1, cmd);
if (ret)
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH net v2 5/5] net: phy: vitesse: repair vsc73xx autonegotiation
2024-08-05 21:10 [PATCH net v2 0/5] net: dsa: vsc73xx: fix MDIO bus access and PHY operations Pawel Dembicki
` (3 preceding siblings ...)
2024-08-05 21:10 ` [PATCH net v2 4/5] net: dsa: vsc73xx: allow phy resetting Pawel Dembicki
@ 2024-08-05 21:10 ` Pawel Dembicki
2024-08-08 3:09 ` Jakub Kicinski
4 siblings, 1 reply; 8+ messages in thread
From: Pawel Dembicki @ 2024-08-05 21:10 UTC (permalink / raw)
To: netdev
Cc: Pawel Dembicki, Linus Walleij, Andrew Lunn, Florian Fainelli,
Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Heiner Kallweit, Russell King, linux-kernel
When the vsc73xx mdio bus work properly, the generic autonegotiation
configuration works well.
Vsc73xx have auto MDI-X disabled by default in forced mode. This commit
enables it.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
---
This patch came from net-next series[0].
Changes since net-next:
- rebased to netdev/main only
[0] https://patchwork.kernel.org/project/netdevbpf/patch/20240729210615.279952-6-paweldembicki@gmail.com/
---
drivers/net/phy/vitesse.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/vitesse.c b/drivers/net/phy/vitesse.c
index 897b979ec03c..19b7bf189be5 100644
--- a/drivers/net/phy/vitesse.c
+++ b/drivers/net/phy/vitesse.c
@@ -60,6 +60,11 @@
/* Vitesse Extended Page Access Register */
#define MII_VSC82X4_EXT_PAGE_ACCESS 0x1f
+/* VSC73XX PHY_BYPASS_CTRL register*/
+#define MII_VSC73XX_PHY_BYPASS_CTRL MII_DCOUNTER
+#define MII_PBC_FORCED_SPEED_AUTO_MDIX_DIS BIT(7)
+#define MII_VSC73XX_PBC_AUTO_NP_EXCHANGE_DIS BIT(1)
+
/* Vitesse VSC8601 Extended PHY Control Register 1 */
#define MII_VSC8601_EPHY_CTL 0x17
#define MII_VSC8601_EPHY_CTL_RGMII_SKEW (1 << 8)
@@ -239,12 +244,20 @@ static int vsc739x_config_init(struct phy_device *phydev)
static int vsc73xx_config_aneg(struct phy_device *phydev)
{
- /* The VSC73xx switches does not like to be instructed to
- * do autonegotiation in any way, it prefers that you just go
- * with the power-on/reset defaults. Writing some registers will
- * just make autonegotiation permanently fail.
- */
- return 0;
+ int ret;
+
+ /* Enable Auto MDI-X in forced 10/100 mode */
+ if (phydev->autoneg != AUTONEG_ENABLE && phydev->speed <= SPEED_100) {
+ ret = genphy_setup_forced(phydev);
+
+ if (ret < 0) /* error */
+ return ret;
+
+ return phy_clear_bits(phydev, MII_VSC73XX_PHY_BYPASS_CTRL,
+ MII_PBC_FORCED_SPEED_AUTO_MDIX_DIS);
+ }
+
+ return genphy_config_aneg(phydev);
}
/* This adds a skew for both TX and RX clocks, so the skew should only be
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH net v2 5/5] net: phy: vitesse: repair vsc73xx autonegotiation
2024-08-05 21:10 ` [PATCH net v2 5/5] net: phy: vitesse: repair vsc73xx autonegotiation Pawel Dembicki
@ 2024-08-08 3:09 ` Jakub Kicinski
0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2024-08-08 3:09 UTC (permalink / raw)
To: Pawel Dembicki
Cc: netdev, Linus Walleij, Andrew Lunn, Florian Fainelli,
Vladimir Oltean, David S. Miller, Eric Dumazet, Paolo Abeni,
Heiner Kallweit, Russell King, linux-kernel
On Mon, 5 Aug 2024 23:10:31 +0200 Pawel Dembicki wrote:
> When the vsc73xx mdio bus work properly, the generic autonegotiation
> configuration works well.
>
> Vsc73xx have auto MDI-X disabled by default in forced mode. This commit
> enables it.
This feels a bit like net-next material.
Never worked, so it's more new feature than a fix.
^ permalink raw reply [flat|nested] 8+ messages in thread