From nobody Sat Jul 25 03:45:46 2026 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A041253B73; Sat, 25 Jul 2026 02:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945745; cv=none; b=dMrQUsdmz3qfhGvSxShYDOl8Eun9fBZO6l5vQ2x5R6KovR3LSlaTt8cTXQH8n0vOsL2Sihjx4ayZHqutA16+QkwYcH9vhAccfgNfjYkJsdtdvNGBpUtWM6akU1RVwWsF492aEecRjMoPxYaf7Zj7mLO7swBDo1vmcZc4m6SmdYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945745; c=relaxed/simple; bh=jXCakz0ZLgqE7N5RhPNwIbYHT1Wge1Ynu8U+vXUFSHo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oCnnhGCIohzYfnpB2MaH0jIWsB5/LTC6PK6THrPOTEnHWzkqBTuWgauDJ1b9MOx3p+mfIw2W3Eff04C6Qk67aoQPFakYjuDixDxwpbxrWnsfxuFp6Ti/P+pgVlohZUsKf+nN36MvSpyoC31e1X0jPSDrprbhzUfBBwsx33jE7U4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.99) (envelope-from ) id 1wnRvO-000000002jD-09Ad; Sat, 25 Jul 2026 02:15:38 +0000 Date: Sat, 25 Jul 2026 03:15:35 +0100 From: Daniel Golle To: Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Daniel Golle , Andrew Lunn , Vladimir Oltean , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 1/5] net: dsa: wire flash_update devlink callback to drivers Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a devlink_flash_update callback to dsa_switch_ops so that DSA drivers can support devlink dev flash without open-coding the devlink plumbing. Unlike the other trampolines in net/dsa/devlink.c, the flash_update op is only installed for switches whose driver implements the callback: the devlink core rejects flash requests up front when the op is absent, before fetching the firmware file from userspace, and an unconditionally present trampoline would defeat that early check and let unsupported requests block on request_firmware() only to fail with -EOPNOTSUPP afterwards. Signed-off-by: Daniel Golle --- v5: no changes v4: * only install the flash_update op for drivers implementing the callback so the devlink core keeps rejecting unsupported flash requests before fetching the firmware file v3: no changes v2: align continuation lines with the open parenthesis include/net/dsa.h | 3 +++ net/dsa/devlink.c | 50 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 8c16ef23cc10..c9e19348de61 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -1170,6 +1170,9 @@ struct dsa_switch_ops { int (*devlink_info_get)(struct dsa_switch *ds, struct devlink_info_req *req, struct netlink_ext_ack *extack); + int (*devlink_flash_update)(struct dsa_switch *ds, + struct devlink_flash_update_params *params, + struct netlink_ext_ack *extack); int (*devlink_sb_pool_get)(struct dsa_switch *ds, unsigned int sb_index, u16 pool_index, struct devlink_sb_pool_info *pool_info); diff --git a/net/dsa/devlink.c b/net/dsa/devlink.c index ed342f345692..d6022267a839 100644 --- a/net/dsa/devlink.c +++ b/net/dsa/devlink.c @@ -20,6 +20,15 @@ static int dsa_devlink_info_get(struct devlink *dl, return -EOPNOTSUPP; } =20 +static int dsa_devlink_flash_update(struct devlink *dl, + struct devlink_flash_update_params *params, + struct netlink_ext_ack *extack) +{ + struct dsa_switch *ds =3D dsa_devlink_to_ds(dl); + + return ds->ops->devlink_flash_update(ds, params, extack); +} + static int dsa_devlink_sb_pool_get(struct devlink *dl, unsigned int sb_index, u16 pool_index, struct devlink_sb_pool_info *pool_info) @@ -167,18 +176,31 @@ dsa_devlink_sb_occ_tc_port_bind_get(struct devlink_po= rt *dlp, p_max); } =20 -static const struct devlink_ops dsa_devlink_ops =3D { - .info_get =3D dsa_devlink_info_get, - .sb_pool_get =3D dsa_devlink_sb_pool_get, - .sb_pool_set =3D dsa_devlink_sb_pool_set, - .sb_port_pool_get =3D dsa_devlink_sb_port_pool_get, - .sb_port_pool_set =3D dsa_devlink_sb_port_pool_set, - .sb_tc_pool_bind_get =3D dsa_devlink_sb_tc_pool_bind_get, - .sb_tc_pool_bind_set =3D dsa_devlink_sb_tc_pool_bind_set, - .sb_occ_snapshot =3D dsa_devlink_sb_occ_snapshot, - .sb_occ_max_clear =3D dsa_devlink_sb_occ_max_clear, - .sb_occ_port_pool_get =3D dsa_devlink_sb_occ_port_pool_get, +/* The devlink core rejects flash requests up front when the flash_update + * op is absent, before fetching the firmware file from userspace. Only + * install the op for switches whose driver implements it, so that + * unsupported requests keep failing early. + */ +#define DSA_DEVLINK_OPS \ + .info_get =3D dsa_devlink_info_get, \ + .sb_pool_get =3D dsa_devlink_sb_pool_get, \ + .sb_pool_set =3D dsa_devlink_sb_pool_set, \ + .sb_port_pool_get =3D dsa_devlink_sb_port_pool_get, \ + .sb_port_pool_set =3D dsa_devlink_sb_port_pool_set, \ + .sb_tc_pool_bind_get =3D dsa_devlink_sb_tc_pool_bind_get, \ + .sb_tc_pool_bind_set =3D dsa_devlink_sb_tc_pool_bind_set, \ + .sb_occ_snapshot =3D dsa_devlink_sb_occ_snapshot, \ + .sb_occ_max_clear =3D dsa_devlink_sb_occ_max_clear, \ + .sb_occ_port_pool_get =3D dsa_devlink_sb_occ_port_pool_get, \ .sb_occ_tc_port_bind_get =3D dsa_devlink_sb_occ_tc_port_bind_get, + +static const struct devlink_ops dsa_devlink_ops =3D { + DSA_DEVLINK_OPS +}; + +static const struct devlink_ops dsa_devlink_flash_ops =3D { + DSA_DEVLINK_OPS + .flash_update =3D dsa_devlink_flash_update, }; =20 int dsa_devlink_param_get(struct devlink *dl, u32 id, @@ -378,12 +400,16 @@ void dsa_switch_devlink_unregister(struct dsa_switch = *ds) int dsa_switch_devlink_alloc(struct dsa_switch *ds) { struct dsa_devlink_priv *dl_priv; + const struct devlink_ops *ops; struct devlink *dl; =20 + ops =3D ds->ops->devlink_flash_update ? &dsa_devlink_flash_ops + : &dsa_devlink_ops; + /* Add the switch to devlink before calling setup, so that setup can * add dpipe tables */ - dl =3D devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev); + dl =3D devlink_alloc(ops, sizeof(*dl_priv), ds->dev); if (!dl) return -ENOMEM; =20 --=20 2.55.0 From nobody Sat Jul 25 03:45:46 2026 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBA2C243951; Sat, 25 Jul 2026 02:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945772; cv=none; b=ei33U9dz1Sr2Vqdi5fR7KS8nPGnuBp1sdUyRd+1zysn6ncDCKtiBckRMWm7LbwQFc8U/N0hfqzsThf2RgLpxMZJZXBHJ8K8XI0ZhA9DEQQzk8cZL2+v8l2FTdLl+p0ObbdBuAFYyzrhHSzvAFA0mjoOnXLh7A5tVbGxX1vrf2eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945772; c=relaxed/simple; bh=Oi4qOODfcgQZDCsE3th31lRXUHsRqMEDH7v/9eM6CnI=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VbMKTtb0ITXkLowhNlr+dAwoKabDeLWn7xcM4ML7XgqwI5GfnbTKLTWqVXFbHbFAr8o+PhZb8PrSGds9FkrBVLOvHtlniOZnL+Ha5q9GHP+nussU9o4KIsrcoZC7PeQIsNfjsYGf/NwWuraZRfNGl/jwGIideK3koTMZge2FS2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.99) (envelope-from ) id 1wnRvp-000000002jn-3pRe; Sat, 25 Jul 2026 02:16:06 +0000 Date: Sat, 25 Jul 2026 03:16:03 +0100 From: Daniel Golle To: Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Daniel Golle , Andrew Lunn , Vladimir Oltean , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 2/5] net: dsa: mxl862xx: add SMDIO clause-22 register access Message-ID: <4703e62868c862be4cef4933c7a7466310acee7a.1784945329.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add mxl862xx_smdio_read() and mxl862xx_smdio_write() for clause-22 SMDIO register access. The switch's MCUboot bootloader exposes only clause-22 registers; the clause-45 MMD interface needs the running firmware and is unavailable while the switch is in MCUboot. The MDIO bus lock is held per-transaction (not across polls) so that SB PDI polling during flash erase does not starve other non-switch users of the same MDIO bus, such as separate PHYs providing WAN or management interfaces. Unlike mxl862xx_api_wrap(), which takes the bus lock with MDIO_MUTEX_NESTED because it can be entered from the accessors of the switch-internal MDIO bus while that bus's lock of the same lock class is already held, the SMDIO helpers take it with a plain mutex_lock(). They are only called from probe and devlink flash contexts where no other MDIO bus lock can be held. Signed-off-by: Daniel Golle --- v5: no changes v4: no changes v3: explain the plain mutex_lock() vs MDIO_MUTEX_NESTED choice in the commit message v2: clarify in the commit message that the per-transaction bus locking is about unrelated non-switch devices on the same MDIO bus (Andrew Lunn) drivers/net/dsa/mxl862xx/mxl862xx-host.c | 35 ++++++++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-host.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-host.c b/drivers/net/dsa/mxl= 862xx/mxl862xx-host.c index 4acd216f7cc0..6e582caea1fa 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c @@ -495,6 +495,41 @@ int mxl862xx_reset(struct mxl862xx_priv *priv) return ret; } =20 +#define MXL862XX_SMDIO_ADDR_REG 0x1f +#define MXL862XX_SMDIO_PAGE_MASK 0xfff0 +#define MXL862XX_SMDIO_OFF_MASK 0x000f + +int mxl862xx_smdio_read(struct mxl862xx_priv *priv, u32 addr) +{ + struct mii_bus *bus =3D priv->mdiodev->bus; + int phy =3D priv->mdiodev->addr; + int ret; + + mutex_lock(&bus->mdio_lock); + ret =3D __mdiobus_write(bus, phy, MXL862XX_SMDIO_ADDR_REG, + addr & MXL862XX_SMDIO_PAGE_MASK); + if (ret >=3D 0) + ret =3D __mdiobus_read(bus, phy, addr & MXL862XX_SMDIO_OFF_MASK); + mutex_unlock(&bus->mdio_lock); + return ret; +} + +int mxl862xx_smdio_write(struct mxl862xx_priv *priv, u32 addr, u16 val) +{ + struct mii_bus *bus =3D priv->mdiodev->bus; + int phy =3D priv->mdiodev->addr; + int ret; + + mutex_lock(&bus->mdio_lock); + ret =3D __mdiobus_write(bus, phy, MXL862XX_SMDIO_ADDR_REG, + addr & MXL862XX_SMDIO_PAGE_MASK); + if (ret >=3D 0) + ret =3D __mdiobus_write(bus, phy, addr & MXL862XX_SMDIO_OFF_MASK, + val); + mutex_unlock(&bus->mdio_lock); + return ret; +} + void mxl862xx_host_init(struct mxl862xx_priv *priv) { INIT_WORK(&priv->crc_err_work, mxl862xx_crc_err_work_fn); diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-host.h b/drivers/net/dsa/mxl= 862xx/mxl862xx-host.h index 66d6ae198aff..4e054c6e4c0e 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx-host.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.h @@ -18,5 +18,7 @@ int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 cmd= , void *data, u16 size, mxl862xx_api_wrap(dev, cmd, &(data), sizeof((data)), true, true) =20 int mxl862xx_reset(struct mxl862xx_priv *priv); +int mxl862xx_smdio_read(struct mxl862xx_priv *priv, u32 addr); +int mxl862xx_smdio_write(struct mxl862xx_priv *priv, u32 addr, u16 val); =20 #endif /* __MXL862XX_HOST_H */ --=20 2.55.0 From nobody Sat Jul 25 03:45:46 2026 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A3DA299A87; Sat, 25 Jul 2026 02:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945811; cv=none; b=jAGP+JdGk6lnXnk6+frFF2B/T5y8woWAZ203+GDgWDZrTeHNs7T/hCjfd0ORFIGyXknu0kkFX5+OLUqAIjtELS8h4uec2TGBVzFWyzTpVdoLSPw+Yo0BwNm8I53ZU3giyLkgsjV3IVuK7pco86KDC2q8CoUMtZpOUlhupC/5HlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945811; c=relaxed/simple; bh=JN60oURDJvTkBbDu9O/8/Rn0+L55AfJyxZiTwuYwlBg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=S8afEJ9847AO27vUo6JA4Bu3qUs3zTNHNESdy+tko7yvlpBCk3Vb0xrNlteqvr+wS4bY4d+xQ2zjDwzSlInqfb28ZpxfGzJDbdZcL+dgGydkeVEfmOMX9H0jnN/JxpqIrzURu6Ar2s30vxLQpT5KZYXJ+XC1BeBMpyTYPjtytko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.99) (envelope-from ) id 1wnRwQ-000000002kK-0EbG; Sat, 25 Jul 2026 02:16:42 +0000 Date: Sat, 25 Jul 2026 03:16:39 +0100 From: Daniel Golle To: Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Daniel Golle , Andrew Lunn , Vladimir Oltean , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 3/5] net: dsa: mxl862xx: add devlink flash_update and info_get Message-ID: <73a63f1d11658a041514f79ae177bfb93153d33a.1784945329.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement runtime firmware upgrade via "devlink dev flash" and version reporting via "devlink dev info": $ devlink dev info mdio_bus/mdio-bus:10 mdio_bus/mdio-bus:10: driver mxl862xx versions: fixed: asic.id 8628 asic.rev 0 running: fw 1.0.70 stored: fw 1.0.70 The "asic.id" and "asic.rev" fixed versions carry the numeric chip part number and revision from the static CHIP ID registers (SYS_MISC_REG_RD), which userspace such as fwupd matches firmware against. The switch boots its firmware from its own flash, so "fw" is reported as both the running and the stored version; a flashless part would omit "stored", distinguishing the two without an API change. $ devlink dev flash mdio_bus/mdio-bus:10 file mxl862xx-fw.bin The image, including both payload CRCs, is validated first, so a malformed file is rejected without disturbing the running switch. The 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 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 -- after a failure the switch is still in MCUboot and probe re-detects it. 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. The reprobe holds module and device references taken before the switch was disturbed and runs from a heap work item, not a kernel thread: remove() frees the devm-managed priv, and kthread_create() in the devlink caller would return -EINTR on interrupt or trip the hung-task watchdog while parked across the minute-long flash. Signed-off-by: Daniel Golle --- v5: - report the numeric chip part number and version read from the static CHIP ID registers as "asic.id" and "asic.rev" instead of a model-name string, which does not belong in a devlink version identifier (Jakub Kicinski) - report the running firmware version as the "stored" version too, since the switch boots it from its own flash, so userspace can tell a flash-backed part from a flashless one by the presence of "stored" without a future API change - run the post-flash reprobe from a self-contained work item again instead of the v4 kernel thread, which tripped the hung-task watchdog while parked across the flash and returned -EINTR from kthread_create() when the devlink command was interrupted - re-read the new firmware version through the reprobe's fresh probe and drop the SYS_MISC_FW_VERSION exemption from the host block - raise the firmware command poll timeout so the FW_UPDATE command that reboots into MCUboot is not cut short - move the devlink documentation into its own patch v4: - run the deferred reprobe from a kernel thread ending in module_put_and_kthread_exit() instead of a work item whose final module_put() raced against module unload - fail API read commands with -ENODEV after the update instead of faking success with an unfilled buffer, which sent port_fdb_dump() into an endless loop - keep block_host set across the post-update version query by exempting SYS_MISC_FW_VERSION instead of briefly lifting the block, and write the blocking flags under the MDIO bus lock - check the return value of every SB PDI control write; a failed address write during the half-bank switch could place the second half of the payload at the wrong flash offset undetected - report SMDIO write failures through one shared error path instead of per-site messages - initialise the progress notification deadline from jiffies so notifications are not suppressed on 32-bit shortly after boot - flush the switchdev deferred queue after closing the ports so the bridge's deferred STP DISABLED transitions reach the firmware while it is still running instead of failing with -EBUSY against the host block - treat -ENODEV as successful deletion in port_mdb_del() so the post-update teardown does not leave leftover host MDB entries behind for the DSA core to report v3: - validate the image, including both CRCs, before closing any ports so a malformed file no longer triggers a flash and reprobe cycle - reject images whose declared payload sizes overflow when summed (check_add_overflow) or sum up to zero; the latter used to erase the flash without writing anything back - allocate the reprobe work item and take the module and device references before disturbing the switch instead of silently skipping the reprobe when the allocation fails afterwards - check block_host/skip_teardown under the MDIO bus lock to close the window where a command already past the check could reach the bus after the switch rebooted into MCUboot - prevent the stats poll work from being re-armed and cancel the CRC error work before the transfer - check the return value of SB PDI data word writes; control writes are verified by the subsequent status polls - report a per-model chip name from the OF match data as "asic.id" instead of the devicetree compatible string whose comma is awkward for userspace consumers (Andrew Lunn) - commit message: the conduit is only closed, not detached v2: - factor out SB PDI slice flush and devlink status notification helpers, resolving checkpatch issues - use kzalloc_obj() (Manuel Ebner) - add kernel-doc for the new mxl862xx_priv members - trim comments and state the actual duration of a flash and reprobe cycle, just under a minute (Manuel Ebner) - reword commit message: split up run-on sentence, explain the dynamically allocated reprobe work item (Manuel Ebner), mention that closing the ports stops phylib polling (Andrew Lunn) drivers/net/dsa/mxl862xx/Makefile | 2 +- drivers/net/dsa/mxl862xx/mxl862xx-api.h | 10 + drivers/net/dsa/mxl862xx/mxl862xx-cmd.h | 2 + drivers/net/dsa/mxl862xx/mxl862xx-fw.c | 572 +++++++++++++++++++++++ drivers/net/dsa/mxl862xx/mxl862xx-fw.h | 17 + drivers/net/dsa/mxl862xx/mxl862xx-host.c | 11 + drivers/net/dsa/mxl862xx/mxl862xx.c | 49 ++ drivers/net/dsa/mxl862xx/mxl862xx.h | 12 + 8 files changed, 674 insertions(+), 1 deletion(-) create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.c create mode 100644 drivers/net/dsa/mxl862xx/mxl862xx-fw.h diff --git a/drivers/net/dsa/mxl862xx/Makefile b/drivers/net/dsa/mxl862xx/M= akefile index a7be0e6669df..bccac0d0f703 100644 --- a/drivers/net/dsa/mxl862xx/Makefile +++ b/drivers/net/dsa/mxl862xx/Makefile @@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_MXL862) +=3D mxl862xx_dsa.o -mxl862xx_dsa-y :=3D mxl862xx.o mxl862xx-host.o mxl862xx-phylink.o +mxl862xx_dsa-y :=3D mxl862xx.o mxl862xx-host.o mxl862xx-phylink.o mxl862xx= -fw.o diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-api.h b/drivers/net/dsa/mxl8= 62xx/mxl862xx-api.h index a180a5decffc..6f771895984c 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx-api.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx-api.h @@ -1224,6 +1224,16 @@ struct mxl862xx_sys_fw_image_version { __le32 iv_build_num; } __packed; =20 +/** + * struct mxl862xx_sys_reg_rw - System register read/write + * @addr: 32-bit register address + * @val: register value + */ +struct mxl862xx_sys_reg_rw { + __le32 addr; + __le32 val; +} __packed; + /** * enum mxl862xx_port_type - Port Type * @MXL862XX_LOGICAL_PORT: Logical Port diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-cmd.h b/drivers/net/dsa/mxl8= 62xx/mxl862xx-cmd.h index c87a955c13c4..a865425aa61e 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx-cmd.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx-cmd.h @@ -70,7 +70,9 @@ #define INT_GPHY_READ (GPY_GPY2XX_MAGIC + 0x1) #define INT_GPHY_WRITE (GPY_GPY2XX_MAGIC + 0x2) =20 +#define SYS_MISC_FW_UPDATE (SYS_MISC_MAGIC + 0x1) #define SYS_MISC_FW_VERSION (SYS_MISC_MAGIC + 0x2) +#define SYS_MISC_REG_RD (SYS_MISC_MAGIC + 0x8) =20 #define MXL862XX_XPCS_PCS_CONFIG (MXL862XX_XPCS_MAGIC + 0x1) #define MXL862XX_XPCS_PCS_GET_STATE (MXL862XX_XPCS_MAGIC + 0x2) diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-fw.c b/drivers/net/dsa/mxl86= 2xx/mxl862xx-fw.c new file mode 100644 index 000000000000..cde00e5583ee --- /dev/null +++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.c @@ -0,0 +1,572 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Firmware flash and devlink support for MaxLinear MxL862xx + * + * Copyright (C) 2025 Daniel Golle + * + * SB PDI - firmware download interface over clause-22 SMDIO + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * The MxL862xx MCUboot loader accepts a firmware image through four "SB P= DI" + * registers in the switch SMDIO register space. It runs whenever no WSP + * firmware is active: the normal firmware update enters it deliberately -= the + * SYS_MISC_FW_UPDATE API command sets a sticky rescue bit and reboots into + * MCUboot - and the loader also stays here when the stored WSP firmware f= ails + * its boot-time integrity check. This driver drives the loader's 0xc55c + * "console" download path. + * + * SMDIO register access (mxl862xx_smdio_read/write): + * MII reg 0x1f :=3D ; address/page latch + * MII reg 0x00 :=3D / =3D> ; data window + * + * SB PDI registers (host name/addr -> MCU mailbox): + * CTRL 0xe100 -> 0xc0938400 mode: RST=3D0x00 RD=3D0x01 WR=3D0x02 + * ADDR 0xe101 -> 0xc0938404 SB target word address (SB1 bank =3D 0x78= 00) + * DATA 0xe102 -> 0xc0938408 16-bit data / reply word + * STAT 0xe103 -> 0xc093840c handshake: a magic (below) or a byte count + * + * STAT magics: + * READY 0xc55c loader idle in the console loop (this driver) + * START 0xf48f host -> begin download session + * ACK 0xf490 loader -> START acknowledged (START + 1) + * END 0x3cc3 host -> end of transfer / finalise + * + * Console flash path (STAT=3D0xc55c) - mxl862xx_flash_firmware(): + * + * host loader + * ---- ------ + * reset (CTRL=3DADDR=3DDATA=3D0) + * read STAT ............................ 0xc55c (READY, idle) + * STAT :=3D START(0xf48f) --------------> + * <-------------- STAT =3D 0xf490 (ACK) + * CTRL :=3D WR + * DATA :=3D hdr[0..9] (20-byte header: type,size1,crc1,size2,crc2) + * reset; STAT :=3D 20 (header len) -----> parse hdr; r_remain=3Dsize1+= size2; + * ERASE target region(s) + * <-------------- STAT=3D21 (len+1), then STAT= =3D0 + * (erased) + * -- payload, streamed in slices: -- + * CTRL :=3D WR + * DATA :=3D word x N ... + * at word 16384: reset; ADDR:=3D0x7800; CTRL:=3DWR (half-bank -> SB= 1) + * at word 32760: flush slice: + * reset; STAT :=3D ---> r_remain -=3D bytes; pr= ogram + * <------------------- STAT=3D0 (ready for next= slice) + * ... repeat until the whole payload is sent ... + * STAT :=3D END(0x3cc3) ---------------------> finalise + * + * The r_remain =3D=3D 0 rule (critical): + * Every host STAT write in the payload phase is a byte count; the loader + * does r_remain -=3D count and stays in the receive loop while r_remain= !=3D 0. + * It leaves the loop, validates, and - if it was in rescue - clears its + * rescue-enable bit so boot_go boots the new image, ONLY when r_remain = hits + * EXACTLY 0. A count larger than r_remain underflows the 32-bit counter= and + * wedges the loader until a power cycle. Hence: + * - never send a slice/chunk count larger than what is outstanding; + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mxl862xx.h" +#include "mxl862xx-api.h" +#include "mxl862xx-cmd.h" +#include "mxl862xx-fw.h" +#include "mxl862xx-host.h" + +/* SB PDI registers (clause-22 SMDIO address space) */ +#define MXL862XX_SB_PDI_CTRL 0xe100 +#define MXL862XX_SB_PDI_ADDR 0xe101 +#define MXL862XX_SB_PDI_DATA 0xe102 +#define MXL862XX_SB_PDI_STAT 0xe103 + +/* SB PDI CTRL modes */ +#define MXL862XX_SB_PDI_CTRL_RST 0x00 +#define MXL862XX_SB_PDI_CTRL_WR 0x02 + +/* SB PDI handshake magic (published/consumed via STAT) */ +#define MXL862XX_SB_PDI_READY 0xc55c /* loader idle, console loop */ +#define MXL862XX_SB_PDI_START 0xf48f +#define MXL862XX_SB_PDI_END 0x3cc3 + +/* Firmware transfer geometry */ +#define MXL862XX_FW_HDR_SIZE 20 +#define MXL862XX_FW_BANK_HALF 16384 /* words per half-bank */ +#define MXL862XX_FW_BANK_SLICE 32760 /* words per full slice */ +#define MXL862XX_FW_SB1_ADDR 0x7800 /* SB1 word address */ + +/* Timeouts (generous upper bounds) */ +#define MXL862XX_FW_READY_TIMEOUT_MS 3000 +#define MXL862XX_FW_ACK_TIMEOUT_MS 5000 +#define MXL862XX_FW_ERASE_TIMEOUT_MS 300000 +#define MXL862XX_FW_WRITE_TIMEOUT_MS 120000 +#define MXL862XX_FW_REBOOT_DELAY_MS 5000 +#define MXL862XX_FW_REPROBE_DELAY_MS 500 + +static int mxl862xx_sb_pdi_reset(struct mxl862xx_priv *priv) +{ + int ret; + + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + MXL862XX_SB_PDI_CTRL_RST); + if (ret < 0) + return ret; + + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_ADDR, + MXL862XX_SB_PDI_CTRL_RST); + if (ret < 0) + return ret; + + return mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, + MXL862XX_SB_PDI_CTRL_RST); +} + +static int mxl862xx_sb_pdi_poll_stat(struct mxl862xx_priv *priv, u16 expec= ted, + unsigned long timeout_ms) +{ + unsigned long timeout =3D jiffies + msecs_to_jiffies(timeout_ms); + int ret; + + do { + ret =3D mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_STAT); + if (ret < 0) + return ret; + if ((u16)ret =3D=3D expected) + return 0; + usleep_range(10000, 11000); + } while (time_before(jiffies, timeout)); + + return -ETIMEDOUT; +} + +static int mxl862xx_sb_pdi_flush_slice(struct mxl862xx_priv *priv, + u32 data_written) +{ + int ret; + + ret =3D mxl862xx_sb_pdi_reset(priv); + if (ret < 0) + return ret; + + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, data_written); + if (ret < 0) + return ret; + + return mxl862xx_sb_pdi_poll_stat(priv, 0, + MXL862XX_FW_WRITE_TIMEOUT_MS); +} + +static void mxl862xx_flash_notify(struct devlink *dl, const char *status, + u32 done, u32 total) +{ + devlink_flash_update_status_notify(dl, status, NULL, done, total); +} + +/* Post-flash reprobe. Runs from a self-contained heap work (not a kthread= and + * not the devlink caller's context): kthread_create() in the caller conte= xt + * fails -EINTR if the devlink command was Ctrl-C'd, and schedule_work() c= annot. + * device_reprobe() -> remove() frees priv, so this must not touch priv; i= t uses + * only the held device reference and drops its module reference afterward= s. + */ +struct mxl862xx_reprobe_work { + struct work_struct work; + struct device *dev; +}; + +static void mxl862xx_reprobe_work_fn(struct work_struct *work) +{ + struct mxl862xx_reprobe_work *rw =3D + container_of(work, struct mxl862xx_reprobe_work, work); + struct device *dev =3D rw->dev; + + msleep(MXL862XX_FW_REPROBE_DELAY_MS); + if (device_reprobe(dev)) + dev_err(dev, "reprobe failed\n"); + put_device(dev); + kfree(rw); + module_put(THIS_MODULE); +} + +/* MCUboot firmware image header */ +struct mxl862xx_fw_hdr { + __le32 image_type; + __le32 image_size_1; + __le32 image_checksum_1; + __le32 image_size_2; + __le32 image_checksum_2; +} __packed; + +static int mxl862xx_flash_validate(struct mxl862xx_priv *priv, + const struct firmware *fw, + u32 *payload_size) +{ + const struct mxl862xx_fw_hdr *hdr; + u32 size1, size2, total; + const u8 *payload; + u32 crc; + + if (fw->size < MXL862XX_FW_HDR_SIZE) + return -EINVAL; + + hdr =3D (const struct mxl862xx_fw_hdr *)fw->data; + payload =3D fw->data + MXL862XX_FW_HDR_SIZE; + size1 =3D le32_to_cpu(hdr->image_size_1); + size2 =3D le32_to_cpu(hdr->image_size_2); + + if (check_add_overflow(size1, size2, &total) || + total > fw->size - MXL862XX_FW_HDR_SIZE) { + dev_err(&priv->mdiodev->dev, + "flash: firmware file too small for declared size\n"); + return -EINVAL; + } + + if (!total) { + dev_err(&priv->mdiodev->dev, + "flash: firmware file with empty payload\n"); + return -EINVAL; + } + + if (size1) { + crc =3D ~crc32_le(~0U, payload, size1); + if (crc !=3D le32_to_cpu(hdr->image_checksum_1)) { + dev_err(&priv->mdiodev->dev, + "flash: image 1 CRC mismatch (got %08x, expected %08x)\n", + crc, le32_to_cpu(hdr->image_checksum_1)); + return -EINVAL; + } + } + + if (size2) { + crc =3D ~crc32_le(~0U, payload + size1, size2); + if (crc !=3D le32_to_cpu(hdr->image_checksum_2)) { + dev_err(&priv->mdiodev->dev, + "flash: image 2 CRC mismatch (got %08x, expected %08x)\n", + crc, le32_to_cpu(hdr->image_checksum_2)); + return -EINVAL; + } + } + + *payload_size =3D total; + + return 0; +} + +static int mxl862xx_flash_firmware(struct mxl862xx_priv *priv, + const struct firmware *fw, + u32 payload_size, struct devlink *dl) +{ + const u8 *payload =3D fw->data + MXL862XX_FW_HDR_SIZE; + u32 word_idx =3D 0, data_written =3D 0, idx =3D 0; + unsigned long next_notify =3D jiffies - 1; + u16 word, fdata; + int ret, i; + + /* Step 1: reboot the firmware into MCUboot rescue mode */ + ret =3D 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 */ + mxl862xx_flash_notify(dl, "Waiting for bootloader", 0, 0); + ret =3D mxl862xx_sb_pdi_reset(priv); + if (ret < 0) + goto write_err; + + /* Failures from here on must go through end_magic so MCUboot + * reboots instead of waiting forever. + */ + ret =3D mxl862xx_sb_pdi_poll_stat(priv, MXL862XX_SB_PDI_READY, + MXL862XX_FW_READY_TIMEOUT_MS); + if (ret) { + dev_err(&priv->mdiodev->dev, + "flash: bootloader not ready: %pe\n", ERR_PTR(ret)); + return ret; + } + + /* Step 3: start handshake */ + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, + MXL862XX_SB_PDI_START); + if (ret < 0) + goto write_err; + + ret =3D mxl862xx_sb_pdi_poll_stat(priv, MXL862XX_SB_PDI_START + 1, + MXL862XX_FW_ACK_TIMEOUT_MS); + if (ret) { + dev_err(&priv->mdiodev->dev, + "flash: start handshake failed: %pe\n", ERR_PTR(ret)); + return ret; + } + + /* Step 4: transfer image header */ + mxl862xx_flash_notify(dl, "Erasing flash", 0, 0); + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + MXL862XX_SB_PDI_CTRL_WR); + if (ret < 0) + goto write_err; + + for (i =3D 0; i < MXL862XX_FW_HDR_SIZE / 2; i++) { + word =3D fw->data[i * 2] | + ((u16)fw->data[i * 2 + 1] << 8); + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, word); + if (ret < 0) + goto write_err; + } + + ret =3D mxl862xx_sb_pdi_reset(priv); + if (ret < 0) + goto write_err; + + /* the byte count in STAT triggers the erase */ + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, + MXL862XX_FW_HDR_SIZE); + if (ret < 0) + goto write_err; + + /* ACK is byte count + 1 */ + ret =3D mxl862xx_sb_pdi_poll_stat(priv, MXL862XX_FW_HDR_SIZE + 1, + MXL862XX_FW_ACK_TIMEOUT_MS); + if (ret) { + dev_err(&priv->mdiodev->dev, + "flash: header ACK failed: %pe\n", ERR_PTR(ret)); + return ret; + } + + /* Step 5: wait for erase to complete */ + ret =3D mxl862xx_sb_pdi_poll_stat(priv, 0, + MXL862XX_FW_ERASE_TIMEOUT_MS); + if (ret) { + dev_err(&priv->mdiodev->dev, + "flash: erase timeout: %pe\n", ERR_PTR(ret)); + return ret; + } + + /* Step 6: transfer payload */ + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + MXL862XX_SB_PDI_CTRL_WR); + if (ret < 0) + goto write_err; + + while (idx < payload_size) { + if (idx + 1 < payload_size) { + fdata =3D payload[idx] | + ((u16)payload[idx + 1] << 8); + idx +=3D 2; + data_written +=3D 2; + } else { + fdata =3D payload[idx]; + idx++; + data_written++; + } + + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, fdata); + if (ret < 0) + goto write_err; + word_idx++; + + if (idx >=3D payload_size) { + ret =3D mxl862xx_sb_pdi_flush_slice(priv, data_written); + break; + } + + /* Half-bank boundary: switch to SB1 address */ + if (word_idx =3D=3D MXL862XX_FW_BANK_HALF) { + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + MXL862XX_SB_PDI_CTRL_RST); + if (ret < 0) + goto write_err; + + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_ADDR, + MXL862XX_FW_SB1_ADDR); + if (ret < 0) + goto write_err; + + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + MXL862XX_SB_PDI_CTRL_WR); + if (ret < 0) + goto write_err; + } else if (word_idx >=3D MXL862XX_FW_BANK_SLICE) { + ret =3D mxl862xx_sb_pdi_flush_slice(priv, data_written); + if (ret) { + dev_err(&priv->mdiodev->dev, + "flash: write timeout at %u/%u: %pe\n", + idx, payload_size, ERR_PTR(ret)); + return ret; + } + word_idx =3D 0; + data_written =3D 0; + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + MXL862XX_SB_PDI_CTRL_WR); + if (ret < 0) + goto write_err; + + if (time_after(jiffies, next_notify)) { + mxl862xx_flash_notify(dl, "Flashing", idx, + payload_size); + next_notify =3D jiffies + msecs_to_jiffies(500); + } + } + } + + if (ret) { + dev_err(&priv->mdiodev->dev, + "flash: final write timeout: %pe\n", ERR_PTR(ret)); + goto end_magic; + } + + mxl862xx_flash_notify(dl, "Flashing", payload_size, payload_size); + goto end_magic; + +write_err: + dev_err(&priv->mdiodev->dev, "flash: SMDIO write failed: %pe\n", + ERR_PTR(ret)); +end_magic: + /* reboot MCUboot even after a failed transfer */ + mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, + MXL862XX_SB_PDI_END); + msleep(MXL862XX_FW_REBOOT_DELAY_MS); + + return ret; +} + +int mxl862xx_devlink_info_get(struct dsa_switch *ds, + struct devlink_info_req *req, + struct netlink_ext_ack *extack) +{ + struct mxl862xx_priv *priv =3D ds->priv; + char buf[16]; + int ret; + + snprintf(buf, sizeof(buf), "%04X", priv->asic_id); + ret =3D devlink_info_version_fixed_put(req, + DEVLINK_INFO_VERSION_GENERIC_ASIC_ID, + buf); + if (ret) + return ret; + + snprintf(buf, sizeof(buf), "%u", priv->asic_rev); + ret =3D devlink_info_version_fixed_put(req, + DEVLINK_INFO_VERSION_GENERIC_ASIC_REV, + buf); + if (ret) + return ret; + + snprintf(buf, sizeof(buf), "%u.%u.%u", + priv->fw_version.major, priv->fw_version.minor, + priv->fw_version.revision); + + ret =3D devlink_info_version_running_put(req, "fw", buf); + if (ret) + return ret; + + /* boots this image from its own flash: stored =3D=3D running */ + return devlink_info_version_stored_put(req, "fw", buf); +} + +int mxl862xx_devlink_flash_update(struct dsa_switch *ds, + struct devlink_flash_update_params *params, + struct netlink_ext_ack *extack) +{ + struct mxl862xx_priv *priv =3D ds->priv; + struct mxl862xx_reprobe_work *rw; + struct dsa_port *dp; + u32 payload_size; + int ret, i; + + if (params->component) { + NL_SET_ERR_MSG_MOD(extack, "component is not supported"); + return -EOPNOTSUPP; + } + + ret =3D mxl862xx_flash_validate(priv, params->fw, &payload_size); + if (ret) { + NL_SET_ERR_MSG_MOD(extack, "firmware image validation failed"); + 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); + + 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 cannot reopen them during the flash. The + * conduit belongs to the MAC driver and is only closed. + */ + rtnl_lock(); + dsa_switch_for_each_user_port(dp, ds) { + if (dp->user) { + dev_close(dp->user); + netif_device_detach(dp->user); + } + } + dsa_switch_for_each_cpu_port(dp, ds) + dev_close(dp->conduit); + /* The bridge defers the STP state changes triggered by closing + * the ports; let them reach the firmware while it is still alive. + */ + switchdev_deferred_process(); + rtnl_unlock(); + + mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); + priv->block_host =3D true; + mutex_unlock(&priv->mdiodev->bus->mdio_lock); + + set_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags); + cancel_delayed_work_sync(&priv->stats_work); + cancel_work_sync(&priv->crc_err_work); + for (i =3D 0; i < ds->num_ports; i++) + cancel_work_sync(&priv->ports[i].host_flood_work); + + ret =3D mxl862xx_flash_firmware(priv, params->fw, payload_size, + ds->devlink); + if (ret) + NL_SET_ERR_MSG_MOD(extack, "firmware transfer failed"); + + /* The reprobe below re-reads and logs the new version. */ + + mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); + priv->skip_teardown =3D true; + mutex_unlock(&priv->mdiodev->bus->mdio_lock); + + /* Hand the reprobe to a self-contained work, scheduled last. Doing it + * from a work (rather than a kthread spawned here) avoids both the + * hung-task splat of a thread parked across the flash and the -EINTR + * that kthread_create() returns if the devlink command was Ctrl-C'd. + * Its module and device references are already held above. + */ + rw =3D kzalloc_obj(*rw); + if (!rw) { + dev_err(ds->dev, + "flash: out of memory for reprobe; reload the driver to restore operati= on\n"); + put_device(ds->dev); + module_put(THIS_MODULE); + return ret ? ret : -ENOMEM; + } + INIT_WORK(&rw->work, mxl862xx_reprobe_work_fn); + rw->dev =3D ds->dev; + schedule_work(&rw->work); + + return ret; +} diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-fw.h b/drivers/net/dsa/mxl86= 2xx/mxl862xx-fw.h new file mode 100644 index 000000000000..e96db19b2888 --- /dev/null +++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __MXL862XX_FW_H +#define __MXL862XX_FW_H + +#include + +struct mxl862xx_priv; + +int mxl862xx_devlink_info_get(struct dsa_switch *ds, + struct devlink_info_req *req, + struct netlink_ext_ack *extack); +int mxl862xx_devlink_flash_update(struct dsa_switch *ds, + struct devlink_flash_update_params *params, + struct netlink_ext_ack *extack); + +#endif /* __MXL862XX_FW_H */ diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-host.c b/drivers/net/dsa/mxl= 862xx/mxl862xx-host.c index 6e582caea1fa..66b388eed0ce 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c @@ -15,6 +15,7 @@ #include #include #include "mxl862xx.h" +#include "mxl862xx-cmd.h" #include "mxl862xx-host.h" =20 #define CTRL_BUSY_MASK BIT(15) @@ -340,6 +341,16 @@ int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 = cmd, void *_data, =20 mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); =20 + if (priv->skip_teardown) { + ret =3D read ? -ENODEV : 0; + goto out; + } + + if (priv->block_host && cmd !=3D SYS_MISC_FW_UPDATE) { + ret =3D -EBUSY; + goto out; + } + max =3D (size + 1) / 2; =20 ret =3D mxl862xx_busy_wait(priv); diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.c b/drivers/net/dsa/mxl862xx= /mxl862xx.c index 45d237b3a40f..5d4a13beed1a 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c @@ -21,6 +21,7 @@ #include "mxl862xx.h" #include "mxl862xx-api.h" #include "mxl862xx-cmd.h" +#include "mxl862xx-fw.h" #include "mxl862xx-host.h" #include "mxl862xx-phylink.h" =20 @@ -71,6 +72,13 @@ static const struct ethtool_rmon_hist_range mxl862xx_rmo= n_ranges[] =3D { #define MXL862XX_READY_TIMEOUT_MS 10000 #define MXL862XX_READY_POLL_MS 100 =20 +/* Chip ID registers, read via SYS_MISC_REG_RD */ +#define MXL862XX_CHIPID_L 0xc0d28884 +#define MXL862XX_CHIPID_M 0xc0d28888 +#define MXL862XX_CHIPID_L_PNUML GENMASK(15, 12) +#define MXL862XX_CHIPID_M_PNUMM GENMASK(11, 0) +#define MXL862XX_CHIPID_M_VERSION GENMASK(14, 12) + #define MXL862XX_TCM_INST_SEL 0xe00 #define MXL862XX_TCM_CBS 0xe12 #define MXL862XX_TCM_EBS 0xe13 @@ -222,6 +230,35 @@ static int mxl862xx_phy_write_c45_mii_bus(struct mii_b= us *bus, int addr, return mxl862xx_phy_write_mmd(bus->priv, addr, devadd, regnum, val); } =20 +/* Read the static chip part number and version from the CHIP ID + * registers. Only possible with a running firmware, so the values are + * cached at setup and left zero when the switch is in rescue mode. + */ +static int mxl862xx_read_chip_id(struct mxl862xx_priv *priv) +{ + struct mxl862xx_sys_reg_rw reg =3D {}; + u16 chipid_l, chipid_m; + int ret; + + reg.addr =3D cpu_to_le32(MXL862XX_CHIPID_L); + ret =3D MXL862XX_API_READ(priv, SYS_MISC_REG_RD, reg); + if (ret) + return ret; + chipid_l =3D le32_to_cpu(reg.val); + + reg.addr =3D cpu_to_le32(MXL862XX_CHIPID_M); + ret =3D MXL862XX_API_READ(priv, SYS_MISC_REG_RD, reg); + if (ret) + return ret; + chipid_m =3D le32_to_cpu(reg.val); + + priv->asic_id =3D FIELD_GET(MXL862XX_CHIPID_L_PNUML, chipid_l) | + FIELD_GET(MXL862XX_CHIPID_M_PNUMM, chipid_m) << 4; + priv->asic_rev =3D FIELD_GET(MXL862XX_CHIPID_M_VERSION, chipid_m); + + return 0; +} + static int mxl862xx_wait_ready(struct dsa_switch *ds) { struct mxl862xx_sys_fw_image_version ver =3D {}; @@ -254,6 +291,11 @@ static int mxl862xx_wait_ready(struct dsa_switch *ds) priv->fw_version.major =3D ver.iv_major; priv->fw_version.minor =3D ver.iv_minor; priv->fw_version.revision =3D le16_to_cpu(ver.iv_revision); + + ret =3D mxl862xx_read_chip_id(priv); + if (ret) + dev_warn(ds->dev, "failed to read chip ID: %pe\n", + ERR_PTR(ret)); return 0; =20 not_ready_yet: @@ -1572,6 +1614,11 @@ static int mxl862xx_port_mdb_del(struct dsa_switch *= ds, int port, ether_addr_copy(qparam.mac, mdb->addr); =20 ret =3D MXL862XX_API_READ(priv, MXL862XX_MAC_TABLEENTRYQUERY, qparam); + /* -ENODEV: the firmware and its MAC table are gone, nothing left + * to delete + */ + if (ret =3D=3D -ENODEV) + return 0; if (ret) return ret; =20 @@ -2086,6 +2133,8 @@ static const struct dsa_switch_ops mxl862xx_switch_op= s =3D { .get_pause_stats =3D mxl862xx_get_pause_stats, .get_rmon_stats =3D mxl862xx_get_rmon_stats, .get_stats64 =3D mxl862xx_get_stats64, + .devlink_info_get =3D mxl862xx_devlink_info_get, + .devlink_flash_update =3D mxl862xx_devlink_flash_update, }; =20 static int mxl862xx_probe(struct mdio_device *mdiodev) diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.h b/drivers/net/dsa/mxl862xx= /mxl862xx.h index 432a5f3f2e08..39535cd58706 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx.h @@ -303,6 +303,10 @@ struct mxl862xx_fw_version { * flooding) * @fw_version: cached firmware version, populated at probe and * compared with MXL862XX_FW_VER_MIN() + * @asic_id: chip part number read from the CHIP ID registers, + * reported as the devlink "asic.id" fixed version + * @asic_rev: chip version read from the CHIP ID registers, + * reported as the devlink "asic.rev" fixed version * @serdes_ports: SerDes interfaces incl. sub-interfaces in case of * 10G_QXGMII or QSGMII * @serdes_refcount: per-XPCS count of sub-ports enabled by phylink; @@ -319,6 +323,10 @@ struct mxl862xx_fw_version { * @evlan_ingress_size: per-port ingress Extended VLAN block size * @evlan_egress_size: per-port egress Extended VLAN block size * @vf_block_size: per-port VLAN Filter block size + * @block_host: reject firmware API commands (except FW_UPDATE) + * during a firmware flash + * @skip_teardown: discard firmware API commands during the teardown + * triggered by the post-flash reprobe * @stats_work: periodic work item that polls RMON hardware counte= rs * and accumulates them into 64-bit per-port stats */ @@ -329,6 +337,8 @@ struct mxl862xx_priv { unsigned long flags; u16 drop_meter; struct mxl862xx_fw_version fw_version; + u16 asic_id; + u8 asic_rev; struct mxl862xx_pcs serdes_ports[8]; int serdes_refcount[2]; struct mutex serdes_lock; @@ -337,6 +347,8 @@ struct mxl862xx_priv { u16 evlan_ingress_size; u16 evlan_egress_size; u16 vf_block_size; + bool block_host; + bool skip_teardown; struct delayed_work stats_work; }; =20 --=20 2.55.0 From nobody Sat Jul 25 03:45:46 2026 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17D6D299A87; Sat, 25 Jul 2026 02:17:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945831; cv=none; b=ES0bE4jKzN0Luir4jy3ROj1QWnw14nyI3H24kZslvvO/2/SLxOOHgvqKsWNqGGLtDpLNbg6eZ3K4V4m9HmMcsN0FoHasHHFaIlZ8CoRrxbLjpo0D0FG4Q4JRfFl38GEtMPo7vyOB3+Y6h2Xpf6Aap0eyqBkRTDS0w/FdY56dDB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945831; c=relaxed/simple; bh=NshBbPYnSwCi13qNuwa5OujpwAwLeSIop0CsCTRU0vM=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NNM9Ii1gYLFIIzNpXSCT29+QcnrHFD/+4f7eejMyifBNwMLSe24nOxZ3gsPe7SizKZnj+OaGKgGyGUfujcRV//hAGVlwooG7jMpLUJnsKYxyI2YUEaIdkfp5n3EqOIeecbgoPSpUs2QNKw0M7uBC3LG3Kl2OlSce/2AhYtcwUmU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.99) (envelope-from ) id 1wnRwj-000000002kk-2y7q; Sat, 25 Jul 2026 02:17:01 +0000 Date: Sat, 25 Jul 2026 03:16:58 +0100 From: Daniel Golle To: Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Daniel Golle , Andrew Lunn , Vladimir Oltean , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 4/5] net: dsa: mxl862xx: recover switch stuck in MCUboot rescue mode Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. The same probe tells three cases apart without touching C45: a running firmware (probe continues normally), a switch in MCUboot (enter rescue mode), and a switch that does not answer at all -- absent, unpowered, or misdescribed in the device tree (wrong address or bus, or a reset GPIO with inverted polarity) -- which fails probe cleanly with -ENODEV instead of a CRC-error storm. 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. It is drained back to a clean ready state by feeding the outstanding byte count, which can take minutes, so it runs from a background work item off the devlink flash path; until it finishes, devlink dev info reports no version and devlink dev flash returns -EBUSY. 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 --- v5: - detect the switch state from the value MCUboot publishes in the SB PDI STAT register (loader ready, wedged download, or running firmware), confirming a live console loader with a register-read challenge, instead of trusting a bare SMDIO scratch write - fail probe with -ENODEV over SB PDI when the switch does not respond at all -- absent, unpowered, or misdescribed in the device tree -- instead of letting the clause-45 API flood the log with CRC errors - drain a wedged interrupted download back to a clean ready state from a background work item so the multi-minute recovery never holds the devlink instance lock, and refuse devlink dev info and flash until it is ready - report the null firmware version as the stored version too, matching the running/stored reporting of the previous patch - do not report asic.id/asic.rev in rescue mode as the CHIP ID registers are unreadable without firmware; recovery tools match on the driver name and the "0.0.0" version instead (follows the numeric asic.id change in the previous patch) - move the devlink documentation into its own patch v4: - log a distinct diagnostic when rescue mode detection fails on an SMDIO bus error instead of silently treating it as "not in rescue mode" - clear the rescue_mode flag under the MDIO bus lock, following the flag write locking in the previous patch v3: - report the canonical null version "0.0.0" instead of "mcuboot-rescue" so that version-comparing update tools like fwupd offer any available release as an upgrade for recovery - check the rescue_mode flag under the MDIO bus lock, following the block_host/skip_teardown change in the previous patch v2: new patch, allowing recovery from a failed or interrupted update without having to use a special recovery OS image (Andrew Lunn) drivers/net/dsa/mxl862xx/mxl862xx-fw.c | 334 +++++++++++++++++++- 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 | 67 +++- drivers/net/dsa/mxl862xx/mxl862xx.h | 12 + 6 files changed, 408 insertions(+), 18 deletions(-) diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-fw.c b/drivers/net/dsa/mxl86= 2xx/mxl862xx-fw.c index cde00e5583ee..d28ceb98cd56 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx-fw.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.c @@ -27,9 +27,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 -> end of transfer / finalise + * RDREG 0xe2c0 host -> register-read command (| index), see below * * Console flash path (STAT=3D0xc55c) - mxl862xx_flash_firmware(): * @@ -63,6 +65,36 @@ * EXACTLY 0. A count larger than r_remain underflows the 32-bit counter= and * wedges the loader until a power cycle. Hence: * - never send a slice/chunk count larger than what is outstanding; + * - 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 spinning in the slice = loop + * holding STAT=3D0 (no magic). Feed single 1-byte chunks (one DATA word= + + * STAT=3D1) until r_remain reaches 0, then STAT=3DEND; the loader final= ises the + * (now corrupt) image and re-arms READY for a clean reflash. + * + * Register-read challenge (non-destructive liveness proof): + * DATA :=3D 0x7c23 (marker); STAT :=3D 0xe2c0|idx + * -> loader returns a runtime word in DATA and re-arms STAT=3D0xc55c. + * The reply source is loader BSS, not a chip id; used only to prove a l= ive + * 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 n= ot + * 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 multi-minute 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 MCUboo= t. + * Rescue identity is by SB PDI behaviour only (mxl862xx_rescue_mode_d= etect). + * - The SMDIO PHY address and the 0xe1xx offsets are OTP-configurable; = derive + * them from the DT binding, do not assume fixed values. */ =20 #include @@ -94,8 +126,15 @@ =20 /* 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 RDR= EG */ + +/* 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 =20 /* Firmware transfer geometry */ #define MXL862XX_FW_HDR_SIZE 20 @@ -110,6 +149,7 @@ #define MXL862XX_FW_WRITE_TIMEOUT_MS 120000 #define MXL862XX_FW_REBOOT_DELAY_MS 5000 #define MXL862XX_FW_REPROBE_DELAY_MS 500 +#define MXL862XX_RESCUE_READY_TIMEOUT_MS 1000 =20 static int mxl862xx_sb_pdi_reset(struct mxl862xx_priv *priv) { @@ -170,6 +210,242 @@ static void mxl862xx_flash_notify(struct devlink *dl,= const char *status, devlink_flash_update_status_notify(dl, status, NULL, done, total); } =20 +/* Byte-count of each chunk fed to the loader during drain. It MUST be 1: = the + * loader only lets us observe "counter =3D=3D 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). Steppi= ng by + * 1 walks the counter through every value and is guaranteed to land on ze= ro + * 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 f= or + * odd-sized images (see Step 6). + */ +#define MXL862XX_DRAIN_CHUNK_BYTES 1 + +/* Poll STAT while draining a stuck download: 0 means "feed the next chunk= ", + * READY means the loader left the receive loop and re-armed its command l= oop, + * anything else is a transient (the count being consumed) - BUSY past the + * window means the counter has hit zero and the loader is finalising. + */ +enum { MXL862XX_DRAIN_FEED, MXL862XX_DRAIN_READY, MXL862XX_DRAIN_BUSY }; +static int mxl862xx_sb_pdi_poll_drain(struct mxl862xx_priv *priv, + unsigned long timeout_ms) +{ + unsigned long timeout =3D jiffies + msecs_to_jiffies(timeout_ms); + int ret; + + do { + ret =3D mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_STAT); + if (ret < 0) + return ret; + if ((u16)ret =3D=3D MXL862XX_SB_PDI_READY) + return MXL862XX_DRAIN_READY; + if ((u16)ret =3D=3D 0) + return MXL862XX_DRAIN_FEED; + usleep_range(50, 150); + } while (time_before(jiffies, timeout)); + + return MXL862XX_DRAIN_BUSY; +} + +/* Recover a switch whose SB PDI download was interrupted mid-transfer - t= he + * host died after MCUboot began erasing flash, whether it aborted mid era= se or + * mid image-write, both end up in the same place: the payload receive loo= p. + * There the loader publishes STAT=3D0, 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. T= he + * image size died with the host, so we feed single-byte chunks (see + * MXL862XX_DRAIN_CHUNK_BYTES) to walk the counter to zero without underfl= ow, + * then send END. The loader runs its (failed) checksum and either re-arms + * READY or, if a valid image survived in flash, boots it. Returns 0 when = READY + * is reached (the caller can flash), 1 when the loader booted instead (the + * switch is recovered but the intended image was not written), <0 on erro= r. + * 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 =3D &priv->mdiodev->dev; + /* Bound: twice the loader's 16 MiB image cap, one byte per chunk. */ + u32 max_chunks =3D 2u * (16u << 20) / MXL862XX_DRAIN_CHUNK_BYTES; + u32 chunk =3D 0; + int ret; + + dev_warn(dev, "flash: draining interrupted download\n"); + + while (chunk < max_chunks) { + /* Teardown can interrupt this minutes-long drain. */ + if (test_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags)) + return -ECANCELED; + + ret =3D mxl862xx_sb_pdi_poll_drain(priv, 2000); + if (ret < 0) + return ret; + if (ret =3D=3D MXL862XX_DRAIN_READY) + return 0; + if (ret =3D=3D MXL862XX_DRAIN_BUSY) + break; + + /* Feed one zero byte; reset cleared the write latch. */ + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + MXL862XX_SB_PDI_CTRL_WR); + if (ret < 0) + return ret; + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, 0x0000); + if (ret < 0) + return ret; + ret =3D mxl862xx_sb_pdi_reset(priv); + if (ret < 0) + return ret; + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, + MXL862XX_DRAIN_CHUNK_BYTES); + if (ret < 0) + return ret; + chunk++; + cond_resched(); + } + + if (chunk >=3D max_chunks) { + dev_err(dev, + "flash: interrupted download did not drain after %u chunks\n", + chunk); + return -ETIMEDOUT; + } + + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, + MXL862XX_SB_PDI_END); + if (ret < 0) + return ret; + + return mxl862xx_sb_pdi_poll_stat(priv, MXL862XX_SB_PDI_READY, + MXL862XX_FW_ACK_TIMEOUT_MS); +} + +/* Background self-heal: drain a wedged download back to READY off the dev= link + * flash path, so the minutes-long recovery never holds the devlink lock. + * Scheduled from probe; publishes rescue_ready on success. + */ +void mxl862xx_rescue_heal_work_fn(struct work_struct *work) +{ + struct mxl862xx_priv *priv =3D + container_of(work, struct mxl862xx_priv, rescue_heal_work); + struct device *dev =3D &priv->mdiodev->dev; + int ret; + + dev_info(dev, "recovering interrupted download in background\n"); + ret =3D mxl862xx_rescue_drain(priv); + if (test_bit(MXL862XX_FLAG_WORK_STOPPED, &priv->flags)) + return; + if (!ret) { + WRITE_ONCE(priv->rescue_ready, true); + dev_info(dev, "recovery complete, ready to flash\n"); + } +} + +/* Detect MCUboot rescue mode over clause-22 SMDIO alone, so the caller ca= n 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); STAT then classifies the state, poked destructively o= nly + * when 0, the one value a running firmware never holds: + * + * - 0xc33c: flashless loop, ready. + * - 0xc55c: console loop, if the register-read challenge is serviced. + * - other non-zero: running firmware, left unpoked. + * - 0: wedged receive loop, if a 1-byte slice-advance drains back to 0. + * + * Return: MXL862XX_IN_RESCUE, MXL862XX_NOT_RESCUE, or negative (-ENODEV/S= MDIO). + */ +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. */ + priv->rescue_ready =3D false; + + /* Presence: a live chip latches the scratch write, an absent one floats.= */ + a =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_ADDR, + MXL862XX_SB_PDI_PROBE_A); + if (a < 0) + return a; + d =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, + MXL862XX_SB_PDI_PROBE_D); + if (d < 0) + return d; + a =3D mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_ADDR); + if (a < 0) + return a; + d =3D mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_DATA); + if (d < 0) + return d; + if ((u16)a !=3D MXL862XX_SB_PDI_PROBE_A || + (u16)d !=3D MXL862XX_SB_PDI_PROBE_D) + return -ENODEV; + + ret =3D mxl862xx_sb_pdi_reset(priv); + if (ret < 0) + return ret; + + stat =3D mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_STAT); + if (stat < 0) + return stat; + + /* Flashless-download loop: unambiguous ready magic, leave it alone. */ + if ((u16)stat =3D=3D MXL862XX_SB_PDI_DL_READY) { + priv->rescue_ready =3D true; + return MXL862XX_IN_RESCUE; + } + + /* 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 =3D=3D MXL862XX_SB_PDI_READY) { + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, + MXL862XX_SB_PDI_RDREG_MARK); + if (ret < 0) + return ret; + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, + MXL862XX_SB_PDI_RDREG); + if (ret < 0) + return ret; + rb =3D mxl862xx_sb_pdi_poll_stat(priv, MXL862XX_SB_PDI_READY, + MXL862XX_RESCUE_READY_TIMEOUT_MS); + dat =3D mxl862xx_smdio_read(priv, MXL862XX_SB_PDI_DATA); + if (dat < 0) + return dat; + mxl862xx_sb_pdi_reset(priv); + if (!rb && (u16)dat !=3D MXL862XX_SB_PDI_RDREG_MARK) { + priv->rescue_ready =3D true; + return MXL862XX_IN_RESCUE; + } + return -ENODEV; + } + + /* Any other non-zero value is a running firmware, not a loader. */ + if (stat) + return MXL862XX_NOT_RESCUE; + + /* STAT =3D=3D 0: a wedged receive loop consumes a 1-byte slice-advance b= ack + * to 0 (feed one DATA word first, like a drain chunk). + */ + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_CTRL, + MXL862XX_SB_PDI_CTRL_WR); + if (ret < 0) + return ret; + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_DATA, 0x0000); + if (ret < 0) + return ret; + ret =3D mxl862xx_sb_pdi_reset(priv); + if (ret < 0) + return ret; + ret =3D mxl862xx_smdio_write(priv, MXL862XX_SB_PDI_STAT, 1); + if (ret < 0) + return ret; + rb =3D mxl862xx_sb_pdi_poll_stat(priv, 0, MXL862XX_RESCUE_READY_TIMEOUT_M= S); + if (!rb) + return MXL862XX_IN_RESCUE; + + return -ENODEV; +} + /* Post-flash reprobe. Runs from a self-contained heap work (not a kthread= and * not the devlink caller's context): kthread_create() in the caller conte= xt * fails -EINTR if the devlink command was Ctrl-C'd, and schedule_work() c= annot. @@ -270,13 +546,15 @@ static int mxl862xx_flash_firmware(struct mxl862xx_pr= iv *priv, int ret, i; =20 /* Step 1: reboot the firmware into MCUboot rescue mode */ - ret =3D 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 =3D 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; + } } =20 /* Step 2: wait for bootloader ready */ @@ -449,6 +727,23 @@ int mxl862xx_devlink_info_get(struct dsa_switch *ds, char buf[16]; int ret; =20 + /* 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 =3D devlink_info_version_running_put(req, "fw", buf); + if (ret) + return ret; + return devlink_info_version_stored_put(req, "fw", buf); + } + snprintf(buf, sizeof(buf), "%04X", priv->asic_id); ret =3D devlink_info_version_fixed_put(req, DEVLINK_INFO_VERSION_GENERIC_ASIC_ID, @@ -496,6 +791,13 @@ int mxl862xx_devlink_flash_update(struct dsa_switch *d= s, return ret; } =20 + /* Refuse to flash while the background self-heal is still draining. */ + 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). @@ -505,9 +807,13 @@ int mxl862xx_devlink_flash_update(struct dsa_switch *d= s, =20 get_device(ds->dev); =20 - 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); =20 /* Close ports while the firmware is still alive so the DSA * core's MDB/FDB tracking is drained, and detach user ports @@ -544,7 +850,13 @@ int mxl862xx_devlink_flash_update(struct dsa_switch *d= s, if (ret) NL_SET_ERR_MSG_MOD(extack, "firmware transfer failed"); =20 - /* The reprobe below re-reads and logs the new version. */ + if (!ret) { + mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, + MDIO_MUTEX_NESTED); + priv->rescue_mode =3D false; + mutex_unlock(&priv->mdiodev->bus->mdio_lock); + /* The reprobe below re-reads and logs the new version. */ + } =20 mutex_lock_nested(&priv->mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED); priv->skip_teardown =3D true; diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-fw.h b/drivers/net/dsa/mxl86= 2xx/mxl862xx-fw.h index e96db19b2888..7cd87c7ad871 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx-fw.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx-fw.h @@ -6,7 +6,10 @@ #include =20 struct mxl862xx_priv; +struct work_struct; =20 +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); diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-host.c b/drivers/net/dsa/mxl= 862xx/mxl862xx-host.c index 66b388eed0ce..2dbd074c0fe2 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx-host.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx-host.c @@ -16,6 +16,7 @@ #include #include "mxl862xx.h" #include "mxl862xx-cmd.h" +#include "mxl862xx-fw.h" #include "mxl862xx-host.h" =20 #define CTRL_BUSY_MASK BIT(15) @@ -346,6 +347,11 @@ int mxl862xx_api_wrap(struct mxl862xx_priv *priv, u16 = cmd, void *_data, goto out; } =20 + if (priv->rescue_mode) { + ret =3D -ENODEV; + goto out; + } + if (priv->block_host && cmd !=3D SYS_MISC_FW_UPDATE) { ret =3D -EBUSY; goto out; @@ -544,9 +550,11 @@ int mxl862xx_smdio_write(struct mxl862xx_priv *priv, u= 32 addr, u16 val) 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); } =20 void mxl862xx_host_shutdown(struct mxl862xx_priv *priv) { cancel_work_sync(&priv->crc_err_work); + cancel_work_sync(&priv->rescue_heal_work); } diff --git a/drivers/net/dsa/mxl862xx/mxl862xx-phylink.c b/drivers/net/dsa/= mxl862xx/mxl862xx-phylink.c index b689652aa9b9..a5b6940b552e 100644 --- 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 phylink_config *= config, =20 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"); diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.c b/drivers/net/dsa/mxl862xx= /mxl862xx.c index 5d4a13beed1a..9ac668c13c9e 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx.c +++ b/drivers/net/dsa/mxl862xx/mxl862xx.c @@ -664,15 +664,49 @@ static int mxl862xx_setup(struct dsa_switch *ds) int n_user_ports =3D 0, max_vlans; int ingress_finals, vid_rules; struct dsa_port *dp; - int ret, i; + int ret, i, rescue; =20 - ret =3D mxl862xx_reset(priv); - if (ret) - return ret; + /* 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 =3D mxl862xx_rescue_mode_detect(priv); + if (rescue < 0) + return rescue; =20 - ret =3D mxl862xx_wait_ready(ds); - if (ret) - return ret; + if (rescue =3D=3D MXL862XX_NOT_RESCUE) { + ret =3D mxl862xx_reset(priv); + if (ret) + return ret; + + ret =3D mxl862xx_wait_ready(ds); + if (ret) { + /* the reset may only now have triggered rescue mode */ + rescue =3D mxl862xx_rescue_mode_detect(priv); + if (rescue < 0) + return rescue; + if (rescue =3D=3D MXL862XX_NOT_RESCUE) + return ret; + } + } + + priv->rescue_mode =3D 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 backgr= ound\n"); + queue_work(system_long_wq, &priv->rescue_heal_work); + } + return 0; + } =20 mutex_init(&priv->serdes_lock); for (i =3D 0; i < ARRAY_SIZE(priv->serdes_ports); i++) @@ -757,11 +791,21 @@ static int mxl862xx_port_state(struct dsa_switch *ds,= int port, bool enable) static int mxl862xx_port_enable(struct dsa_switch *ds, int port, struct phy_device *phydev) { + struct mxl862xx_priv *priv =3D ds->priv; + + if (priv->rescue_mode) + return 0; + return mxl862xx_port_state(ds, port, true); } =20 static void mxl862xx_port_disable(struct dsa_switch *ds, int port) { + struct mxl862xx_priv *priv =3D 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); } @@ -1379,6 +1423,12 @@ static int mxl862xx_port_setup(struct dsa_switch *ds= , int port) bool is_cpu_port =3D dsa_port_is_cpu(dp); int ret; =20 + /* 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 =3D mxl862xx_port_state(ds, port, false); if (ret) return ret; @@ -1675,6 +1725,9 @@ static void mxl862xx_port_stp_state_set(struct dsa_sw= itch *ds, int port, struct mxl862xx_priv *priv =3D ds->priv; int ret; =20 + if (priv->rescue_mode) + return; + switch (state) { case BR_STATE_DISABLED: param.port_state =3D cpu_to_le32(MXL862XX_STP_PORT_STATE_DISABLE); diff --git a/drivers/net/dsa/mxl862xx/mxl862xx.h b/drivers/net/dsa/mxl862xx= /mxl862xx.h index 39535cd58706..72dc31cc2b62 100644 --- a/drivers/net/dsa/mxl862xx/mxl862xx.h +++ b/drivers/net/dsa/mxl862xx/mxl862xx.h @@ -14,6 +14,10 @@ struct mxl862xx_priv; #define MXL862XX_FIRST_SERDES_PORT 9 #define MXL862XX_SERDES_SLOTS 4 =20 +/* 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 +331,11 @@ 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 f= ast, + * only clause-22 SMDIO works + * @rescue_ready: (rescue_mode) loader is at a clean READY and will = accept + * a flash; false while rescue_heal_work is draining + * @rescue_heal_work: background self-heal draining a wedged download to= READY * @stats_work: periodic work item that polls RMON hardware counte= rs * and accumulates them into 64-bit per-port stats */ @@ -334,6 +343,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 +359,8 @@ struct mxl862xx_priv { u16 vf_block_size; bool block_host; bool skip_teardown; + bool rescue_mode; + bool rescue_ready; struct delayed_work stats_work; }; =20 --=20 2.55.0 From nobody Sat Jul 25 03:45:46 2026 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C5DE1A6812; Sat, 25 Jul 2026 02:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945860; cv=none; b=nYVCEfKHF9Nol+2Vg+iCBn4yr1QDqS4V+VUFQ5tmvII+zKd3blfC7Te4bbjuOhTKOf6C0MBOMzzG4dYNkzaJrgLFWHf/Lc9COG05HcRyEDtbBmKm6ASOuD1cbG+wJK9iWQvZGK2/AoE5K3xXdh4lhpHuJiXGxLW0Xw+g1fCvKJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784945860; c=relaxed/simple; bh=mRoIgPi4xqc6YB82bZxJdGCTWM3VUVTC4H+B9KPyXKg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EKFTwifEoQF6JP1kxD0Fz9ggy1zxc+cngQZK28gQdCoS706G1HS71CrmkDWs0Az9JjLP3VMUwqforaRwcl9TP4sWLZRC55xfSAX8364xifdSUezeMpaO9ubdHgQQT3B2eykUrRh5FcRlC0c3NqqHXCXolfD+5ekNInZqh9rs5Do= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.99) (envelope-from ) id 1wnRxF-000000002lc-2oWG; Sat, 25 Jul 2026 02:17:33 +0000 Date: Sat, 25 Jul 2026 03:17:30 +0100 From: Daniel Golle To: Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Daniel Golle , Andrew Lunn , Vladimir Oltean , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v5 5/5] net: dsa: mxl862xx: document devlink flash and info support Message-ID: <3a85832b8584543241bc9fe382fcb9849b78bd01.1784945329.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Describe the devlink info versions and the flash update behaviour, including the MCUboot rescue mode recovery, in a dedicated file under Documentation/networking/devlink/ and link it from the index. Add the new file to the driver's MAINTAINERS entry. Signed-off-by: Daniel Golle --- v5: new patch Documentation/networking/devlink/index.rst | 1 + Documentation/networking/devlink/mxl862xx.rst | 63 +++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 65 insertions(+) create mode 100644 Documentation/networking/devlink/mxl862xx.rst diff --git a/Documentation/networking/devlink/index.rst b/Documentation/net= working/devlink/index.rst index 4745148fecf4..058999d0dc56 100644 --- a/Documentation/networking/devlink/index.rst +++ b/Documentation/networking/devlink/index.rst @@ -94,6 +94,7 @@ parameters, info versions, and other features it supports. mlx5 mlxsw mv88e6xxx + mxl862xx netdevsim nfp octeontx2 diff --git a/Documentation/networking/devlink/mxl862xx.rst b/Documentation/= networking/devlink/mxl862xx.rst new file mode 100644 index 000000000000..b3e9f7d4d496 --- /dev/null +++ b/Documentation/networking/devlink/mxl862xx.rst @@ -0,0 +1,63 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +mxl862xx devlink support +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This document describes the devlink features implemented by the +``mxl862xx`` device driver. + +Info versions +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The ``mxl862xx`` driver reports the following versions + +.. list-table:: devlink info versions implemented + :widths: 5 5 5 85 + + * - Name + - Type + - Example + - Description + * - ``asic.id`` + - fixed + - 8628 + - The chip part number read from the CHIP ID registers. Not + reported for a switch sitting in MCUboot rescue mode as the + registers are only accessible with a running firmware. + * - ``asic.rev`` + - fixed + - 0 + - The chip version read from the CHIP ID registers. Not reported + in MCUboot rescue mode either. + * - ``fw`` + - running, stored + - 1.0.70 + - Version of the firmware running on the switch, reported as both + running and stored since the switch boots it from its own flash. + In MCUboot rescue mode nothing is reported while an interrupted + download is still being recovered in the background; once the + loader is ready to accept a new image the version is reported (as + both running and stored), which is the signal that a flash will be + accepted. It reads "0.0.0" when the switch came up straight into + MCUboot without ever running firmware. + +Flash update +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The ``mxl862xx`` driver implements support for ``devlink dev flash``. +The signed firmware image is transferred to the switch over the same +MDIO bus which is also used to manage the switch, then verified and +installed by the MCUboot bootloader running on the switch. All ports +of the switch are closed for the duration of the update and the driver +reprobes the switch after it has rebooted into the new firmware. A +complete flash and reprobe cycle takes about one minute. + +A switch stuck in MCUboot rescue mode, e.g. after an interrupted +update, is registered without user ports. If the previous download was +interrupted mid-transfer the loader is wedged; the driver drains it +back to a clean ready state in the background, which can easily take +more than 10 minutes. During that recovery ``devlink dev info`` reports +no firmware version and ``devlink dev flash`` returns ``-EBUSY``. +Once the loader is ready the firmware version appears and flashing a +firmware image through the regular update flow recovers the switch. diff --git a/MAINTAINERS b/MAINTAINERS index 60cff00953dc..3a55ed2bad9c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16107,6 +16107,7 @@ M: Daniel Golle L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/dsa/maxlinear,mxl862xx.yaml +F: Documentation/networking/devlink/mxl862xx.rst F: drivers/net/dsa/mxl862xx/ F: net/dsa/tag_mxl862xx.c =20 --=20 2.55.0