net: dsa: vsc73xx: fix MDIO bus access and PHY operations
Subsystems (4)
v3 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.
[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 | 54 +++++++++++++++++++------- drivers/net/phy/vitesse.c | 14 ------- 2 files changed, 41 insertions(+), 27 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 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.
---
v3:
- resend only
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 v3 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.
---
v3:
- resend only
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 v3 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.
---
v3:
- removed blank line and unnecessary variable init
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 | 37 +++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +36 -1
@@ -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,12 +557,20 @@ 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;
@@ -563,6 +594,10 @@ static int vsc73xx_phy_write(struct dsa_switch *ds, int phy, int regnum,u32 cmd;int ret; + 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 * never recover if that happens: autonegotiation stops
Signature · 1 line
2.34.1
PATCH v3 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.
---
v3:
- resend only
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
@@ -598,17 +598,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 v3 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.
---
v3:
- removed MDI-X with disabled autoneg feature (it will goes to net-next in future)
v2:
- resend only
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 | 14 -------------- 1 file changed, 14 deletions(-)
drivers/net/phy/vitesse.c +0 -14
@@ -237,16 +237,6 @@ static int vsc739x_config_init(struct phy_device *phydev)return 0 ; } -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 ; -} -/* This adds a skew for both TX and RX clocks, so the skew should only be * applied to "rgmii-id" interfaces. It may not work as expected * on "rgmii-txid", "rgmii-rxid" or "rgmii" interfaces.
@@ -444,7 +434,6 @@ static struct phy_driver vsc82xx_driver[] = { .phy_id_mask = 0x000ffff0, /* PHY_GBIT_FEATURES */ .config_init = vsc738x_config_init, - .config_aneg = vsc73xx_config_aneg, .read_page = vsc73xx_read_page, .write_page = vsc73xx_write_page, }, {
@@ -453,7 +442,6 @@ static struct phy_driver vsc82xx_driver[] = { .phy_id_mask = 0x000ffff0, /* PHY_GBIT_FEATURES */ .config_init = vsc738x_config_init, - .config_aneg = vsc73xx_config_aneg, .read_page = vsc73xx_read_page, .write_page = vsc73xx_write_page, }, {
@@ -462,7 +450,6 @@ static struct phy_driver vsc82xx_driver[] = { .phy_id_mask = 0x000ffff0, /* PHY_GBIT_FEATURES */ .config_init = vsc739x_config_init, - .config_aneg = vsc73xx_config_aneg, .read_page = vsc73xx_read_page, .write_page = vsc73xx_write_page, }, {
@@ -471,7 +458,6 @@ static struct phy_driver vsc82xx_driver[] = { .phy_id_mask = 0x000ffff0, /* PHY_GBIT_FEATURES */ .config_init = vsc739x_config_init, - .config_aneg = vsc73xx_config_aneg, .read_page = vsc73xx_read_page, .write_page = vsc73xx_write_page, }, {
Signature · 1 line
2.34.1
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 9 lines · On Fri, 9 Aug 2024 21:38:01 +0200 you wrote:
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.
[...]
Here is the summary with links:
- [net,v3,1/5] net: dsa: vsc73xx: fix port MAC configuration in full duplex mode
https://git.kernel.org/netdev/net/c/63796bc2e97c - [net,v3,2/5] net: dsa: vsc73xx: pass value in phy_write operation https://git.kernel.org/netdev/net/c/5b9eebc2c7a5 - [net,v3,3/5] net: dsa: vsc73xx: check busy flag in MDIO operations https://git.kernel.org/netdev/net/c/fa63c6434b6f - [net,v3,4/5] net: dsa: vsc73xx: allow phy resetting https://git.kernel.org/netdev/net/c/9f9a72654622 - [net,v3,5/5] net: phy: vitesse: repair vsc73xx autonegotiation https://git.kernel.org/netdev/net/c/de7a670f8def
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html