diff mbox series

KSZ8795 fixes for v5.15

Message ID uz5k4wl4fka3rxoz2tkvpogiwblokbpo72p3sdjdbakwgfbwfi@bzxazuhkhbps (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series KSZ8795 fixes for v5.15 | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Jörg Sommer Dec. 7, 2024, 8:44 a.m. UTC
Hi,

it's me again with the KSZ8795 connected to TI_DAVINCI_EMAC. It works on
v5.10.227 and now, I try to get this working on v5.15 (and then later
versions). I found this patch [1] in the Microchip forum [2]. Someone put it
together to make this chip work with v5.15. I applies fine on v5.15.173 and
gets me to a point where the kernel detects the chip during boot. (It still
doesn't work, but it's better with this patch than without.)

[1] https://forum.microchip.com/sfc/servlet.shepherd/document/download/0693l00000XiIt9AAF
[2] https://forum.microchip.com/s/topic/a5C3l000000MfQkEAK/t388621

The driver code was restructured in 9f73e1 which contained some mistakes.
These were fixed later with 4bdf79 (which is part of the patch), but was not
backported to v5.15 as a grep shows:

$ git grep STATIC_MAC_TABLE_OVERRIDE'.*2[26]' v5.15.173
v5.15.173:drivers/net/dsa/microchip/ksz8795.c:55:       [STATIC_MAC_TABLE_OVERRIDE]     = BIT(26),
$ git grep STATIC_MAC_TABLE_OVERRIDE'.*2[26]' v6.6.62
v6.6.62:drivers/net/dsa/microchip/ksz_common.c:334:     [STATIC_MAC_TABLE_OVERRIDE]     = BIT(22),

Can someone review this patch and apply it to the v5.15 branch?


commit 9f73e11250fb3948a8599d72318951d5e93b1eaf
Author: Michael Grzeschik <m.grzeschik@pengutronix.de>
Date:   Tue Apr 27 09:09:03 2021 +0200

    net: dsa: microchip: ksz8795: move register offsets and shifts to separate struct

    In order to get this driver used with other switches the functions need
    to use different offsets and register shifts. This patch changes the
    direct use of the register defines to register description structures,
    which can be set depending on the chips register layout.

    Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
    Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
    Reviewed-by: Andrew Lunn <andrew@lunn.ch>
    Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

commit 4bdf79d686b49ac49373b36466acfb93972c7d7c
Author: Tristram Ha <Tristram.Ha@microchip.com>
Date:   Thu Jul 13 17:46:22 2023 -0700

    net: dsa: microchip: correct KSZ8795 static MAC table access

    The KSZ8795 driver code was modified to use on KSZ8863/73, which has
    different register definitions.  Some of the new KSZ8795 register
    information are wrong compared to previous code.

    KSZ8795 also behaves differently in that the STATIC_MAC_TABLE_USE_FID
    and STATIC_MAC_TABLE_FID bits are off by 1 when doing MAC table reading
    than writing.  To compensate that a special code was added to shift the
    register value by 1 before applying those bits.  This is wrong when the
    code is running on KSZ8863, so this special code is only executed when
    KSZ8795 is detected.

    Fixes: 4b20a07e103f ("net: dsa: microchip: ksz8795: add support for ksz88xx chips")
    Signed-off-by: Tristram Ha <Tristram.Ha@microchip.com>
    Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>


Kind regards, Jörg

Comments

Andrew Lunn Dec. 7, 2024, 8:58 p.m. UTC | #1
On Sat, Dec 07, 2024 at 09:44:46AM +0100, Jörg Sommer wrote:
> Hi,
> 
> it's me again with the KSZ8795 connected to TI_DAVINCI_EMAC. It works on
> v5.10.227 and now, I try to get this working on v5.15 (and then later
> versions). I found this patch [1] in the Microchip forum [2]. Someone put it
> together to make this chip work with v5.15. I applies fine on v5.15.173 and
> gets me to a point where the kernel detects the chip during boot. (It still
> doesn't work, but it's better with this patch than without.)
> 
> [1] https://forum.microchip.com/sfc/servlet.shepherd/document/download/0693l00000XiIt9AAF
> [2] https://forum.microchip.com/s/topic/a5C3l000000MfQkEAK/t388621
> 
> The driver code was restructured in 9f73e1 which contained some mistakes.
> These were fixed later with 4bdf79 (which is part of the patch), but was not
> backported to v5.15 as a grep shows:
> 
> $ git grep STATIC_MAC_TABLE_OVERRIDE'.*2[26]' v5.15.173
> v5.15.173:drivers/net/dsa/microchip/ksz8795.c:55:       [STATIC_MAC_TABLE_OVERRIDE]     = BIT(26),
> $ git grep STATIC_MAC_TABLE_OVERRIDE'.*2[26]' v6.6.62
> v6.6.62:drivers/net/dsa/microchip/ksz_common.c:334:     [STATIC_MAC_TABLE_OVERRIDE]     = BIT(22),
> 
> Can someone review this patch and apply it to the v5.15 branch?

Hi Jörg

Please see:

https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html

Option 2.

       Andrew
Jörg Sommer Dec. 9, 2024, 6:45 p.m. UTC | #2
Andrew Lunn schrieb am Sa 07. Dez, 21:58 (+0100):
> On Sat, Dec 07, 2024 at 09:44:46AM +0100, Jörg Sommer wrote:
> > Hi,
> > 
> > it's me again with the KSZ8795 connected to TI_DAVINCI_EMAC. It works on
> > v5.10.227 and now, I try to get this working on v5.15 (and then later
> > versions). I found this patch [1] in the Microchip forum [2]. Someone put it
> > together to make this chip work with v5.15. I applies fine on v5.15.173 and
> > gets me to a point where the kernel detects the chip during boot. (It still
> > doesn't work, but it's better with this patch than without.)
> > 
> > [1] https://forum.microchip.com/sfc/servlet.shepherd/document/download/0693l00000XiIt9AAF
> > [2] https://forum.microchip.com/s/topic/a5C3l000000MfQkEAK/t388621
> > 
> > The driver code was restructured in 9f73e1 which contained some mistakes.
> > These were fixed later with 4bdf79 (which is part of the patch), but was not
> > backported to v5.15 as a grep shows:
> > 
> > $ git grep STATIC_MAC_TABLE_OVERRIDE'.*2[26]' v5.15.173
> > v5.15.173:drivers/net/dsa/microchip/ksz8795.c:55:       [STATIC_MAC_TABLE_OVERRIDE]     = BIT(26),
> > $ git grep STATIC_MAC_TABLE_OVERRIDE'.*2[26]' v6.6.62
> > v6.6.62:drivers/net/dsa/microchip/ksz_common.c:334:     [STATIC_MAC_TABLE_OVERRIDE]     = BIT(22),
> > 
> > Can someone review this patch and apply it to the v5.15 branch?
> 
> Hi Jörg
> 
> Please see:
> 
> https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
> 
> Option 2.

I didn't know everyone can request a backport. But, unfortunately, neither
4bdf79d686b49ac49373b36466acfb93972c7d7c from main, nor
ce3ec3fc64e0e0f4d148cccba4e31246d50ec910 from v6.1 can be cherry-picked
without big conflicts.

I think I have to use Option 3 and send a new commit.


Kind regards, Jörg
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h
index 9d611895d3cf..bb98cc3d89f6 100644
--- a/drivers/net/dsa/microchip/ksz8.h
+++ b/drivers/net/dsa/microchip/ksz8.h
@@ -34,8 +34,10 @@  enum ksz_masks {
 	VLAN_TABLE_MEMBERSHIP,
 	VLAN_TABLE_VALID,
 	STATIC_MAC_TABLE_VALID,
-	STATIC_MAC_TABLE_USE_FID,
-	STATIC_MAC_TABLE_FID,
+	STATIC_MAC_TABLE_USE_FID_R,
+	STATIC_MAC_TABLE_USE_FID_W,
+	STATIC_MAC_TABLE_FID_R,
+	STATIC_MAC_TABLE_FID_W,
 	STATIC_MAC_TABLE_OVERRIDE,
 	STATIC_MAC_TABLE_FWD_PORTS,
 	DYNAMIC_MAC_TABLE_ENTRIES_H,
@@ -51,7 +53,8 @@  enum ksz_shifts {
 	VLAN_TABLE_MEMBERSHIP_S,
 	VLAN_TABLE,
 	STATIC_MAC_FWD_PORTS,
-	STATIC_MAC_FID,
+	STATIC_MAC_FID_R,
+	STATIC_MAC_FID_W,
 	DYNAMIC_MAC_ENTRIES_H,
 	DYNAMIC_MAC_ENTRIES,
 	DYNAMIC_MAC_FID,
diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index c9c682352ac3..3c6fee9db038 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -50,10 +50,12 @@  static const u32 ksz8795_masks[] = {
 	[VLAN_TABLE_MEMBERSHIP]		= GENMASK(11, 7),
 	[VLAN_TABLE_VALID]		= BIT(12),
 	[STATIC_MAC_TABLE_VALID]	= BIT(21),
-	[STATIC_MAC_TABLE_USE_FID]	= BIT(23),
-	[STATIC_MAC_TABLE_FID]		= GENMASK(30, 24),
-	[STATIC_MAC_TABLE_OVERRIDE]	= BIT(26),
-	[STATIC_MAC_TABLE_FWD_PORTS]	= GENMASK(24, 20),
+	[STATIC_MAC_TABLE_USE_FID_R]	= BIT(24),
+	[STATIC_MAC_TABLE_USE_FID_W]	= BIT(23),
+	[STATIC_MAC_TABLE_FID_R]	= GENMASK(31, 25),
+	[STATIC_MAC_TABLE_FID_W]	= GENMASK(30, 24),
+	[STATIC_MAC_TABLE_OVERRIDE]	= BIT(22),
+	[STATIC_MAC_TABLE_FWD_PORTS]	= GENMASK(20, 16),
 	[DYNAMIC_MAC_TABLE_ENTRIES_H]	= GENMASK(6, 0),
 	[DYNAMIC_MAC_TABLE_MAC_EMPTY]	= BIT(8),
 	[DYNAMIC_MAC_TABLE_NOT_READY]	= BIT(7),
@@ -67,7 +69,8 @@  static const u8 ksz8795_shifts[] = {
 	[VLAN_TABLE_MEMBERSHIP_S]	= 7,
 	[VLAN_TABLE]			= 16,
 	[STATIC_MAC_FWD_PORTS]		= 16,
-	[STATIC_MAC_FID]		= 24,
+	[STATIC_MAC_FID_R]		= 25,
+	[STATIC_MAC_FID_W]		= 24,
 	[DYNAMIC_MAC_ENTRIES_H]		= 3,
 	[DYNAMIC_MAC_ENTRIES]		= 29,
 	[DYNAMIC_MAC_FID]		= 16,
@@ -100,8 +103,10 @@  static const u32 ksz8863_masks[] = {
 	[VLAN_TABLE_MEMBERSHIP]		= GENMASK(18, 16),
 	[VLAN_TABLE_VALID]		= BIT(19),
 	[STATIC_MAC_TABLE_VALID]	= BIT(19),
-	[STATIC_MAC_TABLE_USE_FID]	= BIT(21),
-	[STATIC_MAC_TABLE_FID]		= GENMASK(29, 26),
+	[STATIC_MAC_TABLE_USE_FID_R]	= BIT(21),
+	[STATIC_MAC_TABLE_USE_FID_W]	= BIT(21),
+	[STATIC_MAC_TABLE_FID_R]	= GENMASK(25, 22),
+	[STATIC_MAC_TABLE_FID_W]	= GENMASK(25, 22),
 	[STATIC_MAC_TABLE_OVERRIDE]	= BIT(20),
 	[STATIC_MAC_TABLE_FWD_PORTS]	= GENMASK(18, 16),
 	[DYNAMIC_MAC_TABLE_ENTRIES_H]	= GENMASK(5, 0),
@@ -116,7 +121,8 @@  static const u32 ksz8863_masks[] = {
 static u8 ksz8863_shifts[] = {
 	[VLAN_TABLE_MEMBERSHIP_S]	= 16,
 	[STATIC_MAC_FWD_PORTS]		= 16,
-	[STATIC_MAC_FID]		= 22,
+	[STATIC_MAC_FID_R]		= 22,
+	[STATIC_MAC_FID_W]		= 22,
 	[DYNAMIC_MAC_ENTRIES_H]		= 3,
 	[DYNAMIC_MAC_ENTRIES]		= 24,
 	[DYNAMIC_MAC_FID]		= 16,
@@ -604,9 +610,9 @@  static int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
 		data_hi >>= 1;
 		alu->is_static = true;
 		alu->is_use_fid =
-			(data_hi & masks[STATIC_MAC_TABLE_USE_FID]) ? 1 : 0;
-		alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID]) >>
-				shifts[STATIC_MAC_FID];
+			(data_hi & masks[STATIC_MAC_TABLE_USE_FID_R]) ? 1 : 0;
+		alu->fid = (data_hi & masks[STATIC_MAC_TABLE_FID_R]) >>
+				shifts[STATIC_MAC_FID_R];
 		return 0;
 	}
 	return -ENXIO;
@@ -633,8 +639,8 @@  static void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
 	if (alu->is_override)
 		data_hi |= masks[STATIC_MAC_TABLE_OVERRIDE];
 	if (alu->is_use_fid) {
-		data_hi |= masks[STATIC_MAC_TABLE_USE_FID];
-		data_hi |= (u32)alu->fid << shifts[STATIC_MAC_FID];
+		data_hi |= masks[STATIC_MAC_TABLE_USE_FID_W];
+		data_hi |= ((u32)alu->fid << shifts[STATIC_MAC_FID_W]) & masks[STATIC_MAC_TABLE_FID_W];
 	}
 	if (alu->is_static)
 		data_hi |= masks[STATIC_MAC_TABLE_VALID];