Skip to contentSkip to conversation

net: dsa: lantiq_gswip: add support for SWAPI version 2.3

RFC PATCH In review Daniel Golle 2 participants 3 messages Aug 16, 2025 – Aug 17, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 9/23 net: dsa: lantiq_gswip: add support for SWAPI version 2.3

Add definition for switch API version 2.3 and a macro to make comparing the version more conveniant.

---
 drivers/net/dsa/lantiq_gswip.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/dsa/lantiq_gswip.h +3 -0
index 433b65b047dd..fd0c01edb914 100644
@@ -7,6 +7,7 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/reset.h>
+#include <linux/swab.h>
 #include <net/dsa.h>
 
 /* GSWIP MDIO Registers */
@@ -93,6 +94,8 @@
 #define   GSWIP_VERSION_2_1		0x021
 #define   GSWIP_VERSION_2_2		0x122
 #define   GSWIP_VERSION_2_2_ETC		0x022
+#define   GSWIP_VERSION_2_3		0x023
+#define GSWIP_VERSION_GE(priv, ver)	(swab16(priv->version) >= swab16(ver))
 
 #define GSWIP_BM_RAM_VAL(x)		(0x043 - (x))
 #define GSWIP_BM_RAM_ADDR		0x044
Signature · 1 line
2.50.1
maintainer
#1 lore raw
Quoted 21 lines · Daniel Golle

Add definition for switch API version 2.3 and a macro to make comparing the version more conveniant.

---
 drivers/net/dsa/lantiq_gswip.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/dsa/lantiq_gswip.h +1 -0
index 433b65b047dd..fd0c01edb914 100644
@@ -7,6 +7,7 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/reset.h>
+#include <linux/swab.h>
 #include <net/dsa.h>
 
 /* GSWIP MDIO Registers */

drivers/net/dsa/lantiq_gswip.h line 98

Quoted 5 lines
drivers/net/dsa/lantiq_gswip.h +2 -0
@@ -93,6 +94,8 @@
 #define   GSWIP_VERSION_2_1		0x021
 #define   GSWIP_VERSION_2_2		0x122
 #define   GSWIP_VERSION_2_2_ETC		0x022
+#define   GSWIP_VERSION_2_3		0x023
+#define GSWIP_VERSION_GE(priv, ver)	(swab16(priv->version) >= swab16(ver))

Don't this depend on the endiannes of the CPU?

It seems like it would be better to make your new version member cpu endian, and when writing to it, do le16_to_cpu().

Also, if i remember correctly, you made version a u32. Should it really be a u16?

Andrew

#2 lore raw
Quoted 30 lines · Andrew Lunn
Quoted 21 lines · Daniel Golle

Add definition for switch API version 2.3 and a macro to make comparing the version more conveniant.

---
 drivers/net/dsa/lantiq_gswip.h | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/dsa/lantiq_gswip.h +1 -0
index 433b65b047dd..fd0c01edb914 100644
@@ -7,6 +7,7 @@
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/reset.h>
+#include <linux/swab.h>
 #include <net/dsa.h>
 
 /* GSWIP MDIO Registers */

drivers/net/dsa/lantiq_gswip.h line 98

Quoted 5 lines
drivers/net/dsa/lantiq_gswip.h +2 -0
@@ -93,6 +94,8 @@
 #define   GSWIP_VERSION_2_1		0x021
 #define   GSWIP_VERSION_2_2		0x122
 #define   GSWIP_VERSION_2_2_ETC		0x022
+#define   GSWIP_VERSION_2_3		0x023
+#define GSWIP_VERSION_GE(priv, ver)	(swab16(priv->version) >= swab16(ver))

Don't this depend on the endiannes of the CPU?

Quoted 2 lines

It seems like it would be better to make your new version member cpu endian, and when writing to it, do le16_to_cpu().

Yes, that does make sense.

Quoted 3 lines

Also, if i remember correctly, you made version a u32. Should it really be a u16?

True, it should probably be u16. It would complicate things a bit though as the (existing, currently supported) MMIO switches built-into the Lantiq SoCs use 32-bit memory operations to access the 16-bit switch registers, where the upper 16-bit are always all zero... Hence I got to use .val_bits = 32 to not end up with bus errors, and also .reg_shift = -2 is needed as each 16-bit register address needs to be multiplied by 4 (ie. addr =<< 2, which is what .reg_shift = -2 is doing).
So up to now, eg. when passed as a function paramter in existing code paths, the version has been a u32 type. When using a different type for the version stored in the priv struct, that would create quite a bit of confusion imho:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/dsa/lantiq_gswip.c?h=v6.16#n2018

Let me know what you think.