From: Daniel Golle <daniel@makrotopia.org>
To: Hauke Mehrtens <hauke@hauke-m.de>, Andrew Lunn <andrew@lunn.ch>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Russell King <linux@armlinux.org.uk>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Andreas Schirm <andreas.schirm@siemens.com>,
Lukas Stockmann <lukas.stockmann@siemens.com>,
Alexander Sverdlin <alexander.sverdlin@siemens.com>,
Peter Christen <peter.christen@siemens.com>,
Avinash Jayaraman <ajayaraman@maxlinear.com>,
Bing tao Xu <bxu@maxlinear.com>, Liang Xu <lxu@maxlinear.com>,
Juraj Povazanec <jpovazanec@maxlinear.com>,
"Fanni (Fang-Yi) Chan" <fchan@maxlinear.com>,
"Benny (Ying-Tsan) Weng" <yweng@maxlinear.com>,
"Livia M. Rosu" <lrosu@maxlinear.com>,
John Crispin <john@phrozen.org>
Subject: [PATCH net-next v4 7/7] net: dsa: lantiq_gswip: store switch API version in priv
Date: Fri, 22 Aug 2025 17:12:21 +0100 [thread overview]
Message-ID: <eddb51ae8d0b2046ca91906e93daad7be5af56d7.1755878232.git.daniel@makrotopia.org> (raw)
In-Reply-To: <cover.1755878232.git.daniel@makrotopia.org>
Store the switch API version in struct gswip_priv. As the hardware has
the 'major/minor' version bytes in the wrong order preventing numerical
comparisons the version to be stored in gswip_priv is constructed in
such a way that the REV field is the most significant byte and the MOD
field the least significant byte. Also provide a conveniance macro to
allow comparing the stored version of the hardware against the already
defined GSWIP_VERSION_* macros.
This is done in order to prepare supporting newer features such as 4096
VLANs and per-port configurable learning which are only available
starting from specific hardware versions.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
v4: use FIELD_GET accessor macro to construct version to be stored,
add comments and postpone adding the for now unused
GSWIP_VERSION_2_3 macro
v3: use __force for version field endian exception (__le16 __force) to
fix sparse warning.
v2: no changes
drivers/net/dsa/lantiq_gswip.c | 13 +++++++++++--
drivers/net/dsa/lantiq_gswip.h | 13 +++++++++++--
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index f8a43c351649..638f9a42f218 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -1908,6 +1908,16 @@ static int gswip_probe(struct platform_device *pdev)
mutex_init(&priv->pce_table_lock);
version = gswip_switch_r(priv, GSWIP_VERSION);
+ /* The hardware has the 'major/minor' version bytes in the wrong order
+ * preventing numerical comparisons. Construct a 16-bit unsigned integer
+ * having the REV field as most significant byte and the MOD field as
+ * least significant byte. This is effectively swapping the two bytes of
+ * the version variable, but other than using swab16 it doesn't affect
+ * the source variable.
+ */
+ priv->version = GSWIP_VERSION_REV(version) << 8 |
+ GSWIP_VERSION_MOD(version);
+
np = dev->of_node;
switch (version) {
case GSWIP_VERSION_2_0:
@@ -1956,8 +1966,7 @@ static int gswip_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, priv);
dev_info(dev, "probed GSWIP version %lx mod %lx\n",
- (version & GSWIP_VERSION_REV_MASK) >> GSWIP_VERSION_REV_SHIFT,
- (version & GSWIP_VERSION_MOD_MASK) >> GSWIP_VERSION_MOD_SHIFT);
+ GSWIP_VERSION_REV(version), GSWIP_VERSION_MOD(version));
return 0;
disable_switch:
diff --git a/drivers/net/dsa/lantiq_gswip.h b/drivers/net/dsa/lantiq_gswip.h
index 0b7b6db4eab9..620c2d560cbe 100644
--- a/drivers/net/dsa/lantiq_gswip.h
+++ b/drivers/net/dsa/lantiq_gswip.h
@@ -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 */
@@ -85,14 +86,21 @@
#define GSWIP_SWRES_R1 BIT(1) /* GSWIP Software reset */
#define GSWIP_SWRES_R0 BIT(0) /* GSWIP Hardware reset */
#define GSWIP_VERSION 0x013
-#define GSWIP_VERSION_REV_SHIFT 0
#define GSWIP_VERSION_REV_MASK GENMASK(7, 0)
-#define GSWIP_VERSION_MOD_SHIFT 8
#define GSWIP_VERSION_MOD_MASK GENMASK(15, 8)
+#define GSWIP_VERSION_REV(v) FIELD_GET(GSWIP_VERSION_REV_MASK, v)
+#define GSWIP_VERSION_MOD(v) FIELD_GET(GSWIP_VERSION_MOD_MASK, v)
#define GSWIP_VERSION_2_0 0x100
#define GSWIP_VERSION_2_1 0x021
#define GSWIP_VERSION_2_2 0x122
#define GSWIP_VERSION_2_2_ETC 0x022
+/* The hardware has the 'major/minor' version bytes in the wrong order
+ * preventing numerical comparisons. Swap the bytes of the 16-bit value
+ * to end up with REV being the most significant byte and MOD being the
+ * least significant byte, which then allows comparing it with the
+ * value stored in struct gswip_priv.
+ */
+#define GSWIP_VERSION_GE(priv, ver) ((priv)->version >= swab16(ver))
#define GSWIP_BM_RAM_VAL(x) (0x043 - (x))
#define GSWIP_BM_RAM_ADDR 0x044
@@ -258,6 +266,7 @@ struct gswip_priv {
struct gswip_gphy_fw *gphy_fw;
u32 port_vlan_filter;
struct mutex pce_table_lock;
+ u16 version;
};
#endif /* __LANTIQ_GSWIP_H */
--
2.50.1
next prev parent reply other threads:[~2025-08-22 16:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 16:11 [PATCH net-next v4 0/7] net: dsa: lantiq_gswip: prepare for supporting new features Daniel Golle
2025-08-22 16:11 ` [PATCH net-next v4 1/7] net: dsa: lantiq_gswip: deduplicate dsa_switch_ops Daniel Golle
2025-08-22 16:11 ` [PATCH net-next v4 2/7] net: dsa: lantiq_gswip: prepare for more CPU port options Daniel Golle
2025-08-22 16:11 ` [PATCH net-next v4 3/7] net: dsa: lantiq_gswip: move definitions to header Daniel Golle
2025-08-22 16:11 ` [PATCH net-next v4 4/7] net: dsa: lantiq_gswip: introduce bitmap for MII ports Daniel Golle
2025-08-22 16:12 ` [PATCH net-next v4 5/7] net: dsa: lantiq_gswip: load model-specific microcode Daniel Golle
2025-08-22 16:12 ` [PATCH net-next v4 6/7] net: dsa: lantiq_gswip: make DSA tag protocol model-specific Daniel Golle
2025-08-22 16:12 ` Daniel Golle [this message]
2025-08-24 16:00 ` [PATCH net-next v4 7/7] net: dsa: lantiq_gswip: store switch API version in priv Andrew Lunn
2025-08-25 22:30 ` [PATCH net-next v4 0/7] net: dsa: lantiq_gswip: prepare for supporting new features patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eddb51ae8d0b2046ca91906e93daad7be5af56d7.1755878232.git.daniel@makrotopia.org \
--to=daniel@makrotopia.org \
--cc=ajayaraman@maxlinear.com \
--cc=alexander.sverdlin@siemens.com \
--cc=andreas.schirm@siemens.com \
--cc=andrew@lunn.ch \
--cc=bxu@maxlinear.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fchan@maxlinear.com \
--cc=hauke@hauke-m.de \
--cc=john@phrozen.org \
--cc=jpovazanec@maxlinear.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lrosu@maxlinear.com \
--cc=lukas.stockmann@siemens.com \
--cc=lxu@maxlinear.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=p.zabel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=peter.christen@siemens.com \
--cc=yweng@maxlinear.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).