From 2099002b6204ac99b6754eb11f2a2287f889f2ee Mon Sep 17 00:00:00 2001 From: Navdeep Parhar Date: Fri, 7 Oct 2016 19:13:29 +0000 Subject: [PATCH] cxgbetool: Add a loadcfg subcommand to allow a user to upload a firmware configuration file to the card. --- tools/tools/cxgbetool/cxgbetool.8 | 13 +++++++++ tools/tools/cxgbetool/cxgbetool.c | 47 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/tools/tools/cxgbetool/cxgbetool.8 b/tools/tools/cxgbetool/cxgbetool.8 index 16b0ce63f35..bdc4eb7ea75 100644 --- a/tools/tools/cxgbetool/cxgbetool.8 +++ b/tools/tools/cxgbetool/cxgbetool.8 @@ -56,6 +56,10 @@ .It .Nm Ar nexus Cm i2c Ar port_id devaddr addr Op Ar len .It +.Nm Ar nexus Cm loadcfg Ar fw-config.txt +.It +.Nm Ar nexus Cm loadcfg clear +.It .Nm Ar nexus Cm loadfw Ar fw-image.bin .It .Nm Ar nexus Cm memdump Ar addr len @@ -353,6 +357,15 @@ Delete filter that is at the given index. .It Cm filter Cm list List all filters programmed into the hardware. .It Cm i2c Ar port_id devaddr addr Op Ar len +.It Cm loadcfg Ar fw-config.txt +Install the firmware configuration file contained in +.Ar fw-config.txt +to the card. +Set hw.cxgbe.config_file="flash" in loader.conf to get +.Xr cxgbe 4 +to use the on-flash configuration. +.It Cm loadcfg Cm clear +Erase configuration file from the card. .It Cm loadfw Ar fw-image.bin Install the firmware contained in .Ar fw-image.bin diff --git a/tools/tools/cxgbetool/cxgbetool.c b/tools/tools/cxgbetool/cxgbetool.c index 7d9a4c96ee1..71f07dfefc0 100644 --- a/tools/tools/cxgbetool/cxgbetool.c +++ b/tools/tools/cxgbetool/cxgbetool.c @@ -95,6 +95,8 @@ usage(FILE *fp) "\tfilter list list all filters\n" "\tfilter mode [] ... get/set global filter mode\n" "\ti2c [] read from i2c device\n" + "\tloadcfg install configuration file\n" + "\tloadcfg clear remove configuration file\n" "\tloadfw install firmware\n" "\tmemdump dump a memory range\n" "\tmodinfo [raw] optics/cable information\n" @@ -1834,6 +1836,49 @@ loadfw(int argc, const char *argv[]) return (rc); } +static int +loadcfg(int argc, const char *argv[]) +{ + int rc, fd; + struct t4_data data = {0}; + const char *fname = argv[0]; + struct stat st = {0}; + + if (argc != 1) { + warnx("loadcfg: incorrect number of arguments."); + return (EINVAL); + } + + if (strcmp(fname, "clear") == 0) + return (doit(CHELSIO_T4_LOAD_CFG, &data)); + + fd = open(fname, O_RDONLY); + if (fd < 0) { + warn("open(%s)", fname); + return (errno); + } + + if (fstat(fd, &st) < 0) { + warn("fstat"); + close(fd); + return (errno); + } + + data.len = st.st_size; + data.len &= ~3; /* Clip off to make it a multiple of 4 */ + data.data = mmap(0, data.len, PROT_READ, MAP_PRIVATE, fd, 0); + if (data.data == MAP_FAILED) { + warn("mmap"); + close(fd); + return (errno); + } + + rc = doit(CHELSIO_T4_LOAD_CFG, &data); + munmap(data.data, data.len); + close(fd); + return (rc); +} + static int read_mem(uint32_t addr, uint32_t len, void (*output)(uint32_t *, uint32_t)) { @@ -2732,6 +2777,8 @@ run_cmd(int argc, const char *argv[]) rc = sched_class(argc, argv); else if (!strcmp(cmd, "sched-queue")) rc = sched_queue(argc, argv); + else if (!strcmp(cmd, "loadcfg")) + rc = loadcfg(argc, argv); else { rc = EINVAL; warnx("invalid command \"%s\"", cmd);