generic: 6.18: sync MxL862xx DSA switch driver

The PCS ops were chosen at the top of the setup function while the
firmware version was still zero, which selected the legacy SFP API
fallback on every firmware. Update the firmware update and MCUboot
rescue patches to v19 of the series, which sets up the SerDes PCS
instances once the firmware has reported ready and its version has
been read. Rebinding after a flash now goes through the new driver
core helper device_schedule_reprobe(). Backport the upstream stats
poll teardown fix the series builds on.

Fixes: f0204d78e1 ("generic: 6.18: sync MxL862xx DSA switch driver")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
Daniel Golle committed 2026-11-24 20:57:54 +00:00
1 parent 94ac3dc9c8
commit d253e623cc
22 files changed
+1997 -1367

No files matched your search

@@ -0,0 +1,101 @@
From 9e92ad4630f5dd1838ce6bbe6b1bd2c73d34de36 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Thu, 10 Sep 2026 14:13:15 +0100
Subject: [PATCH] net: dsa: mxl862xx: disable the stats poll on teardown
mxl862xx_setup() arms the stats poll before mxl862xx_setup_mdio(), and
nothing stops it until dsa_register_switch() has returned an error to
mxl862xx_probe(). DSA frees the dsa_port list before it returns, so a
poll that fires once .setup or a later step of dsa_tree_setup() has
failed walks freed ports. On shutdown the user ports stay registered,
and the WORK_STOPPED flag test in mxl862xx_get_stats64() is not atomic
with the cancel in mxl862xx_shutdown(), so a re-arm that read the flag
before it was set queues the poll after cancel_delayed_work_sync() has
returned.
Arm the poll once .setup has succeeded and stop it from a .teardown op,
which DSA calls on unregister and after a failed registration, in both
cases before it frees the ports. Use disable_delayed_work_sync() there
and in shutdown(): it drains a running poll as the cancel did and turns
every later attempt to queue the work into a no-op, so the re-arm
cannot bring the poll back. remove() and the probe error path only set
WORK_STOPPED, which crc_err_work tests before it walks the ports.
Fixes: a21d33a5265f ("net: dsa: mxl862xx: implement .get_stats64")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Link: https://patch.msgid.link/1eb6f7fc1789b67e4b11e3f4d5ff080d0b6f7cbb.1789045590.git.daniel@makrotopia.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
drivers/net/dsa/mxl862xx/mxl862xx.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -685,10 +685,22 @@ static int mxl862xx_setup(struct dsa_swi
if (ret)
return ret;
+ ret = mxl862xx_setup_mdio(ds);
+ if (ret)
+ return ret;
+
schedule_delayed_work(&priv->stats_work,
MXL862XX_STATS_POLL_INTERVAL);
- return mxl862xx_setup_mdio(ds);
+ return 0;
+}
+
+static void mxl862xx_teardown(struct dsa_switch *ds)
+{
+ struct mxl862xx_priv *priv = ds->priv;
+
+ set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags);
+ disable_delayed_work_sync(&priv->stats_work);
}
static int mxl862xx_port_state(struct dsa_switch *ds, int port, bool enable)
@@ -2047,9 +2059,7 @@ static void mxl862xx_get_stats64(struct
spin_unlock_bh(&priv->ports[port].stats_lock);
- /* Trigger a fresh poll so the next read sees up-to-date counters.
- * No-op if the work is already pending, running, or teardown started.
- */
+ /* Trigger a fresh poll so the next read sees up-to-date counters. */
if (!test_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags))
schedule_delayed_work(&priv->stats_work, 0);
}
@@ -2057,6 +2067,7 @@ static void mxl862xx_get_stats64(struct
static const struct dsa_switch_ops mxl862xx_switch_ops = {
.get_tag_protocol = mxl862xx_get_tag_protocol,
.setup = mxl862xx_setup,
+ .teardown = mxl862xx_teardown,
.port_setup = mxl862xx_port_setup,
.port_teardown = mxl862xx_port_teardown,
.phylink_get_caps = mxl862xx_phylink_get_caps,
@@ -2131,7 +2142,6 @@ static int mxl862xx_probe(struct mdio_de
err = dsa_register_switch(ds);
if (err) {
set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags);
- cancel_delayed_work_sync(&priv->stats_work);
mxl862xx_host_shutdown(priv);
for (i = 0; i < MXL862XX_MAX_PORTS; i++)
cancel_work_sync(&priv->ports[i].host_flood_work);
@@ -2152,7 +2162,6 @@ static void mxl862xx_remove(struct mdio_
priv = ds->priv;
set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags);
- cancel_delayed_work_sync(&priv->stats_work);
dsa_unregister_switch(ds);
@@ -2181,7 +2190,7 @@ static void mxl862xx_shutdown(struct mdi
dsa_switch_shutdown(ds);
set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags);
- cancel_delayed_work_sync(&priv->stats_work);
+ disable_delayed_work_sync(&priv->stats_work);
mxl862xx_host_shutdown(priv);
@@ -244,7 +244,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#endif /* __MXL862XX_PHYLINK_H */ #endif /* __MXL862XX_PHYLINK_H */
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c --- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -1795,6 +1795,8 @@ static void mxl862xx_get_strings(struct @@ -1807,6 +1807,8 @@ static void mxl862xx_get_strings(struct
for (i = 0; i < ARRAY_SIZE(mxl862xx_mib); i++) for (i = 0; i < ARRAY_SIZE(mxl862xx_mib); i++)
ethtool_puts(&data, mxl862xx_mib[i].name); ethtool_puts(&data, mxl862xx_mib[i].name);
@@ -253,7 +253,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
static int mxl862xx_get_sset_count(struct dsa_switch *ds, int port, int sset) static int mxl862xx_get_sset_count(struct dsa_switch *ds, int port, int sset)
@@ -1802,7 +1804,7 @@ static int mxl862xx_get_sset_count(struc @@ -1814,7 +1816,7 @@ static int mxl862xx_get_sset_count(struc
if (sset != ETH_SS_STATS) if (sset != ETH_SS_STATS)
return 0; return 0;
@@ -262,7 +262,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
static int mxl862xx_read_rmon(struct dsa_switch *ds, int port, static int mxl862xx_read_rmon(struct dsa_switch *ds, int port,
@@ -1838,6 +1840,8 @@ static void mxl862xx_get_ethtool_stats(s @@ -1850,6 +1852,8 @@ static void mxl862xx_get_ethtool_stats(s
else else
*data++ = le64_to_cpu(*(__le64 *)field); *data++ = le64_to_cpu(*(__le64 *)field);
} }
@@ -1,23 +1,33 @@
From 76491785e22884af9ee8ab5ea824ba8100a91fe1 Mon Sep 17 00:00:00 2001 From 965904e9a6e3341994daff10d2433e4eadc07c79 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org> From: Daniel Golle <daniel@makrotopia.org>
Date: Mon, 3 Aug 2026 04:51:51 +0100 Date: Fri, 14 Aug 2026 13:38:14 +0100
Subject: [PATCH net-next v10 1/5] net: dsa: add devlink flash_update callback Subject: [PATCH net-next v19] net: dsa: add devlink flash_update callback to
to dsa_switch_ops dsa_switch_ops
Add a devlink_flash_update callback to dsa_switch_ops so that DSA Add a devlink_flash_update callback to dsa_switch_ops so that DSA
drivers can support devlink dev flash without open-coding the devlink drivers can support devlink dev flash without open-coding the devlink
plumbing. Like the other trampolines in net/dsa/devlink.c, the op plumbing. Like the other trampolines in net/dsa/devlink.c, the op
returns -EOPNOTSUPP when the driver does not implement the callback; returns -EOPNOTSUPP when the driver does not implement the callback.
the devlink core will then have fetched the firmware file from The devlink core takes a non-NULL ops->flash_update as the capability
userspace before the request fails, which is acceptable for an gate, so on a switch without the callback a flash request now fetches
operation as infrequent as a firmware update. the firmware file, unless it names a component, which the core refuses
after consulting the driver's info versions, or an overwrite mask,
which it refuses outright: a missing file fails with the firmware
loader's errno, -ENOENT, instead of -EOPNOTSUPP, and a file that is
found reaches the trampoline inside a FLASH_UPDATE/FLASH_UPDATE_END
notification pair. The ETHTOOL_FLASHDEV ioctl on a user port reaches
the same trampoline through devlink's compat path, without extack.
Both are acceptable for an operation as infrequent as a firmware
update.
The devlink core calls the op with the devlink instance lock held and The devlink core calls the op with the devlink instance lock held and
without rtnl_lock, whereas DSA serialises its switch and port ops without rtnl_lock. DSA calls its port ops from paths of its own, some
under rtnl_lock, so a driver has to serialise a flash against its own without rtnl_lock either, and registers the devlink instance before
ops itself. the user ports exist, so a driver serialises a flash against its own
ops and its own setup itself.
Signed-off-by: Daniel Golle <daniel@makrotopia.org> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
--- ---
include/net/dsa.h | 3 +++ include/net/dsa.h | 3 +++
net/dsa/devlink.c | 13 +++++++++++++ net/dsa/devlink.c | 13 +++++++++++++
@@ -1,8 +1,8 @@
From e2ee86f5e021eb02a9c08d37e87e0206a5da16a2 Mon Sep 17 00:00:00 2001 From b3498e09980c72d2af80b98dd4dc1902a19a7403 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org> From: Daniel Golle <daniel@makrotopia.org>
Date: Mon, 3 Aug 2026 04:51:57 +0100 Date: Fri, 14 Aug 2026 13:38:59 +0100
Subject: [PATCH net-next v10 2/5] net: dsa: mxl862xx: add SMDIO clause-22 Subject: [PATCH net-next v19] net: dsa: mxl862xx: add SMDIO clause-22 register
register access access
Add mxl862xx_smdio_read() and mxl862xx_smdio_write() for clause-22 Add mxl862xx_smdio_read() and mxl862xx_smdio_write() for clause-22
SMDIO register access. The switch's MCUboot bootloader exposes only SMDIO register access. The switch's MCUboot bootloader exposes only
@@ -13,23 +13,23 @@ polling during flash erase does not starve other non-switch users of
the same MDIO bus, such as separate PHYs providing WAN or management the same MDIO bus, such as separate PHYs providing WAN or management
interfaces. interfaces.
Unlike mxl862xx_api_wrap(), which takes the bus lock with mxl862xx_api_wrap() takes the bus lock with MDIO_MUTEX_NESTED because
MDIO_MUTEX_NESTED because it can be entered from the accessors of it can be entered from the accessors of the switch-internal MDIO bus
the switch-internal MDIO bus while that bus's lock of the same lock while that bus's lock of the same lock class is already held. The
class is already held, the SMDIO helpers take it with a plain SMDIO helpers take it with a plain mutex_lock(): they run where no
mutex_lock(). They are only called from probe and devlink flash other MDIO bus lock is held, from probe, the devlink flash path and
contexts where no other MDIO bus lock can be held. the rescue recovery work.
Signed-off-by: Daniel Golle <daniel@makrotopia.org> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
--- ---
drivers/net/dsa/mxl862xx/mxl862xx-host.c | 40 ++++++++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.c | 41 ++++++++++++++++++++++++
drivers/net/dsa/mxl862xx/mxl862xx-host.h | 2 ++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 2 ++
2 files changed, 42 insertions(+) 2 files changed, 43 insertions(+)
--- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c --- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c
@@ -495,6 +495,46 @@ out: @@ -495,6 +495,47 @@ out:
return ret; return ret;
} }
@@ -39,8 +39,9 @@ Reviewed-by: Andrew Lunn <andrew@lunn.ch>
+ +
+/* Paged clause-22 window: the page goes into MII register 0x1f, the low nibble +/* Paged clause-22 window: the page goes into MII register 0x1f, the low nibble
+ * of addr selects one of the 16 registers within it. Both helpers take the MDIO + * of addr selects one of the 16 registers within it. Both helpers take the MDIO
+ * bus lock per transaction, so callers must not already hold it -- unlike + * bus lock per transaction with a plain mutex_lock(), so the caller may hold
+ * mxl862xx_api_wrap(), which holds it across a whole firmware command. + * no MDIO bus lock at all, every bus sharing the lock class;
+ * mxl862xx_api_wrap() holds this one across a whole firmware command.
+ */ + */
+int mxl862xx_smdio_read(struct mxl862xx_priv *priv, u32 addr) +int mxl862xx_smdio_read(struct mxl862xx_priv *priv, u32 addr)
+{ +{
@@ -0,0 +1,305 @@
From 4027cdf0d424dd6ef61f94e938e67f134c65727d Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Fri, 14 Aug 2026 13:39:44 +0100
Subject: [PATCH net-next v19] driver core: add device_schedule_reprobe()
Drivers that need a deferred re-probe of their own device open-code a
work item in module text. iwlwifi (iwl_trans_schedule_reprobe(), for a
firmware crash a lighter restart cannot fix) and hci_h5
(h5_btrtl_resume(), RTL devices lose their firmware state over suspend)
both end that work function with put_device(); kfree();
module_put(THIS_MODULE);, where a concurrent rmmod can free the module
text the epilogue is still executing. Neither gates the re-probe on the
device still being bound to the driver that scheduled it, which a driver
cannot do from outside because device_reprobe() takes the device lock
internally. Their conversion is left to follow-up patches.
Add device_schedule_reprobe(), which detaches and re-probes a device
after a caller-specified delay. The work function is built-in text, so a
caller needs no module reference. The first user is the mxl862xx
devlink flash path added later in this series.
At most one request exists per device, recorded in struct
device_private from its scheduling until its work has released the
driver. The slot identifies the binding: device_del() and
device_unbind_cleanup() clear it, the latter after ->remove() has
returned and the driver pointer is cleared, so a request the driver
schedules from a context its ->remove() waits for is cancelled too, a
failed probe leaves none behind, and neither an unbind followed by a
rebind nor a module reload within the delay gets a re-probe it did not
ask for. A spinlock ties the slot to the queueing and cancelling of its
work, so a cancel either removes a pending work and frees the request
or leaves it to the running work, which frees itself once the slot is
no longer its own; the reference the request holds on the device goes
with it.
A failed re-probe leaves the device unbound, as a failed initial probe
would, and really_probe() logs it like one. The work does not judge the
outcome itself: a deferred retry is off the deferred-probe list while
it runs, so no read of the device state tells one from a failure.
No sleeping lock is taken in the caller's context, only the leaf
spinlock of the slot, and the checks are snapshots the work repeats
under the device lock, so the helper may be called with the device
lock held, as the prepare, suspend, resume and complete callbacks,
->remove() and ->shutdown() hold it. The caller is the bound driver, in
a context its ->remove() waits for. Buses that take the parent lock to
bind are refused with -EINVAL: that lock has to be taken before @dev's
own, so the parent would have to be recorded before either is held,
where device_move() can replace it without taking any device lock.
usb_bus_type is the only such bus and no caller needs it today.
While probing is blocked, which device_shutdown() and dpm_prepare() both
set before they touch any device, a request that fires is dropped once
a halt, power-off or restart has begun and otherwise re-arms itself
once a second, so one pending across a system suspend or a hibernation
restore runs once the system has resumed. Beyond
that gate this is device_reprobe() deferred, with the release path of
__device_release_driver() untouched, so it carries device_reprobe()'s
pre-existing limitations: the detach and the re-attach are not one
locked operation, so an administrative unbind between them may be
undone, and detaching a device that has managed consumers unbinds them
as any release does, so a re-probe a concurrent device_shutdown()
overtakes may run ->remove() after ->shutdown(). None of this is
specific to the helper.
---
drivers/base/base.h | 5 ++
drivers/base/core.c | 1 +
drivers/base/dd.c | 172 +++++++++++++++++++++++++++++++++++++++++
include/linux/device.h | 2 +
4 files changed, 180 insertions(+)
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -103,6 +103,9 @@ struct driver_private {
* @dead - This device is currently either in the process of or has been
* removed from the system. Any asynchronous events scheduled for this
* device should exit without taking any action.
+ * @reprobe - request scheduled with device_schedule_reprobe(), held until
+ * its work has released the driver; cancelled when the device is
+ * deleted or the binding that scheduled it ends
*
* Nothing outside of the driver core should ever touch these fields.
*/
@@ -116,6 +119,7 @@ struct device_private {
const struct device_driver *async_driver;
char *deferred_probe_reason;
struct device *device;
+ struct device_reprobe *reprobe;
u8 dead:1;
};
#define to_device_private_parent(obj) \
@@ -200,6 +204,7 @@ static inline void device_set_driver(str
int devres_release_all(struct device *dev);
void device_block_probing(void);
void device_unblock_probing(void);
+void device_reprobe_cancel(struct device *dev);
void deferred_probe_extend_timeout(void);
void driver_deferred_probe_trigger(void);
const char *device_get_devnode(const struct device *dev, umode_t *mode,
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3923,6 +3923,7 @@ void device_del(struct device *dev)
device_lock(dev);
kill_device(dev);
device_unlock(dev);
+ device_reprobe_cancel(dev);
if (dev->fwnode && dev->fwnode->dev == dev)
dev->fwnode->dev = NULL;
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -607,6 +607,7 @@ static void device_unbind_cleanup(struct
kfree(dev->dma_range_map);
dev->dma_range_map = NULL;
device_set_driver(dev, NULL);
+ device_reprobe_cancel(dev);
dev_set_drvdata(dev, NULL);
dev_pm_domain_detach(dev, dev->power.detach_power_off);
if (dev->pm_domain && dev->pm_domain->dismiss)
@@ -1436,3 +1437,174 @@ void driver_detach(const struct device_d
put_device(dev);
}
}
+
+struct device_reprobe {
+ struct delayed_work work;
+ struct device *dev;
+};
+
+/* Retry interval while probing is blocked; the caller's delay may be 0. */
+#define DEVICE_REPROBE_BLOCKED_RETRY HZ
+
+/* Ties the slot in struct device_private to the queueing of its work. */
+static DEFINE_SPINLOCK(device_reprobe_lock);
+
+static void device_reprobe_free(struct device_reprobe *rp)
+{
+ put_device(rp->dev);
+ kfree(rp);
+}
+
+/*
+ * The slot holds a request from its scheduling until its work has released
+ * the driver. A pending work is freed here; a running one finds the slot no
+ * longer its own and frees itself.
+ */
+void device_reprobe_cancel(struct device *dev)
+{
+ struct device_reprobe *rp;
+ bool pending = false;
+
+ if (!dev->p)
+ return;
+ spin_lock(&device_reprobe_lock);
+ rp = dev->p->reprobe;
+ WRITE_ONCE(dev->p->reprobe, NULL);
+ if (rp)
+ pending = cancel_delayed_work(&rp->work);
+ spin_unlock(&device_reprobe_lock);
+ if (pending)
+ device_reprobe_free(rp);
+}
+
+static void device_reprobe_work_fn(struct work_struct *work)
+{
+ struct device_reprobe *rp = container_of(work, struct device_reprobe,
+ work.work);
+ struct device *dev = rp->dev;
+ bool rearm;
+ int ret;
+
+ device_lock(dev);
+ /* The slot still holding rp means the binding that scheduled it does. */
+ if (dev->p->dead || READ_ONCE(dev->p->reprobe) != rp) {
+ device_unlock(dev);
+ goto out;
+ }
+ if (defer_all_probes) {
+ device_unlock(dev);
+ spin_lock(&device_reprobe_lock);
+ rearm = dev->p->reprobe == rp &&
+ (system_state < SYSTEM_HALT ||
+ system_state == SYSTEM_SUSPEND) &&
+ queue_delayed_work(system_freezable_wq, &rp->work,
+ DEVICE_REPROBE_BLOCKED_RETRY);
+ spin_unlock(&device_reprobe_lock);
+ if (rearm)
+ return;
+ goto out;
+ }
+ /* Releasing the driver clears the slot, which was this request. */
+ __device_release_driver(dev, NULL);
+ device_unlock(dev);
+
+ /* A failed probe is logged by the probe path, as for a first probe. */
+ ret = device_attach(dev);
+ dev_dbg(dev, "re-probe: device_attach() returned %d\n", ret);
+out:
+ spin_lock(&device_reprobe_lock);
+ if (dev->p->reprobe == rp)
+ WRITE_ONCE(dev->p->reprobe, NULL);
+ spin_unlock(&device_reprobe_lock);
+ device_reprobe_free(rp);
+}
+
+/**
+ * device_schedule_reprobe - schedule a deferred detach and re-probe
+ * @dev: device to detach and re-probe
+ * @delay_ms: delay in milliseconds before the re-probe runs
+ *
+ * Schedule a detach and re-probe of @dev after @delay_ms milliseconds,
+ * from built-in driver-core work rather than a driver-owned work item,
+ * so the bound driver may call it without pinning its own module.
+ *
+ * At most one request exists per device, from its scheduling until its
+ * work has released the driver, and the request identifies the binding
+ * that scheduled it. It is cancelled when @dev is deleted or when that
+ * binding ends, whether by a release or by a failed probe, so neither an
+ * unbind followed by a rebind nor a module reload within the delay gets a
+ * re-probe it did not ask for; its reference on @dev is dropped with it,
+ * or once a work already running has finished. A request that fires
+ * while probing is blocked for a system suspend or a hibernation restore
+ * re-arms itself every second and runs once the system has resumed; one
+ * that fires while probing is blocked for a halt, power-off or restart is
+ * dropped. A failed re-probe leaves @dev unbound, as a failed initial
+ * probe would, and is logged by the probe path like one.
+ *
+ * This is device_reprobe() deferred, and shares its limitations; the
+ * release path of __device_release_driver() is untouched. The detach and
+ * the re-attach are not one locked operation, so an administrative unbind
+ * arriving between them may be undone. If @dev has managed consumers,
+ * detaching it unbinds them as any driver release does, so a re-probe a
+ * concurrent device_shutdown() overtakes may run ->remove() after
+ * ->shutdown(). None of this is specific to this helper.
+ *
+ * Buses that take the parent lock to bind (only usb_bus_type) are refused
+ * with -EINVAL: the parent would have to be recorded before either lock
+ * is held, where device_move() can replace it.
+ *
+ * Context: May sleep (allocates with %GFP_KERNEL). Must be called by the
+ * driver bound to @dev, from a process context its ->remove() waits for,
+ * so that the binding outlives the call; @dev's own device lock may be
+ * held. A request from ->probe() runs once the probe has returned and is
+ * cancelled if the probe fails.
+ *
+ * Returns: 0 on success, -EINVAL if @dev is not a registered device
+ * bound to a driver or sits on a bus which takes the parent lock to
+ * bind, -EBUSY if a re-probe of @dev is pending or has not yet released
+ * the driver, -ENOMEM on allocation failure.
+ */
+int device_schedule_reprobe(struct device *dev, unsigned int delay_ms)
+{
+ const struct device_driver *drv;
+ struct device_reprobe *rp;
+ int ret = 0;
+
+ drv = READ_ONCE(dev->driver);
+ /*
+ * A bus taking the parent lock would need @dev's parent pinned until
+ * the work runs, which device_move() can invalidate.
+ */
+ if (!drv || !dev->bus || dev->bus->need_parent_lock || !dev->p ||
+ dev->p->dead || !device_is_registered(dev))
+ return -EINVAL;
+
+ rp = kzalloc_obj(*rp);
+ if (!rp)
+ return -ENOMEM;
+
+ rp->dev = get_device(dev);
+ INIT_DELAYED_WORK(&rp->work, device_reprobe_work_fn);
+
+ /*
+ * A release or deletion that got here first has cleared the driver or
+ * set dead before cancelling, so a request published after its cancel
+ * is refused here; one published before is cancelled by it.
+ */
+ spin_lock(&device_reprobe_lock);
+ if (dev->p->reprobe)
+ ret = -EBUSY;
+ else if (dev->p->dead || READ_ONCE(dev->driver) != drv)
+ ret = -EINVAL;
+ else
+ WRITE_ONCE(dev->p->reprobe, rp);
+ if (!ret)
+ queue_delayed_work(system_freezable_wq, &rp->work,
+ msecs_to_jiffies(delay_ms));
+ spin_unlock(&device_reprobe_lock);
+ if (ret)
+ device_reprobe_free(rp);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(device_schedule_reprobe);
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1237,6 +1237,8 @@ int __must_check device_attach(struct d
int __must_check driver_attach(const struct device_driver *drv);
void device_initial_probe(struct device *dev);
int __must_check device_reprobe(struct device *dev);
+int __must_check device_schedule_reprobe(struct device *dev,
+ unsigned int delay_ms);
bool device_is_bound(struct device *dev);
@@ -1,103 +1,67 @@
From 66aaa1b09b0f2e9e74a7274a878c6902e1aa2b9c Mon Sep 17 00:00:00 2001 From beb8f60ed80bfacd375b4616474735cb23af8e5b Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org> From: Daniel Golle <daniel@makrotopia.org>
Date: Mon, 3 Aug 2026 04:52:03 +0100 Date: Fri, 14 Aug 2026 13:40:29 +0100
Subject: [PATCH net-next v10 3/5] net: dsa: mxl862xx: add devlink flash_update Subject: [PATCH net-next v19] net: dsa: mxl862xx: add devlink flash_update and
and info_get info_get
Implement runtime firmware upgrade via "devlink dev flash" and version Implement "devlink dev flash" for firmware upgrade and "devlink dev
reporting via "devlink dev info": info" for version reporting. info reports the chip part number and
revision as the asic.id and asic.rev fixed versions, and the firmware
version as both the running and the stored version, since the switch
boots its firmware from its own flash; a zero part number or an all-zero
version is omitted rather than published as a bogus match for userspace.
$ devlink dev info mdio_bus/mdio-bus:10 flash validates the image and its payload CRCs, reboots the switch into
mdio_bus/mdio-bus:10: its MCUboot loader with SYS_MISC_FW_UPDATE, transfers the image over the
driver mxl862xx SB PDI clause-22 SMDIO protocol, and reboots into the new firmware once
versions: the loader has verified it. For the duration the driver closes and
fixed: detaches the user ports so userspace cannot reopen them, closes the
asic.id 8628 conduit, and blocks firmware API access under the MDIO bus lock so
asic.rev 0 nothing reaches the bus after the switch has left for MCUboot. A blocked
running: write reports success, so a bridge tearing its ports down over a flash
fw 1.0.70 does not see port_vlan_del() fail and leak its VLAN group. A transfer
stored: that fails leaves the switch in the loader; the next patch recovers it
fw 1.0.70 from there.
The "asic.id" and "asic.rev" fixed versions carry the numeric chip part MCUboot offers no in-place path back, so the driver reinitialises with a
number and revision from the static CHIP ID registers (SYS_MISC_REG_RD), deferred re-probe scheduled through device_schedule_reprobe() from the
which userspace such as fwupd matches firmware against; they are omitted previous patch, which runs in the driver core off the devlink caller's
if the read fails or the part is unfused, so no bogus "0000" is locks and without pinning the driver module. ->shutdown() and
published. The switch boots its firmware from its own flash, so "fw" is .remove() take the devlink instance lock up front, since neither goes
reported as both the running and the stored version; a flashless part through devlink and dsa_unregister_switch() frees the user netdevs
would omit "stored", distinguishing the two without an API change. before devlink_unregister() would: this waits out a transfer in flight,
for as long as the transfer's own timeouts allow, rather than cutting
$ devlink dev flash mdio_bus/mdio-bus:10 file mxl862xx-fw.bin it in half, and refuses a flash that starts once teardown has begun. A
flash is refused as well until the DSA tree has finished its setup,
The image, including both payload CRCs, is validated first, so a since devlink registers the switch before the core creates the user
malformed file is rejected without disturbing the running switch. The ports.
driver then sends SYS_MISC_FW_UPDATE, which reboots the switch into its
MCUboot bootloader, and transfers the signed image over the SB PDI
protocol (clause-22 SMDIO), checking every write: a failed address write
at the half-bank boundary would otherwise misplace half the payload
unnoticed. A successful transfer reboots the switch into the new
firmware. The loader verifies the image once the last slice has been
programmed and publishes the verdict, so a rejected image is reported as
such rather than as a transfer timeout. The whole cycle takes just under
a minute.
For its duration the driver closes all user and conduit interfaces and
marks the user ports not-present with netif_device_detach() so userspace
cannot reopen them; the conduit belongs to the MAC driver and is only
closed. This also stops phylib polling the switch-internal PHYs,
unreachable in MCUboot. The bridge's deferred STP DISABLED transitions
are flushed under rtnl so they reach the firmware while it still runs;
the stats poll and CRC error handler are stopped; and firmware API
commands from other paths are blocked under the MDIO bus lock so none
reaches the bus once the switch has rebooted. Progress is reported
through devlink status notifications.
The switch leaves MCUboot on its own by booting the new image, but the
driver has no in-place path back, so it reinitialises with a full
device_reprobe() scheduled regardless of the transfer outcome. During
the teardown its API reads return -ENODEV and writes fake success, so it
neither stalls on the absent firmware nor consumes buffers it never
filled; port_mdb_del() takes that -ENODEV for a MAC table that is gone
and reports success, since there is nothing left to delete. The reprobe
holds module and device references taken before the switch was disturbed
and runs from a work item, off the devlink caller's locking and signal
context; it frees itself and drops both references when it finishes. A
failed reprobe leaves the device unbound, exactly as a failed initial
probe would, and a further flash is refused until it has run. An aborted
transfer leaves the switch in MCUboot, where nothing here can reach it;
the next patch adds the detection that makes such a switch flashable
again.
The reprobe cannot be cancelled from teardown: .shutdown() runs under
device_lock(), which device_reprobe() takes as well, so a lock shared
between the two would deadlock, and cancel_delayed_work_sync() would
hang on the nested remove() the work triggers itself. The work checks
instead whether the device is still bound, which both .shutdown() and
the driver core signal by clearing drvdata, and skips the reprobe when
it is not. device_lock() excludes .shutdown() while it looks, and the
dsa_switch is kept out of devres so that a .shutdown() slipping into
the remaining window cannot free it while the DSA tree still holds
dsa_ports pointing at it.
The closed user ports and conduit are not returned to their pre-flash
administrative state across the reprobe; userspace brings them back up,
and restoring it in-driver would need DSA-core support that does not
yet exist.
Signed-off-by: Daniel Golle <daniel@makrotopia.org> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- ---
drivers/net/dsa/mxl862xx/Kconfig | 1 +
drivers/net/dsa/mxl862xx/Makefile | 2 +- drivers/net/dsa/mxl862xx/Makefile | 2 +-
drivers/net/dsa/mxl862xx/mxl862xx-api.h | 10 + drivers/net/dsa/mxl862xx/mxl862xx-api.h | 10 +
drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 2 + drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 2 +
drivers/net/dsa/mxl862xx/mxl862xx-fw.c | 716 +++++++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-fw.c | 711 +++++++++++++++++++++++
drivers/net/dsa/mxl862xx/mxl862xx-fw.h | 17 + drivers/net/dsa/mxl862xx/mxl862xx-fw.h | 18 +
drivers/net/dsa/mxl862xx/mxl862xx-host.c | 11 + drivers/net/dsa/mxl862xx/mxl862xx-host.c | 31 +
drivers/net/dsa/mxl862xx/mxl862xx.c | 81 ++- drivers/net/dsa/mxl862xx/mxl862xx-host.h | 1 +
drivers/net/dsa/mxl862xx/mxl862xx.h | 14 + drivers/net/dsa/mxl862xx/mxl862xx.c | 83 ++-
8 files changed, 850 insertions(+), 3 deletions(-) drivers/net/dsa/mxl862xx/mxl862xx.h | 33 +-
10 files changed, 888 insertions(+), 4 deletions(-)
create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.c
create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.h create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.h
--- a/drivers/net/dsa/mxl862xx/Kconfig
+++ b/drivers/net/dsa/mxl862xx/Kconfig
@@ -3,6 +3,7 @@ config NET_DSA_MXL862
tristate "MaxLinear MxL862xx"
depends on NET_DSA
select CRC16
+ select CRC32
select NET_DSA_TAG_MXL_862XX
help
This enables support for the MaxLinear MxL862xx switch family.
--- a/drivers/net/dsa/mxl862xx/Makefile --- a/drivers/net/dsa/mxl862xx/Makefile
+++ b/drivers/net/dsa/mxl862xx/Makefile +++ b/drivers/net/dsa/mxl862xx/Makefile
@@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
@@ -138,7 +102,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#define MXL862XX_XPCS_PCS_GET_STATE (MXL862XX_XPCS_MAGIC + 0x2) #define MXL862XX_XPCS_PCS_GET_STATE (MXL862XX_XPCS_MAGIC + 0x2)
--- /dev/null --- /dev/null
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.c
@@ -0,0 +1,716 @@ @@ -0,0 +1,711 @@
+// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-License-Identifier: GPL-2.0-or-later
+/* +/*
+ * Firmware flash and devlink support for MaxLinear MxL862xx + * Firmware flash and devlink support for MaxLinear MxL862xx
@@ -212,17 +176,19 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ * - never send a slice/chunk count larger than what is outstanding; + * - never send a slice/chunk count larger than what is outstanding;
+ * - a STAT write is a command only once the loader has left the loop; + * - a STAT write is a command only once the loader has left the loop;
+ * - the loader leaves the count in STAT while it programs the chunk, so + * - the loader leaves the count in STAT while it programs the chunk, so
+ * a lingering count does not distinguish "busy" from "verdict". + * a lingering count does not distinguish "busy" from "verdict";
+ * - STAT is a 16-bit register, so a slice holds at most 65535 bytes,
+ * which is what bounds MXL862XX_FW_BANK_SLICE.
+ */ + */
+ +
+#include <linux/crc32.h> +#include <linux/crc32.h>
+#include <linux/delay.h> +#include <linux/delay.h>
+#include <linux/device.h> +#include <linux/device.h>
+#include <linux/iopoll.h> +#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/netdevice.h> +#include <linux/netdevice.h>
+#include <linux/overflow.h> +#include <linux/overflow.h>
+#include <linux/rtnetlink.h> +#include <linux/rtnetlink.h>
+#include <linux/sched.h>
+#include <linux/workqueue.h> +#include <linux/workqueue.h>
+#include <net/dsa.h> +#include <net/dsa.h>
+#include <net/switchdev.h> +#include <net/switchdev.h>
@@ -255,7 +221,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+/* Firmware transfer geometry */ +/* Firmware transfer geometry */
+#define MXL862XX_FW_HDR_SIZE 20 +#define MXL862XX_FW_HDR_SIZE 20
+#define MXL862XX_FW_BANK_HALF 16384 /* words per half-bank */ +#define MXL862XX_FW_BANK_HALF 16384 /* words per half-bank */
+#define MXL862XX_FW_BANK_SLICE 32760 /* words per full slice */ +#define MXL862XX_FW_BANK_SLICE 32760 /* words per full slice, 65520 B */
+#define MXL862XX_FW_SB1_ADDR 0x7800 /* SB1 word address */ +#define MXL862XX_FW_SB1_ADDR 0x7800 /* SB1 word address */
+ +
+/* Timeouts (generous upper bounds) */ +/* Timeouts (generous upper bounds) */
@@ -263,6 +229,10 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+#define MXL862XX_FW_ACK_TIMEOUT_MS 5000 +#define MXL862XX_FW_ACK_TIMEOUT_MS 5000
+#define MXL862XX_FW_ERASE_TIMEOUT_MS 300000 +#define MXL862XX_FW_ERASE_TIMEOUT_MS 300000
+#define MXL862XX_FW_WRITE_TIMEOUT_MS 60000 +#define MXL862XX_FW_WRITE_TIMEOUT_MS 60000
+/* Covers the loader's END wait, verification and the reset into READY */
+#define MXL862XX_SB_PDI_VERIFY_MS 15000
+
+/* Delays spent in full: the reboot into the new image, and the re-probe */
+#define MXL862XX_FW_REBOOT_DELAY_MS 5000 +#define MXL862XX_FW_REBOOT_DELAY_MS 5000
+#define MXL862XX_FW_REPROBE_DELAY_MS 500 +#define MXL862XX_FW_REPROBE_DELAY_MS 500
+ +
@@ -270,18 +240,17 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+{ +{
+ int ret; + int ret;
+ +
+ /* CTRL selects RST mode; ADDR and DATA are cleared to 0. */
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL,
+ MXL862XX_SB_PDI_CTRL_RST); + MXL862XX_SB_PDI_CTRL_RST);
+ if (ret < 0) + if (ret < 0)
+ return ret; + return ret;
+ +
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_ADDR, + ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_ADDR, 0x0000);
+ MXL862XX_SB_PDI_CTRL_RST);
+ if (ret < 0) + if (ret < 0)
+ return ret; + return ret;
+ +
+ return mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, + return mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, 0x0000);
+ MXL862XX_SB_PDI_CTRL_RST);
+} +}
+ +
+static int mxl862xx_sb_pdi_poll_stat(struct mxl862xx_priv *priv, u16 expected, +static int mxl862xx_sb_pdi_poll_stat(struct mxl862xx_priv *priv, u16 expected,
@@ -334,7 +303,8 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ +
+ ret = read_poll_timeout(mxl862xx_smdio_read, val, + ret = read_poll_timeout(mxl862xx_smdio_read, val,
+ val < 0 || (u16)val != (u16)data_written, + val < 0 || (u16)val != (u16)data_written,
+ 10000, MXL862XX_FW_WRITE_TIMEOUT_MS * 1000, + 10000, (MXL862XX_FW_WRITE_TIMEOUT_MS +
+ MXL862XX_SB_PDI_VERIFY_MS) * 1000,
+ false, priv, MXL862XX_SB_PDI_STAT); + false, priv, MXL862XX_SB_PDI_STAT);
+ if (val < 0) + if (val < 0)
+ return val; + return val;
@@ -360,65 +330,6 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ devlink_flash_update_status_notify(dl, status, NULL, done, total); + devlink_flash_update_status_notify(dl, status, NULL, done, total);
+} +}
+ +
+/* Post-flash reprobe. device_reprobe() detaches the driver -- running
+ * remove(), which frees priv -- then re-probes, so this work touches only its
+ * own device and module references and frees itself. A re-probe failure leaves
+ * the device unbound, exactly as a failed initial probe would, so it is only
+ * logged. Running from a workqueue keeps device_reprobe() out of the devlink
+ * caller's locking and signal context.
+ *
+ * The work cannot be cancelled from teardown: .shutdown() runs under
+ * device_lock(), which device_reprobe() takes as well, so a lock the two could
+ * share would deadlock, and cancel_delayed_work_sync() would hang on the
+ * nested remove() this work triggers itself. It therefore checks instead:
+ * drvdata is cleared both by .shutdown() and by the driver core once a device
+ * is unbound, so a NULL means there is nothing left to reprobe. device_lock()
+ * excludes .shutdown() while the check runs, and mxl862xx_probe() keeps the
+ * dsa_switch allocation out of devres so that losing the remaining race with
+ * .shutdown() cannot free it while the DSA tree still points at it.
+ */
+struct mxl862xx_reprobe {
+ struct delayed_work work;
+ struct device *dev;
+};
+
+static void mxl862xx_reprobe_work_fn(struct work_struct *work)
+{
+ struct mxl862xx_reprobe *rp =
+ container_of(work, struct mxl862xx_reprobe, work.work);
+ struct device *dev = rp->dev;
+ bool bound;
+
+ device_lock(dev);
+ bound = !!dev_get_drvdata(dev);
+ device_unlock(dev);
+
+ if (!bound)
+ dev_dbg(dev, "reprobe skipped, device is gone\n");
+ else if (device_reprobe(dev))
+ dev_err(dev, "reprobe failed; device left unbound\n");
+
+ put_device(dev);
+ kfree(rp);
+ module_put(THIS_MODULE);
+}
+
+/* Allocate the reprobe up front, before the switch is disturbed, so an
+ * allocation failure aborts cleanly. The caller holds a module and a device
+ * reference; the work releases both once it runs. Returns NULL on -ENOMEM.
+ */
+static struct mxl862xx_reprobe *mxl862xx_reprobe_alloc(struct device *dev)
+{
+ struct mxl862xx_reprobe *rp;
+
+ rp = kzalloc_obj(*rp);
+ if (!rp)
+ return NULL;
+ rp->dev = dev;
+ INIT_DELAYED_WORK(&rp->work, mxl862xx_reprobe_work_fn);
+ return rp;
+}
+
+/* MCUboot firmware image header */ +/* MCUboot firmware image header */
+struct mxl862xx_fw_hdr { +struct mxl862xx_fw_hdr {
+ __le32 image_type; + __le32 image_type;
@@ -491,7 +402,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ u32 word_idx = 0, data_written = 0, idx = 0; + u32 word_idx = 0, data_written = 0, idx = 0;
+ unsigned long next_notify = jiffies - 1; + unsigned long next_notify = jiffies - 1;
+ u16 word, fdata; + u16 word, fdata;
+ int ret, i; + int ret, val, i;
+ +
+ /* Step 1: reboot the firmware into MCUboot rescue mode */ + /* Step 1: reboot the firmware into MCUboot rescue mode */
+ ret = mxl862xx_api_wrap(priv, SYS_MISC_FW_UPDATE, NULL, 0, + ret = mxl862xx_api_wrap(priv, SYS_MISC_FW_UPDATE, NULL, 0,
@@ -559,9 +470,18 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ if (ret < 0) + if (ret < 0)
+ goto write_err; + goto write_err;
+ +
+ /* ACK is byte count + 1 */ + /* The ACK is the count + 1, replaced by 0 as soon as the erase is done,
+ ret = mxl862xx_sb_pdi_poll_stat(priv, MXL862XX_FW_HDR_SIZE + 1, + * so wait for the count to go: a short erase retires the ACK between
+ MXL862XX_FW_ACK_TIMEOUT_MS); + * two polls.
+ */
+ ret = read_poll_timeout(mxl862xx_smdio_read, val,
+ val < 0 || (u16)val != MXL862XX_FW_HDR_SIZE,
+ 10000, MXL862XX_FW_ACK_TIMEOUT_MS * 1000, false,
+ priv, MXL862XX_SB_PDI_STAT);
+ if (val < 0)
+ ret = val;
+ if (!ret && (u16)val != MXL862XX_FW_HDR_SIZE + 1 && (u16)val != 0)
+ ret = -EPROTO;
+ if (ret) { + if (ret) {
+ dev_err(&priv->mdiodev->dev, + dev_err(&priv->mdiodev->dev,
+ "flash: header ACK failed: %pe\n", ERR_PTR(ret)); + "flash: header ACK failed: %pe\n", ERR_PTR(ret));
@@ -573,7 +493,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ MXL862XX_FW_ERASE_TIMEOUT_MS); + MXL862XX_FW_ERASE_TIMEOUT_MS);
+ if (ret) { + if (ret) {
+ dev_err(&priv->mdiodev->dev, + dev_err(&priv->mdiodev->dev,
+ "flash: erase timeout: %pe\n", ERR_PTR(ret)); + "flash: erase failed: %pe\n", ERR_PTR(ret));
+ goto no_end; + goto no_end;
+ } + }
+ +
@@ -626,7 +546,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ ret = mxl862xx_sb_pdi_flush_slice(priv, data_written); + ret = mxl862xx_sb_pdi_flush_slice(priv, data_written);
+ if (ret) { + if (ret) {
+ dev_err(&priv->mdiodev->dev, + dev_err(&priv->mdiodev->dev,
+ "flash: write timeout at %u/%u: %pe\n", + "flash: write failed at %u/%u: %pe\n",
+ idx, payload_size, ERR_PTR(ret)); + idx, payload_size, ERR_PTR(ret));
+ goto no_end; + goto no_end;
+ } + }
@@ -646,8 +566,10 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ } + }
+ +
+ if (ret) { + if (ret) {
+ dev_err(&priv->mdiodev->dev, + /* a rejected image (-EBADMSG) has been logged where it was seen */
+ "flash: final slice failed: %pe\n", ERR_PTR(ret)); + if (ret != -EBADMSG)
+ dev_err(&priv->mdiodev->dev,
+ "flash: final slice failed: %pe\n", ERR_PTR(ret));
+ goto no_end; + goto no_end;
+ } + }
+ +
@@ -660,16 +582,21 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ */ + */
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, + ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT,
+ MXL862XX_SB_PDI_END); + MXL862XX_SB_PDI_END);
+ if (ret < 0)
+ dev_warn(&priv->mdiodev->dev,
+ "flash: END signalling failed, waiting the loader out: %pe\n",
+ ERR_PTR(ret));
+
+ msleep(MXL862XX_FW_REBOOT_DELAY_MS); + msleep(MXL862XX_FW_REBOOT_DELAY_MS);
+ return ret; + return 0;
+ +
+write_err: +write_err:
+ dev_err(&priv->mdiodev->dev, "flash: SMDIO write failed: %pe\n", + dev_err(&priv->mdiodev->dev, "flash: SMDIO write failed: %pe\n",
+ ERR_PTR(ret)); + ERR_PTR(ret));
+no_end: +no_end:
+ /* A failure leaves the loader mid transfer; do not signal END (a STAT + /* A failure may leave the loader mid transfer, where a STAT write is a
+ * write is a byte count then, and END would be misread as one, risking + * byte count and END would be misread as one, risking a receive-counter
+ * a receive-counter underflow). Return the error; the caller reprobes. + * underflow, so END is never signalled here. The caller reprobes.
+ */ + */
+ return ret; + return ret;
+} +}
@@ -682,10 +609,10 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ char buf[16]; + char buf[16];
+ int ret; + int ret;
+ +
+ /* A 0 part number means the CHIP ID read failed or the part is + /* A 0 part number means the CHIP ID read failed, the part is unfused
+ * unfused; omit it rather than publish a bogus "0000" that fwupd + * or a flash failed; omit it rather than publish a bogus "0000" that
+ * would match firmware against -- it then falls back to the driver + * fwupd would match firmware against, it then falls back to the
+ * name. + * driver name.
+ */ + */
+ if (priv->asic_id) { + if (priv->asic_id) {
+ snprintf(buf, sizeof(buf), "%04X", priv->asic_id); + snprintf(buf, sizeof(buf), "%04X", priv->asic_id);
@@ -729,23 +656,31 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ struct netlink_ext_ack *extack) + struct netlink_ext_ack *extack)
+{ +{
+ struct mxl862xx_priv *priv = ds->priv; + struct mxl862xx_priv *priv = ds->priv;
+ struct mxl862xx_reprobe *ko;
+ struct dsa_port *dp; + struct dsa_port *dp;
+ u32 payload_size; + u32 payload_size;
+ int ret, i; + int ret, err, i;
+ +
+ if (params->component) { + /* devlink registers the switch before the DSA core creates its user
+ NL_SET_ERR_MSG_MOD(extack, "component is not supported"); + * ports, which it publishes without rtnl held.
+ return -EOPNOTSUPP; + */
+ if (!ds->dst->setup) {
+ NL_SET_ERR_MSG_MOD(extack, "switch tree is not set up");
+ return -EBUSY;
+ } + }
+ +
+ /* A previous flash is still waiting for its reprobe: the firmware API + /* Written under the instance lock this call is holding. */
+ * is short-circuited, so the raw SB PDI writes below would run against + if (priv->shutting_down) {
+ * a switch this driver no longer tracks. + NL_SET_ERR_MSG_MOD(extack, "device is shutting down");
+ return -ENODEV;
+ }
+
+ /* A previous flash has short-circuited the firmware API until the
+ * reprobe or a rebind, so the raw SB PDI writes below would run
+ * against a switch this driver no longer tracks.
+ */ + */
+ if (priv->skip_teardown) { + if (priv->skip_teardown) {
+ NL_SET_ERR_MSG_MOD(extack, + NL_SET_ERR_MSG_MOD(extack,
+ "device is reinitializing, retry later"); + "a previous flash left the driver awaiting reinitialisation");
+ return -EBUSY; + return -EBUSY;
+ } + }
+ +
@@ -755,25 +690,6 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ return ret; + return ret;
+ } + }
+ +
+ /* The references the reprobe work needs to restore normal operation
+ * must be held before the switch is disturbed; the work itself is
+ * scheduled only once the flash is done (see below).
+ */
+ if (!try_module_get(THIS_MODULE))
+ return -ENODEV;
+
+ get_device(ds->dev);
+
+ /* Allocate the reprobe work before disturbing the switch, so an
+ * -ENOMEM here cannot strand it flashed but never reprobed.
+ */
+ ko = mxl862xx_reprobe_alloc(ds->dev);
+ if (!ko) {
+ put_device(ds->dev);
+ module_put(THIS_MODULE);
+ return -ENOMEM;
+ }
+
+ dev_info(ds->dev, "flash: running firmware %u.%u.%u\n", + dev_info(ds->dev, "flash: running firmware %u.%u.%u\n",
+ priv->fw_version.major, priv->fw_version.minor, + priv->fw_version.major, priv->fw_version.minor,
+ priv->fw_version.revision); + priv->fw_version.revision);
@@ -800,26 +716,33 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ */ + */
+ switchdev_deferred_process(); + switchdev_deferred_process();
+ rtnl_unlock(); + rtnl_unlock();
+ /* The bridge's host address deletions run on the DSA workqueue. */
+ dsa_flush_workqueue();
+ +
+ mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); + mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED);
+ priv->block_host = true; + priv->block_host = true;
+ mutex_unlock(&priv->mdiodev->bus->mdio_lock); + mutex_unlock(&priv->mdiodev->bus->mdio_lock);
+ +
+ set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags); + set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags);
+ cancel_delayed_work_sync(&priv->stats_work); + disable_delayed_work_sync(&priv->stats_work);
+ cancel_work_sync(&priv->crc_err_work); + cancel_work_sync(&priv->crc_err_work);
+ for (i = 0; i < ds->num_ports; i++) + for (i = 0; i < ds->num_ports; i++)
+ cancel_work_sync(&priv->ports[i].host_flood_work); + cancel_work_sync(&priv->ports[i].host_flood_work);
+ +
+ ret = mxl862xx_flash_firmware(priv, params->fw, payload_size, + ret = mxl862xx_flash_firmware(priv, params->fw, payload_size,
+ ds->devlink); + ds->devlink);
+ if (ret) + if (ret == -EBADMSG)
+ NL_SET_ERR_MSG_MOD(extack, "firmware transfer failed"); + NL_SET_ERR_MSG_MOD(extack, "loader rejected the image");
+ else if (ret)
+ NL_SET_ERR_MSG_MOD(extack, "firmware update failed");
+ +
+ if (!ret) { + if (!ret) {
+ mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, + mutex_lock_nested(&priv->mdiodev->bus->mdio_lock,
+ MDIO_MUTEX_NESTED); + MDIO_MUTEX_NESTED);
+ priv->block_host = false; + /* Keep block_host set so host writes stay blocked, but let the
+ * readiness poll below read the freshly booted firmware.
+ */
+ priv->flash_owner = current;
+ mutex_unlock(&priv->mdiodev->bus->mdio_lock); + mutex_unlock(&priv->mdiodev->bus->mdio_lock);
+ +
+ /* Refresh the cached versions so the flash update only + /* Refresh the cached versions so the flash update only
@@ -834,9 +757,9 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ } + }
+ +
+ if (ret) { + if (ret) {
+ /* The switch is in MCUboot with erased or partly written flash; + /* The loader may hold an erased or partly written image; drop
+ * drop the cached identity so devlink dev info stops reporting + * the cached identity so devlink dev info stops reporting the
+ * the pre-flash version until the reprobe re-reads the truth. + * pre-flash version until the reprobe re-reads the truth.
+ */ + */
+ memset(&priv->fw_version, 0, sizeof(priv->fw_version)); + memset(&priv->fw_version, 0, sizeof(priv->fw_version));
+ priv->asic_id = 0; + priv->asic_id = 0;
@@ -844,20 +767,56 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ } + }
+ +
+ mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); + mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED);
+ priv->flash_owner = NULL;
+ priv->block_host = false;
+ priv->skip_teardown = true; + priv->skip_teardown = true;
+ mutex_unlock(&priv->mdiodev->bus->mdio_lock); + mutex_unlock(&priv->mdiodev->bus->mdio_lock);
+ +
+ /* Queue the reprobe last; the work was allocated up front and its + /* Reinitialise through a deferred re-probe: remove() runs with
+ * module and device references are already held. + * skip_teardown set, then a fresh probe() starts against whatever
+ * the switch now runs. The core drops the re-probe if the device is
+ * unbound or deleted before it fires.
+ */ + */
+ queue_delayed_work(system_long_wq, &ko->work, + err = device_schedule_reprobe(ds->dev, MXL862XX_FW_REPROBE_DELAY_MS);
+ msecs_to_jiffies(MXL862XX_FW_REPROBE_DELAY_MS)); + /* -EINVAL is a device being deleted, whose teardown takes over. */
+ if (err == -EINVAL)
+ err = 0;
+ if (err)
+ dev_err(ds->dev,
+ "flash: re-probe could not be scheduled (%pe); unbind and rebind to reinitialise\n",
+ ERR_PTR(err));
+ if (err && !ret)
+ NL_SET_ERR_MSG_MOD(extack,
+ "new firmware is running, the driver needs rebinding");
+ +
+ return ret; + return ret ? ret : err;
+}
+
+/* The devlink core holds the instance lock across a flash, so taking it here
+ * waits for a transfer in flight instead of cutting the image in half, and
+ * bars one that has not started yet.
+ */
+void mxl862xx_flash_shutdown(struct dsa_switch *ds)
+{
+ struct mxl862xx_priv *priv = ds->priv;
+
+ if (!ds->devlink)
+ return;
+
+ /* A flash holds the instance lock for its whole run. Announce the
+ * wait so the delay is not mistaken for a hang.
+ */
+ if (!devl_trylock(ds->devlink)) {
+ dev_info(ds->dev,
+ "firmware update in progress, waiting for it to finish\n");
+ devl_lock(ds->devlink);
+ }
+ priv->shutting_down = true;
+ devl_unlock(ds->devlink);
+} +}
--- /dev/null --- /dev/null
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.h
@@ -0,0 +1,17 @@ @@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* SPDX-License-Identifier: GPL-2.0-or-later */
+ +
+#ifndef __MXL862XX_FW_H +#ifndef __MXL862XX_FW_H
@@ -873,11 +832,16 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+int mxl862xx_devlink_flash_update(struct dsa_switch *ds, +int mxl862xx_devlink_flash_update(struct dsa_switch *ds,
+ struct devlink_flash_update_params *params, + struct devlink_flash_update_params *params,
+ struct netlink_ext_ack *extack); + struct netlink_ext_ack *extack);
+void mxl862xx_flash_shutdown(struct dsa_switch *ds);
+ +
+#endif /* __MXL862XX_FW_H */ +#endif /* __MXL862XX_FW_H */
--- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c --- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c
@@ -15,6 +15,7 @@ @@ -12,9 +12,11 @@
#include <linux/crc16.h>
#include <linux/iopoll.h>
#include <linux/limits.h>
+#include <linux/sched.h>
#include <linux/unaligned.h> #include <linux/unaligned.h>
#include <net/dsa.h> #include <net/dsa.h>
#include "mxl862xx.h" #include "mxl862xx.h"
@@ -885,7 +849,25 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#include "mxl862xx-host.h" #include "mxl862xx-host.h"
#define CTRL_BUSY_MASK BIT(15) #define CTRL_BUSY_MASK BIT(15)
@@ -340,6 +341,16 @@ int mxl862xx_api_wrap(struct mxl862xx_pr @@ -327,6 +329,17 @@ static int mxl862xx_send_cmd(struct mxl8
return ret;
}
+bool mxl862xx_api_gated(struct mxl862xx_priv *priv)
+{
+ bool gated;
+
+ mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED);
+ gated = priv->block_host || priv->skip_teardown;
+ mutex_unlock(&priv->mdiodev->bus->mdio_lock);
+
+ return gated;
+}
+
int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd, void *_data,
u16 size, bool read, bool quiet)
{
@@ -340,6 +353,24 @@ int mxl862xx_api_wrap(struct mxl862xx_pr
mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED);
@@ -894,14 +876,32 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ goto out; + goto out;
+ } + }
+ +
+ if (priv->block_host && cmd != SYS_MISC_FW_UPDATE) { + /* During the post-flash readiness poll block_host stays set, but the
+ ret = -EBUSY; + * flash path's own firmware version reads must reach the new image;
+ * host writes stay blocked so stale resource IDs cannot corrupt it.
+ * A blocked write reports success: the reprobe discards the switch
+ * configuration anyway, and a bridge tearing down over a flash must
+ * not see port_vlan_del() fail, which leaks its VLAN group.
+ */
+ if (priv->block_host && cmd != SYS_MISC_FW_UPDATE &&
+ !(read && priv->flash_owner == current)) {
+ ret = read ? -EBUSY : 0;
+ goto out; + goto out;
+ } + }
+ +
max = (size + 1) / 2; max = (size + 1) / 2;
ret = mxl862xx_busy_wait(priv); ret = mxl862xx_busy_wait(priv);
--- a/drivers/net/dsa/mxl862xx/mxl862xx-host.h
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.h
@@ -7,6 +7,7 @@
void mxl862xx_host_init(struct mxl862xx_priv *priv);
void mxl862xx_host_shutdown(struct mxl862xx_priv *priv);
+bool mxl862xx_api_gated(struct mxl862xx_priv *priv);
int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd, void *data, u16 size,
bool read, bool quiet);
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c --- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
@@ -926,14 +926,13 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#define MXL862XX_TCM_INST_SEL 0xe00 #define MXL862XX_TCM_INST_SEL 0xe00
#define MXL862XX_TCM_CBS 0xe12 #define MXL862XX_TCM_CBS 0xe12
#define MXL862XX_TCM_EBS 0xe13 #define MXL862XX_TCM_EBS 0xe13
@@ -222,7 +230,46 @@ static int mxl862xx_phy_write_c45_mii_bu @@ -222,7 +230,48 @@ static int mxl862xx_phy_write_c45_mii_bu
return mxl862xx_phy_write_mmd(bus->priv, addr, devadd, regnum, val); return mxl862xx_phy_write_mmd(bus->priv, addr, devadd, regnum, val);
} }
-static int mxl862xx_wait_ready(struct dsa_switch *ds) -static int mxl862xx_wait_ready(struct dsa_switch *ds)
+/* Read the static chip part number and version from the CHIP ID +/* The CHIP ID registers are only readable through the firmware mailbox, so
+ * registers. Only possible with a running firmware, so the values are + * the values are cached here and stay zero while no firmware answers.
+ * cached at setup and left zero when the switch is in rescue mode.
+ */ + */
+static int mxl862xx_read_chip_id(struct mxl862xx_priv *priv) +static int mxl862xx_read_chip_id(struct mxl862xx_priv *priv)
+{ +{
@@ -941,6 +940,9 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ u16 chipid_l, chipid_m; + u16 chipid_l, chipid_m;
+ int ret; + int ret;
+ +
+ priv->asic_id = 0;
+ priv->asic_rev = 0;
+
+ reg.addr = cpu_to_le32(MXL862XX_CHIPID_L); + reg.addr = cpu_to_le32(MXL862XX_CHIPID_L);
+ ret = MXL862XX_API_READ(priv, SYS_MISC_REG_RD, reg); + ret = MXL862XX_API_READ(priv, SYS_MISC_REG_RD, reg);
+ if (ret) + if (ret)
@@ -965,8 +967,8 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ * @ds: DSA switch instance + * @ds: DSA switch instance
+ * + *
+ * Poll the firmware until it reports its version and accepts + * Poll the firmware until it reports its version and accepts
+ * configuration commands, then cache the firmware version and chip ID. + * configuration commands, then cache the firmware version, and the chip
+ * Takes at least two seconds. + * ID when it can be read. Takes at least two seconds.
+ * + *
+ * Return: 0 on success or a negative error code. + * Return: 0 on success or a negative error code.
+ */ + */
@@ -974,7 +976,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
{ {
struct mxl862xx_sys_fw_image_version ver = {}; struct mxl862xx_sys_fw_image_version ver = {};
unsigned long start = jiffies, timeout; unsigned long start = jiffies, timeout;
@@ -272,6 +319,11 @@ static int mxl862xx_wait_ready(struct ds @@ -272,6 +321,11 @@ static int mxl862xx_wait_ready(struct ds
priv->fw_version.major = ver.iv_major; priv->fw_version.major = ver.iv_major;
priv->fw_version.minor = ver.iv_minor; priv->fw_version.minor = ver.iv_minor;
priv->fw_version.revision = le16_to_cpu(ver.iv_revision); priv->fw_version.revision = le16_to_cpu(ver.iv_revision);
@@ -986,33 +988,45 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return 0; return 0;
not_ready_yet: not_ready_yet:
@@ -1590,6 +1642,12 @@ static int mxl862xx_port_mdb_del(struct @@ -1565,6 +1619,12 @@ static int mxl862xx_port_mdb_add(struct
ether_addr_copy(qparam.mac, mdb->addr); qparam.tci = cpu_to_le16(FIELD_PREP(MXL862XX_TCI_VLAN_ID, mdb->vid));
ret = MXL862XX_API_READ(priv, MXL862XX_MAC_TABLEENTRYQUERY, qparam); ret = MXL862XX_API_READ(priv, MXL862XX_MAC_TABLEENTRYQUERY, qparam);
+ /* Post-flash teardown: the firmware and its MAC table are gone, so + /* A flash blocks the API (-EBUSY) and its teardown drops the MAC
+ * there is nothing left to delete. Outside it, -ENODEV is a bus error + * table (-ENODEV); there is then nothing to program, and the reprobe
+ * and must be reported. + * starts from a fresh configuration. See mxl862xx_port_mdb_del().
+ */ + */
+ if (ret == -ENODEV && priv->skip_teardown) + if ((ret == -EBUSY || ret == -ENODEV) && mxl862xx_api_gated(priv))
+ return 0; + return 0;
if (ret) if (ret)
return ret; return ret;
@@ -2037,6 +2095,12 @@ static void mxl862xx_stats_work_fn(struc @@ -1602,6 +1662,12 @@ static int mxl862xx_port_mdb_del(struct
struct dsa_switch *ds = priv->ds; ether_addr_copy(qparam.mac, mdb->addr);
struct dsa_port *dp;
+ /* A get_stats64() re-arm can race the flash teardown's WORK_STOPPED ret = MXL862XX_API_READ(priv, MXL862XX_MAC_TABLEENTRYQUERY, qparam);
+ * set and cancel; bail here so a stray poll never runs during a flash. + /* A flash blocks the API (-EBUSY) and its teardown drops the MAC
+ * table (-ENODEV); a delete then has nothing to do. Outside these,
+ * both are bus errors and must be reported.
+ */ + */
+ if (test_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags)) + if ((ret == -EBUSY || ret == -ENODEV) && mxl862xx_api_gated(priv))
+ return; + return 0;
+ if (ret)
dsa_switch_for_each_available_port(dp, ds) return ret;
mxl862xx_stats_poll(ds, dp->index);
@@ -2108,6 +2172,8 @@ static const struct dsa_switch_ops mxl86 @@ -1838,6 +1904,11 @@ static void mxl862xx_get_ethtool_stats(s
void *field;
ret = mxl862xx_read_rmon(ds, port, &cnt);
+ /* The flash gates refuse with these, and ethtool -S needs no privilege
+ * to reach them, so they must not log.
+ */
+ if ((ret == -EBUSY || ret == -ENODEV) && mxl862xx_api_gated(ds->priv))
+ return;
if (ret) {
dev_err(ds->dev, "failed to read RMON stats on port %d\n", port);
return;
@@ -2119,6 +2190,8 @@ static const struct dsa_switch_ops mxl86
.get_pause_stats = mxl862xx_get_pause_stats, .get_pause_stats = mxl862xx_get_pause_stats,
.get_rmon_stats = mxl862xx_get_rmon_stats, .get_rmon_stats = mxl862xx_get_rmon_stats,
.get_stats64 = mxl862xx_get_stats64, .get_stats64 = mxl862xx_get_stats64,
@@ -1021,46 +1035,44 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
}; };
static int mxl862xx_probe(struct mdio_device *mdiodev) static int mxl862xx_probe(struct mdio_device *mdiodev)
@@ -2123,7 +2189,13 @@ static int mxl862xx_probe(struct mdio_de @@ -2183,6 +2256,12 @@ static void mxl862xx_remove(struct mdio_
priv->mdiodev = mdiodev; priv = ds->priv;
- ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL); + /* Wait out a flash in flight and bar a new one before the DSA core
+ /* Not devres managed: .shutdown() leaves the DSA tree holding + * frees the user netdevs; the devlink instance lock does not cover
+ * dsa_ports whose dp->ds points here, and the flash reprobe can + * that free, which dsa_unregister_switch() reaches first.
+ * detach the driver afterwards, which would let devres free this
+ * while dsa_switch_find() still walks it. Freed in .remove() only,
+ * so a switch that was shut down keeps it until the power goes.
+ */ + */
+ ds = kzalloc_obj(*ds); + mxl862xx_flash_shutdown(ds);
if (!ds)
return -ENOMEM;
@@ -2157,6 +2229,8 @@ static int mxl862xx_probe(struct mdio_de
mxl862xx_host_shutdown(priv);
for (i = 0; i < MXL862XX_MAX_PORTS; i++)
cancel_work_sync(&priv->ports[i].host_flood_work);
+ dev_set_drvdata(dev, NULL);
+ kfree(ds);
}
return err;
@@ -2187,6 +2261,9 @@ static void mxl862xx_remove(struct mdio_
*/
for (i = 0; i < MXL862XX_MAX_PORTS; i++)
cancel_work_sync(&priv->ports[i].host_flood_work);
+ +
+ dev_set_drvdata(&mdiodev->dev, NULL); set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags);
+ kfree(ds);
}
static void mxl862xx_shutdown(struct mdio_device *mdiodev) dsa_unregister_switch(ds);
@@ -2209,6 +2288,8 @@ static void mxl862xx_shutdown(struct mdi
priv = ds->priv;
+ mxl862xx_flash_shutdown(ds);
+
dsa_switch_shutdown(ds);
set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags);
--- a/drivers/net/dsa/mxl862xx/mxl862xx.h --- a/drivers/net/dsa/mxl862xx/mxl862xx.h
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx.h
@@ -303,6 +303,10 @@ struct mxl862xx_fw_version { @@ -298,11 +298,18 @@ struct mxl862xx_fw_version {
* before CRC-triggered shutdown and cleared after;
* %MXL862XX_FLAG_WORK_STOPPED is set before cancelling
* stats_work to prevent rescheduling during teardown
+ * and a flash
* @drop_meter: index of the single shared zero-rate firmware meter
* used to unconditionally drop traffic (used to block
* flooding) * flooding)
* @fw_version: cached firmware version, populated at probe and - * @fw_version: cached firmware version, populated at probe and
* compared with MXL862XX_FW_VER_MIN() - * compared with MXL862XX_FW_VER_MIN()
+ * @fw_version: cached firmware version, compared with
+ * MXL862XX_FW_VER_MIN(); refreshed by
+ * mxl862xx_wait_ready() after a flash and cleared by
+ * a failed one until the reprobe
+ * @asic_id: chip part number read from the CHIP ID registers, + * @asic_id: chip part number read from the CHIP ID registers,
+ * reported as the devlink "asic.id" fixed version + * reported as the devlink "asic.id" fixed version
+ * @asic_rev: chip version read from the CHIP ID registers, + * @asic_rev: chip version read from the CHIP ID registers,
@@ -1068,18 +1080,28 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* @serdes_ports: SerDes interfaces incl. sub-interfaces in case of * @serdes_ports: SerDes interfaces incl. sub-interfaces in case of
* 10G_QXGMII or QSGMII * 10G_QXGMII or QSGMII
* @serdes_refcount: per-XPCS count of sub-ports enabled by phylink; * @serdes_refcount: per-XPCS count of sub-ports enabled by phylink;
@@ -319,6 +323,10 @@ struct mxl862xx_fw_version { @@ -319,6 +326,20 @@ struct mxl862xx_fw_version {
* @evlan_ingress_size: per-port ingress Extended VLAN block size * @evlan_ingress_size: per-port ingress Extended VLAN block size
* @evlan_egress_size: per-port egress Extended VLAN block size * @evlan_egress_size: per-port egress Extended VLAN block size
* @vf_block_size: per-port VLAN Filter block size * @vf_block_size: per-port VLAN Filter block size
+ * @block_host: reject firmware API commands (except FW_UPDATE) + * @block_host: during a firmware flash, a host firmware read fails
+ * during a firmware flash + * with -EBUSY and a write reports success without
+ * @skip_teardown: discard firmware API commands during the teardown + * touching the bus, so a teardown racing the flash
+ * triggered by the post-flash reprobe + * does not fail; FW_UPDATE and the flash owner's own
+ * reads still reach the bus
+ * @flash_owner: task running the post-flash readiness poll; only its
+ * own firmware reads pass block_host
+ * @skip_teardown: from the end of a flash until the reprobe, or a rebind
+ * when the reprobe could not be scheduled, a host
+ * firmware read fails with -ENODEV and a write reports
+ * success without touching the bus
+ * @shutting_down: set under the devlink instance lock once ->shutdown()
+ * or .remove() has begun, so no flash starts while the
+ * switch is going away
* @stats_work: periodic work item that polls RMON hardware counters * @stats_work: periodic work item that polls RMON hardware counters
* and accumulates them into 64-bit per-port stats * and accumulates them into 64-bit per-port stats
*/ */
@@ -329,6 +337,8 @@ struct mxl862xx_priv { @@ -329,6 +350,8 @@ struct mxl862xx_priv {
unsigned long flags; unsigned long flags;
u16 drop_meter; u16 drop_meter;
struct mxl862xx_fw_version fw_version; struct mxl862xx_fw_version fw_version;
@@ -1088,12 +1110,14 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
struct mxl862xx_pcs serdes_ports[8]; struct mxl862xx_pcs serdes_ports[8];
int serdes_refcount[2]; int serdes_refcount[2];
struct mutex serdes_lock; struct mutex serdes_lock;
@@ -337,7 +347,11 @@ struct mxl862xx_priv { @@ -337,7 +360,13 @@ struct mxl862xx_priv {
u16 evlan_ingress_size; u16 evlan_ingress_size;
u16 evlan_egress_size; u16 evlan_egress_size;
u16 vf_block_size; u16 vf_block_size;
+ struct task_struct *flash_owner;
+ bool block_host; + bool block_host;
+ bool skip_teardown; + bool skip_teardown;
+ bool shutting_down;
struct delayed_work stats_work; struct delayed_work stats_work;
}; };
@@ -1,917 +0,0 @@
From 513eb8147a2c74762bf700b2859bb39469aaa707 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Mon, 3 Aug 2026 04:52:10 +0100
Subject: [PATCH net-next v10 4/5] net: dsa: mxl862xx: recover switch stuck in
MCUboot rescue mode
A broken or interrupted firmware image, or the sticky rescue bit, keeps
the switch in its MCUboot bootloader, which exposes only the clause-22
SMDIO download interface. The clause-45 MMD API never comes up, so probe
would fail with -ETIMEDOUT and the only way back would be the switch's
UART console, or a power cycle or out-of-band reset (not currently
implemented).
Probe for the loader over SB PDI at setup, before any clause-45 access,
since the C45 API floods the log with CRC errors when no firmware
answers. A scratch write to two mailbox registers first establishes
that a switch is there at all. It reaches a running firmware as well,
but lands in registers that firmware does not read, so it is inert
there. The status register the loader publishes then tells the cases
apart without touching C45: a running firmware, which answers with its
own non-zero status word (0x0003 on the firmware tested), so probe
continues normally; a loader idle in its console loop, confirmed live
by a register-read challenge; a loader wedged mid-download, the one
case that publishes zero; the flashless download loop, which this
driver cannot drive; and a switch whose scratch write does not latch --
absent, unpowered, misdescribed in the device tree (wrong address or
bus, or a reset GPIO with inverted polarity), or with its SB PDI window
somewhere other than the OTP reset offsets assumed here. The first
three enter rescue mode or normal operation, the last two fail probe
cleanly with -EOPNOTSUPP and -ENODEV instead of a CRC-error storm.
A loader that publishes the ready magic but never services the
register-read challenge fails probe too, with -ENXIO. The challenge is
what tells the loader apart from a firmware whose status word happens
to read the same value, and offering to flash a healthy firmware would
be worse than refusing to bind, so a mailbox that does not answer is
treated as unusable rather than as a flash target. Every loader tested
services it.
In rescue mode the switch registers without user interfaces so devlink
stays available: user ports fail port_setup with -ENODEV (the DSA core
re-registers them as unused) while shared and CPU ports succeed, and the
CPU port works on its fixed link with mac_select_pcs returning no PCS.
Firmware API commands fail fast with -ENODEV and the port and STP
callbacks become no-ops.
An interrupted download can leave the loader wedged mid-payload. A
background work item off the devlink flash path drains it back to a
clean ready state by feeding the outstanding byte count one byte at a
time, which takes tens of minutes for a large image and is logged as it
progresses; until then devlink dev info reports no version and devlink
dev flash returns -EBUSY, and -EIO once a drain has failed for good.
Reaching the end of the count is all the drain does: the loader then
verifies the corrupt image and returns to its console loop on its own,
so the drain reprobes and lets the probe-time detection re-classify the
switch -- a valid image that a last-moment interruption left bootable
comes up as running firmware, with no second-guessing in the drain path.
The reprobe the drain queues owns itself and cannot be cancelled from
teardown, so, like the post-flash reprobe, it checks whether the device
is still bound before touching it: a drain finishing after the driver
is gone does nothing. Should that hand-off fail to be set up at all,
recovery stops with an error, since the loader would otherwise sit at a
clean ready state that nothing reclassifies while devlink keeps
promising that a retry will work.
The CHIP ID registers need a running firmware, so no asic.id/asic.rev is
reported in rescue mode. Once the loader is ready, devlink dev info
reports the null firmware version "0.0.0" as both running and stored:
$ devlink dev info mdio_bus/mdio-bus:10
mdio_bus/mdio-bus:10:
driver mxl862xx
versions:
running:
fw 0.0.0
stored:
fw 0.0.0
An operational switch never reports 0.0.0 (a released firmware's major
is non-zero), so version-comparing tools like fwupd offer every release
as an upgrade, recovering the switch through the regular flash flow,
matched on the driver name. The flash skips the FW_UPDATE command since
MCUboot is already waiting. A successful flash reboots the switch into
the new firmware and the reprobe then brings the driver up against it
normally; after a failed one the switch is still in MCUboot, rescue mode
is detected again, and the user can retry.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/net/dsa/mxl862xx/mxl862xx-fw.c | 463 +++++++++++++++++++-
drivers/net/dsa/mxl862xx/mxl862xx-fw.h | 3 +
drivers/net/dsa/mxl862xx/mxl862xx-host.c | 8 +
drivers/net/dsa/mxl862xx/mxl862xx-phylink.c | 2 +
drivers/net/dsa/mxl862xx/mxl862xx.c | 100 ++++-
drivers/net/dsa/mxl862xx/mxl862xx.h | 20 +
6 files changed, 566 insertions(+), 30 deletions(-)
--- a/drivers/net/dsa/mxl862xx/mxl862xx-fw.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.c
@@ -29,9 +29,11 @@
*
* STAT magics:
* READY 0xc55c loader idle in the console loop (this driver)
+ * DL_RDY 0xc33c loader idle in the flashless loop
* START 0xf48f host -> begin download session
* ACK 0xf490 loader -> START acknowledged (START + 1)
* END 0x3cc3 host -> finalise now (optional, see below)
+ * RDREG 0xe2c0 host -> register-read command (| index), see below
*
* Console flash path (STAT=0xc55c) - mxl862xx_flash_firmware():
*
@@ -71,7 +73,40 @@
* - never send a slice/chunk count larger than what is outstanding;
* - a STAT write is a command only once the loader has left the loop;
* - the loader leaves the count in STAT while it programs the chunk, so
- * a lingering count does not distinguish "busy" from "verdict".
+ * a lingering count does not distinguish "busy" from "verdict";
+ * - interrupted-download recovery feeds 1 byte at a time (see below).
+ *
+ * Interrupted-flash recovery (mxl862xx_rescue_drain):
+ * A host that dies mid-payload leaves the loader in the receive loop holding
+ * STAT=0. Feed single 1-byte chunks (one DATA word + STAT=1) until r_remain
+ * reaches 0; the loader then verifies the (now corrupt) image, publishes its
+ * verdict and comes back to READY by itself. END is never sent here: while
+ * r_remain is non-zero it would be consumed as a 15555-byte count, and a
+ * lingering STAT=1 cannot be told from a chunk still being programmed.
+ *
+ * Register-read challenge (non-destructive liveness proof):
+ * DATA := 0x7c23 (marker); STAT := 0xe2c0|idx
+ * -> loader returns a runtime word in DATA and re-arms STAT=0xc55c.
+ * The reply source is loader BSS, not a chip id; used only to prove a live
+ * mailbox in mxl862xx_rescue_mode_detect().
+ *
+ * The other STAT ready magic, 0xc33c, marks the loader's flashless
+ * chip-to-chip download mode (MxL86281S 16-port tier); this driver does not
+ * use it.
+ *
+ * Rescue lifecycle (devlink): probe runs mxl862xx_rescue_mode_detect(); a
+ * wedged loader is drained back to READY by a background self-heal
+ * (rescue_heal_work), so the long recovery never holds the devlink lock.
+ * devlink dev info exposes the fw version (the "flashable" signal) only once at
+ * READY; flash_update returns -EBUSY until then, and reprobes to WSP firmware
+ * on success.
+ *
+ * Notes:
+ * - Chip id/revision (0xc0d28884/88) are NOT reachable on this channel; they
+ * need the clause-45 MMD firmware mailbox, which is dead under MCUboot.
+ * Rescue identity is by SB PDI behaviour only (mxl862xx_rescue_mode_detect).
+ * - The SMDIO PHY address comes from the device tree; the 0xe1xx register
+ * offsets are the OTP reset defaults and the only layout supported here.
*/
#include <linux/crc32.h>
@@ -104,8 +139,15 @@
/* SB PDI handshake magic (published/consumed via STAT) */
#define MXL862XX_SB_PDI_READY 0xc55c /* loader idle, console loop */
+#define MXL862XX_SB_PDI_DL_READY 0xc33c /* loader idle, flashless loop */
#define MXL862XX_SB_PDI_START 0xf48f
#define MXL862XX_SB_PDI_END 0x3cc3
+#define MXL862XX_SB_PDI_RDREG 0xe2c0 /* register-read cmd (| index) */
+#define MXL862XX_SB_PDI_RDREG_MARK 0x7c23 /* marker placed in DATA for RDREG */
+
+/* Behavioural presence probe: two distinct 16-bit latches on ADDR/DATA. */
+#define MXL862XX_SB_PDI_PROBE_A 0x5a5a
+#define MXL862XX_SB_PDI_PROBE_D 0xa5a5
/* Image verification verdict published in STAT once the receive loop ends */
#define MXL862XX_SB_PDI_VERIFY_OK 0
@@ -124,6 +166,10 @@
#define MXL862XX_FW_WRITE_TIMEOUT_MS 60000
#define MXL862XX_FW_REBOOT_DELAY_MS 5000
#define MXL862XX_FW_REPROBE_DELAY_MS 500
+/* One loader mailbox step: program a 1-byte chunk or service a command */
+#define MXL862XX_SB_PDI_STEP_MS 2000
+/* Covers the loader's END wait, verification and the reset into READY */
+#define MXL862XX_SB_PDI_VERIFY_MS 15000
static int mxl862xx_sb_pdi_reset(struct mxl862xx_priv *priv)
{
@@ -193,7 +239,8 @@ static int mxl862xx_sb_pdi_flush_last(st
ret = read_poll_timeout(mxl862xx_smdio_read, val,
val < 0 || (u16)val != (u16)data_written,
- 10000, MXL862XX_FW_WRITE_TIMEOUT_MS * 1000,
+ 10000, (MXL862XX_FW_WRITE_TIMEOUT_MS +
+ MXL862XX_SB_PDI_VERIFY_MS) * 1000,
false, priv, MXL862XX_SB_PDI_STAT);
if (val < 0)
return val;
@@ -278,6 +325,357 @@ static struct mxl862xx_reprobe *mxl862xx
return rp;
}
+/* Byte-count of each chunk fed to the loader during drain. It MUST be 1: the
+ * loader only lets us observe "counter == 0", never "counter < step", so any
+ * step > 1 can subtract past zero, underflow the 32-bit counter and wedge the
+ * loader for ~2^32 more bytes (a state only a power cycle clears). Stepping by
+ * 1 walks the counter through every value and is guaranteed to land on zero
+ * whatever its (possibly odd) start. A 1-byte chunk is a path the loader
+ * already handles: the normal transfer ends with a single trailing byte for
+ * odd-sized images (see Step 6).
+ */
+#define MXL862XX_DRAIN_CHUNK_BYTES 1
+
+/* Log the drain's progress every so many bytes; it can run for a long time */
+#define MXL862XX_DRAIN_LOG_BYTES (128 * 1024)
+
+/* Wait for the loader to ask for the next chunk (STAT 0) or to come back to its
+ * command loop (STAT READY), and return the STAT value either way. On timeout
+ * that is whatever STAT still holds, which carries no further information: the
+ * loader keeps the count we wrote visible while it programs the chunk, and that
+ * is the same value it publishes as the "image rejected" verdict once the
+ * counter reaches zero.
+ *
+ * STAT 0 is unambiguous here even though it is also the "image verified"
+ * verdict: by the r_remain == 0 rule the loader leaves the receive loop the
+ * moment the counter reaches zero, so it is never both inside the loop asking
+ * for a chunk and publishing a verdict. Once it has left, the next STAT write
+ * is a command rather than a count, so feeding one more chunk after a verdict
+ * cannot underflow anything either.
+ */
+static int mxl862xx_sb_pdi_poll_drain(struct mxl862xx_priv *priv,
+ unsigned long timeout_ms)
+{
+ int val;
+
+ read_poll_timeout(mxl862xx_smdio_read, val,
+ val < 0 || (u16)val == MXL862XX_SB_PDI_READY ||
+ (u16)val == 0,
+ 50, timeout_ms * 1000, false,
+ priv, MXL862XX_SB_PDI_STAT);
+ if (val < 0)
+ return val;
+ return (u16)val;
+}
+
+/* The loader is not asking for a chunk: it may still be programming the last
+ * one, or the counter has reached zero and it is verifying the image and
+ * resetting into READY. Wait that out -- STAT cannot tell the two apart, and
+ * guessing would mean writing END into a live receive loop.
+ *
+ * Return: 0 once the loader has left the loop, -EAGAIN if it asks for another
+ * chunk after all, -EIO for a loader still holding the count when the verify
+ * window expires, or an SMDIO bus error.
+ */
+static int mxl862xx_rescue_drain_finish(struct mxl862xx_priv *priv, u32 chunk)
+{
+ struct device *dev = &priv->mdiodev->dev;
+ int stat;
+
+ stat = mxl862xx_sb_pdi_poll_drain(priv, MXL862XX_SB_PDI_VERIFY_MS);
+ if (stat < 0)
+ return stat;
+ if (stat == MXL862XX_SB_PDI_READY)
+ return 0;
+ if (stat == MXL862XX_SB_PDI_VERIFY_BAD) {
+ dev_err(dev,
+ "flash: loader stuck after %u chunks, power cycle it\n",
+ chunk);
+ return -EIO;
+ }
+ if (stat) {
+ /* A firmware is answering, not the loader: an image survived
+ * in flash and booted.
+ */
+ dev_info(dev, "flash: firmware booted while draining\n");
+ return 0;
+ }
+
+ return -EAGAIN;
+}
+
+/* Recover a switch whose SB PDI download was interrupted mid-transfer - the
+ * host died after MCUboot began erasing flash, whether it aborted mid erase or
+ * mid image-write, both end up in the same place: the payload receive loop.
+ * There the loader publishes STAT=0, waits for the host to write a byte-count
+ * to STAT, DMAs that many bytes and subtracts the count from a remaining-bytes
+ * counter, leaving the loop only when the counter reaches exactly zero. The
+ * image size died with the host, so we feed single-byte chunks (see
+ * MXL862XX_DRAIN_CHUNK_BYTES) to walk the counter to zero without underflow.
+ * The loader then verifies the (now corrupt) image and returns to READY by
+ * itself, or boots a valid image that happened to survive in flash; either way
+ * the caller's reprobe classifies the result. Every byte costs about a dozen
+ * MDIO frames, so a multi-MiB outstanding count takes tens of minutes.
+ * Returns 0 once the loader has left the receive loop, <0 on error. Does NOT
+ * recover a counter already underflowed by an earlier oversized-chunk attempt
+ * - that needs a power cycle.
+ */
+static int mxl862xx_rescue_drain(struct mxl862xx_priv *priv)
+{
+ struct device *dev = &priv->mdiodev->dev;
+ /* Bound: twice the loader's 16 MiB image cap, one byte per chunk. */
+ u32 max_chunks = 2u * (16u << 20) / MXL862XX_DRAIN_CHUNK_BYTES;
+ u32 chunk = 0;
+ int ret, stat;
+
+ while (chunk < max_chunks) {
+ /* Teardown can interrupt this long drain. */
+ if (test_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags))
+ return -ECANCELED;
+
+ stat = mxl862xx_sb_pdi_poll_drain(priv, MXL862XX_SB_PDI_STEP_MS);
+ if (stat < 0)
+ return stat;
+ if (stat == MXL862XX_SB_PDI_READY)
+ return 0;
+
+ if (stat) {
+ ret = mxl862xx_rescue_drain_finish(priv, chunk);
+ if (ret != -EAGAIN)
+ return ret;
+ }
+
+ /* Feed one zero byte; reset cleared the write latch. */
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL,
+ MXL862XX_SB_PDI_CTRL_WR);
+ if (ret < 0)
+ return ret;
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, 0x0000);
+ if (ret < 0)
+ return ret;
+ ret = mxl862xx_sb_pdi_reset(priv);
+ if (ret < 0)
+ return ret;
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT,
+ MXL862XX_DRAIN_CHUNK_BYTES);
+ if (ret < 0)
+ return ret;
+ chunk++;
+ if (!(chunk % MXL862XX_DRAIN_LOG_BYTES))
+ dev_info(dev, "flash: drained %u KiB so far\n",
+ chunk / 1024);
+ cond_resched();
+ }
+
+ dev_err(dev,
+ "flash: interrupted download did not drain after %u chunks\n",
+ chunk);
+
+ return -ETIMEDOUT;
+}
+
+/* Background self-heal: drain a wedged download off the devlink flash path, so
+ * the long recovery never holds the devlink lock. Scheduled from probe;
+ * reprobes on success so the probe-time detection re-classifies the switch.
+ */
+void mxl862xx_rescue_heal_work_fn(struct work_struct *work)
+{
+ struct mxl862xx_priv *priv =
+ container_of(work, struct mxl862xx_priv, rescue_heal_work);
+ struct device *dev = &priv->mdiodev->dev;
+ struct mxl862xx_reprobe *ko;
+ int ret;
+
+ ret = mxl862xx_rescue_drain(priv);
+ if (ret == -ECANCELED)
+ return;
+ if (ret) {
+ /* Nothing retries this, so say so: rescue_ready stays clear
+ * and devlink dev flash reports why it refuses.
+ */
+ dev_err(dev, "flash: download recovery failed: %pe\n",
+ ERR_PTR(ret));
+ WRITE_ONCE(priv->rescue_failed, true);
+ return;
+ }
+
+ /* The interrupted transfer is finalised; reprobe so the probe-time
+ * detection brings the driver up -- flashable in rescue mode if the
+ * loader is at READY, or normally if a valid image booted. The refs
+ * are released by the reprobe once it completes, which also decides
+ * whether it may still run: teardown cannot cancel a work item queued
+ * here, so the reprobe checks for itself that the device is still
+ * bound. The flag test below only avoids queueing work that would
+ * certainly be skipped.
+ */
+ if (test_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags))
+ return;
+
+ if (!try_module_get(THIS_MODULE))
+ return;
+
+ get_device(dev);
+ ko = mxl862xx_reprobe_alloc(dev);
+ if (!ko) {
+ put_device(dev);
+ module_put(THIS_MODULE);
+ /* The loader is at READY and would take an image, but nothing
+ * will reclassify the switch, so refuse flashing with a real
+ * error instead of the "retry shortly" that never comes true.
+ */
+ dev_err(dev, "flash: cannot reinitialise after recovery, unbind and rebind to flash\n");
+ WRITE_ONCE(priv->rescue_failed, true);
+ return;
+ }
+
+ queue_delayed_work(system_long_wq, &ko->work,
+ msecs_to_jiffies(MXL862XX_FW_REPROBE_DELAY_MS));
+}
+
+/* Detect MCUboot rescue mode over clause-22 SMDIO alone, so the caller can rule
+ * the loader out before any C45 API request (which spews CRC errors when no WSP
+ * firmware answers). A scratch write to ADDR/DATA must latch or the chip is
+ * absent (-ENODEV); the mailbox is reset first, or a transfer interrupted with
+ * CTRL=WR would take that write as a payload word instead of latching it. STAT
+ * then classifies the state, poked destructively only when 0, the one value a
+ * running firmware never holds:
+ *
+ * - 0xc33c: flashless loop; recognised but not supported here.
+ * - 0xc55c: console loop, if the register-read challenge is serviced.
+ * - other non-zero: running firmware, left unpoked.
+ * - 0: wedged receive loop; the 1-byte slice-advance then says whether it
+ * still needs draining or has just finished.
+ *
+ * The scratch write reaches a running firmware too, but lands in mailbox
+ * registers it does not read, so it is inert there.
+ *
+ * Return: MXL862XX_IN_RESCUE, MXL862XX_NOT_RESCUE, -ENODEV when the scratch
+ * write does not latch, which is a switch that does not answer at all or one
+ * whose SB PDI window is not at the offsets above, -EOPNOTSUPP for the
+ * flashless loop, -ENXIO for a READY loader whose mailbox fails the challenge,
+ * or an SMDIO bus error.
+ */
+int mxl862xx_rescue_mode_detect(struct mxl862xx_priv *priv)
+{
+ int stat, dat, ret, rb, a, d;
+
+ /* rescue_ready gates flashing; a wedged loader needs the drain first. */
+ WRITE_ONCE(priv->rescue_ready, false);
+
+ ret = mxl862xx_sb_pdi_reset(priv);
+ if (ret < 0)
+ return ret;
+
+ /* Presence: a live chip latches the scratch write, an absent one floats. */
+ a = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_ADDR,
+ MXL862XX_SB_PDI_PROBE_A);
+ if (a < 0)
+ return a;
+ d = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA,
+ MXL862XX_SB_PDI_PROBE_D);
+ if (d < 0)
+ return d;
+ a = mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_ADDR);
+ if (a < 0)
+ return a;
+ d = mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_DATA);
+ if (d < 0)
+ return d;
+ if ((u16)a != MXL862XX_SB_PDI_PROBE_A ||
+ (u16)d != MXL862XX_SB_PDI_PROBE_D)
+ return -ENODEV;
+
+ ret = mxl862xx_sb_pdi_reset(priv);
+ if (ret < 0)
+ return ret;
+
+ stat = mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_STAT);
+ if (stat < 0)
+ return stat;
+
+ /* Flashless-download loop (MxL86281S tier): this driver does not
+ * support it -- the console flash path expects READY. Treat it as an
+ * unusable configuration, like any other unsupported state.
+ */
+ if ((u16)stat == MXL862XX_SB_PDI_DL_READY)
+ return -EOPNOTSUPP;
+
+ /* Console loop at READY: confirm the live mailbox with the register-read
+ * challenge (consumes the marker from DATA and re-arms READY).
+ */
+ if ((u16)stat == MXL862XX_SB_PDI_READY) {
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA,
+ MXL862XX_SB_PDI_RDREG_MARK);
+ if (ret < 0)
+ return ret;
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT,
+ MXL862XX_SB_PDI_RDREG);
+ if (ret < 0)
+ return ret;
+ rb = mxl862xx_sb_pdi_poll_stat(priv, MXL862XX_SB_PDI_READY,
+ MXL862XX_SB_PDI_STEP_MS);
+ dat = mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_DATA);
+ ret = mxl862xx_sb_pdi_reset(priv);
+ /* Never re-arming READY fails the challenge like any other
+ * unserviced command; report it as such rather than as a bus
+ * timeout the bus never saw.
+ */
+ if (rb == -ETIMEDOUT)
+ rb = -ENXIO;
+ if (rb < 0)
+ return rb;
+ if (dat < 0)
+ return dat;
+ if (ret < 0)
+ return ret;
+ if ((u16)dat != MXL862XX_SB_PDI_RDREG_MARK) {
+ WRITE_ONCE(priv->rescue_ready, true);
+ return MXL862XX_IN_RESCUE;
+ }
+ /* READY but the marker is untouched, so nothing is servicing the
+ * mailbox. A firmware publishing 0xc55c as its status word looks
+ * exactly like this, and flashing one would be far worse than
+ * refusing to bind, so treat it as unusable.
+ */
+ return -ENXIO;
+ }
+
+ /* Any other non-zero value is a running firmware, not a loader. */
+ if (stat)
+ return MXL862XX_NOT_RESCUE;
+
+ /* STAT == 0: a wedged receive loop takes a 1-byte slice-advance (feed
+ * one DATA word first, like a drain chunk) and asks for the next chunk
+ * by publishing 0 again. Had that byte been the last one outstanding,
+ * the loader leaves the loop instead and returns to READY, having
+ * consumed the advance -- proof enough of a live mailbox to skip the
+ * challenge. Anything else means it is still working on it. All three
+ * are rescue, so this never fails probe; only the drain does.
+ */
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL,
+ MXL862XX_SB_PDI_CTRL_WR);
+ if (ret < 0)
+ return ret;
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, 0x0000);
+ if (ret < 0)
+ return ret;
+ ret = mxl862xx_sb_pdi_reset(priv);
+ if (ret < 0)
+ return ret;
+ ret = mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT,
+ MXL862XX_DRAIN_CHUNK_BYTES);
+ if (ret < 0)
+ return ret;
+
+ rb = mxl862xx_sb_pdi_poll_drain(priv, MXL862XX_SB_PDI_STEP_MS);
+ if (rb < 0)
+ return rb;
+ if (rb == MXL862XX_SB_PDI_READY)
+ WRITE_ONCE(priv->rescue_ready, true);
+
+ return MXL862XX_IN_RESCUE;
+}
+
/* MCUboot firmware image header */
struct mxl862xx_fw_hdr {
__le32 image_type;
@@ -353,13 +751,15 @@ static int mxl862xx_flash_firmware(struc
int ret, i;
/* Step 1: reboot the firmware into MCUboot rescue mode */
- ret = mxl862xx_api_wrap(priv, SYS_MISC_FW_UPDATE, NULL, 0,
- false, false);
- if (ret) {
- dev_err(&priv->mdiodev->dev,
- "flash: FW_UPDATE command failed: %pe\n",
- ERR_PTR(ret));
- return ret;
+ if (!priv->rescue_mode) {
+ ret = mxl862xx_api_wrap(priv, SYS_MISC_FW_UPDATE, NULL, 0,
+ false, false);
+ if (ret) {
+ dev_err(&priv->mdiodev->dev,
+ "flash: FW_UPDATE command failed: %pe\n",
+ ERR_PTR(ret));
+ return ret;
+ }
}
/* Step 2: wait for bootloader ready */
@@ -541,6 +941,25 @@ int mxl862xx_devlink_info_get(struct dsa
char buf[16];
int ret;
+ /* No chip-id/revision in MCUboot (needs the firmware MMD mailbox). The
+ * fw version doubles as the "ready to flash" signal: report it only
+ * once the loader is at a clean READY, nothing while still draining.
+ */
+ if (priv->rescue_mode) {
+ if (!READ_ONCE(priv->rescue_ready))
+ return 0;
+
+ snprintf(buf, sizeof(buf), "%u.%u.%u",
+ priv->fw_version.major, priv->fw_version.minor,
+ priv->fw_version.revision);
+ ret = devlink_info_version_running_put(req,
+ DEVLINK_INFO_VERSION_GENERIC_FW, buf);
+ if (ret)
+ return ret;
+ return devlink_info_version_stored_put(req,
+ DEVLINK_INFO_VERSION_GENERIC_FW, buf);
+ }
+
/* A 0 part number means the CHIP ID read failed or the part is
* unfused; omit it rather than publish a bogus "0000" that fwupd
* would match firmware against -- it then falls back to the driver
@@ -614,6 +1033,21 @@ int mxl862xx_devlink_flash_update(struct
return ret;
}
+ /* Refuse to flash while the background self-heal is still draining, and
+ * for good once it has given up on the loader.
+ */
+ if (READ_ONCE(priv->rescue_failed)) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "download recovery failed, power cycle the switch");
+ return -EIO;
+ }
+
+ if (priv->rescue_mode && !READ_ONCE(priv->rescue_ready)) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "switch is recovering an interrupted download, retry shortly");
+ return -EBUSY;
+ }
+
/* The references the reprobe work needs to restore normal operation
* must be held before the switch is disturbed; the work itself is
* scheduled only once the flash is done (see below).
@@ -633,9 +1067,13 @@ int mxl862xx_devlink_flash_update(struct
return -ENOMEM;
}
- dev_info(ds->dev, "flash: running firmware %u.%u.%u\n",
- priv->fw_version.major, priv->fw_version.minor,
- priv->fw_version.revision);
+ if (priv->rescue_mode)
+ dev_info(ds->dev,
+ "flash: flashing switch via MCUboot rescue mode\n");
+ else
+ dev_info(ds->dev, "flash: running firmware %u.%u.%u\n",
+ priv->fw_version.major, priv->fw_version.minor,
+ priv->fw_version.revision);
/* Close ports while the firmware is still alive so the DSA core's
* MDB/FDB tracking is drained, and detach user ports so userspace
@@ -679,6 +1117,7 @@ int mxl862xx_devlink_flash_update(struct
mutex_lock_nested(&priv->mdiodev->bus->mdio_lock,
MDIO_MUTEX_NESTED);
priv->block_host = false;
+ priv->rescue_mode = false;
mutex_unlock(&priv->mdiodev->bus->mdio_lock);
/* Refresh the cached versions so the flash update only
--- a/drivers/net/dsa/mxl862xx/mxl862xx-fw.h
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.h
@@ -6,7 +6,10 @@
#include <net/dsa.h>
struct mxl862xx_priv;
+struct work_struct;
+int mxl862xx_rescue_mode_detect(struct mxl862xx_priv *priv);
+void mxl862xx_rescue_heal_work_fn(struct work_struct *work);
int mxl862xx_devlink_info_get(struct dsa_switch *ds,
struct devlink_info_req *req,
struct netlink_ext_ack *extack);
--- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c
@@ -16,6 +16,7 @@
#include <net/dsa.h>
#include "mxl862xx.h"
#include "mxl862xx-cmd.h"
+#include "mxl862xx-fw.h"
#include "mxl862xx-host.h"
#define CTRL_BUSY_MASK BIT(15)
@@ -346,6 +347,11 @@ int mxl862xx_api_wrap(struct mxl862xx_pr
goto out;
}
+ if (priv->rescue_mode) {
+ ret = -ENODEV;
+ goto out;
+ }
+
if (priv->block_host && cmd != SYS_MISC_FW_UPDATE) {
ret = -EBUSY;
goto out;
@@ -549,9 +555,11 @@ int mxl862xx_smdio_write(struct mxl862xx
void mxl862xx_host_init(struct mxl862xx_priv *priv)
{
INIT_WORK(&priv->crc_err_work, mxl862xx_crc_err_work_fn);
+ INIT_WORK(&priv->rescue_heal_work, mxl862xx_rescue_heal_work_fn);
}
void mxl862xx_host_shutdown(struct mxl862xx_priv *priv)
{
cancel_work_sync(&priv->crc_err_work);
+ cancel_work_sync(&priv->rescue_heal_work);
}
--- a/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c
@@ -406,6 +406,8 @@ mxl862xx_phylink_mac_select_pcs(struct p
switch (port) {
case 9 ... 16:
+ if (priv->rescue_mode)
+ return NULL;
if (!MXL862XX_FW_VER_MIN(priv, 1, 0, 84)) {
dev_warn_once(dp->ds->dev,
"SerDes PCS unsupported on old firmware.\n");
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -692,21 +692,66 @@ static int mxl862xx_setup(struct dsa_swi
int n_user_ports = 0, max_vlans;
int ingress_finals, vid_rules;
struct dsa_port *dp;
- int ret, i;
-
- ret = mxl862xx_reset(priv);
- if (ret)
- return ret;
-
- ret = mxl862xx_wait_ready(ds);
- if (ret)
- return ret;
+ int ret, i, rescue;
+ /* The SerDes state is software-only and must exist before anything can
+ * reach phylink, including a rescue-mode flash clearing rescue_mode
+ * ahead of the reprobe.
+ */
mutex_init(&priv->serdes_lock);
for (i = 0; i < ARRAY_SIZE(priv->serdes_ports); i++)
mxl862xx_setup_pcs(priv, &priv->serdes_ports[i],
i + MXL862XX_FIRST_SERDES_PORT);
+ /* Detect the loader over SB PDI first: it needs no firmware, unlike the
+ * C45 API (mxl862xx_reset/wait_ready) which spews CRC errors when none
+ * answers. Touch C45 only once rescue is ruled out.
+ */
+ rescue = mxl862xx_rescue_mode_detect(priv);
+ if (rescue < 0) {
+ dev_err(ds->dev, "switch state detection failed: %pe\n",
+ ERR_PTR(rescue));
+ return rescue;
+ }
+
+ if (rescue == MXL862XX_NOT_RESCUE) {
+ ret = mxl862xx_reset(priv);
+ if (ret)
+ return ret;
+
+ ret = mxl862xx_wait_ready(ds);
+ if (ret) {
+ /* the reset may only now have triggered rescue mode */
+ rescue = mxl862xx_rescue_mode_detect(priv);
+ if (rescue < 0) {
+ dev_err(ds->dev,
+ "switch not responding after reset: %pe\n",
+ ERR_PTR(rescue));
+ return rescue;
+ }
+ if (rescue == MXL862XX_NOT_RESCUE)
+ return ret;
+ }
+ }
+
+ priv->rescue_mode = rescue;
+
+ if (priv->rescue_mode) {
+ if (priv->rescue_ready) {
+ dev_warn(ds->dev,
+ "switch in MCUboot rescue mode, use devlink to flash new firmware\n");
+ } else {
+ /* Drain the wedged download in the background so it
+ * never holds the devlink lock; info and flash become
+ * available once ready.
+ */
+ dev_warn(ds->dev,
+ "switch in MCUboot with an interrupted download, recovering in background\n");
+ queue_work(system_long_wq, &priv->rescue_heal_work);
+ }
+ return 0;
+ }
+
/* Calculate Extended VLAN block sizes.
* With VLAN Filter handling VID membership checks:
* Ingress: only final catchall rules (PVID insertion, 802.1Q
@@ -785,11 +830,21 @@ static int mxl862xx_port_state(struct ds
static int mxl862xx_port_enable(struct dsa_switch *ds, int port,
struct phy_device *phydev)
{
+ struct mxl862xx_priv *priv = ds->priv;
+
+ if (priv->rescue_mode)
+ return 0;
+
return mxl862xx_port_state(ds, port, true);
}
static void mxl862xx_port_disable(struct dsa_switch *ds, int port)
{
+ struct mxl862xx_priv *priv = ds->priv;
+
+ if (priv->rescue_mode)
+ return;
+
if (mxl862xx_port_state(ds, port, false))
dev_err(ds->dev, "failed to disable port %d\n", port);
}
@@ -1407,6 +1462,17 @@ static int mxl862xx_port_setup(struct ds
bool is_cpu_port = dsa_port_is_cpu(dp);
int ret;
+ if (dsa_port_is_dsa(dp)) {
+ dev_err(ds->dev, "port %d: DSA links not supported\n", port);
+ return -EOPNOTSUPP;
+ }
+
+ /* DSA reinits failed user ports as unused; shared ports must
+ * succeed for the tree to register.
+ */
+ if (priv->rescue_mode)
+ return dsa_port_is_user(dp) ? -ENODEV : 0;
+
ret = mxl862xx_port_state(ds, port, false);
if (ret)
return ret;
@@ -1416,11 +1482,6 @@ static int mxl862xx_port_setup(struct ds
if (dsa_port_is_unused(dp))
return 0;
- if (dsa_port_is_dsa(dp)) {
- dev_err(ds->dev, "port %d: DSA links not supported\n", port);
- return -EOPNOTSUPP;
- }
-
ret = mxl862xx_configure_sp_tag_proto(ds, port, is_cpu_port);
if (ret)
return ret;
@@ -1642,11 +1703,11 @@ static int mxl862xx_port_mdb_del(struct
ether_addr_copy(qparam.mac, mdb->addr);
ret = MXL862XX_API_READ(priv, MXL862XX_MAC_TABLEENTRYQUERY, qparam);
- /* Post-flash teardown: the firmware and its MAC table are gone, so
- * there is nothing left to delete. Outside it, -ENODEV is a bus error
- * and must be reported.
+ /* Post-flash teardown or MCUboot: the firmware and its MAC table are
+ * gone, so there is nothing left to delete. Outside those, -ENODEV is a
+ * bus error and must be reported.
*/
- if (ret == -ENODEV && priv->skip_teardown)
+ if (ret == -ENODEV && (priv->skip_teardown || priv->rescue_mode))
return 0;
if (ret)
return ret;
@@ -1704,6 +1765,9 @@ static void mxl862xx_port_stp_state_set(
struct mxl862xx_priv *priv = ds->priv;
int ret;
+ if (priv->rescue_mode)
+ return;
+
switch (state) {
case BR_STATE_DISABLED:
param.port_state = cpu_to_le32(MXL862XX_STP_PORT_STATE_DISABLE);
--- a/drivers/net/dsa/mxl862xx/mxl862xx.h
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.h
@@ -4,7 +4,9 @@
#define __MXL862XX_H
#include <asm/byteorder.h>
+#include <linux/bitops.h>
#include <linux/mdio.h>
+#include <linux/mutex.h>
#include <linux/workqueue.h>
#include <net/dsa.h>
@@ -14,6 +16,10 @@ struct mxl862xx_priv;
#define MXL862XX_FIRST_SERDES_PORT 9
#define MXL862XX_SERDES_SLOTS 4
+/* mxl862xx_rescue_mode_detect() return codes (negative values are errors) */
+#define MXL862XX_NOT_RESCUE 0
+#define MXL862XX_IN_RESCUE 1
+
#define MXL862XX_DEFAULT_BRIDGE 0
#define MXL862XX_MAX_BRIDGES 48
#define MXL862XX_MAX_BRIDGE_PORTS 128
@@ -327,6 +333,16 @@ struct mxl862xx_fw_version {
* during a firmware flash
* @skip_teardown: discard firmware API commands during the teardown
* triggered by the post-flash reprobe
+ * @rescue_mode: switch is in MCUboot; firmware API commands fail fast,
+ * only clause-22 SMDIO works. Set from setup() before the
+ * switch is registered and cleared under the MDIO bus lock
+ * for the benefit of mxl862xx_api_wrap(); other readers
+ * only need it to be a stable single flag.
+ * @rescue_ready: (rescue_mode) loader is at a clean READY and will accept
+ * a flash; false while rescue_heal_work is draining
+ * @rescue_failed: (rescue_mode) the self-heal gave up; the loader needs a
+ * power cycle and no flash can be accepted
+ * @rescue_heal_work: background self-heal draining a wedged download to READY
* @stats_work: periodic work item that polls RMON hardware counters
* and accumulates them into 64-bit per-port stats
*/
@@ -334,6 +350,7 @@ struct mxl862xx_priv {
struct dsa_switch *ds;
struct mdio_device *mdiodev;
struct work_struct crc_err_work;
+ struct work_struct rescue_heal_work;
unsigned long flags;
u16 drop_meter;
struct mxl862xx_fw_version fw_version;
@@ -349,6 +366,9 @@ struct mxl862xx_priv {
u16 vf_block_size;
bool block_host;
bool skip_teardown;
+ bool rescue_mode;
+ bool rescue_ready;
+ bool rescue_failed;
struct delayed_work stats_work;
};
@@ -1,4 +1,4 @@
From 37e3010db4b84caa239d97cb0f334542e7a7a1bb Mon Sep 17 00:00:00 2001 From d8575735a82d3c3a08120d60a2162fdf4a036eda Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org> From: Daniel Golle <daniel@makrotopia.org>
Date: Tue, 24 Mar 2026 18:51:13 +0000 Date: Tue, 24 Mar 2026 18:51:13 +0000
Subject: [PATCH 02/12] net: dsa: mxl862xx: trap link-local and multicast Subject: [PATCH 02/12] net: dsa: mxl862xx: trap link-local and multicast
@@ -55,9 +55,9 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- ---
drivers/net/dsa/mxl862xx/mxl862xx-api.h | 709 ++++++++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-api.h | 709 ++++++++++++++++++++++++
drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 6 + drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 6 +
drivers/net/dsa/mxl862xx/mxl862xx.c | 225 +++++++- drivers/net/dsa/mxl862xx/mxl862xx.c | 221 +++++++-
drivers/net/dsa/mxl862xx/mxl862xx.h | 8 + drivers/net/dsa/mxl862xx/mxl862xx.h | 8 +
4 files changed, 943 insertions(+), 5 deletions(-) 4 files changed, 939 insertions(+), 5 deletions(-)
--- a/drivers/net/dsa/mxl862xx/mxl862xx-api.h --- a/drivers/net/dsa/mxl862xx/mxl862xx-api.h
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-api.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx-api.h
@@ -809,7 +809,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#include <linux/if_bridge.h> #include <linux/if_bridge.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h> #include <linux/of_device.h>
@@ -451,6 +452,173 @@ static int mxl862xx_setup_drop_meter(str @@ -453,6 +454,173 @@ static int mxl862xx_setup_drop_meter(str
return MXL862XX_API_WRITE(priv, MXL862XX_COMMON_REGISTERMOD, reg); return MXL862XX_API_WRITE(priv, MXL862XX_COMMON_REGISTERMOD, reg);
} }
@@ -983,7 +983,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static int mxl862xx_set_bridge_port(struct dsa_switch *ds, int port) static int mxl862xx_set_bridge_port(struct dsa_switch *ds, int port)
{ {
struct mxl862xx_bridge_port_config br_port_cfg = {}; struct mxl862xx_bridge_port_config br_port_cfg = {};
@@ -666,17 +834,23 @@ static int mxl862xx_allocate_bridge(stru @@ -668,17 +836,23 @@ static int mxl862xx_allocate_bridge(stru
return le16_to_cpu(br_alloc.bridge_id); return le16_to_cpu(br_alloc.bridge_id);
} }
@@ -1011,7 +1011,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) { if (ret) {
dev_err(ds->dev, "failed to free fw bridge %u: %pe\n", dev_err(ds->dev, "failed to free fw bridge %u: %pe\n",
fw_id, ERR_PTR(ret)); fw_id, ERR_PTR(ret));
@@ -800,10 +974,42 @@ static int mxl862xx_setup(struct dsa_swi @@ -815,14 +989,42 @@ static int mxl862xx_setup(struct dsa_swi
if (ret) if (ret)
return ret; return ret;
@@ -1039,23 +1039,23 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ if (ret) + if (ret)
+ goto free_trap_fid; + goto free_trap_fid;
+ +
+ ret = mxl862xx_setup_mdio(ds); ret = mxl862xx_setup_mdio(ds);
+ if (ret) if (ret)
- return ret;
+ goto free_trap_fid; + goto free_trap_fid;
+
schedule_delayed_work(&priv->stats_work, schedule_delayed_work(&priv->stats_work,
MXL862XX_STATS_POLL_INTERVAL); MXL862XX_STATS_POLL_INTERVAL);
- return mxl862xx_setup_mdio(ds); return 0;
+ return 0;
+ +
+free_trap_fid: +free_trap_fid:
+ mxl862xx_free_fw_bridge(priv, priv->cpu_trap_fid); + mxl862xx_free_fw_bridge(priv, priv->cpu_trap_fid);
+ return ret; + return ret;
} }
static int mxl862xx_port_state(struct dsa_switch *ds, int port, bool enable) static void mxl862xx_teardown(struct dsa_switch *ds)
@@ -1515,6 +1721,15 @@ static int mxl862xx_port_setup(struct ds @@ -1542,6 +1744,15 @@ static int mxl862xx_port_setup(struct ds
if (ret) if (ret)
return ret; return ret;
@@ -1073,9 +1073,9 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) if (ret)
--- a/drivers/net/dsa/mxl862xx/mxl862xx.h --- a/drivers/net/dsa/mxl862xx/mxl862xx.h
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx.h
@@ -343,6 +343,13 @@ struct mxl862xx_fw_version { @@ -359,6 +359,13 @@ struct mxl862xx_fw_version {
* @rescue_failed: (rescue_mode) the self-heal gave up; the loader needs a * re-probe that could not be scheduled; the log names
* power cycle and no flash can be accepted * the cause, the devlink documentation the remedy
* @rescue_heal_work: background self-heal draining a wedged download to READY * @rescue_heal_work: background self-heal draining a wedged download to READY
+ * @cpu_trap_fid: firmware bridge FID allocated for PCE-trapped frames; + * @cpu_trap_fid: firmware bridge FID allocated for PCE-trapped frames;
+ * configured with uc/mc/bc flood all enabled so that + * configured with uc/mc/bc flood all enabled so that
@@ -1087,7 +1087,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* @stats_work: periodic work item that polls RMON hardware counters * @stats_work: periodic work item that polls RMON hardware counters
* and accumulates them into 64-bit per-port stats * and accumulates them into 64-bit per-port stats
*/ */
@@ -369,6 +376,7 @@ struct mxl862xx_priv { @@ -387,6 +394,7 @@ struct mxl862xx_priv {
bool rescue_mode; bool rescue_mode;
bool rescue_ready; bool rescue_ready;
bool rescue_failed; bool rescue_failed;
@@ -19,7 +19,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c --- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -998,6 +998,10 @@ static int mxl862xx_setup(struct dsa_swi @@ -1013,6 +1013,10 @@ static int mxl862xx_setup(struct dsa_swi
if (ret) if (ret)
goto free_trap_fid; goto free_trap_fid;
@@ -1,4 +1,4 @@
From a09bb7727358764e8bac42d3b15f6c997a9cef89 Mon Sep 17 00:00:00 2001 From 258b0ee5f745a8bd0316100feeb9d381e4b4aca3 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org> From: Daniel Golle <daniel@makrotopia.org>
Date: Sun, 22 Mar 2026 00:58:04 +0000 Date: Sun, 22 Mar 2026 00:58:04 +0000
Subject: [PATCH 04/12] net: dsa: add 802.1Q VLAN-based tag driver for MxL862xx Subject: [PATCH 04/12] net: dsa: add 802.1Q VLAN-based tag driver for MxL862xx
@@ -36,7 +36,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
drivers/net/dsa/mxl862xx/Kconfig | 1 + drivers/net/dsa/mxl862xx/Kconfig | 1 +
drivers/net/dsa/mxl862xx/mxl862xx-api.h | 221 +++ drivers/net/dsa/mxl862xx/mxl862xx-api.h | 221 +++
drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 2 + drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 2 +
drivers/net/dsa/mxl862xx/mxl862xx.c | 1697 ++++++++++++++++++++--- drivers/net/dsa/mxl862xx/mxl862xx.c | 1686 ++++++++++++++++++++---
drivers/net/dsa/mxl862xx/mxl862xx.h | 12 + drivers/net/dsa/mxl862xx/mxl862xx.h | 12 +
include/net/dsa.h | 2 + include/net/dsa.h | 2 +
net/dsa/Kconfig | 7 + net/dsa/Kconfig | 7 +
@@ -44,15 +44,15 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
net/dsa/tag_mxl862xx.c | 89 +- net/dsa/tag_mxl862xx.c | 89 +-
net/dsa/tag_mxl862xx.h | 92 ++ net/dsa/tag_mxl862xx.h | 92 ++
net/dsa/tag_mxl862xx_8021q.c | 70 + net/dsa/tag_mxl862xx_8021q.c | 70 +
11 files changed, 1917 insertions(+), 277 deletions(-) 11 files changed, 1913 insertions(+), 270 deletions(-)
create mode 100644 net/dsa/tag_mxl862xx.h create mode 100644 net/dsa/tag_mxl862xx.h
create mode 100644 net/dsa/tag_mxl862xx_8021q.c create mode 100644 net/dsa/tag_mxl862xx_8021q.c
--- a/drivers/net/dsa/mxl862xx/Kconfig --- a/drivers/net/dsa/mxl862xx/Kconfig
+++ b/drivers/net/dsa/mxl862xx/Kconfig +++ b/drivers/net/dsa/mxl862xx/Kconfig
@@ -4,6 +4,7 @@ config NET_DSA_MXL862 @@ -5,6 +5,7 @@ config NET_DSA_MXL862
depends on NET_DSA
select CRC16 select CRC16
select CRC32
select NET_DSA_TAG_MXL_862XX select NET_DSA_TAG_MXL_862XX
+ select NET_DSA_TAG_MXL_862XX_8021Q + select NET_DSA_TAG_MXL_862XX_8021Q
help help
@@ -404,7 +404,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
/* PHY access via firmware relay */ /* PHY access via firmware relay */
@@ -477,6 +540,78 @@ static int mxl862xx_pce_rule_write(struc @@ -479,6 +542,78 @@ static int mxl862xx_pce_rule_write(struc
*rule); *rule);
} }
@@ -483,7 +483,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
/* Fill the action fields of a PCE rule that traps ingress frames to /* Fill the action fields of a PCE rule that traps ingress frames to
* the CPU port. Used by both the link-local trap and the multicast * the CPU port. Used by both the link-local trap and the multicast
* snooping traps. The caller must already have set the rule header * snooping traps. The caller must already have set the rule header
@@ -485,24 +620,36 @@ static int mxl862xx_pce_rule_write(struc @@ -487,24 +622,36 @@ static int mxl862xx_pce_rule_write(struc
* PORTMAP_ALTERNATIVE redirects the frame to the CPU port but does * PORTMAP_ALTERNATIVE redirects the frame to the CPU port but does
* not by itself bypass downstream flood gates. In SpTag mode the * not by itself bypass downstream flood gates. In SpTag mode the
* ingress port's private FID may have forward_unknown_multicast=false, * ingress port's private FID may have forward_unknown_multicast=false,
@@ -523,7 +523,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
rule->action.cross_state_action = rule->action.cross_state_action =
cpu_to_le32(MXL862XX_PCE_ACTION_CROSS_STATE_CROSS); cpu_to_le32(MXL862XX_PCE_ACTION_CROSS_STATE_CROSS);
@@ -635,11 +782,17 @@ static int mxl862xx_set_bridge_port(stru @@ -637,11 +784,17 @@ static int mxl862xx_set_bridge_port(stru
return 0; return 0;
if (dsa_port_is_cpu(dp)) { if (dsa_port_is_cpu(dp)) {
@@ -546,7 +546,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
} else if (dp->bridge) { } else if (dp->bridge) {
dsa_switch_for_each_bridge_member(member_dp, ds, dsa_switch_for_each_bridge_member(member_dp, ds,
@@ -650,10 +803,10 @@ static int mxl862xx_set_bridge_port(stru @@ -652,10 +805,10 @@ static int mxl862xx_set_bridge_port(stru
member_dp->index); member_dp->index);
} }
mxl862xx_fw_portmap_set_bit(br_port_cfg.bridge_port_map, mxl862xx_fw_portmap_set_bit(br_port_cfg.bridge_port_map,
@@ -559,7 +559,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
p->flood_block = 0; p->flood_block = 0;
p->learning = false; p->learning = false;
} }
@@ -863,10 +1016,12 @@ static void mxl862xx_free_bridge(struct @@ -889,10 +1042,12 @@ static void mxl862xx_setup_rescue(struct
static int mxl862xx_setup(struct dsa_switch *ds) static int mxl862xx_setup(struct dsa_switch *ds)
{ {
struct mxl862xx_priv *priv = ds->priv; struct mxl862xx_priv *priv = ds->priv;
@@ -572,9 +572,9 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
struct dsa_port *dp; struct dsa_port *dp;
- int ret, i, rescue; - int ret, i, rescue;
/* The SerDes state is software-only and must exist before anything can /* Detect the loader over SB PDI first: it needs no firmware, unlike the
* reach phylink, including a rescue-mode flash clearing rescue_mode * C45 API (mxl862xx_reset/wait_ready), which spends its whole 10 s
@@ -926,7 +1081,7 @@ static int mxl862xx_setup(struct dsa_swi @@ -941,7 +1096,7 @@ static int mxl862xx_setup(struct dsa_swi
return 0; return 0;
} }
@@ -583,7 +583,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* With VLAN Filter handling VID membership checks: * With VLAN Filter handling VID membership checks:
* Ingress: only final catchall rules (PVID insertion, 802.1Q * Ingress: only final catchall rules (PVID insertion, 802.1Q
* accept, non-8021Q TPID handling, discard). * accept, non-8021Q TPID handling, discard).
@@ -934,46 +1089,151 @@ static int mxl862xx_setup(struct dsa_swi @@ -949,46 +1104,151 @@ static int mxl862xx_setup(struct dsa_swi
* ingress EVLAN rules are needed. (7 entries.) * ingress EVLAN rules are needed. (7 entries.)
* Egress: 2 rules per VID that needs tag stripping (untagged VIDs). * Egress: 2 rules per VID that needs tag stripping (untagged VIDs).
* No egress final catchalls -- VLAN Filter does the discard. * No egress final catchalls -- VLAN Filter does the discard.
@@ -747,7 +747,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
/* Allocate a dedicated PCE snooping FID with all flood modes enabled. /* Allocate a dedicated PCE snooping FID with all flood modes enabled.
* Per-port PCE trap rules (link-local, IGMP, MLD) set bFidEnable to * Per-port PCE trap rules (link-local, IGMP, MLD) set bFidEnable to
* this FID so that the bridge engine uses it for its flood-permission * this FID so that the bridge engine uses it for its flood-permission
@@ -998,10 +1258,6 @@ static int mxl862xx_setup(struct dsa_swi @@ -1013,10 +1273,6 @@ static int mxl862xx_setup(struct dsa_swi
if (ret) if (ret)
goto free_trap_fid; goto free_trap_fid;
@@ -758,7 +758,21 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
ret = mxl862xx_setup_mdio(ds); ret = mxl862xx_setup_mdio(ds);
if (ret) if (ret)
goto free_trap_fid; goto free_trap_fid;
@@ -1100,10 +1356,71 @@ static int mxl862xx_configure_sp_tag_pro @@ -1037,6 +1293,13 @@ static void mxl862xx_teardown(struct dsa
set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags);
disable_delayed_work_sync(&priv->stats_work);
+
+ /* tag_8021q teardown is handled in mxl862xx_remove() under
+ * RTNL, before dsa_unregister_switch() takes dsa2_mutex.
+ * dsa_tag_8021q_unregister() needs RTNL for vlan_vid_del(),
+ * and acquiring RTNL inside teardown() (which runs under
+ * dsa2_mutex) would invert the RTNL -> dsa2_mutex lock order.
+ */
}
static int mxl862xx_port_state(struct dsa_switch *ds, int port, bool enable)
@@ -1123,10 +1386,71 @@ static int mxl862xx_configure_sp_tag_pro
return MXL862XX_API_WRITE(ds->priv, MXL862XX_SS_SPTAG_SET, tag); return MXL862XX_API_WRITE(ds->priv, MXL862XX_SS_SPTAG_SET, tag);
} }
@@ -831,7 +845,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
{ {
struct mxl862xx_extendedvlan_config cfg = {}; struct mxl862xx_extendedvlan_config cfg = {};
struct mxl862xx_extendedvlan_filter_vlan *fv; struct mxl862xx_extendedvlan_filter_vlan *fv;
@@ -1172,6 +1489,31 @@ static int mxl862xx_evlan_write_rule(str @@ -1195,6 +1519,31 @@ static int mxl862xx_evlan_write_rule(str
cpu_to_le32(MXL862XX_EXTENDEDVLAN_TREATMENT_DISCARD_UPSTREAM); cpu_to_le32(MXL862XX_EXTENDEDVLAN_TREATMENT_DISCARD_UPSTREAM);
} }
break; break;
@@ -863,7 +877,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
return MXL862XX_API_WRITE(priv, MXL862XX_EXTENDEDVLAN_SET, cfg); return MXL862XX_API_WRITE(priv, MXL862XX_EXTENDEDVLAN_SET, cfg);
@@ -1210,7 +1552,7 @@ static int mxl862xx_evlan_write_final_ru @@ -1233,7 +1582,7 @@ static int mxl862xx_evlan_write_final_ru
for (i = 0; i < n_rules; i++) { for (i = 0; i < n_rules; i++) {
ret = mxl862xx_evlan_write_rule(priv, blk->block_id, ret = mxl862xx_evlan_write_rule(priv, blk->block_id,
start_idx + i, &rules[i], start_idx + i, &rules[i],
@@ -872,7 +886,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) if (ret)
return ret; return ret;
} }
@@ -1331,6 +1673,41 @@ static int mxl862xx_vf_del_vid(struct mx @@ -1354,6 +1703,41 @@ static int mxl862xx_vf_del_vid(struct mx
return 0; return 0;
} }
@@ -914,7 +928,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static int mxl862xx_evlan_program_ingress(struct mxl862xx_priv *priv, int port) static int mxl862xx_evlan_program_ingress(struct mxl862xx_priv *priv, int port)
{ {
struct mxl862xx_port *p = &priv->ports[port]; struct mxl862xx_port *p = &priv->ports[port];
@@ -1355,8 +1732,8 @@ static int mxl862xx_evlan_program_egress @@ -1378,8 +1762,8 @@ static int mxl862xx_evlan_program_egress
const struct mxl862xx_evlan_rule_desc *vid_rules; const struct mxl862xx_evlan_rule_desc *vid_rules;
struct mxl862xx_vf_vid *vfv; struct mxl862xx_vf_vid *vfv;
u16 old_active = blk->n_active; u16 old_active = blk->n_active;
@@ -924,7 +938,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (p->vlan_filtering) { if (p->vlan_filtering) {
vid_rules = vid_accept_standard; vid_rules = vid_accept_standard;
@@ -1370,13 +1747,23 @@ static int mxl862xx_evlan_program_egress @@ -1393,13 +1777,23 @@ static int mxl862xx_evlan_program_egress
if (!vfv->untagged) if (!vfv->untagged)
continue; continue;
@@ -949,7 +963,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) if (ret)
return ret; return ret;
@@ -1385,7 +1772,29 @@ static int mxl862xx_evlan_program_egress @@ -1408,7 +1802,29 @@ static int mxl862xx_evlan_program_egress
idx++, &vid_rules[1], idx++, &vid_rules[1],
vfv->vid, vfv->vid,
vfv->untagged, vfv->untagged,
@@ -980,7 +994,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) if (ret)
return ret; return ret;
} }
@@ -1397,8 +1806,7 @@ static int mxl862xx_evlan_program_egress @@ -1420,8 +1836,7 @@ static int mxl862xx_evlan_program_egress
*/ */
for (i = idx; i < old_active; i++) { for (i = idx; i < old_active; i++) {
ret = mxl862xx_evlan_deactivate_entry(priv, ret = mxl862xx_evlan_deactivate_entry(priv,
@@ -990,7 +1004,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) if (ret)
return ret; return ret;
} }
@@ -1423,13 +1831,16 @@ static int mxl862xx_port_vlan_filtering( @@ -1446,13 +1861,16 @@ static int mxl862xx_port_vlan_filtering(
p->vlan_filtering = vlan_filtering; p->vlan_filtering = vlan_filtering;
if (changed) { if (changed) {
@@ -1012,7 +1026,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
ret = mxl862xx_evlan_program_ingress(priv, port); ret = mxl862xx_evlan_program_ingress(priv, port);
if (ret) if (ret)
@@ -1649,22 +2060,581 @@ static void mxl862xx_port_bridge_leave(s @@ -1672,22 +2090,571 @@ static void mxl862xx_port_bridge_leave(s
port, ERR_PTR(err)); port, ERR_PTR(err));
/* Revert leaving port, omitted by the sync above, to its /* Revert leaving port, omitted by the sync above, to its
@@ -1469,7 +1483,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ int ret, port; + int ret, port;
+ +
+ /* Just do nothing when in rescue mode */ + /* Just do nothing when in rescue mode */
+ if (priv->rescue_mode) { + if (READ_ONCE(priv->rescue_mode)) {
+ priv->tag_proto = proto; + priv->tag_proto = proto;
+ return 0; + return 0;
+ } + }
@@ -1582,21 +1596,11 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ priv->tag_proto = old_proto; + priv->tag_proto = old_proto;
+ return ret; + return ret;
+} +}
+
+static void mxl862xx_teardown(struct dsa_switch *ds)
+{
+ /* tag_8021q teardown is handled in mxl862xx_remove() under
+ * RTNL, before dsa_unregister_switch() takes dsa2_mutex.
+ * dsa_tag_8021q_unregister() needs RTNL for vlan_vid_del(),
+ * and acquiring RTNL inside teardown() (which runs under
+ * dsa2_mutex) would invert the RTNL -> dsa2_mutex lock order.
+ */
+}
+ +
static int mxl862xx_port_setup(struct dsa_switch *ds, int port) static int mxl862xx_port_setup(struct dsa_switch *ds, int port)
{ {
struct mxl862xx_priv *priv = ds->priv; struct mxl862xx_priv *priv = ds->priv;
@@ -1692,33 +2662,52 @@ static int mxl862xx_port_setup(struct ds @@ -1715,33 +2682,52 @@ static int mxl862xx_port_setup(struct ds
if (dsa_port_is_unused(dp)) if (dsa_port_is_unused(dp))
return 0; return 0;
@@ -1665,7 +1669,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) if (ret)
return ret; return ret;
ret = mxl862xx_set_bridge_port(ds, port); ret = mxl862xx_set_bridge_port(ds, port);
@@ -1734,24 +2723,7 @@ static int mxl862xx_port_setup(struct ds @@ -1757,24 +2743,7 @@ static int mxl862xx_port_setup(struct ds
if (ret) if (ret)
return ret; return ret;
@@ -1690,7 +1694,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return 0; return 0;
} }
@@ -1773,7 +2745,7 @@ static void mxl862xx_port_teardown(struc @@ -1796,7 +2765,7 @@ static void mxl862xx_port_teardown(struc
priv->ports[port].setup_done = false; priv->ports[port].setup_done = false;
} }
@@ -1699,7 +1703,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
{ {
struct mxl862xx_priv *priv = ds->priv; struct mxl862xx_priv *priv = ds->priv;
@@ -1791,23 +2763,253 @@ static int mxl862xx_get_fid(struct dsa_s @@ -1814,23 +2783,254 @@ static int mxl862xx_get_fid(struct dsa_s
} }
} }
@@ -1736,11 +1740,11 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ if (bp_cpu) + if (bp_cpu)
+ return bp_cpu; + return bp_cpu;
+ } + }
+
- param.port_id = cpu_to_le32(port);
+ return port; + return port;
+} +}
+
- param.port_id = cpu_to_le32(port);
+/** +/**
+ * mxl862xx_fdb_add_per_fid - Install a unicast FDB entry in one FID + * mxl862xx_fdb_add_per_fid - Install a unicast FDB entry in one FID
+ */ + */
@@ -1854,7 +1858,8 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ * gone, so there is nothing left to delete. Outside those, -ENODEV is a + * gone, so there is nothing left to delete. Outside those, -ENODEV is a
+ * bus error and must be reported. + * bus error and must be reported.
+ */ + */
+ if (ret == -ENODEV && (priv->skip_teardown || priv->rescue_mode)) + if (ret == -ENODEV &&
+ (priv->skip_teardown || READ_ONCE(priv->rescue_mode)))
+ return 0; + return 0;
+ if (ret) + if (ret)
+ return ret; + return ret;
@@ -1961,7 +1966,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) if (ret)
dev_err(ds->dev, "failed to add FDB entry on port %d\n", port); dev_err(ds->dev, "failed to add FDB entry on port %d\n", port);
@@ -1817,18 +3019,25 @@ static int mxl862xx_port_fdb_add(struct @@ -1840,18 +3040,25 @@ static int mxl862xx_port_fdb_add(struct
static int mxl862xx_port_fdb_del(struct dsa_switch *ds, int port, static int mxl862xx_port_fdb_del(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid, const struct dsa_db db) const unsigned char *addr, u16 vid, const struct dsa_db db)
{ {
@@ -1994,7 +1999,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (ret) if (ret)
dev_err(ds->dev, "failed to remove FDB entry on port %d\n", port); dev_err(ds->dev, "failed to remove FDB entry on port %d\n", port);
@@ -1867,90 +3076,153 @@ static int mxl862xx_port_fdb_dump(struct @@ -1890,24 +3097,70 @@ static int mxl862xx_port_fdb_dump(struct
return 0; return 0;
} }
@@ -2069,6 +2074,10 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ ret = mxl862xx_mdb_add_to_fid(ds, mdb, fid, + ret = mxl862xx_mdb_add_to_fid(ds, mdb, fid,
+ mxl862xx_fdb_bridge_port(ds, port, db), + mxl862xx_fdb_bridge_port(ds, port, db),
+ mdb->vid); + mdb->vid);
/* A flash blocks the API (-EBUSY) and its teardown drops the MAC
* table (-ENODEV); there is then nothing to program, and the reprobe
* starts from a fresh configuration. See mxl862xx_port_mdb_del().
@@ -1917,40 +3170,77 @@ static int mxl862xx_port_mdb_add(struct
if (ret) if (ret)
return ret; return ret;
@@ -2095,7 +2104,8 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
- sizeof(aparam.port_map)); - sizeof(aparam.port_map));
+ return ret; + return ret;
+} +}
+
- mxl862xx_fw_portmap_set_bit(aparam.port_map, port);
+/** +/**
+ * mxl862xx_mac_del_host_bridge - Remove every user-port VBP bit from a host + * mxl862xx_mac_del_host_bridge - Remove every user-port VBP bit from a host
+ * FDB/MDB entry, dropping the entry when its + * FDB/MDB entry, dropping the entry when its
@@ -2119,14 +2129,13 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ struct dsa_port *dp; + struct dsa_port *dp;
+ u16 vbp; + u16 vbp;
- mxl862xx_fw_portmap_set_bit(aparam.port_map, port); - return MXL862XX_API_WRITE(priv, MXL862XX_MAC_TABLEENTRYADD, aparam);
+ dsa_switch_for_each_user_port(dp, ds) { + dsa_switch_for_each_user_port(dp, ds) {
+ vbp = priv->ports[dp->index].bridge_port_cpu; + vbp = priv->ports[dp->index].bridge_port_cpu;
+ if (vbp) + if (vbp)
+ mxl862xx_fw_portmap_set_bit(del_map, vbp); + mxl862xx_fw_portmap_set_bit(del_map, vbp);
+ } + }
+
- return MXL862XX_API_WRITE(priv, MXL862XX_MAC_TABLEENTRYADD, aparam);
+ return mxl862xx_mac_portmap_del(priv, addr, fid, vid, del_map); + return mxl862xx_mac_portmap_del(priv, addr, fid, vid, del_map);
} }
@@ -2160,15 +2169,13 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
- ether_addr_copy(qparam.mac, mdb->addr); - ether_addr_copy(qparam.mac, mdb->addr);
- -
- ret = MXL862XX_API_READ(priv, MXL862XX_MAC_TABLEENTRYQUERY, qparam); - ret = MXL862XX_API_READ(priv, MXL862XX_MAC_TABLEENTRYQUERY, qparam);
- /* Post-flash teardown or MCUboot: the firmware and its MAC table are
- * gone, so there is nothing left to delete. Outside those, -ENODEV is a
- * bus error and must be reported.
- */
- if (ret == -ENODEV && (priv->skip_teardown || priv->rescue_mode))
- return 0;
+ ret = mxl862xx_mdb_del_from_fid(ds, mdb, fid, + ret = mxl862xx_mdb_del_from_fid(ds, mdb, fid,
+ mxl862xx_fdb_bridge_port(ds, port, db), + mxl862xx_fdb_bridge_port(ds, port, db),
+ mdb->vid); + mdb->vid);
/* A flash blocks the API (-EBUSY) and its teardown drops the MAC
* table (-ENODEV); a delete then has nothing to do. Outside these,
* both are bus errors and must be reported.
@@ -1960,26 +3250,12 @@ static int mxl862xx_port_mdb_del(struct
if (ret) if (ret)
return ret; return ret;
@@ -2201,7 +2208,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return ret; return ret;
} }
@@ -2038,6 +3310,9 @@ static void mxl862xx_host_flood_work_fn( @@ -2067,6 +3343,9 @@ static void mxl862xx_host_flood_work_fn(
host_flood_work); host_flood_work);
struct mxl862xx_priv *priv = p->priv; struct mxl862xx_priv *priv = p->priv;
struct dsa_switch *ds = priv->ds; struct dsa_switch *ds = priv->ds;
@@ -2211,7 +2218,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
rtnl_lock(); rtnl_lock();
@@ -2047,13 +3322,34 @@ static void mxl862xx_host_flood_work_fn( @@ -2076,13 +3355,34 @@ static void mxl862xx_host_flood_work_fn(
return; return;
} }
@@ -2253,17 +2260,15 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
rtnl_unlock(); rtnl_unlock();
} }
@@ -2425,7 +3721,9 @@ static void mxl862xx_get_stats64(struct @@ -2451,6 +3751,7 @@ static void mxl862xx_get_stats64(struct
static const struct dsa_switch_ops mxl862xx_switch_ops = { static const struct dsa_switch_ops mxl862xx_switch_ops = {
.get_tag_protocol = mxl862xx_get_tag_protocol, .get_tag_protocol = mxl862xx_get_tag_protocol,
+ .change_tag_protocol = mxl862xx_change_tag_protocol, + .change_tag_protocol = mxl862xx_change_tag_protocol,
.setup = mxl862xx_setup, .setup = mxl862xx_setup,
+ .teardown = mxl862xx_teardown, .teardown = mxl862xx_teardown,
.port_setup = mxl862xx_port_setup, .port_setup = mxl862xx_port_setup,
.port_teardown = mxl862xx_port_teardown, @@ -2474,6 +3775,8 @@ static const struct dsa_switch_ops mxl86
.phylink_get_caps = mxl862xx_phylink_get_caps,
@@ -2447,6 +3745,8 @@ static const struct dsa_switch_ops mxl86
.port_vlan_filtering = mxl862xx_port_vlan_filtering, .port_vlan_filtering = mxl862xx_port_vlan_filtering,
.port_vlan_add = mxl862xx_port_vlan_add, .port_vlan_add = mxl862xx_port_vlan_add,
.port_vlan_del = mxl862xx_port_vlan_del, .port_vlan_del = mxl862xx_port_vlan_del,
@@ -2272,7 +2277,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
.get_strings = mxl862xx_get_strings, .get_strings = mxl862xx_get_strings,
.get_sset_count = mxl862xx_get_sset_count, .get_sset_count = mxl862xx_get_sset_count,
.get_ethtool_stats = mxl862xx_get_ethtool_stats, .get_ethtool_stats = mxl862xx_get_ethtool_stats,
@@ -2503,6 +3803,8 @@ static int mxl862xx_probe(struct mdio_de @@ -2524,6 +3827,8 @@ static int mxl862xx_probe(struct mdio_de
INIT_DELAYED_WORK(&priv->stats_work, mxl862xx_stats_work_fn); INIT_DELAYED_WORK(&priv->stats_work, mxl862xx_stats_work_fn);
@@ -2281,9 +2286,9 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
dev_set_drvdata(dev, ds); dev_set_drvdata(dev, ds);
err = dsa_register_switch(ds); err = dsa_register_switch(ds);
@@ -2533,6 +3835,19 @@ static void mxl862xx_remove(struct mdio_ @@ -2556,6 +3861,19 @@ static void mxl862xx_remove(struct mdio_
set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags); */
cancel_delayed_work_sync(&priv->stats_work); mxl862xx_flash_shutdown(ds);
+ /* Tear down tag_8021q under RTNL before dsa_unregister_switch(). + /* Tear down tag_8021q under RTNL before dsa_unregister_switch().
+ * dsa_tag_8021q_unregister() calls vlan_vid_del() which needs + * dsa_tag_8021q_unregister() calls vlan_vid_del() which needs
@@ -2335,23 +2340,23 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
struct mxl862xx_port_stats stats; struct mxl862xx_port_stats stats;
spinlock_t stats_lock; /* protects stats accumulators */ spinlock_t stats_lock; /* protects stats accumulators */
}; };
@@ -304,6 +312,7 @@ struct mxl862xx_fw_version { @@ -306,6 +314,7 @@ struct mxl862xx_fw_version {
* before CRC-triggered shutdown and cleared after;
* %MXL862XX_FLAG_WORK_STOPPED is set before cancelling
* stats_work to prevent rescheduling during teardown * stats_work to prevent rescheduling during teardown
* and a flash, and ends the rescue drain and its
* reprobe hand-off
+ * @tag_proto: active DSA tag protocol (native or 8021q) + * @tag_proto: active DSA tag protocol (native or 8021q)
* @drop_meter: index of the single shared zero-rate firmware meter * @drop_meter: index of the single shared zero-rate firmware meter
* used to unconditionally drop traffic (used to block * used to unconditionally drop traffic (used to block
* flooding) * flooding)
@@ -328,6 +337,7 @@ struct mxl862xx_fw_version { @@ -332,6 +341,7 @@ struct mxl862xx_fw_version {
* (0 .. ds->max_num_bridges). * (0 .. ds->max_num_bridges).
* @evlan_ingress_size: per-port ingress Extended VLAN block size * @evlan_ingress_size: per-port ingress Extended VLAN block size
* @evlan_egress_size: per-port egress Extended VLAN block size * @evlan_egress_size: per-port egress Extended VLAN block size
+ * @cpu_evlan_ingress_size: CPU port ingress EVLAN block size (tag_8021q) + * @cpu_evlan_ingress_size: CPU port ingress EVLAN block size (tag_8021q)
* @vf_block_size: per-port VLAN Filter block size * @vf_block_size: per-port VLAN Filter block size
* @block_host: reject firmware API commands (except FW_UPDATE) * @block_host: during a firmware flash, a host firmware read fails
* during a firmware flash * with -EBUSY and a write reports success without
@@ -359,6 +369,7 @@ struct mxl862xx_priv { @@ -375,6 +385,7 @@ struct mxl862xx_priv {
struct work_struct crc_err_work; struct work_struct crc_err_work;
struct work_struct rescue_heal_work; struct work_struct rescue_heal_work;
unsigned long flags; unsigned long flags;
@@ -2359,14 +2364,14 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
u16 drop_meter; u16 drop_meter;
struct mxl862xx_fw_version fw_version; struct mxl862xx_fw_version fw_version;
u16 asic_id; u16 asic_id;
@@ -370,6 +381,7 @@ struct mxl862xx_priv { @@ -386,6 +397,7 @@ struct mxl862xx_priv {
u16 bridges[MXL862XX_MAX_BRIDGES + 1]; u16 bridges[MXL862XX_MAX_BRIDGES + 1];
u16 evlan_ingress_size; u16 evlan_ingress_size;
u16 evlan_egress_size; u16 evlan_egress_size;
+ u16 cpu_evlan_ingress_size; + u16 cpu_evlan_ingress_size;
u16 vf_block_size; u16 vf_block_size;
struct task_struct *flash_owner;
bool block_host; bool block_host;
bool skip_teardown;
--- a/include/net/dsa.h --- a/include/net/dsa.h
+++ b/include/net/dsa.h +++ b/include/net/dsa.h
@@ -56,6 +56,7 @@ struct tc_action; @@ -56,6 +56,7 @@ struct tc_action;
@@ -90,7 +90,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#define INT_GPHY_READ (GPY_GPY2XX_MAGIC + 0x1) #define INT_GPHY_READ (GPY_GPY2XX_MAGIC + 0x1)
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c --- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -766,7 +766,42 @@ static int mxl862xx_setup_snooping_traps @@ -768,7 +768,42 @@ static int mxl862xx_setup_snooping_traps
return mxl862xx_pce_rule_write(priv, &rule); return mxl862xx_pce_rule_write(priv, &rule);
} }
@@ -134,7 +134,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
{ {
struct mxl862xx_bridge_port_config br_port_cfg = {}; struct mxl862xx_bridge_port_config br_port_cfg = {};
struct dsa_port *dp = dsa_to_port(ds, port); struct dsa_port *dp = dsa_to_port(ds, port);
@@ -799,8 +834,12 @@ static int mxl862xx_set_bridge_port(stru @@ -801,8 +836,12 @@ static int mxl862xx_set_bridge_port(stru
dp->bridge->dev) { dp->bridge->dev) {
if (member_dp->index == port) if (member_dp->index == port)
continue; continue;
@@ -149,7 +149,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
mxl862xx_fw_portmap_set_bit(br_port_cfg.bridge_port_map, mxl862xx_fw_portmap_set_bit(br_port_cfg.bridge_port_map,
mxl862xx_cpu_bridge_port_id(ds, port)); mxl862xx_cpu_bridge_port_id(ds, port));
@@ -813,7 +852,7 @@ static int mxl862xx_set_bridge_port(stru @@ -815,7 +854,7 @@ static int mxl862xx_set_bridge_port(stru
bridge_id = dp->bridge ? priv->bridges[dp->bridge->num] : p->fid; bridge_id = dp->bridge ? priv->bridges[dp->bridge->num] : p->fid;
@@ -158,7 +158,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
br_port_cfg.bridge_id = cpu_to_le16(bridge_id); br_port_cfg.bridge_id = cpu_to_le16(bridge_id);
br_port_cfg.mask = cpu_to_le32(MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_ID | br_port_cfg.mask = cpu_to_le32(MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_ID |
MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_PORT_MAP | MXL862XX_BRIDGE_PORT_CONFIG_MASK_BRIDGE_PORT_MAP |
@@ -894,11 +933,38 @@ static int mxl862xx_set_bridge_port(stru @@ -896,11 +935,38 @@ static int mxl862xx_set_bridge_port(stru
br_port_cfg); br_port_cfg);
} }
@@ -198,7 +198,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
dsa_switch_for_each_bridge_member(dp, ds, bridge->dev) { dsa_switch_for_each_bridge_member(dp, ds, bridge->dev) {
err = mxl862xx_set_bridge_port(ds, dp->index); err = mxl862xx_set_bridge_port(ds, dp->index);
@@ -906,6 +972,25 @@ static int mxl862xx_sync_bridge_members( @@ -908,6 +974,25 @@ static int mxl862xx_sync_bridge_members(
ret = err; ret = err;
} }
@@ -224,7 +224,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return ret; return ret;
} }
@@ -2018,6 +2103,408 @@ static int mxl862xx_setup_cpu_bridge(str @@ -2048,6 +2133,408 @@ static int mxl862xx_setup_cpu_bridge(str
return mxl862xx_set_bridge_port(ds, port); return mxl862xx_set_bridge_port(ds, port);
} }
@@ -633,7 +633,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static int mxl862xx_port_bridge_join(struct dsa_switch *ds, int port, static int mxl862xx_port_bridge_join(struct dsa_switch *ds, int port,
const struct dsa_bridge bridge, const struct dsa_bridge bridge,
bool *tx_fwd_offload, bool *tx_fwd_offload,
@@ -2043,7 +2530,18 @@ static int mxl862xx_port_bridge_join(str @@ -2073,7 +2560,18 @@ static int mxl862xx_port_bridge_join(str
return 0; return 0;
} }
@@ -653,7 +653,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
static void mxl862xx_port_bridge_leave(struct dsa_switch *ds, int port, static void mxl862xx_port_bridge_leave(struct dsa_switch *ds, int port,
@@ -2094,6 +2592,17 @@ static void mxl862xx_port_bridge_leave(s @@ -2124,6 +2622,17 @@ static void mxl862xx_port_bridge_leave(s
"failed to update CPU VBP for port %d: %pe\n", port, "failed to update CPU VBP for port %d: %pe\n", port,
ERR_PTR(err)); ERR_PTR(err));
@@ -671,7 +671,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (!dsa_bridge_ports(ds, bridge.dev)) if (!dsa_bridge_ports(ds, bridge.dev))
mxl862xx_free_bridge(ds, &bridge); mxl862xx_free_bridge(ds, &bridge);
} }
@@ -2764,18 +3273,17 @@ static int mxl862xx_get_fid(struct dsa_s @@ -2784,18 +3293,17 @@ static int mxl862xx_get_fid(struct dsa_s
} }
/** /**
@@ -697,7 +697,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
*/ */
static int mxl862xx_fdb_bridge_port(struct dsa_switch *ds, int port, static int mxl862xx_fdb_bridge_port(struct dsa_switch *ds, int port,
const struct dsa_db db) const struct dsa_db db)
@@ -2791,7 +3299,7 @@ static int mxl862xx_fdb_bridge_port(stru @@ -2811,7 +3319,7 @@ static int mxl862xx_fdb_bridge_port(stru
return bp_cpu; return bp_cpu;
} }
@@ -706,7 +706,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
/** /**
@@ -3044,11 +3552,43 @@ static int mxl862xx_port_fdb_del(struct @@ -3065,11 +3573,43 @@ static int mxl862xx_port_fdb_del(struct
return ret; return ret;
} }
@@ -750,7 +750,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
u32 entry_port_id; u32 entry_port_id;
int ret; int ret;
@@ -3062,7 +3602,7 @@ static int mxl862xx_port_fdb_dump(struct @@ -3083,7 +3623,7 @@ static int mxl862xx_port_fdb_dump(struct
entry_port_id = le32_to_cpu(param.port_id); entry_port_id = le32_to_cpu(param.port_id);
@@ -759,7 +759,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
ret = cb(param.mac, FIELD_GET(MXL862XX_TCI_VLAN_ID, ret = cb(param.mac, FIELD_GET(MXL862XX_TCI_VLAN_ID,
le16_to_cpu(param.tci)), le16_to_cpu(param.tci)),
param.static_entry, data); param.static_entry, data);
@@ -3742,6 +4282,11 @@ static const struct dsa_switch_ops mxl86 @@ -3772,6 +4312,11 @@ static const struct dsa_switch_ops mxl86
.port_fdb_dump = mxl862xx_port_fdb_dump, .port_fdb_dump = mxl862xx_port_fdb_dump,
.port_mdb_add = mxl862xx_port_mdb_add, .port_mdb_add = mxl862xx_port_mdb_add,
.port_mdb_del = mxl862xx_port_mdb_del, .port_mdb_del = mxl862xx_port_mdb_del,
@@ -771,7 +771,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
.port_vlan_filtering = mxl862xx_port_vlan_filtering, .port_vlan_filtering = mxl862xx_port_vlan_filtering,
.port_vlan_add = mxl862xx_port_vlan_add, .port_vlan_add = mxl862xx_port_vlan_add,
.port_vlan_del = mxl862xx_port_vlan_del, .port_vlan_del = mxl862xx_port_vlan_del,
@@ -3791,6 +4336,7 @@ static int mxl862xx_probe(struct mdio_de @@ -3815,6 +4360,7 @@ static int mxl862xx_probe(struct mdio_de
ds->assisted_learning_on_cpu_port = true; ds->assisted_learning_on_cpu_port = true;
ds->fdb_isolation = true; ds->fdb_isolation = true;
ds->max_num_bridges = MXL862XX_MAX_BRIDGES; ds->max_num_bridges = MXL862XX_MAX_BRIDGES;
@@ -824,7 +824,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
struct mxl862xx_port_stats stats; struct mxl862xx_port_stats stats;
spinlock_t stats_lock; /* protects stats accumulators */ spinlock_t stats_lock; /* protects stats accumulators */
}; };
@@ -360,6 +382,15 @@ struct mxl862xx_fw_version { @@ -376,6 +398,15 @@ struct mxl862xx_fw_version {
* policy. Set once in setup() and referenced by * policy. Set once in setup() and referenced by
* fill_cpu_trap_action() via bFidEnable. The PCE FID * fill_cpu_trap_action() via bFidEnable. The PCE FID
* action field is 6 bits, so this value must be <= 63. * action field is 6 bits, so this value must be <= 63.
@@ -840,7 +840,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* @stats_work: periodic work item that polls RMON hardware counters * @stats_work: periodic work item that polls RMON hardware counters
* and accumulates them into 64-bit per-port stats * and accumulates them into 64-bit per-port stats
*/ */
@@ -389,6 +420,8 @@ struct mxl862xx_priv { @@ -407,6 +438,8 @@ struct mxl862xx_priv {
bool rescue_ready; bool rescue_ready;
bool rescue_failed; bool rescue_failed;
u16 cpu_trap_fid; u16 cpu_trap_fid;
@@ -50,7 +50,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#define MXL862XX_TFLOW_PCERULEALLOC (MXL862XX_TFLOW_MAGIC + 0x4) #define MXL862XX_TFLOW_PCERULEALLOC (MXL862XX_TFLOW_MAGIC + 0x4)
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c --- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -1239,6 +1239,8 @@ static int mxl862xx_setup(struct dsa_swi @@ -1254,6 +1254,8 @@ static int mxl862xx_setup(struct dsa_swi
(n_user_ports + n_cpu_ports); (n_user_ports + n_cpu_ports);
} }
@@ -59,7 +59,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
ret = mxl862xx_setup_drop_meter(ds); ret = mxl862xx_setup_drop_meter(ds);
if (ret) if (ret)
return ret; return ret;
@@ -2103,6 +2105,120 @@ static int mxl862xx_setup_cpu_bridge(str @@ -2133,6 +2135,120 @@ static int mxl862xx_setup_cpu_bridge(str
return mxl862xx_set_bridge_port(ds, port); return mxl862xx_set_bridge_port(ds, port);
} }
@@ -180,7 +180,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
/** /**
* mxl862xx_lag_master_port - Find the LAG master (lowest-numbered member) * mxl862xx_lag_master_port - Find the LAG master (lowest-numbered member)
* @ds: DSA switch * @ds: DSA switch
@@ -4282,6 +4398,8 @@ static const struct dsa_switch_ops mxl86 @@ -4312,6 +4428,8 @@ static const struct dsa_switch_ops mxl86
.port_fdb_dump = mxl862xx_port_fdb_dump, .port_fdb_dump = mxl862xx_port_fdb_dump,
.port_mdb_add = mxl862xx_port_mdb_add, .port_mdb_add = mxl862xx_port_mdb_add,
.port_mdb_del = mxl862xx_port_mdb_del, .port_mdb_del = mxl862xx_port_mdb_del,
@@ -209,7 +209,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
struct dsa_lag *lag; struct dsa_lag *lag;
bool lag_tx_enabled; bool lag_tx_enabled;
u8 lag_hash_bits; u8 lag_hash_bits;
@@ -391,6 +395,8 @@ struct mxl862xx_fw_version { @@ -407,6 +411,8 @@ struct mxl862xx_fw_version {
* @trunk_hash: current global hash field bitmask (6 bits, * @trunk_hash: current global hash field bitmask (6 bits,
* MXL862XX_TRUNK_HASH_*); union of all active LAGs' * MXL862XX_TRUNK_HASH_*); union of all active LAGs'
* hash requirements * hash requirements
@@ -218,7 +218,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* @stats_work: periodic work item that polls RMON hardware counters * @stats_work: periodic work item that polls RMON hardware counters
* and accumulates them into 64-bit per-port stats * and accumulates them into 64-bit per-port stats
*/ */
@@ -422,6 +428,7 @@ struct mxl862xx_priv { @@ -440,6 +446,7 @@ struct mxl862xx_priv {
u16 cpu_trap_fid; u16 cpu_trap_fid;
u16 lag_bridge_ports[MXL862XX_MAX_LAG_IDS + 1]; u16 lag_bridge_ports[MXL862XX_MAX_LAG_IDS + 1];
u8 trunk_hash; u8 trunk_hash;
@@ -25,7 +25,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_mdio.h> #include <linux/of_mdio.h>
@@ -3903,6 +3904,53 @@ static int mxl862xx_set_ageing_time(stru @@ -3936,6 +3937,53 @@ static int mxl862xx_set_ageing_time(stru
return ret; return ret;
} }
@@ -79,7 +79,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static void mxl862xx_port_stp_state_set(struct dsa_switch *ds, int port, static void mxl862xx_port_stp_state_set(struct dsa_switch *ds, int port,
u8 state) u8 state)
{ {
@@ -4387,6 +4435,8 @@ static const struct dsa_switch_ops mxl86 @@ -4417,6 +4465,8 @@ static const struct dsa_switch_ops mxl86
.port_disable = mxl862xx_port_disable, .port_disable = mxl862xx_port_disable,
.port_fast_age = mxl862xx_port_fast_age, .port_fast_age = mxl862xx_port_fast_age,
.set_ageing_time = mxl862xx_set_ageing_time, .set_ageing_time = mxl862xx_set_ageing_time,
@@ -24,7 +24,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c --- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -844,6 +844,10 @@ static int __mxl862xx_set_bridge_port(st @@ -846,6 +846,10 @@ static int __mxl862xx_set_bridge_port(st
} }
mxl862xx_fw_portmap_set_bit(br_port_cfg.bridge_port_map, mxl862xx_fw_portmap_set_bit(br_port_cfg.bridge_port_map,
mxl862xx_cpu_bridge_port_id(ds, port)); mxl862xx_cpu_bridge_port_id(ds, port));
@@ -35,7 +35,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} else { } else {
mxl862xx_fw_portmap_set_bit(br_port_cfg.bridge_port_map, mxl862xx_fw_portmap_set_bit(br_port_cfg.bridge_port_map,
mxl862xx_cpu_bridge_port_id(ds, port)); mxl862xx_cpu_bridge_port_id(ds, port));
@@ -4074,7 +4078,7 @@ static int mxl862xx_port_pre_bridge_flag @@ -4107,7 +4111,7 @@ static int mxl862xx_port_pre_bridge_flag
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD | if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD |
@@ -44,7 +44,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return -EINVAL; return -EINVAL;
return 0; return 0;
@@ -4116,7 +4120,11 @@ static int mxl862xx_port_bridge_flags(st @@ -4149,7 +4153,11 @@ static int mxl862xx_port_bridge_flags(st
if (flags.mask & BR_LEARNING) if (flags.mask & BR_LEARNING)
priv->ports[port].learning = !!(flags.val & BR_LEARNING); priv->ports[port].learning = !!(flags.val & BR_LEARNING);
@@ -19,7 +19,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c --- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -837,6 +837,8 @@ static int __mxl862xx_set_bridge_port(st @@ -839,6 +839,8 @@ static int __mxl862xx_set_bridge_port(st
continue; continue;
if (!mxl862xx_is_lag_master(priv, member_dp->index)) if (!mxl862xx_is_lag_master(priv, member_dp->index))
continue; continue;
@@ -28,7 +28,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
mxl862xx_fw_portmap_set_bit( mxl862xx_fw_portmap_set_bit(
br_port_cfg.bridge_port_map, br_port_cfg.bridge_port_map,
mxl862xx_lag_bridge_port(priv, mxl862xx_lag_bridge_port(priv,
@@ -4078,7 +4080,7 @@ static int mxl862xx_port_pre_bridge_flag @@ -4111,7 +4113,7 @@ static int mxl862xx_port_pre_bridge_flag
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD | if (flags.mask & ~(BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD |
@@ -37,7 +37,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return -EINVAL; return -EINVAL;
return 0; return 0;
@@ -4091,6 +4093,7 @@ static int mxl862xx_port_bridge_flags(st @@ -4124,6 +4126,7 @@ static int mxl862xx_port_bridge_flags(st
struct mxl862xx_priv *priv = ds->priv; struct mxl862xx_priv *priv = ds->priv;
unsigned long old_block = priv->ports[port].flood_block; unsigned long old_block = priv->ports[port].flood_block;
unsigned long block = old_block; unsigned long block = old_block;
@@ -45,7 +45,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
int ret; int ret;
if (flags.mask & BR_FLOOD) { if (flags.mask & BR_FLOOD) {
@@ -4131,6 +4134,21 @@ static int mxl862xx_port_bridge_flags(st @@ -4164,6 +4167,21 @@ static int mxl862xx_port_bridge_flags(st
return ret; return ret;
} }
@@ -46,7 +46,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#define MXL862XX_TFLOW_PCERULELOGICWRITE \ #define MXL862XX_TFLOW_PCERULELOGICWRITE \
--- a/drivers/net/dsa/mxl862xx/mxl862xx.c --- a/drivers/net/dsa/mxl862xx/mxl862xx.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c
@@ -516,6 +516,44 @@ static int mxl862xx_setup_drop_meter(str @@ -518,6 +518,44 @@ static int mxl862xx_setup_drop_meter(str
return MXL862XX_API_WRITE(priv, MXL862XX_COMMON_REGISTERMOD, reg); return MXL862XX_API_WRITE(priv, MXL862XX_COMMON_REGISTERMOD, reg);
} }
@@ -91,7 +91,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
/* Per-CTP logical indices for protocol trap rules. /* Per-CTP logical indices for protocol trap rules.
* *
* The firmware pre-allocates a per-CTP PCE block for every port during * The firmware pre-allocates a per-CTP PCE block for every port during
@@ -529,16 +567,20 @@ static int mxl862xx_setup_drop_meter(str @@ -531,16 +569,20 @@ static int mxl862xx_setup_drop_meter(str
#define MXL862XX_MLDV1_CTP_INDEX 3 #define MXL862XX_MLDV1_CTP_INDEX 3
#define MXL862XX_MLDV2_CTP_INDEX 4 #define MXL862XX_MLDV2_CTP_INDEX 4
@@ -118,7 +118,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
} }
/** /**
@@ -1252,9 +1294,11 @@ static int mxl862xx_setup(struct dsa_swi @@ -1267,9 +1309,11 @@ static int mxl862xx_setup(struct dsa_swi
if (ret) if (ret)
return ret; return ret;
@@ -301,7 +301,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#define MXL862XX_XPCS_PCS_GET_STATE (MXL862XX_XPCS_MAGIC + 0x2) #define MXL862XX_XPCS_PCS_GET_STATE (MXL862XX_XPCS_MAGIC + 0x2)
--- a/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c --- a/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c
@@ -66,6 +66,153 @@ static struct mxl862xx_pcs *pcs_to_mxl86 @@ -71,6 +71,153 @@ static struct mxl862xx_pcs *pcs_to_mxl86
return container_of(pcs, struct mxl862xx_pcs, pcs); return container_of(pcs, struct mxl862xx_pcs, pcs);
} }
@@ -455,7 +455,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
static int mxl862xx_xpcs_if_mode(phy_interface_t interface) static int mxl862xx_xpcs_if_mode(phy_interface_t interface)
{ {
switch (interface) { switch (interface) {
@@ -380,7 +527,10 @@ void mxl862xx_setup_pcs(struct mxl862xx_ @@ -385,7 +532,10 @@ void mxl862xx_setup_pcs(struct mxl862xx_
pcs->slot = MXL862XX_SERDES_SLOT(port); pcs->slot = MXL862XX_SERDES_SLOT(port);
pcs->interface = PHY_INTERFACE_MODE_NA; pcs->interface = PHY_INTERFACE_MODE_NA;
@@ -14,7 +14,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
--- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c --- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c
@@ -210,7 +210,7 @@ static int mxl862xx_busy_wait(struct mxl @@ -216,7 +216,7 @@ static int mxl862xx_busy_wait(struct mxl
int val; int val;
return readx_poll_timeout(mxl862xx_ctrl_read, priv, val, return readx_poll_timeout(mxl862xx_ctrl_read, priv, val,
@@ -86,7 +86,7 @@ Signed-off-by: Jonas Jelonek <jonas@jonasjelonek.de>
} }
--- a/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c --- a/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c
+++ b/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c
@@ -71,7 +71,7 @@ static int mxl862xx_legacy_pcs_config(st @@ -76,7 +76,7 @@ static int mxl862xx_legacy_pcs_config(st
unsigned int neg_mode, unsigned int neg_mode,
phy_interface_t interface, phy_interface_t interface,
const unsigned long *advertising, const unsigned long *advertising,
@@ -95,7 +95,7 @@ Signed-off-by: Jonas Jelonek <jonas@jonasjelonek.de>
{ {
struct mxl862xx_pcs *mpcs = pcs_to_mxl862xx_pcs(pcs); struct mxl862xx_pcs *mpcs = pcs_to_mxl862xx_pcs(pcs);
struct mxl862xx_priv *priv = mpcs->priv; struct mxl862xx_priv *priv = mpcs->priv;
@@ -298,7 +298,7 @@ static int mxl862xx_xpcs_errno(int resul @@ -303,7 +303,7 @@ static int mxl862xx_xpcs_errno(int resul
static int mxl862xx_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode, static int mxl862xx_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
phy_interface_t interface, phy_interface_t interface,
const unsigned long *advertising, const unsigned long *advertising,
@@ -49,7 +49,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
#include <linux/unaligned.h> #include <linux/unaligned.h>
#include "realtek-pse-mcu.h" #include "realtek-pse-mcu.h"
@@ -90,6 +92,7 @@ enum rtpse_mcu_cmd { @@ -88,6 +90,7 @@ enum rtpse_mcu_cmd {
RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT, RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT,
RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_EXT, RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_EXT,
RTPSE_MCU_CMD_PORT_SET_PRIORITY, RTPSE_MCU_CMD_PORT_SET_PRIORITY,
@@ -57,7 +57,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
RTPSE_MCU_CMD_PORT_GET_STATUS, RTPSE_MCU_CMD_PORT_GET_STATUS,
RTPSE_MCU_CMD_PORT_GET_POWER_STATS, RTPSE_MCU_CMD_PORT_GET_POWER_STATS,
RTPSE_MCU_CMD_PORT_GET_CONFIG, RTPSE_MCU_CMD_PORT_GET_CONFIG,
@@ -134,6 +137,7 @@ struct rtpse_mcu_port_measurement { @@ -132,6 +135,7 @@ struct rtpse_mcu_port_measurement {
struct rtpse_mcu_port_config { struct rtpse_mcu_port_config {
bool enable; bool enable;
@@ -65,7 +65,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
}; };
struct rtpse_mcu_port_ext_config { struct rtpse_mcu_port_ext_config {
@@ -153,6 +157,15 @@ struct rtpse_mcu_dialect { @@ -151,6 +155,15 @@ struct rtpse_mcu_dialect {
void (*parse_system_info)(const u8 *payload, struct rtpse_mcu_info *info); void (*parse_system_info)(const u8 *payload, struct rtpse_mcu_info *info);
int (*parse_port_class)(const struct rtpse_mcu_port_status *status); int (*parse_port_class)(const struct rtpse_mcu_port_status *status);
const char *(*mcu_type_str)(unsigned int mcu_type); const char *(*mcu_type_str)(unsigned int mcu_type);
@@ -81,7 +81,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
}; };
struct rtpse_mcu_chip_info { struct rtpse_mcu_chip_info {
@@ -576,6 +589,7 @@ static int rtpse_mcu_port_get_config(str @@ -574,6 +587,7 @@ static int rtpse_mcu_port_get_config(str
return ret; return ret;
config->enable = (resp.payload[1] == 1); config->enable = (resp.payload[1] == 1);
@@ -89,7 +89,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
return 0; return 0;
} }
@@ -862,6 +876,138 @@ static const struct pse_controller_ops r @@ -860,6 +874,138 @@ static const struct pse_controller_ops r
.pi_set_prio = rtpse_mcu_port_set_prio, .pi_set_prio = rtpse_mcu_port_set_prio,
}; };
@@ -228,7 +228,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
static int rtpse_mcu_discover(struct rtpse_mcu_ctrl *pse, struct rtpse_mcu_info *info) static int rtpse_mcu_discover(struct rtpse_mcu_ctrl *pse, struct rtpse_mcu_info *info)
{ {
struct rtpse_mcu_ext_config ext_config; struct rtpse_mcu_ext_config ext_config;
@@ -1047,6 +1193,10 @@ int rtpse_mcu_register(struct rtpse_mcu_ @@ -1044,6 +1190,10 @@ int rtpse_mcu_register(struct rtpse_mcu_
if (ret) if (ret)
goto err_restore_budget; goto err_restore_budget;
@@ -239,7 +239,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
return 0; return 0;
err_restore_budget: err_restore_budget:
@@ -1124,6 +1274,8 @@ static const struct rtpse_mcu_dialect rt @@ -1121,6 +1271,8 @@ static const struct rtpse_mcu_dialect rt
.parse_system_info = rtpse_mcu_gen2_parse_system_info, .parse_system_info = rtpse_mcu_gen2_parse_system_info,
.parse_port_class = rtpse_mcu_gen2_parse_port_class, .parse_port_class = rtpse_mcu_gen2_parse_port_class,
.mcu_type_str = rtpse_mcu_gen2_mcu_type_str, .mcu_type_str = rtpse_mcu_gen2_mcu_type_str,
@@ -248,7 +248,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
.opcode = { .opcode = {
[RTPSE_MCU_CMD_SET_GLOBAL_STATE] = RTPSE_MCU_OP(0x00), [RTPSE_MCU_CMD_SET_GLOBAL_STATE] = RTPSE_MCU_OP(0x00),
[RTPSE_MCU_CMD_GET_SYSTEM_INFO] = RTPSE_MCU_OP(0x40), [RTPSE_MCU_CMD_GET_SYSTEM_INFO] = RTPSE_MCU_OP(0x40),
@@ -1137,6 +1289,7 @@ static const struct rtpse_mcu_dialect rt @@ -1134,6 +1286,7 @@ static const struct rtpse_mcu_dialect rt
[RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT] = RTPSE_MCU_OP(0x13), [RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT] = RTPSE_MCU_OP(0x13),
[RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_EXT] = RTPSE_MCU_OP(0x14), [RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_EXT] = RTPSE_MCU_OP(0x14),
[RTPSE_MCU_CMD_PORT_SET_PRIORITY] = RTPSE_MCU_OP(0x15), [RTPSE_MCU_CMD_PORT_SET_PRIORITY] = RTPSE_MCU_OP(0x15),
@@ -256,7 +256,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
[RTPSE_MCU_CMD_PORT_GET_STATUS] = RTPSE_MCU_OP(0x42), [RTPSE_MCU_CMD_PORT_GET_STATUS] = RTPSE_MCU_OP(0x42),
[RTPSE_MCU_CMD_PORT_GET_POWER_STATS] = RTPSE_MCU_OP(0x44), [RTPSE_MCU_CMD_PORT_GET_POWER_STATS] = RTPSE_MCU_OP(0x44),
[RTPSE_MCU_CMD_PORT_GET_CONFIG] = RTPSE_MCU_OP(0x48), [RTPSE_MCU_CMD_PORT_GET_CONFIG] = RTPSE_MCU_OP(0x48),
@@ -1148,6 +1301,8 @@ static const struct rtpse_mcu_dialect rt @@ -1145,6 +1298,8 @@ static const struct rtpse_mcu_dialect rt
.parse_system_info = rtpse_mcu_gen1_parse_system_info, .parse_system_info = rtpse_mcu_gen1_parse_system_info,
.parse_port_class = rtpse_mcu_gen1_parse_port_class, .parse_port_class = rtpse_mcu_gen1_parse_port_class,
.mcu_type_str = rtpse_mcu_gen1_mcu_type_str, .mcu_type_str = rtpse_mcu_gen1_mcu_type_str,
@@ -265,7 +265,7 @@ Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
.opcode = { .opcode = {
[RTPSE_MCU_CMD_GET_SYSTEM_INFO] = RTPSE_MCU_OP(0x20), [RTPSE_MCU_CMD_GET_SYSTEM_INFO] = RTPSE_MCU_OP(0x20),
[RTPSE_MCU_CMD_GET_EXT_CONFIG] = RTPSE_MCU_OP(0x2b), [RTPSE_MCU_CMD_GET_EXT_CONFIG] = RTPSE_MCU_OP(0x2b),
@@ -1159,6 +1314,7 @@ static const struct rtpse_mcu_dialect rt @@ -1156,6 +1311,7 @@ static const struct rtpse_mcu_dialect rt
[RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_TYPE] = RTPSE_MCU_OP(0x15), [RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT_TYPE] = RTPSE_MCU_OP(0x15),
[RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT] = RTPSE_MCU_OP(0x16), [RTPSE_MCU_CMD_PORT_SET_POWER_LIMIT] = RTPSE_MCU_OP(0x16),
[RTPSE_MCU_CMD_PORT_SET_PRIORITY] = RTPSE_MCU_OP(0x1a), [RTPSE_MCU_CMD_PORT_SET_PRIORITY] = RTPSE_MCU_OP(0x1a),