net: dsa: vsc73xx: fix MDIO bus access and PHY operations
Subsystems (4)
v2 cover net: dsa: vsc73xx: fix MDIO bus access and PHY operations
This series are extracted patches from net-next series [0].
The VSC73xx driver has issues with PHY configuration. This patch series fixes most of them.
The first patch synchronizes the register configuration routine with the datasheet recommendations.
Patches 2-3 restore proper communication on the MDIO bus. Currently, the write value isn't sent to the MDIO register, and without a busy check, communication with the PHY can be interrupted. This causes the PHY to receive improper configuration and autonegotiation could fail.
The fourth patch removes the PHY reset blockade, as it is no longer required.
After fixing the MDIO operations, autonegotiation became possible. The last patch removes the blockade, which became unnecessary after the MDIO operations fix. It also enables the MDI-X feature, which is disabled by default in forced 100BASE-TX mode like other Vitesse PHYs.
[0] https://patchwork.kernel.org/project/netdevbpf/list/?series=874739&state=%2A&archive=both
Pawel Dembicki (5):
net: dsa: vsc73xx: fix port MAC configuration in full duplex mode
net: dsa: vsc73xx: pass value in phy_write operation
net: dsa: vsc73xx: check busy flag in MDIO operations
net: dsa: vsc73xx: allow phy resetting
net: phy: vitesse: repair vsc73xx autonegotiation
drivers/net/dsa/vitesse-vsc73xx-core.c | 57 +++++++++++++++++++------- drivers/net/phy/vitesse.c | 25 ++++++++--- 2 files changed, 62 insertions(+), 20 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/5 net: dsa: vsc73xx: fix port MAC configuration in full duplex mode
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.
---
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/[email protected]/
--- drivers/net/dsa/vitesse-vsc73xx-core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +5 -1
@@ -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.
Signature · 1 line
2.34.1
PATCH v2 2/5 net: dsa: vsc73xx: pass value in phy_write operation
In reply to Pawel DembickiIn 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.
---
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/[email protected]/
--- drivers/net/dsa/vitesse-vsc73xx-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +1 -1
@@ -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;
Signature · 1 line
2.34.1
PATCH v2 3/5 net: dsa: vsc73xx: check busy flag in MDIO operations
In reply to Pawel DembickiThe 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.
---
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/[email protected]/
--- drivers/net/dsa/vitesse-vsc73xx-core.c | 40 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +38 -2
@@ -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 10000struct 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
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerRe: [PATCH net v2 3/5] net: dsa: vsc73xx: check busy flag in MDIO operations
drivers/net/dsa/vitesse-vsc73xx-core.c static int vsc73xx_phy_read(struct dsa_switch *ds, int phy, int regnum) · line 576
Quoted 9 lines · On Mon, 5 Aug 2024 23:10:29 +0200 Pawel Dembicki wrote:
drivers/net/dsa/vitesse-vsc73xx-core.c +6
-1-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?
drivers/net/dsa/vitesse-vsc73xx-core.c static int vsc73xx_phy_write(struct dsa_switch *ds, int phy, int regnum, · line 598
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +3
-1return 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 ?
PATCH v2 4/5 net: dsa: vsc73xx: allow phy resetting
In reply to Pawel DembickiResetting 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.
---
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/[email protected]/
--- drivers/net/dsa/vitesse-vsc73xx-core.c | 11 ----------- 1 file changed, 11 deletions(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +0 -11
@@ -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)
Signature · 1 line
2.34.1
PATCH v2 5/5 net: phy: vitesse: repair vsc73xx autonegotiation
In reply to Pawel DembickiWhen 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 patch came from net-next series[0].
Changes since net-next:
- rebased to netdev/main only
[0] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
--- drivers/net/phy/vitesse.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/net/phy/vitesse.c +19 -6
@@ -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
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerRe: [PATCH net v2 5/5] net: phy: vitesse: repair vsc73xx autonegotiation
Quoted 5 lines · 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.