diff mbox series

[net] net: mdio: mdio-bitbang: Fix C45 read/write protocol

Message ID 20230816180656.18780-1-fancer.lancer@gmail.com (mailing list archive)
State Accepted
Commit 2572ce62415cf3b632391091447252e2661ed520
Delegated to: Netdev Maintainers
Headers show
Series [net] net: mdio: mdio-bitbang: Fix C45 read/write protocol | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1328 this patch: 1328
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 1351 this patch: 1351
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1351 this patch: 1351
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Serge Semin Aug. 16, 2023, 6:06 p.m. UTC
Based on the original code semantic in case of Clause 45 MDIO, the address
command is supposed to be followed by the command sending the MMD address,
not the CSR address. The commit 002dd3de097c ("net: mdio: mdio-bitbang:
Separate C22 and C45 transactions") has erroneously broken that. So most
likely due to an unfortunate variable name it switched the code to sending
the CSR address. In our case it caused the protocol malfunction so the
read operation always failed with the turnaround bit always been driven to
one by PHY instead of zero. Fix that by getting back the correct
behaviour: sending MMD address command right after the regular address
command.

Fixes: 002dd3de097c ("net: mdio: mdio-bitbang: Separate C22 and C45 transactions")
Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
---
 drivers/net/mdio/mdio-bitbang.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrew Lunn Aug. 16, 2023, 7:39 p.m. UTC | #1
On Wed, Aug 16, 2023 at 09:06:52PM +0300, Serge Semin wrote:
> Based on the original code semantic in case of Clause 45 MDIO, the address
> command is supposed to be followed by the command sending the MMD address,
> not the CSR address. The commit 002dd3de097c ("net: mdio: mdio-bitbang:
> Separate C22 and C45 transactions") has erroneously broken that. So most
> likely due to an unfortunate variable name it switched the code to sending
> the CSR address. In our case it caused the protocol malfunction so the
> read operation always failed with the turnaround bit always been driven to
> one by PHY instead of zero. Fix that by getting back the correct
> behaviour: sending MMD address command right after the regular address
> command.

I'm actually surprised we have not got more reports of me breaking
MDIO with this patchset. I did test bit-banging, but only for C22.

> Fixes: 002dd3de097c ("net: mdio: mdio-bitbang: Separate C22 and C45 transactions")
> Signed-off-by: Serge Semin <fancer.lancer@gmail.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Serge Semin Aug. 16, 2023, 8:11 p.m. UTC | #2
On Wed, Aug 16, 2023 at 09:39:37PM +0200, Andrew Lunn wrote:
> On Wed, Aug 16, 2023 at 09:06:52PM +0300, Serge Semin wrote:
> > Based on the original code semantic in case of Clause 45 MDIO, the address
> > command is supposed to be followed by the command sending the MMD address,
> > not the CSR address. The commit 002dd3de097c ("net: mdio: mdio-bitbang:
> > Separate C22 and C45 transactions") has erroneously broken that. So most
> > likely due to an unfortunate variable name it switched the code to sending
> > the CSR address. In our case it caused the protocol malfunction so the
> > read operation always failed with the turnaround bit always been driven to
> > one by PHY instead of zero. Fix that by getting back the correct
> > behaviour: sending MMD address command right after the regular address
> > command.
> 

> I'm actually surprised we have not got more reports of me breaking
> MDIO with this patchset. I did test bit-banging, but only for C22.

Yeah, I was also surprised not to find any fixes or reports for more
than a half of year in the mailing list or in the commits log. I was
sitting on 6.4-rc1 when the problem was discovered. Seeing the problem
was easily reproducible I decided to get to the latest kernel before
get to debugging it. It didn't help. The problem remained in 6.5-rc4
too.

> 
> > Fixes: 002dd3de097c ("net: mdio: mdio-bitbang: Separate C22 and C45 transactions")
> > Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
> 
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>

Thanks.

-Serge(y)

> 
>     Andrew
patchwork-bot+netdevbpf@kernel.org Aug. 19, 2023, 11:51 a.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Wed, 16 Aug 2023 21:06:52 +0300 you wrote:
> Based on the original code semantic in case of Clause 45 MDIO, the address
> command is supposed to be followed by the command sending the MMD address,
> not the CSR address. The commit 002dd3de097c ("net: mdio: mdio-bitbang:
> Separate C22 and C45 transactions") has erroneously broken that. So most
> likely due to an unfortunate variable name it switched the code to sending
> the CSR address. In our case it caused the protocol malfunction so the
> read operation always failed with the turnaround bit always been driven to
> one by PHY instead of zero. Fix that by getting back the correct
> behaviour: sending MMD address command right after the regular address
> command.
> 
> [...]

Here is the summary with links:
  - [net] net: mdio: mdio-bitbang: Fix C45 read/write protocol
    https://git.kernel.org/netdev/net/c/2572ce62415c

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/mdio/mdio-bitbang.c b/drivers/net/mdio/mdio-bitbang.c
index b83932562be2..81b7748c10ce 100644
--- a/drivers/net/mdio/mdio-bitbang.c
+++ b/drivers/net/mdio/mdio-bitbang.c
@@ -186,7 +186,7 @@  int mdiobb_read_c45(struct mii_bus *bus, int phy, int devad, int reg)
 	struct mdiobb_ctrl *ctrl = bus->priv;
 
 	mdiobb_cmd_addr(ctrl, phy, devad, reg);
-	mdiobb_cmd(ctrl, MDIO_C45_READ, phy, reg);
+	mdiobb_cmd(ctrl, MDIO_C45_READ, phy, devad);
 
 	return mdiobb_read_common(bus, phy);
 }
@@ -222,7 +222,7 @@  int mdiobb_write_c45(struct mii_bus *bus, int phy, int devad, int reg, u16 val)
 	struct mdiobb_ctrl *ctrl = bus->priv;
 
 	mdiobb_cmd_addr(ctrl, phy, devad, reg);
-	mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, reg);
+	mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, devad);
 
 	return mdiobb_write_common(bus, val);
 }