Skip to content

Commit 7a74156

Browse files
Dirk van der Merwedavem330
authored andcommitted
nfp: implement firmware flashing
Firmware flashing takes around 60s (specified to not take more than 70s). Prevent hogging the RTNL lock in this time and make use of the longer timeout for the NSP command. The timeout is set to 2.5 * 70 seconds. We only allow flashing the firmware from reprs or PF netdevs. VFs do not have an app reference. Signed-off-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 87a2380 commit 7a74156

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <linux/interrupt.h>
4848
#include <linux/pci.h>
4949
#include <linux/ethtool.h>
50+
#include <linux/firmware.h>
5051

5152
#include "nfpcore/nfp.h"
5253
#include "nfpcore/nfp_nsp.h"
@@ -1269,6 +1270,57 @@ static int nfp_net_set_channels(struct net_device *netdev,
12691270
return nfp_net_set_num_rings(nn, total_rx, total_tx);
12701271
}
12711272

1273+
static int
1274+
nfp_net_flash_device(struct net_device *netdev, struct ethtool_flash *flash)
1275+
{
1276+
const struct firmware *fw;
1277+
struct nfp_app *app;
1278+
struct nfp_nsp *nsp;
1279+
struct device *dev;
1280+
int err;
1281+
1282+
if (flash->region != ETHTOOL_FLASH_ALL_REGIONS)
1283+
return -EOPNOTSUPP;
1284+
1285+
app = nfp_app_from_netdev(netdev);
1286+
if (!app)
1287+
return -EOPNOTSUPP;
1288+
1289+
dev = &app->pdev->dev;
1290+
1291+
nsp = nfp_nsp_open(app->cpp);
1292+
if (IS_ERR(nsp)) {
1293+
err = PTR_ERR(nsp);
1294+
dev_err(dev, "Failed to access the NSP: %d\n", err);
1295+
return err;
1296+
}
1297+
1298+
err = request_firmware_direct(&fw, flash->data, dev);
1299+
if (err)
1300+
goto exit_close_nsp;
1301+
1302+
dev_info(dev, "Please be patient while writing flash image: %s\n",
1303+
flash->data);
1304+
dev_hold(netdev);
1305+
rtnl_unlock();
1306+
1307+
err = nfp_nsp_write_flash(nsp, fw);
1308+
if (err < 0) {
1309+
dev_err(dev, "Flash write failed: %d\n", err);
1310+
goto exit_rtnl_lock;
1311+
}
1312+
dev_info(dev, "Finished writing flash image\n");
1313+
1314+
exit_rtnl_lock:
1315+
rtnl_lock();
1316+
dev_put(netdev);
1317+
release_firmware(fw);
1318+
1319+
exit_close_nsp:
1320+
nfp_nsp_close(nsp);
1321+
return err;
1322+
}
1323+
12721324
static const struct ethtool_ops nfp_net_ethtool_ops = {
12731325
.get_drvinfo = nfp_net_get_drvinfo,
12741326
.get_link = ethtool_op_get_link,
@@ -1279,6 +1331,7 @@ static const struct ethtool_ops nfp_net_ethtool_ops = {
12791331
.get_sset_count = nfp_net_get_sset_count,
12801332
.get_rxnfc = nfp_net_get_rxnfc,
12811333
.set_rxnfc = nfp_net_set_rxnfc,
1334+
.flash_device = nfp_net_flash_device,
12821335
.get_rxfh_indir_size = nfp_net_get_rxfh_indir_size,
12831336
.get_rxfh_key_size = nfp_net_get_rxfh_key_size,
12841337
.get_rxfh = nfp_net_get_rxfh,
@@ -1304,6 +1357,7 @@ const struct ethtool_ops nfp_port_ethtool_ops = {
13041357
.get_strings = nfp_port_get_strings,
13051358
.get_ethtool_stats = nfp_port_get_stats,
13061359
.get_sset_count = nfp_port_get_sset_count,
1360+
.flash_device = nfp_net_flash_device,
13071361
.set_dump = nfp_app_set_dump,
13081362
.get_dump_flag = nfp_app_get_dump_flag,
13091363
.get_dump_data = nfp_app_get_dump_data,

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ enum nfp_nsp_cmd {
9696
SPCODE_FW_LOAD = 6, /* Load fw from buffer, len in option */
9797
SPCODE_ETH_RESCAN = 7, /* Rescan ETHs, write ETH_TABLE to buf */
9898
SPCODE_ETH_CONTROL = 8, /* Update media config from buffer */
99+
SPCODE_NSP_WRITE_FLASH = 11, /* Load and flash image from buffer */
99100
SPCODE_NSP_SENSORS = 12, /* Read NSP sensor(s) */
100101
SPCODE_NSP_IDENTIFY = 13, /* Read NSP version */
101102
};
@@ -514,6 +515,17 @@ int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw)
514515
fw->size, NULL, 0);
515516
}
516517

518+
int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw)
519+
{
520+
/* The flash time is specified to take a maximum of 70s so we add an
521+
* additional factor to this spec time.
522+
*/
523+
u32 timeout_sec = 2.5 * 70;
524+
525+
return __nfp_nsp_command_buf(state, SPCODE_NSP_WRITE_FLASH, fw->size,
526+
fw->data, fw->size, NULL, 0, timeout_sec);
527+
}
528+
517529
int nfp_nsp_read_eth_table(struct nfp_nsp *state, void *buf, unsigned int size)
518530
{
519531
return nfp_nsp_command_buf(state, SPCODE_ETH_RESCAN, size, NULL, 0,

drivers/net/ethernet/netronome/nfp/nfpcore/nfp_nsp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ u16 nfp_nsp_get_abi_ver_minor(struct nfp_nsp *state);
4848
int nfp_nsp_wait(struct nfp_nsp *state);
4949
int nfp_nsp_device_soft_reset(struct nfp_nsp *state);
5050
int nfp_nsp_load_fw(struct nfp_nsp *state, const struct firmware *fw);
51+
int nfp_nsp_write_flash(struct nfp_nsp *state, const struct firmware *fw);
5152
int nfp_nsp_mac_reinit(struct nfp_nsp *state);
5253

5354
static inline bool nfp_nsp_has_mac_reinit(struct nfp_nsp *state)

0 commit comments

Comments
 (0)