sfc: support devlink flash
Subsystems (5)
v2 cover sfc: support devlink flash
From: Edward Cree <[email protected]>
Allow upgrading device firmware on Solarflare NICs through standard tools.
Edward Cree (4):
sfc: parse headers of devlink flash images
sfc: extend NVRAM MCDI handlers
sfc: deploy devlink flash images to NIC over MCDI
sfc: document devlink flash support
Changed in v2:
* Fix build error (unused function) when CONFIG_SFC_MTD=n (kernel test robot)
* Update Kconfig description for CONFIG_SFC_MTD
v1: https://lore.kernel.org/netdev/[email protected]/
Documentation/networking/devlink/sfc.rst | 16 +- drivers/net/ethernet/sfc/Kconfig | 5 +- drivers/net/ethernet/sfc/Makefile | 2 +- drivers/net/ethernet/sfc/ef10.c | 7 +- drivers/net/ethernet/sfc/efx_common.c | 1 + drivers/net/ethernet/sfc/efx_devlink.c | 13 + drivers/net/ethernet/sfc/efx_reflash.c | 514 +++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_reflash.h | 20 + drivers/net/ethernet/sfc/fw_formats.h | 114 +++++ drivers/net/ethernet/sfc/mcdi.c | 115 ++++- drivers/net/ethernet/sfc/mcdi.h | 22 +- drivers/net/ethernet/sfc/net_driver.h | 2 + 12 files changed, 804 insertions(+), 27 deletions(-) create mode 100644 drivers/net/ethernet/sfc/efx_reflash.c create mode 100644 drivers/net/ethernet/sfc/efx_reflash.h create mode 100644 drivers/net/ethernet/sfc/fw_formats.h
PATCH v2 1/4 sfc: parse headers of devlink flash images
From: Edward Cree <[email protected]>
This parsing is necessary to obtain the metadata which will be
used in a subsequent patch to write the image to the device.
--- drivers/net/ethernet/sfc/Makefile | 2 +- drivers/net/ethernet/sfc/efx_devlink.c | 13 ++ drivers/net/ethernet/sfc/efx_reflash.c | 289 +++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_reflash.h | 20 ++ drivers/net/ethernet/sfc/fw_formats.h | 114 ++++++++++ 5 files changed, 437 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/sfc/efx_reflash.c create mode 100644 drivers/net/ethernet/sfc/efx_reflash.h create mode 100644 drivers/net/ethernet/sfc/fw_formats.h
drivers/net/ethernet/sfc/Makefile +1 -1
@@ -7,7 +7,7 @@ sfc-y += efx.o efx_common.o efx_channels.o nic.o \ mcdi_functions.o mcdi_filters.o mcdi_mon.o \ ef100.o ef100_nic.o ef100_netdev.o \ ef100_ethtool.o ef100_rx.o ef100_tx.o \ - efx_devlink.o + efx_devlink.o efx_reflash.o sfc-$(CONFIG_SFC_MTD) += mtd.o sfc-$(CONFIG_SFC_SRIOV) += sriov.o ef10_sriov.o ef100_sriov.o ef100_rep.o \ mae.o tc.o tc_bindings.o tc_counters.o \
drivers/net/ethernet/sfc/efx_devlink.c +13 -0
@@ -19,6 +19,7 @@#include "mae.h" #include "ef100_rep.h" #endif +#include "efx_reflash.h" struct efx_devlink {struct efx_nic *efx;
@@ -615,7 +616,19 @@ static int efx_devlink_info_get(struct devlink *devlink,return 0 ; } +static int efx_devlink_flash_update (struct devlink *devlink, +struct devlink_flash_update_params *params, +struct netlink_ext_ack *extack) +{ +struct efx_devlink *devlink_private =devlink_priv (devlink); +struct efx_nic *efx = devlink_private->efx; + +return efx_reflash_flash_firmware (efx, params->fw, extack); +} +static const struct devlink_ops sfc_devlink_ops = { + .supported_flash_update_params =0 , + .flash_update = efx_devlink_flash_update, .info_get = efx_devlink_info_get, };
drivers/net/ethernet/sfc/efx_reflash.c new file +289 -0
289 lines not on this page · raw message
drivers/net/ethernet/sfc/efx_reflash.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/**************************************************************************** +* Driver for AMD network controllers and boards +* Copyright (C) 2025, Advanced Micro Devices, Inc. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation, incorporated herein by reference. +*/ + +#ifndef _EFX_REFLASH_H +#define _EFX_REFLASH_H + +#include "net_driver.h" +#include <linux/firmware.h> + +int efx_reflash_flash_firmware (struct efx_nic *efx,const struct firmware *fw, +struct netlink_ext_ack *extack); + +#endif /* _EFX_REFLASH_H */
drivers/net/ethernet/sfc/fw_formats.h new file +114 -0
114 lines not on this page · raw message
PATCH v2 2/4 sfc: extend NVRAM MCDI handlers
In reply to [email protected]From: Edward Cree <[email protected]>
Support variable write-alignment, and background updates. The latter
allows other MCDI to continue while the device is processing an MC_CMD_NVRAM_UPDATE_FINISH, since this can take a long time owing to e.g. cryptographic signature verification.
Expose these handlers in mcdi.h, and build them even when
CONFIG_SFC_MTD=n, so they can be used for devlink flash in a subsequent patch.
--- drivers/net/ethernet/sfc/ef10.c | 7 +- drivers/net/ethernet/sfc/mcdi.c | 115 ++++++++++++++++++++++++++------ drivers/net/ethernet/sfc/mcdi.h | 22 +++++- 3 files changed, 121 insertions(+), 23 deletions(-)
drivers/net/ethernet/sfc/ef10.c +5 -2
@@ -3501,7 +3501,7 @@ static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,MCDI_DECLARE_BUF (inbuf,MC_CMD_NVRAM_METADATA_IN_LEN );MCDI_DECLARE_BUF (outbuf,MC_CMD_NVRAM_METADATA_OUT_LENMAX );const struct efx_ef10_nvram_type_info *info; -size_t size, erase_size, outlen; +size_t size, erase_size, write_size, outlen;int type_idx =0 ;bool protected;int rc;
@@ -3516,7 +3516,8 @@ static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,if (info->port !=efx_port_num (efx))return -ENODEV ; - rc =efx_mcdi_nvram_info (efx, type, &size, &erase_size, &protected); + rc =efx_mcdi_nvram_info (efx, type, &size, &erase_size, &write_size, + &protected);if (rc)return rc; if (protected &&
@@ -3561,6 +3562,8 @@ static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,if (!erase_size) part->common.mtd.flags |=MTD_NO_ERASE ; + part->common.mtd.writesize = write_size; +return 0 ; }
drivers/net/ethernet/sfc/mcdi.c +95 -20
205 lines not on this page · raw message
drivers/net/ethernet/sfc/mcdi.h +21 -1
@@ -392,7 +392,7 @@ int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq);int efx_mcdi_nvram_types (struct efx_nic *efx,u32 *nvram_types_out);int efx_mcdi_nvram_info (struct efx_nic *efx,unsigned int type,size_t *size_out,size_t *erase_size_out, -bool *protected_out); +size_t *write_size_out,bool *protected_out);int efx_new_mcdi_nvram_test_all (struct efx_nic *efx); int efx_mcdi_nvram_metadata(struct efx_nic *efx, unsigned int type, u32 *subtype, u16 version[4], char *desc,
@@ -424,6 +424,26 @@ static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; }static inline void efx_mcdi_mon_remove (struct efx_nic *efx) {}#endif +int efx_mcdi_nvram_update_start (struct efx_nic *efx,unsigned int type); +int efx_mcdi_nvram_write (struct efx_nic *efx,unsigned int type, +loff_t offset,const u8 *buffer,size_t length); +int efx_mcdi_nvram_erase (struct efx_nic *efx,unsigned int type, +loff_t offset,size_t length); +int efx_mcdi_nvram_metadata (struct efx_nic *efx,unsigned int type, +u32 *subtype,u16 version[4 ],char *desc, +size_t descsize); + +enum efx_update_finish_mode { +EFX_UPDATE_FINISH_WAIT , +EFX_UPDATE_FINISH_BACKGROUND , +EFX_UPDATE_FINISH_POLL , +EFX_UPDATE_FINISH_ABORT , +}; + +int efx_mcdi_nvram_update_finish (struct efx_nic *efx,unsigned int type, +enum efx_update_finish_mode mode); +int efx_mcdi_nvram_update_finish_polled (struct efx_nic *efx,unsigned int type); +#ifdef CONFIG_SFC_MTD int efx_mcdi_mtd_read (struct mtd_info *mtd,loff_t start,size_t len,size_t *retlen,u8 *buffer);
PATCH v2 4/4 sfc: document devlink flash support
In reply to [email protected]From: Edward Cree <[email protected]>
Update the information in sfc's devlink documentation including
support for firmware update with devlink flash.
Also update the help text for CONFIG_SFC_MTD, as it is no longer
strictly required for firmware updates.
--- Documentation/networking/devlink/sfc.rst | 16 +++++++++++++++- drivers/net/ethernet/sfc/Kconfig | 5 +++-- 2 files changed, 18 insertions(+), 3 deletions(-)
Documentation/networking/devlink/sfc.rst +15 -1
@@ -5,7 +5,7 @@ sfc devlink support =================== This document describes the devlink features implemented by the ``sfc`` -device driver for the ef100 device. +device driver for the ef10 and ef100 devices. Info versions =============
@@ -18,6 +18,10 @@ The ``sfc`` driver reports the following versions * - Name - Type - Description + * - ``fw.bundle_id`` + - stored + - Version of the firmware "bundle" image that was last used to update + multiple components. * - ``fw.mgmt.suc`` - running - For boards where the management function is split between multiple
@@ -55,3 +59,13 @@ The ``sfc`` driver reports the following versions * - ``fw.uefi`` - running - UEFI driver version (No UNDI support). + +Flash Update +============ + +The ``sfc`` driver implements support for flash update using the +``devlink-flash`` interface. It supports updating the device flash using a +combined flash image ("bundle") that contains multiple components (on ef10, +typically ``fw.mgmt``, ``fw.app``, ``fw.exprom`` and ``fw.uefi``). + +The driver does not support any overwrite mask flags.
drivers/net/ethernet/sfc/Kconfig +3 -2
@@ -38,8 +38,9 @@ config SFC_MTD default y help This exposes the on-board flash and/or EEPROM as MTD devices - (e.g. /dev/mtd1). This is required to update the firmware or - the boot configuration under Linux. + (e.g. /dev/mtd1). This is required to update the boot + configuration under Linux, or use some older userland tools to + update the firmware. config SFC_MCDI_MON bool "Solarflare SFC9100-family hwmon support" depends on SFC && HWMON && !(SFC=y && HWMON=m)
PATCH v2 3/4 sfc: deploy devlink flash images to NIC over MCDI
In reply to [email protected]From: Edward Cree <[email protected]>
Use MC_CMD_NVRAM_* wrappers to write the firmware to the partition
identified from the image header.
--- drivers/net/ethernet/sfc/efx_common.c | 1 + drivers/net/ethernet/sfc/efx_reflash.c | 231 ++++++++++++++++++++++++- drivers/net/ethernet/sfc/net_driver.h | 2 + 3 files changed, 231 insertions(+), 3 deletions(-)
drivers/net/ethernet/sfc/efx_common.c +1 -0
@@ -1003,6 +1003,7 @@ int efx_init_struct(struct efx_nic *efx, struct pci_dev *pci_dev)INIT_LIST_HEAD (&efx->vf_reps);INIT_WORK (&efx->mac_work, efx_mac_work);init_waitqueue_head (&efx->flush_wq); +mutex_init (&efx->reflash_mutex); efx->tx_queues_per_channel =1 ; efx->rxq_entries =EFX_DEFAULT_DMAQ_SIZE ;
drivers/net/ethernet/sfc/efx_reflash.c +228 -3
249 lines not on this page · raw message
drivers/net/ethernet/sfc/net_driver.h +2 -0
@@ -1006,6 +1006,7 @@ struct efx_mae;* @dl_port: devlink port associated with the PF * @mem_bar: The BAR that is mapped into membase. * @reg_base: Offset from the start of the bar to the function control window. +* @reflash_mutex: Mutex for serialising firmware reflash operations. * @monitor_work: Hardware monitor workitem * @biu_lock: BIU (bus interface unit) lock * @last_irq_cpu: Last CPU to handle a possible test interrupt. This
@@ -1191,6 +1192,7 @@ struct efx_nic {struct devlink_port *dl_port;unsigned int mem_bar;u32 reg_base; +struct mutex reflash_mutex;/* The following fields may be written more often */
Jiri Pirko
maintainerRe: [PATCH v2 net-next 4/4] sfc: document devlink flash support
In reply to [email protected]Quoted 27 lines · Mon, Feb 10, 2025 at 12:25:45PM +0100, [email protected] wrote:
From: Edward Cree <[email protected]>
Update the information in sfc's devlink documentation including support for firmware update with devlink flash.
Also update the help text forCONFIG_SFC_MTD, as it is no longer strictly required for firmware updates.Signed-off-by Edward Cree <[email protected]>---
Documentation/networking/devlink/sfc.rst| 16 +++++++++++++++-drivers/net/ethernet/sfc/Kconfig| 5 +++--2 files changed, 18 insertions(+), 3 deletions(-)Documentation/networking/devlink/sfc.rst +0
-0@@ -5,7 +5,7 @@ sfc devlink support===================
This document describes the devlink features implemented by the ``sfc``
Documentation/networking/devlink/sfc.rst +1
-1-device driver for the ef100 device. +device driver for the ef10 and ef100 devices.Info versions
=============
Documentation/networking/devlink/sfc.rst The ``sfc`` driver reports the following versions · line 21
Quoted 4 lines
Documentation/networking/devlink/sfc.rst +1
-0@@ -18,6 +18,10 @@ The ``sfc`` driver reports the following versions * - Name - Type - Description + * - ``fw.bundle_id``
Why "id"? It is the bundle version, isn't it. In that case just "bundle" would be fine I guess...
Quoted 36 lines
Documentation/networking/devlink/sfc.rst +13
-0+ - stored + - Version of the firmware "bundle" image that was last used to update + multiple components. * - ``fw.mgmt.suc`` - running - For boards where the management function is split between multiple@@ -55,3 +59,13 @@ The ``sfc`` driver reports the following versions * - ``fw.uefi`` - running - UEFI driver version (No UNDI support). + +Flash Update +============ + +The ``sfc`` driver implements support for flash update using the +``devlink-flash`` interface. It supports updating the device flash using a +combined flash image ("bundle") that contains multiple components (on ef10, +typically ``fw.mgmt``, ``fw.app``, ``fw.exprom`` and ``fw.uefi``). + +The driver does not support any overwrite mask flags.drivers/net/ethernet/sfc/Kconfig +3
-2@@ -38,8 +38,9 @@ config SFC_MTD default y help This exposes the on-board flash and/or EEPROM as MTD devices - (e.g. /dev/mtd1). This is required to update the firmware or - the boot configuration under Linux. + (e.g. /dev/mtd1). This is required to update the boot + configuration under Linux, or use some older userland tools to + update the firmware.config
SFC_MCDI_MONbool "Solarflare SFC9100-family hwmon support" depends on SFC && HWMON && !(SFC=y && HWMON=m)
Edward Cree
maintainerRe: [PATCH v2 net-next 4/4] sfc: document devlink flash support
Quoted 11 lines · Jiri Pirko
Documentation/networking/devlink/sfc.rst The ``sfc`` driver reports the following versions · line 21
Quoted 7 lines · Mon, Feb 10, 2025 at 12:25:45PM +0100, [email protected] wrote:
Info versions
=============Documentation/networking/devlink/sfc.rst +1
-0@@ -18,6 +18,10 @@ The ``sfc`` driver reports the following versions * - Name - Type - Description + * - ``fw.bundle_id``Why "id"? It is the bundle version, isn't it. In that case just "bundle" would be fine I guess...
bundle_id comes from DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID in
include/net/devlink.h, which git blame tells me was added by Jacob Keller in 2020 as a generalisation of a similar name in nfp.[1]
Its use in sfc was added[2] by Alejandro Lucero in 2023 but seems to
have been left out of the documentation at that time.
The present patch series is merely documenting the name that already
exists, not adding it. Changing it might break existing scripts, and in any case would affect more drivers than just sfc (it is used by i40e, ice, and nfp).
CCing Jacob in case he has anything to add on why that name was chosen.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c90977a3c227
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=14743ddd2495
Jiri Pirko
maintainerRe: [PATCH v2 net-next 4/4] sfc: document devlink flash support
Quoted 13 lines · Mon, Feb 10, 2025 at 03:50:18PM +0100, [email protected] wrote:
Quoted 11 lines · Jiri Pirko
Documentation/networking/devlink/sfc.rst The ``sfc`` driver reports the following versions · line 21
Quoted 7 lines · Mon, Feb 10, 2025 at 12:25:45PM +0100, [email protected] wrote:
Info versions
=============Documentation/networking/devlink/sfc.rst +1
-0@@ -18,6 +18,10 @@ The ``sfc`` driver reports the following versions * - Name - Type - Description + * - ``fw.bundle_id``Why "id"? It is the bundle version, isn't it. In that case just "bundle" would be fine I guess...
Quoted 9 lines
bundle_idcomes fromDEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_IDininclude/net/devlink.h, which git blame tells me was added by Jacob Keller in 2020 as a generalisation of a similar name in nfp.[1] Its use in sfc was added[2] by Alejandro Lucero in 2023 but seems to have been left out of the documentation at that time.
The present patch series is merely documenting the name that already exists, not adding it. Changing it might break existing scripts, and in any case would affect more drivers than just sfc (it is used by i40e, ice, and nfp).
Yeah, correct. I just found out myself by accident.
Thanks!
Quoted 5 lines
CCing Jacob in case he has anything to add on why that name was chosen.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c90977a3c227
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=14743ddd2495
Re: [PATCH v2 net-next 4/4] sfc: document devlink flash support
In reply to Edward CreeQuoted 23 lines · Edward Cree
Quoted 11 lines · Jiri Pirko
Documentation/networking/devlink/sfc.rst The ``sfc`` driver reports the following versions · line 21
Quoted 7 lines · Mon, Feb 10, 2025 at 12:25:45PM +0100, [email protected] wrote:
Info versions
=============Documentation/networking/devlink/sfc.rst +1
-0@@ -18,6 +18,10 @@ The ``sfc`` driver reports the following versions * - Name - Type - Description + * - ``fw.bundle_id``Why "id"? It is the bundle version, isn't it. In that case just "bundle" would be fine I guess...
bundle_idcomes fromDEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_IDin
include/net/devlink.h, which git blame tells me was added by Jacob Keller in 2020 as a generalisation of a similar name in nfp.[1]
Its use in sfc was added[2] by Alejandro Lucero in 2023 but seems to
have been left out of the documentation at that time.
The present patch series is merely documenting the name that already
exists, not adding it. Changing it might break existing scripts, and in any case would affect more drivers than just sfc (it is used by i40e, ice, and nfp).
Quoted 5 lines
CCing Jacob in case he has anything to add on why that name was chosen.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c90977a3c227
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=14743ddd2495
Yep. The versions were discussed extensively at [1] and I ultimately settled on re-using fw.bundle_id as a generic name rather than having nfp use bundle_id but everyone else use bundle [2]
[1]
https://lore.kernel.org/netdev/[email protected]/
[2]
https://lore.kernel.org/netdev/[email protected]/
I don't think we can really change this at this point given this is effectively part of uABI.
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 10 Feb 2025 11:25:41 +0000 you wrote:
From: Edward Cree <[email protected]>
Allow upgrading device firmware on Solarflare NICs through standard tools.
Edward Cree (4):
sfc: parse headers of devlink flash images
sfc: extend NVRAM MCDI handlers
sfc: deploy devlink flash images to NIC over MCDI
sfc: document devlink flash support[...]
Here is the summary with links:
- [v2,net-next,1/4] sfc: parse headers of devlink flash images
https://git.kernel.org/netdev/net-next/c/fd118a77ede7 - [v2,net-next,2/4] sfc: extend NVRAM MCDI handlers https://git.kernel.org/netdev/net-next/c/d41987e906e7 - [v2,net-next,3/4] sfc: deploy devlink flash images to NIC over MCDI https://git.kernel.org/netdev/net-next/c/3ed63980ae79 - [v2,net-next,4/4] sfc: document devlink flash support https://git.kernel.org/netdev/net-next/c/5ea73bf3c40d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html