public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: dsa: microchip: fix register write order in ksz8_ind_write8()
@ 2024-03-04 15:41 tobias.jakobi.compleo
  2024-03-05 11:40 ` [PATCH net] " Oleksij Rempel
  2024-03-06  3:20 ` [PATCH] " patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: tobias.jakobi.compleo @ 2024-03-04 15:41 UTC (permalink / raw)
  To: Woojung Huh
  Cc: UNGLinuxDriver, Andrew Lunn, Florian Fainelli, Vladimir Oltean,
	Oleksij Rempel, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel, Tobias Jakobi (Compleo)

From: "Tobias Jakobi (Compleo)" <tobias.jakobi.compleo@gmail.com>

This bug was noticed while re-implementing parts of the kernel
driver in userspace using spidev. The goal was to enable some
of the errata workarounds that Microchip describes in their
errata sheet [1].

Both the errata sheet and the regular datasheet of e.g. the KSZ8795
imply that you need to do this for indirect register accesses:
- write a 16-bit value to a control register pair (this value
  consists of the indirect register table, and the offset inside
  the table)
- either read or write an 8-bit value from the data storage
  register (indicated by REG_IND_BYTE in the kernel)

The current implementation has the order swapped. It can be
proven, by reading back some indirect register with known content
(the EEE register modified in ksz8_handle_global_errata() is one of
these), that this implementation does not work.

Private discussion with Oleksij Rempel of Pengutronix has revealed
that the workaround was apparantly never tested on actual hardware.

[1] https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/Errata/KSZ87xx-Errata-DS80000687C.pdf

Signed-off-by: Tobias Jakobi (Compleo) <tobias.jakobi.compleo@gmail.com>
---
 drivers/net/dsa/microchip/ksz8795.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 61b71bcfe396..c3da97abce20 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -49,9 +49,9 @@ static int ksz8_ind_write8(struct ksz_device *dev, u8 table, u16 addr, u8 data)
 	mutex_lock(&dev->alu_mutex);
 
 	ctrl_addr = IND_ACC_TABLE(table) | addr;
-	ret = ksz_write8(dev, regs[REG_IND_BYTE], data);
+	ret = ksz_write16(dev, regs[REG_IND_CTRL_0], ctrl_addr);
 	if (!ret)
-		ret = ksz_write16(dev, regs[REG_IND_CTRL_0], ctrl_addr);
+		ret = ksz_write8(dev, regs[REG_IND_BYTE], data);
 
 	mutex_unlock(&dev->alu_mutex);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: dsa: microchip: fix register write order in ksz8_ind_write8()
  2024-03-04 15:41 [PATCH] net: dsa: microchip: fix register write order in ksz8_ind_write8() tobias.jakobi.compleo
@ 2024-03-05 11:40 ` Oleksij Rempel
  2024-03-06  3:20 ` [PATCH] " patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2024-03-05 11:40 UTC (permalink / raw)
  To: tobias.jakobi.compleo
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Florian Fainelli,
	Vladimir Oltean, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel

On Mon, Mar 04, 2024 at 04:41:35PM +0100, tobias.jakobi.compleo@gmail.com wrote:
> From: "Tobias Jakobi (Compleo)" <tobias.jakobi.compleo@gmail.com>
> 
> This bug was noticed while re-implementing parts of the kernel
> driver in userspace using spidev. The goal was to enable some
> of the errata workarounds that Microchip describes in their
> errata sheet [1].
> 
> Both the errata sheet and the regular datasheet of e.g. the KSZ8795
> imply that you need to do this for indirect register accesses:
> - write a 16-bit value to a control register pair (this value
>   consists of the indirect register table, and the offset inside
>   the table)
> - either read or write an 8-bit value from the data storage
>   register (indicated by REG_IND_BYTE in the kernel)
> 
> The current implementation has the order swapped. It can be
> proven, by reading back some indirect register with known content
> (the EEE register modified in ksz8_handle_global_errata() is one of
> these), that this implementation does not work.
> 
> Private discussion with Oleksij Rempel of Pengutronix has revealed
> that the workaround was apparantly never tested on actual hardware.
> 
> [1] https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/Errata/KSZ87xx-Errata-DS80000687C.pdf
> 
> Signed-off-by: Tobias Jakobi (Compleo) <tobias.jakobi.compleo@gmail.com>

The subject should have [PATCH net] for stable and Fixes tag:
Fixes: 7b6e6235b664 ("net: dsa: microchip: ksz8795: handle eee specif erratum")

Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>

Thank you!
Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: dsa: microchip: fix register write order in ksz8_ind_write8()
  2024-03-04 15:41 [PATCH] net: dsa: microchip: fix register write order in ksz8_ind_write8() tobias.jakobi.compleo
  2024-03-05 11:40 ` [PATCH net] " Oleksij Rempel
@ 2024-03-06  3:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-06  3:20 UTC (permalink / raw)
  To: None
  Cc: woojung.huh, UNGLinuxDriver, andrew, f.fainelli, olteanv,
	o.rempel, davem, edumazet, kuba, pabeni, netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  4 Mar 2024 16:41:35 +0100 you wrote:
> From: "Tobias Jakobi (Compleo)" <tobias.jakobi.compleo@gmail.com>
> 
> This bug was noticed while re-implementing parts of the kernel
> driver in userspace using spidev. The goal was to enable some
> of the errata workarounds that Microchip describes in their
> errata sheet [1].
> 
> [...]

Here is the summary with links:
  - net: dsa: microchip: fix register write order in ksz8_ind_write8()
    https://git.kernel.org/netdev/net/c/b7fb7729c94f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-06  3:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-04 15:41 [PATCH] net: dsa: microchip: fix register write order in ksz8_ind_write8() tobias.jakobi.compleo
2024-03-05 11:40 ` [PATCH net] " Oleksij Rempel
2024-03-06  3:20 ` [PATCH] " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox