sfc: support devlink flash
Subsystems (5)
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
Documentation/networking/devlink/sfc.rst | 16 +- 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 | 111 ++++- drivers/net/ethernet/sfc/mcdi.h | 22 +- drivers/net/ethernet/sfc/net_driver.h | 2 + 11 files changed, 797 insertions(+), 25 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 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 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 | 111 ++++++++++++++++++++++++++------ drivers/net/ethernet/sfc/mcdi.h | 22 ++++++- 3 files changed, 117 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 +91 -20
195 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 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 */
PATCH 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.
--- Documentation/networking/devlink/sfc.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
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.
kernel test robot
build botRe: [PATCH net-next 2/4] sfc: extend NVRAM MCDI handlers
In reply to [email protected]kernel test robot noticed the following build warnings:
Hi,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/edward-cree-amd-com/sfc-parse-headers-of-devlink-flash-images/20250207-081201 base: net-next/main patch link: https://lore.kernel.org/r/6ad7f4af17c2566ddc53fd247a0d0a790eff02ae.1738881614.git.ecree.xilinx%40gmail.com patch subject: [PATCH net-next 2/4] sfc: extend NVRAM MCDI handlers config: i386-randconfig-002-20250207 (https://download.01.org/0day-ci/archive/20250208/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250208/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/net/ethernet/sfc/mcdi.c:2195:12: warning: 'efx_mcdi_nvram_read' defined but not used [-Wunused-function]
2195 | static int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
| ^~~~~~~~~~~~~~~~~~~
vim +/efx_mcdi_nvram_read +2195 drivers/net/ethernet/sfc/mcdi.c
45a3fd55acc898 Ben Hutchings 2012-11-28 2194
45a3fd55acc898 Ben Hutchings 2012-11-28 @2195 static int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
45a3fd55acc898 Ben Hutchings 2012-11-28 2196 loff_t offset, u8 *buffer, size_t length)
45a3fd55acc898 Ben Hutchings 2012-11-28 2197 {
5fb1beeceab857 Bert Kenward 2019-01-16 2198 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_READ_IN_V2_LEN);
45a3fd55acc898 Ben Hutchings 2012-11-28 2199 MCDI_DECLARE_BUF(outbuf,
45a3fd55acc898 Ben Hutchings 2012-11-28 2200 MC_CMD_NVRAM_READ_OUT_LEN(EFX_MCDI_NVRAM_LEN_MAX));
45a3fd55acc898 Ben Hutchings 2012-11-28 2201 size_t outlen;
45a3fd55acc898 Ben Hutchings 2012-11-28 2202 int rc;
45a3fd55acc898 Ben Hutchings 2012-11-28 2203
45a3fd55acc898 Ben Hutchings 2012-11-28 2204 MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_TYPE, type);
45a3fd55acc898 Ben Hutchings 2012-11-28 2205 MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_OFFSET, offset);
45a3fd55acc898 Ben Hutchings 2012-11-28 2206 MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_LENGTH, length);
5fb1beeceab857 Bert Kenward 2019-01-16 2207 MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_V2_MODE,
5fb1beeceab857 Bert Kenward 2019-01-16 2208 MC_CMD_NVRAM_READ_IN_V2_DEFAULT);
45a3fd55acc898 Ben Hutchings 2012-11-28 2209
45a3fd55acc898 Ben Hutchings 2012-11-28 2210 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_READ, inbuf, sizeof(inbuf),
45a3fd55acc898 Ben Hutchings 2012-11-28 2211 outbuf, sizeof(outbuf), &outlen);
45a3fd55acc898 Ben Hutchings 2012-11-28 2212 if (rc)
1e0b8120b2aef5 Edward Cree 2013-05-31 2213 return rc;
45a3fd55acc898 Ben Hutchings 2012-11-28 2214
45a3fd55acc898 Ben Hutchings 2012-11-28 2215 memcpy(buffer, MCDI_PTR(outbuf, NVRAM_READ_OUT_READ_BUFFER), length);
45a3fd55acc898 Ben Hutchings 2012-11-28 2216 return 0;
45a3fd55acc898 Ben Hutchings 2012-11-28 2217 }
45a3fd55acc898 Ben Hutchings 2012-11-28 2218 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Edward Cree
maintainerRe: [PATCH net-next 2/4] sfc: extend NVRAM MCDI handlers
Quoted 1 line · kernel test robot
Quoted 1 line
Quoted 1 line
drivers/net/ethernet/sfc/mcdi.c:2195:12: warning: 'efx_mcdi_nvram_read' defined but not used [-Wunused-function]
Looks like the caller of this fn is only built #ifdef CONFIG_SFC_MTD,
so this fn should be under the same guard.
Will fix in v2.