]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: dsa: mxl862xx: store firmware version for feature gating
authorDaniel Golle <daniel@makrotopia.org>
Sat, 13 Jun 2026 03:07:11 +0000 (04:07 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 16 Jun 2026 00:18:00 +0000 (17:18 -0700)
Query the firmware version at init (already done in wait_ready),
cache it in priv->fw_version, and provide MXL862XX_FW_VER_MIN()
for version-gated code paths throughout the driver.

MXL862XX_FW_VER() packs major/minor/revision into a u32 with
bitwise shifts so that versions compare with natural ordering,
independent of host endianness.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/91a26a8ffeaa2ce1729f98347e93e779973976bb.1781319534.git.daniel@makrotopia.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/mxl862xx/mxl862xx.c
drivers/net/dsa/mxl862xx/mxl862xx.h

index b60482d93a85570bb579b3afe4cdbd4295eec97a..2f22adedfbf67b63c36bfdfce99f369f4efb160c 100644 (file)
@@ -257,6 +257,9 @@ static int mxl862xx_wait_ready(struct dsa_switch *ds)
                         ver.iv_major, ver.iv_minor,
                         le16_to_cpu(ver.iv_revision),
                         le32_to_cpu(ver.iv_build_num));
+               priv->fw_version.major = ver.iv_major;
+               priv->fw_version.minor = ver.iv_minor;
+               priv->fw_version.revision = le16_to_cpu(ver.iv_revision);
                return 0;
 
 not_ready_yet:
index 80053ab40e4cea7aa3e26dfa329df2bfab430cfe..e3db3711b245323a4297d34366fe4020c96563f1 100644 (file)
@@ -3,6 +3,7 @@
 #ifndef __MXL862XX_H
 #define __MXL862XX_H
 
+#include <asm/byteorder.h>
 #include <linux/mdio.h>
 #include <linux/workqueue.h>
 #include <net/dsa.h>
@@ -241,6 +242,25 @@ struct mxl862xx_port {
        spinlock_t stats_lock; /* protects stats accumulators */
 };
 
+/**
+ * struct mxl862xx_fw_version - firmware version for comparison and display
+ * @major: firmware major version
+ * @minor: firmware minor version
+ * @revision: firmware revision number
+ */
+struct mxl862xx_fw_version {
+       u8 major;
+       u8 minor;
+       u16 revision;
+};
+
+#define MXL862XX_FW_VER(maj, min, rev) \
+       (((u32)(maj) << 24) | ((u32)(min) << 16) | (rev))
+#define MXL862XX_FW_VER_MIN(priv, maj, min, rev) \
+       (MXL862XX_FW_VER((priv)->fw_version.major, (priv)->fw_version.minor, \
+                        (priv)->fw_version.revision) >= \
+        MXL862XX_FW_VER(maj, min, rev))
+
 /* Bit indices for struct mxl862xx_priv::flags */
 #define MXL862XX_FLAG_CRC_ERR          0
 #define MXL862XX_FLAG_WORK_STOPPED     1
@@ -258,6 +278,8 @@ struct mxl862xx_port {
  * @drop_meter:         index of the single shared zero-rate firmware meter
  *                      used to unconditionally drop traffic (used to block
  *                      flooding)
+ * @fw_version:         cached firmware version, populated at probe and
+ *                      compared with MXL862XX_FW_VER_MIN()
  * @ports:              per-port state, indexed by switch port number
  * @bridges:            maps DSA bridge number to firmware bridge ID;
  *                      zero means no firmware bridge allocated for that
@@ -275,6 +297,7 @@ struct mxl862xx_priv {
        struct work_struct crc_err_work;
        unsigned long flags;
        u16 drop_meter;
+       struct mxl862xx_fw_version fw_version;
        struct mxl862xx_port ports[MXL862XX_MAX_PORTS];
        u16 bridges[MXL862XX_MAX_BRIDGES + 1];
        u16 evlan_ingress_size;