Skip to contentSkip to conversation

net: dsa: mxl862xx: add devlink flash_update and info_get

RFC PATCH Superseded Daniel Golle 3 participants 6 messages Jul 7 – Jul 9

Subsystems (4)

v1 of 19 Superseded Latest is v19 →

lore
Share & tools
lore

Daniel Golle

author maintainer
#0 lore raw

RFC PATCH 3/3 net: dsa: mxl862xx: add devlink flash_update and info_get

Implement runtime firmware upgrade via "devlink dev flash" and version reporting via "devlink dev info":

devlink dev info mdio_bus/<bus>/<addr>
devlink dev flash mdio_bus/<bus>/<addr> file <firmware.bin>

The driver sends SYS_MISC_FW_UPDATE to enter MCUboot rescue mode, transfers the signed image over the SB PDI bulk-transfer protocol (clause-22 SMDIO), waits for the switch to reboot, then schedules device_reprobe() for a clean remove()+probe() cycle.

Before the transfer begins the driver closes all conduit interfaces and marks every netdev (user and conduit) not-present via netif_device_detach() so that userspace cannot bring ports back up during the ~15 minute flash process. Progress is reported through devlink status notifications. Once the FW_UPDATE command has been sent the switch is in MCUboot mode and normal operation can only be restored by a reprobe, so the driver always schedules one regardless of transfer outcome.

The reprobe work item is dynamically allocated (following the iwlwifi pattern) because device_reprobe() triggers remove() which frees the devm-managed priv while the work is still executing.

---
 drivers/net/dsa/mxl862xx/Makefile        |   2 +-
 drivers/net/dsa/mxl862xx/mxl862xx-cmd.h  |   1 +
 drivers/net/dsa/mxl862xx/mxl862xx-fw.c   | 434 +++++++++++++++++++++++
 drivers/net/dsa/mxl862xx/mxl862xx-fw.h   |  15 +
 drivers/net/dsa/mxl862xx/mxl862xx-host.c |   7 +
 drivers/net/dsa/mxl862xx/mxl862xx.c      |   3 +
 drivers/net/dsa/mxl862xx/mxl862xx.h      |   2 +
 7 files changed, 463 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.c
 create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.h
drivers/net/dsa/mxl862xx/Makefile +1 -1
index a7be0e6669df..bccac0d0f703 100644
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_NET_DSA_MXL862) += mxl862xx_dsa.o
-mxl862xx_dsa-y := mxl862xx.o mxl862xx-host.o mxl862xx-phylink.o
+mxl862xx_dsa-y := mxl862xx.o mxl862xx-host.o mxl862xx-phylink.o mxl862xx-fw.o
drivers/net/dsa/mxl862xx/mxl862xx-cmd.h +1 -0
index c87a955c13c4..e2aa2934e9e1 100644
@@ -70,6 +70,7 @@
 #define INT_GPHY_READ			(GPY_GPY2XX_MAGIC + 0x1)
 #define INT_GPHY_WRITE			(GPY_GPY2XX_MAGIC + 0x2)
 
+#define SYS_MISC_FW_UPDATE		(SYS_MISC_MAGIC + 0x1)
 #define SYS_MISC_FW_VERSION		(SYS_MISC_MAGIC + 0x2)
 
 #define MXL862XX_XPCS_PCS_CONFIG	(MXL862XX_XPCS_MAGIC + 0x1)
drivers/net/dsa/mxl862xx/mxl862xx-fw.c new file +434 -0

434 lines not on this page · raw message

drivers/net/dsa/mxl862xx/mxl862xx-fw.h new file +15 -0
new file mode 100644
index 000000000000..a1b60fbacebf
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __MXL862XX_FW_H
+#define __MXL862XX_FW_H
+
+#include <net/dsa.h>
+
+int mxl862xx_devlink_info_get(struct dsa_switch *ds,
+			      struct devlink_info_req *req,
+			      struct netlink_ext_ack *extack);
+int mxl862xx_devlink_flash_update(struct dsa_switch *ds,
+				  struct devlink_flash_update_params *params,
+				  struct netlink_ext_ack *extack);
+
+#endif /* __MXL862XX_FW_H */
drivers/net/dsa/mxl862xx/mxl862xx-host.c +7 -0
index 6e582caea1fa..7ba984e94d82 100644
@@ -15,6 +15,7 @@
 #include <linux/unaligned.h>
 #include <net/dsa.h>
 #include "mxl862xx.h"
+#include "mxl862xx-cmd.h"
 #include "mxl862xx-host.h"
 
 #define CTRL_BUSY_MASK			BIT(15)
@@ -336,6 +337,12 @@ int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd, void *_data,
 	int ret, cmd_ret;
 	u16 max, crc, i;
 
+	if (priv->skip_teardown)
+		return 0;
+
+	if (priv->block_host && cmd != SYS_MISC_FW_UPDATE)
+		return -EBUSY;
+
 	dev_dbg(&priv->mdiodev->dev, "CMD %04x DATA %*ph\n", cmd, size, data);
 
 	mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED);
drivers/net/dsa/mxl862xx/mxl862xx.c +3 -0
index 45d237b3a40f..e643083d3938 100644
@@ -21,6 +21,7 @@
 #include "mxl862xx.h"
 #include "mxl862xx-api.h"
 #include "mxl862xx-cmd.h"
+#include "mxl862xx-fw.h"
 #include "mxl862xx-host.h"
 #include "mxl862xx-phylink.h"
 
@@ -2086,6 +2087,8 @@ static const struct dsa_switch_ops mxl862xx_switch_ops = {
 	.get_pause_stats = mxl862xx_get_pause_stats,
 	.get_rmon_stats = mxl862xx_get_rmon_stats,
 	.get_stats64 = mxl862xx_get_stats64,
+	.devlink_info_get = mxl862xx_devlink_info_get,
+	.devlink_flash_update = mxl862xx_devlink_flash_update,
 };
 
 static int mxl862xx_probe(struct mdio_device *mdiodev)
drivers/net/dsa/mxl862xx/mxl862xx.h +2 -0
index 432a5f3f2e08..a53fc4c37451 100644
@@ -337,6 +337,8 @@ struct mxl862xx_priv {
 	u16 evlan_ingress_size;
 	u16 evlan_egress_size;
 	u16 vf_block_size;
+	bool block_host;
+	bool skip_teardown;
 	struct delayed_work stats_work;
 };
 
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 3 lines

+ * The flash process takes approximately 15 minutes. Progress is
+ * reported via devlink status notifications. After a successful (or
+ * failed) flash the driver reprobes the device automatically.

Have you tested the failed use case?

I assume if the firmware in the flash is invalid, the bootloader does not boot it, and it remains in the bootloader waiting for another attempt. Does this DSA driver still load, so devlink can be used to try again?

Andrew

#5 lore raw
In reply to Daniel Golle

Hi Daniel,

Quoted 10 lines · Daniel Golle

Implement runtime firmware upgrade via "devlink dev flash" and version reporting via "devlink dev info":

  devlink dev info mdio_bus/<bus>/<addr>
  devlink dev flash mdio_bus/<bus>/<addr> file <firmware.bin>

The driver sends SYS_MISC_FW_UPDATE to enter MCUboot rescue mode, transfers the signed image over the SB PDI bulk-transfer protocol (clause-22 SMDIO), waits for the switch to reboot, then schedules device_reprobe() for a clean remove()+probe() cycle.

This could be split up into two sentences.

Quoted 11 lines

Before the transfer begins the driver closes all conduit interfaces and marks every netdev (user and conduit) not-present via netif_device_detach() so that userspace cannot bring ports back up during the ~15 minute flash process. Progress is reported through devlink status notifications. Once the FW_UPDATE command has been sent the switch is in MCUboot mode and normal operation can only be restored by a reprobe, so the driver always schedules one regardless of transfer outcome.

The reprobe work item is dynamically allocated (following the iwlwifi pattern)

I'm not familiar with the net subsystem, if the iwlwifi pattern is not trivial consider adding a link or a explanation.

Quoted 45 lines

because device_reprobe() triggers remove() which frees the
devm-managed priv while the work is still executing.

---
 drivers/net/dsa/mxl862xx/Makefile        |   2 +- drivers/net/dsa/mxl862xx/mxl862xx-cmd.h  |   1 + drivers/net/dsa/mxl862xx/mxl862xx-fw.c   | 434 +++++++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-fw.h   |  15 + drivers/net/dsa/mxl862xx/mxl862xx-host.c |   7 + drivers/net/dsa/mxl862xx/mxl862xx.c      |   3 + drivers/net/dsa/mxl862xx/mxl862xx.h      |   2 +

 7 files changed, 463 insertions(+), 1 deletion(-)

 create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.h

drivers/net/dsa/mxl862xx/Makefile +0 -0
index a7be0e6669df..bccac0d0f703 100644
@@ -1,3 +1,3 @@
  # SPDX-License-Identifier: GPL-2.0

 obj-$(CONFIG_NET_DSA_MXL862) += mxl862xx_dsa.o

drivers/net/dsa/mxl862xx/Makefile +1 -1
-mxl862xx_dsa-y := mxl862xx.o mxl862xx-host.o mxl862xx-phylink.o
+mxl862xx_dsa-y := mxl862xx.o mxl862xx-host.o mxl862xx-phylink.o mxl862xx-fw.o
drivers/net/dsa/mxl862xx/mxl862xx-cmd.h +0 -0
index c87a955c13c4..e2aa2934e9e1 100644
@@ -70,6 +70,7 @@
  #define INT_GPHY_READ			(GPY_GPY2XX_MAGIC + 0x1)
  #define INT_GPHY_WRITE			(GPY_GPY2XX_MAGIC + 0x2)


+#define SYS_MISC_FW_UPDATE (SYS_MISC_MAGIC + 0x1)
 #define SYS_MISC_FW_VERSION (SYS_MISC_MAGIC + 0x2)

 #define MXL862XX_XPCS_PCS_CONFIG (MXL862XX_XPCS_MAGIC + 0x1)

drivers/net/dsa/mxl862xx/mxl862xx- renamed from drivers/net/dsa/mxl862xx/mxl862xx-fw.c +0 -0

fw.c
new file mode 100644
index 000000000000..7cd4a462667b

drivers/net/dsa/mxl862xx/mxl862xx-fw.c line 3

Quoted 3 lines
drivers/net/dsa/mxl862xx/mxl862xx-fw.c new file +3 -0
@@ -0,0 +1,434 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Firmware flash and devlink support for MaxLinear MxL862xx

If you have a data sheet for the device please add a link.

drivers/net/dsa/mxl862xx/mxl862xx-fw.c

Quoted 11 lines
drivers/net/dsa/mxl862xx/mxl862xx-fw.c new file +11 -0
+ *
+ * Copyright (C) 2025 Daniel Golle <[email protected]>
+ *
+ * Usage:
+ *   # Query running firmware version:
+ *   devlink dev info mdio_bus/<bus>/<addr>
+ *
+ *   # Flash new firmware (all ports are taken down automatically):
+ *   devlink dev flash mdio_bus/<bus>/<addr> file <firmware.bin>
+ *
+ * The flash process takes approximately 15 minutes. 

Does the user get informed about the wait?

drivers/net/dsa/mxl862xx/mxl862xx-fw.c line 57

Quoted 11 lines

Progress is
+ * reported via devlink status notifications. After a successful (or
+ * failed) flash the driver reprobes the device automatically.
+ */

[...]

drivers/net/dsa/mxl862xx/mxl862xx-fw.c new file +5 -0
+
+/* Timeouts */
+#define MXL862XX_FW_READY_TIMEOUT_MS	30000
+#define MXL862XX_FW_ACK_TIMEOUT_MS	5000
+#define MXL862XX_FW_ERASE_TIMEOUT_MS	300000	/* flash erase is very slow */

Slow is relative.
Can you give an erase speed in MB/s or time for the whole memory?

drivers/net/dsa/mxl862xx/mxl862xx-fw.c line 370

Quoted 13 lines

[...]

drivers/net/dsa/mxl862xx/mxl862xx-fw.c new file +12 -0
+
+	dev_info(ds->dev, "flash: running firmware %u.%u.%u\n",
+		 priv->fw_version.major, priv->fw_version.minor,
+		 priv->fw_version.revision);
+
+	/* Close all user and CPU ports while the firmware is still
+	 * alive. dev_close() on user ports triggers multicast group
+	 * leave and host MDB/FDB removal on the CPU port through the
+	 * normal DSA callbacks so the core's tracking lists are
+	 * drained before we enter MCUboot. Then mark user ports
+	 * not-present so userspace cannot bring them back up during
+	 * the (slow) flash process. The conduit is only closed, not

(slow) -> up to 20 minutes long flash process.

    or -> circa 15 minutes long flash process.

drivers/net/dsa/mxl862xx/mxl862xx-fw.c line 420

Quoted 11 lines
drivers/net/dsa/mxl862xx/mxl862xx-fw.c new file +11 -0
+	 * detached -- it is owned by the Ethernet MAC driver and
+	 * dev_open() during reprobe must be able to bring it back.
+	 */
+[...]
+	/* Silently discard all API commands during the teardown that
+	 * reprobe triggers -- the switch firmware has been reset and
+	 * has no knowledge of the old configuration.
+	 */
+	priv->skip_teardown = true;
+
+	reprobe = kzalloc(sizeof(*reprobe), GFP_KERNEL);

-> kzalloc_obj(*reprobe); - GFP_KERNEL is the default, therefore omitted. as suggested in 2932ba8d9c99 ("slab: Introduce kmalloc_obj() and family")

Did you skip checkpatch or is it out of date?

Anyway thanks
Manuel

Quoted 1 line

[...]

author maintainer
#2 lore raw
In reply to Andrew Lunn
Quoted 10 lines · Andrew Lunn
Quoted 3 lines

+ * The flash process takes approximately 15 minutes. Progress is
+ * reported via devlink status notifications. After a successful (or
+ * failed) flash the driver reprobes the device automatically.

Have you tested the failed use case?

I assume if the firmware in the flash is invalid, the bootloader does not boot it, and it remains in the bootloader waiting for another attempt. Does this DSA driver still load, so devlink can be used to try again?

No. Without a running the firmware the driver doesn't probe and only a special rescue tool allows to recover the hardware. Having the DSA driver detect the presence of the switch stuck in mcuboot mode and probe without registering any user or CPU ports also isn't straight forward.

maintainer
#3 lore raw
Quoted 12 lines · Daniel Golle
Quoted 10 lines · Andrew Lunn
Quoted 3 lines

+ * The flash process takes approximately 15 minutes. Progress is
+ * reported via devlink status notifications. After a successful (or
+ * failed) flash the driver reprobes the device automatically.

Have you tested the failed use case?

I assume if the firmware in the flash is invalid, the bootloader does not boot it, and it remains in the bootloader waiting for another attempt. Does this DSA driver still load, so devlink can be used to try again?

Quoted 5 lines

No. Without a running the firmware the driver doesn't probe and only a special rescue tool allows to recover the hardware. Having the DSA driver detect the presence of the switch stuck in mcuboot mode and probe without registering any user or CPU ports also isn't straight forward.

And that special rescue tool exists?

Why not wrap it in a script which unloads the DSA driver, let it do its thing, and then reload the DSA driver?

All the other users of devlink flash that i know of can operate while the device is still running. So it makes sense for it to be part of the driver, it is something just going on in the background. This device is different, so i don't really see the advantage of making it part of the driver.

Andrew

author maintainer
#4 lore raw
Quoted 13 lines · Andrew Lunn
Quoted 12 lines · Daniel Golle
Quoted 10 lines · Andrew Lunn
Quoted 3 lines

+ * The flash process takes approximately 15 minutes. Progress is
+ * reported via devlink status notifications. After a successful (or
+ * failed) flash the driver reprobes the device automatically.

Have you tested the failed use case?

I assume if the firmware in the flash is invalid, the bootloader does not boot it, and it remains in the bootloader waiting for another attempt. Does this DSA driver still load, so devlink can be used to try again?

Quoted 7 lines
Quoted 5 lines

No. Without a running the firmware the driver doesn't probe and only a special rescue tool allows to recover the hardware. Having the DSA driver detect the presence of the switch stuck in mcuboot mode and probe without registering any user or CPU ports also isn't straight forward.

And that special rescue tool exists?

Yes, but it's basically a custom bootable Linux image, based on a patched/old Linux Kernel and vendor SDK driver.
It cannot just run from userspace because (apart from the out-of-tree mdio-netlink API) there isn't any standard way to access the MDIO bus from userspace.

Quoted 2 lines

Why not wrap it in a script which unloads the DSA driver, let it do its thing, and then reload the DSA driver?

It would need to be yet another driver binding the device on the MDIO bus, check if the mcuboot C22 MDIO interface responds and if not fire the firmware API request to put reset the device into mcuboot mode. And this, issueing a firmware API command, is why it is easier to make it part of the existing DSA driver which already got a robust and endian-safe implementation of the firmware API protocol.

Quoted 5 lines

All the other users of devlink flash that i know of can operate while the device is still running. So it makes sense for it to be part of the driver, it is something just going on in the background. This device is different, so i don't really see the advantage of making it part of the driver.

The controlled teardown/reprobe/reconfigure as well as the ability to issue the reboot-into-mcuboot firmware API command are good arguments imho.