svn commit: r309569 - in stable: 10/sys/dev/cxgbe 10/tools/tools/cxgbetool 11/sys/dev/cxgbe 11/tools/tools/cxgbetool

John Baldwin jhb at FreeBSD.org
Mon Dec 5 23:02:27 UTC 2016


Author: jhb
Date: Mon Dec  5 23:02:26 2016
New Revision: 309569
URL: https://svnweb.freebsd.org/changeset/base/309569

Log:
  MFC 306821,306823: Permit updating firmware config file in flash.
  
  306821:
  cxgbe(4): Add an ioctl to copy a firmware config file to the card's flash.
  
  306823:
  cxgbetool: Add a loadcfg subcommand to allow a user to upload a firmware
  configuration file to the card.

Modified:
  stable/10/sys/dev/cxgbe/t4_ioctl.h
  stable/10/sys/dev/cxgbe/t4_main.c
  stable/10/tools/tools/cxgbetool/cxgbetool.8
  stable/10/tools/tools/cxgbetool/cxgbetool.c
Directory Properties:
  stable/10/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/sys/dev/cxgbe/t4_ioctl.h
  stable/11/sys/dev/cxgbe/t4_main.c
  stable/11/tools/tools/cxgbetool/cxgbetool.8
  stable/11/tools/tools/cxgbetool/cxgbetool.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/10/sys/dev/cxgbe/t4_ioctl.h
==============================================================================
--- stable/10/sys/dev/cxgbe/t4_ioctl.h	Mon Dec  5 23:02:02 2016	(r309568)
+++ stable/10/sys/dev/cxgbe/t4_ioctl.h	Mon Dec  5 23:02:26 2016	(r309569)
@@ -56,6 +56,7 @@ enum {
 	T4_SET_SCHED_QUEUE,             /* set queue class */
 	T4_GET_TRACER,			/* get information about a tracer */
 	T4_SET_TRACER,			/* program a tracer */
+	T4_LOAD_CFG,			/* copy a config file to card's flash */
 };
 
 struct t4_reg {
@@ -344,4 +345,5 @@ struct t4_tracer {
     struct t4_sched_queue)
 #define CHELSIO_T4_GET_TRACER	_IOWR('f', T4_GET_TRACER, struct t4_tracer)
 #define CHELSIO_T4_SET_TRACER	_IOW('f', T4_SET_TRACER, struct t4_tracer)
+#define CHELSIO_T4_LOAD_CFG	_IOW('f', T4_LOAD_CFG, struct t4_data)
 #endif

Modified: stable/10/sys/dev/cxgbe/t4_main.c
==============================================================================
--- stable/10/sys/dev/cxgbe/t4_main.c	Mon Dec  5 23:02:02 2016	(r309568)
+++ stable/10/sys/dev/cxgbe/t4_main.c	Mon Dec  5 23:02:26 2016	(r309569)
@@ -538,6 +538,7 @@ static int set_tcb_rpl(struct sge_iq *, 
     struct mbuf *);
 static int get_sge_context(struct adapter *, struct t4_sge_context *);
 static int load_fw(struct adapter *, struct t4_data *);
+static int load_cfg(struct adapter *, struct t4_data *);
 static int read_card_mem(struct adapter *, int, struct t4_mem_range *);
 static int read_i2c(struct adapter *, struct t4_i2c_data *);
 #ifdef TCP_OFFLOAD
@@ -8452,6 +8453,38 @@ done:
 	return (rc);
 }
 
+static int
+load_cfg(struct adapter *sc, struct t4_data *cfg)
+{
+	int rc;
+	uint8_t *cfg_data = NULL;
+
+	rc = begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4ldcf");
+	if (rc)
+		return (rc);
+
+	if (cfg->len == 0) {
+		/* clear */
+		rc = -t4_load_cfg(sc, NULL, 0);
+		goto done;
+	}
+
+	cfg_data = malloc(cfg->len, M_CXGBE, M_WAITOK);
+	if (cfg_data == NULL) {
+		rc = ENOMEM;
+		goto done;
+	}
+
+	rc = copyin(cfg->data, cfg_data, cfg->len);
+	if (rc == 0)
+		rc = -t4_load_cfg(sc, cfg_data, cfg->len);
+
+	free(cfg_data, M_CXGBE);
+done:
+	end_synchronized_op(sc, 0);
+	return (rc);
+}
+
 #define MAX_READ_BUF_SIZE (128 * 1024)
 static int
 read_card_mem(struct adapter *sc, int win, struct t4_mem_range *mr)
@@ -9009,6 +9042,9 @@ t4_ioctl(struct cdev *dev, unsigned long
 	case CHELSIO_T4_SET_TRACER:
 		rc = t4_set_tracer(sc, (struct t4_tracer *)data);
 		break;
+	case CHELSIO_T4_LOAD_CFG:
+		rc = load_cfg(sc, (struct t4_data *)data);
+		break;
 	default:
 		rc = ENOTTY;
 	}

Modified: stable/10/tools/tools/cxgbetool/cxgbetool.8
==============================================================================
--- stable/10/tools/tools/cxgbetool/cxgbetool.8	Mon Dec  5 23:02:02 2016	(r309568)
+++ stable/10/tools/tools/cxgbetool/cxgbetool.8	Mon Dec  5 23:02:26 2016	(r309569)
@@ -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

Modified: stable/10/tools/tools/cxgbetool/cxgbetool.c
==============================================================================
--- stable/10/tools/tools/cxgbetool/cxgbetool.c	Mon Dec  5 23:02:02 2016	(r309568)
+++ stable/10/tools/tools/cxgbetool/cxgbetool.c	Mon Dec  5 23:02:26 2016	(r309569)
@@ -95,6 +95,8 @@ usage(FILE *fp)
 	    "\tfilter list                         list all filters\n"
 	    "\tfilter mode [<match>] ...           get/set global filter mode\n"
 	    "\ti2c <port> <devaddr> <addr> [<len>] read from i2c device\n"
+	    "\tloadcfg <fw-config.txt>             install configuration file\n"
+	    "\tloadcfg clear                       remove configuration file\n"
 	    "\tloadfw <fw-image.bin>               install firmware\n"
 	    "\tmemdump <addr> <len>                dump a memory range\n"
 	    "\tmodinfo <port> [raw]                optics/cable information\n"
@@ -1835,6 +1837,49 @@ loadfw(int argc, const char *argv[])
 }
 
 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))
 {
 	int rc;
@@ -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);


More information about the svn-src-all mailing list