Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Mar 2018 15:21:56 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r330653 - in head: etc/mtree include share/man/man4 share/man/man5 share/mk sys/conf sys/dev/mlx5 sys/dev/mlx5/mlx5_core sys/modules/mlx5 targets/pseudo/userland tools/build/options usr...
Message-ID:  <201803081521.w28FLudP099465@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu Mar  8 15:21:56 2018
New Revision: 330653
URL: https://svnweb.freebsd.org/changeset/base/330653

Log:
  Add kernel and userspace code to dump the firmware state of supported
  ConnectX-4/5 devices in mlx5core.
  
  The dump is obtained by reading a predefined register map from the
  non-destructive crspace, accessible by the vendor-specific PCIe
  capability (VSC). The dump is stored in preallocated kernel memory and
  managed by the mlx5tool(8), which communicates with the driver using a
  character device node.
  
  The utility allows to store the dump in format
      <address> <value>
  into a file, to reset the dump content, and to manually initiate the
  dump.
  
  A call to mlx5_fwdump() should be added at the places where a dump
  must be fetched automatically. The most likely place is right before a
  firmware reset request.
  
  Submitted by:	kib@
  MFC after:	1 week
  Sponsored by:	Mellanox Technologies

Added:
  head/share/man/man4/mlx5io.4   (contents, props changed)
  head/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5_core/mlx5_fwdump_regmaps.c   (contents, props changed)
  head/sys/dev/mlx5/mlx5io.h   (contents, props changed)
  head/tools/build/options/WITHOUT_MLX5TOOL   (contents, props changed)
  head/tools/build/options/WITH_MLX5TOOL   (contents, props changed)
  head/usr.sbin/mlx5tool/
  head/usr.sbin/mlx5tool/Makefile   (contents, props changed)
  head/usr.sbin/mlx5tool/mlx5tool.8   (contents, props changed)
  head/usr.sbin/mlx5tool/mlx5tool.c   (contents, props changed)
Modified:
  head/etc/mtree/BSD.include.dist
  head/include/Makefile
  head/share/man/man4/Makefile
  head/share/man/man5/src.conf.5
  head/share/mk/src.opts.mk
  head/sys/conf/files
  head/sys/dev/mlx5/driver.h
  head/sys/dev/mlx5/mlx5_core/mlx5_core.h
  head/sys/dev/mlx5/mlx5_core/mlx5_main.c
  head/sys/modules/mlx5/Makefile
  head/targets/pseudo/userland/Makefile.depend
  head/usr.sbin/Makefile

Modified: head/etc/mtree/BSD.include.dist
==============================================================================
--- head/etc/mtree/BSD.include.dist	Thu Mar  8 14:33:59 2018	(r330652)
+++ head/etc/mtree/BSD.include.dist	Thu Mar  8 15:21:56 2018	(r330653)
@@ -132,6 +132,8 @@
         ..
         mfi
         ..
+        mlx5
+        ..
         mmc
         ..
         mpt

Modified: head/include/Makefile
==============================================================================
--- head/include/Makefile	Thu Mar  8 14:33:59 2018	(r330652)
+++ head/include/Makefile	Thu Mar  8 15:21:56 2018	(r330653)
@@ -255,6 +255,11 @@ copies: .PHONY .META
 	${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 nvpair.h \
 	    ${SDESTDIR}${INCLUDEDIR}/sys
 .endif
+.if ${MK_MLX5TOOL} != "no"
+	cd ${SRCTOP}/sys/dev/mlx5; \
+	${INSTALL} -C ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 444 mlx5io.h \
+	    ${SDESTDIR}${INCLUDEDIR}/dev/mlx5
+.endif
 
 symlinks: .PHONY .META
 	@${ECHO} "Setting up symlinks to kernel source tree..."
@@ -384,6 +389,10 @@ symlinks: .PHONY .META
 		${INSTALL_SYMLINK} ${TAG_ARGS} ../../../sys/rpc/$$h \
 		    ${SDESTDIR}${INCLUDEDIR}/rpc; \
 	done
+.if ${MK_MLX5TOOL} != "no"
+	${INSTALL_SYMLINK} ${TAG_ARGS} ../../../../sys/dev/mlx5/mlx5io.h \
+	    ${SDESTDIR}${INCLUDEDIR}/dev/mlx5
+.endif
 
 .include <bsd.prog.mk>
 

Modified: head/share/man/man4/Makefile
==============================================================================
--- head/share/man/man4/Makefile	Thu Mar  8 14:33:59 2018	(r330652)
+++ head/share/man/man4/Makefile	Thu Mar  8 15:21:56 2018	(r330653)
@@ -928,6 +928,10 @@ MAN+=		mlx4ib.4
 MAN+=		mlx5ib.4
 .endif
 
+.if ${MK_MLX5TOOL} != "no"
+MAN+=		mlx5io.4
+.endif
+
 .if ${MK_TESTS} != "no"
 ATF=            ${SRCTOP}/contrib/atf
 .PATH:          ${ATF}/doc

Added: head/share/man/man4/mlx5io.4
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man4/mlx5io.4	Thu Mar  8 15:21:56 2018	(r330653)
@@ -0,0 +1,142 @@
+.\"
+.\" Copyright (c) 2018 Mellanox Technologies
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 20, 2018
+.Dt mlx5io 4
+.Os
+.Sh NAME
+.Nm mlx5io
+.Nd IOCTL interface to manage Connect-X 4/5 Mellanox network adapters
+.Sh SYNOPSIS
+.In dev/mlx5/mlx5io.h
+.Sh DESCRIPTION
+The
+.Nm
+interface is provided for management of the Connect-X 4 and 5 network adapters
+in the aspects not covered by the generic network configuration,
+mostly related to the PCIe attachment and internal card working.
+Interface consists of the commands, which are passed by means of
+.Xr ioctl 2
+on the file descriptor, opened from the
+.Pa /dev/mlx5ctl
+device node.
+.Pp
+The following commands are implemented:
+.Bl -tag -width indent
+.It Dv MLX5_FWDUMP_FORCE
+Take the snapshot of the firmware registers state and store it in the
+kernel buffer.
+The buffer must be empty, in other words, no dumps should be written so
+far, or existing dump cleared with the
+.Dv MLX5_FWDUMP_RESET
+command for the specified device.
+The argument for the command should point to the
+.Vt struct mlx5_fwdump_addr
+structure, containing the PCIe bus address of the device.
+.Bd -literal
+struct mlx5_fwdump_addr {
+	uint32_t domain;
+	uint8_t bus;
+	uint8_t slot;
+	uint8_t func;
+};
+.Ed
+.It Dv MLX5_FWDUMP_RESET
+Clear the stored firmware dump, preparing the kernel buffer for
+the next dump.
+The argument for the command should point to the
+.Vt struct mlx5_fwdump_addr
+structure, containing the PCIe bus address of the device.
+.It Dv MLX5_FWDUMP_GET
+Fetch the stored firmware dump into the user memory.
+The argument to the command should point to the input/output
+.Vt struct mlx5_fwdump_get
+structure.
+Its
+.Dv devaddr
+field specifies the address of the device, the
+.Dv buf
+fields points to the array of
+.Vt struct mlx5_fwdump_reg
+of records of the registers values, the size of the array is specified
+in the
+.Dv reg_cnt
+field.
+.Bd -literal
+struct mlx5_fwdump_get {
+	struct mlx5_fwdump_addr devaddr;
+	struct mlx5_fwdump_reg *buf;
+	size_t reg_cnt;
+	size_t reg_filled; /* out */
+};
+.Ed
+.Pp
+On successfull return, the
+.Dv reg_filled
+field reports the number of the
+.Dv buf
+array elements actually filled with the registers values.
+If
+.Dv buf
+contains the
+.Dv NULL
+pointer, no registers are filled, but
+.Dv reg_filled
+still contains the number of registers that should be passed for
+the complete dump.
+.Pp
+The
+.Vt struct mlx5_fwdump_reg
+element contains the address of the register in the field
+.Dv addr ,
+and its value in the field
+.Dv val .
+.Bd -literal
+struct mlx5_fwdump_reg {
+	uint32_t addr;
+	uint32_t val;
+};
+.Ed
+.El
+.Sh FILES
+The
+.Pa /dev/mlx5ctl
+.Xr devfs 5
+node is used to pass commands to the driver.
+.Sh RETURN VALUES
+If successful, the IOCTL returns zero.
+Otherwise, -1 is returned and the global variable
+.Va errno
+is set to indicate the error.
+.Sh SEE ALSO
+.Xr errno 2 ,
+.Xr ioctl 2 ,
+.Xr mlx5en 4 ,
+.Xr mlx5ib 4 ,
+.Xr mlx5tool 8
+and
+.Xr pci 9 .

Modified: head/share/man/man5/src.conf.5
==============================================================================
--- head/share/man/man5/src.conf.5	Thu Mar  8 14:33:59 2018	(r330652)
+++ head/share/man/man5/src.conf.5	Thu Mar  8 15:21:56 2018	(r330653)
@@ -436,12 +436,18 @@ Set to not build CUSE-related programs and libraries.
 .It Va WITHOUT_CXGBETOOL
 Set to not build
 .Xr cxgbetool 8
+.It Va WITHOUT_MLX5TOOL
+Set to not build
+.Xr mlx5tool 8
 .Pp
 This is a default setting on
 arm/arm, arm/armeb, arm/armv6, arm/armv7, mips/mipsel, mips/mips, mips/mips64el, mips/mips64, mips/mipsn32, mips/mipselhf, mips/mipshf, mips/mips64elhf, mips/mips64hf, powerpc/powerpc, powerpc/powerpcspe, riscv/riscv64 and riscv/riscv64sf.
 .It Va WITH_CXGBETOOL
 Set to build
 .Xr cxgbetool 8
+.It Va WITH_MLX5TOOL
+Set to build
+.Xr mlx5tool 8
 .Pp
 This is a default setting on
 amd64/amd64, arm64/aarch64, i386/i386, powerpc/powerpc64 and sparc64/sparc64.

Modified: head/share/mk/src.opts.mk
==============================================================================
--- head/share/mk/src.opts.mk	Thu Mar  8 14:33:59 2018	(r330652)
+++ head/share/mk/src.opts.mk	Thu Mar  8 15:21:56 2018	(r330653)
@@ -320,8 +320,10 @@ BROKEN_OPTIONS+=PROFILE
 .if ${__T} == "aarch64" || ${__T} == "amd64" || ${__T} == "i386" || \
     ${__T} == "powerpc64" || ${__T} == "sparc64"
 __DEFAULT_YES_OPTIONS+=CXGBETOOL
+__DEFAULT_YES_OPTIONS+=MLX5TOOL
 .else
 __DEFAULT_NO_OPTIONS+=CXGBETOOL
+__DEFAULT_NO_OPTIONS+=MLX5TOOL
 .endif
 
 .include <bsd.mkopt.mk>

Modified: head/sys/conf/files
==============================================================================
--- head/sys/conf/files	Thu Mar  8 14:33:59 2018	(r330652)
+++ head/sys/conf/files	Thu Mar  8 15:21:56 2018	(r330653)
@@ -4731,6 +4731,10 @@ dev/mlx5/mlx5_core/mlx5_fs_tree.c		optional mlx5 pci	\
 	compile-with "${OFED_C}"
 dev/mlx5/mlx5_core/mlx5_fw.c			optional mlx5 pci	\
 	compile-with "${OFED_C}"
+dev/mlx5/mlx5_core/mlx5_fwdump.c		optional mlx5 pci	\
+	compile-with "${OFED_C}"
+dev/mlx5/mlx5_core/mlx5_fwdump_regmaps.c	optional mlx5 pci	\
+	compile-with "${OFED_C}"
 dev/mlx5/mlx5_core/mlx5_health.c		optional mlx5 pci	\
 	compile-with "${OFED_C}"
 dev/mlx5/mlx5_core/mlx5_mad.c			optional mlx5 pci	\

Modified: head/sys/dev/mlx5/driver.h
==============================================================================
--- head/sys/dev/mlx5/driver.h	Thu Mar  8 14:33:59 2018	(r330652)
+++ head/sys/dev/mlx5/driver.h	Thu Mar  8 15:21:56 2018	(r330653)
@@ -615,6 +615,7 @@ struct mlx5_special_contexts {
 };
 
 struct mlx5_flow_root_namespace;
+struct mlx5_dump_data;
 struct mlx5_core_dev {
 	struct pci_dev	       *pdev;
 	/* sync pci state */
@@ -648,6 +649,7 @@ struct mlx5_core_dev {
 	struct mlx5_flow_root_namespace *sniffer_rx_root_ns;
 	struct mlx5_flow_root_namespace *sniffer_tx_root_ns;
 	u32 num_q_counter_allocated[MLX5_INTERFACE_NUMBER];
+	struct mlx5_dump_data	*dump_data;
 };
 
 enum {

Modified: head/sys/dev/mlx5/mlx5_core/mlx5_core.h
==============================================================================
--- head/sys/dev/mlx5/mlx5_core/mlx5_core.h	Thu Mar  8 14:33:59 2018	(r330652)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_core.h	Thu Mar  8 15:21:56 2018	(r330653)
@@ -80,4 +80,17 @@ void mlx5e_cleanup(void);
 
 int mlx5_rename_eq(struct mlx5_core_dev *dev, int eq_ix, char *name);
 
+int mlx5_fwdump_init(void);
+void mlx5_fwdump_fini(void);
+int mlx5_fwdump_prep(struct mlx5_core_dev *mdev);
+void mlx5_fwdump(struct mlx5_core_dev *mdev);
+void mlx5_fwdump_clean(struct mlx5_core_dev *mdev);
+
+struct mlx5_crspace_regmap {
+	uint32_t addr;
+	unsigned cnt;
+};
+
+extern struct pci_driver mlx5_core_driver;
+
 #endif /* __MLX5_CORE_H__ */

Added: head/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c	Thu Mar  8 15:21:56 2018	(r330653)
@@ -0,0 +1,308 @@
+/*-
+ * Copyright (c) 2018, Mellanox Technologies, Ltd.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+#include <dev/mlx5/driver.h>
+#include <dev/mlx5/device.h>
+#include <dev/mlx5/mlx5_core/mlx5_core.h>
+#include <dev/mlx5/mlx5io.h>
+
+extern const struct mlx5_crspace_regmap mlx5_crspace_regmap_mt4117[];
+extern const struct mlx5_crspace_regmap mlx5_crspace_regmap_mt4115[];
+extern const struct mlx5_crspace_regmap mlx5_crspace_regmap_connectx5[];
+
+struct mlx5_dump_data {
+	const struct mlx5_crspace_regmap *rege;
+	uint32_t *dump;
+	unsigned dump_size;
+	int dump_valid;
+	struct mtx dump_lock;
+};
+
+static MALLOC_DEFINE(M_MLX5_DUMP, "MLX5DUMP", "MLX5 Firmware dump");
+
+static unsigned
+mlx5_fwdump_getsize(const struct mlx5_crspace_regmap *rege)
+{
+	const struct mlx5_crspace_regmap *r;
+	unsigned sz;
+
+	for (sz = 0, r = rege; r->cnt != 0; r++)
+		sz += r->cnt;
+	return (sz);
+}
+
+static void
+mlx5_fwdump_destroy_dd(struct mlx5_dump_data *dd)
+{
+
+	mtx_destroy(&dd->dump_lock);
+	free(dd->dump, M_MLX5_DUMP);
+	free(dd, M_MLX5_DUMP);
+}
+
+int
+mlx5_fwdump_prep(struct mlx5_core_dev *mdev)
+{
+	struct mlx5_dump_data *dd;
+	int error;
+
+	error = mlx5_vsc_find_cap(mdev);
+	if (error != 0)
+		return (error);
+	dd = malloc(sizeof(struct mlx5_dump_data), M_MLX5_DUMP, M_WAITOK);
+	switch (pci_get_device(mdev->pdev->dev.bsddev)) {
+	case 0x1013:
+		dd->rege = mlx5_crspace_regmap_mt4115;
+		break;
+	case 0x1015:
+		dd->rege = mlx5_crspace_regmap_mt4117;
+		break;
+	case 0x1017:
+	case 0x1019:
+		dd->rege = mlx5_crspace_regmap_connectx5;
+		break;
+	default:
+		free(dd, M_MLX5_DUMP);
+		return (0); /* silently fail to not prevent driver attach */
+	}
+	dd->dump_size = mlx5_fwdump_getsize(dd->rege);
+	dd->dump = malloc(dd->dump_size * sizeof(uint32_t), M_MLX5_DUMP,
+	    M_WAITOK | M_ZERO);
+	dd->dump_valid = 0;
+	mtx_init(&dd->dump_lock, "mlx5dmp", NULL, MTX_DEF | MTX_NEW);
+	if (atomic_cmpset_rel_ptr((uintptr_t *)&mdev->dump_data, 0,
+	    (uintptr_t)dd) == 0)
+		mlx5_fwdump_destroy_dd(dd);
+	return (0);
+}
+
+void
+mlx5_fwdump(struct mlx5_core_dev *mdev)
+{
+	struct mlx5_dump_data *dd;
+	const struct mlx5_crspace_regmap *r;
+	uint32_t i, ri;
+	int error;
+
+	dd = (struct mlx5_dump_data *)atomic_load_acq_ptr((uintptr_t *)
+	    &mdev->dump_data);
+	if (dd == NULL)
+		return;
+	mtx_lock(&dd->dump_lock);
+	if (dd->dump_valid)
+		/* only one dump */
+		goto failed;
+
+	/* mlx5_vsc already warns, be silent. */
+	error = mlx5_vsc_lock(mdev);
+	if (error != 0)
+		goto failed;
+	error = mlx5_vsc_set_space(mdev, MLX5_VSC_DOMAIN_PROTECTED_CRSPACE);
+	if (error != 0)
+		goto unlock_vsc;
+	for (i = 0, r = dd->rege; r->cnt != 0; r++) {
+		for (ri = 0; ri < r->cnt; ri++) {
+			error = mlx5_vsc_read(mdev, r->addr + ri * 4,
+			    &dd->dump[i]);
+			if (error != 0)
+				goto unlock_vsc;
+			i++;
+		}
+	}
+	atomic_store_rel_int(&dd->dump_valid, 1);
+unlock_vsc:
+	mlx5_vsc_unlock(mdev);
+failed:
+	mtx_unlock(&dd->dump_lock);
+}
+
+void
+mlx5_fwdump_clean(struct mlx5_core_dev *mdev)
+{
+	struct mlx5_dump_data *dd;
+
+	for (;;) {
+		dd = mdev->dump_data;
+		if (dd == NULL)
+			return;
+		if (atomic_cmpset_ptr((uintptr_t *)&mdev->dump_data,
+		    (uintptr_t)dd, 0) == 1) {
+			mlx5_fwdump_destroy_dd(dd);
+			return;
+		}
+	}
+}
+
+static int
+mlx5_dbsf_to_core(const struct mlx5_fwdump_addr *devaddr,
+    struct mlx5_core_dev **mdev)
+{
+	device_t dev;
+	struct pci_dev *pdev;
+
+	dev = pci_find_dbsf(devaddr->domain, devaddr->bus, devaddr->slot,
+	    devaddr->func);
+	if (dev == NULL)
+		return (ENOENT);
+	if (device_get_devclass(dev) != mlx5_core_driver.bsdclass)
+		return (EINVAL);
+	pdev = device_get_softc(dev);
+	*mdev = pci_get_drvdata(pdev);
+	if (*mdev == NULL)
+		return (ENOENT);
+	return (0);
+}
+
+static int
+mlx5_fwdump_copyout(struct mlx5_dump_data *dd, struct mlx5_fwdump_get *fwg)
+{
+	const struct mlx5_crspace_regmap *r;
+	struct mlx5_fwdump_reg rv, *urv;
+	uint32_t i, ri;
+	int error;
+
+	if (dd == NULL)
+		return (ENOENT);
+	if (fwg->buf == NULL) {
+		fwg->reg_filled = dd->dump_size;
+		return (0);
+	}
+	if (atomic_load_acq_int(&dd->dump_valid) == 0)
+		return (ENOENT);
+
+	urv = fwg->buf;
+	for (i = 0, r = dd->rege; r->cnt != 0; r++) {
+		for (ri = 0; ri < r->cnt; ri++) {
+			if (i >= fwg->reg_cnt)
+				goto out;
+			rv.addr = r->addr + ri * 4;
+			rv.val = dd->dump[i];
+			error = copyout(&rv, urv, sizeof(rv));
+			if (error != 0)
+				return (error);
+			urv++;
+			i++;
+		}
+	}
+out:
+	fwg->reg_filled = i;
+	return (0);
+}
+
+static int
+mlx5_fwdump_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
+    struct thread *td)
+{
+	struct mlx5_core_dev *mdev;
+	struct mlx5_fwdump_get *fwg;
+	struct mlx5_fwdump_addr *devaddr;
+	struct mlx5_dump_data *dd;
+	int error;
+
+	error = 0;
+	switch (cmd) {
+	case MLX5_FWDUMP_GET:
+		if ((fflag & FREAD) == 0) {
+			error = EBADF;
+			break;
+		}
+		fwg = (struct mlx5_fwdump_get *)data;
+		devaddr = &fwg->devaddr;
+		error = mlx5_dbsf_to_core(devaddr, &mdev);
+		if (error != 0)
+			break;
+		error = mlx5_fwdump_copyout(mdev->dump_data, fwg);
+		break;
+	case MLX5_FWDUMP_RESET:
+		if ((fflag & FWRITE) == 0) {
+			error = EBADF;
+			break;
+		}
+		devaddr = (struct mlx5_fwdump_addr *)data;
+		error = mlx5_dbsf_to_core(devaddr, &mdev);
+		if (error != 0)
+			break;
+		dd = mdev->dump_data;
+		if (dd != NULL)
+			atomic_store_rel_int(&dd->dump_valid, 0);
+		else
+			error = ENOENT;
+		break;
+	case MLX5_FWDUMP_FORCE:
+		if ((fflag & FWRITE) == 0) {
+			error = EBADF;
+			break;
+		}
+		devaddr = (struct mlx5_fwdump_addr *)data;
+		error = mlx5_dbsf_to_core(devaddr, &mdev);
+		if (error != 0)
+			break;
+		mlx5_fwdump(mdev);
+		break;
+	default:
+		error = ENOTTY;
+		break;
+	}
+	return (error);
+}
+
+static struct cdevsw mlx5_fwdump_devsw = {
+	.d_version =	D_VERSION,
+	.d_ioctl =	mlx5_fwdump_ioctl,
+};
+
+static struct cdev *mlx5_fwdump_dev;
+
+int
+mlx5_fwdump_init(void)
+{
+	struct make_dev_args mda;
+	int error;
+
+	make_dev_args_init(&mda);
+	mda.mda_flags = MAKEDEV_WAITOK | MAKEDEV_CHECKNAME;
+	mda.mda_devsw = &mlx5_fwdump_devsw;
+	mda.mda_uid = UID_ROOT;
+	mda.mda_gid = GID_OPERATOR;
+	mda.mda_mode = 0640;
+	error = make_dev_s(&mda, &mlx5_fwdump_dev, "mlx5ctl");
+	return (-error);
+}
+
+void
+mlx5_fwdump_fini(void)
+{
+
+	if (mlx5_fwdump_dev != NULL)
+		destroy_dev(mlx5_fwdump_dev);
+
+}

Added: head/sys/dev/mlx5/mlx5_core/mlx5_fwdump_regmaps.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/mlx5/mlx5_core/mlx5_fwdump_regmaps.c	Thu Mar  8 15:21:56 2018	(r330653)
@@ -0,0 +1,11187 @@
+/*-
+ * Copyright (c) 2018, Mellanox Technologies, Ltd.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <dev/mlx5/driver.h>
+#include <dev/mlx5/device.h>
+#include <dev/mlx5/mlx5_core/mlx5_core.h>
+
+const struct mlx5_crspace_regmap mlx5_crspace_regmap_mt4117[] = {
+	{0x000000, 16388},
+	{0x010084, 1},
+	{0x01008c, 2},
+	{0x010180, 6},
+	{0x01019c, 9},
+	{0x010304, 1},
+	{0x0103bc, 52},
+	{0x010500, 35},
+	{0x010604, 1},
+	{0x01060c, 1},
+	{0x010624, 1},
+	{0x01062c, 1},
+	{0x010644, 1},
+	{0x01064c, 3},
+	{0x010800, 1},
+	{0x010814, 3},
+	{0x010844, 1},
+	{0x01084c, 4},
+	{0x011000, 32},
+	{0x011200, 32},
+	{0x011400, 32},
+	{0x011600, 32},
+	{0x011800, 32},
+	{0x011a00, 5},
+	{0x011a24, 1},
+	{0x011a2c, 1},
+	{0x011a34, 3},
+	{0x011a44, 1},
+	{0x011a4c, 2},
+	{0x012000, 20},
+	{0x012088, 22},
+	{0x012100, 18},
+	{0x012200, 36},
+	{0x012300, 3},
+	{0x012310, 1},
+	{0x012320, 1},
+	{0x012330, 1},
+	{0x012340, 1},
+	{0x012350, 1},
+	{0x012360, 1},
+	{0x012370, 1},
+	{0x012400, 166},
+	{0x0126a0, 1},
+	{0x012700, 32},
+	{0x012800, 1},
+	{0x012808, 1},
+	{0x012810, 1},
+	{0x012818, 1},
+	{0x012820, 1},
+	{0x012828, 1},
+	{0x012830, 1},
+	{0x012838, 1},
+	{0x012850, 1},
+	{0x012858, 1},
+	{0x012860, 1},
+	{0x012868, 1},
+	{0x012870, 1},
+	{0x012878, 1},
+	{0x012880, 1},
+	{0x012888, 1},
+	{0x012890, 5},
+	{0x012900, 10},
+	{0x012940, 6},
+	{0x012960, 6},
+	{0x012980, 5},
+	{0x012a00, 6},
+	{0x012a40, 5},
+	{0x012a80, 9},
+	{0x012ac0, 19},
+	{0x012b10, 2},
+	{0x014000, 1},
+	{0x014010, 10},
+	{0x014104, 1},
+	{0x01410c, 4},
+	{0x014200, 1},
+	{0x014210, 4},
+	{0x014300, 4},
+	{0x014400, 3},
+	{0x014410, 1},
+	{0x014444, 1},
+	{0x01444c, 4},
+	{0x014480, 2},
+	{0x014500, 35},
+	{0x014590, 1},
+	{0x014600, 32},
+	{0x014704, 1},
+	{0x01470c, 1},
+	{0x014804, 2},
+	{0x014814, 3},
+	{0x014824, 2},
+	{0x014834, 3},
+	{0x014844, 2},
+	{0x014854, 5},
+	{0x014a00, 4},
+	{0x014a14, 2},
+	{0x015004, 1},
+	{0x01500c, 4},
+	{0x015204, 1},
+	{0x015214, 4},
+	{0x015228, 1},
+	{0x015244, 1},
+	{0x015250, 4},
+	{0x015274, 1},
+	{0x01527c, 1},
+	{0x0152a4, 1},
+	{0x015300, 4},
+	{0x015314, 1},
+	{0x01531c, 3},
+	{0x015404, 2},
+	{0x015430, 20},
+	{0x015484, 2},
+	{0x015498, 5},
+	{0x0154bc, 1},
+	{0x0154c8, 1},
+	{0x0154d4, 2},
+	{0x01550c, 3},
+	{0x015524, 3},
+	{0x015608, 3},
+	{0x015618, 4},
+	{0x015680, 16},
+	{0x015704, 2},
+	{0x015730, 20},
+	{0x015784, 3},
+	{0x015794, 3},
+	{0x0157c0, 6},
+	{0x015800, 52},
+	{0x0158d4, 1},
+	{0x0158dc, 1},
+	{0x0158e4, 3},
+	{0x0158f4, 1},
+	{0x0158fc, 52},
+	{0x015b04, 2},
+	{0x015b14, 3},
+	{0x015b24, 2},
+	{0x015b38, 6},
+	{0x015b60, 5},
+	{0x015c04, 1},
+	{0x015cb8, 18},
+	{0x015d98, 1},
+	{0x015e00, 1},
+	{0x015e08, 1},
+	{0x015e10, 1},
+	{0x016000, 32},
+	{0x016100, 7},
+	{0x016120, 2},
+	{0x016144, 3},
+	{0x016204, 1},
+	{0x01620c, 1},
+	{0x016224, 1},
+	{0x01622c, 1},
+	{0x016234, 1},
+	{0x01623c, 1},
+	{0x016244, 1},
+	{0x01624c, 1},
+	{0x016254, 1},
+	{0x01625c, 2},
+	{0x016270, 1},
+	{0x016280, 1},
+	{0x016290, 1},
+	{0x0162a0, 1},
+	{0x0162b0, 1},
+	{0x0162c0, 1},
+	{0x0162d0, 1},
+	{0x0162e0, 1},
+	{0x0162f0, 1},
+	{0x016300, 1},
+	{0x016310, 1},
+	{0x016320, 1},
+	{0x016330, 1},
+	{0x016340, 32},
+	{0x016400, 19},
+	{0x016454, 7},
+	{0x016484, 1},
+	{0x01648c, 1},
+	{0x016800, 9},
+	{0x016840, 16},
+	{0x017800, 1},
+	{0x017828, 1},
+	{0x017850, 1},
+	{0x017878, 1},
+	{0x0178a0, 12},
+	{0x0179ac, 1},
+	{0x0179d8, 4},
+	{0x017a00, 6},
+	{0x017a20, 6},
+	{0x017a40, 3},
+	{0x017c00, 6},
+	{0x017c20, 6},
+	{0x017c40, 6},
+	{0x017c60, 6},
+	{0x017c80, 6},
+	{0x017ca0, 6},
+	{0x017cc0, 6},
+	{0x017ce0, 6},
+	{0x017d00, 3},
+	{0x017d10, 6},
+	{0x018400, 11},
+	{0x018430, 2},
+	{0x018440, 4},
+	{0x018604, 1},
+	{0x018618, 2},
+	{0x018640, 4},
+	{0x018660, 2},
+	{0x018800, 1},
+	{0x018810, 4},
+	{0x018844, 1},
+	{0x01884c, 4},
+	{0x018880, 2},
+	{0x01a400, 12},
+	{0x01a444, 1},
+	{0x01a44c, 1},
+	{0x01a800, 1},
+	{0x01a814, 3},
+	{0x01a844, 1},
+	{0x01a84c, 4},
+	{0x01c400, 7},
+	{0x01c500, 8},
+	{0x01c544, 1},
+	{0x01c554, 3},
+	{0x01c564, 3},
+	{0x01c574, 3},
+	{0x01c604, 1},
+	{0x01c60c, 3},
+	{0x01c800, 1},
+	{0x01c814, 3},
+	{0x01c844, 1},
+	{0x01c84c, 4},
+	{0x01f000, 1},
+	{0x01f400, 1},
+	{0x01f408, 4},
+	{0x01f41c, 3},
+	{0x01f500, 2},
+	{0x01f800, 1},
+	{0x01f814, 3},
+	{0x01f844, 1},
+	{0x01f84c, 4},
+	{0x01f880, 3},
+	{0x020004, 1},
+	{0x02000c, 4},
+	{0x020080, 3},
+	{0x020090, 5},
+	{0x020800, 16},
+	{0x020900, 192},
+	{0x021004, 1},
+	{0x02100c, 4},
+	{0x021400, 5},
+	{0x021418, 5},
+	{0x021480, 1},
+	{0x021704, 2},
+	{0x02173c, 17},
+	{0x0217fc, 2},
+	{0x021844, 1},
+	{0x022280, 12},
+	{0x022408, 6},
+	{0x022444, 1},
+	{0x022454, 3},
+	{0x022504, 1},
+	{0x02250c, 4},
+	{0x022624, 1},
+	{0x02262c, 3},
+	{0x02263c, 1},
+	{0x022804, 1},
+	{0x02280c, 4},
+	{0x022904, 4},
+	{0x022924, 4},
+	{0x024000, 36},
+	{0x0240c0, 21},
+	{0x024120, 11},
+	{0x024200, 5},
+	{0x024220, 1},
+	{0x024230, 8},
+	{0x024258, 1},
+	{0x024260, 1},
+	{0x024270, 9},
+	{0x0242a0, 1},
+	{0x0242b0, 4},
+	{0x0242c8, 2},
+	{0x024300, 5},
+	{0x024318, 2},
+	{0x02439c, 25},
+	{0x024424, 4},
+	{0x024464, 13},
+	{0x0244a4, 1},
+	{0x0244ac, 3},
+	{0x0244c0, 2},
+	{0x0244d0, 3},
+	{0x0244e0, 3},
+	{0x0244f0, 3},
+	{0x024500, 3},
+	{0x024510, 3},
+	{0x024520, 3},
+	{0x024530, 3},
+	{0x024884, 11},
+	{0x0248b4, 3},
+	{0x0248c4, 1},
+	{0x0248cc, 1},
+	{0x0248d4, 1},
+	{0x0248dc, 1},
+	{0x0248f0, 2},
+	{0x024908, 6},
+	{0x024928, 6},
+	{0x024968, 6},
+	{0x024984, 3},
+	{0x024994, 1},
+	{0x02499c, 6},
+	{0x0249b8, 7},
+	{0x024a08, 6},
+	{0x024a28, 6},
+	{0x024a68, 6},
+	{0x024a84, 1},
+	{0x024a8c, 1},
+	{0x024a94, 1},
+	{0x024a9c, 13},
+	{0x024ae0, 6},
+	{0x024b00, 7},
+	{0x024b20, 6},
+	{0x024b40, 8},
+	{0x024c00, 2},
+	{0x024c24, 3},
+	{0x024c34, 3},
+	{0x025004, 6},
+	{0x025800, 37},
+	{0x025904, 1},
+	{0x02590c, 1},
+	{0x026000, 99},
+	{0x026200, 1},
+	{0x026800, 7},
+	{0x026824, 6},
+	{0x026840, 2},
+	{0x026864, 1},
+	{0x02686c, 1},
+	{0x026874, 3},
+	{0x026884, 1},
+	{0x0268a4, 7},
+	{0x026904, 1},
+	{0x02690c, 4},
+	{0x026940, 1},
+	{0x026980, 33},
+	{0x026a0c, 7},
+	{0x026a30, 1},
+	{0x026a44, 4},
+	{0x026a60, 1},
+	{0x026a70, 1},
+	{0x026b00, 9},
+	{0x026b44, 2},
+	{0x026b68, 6},
+	{0x026b84, 2},
+	{0x026ba8, 14},
+	{0x026c00, 16},
+	{0x026c44, 1},
+	{0x026c4c, 1},
+	{0x026c84, 1},
+	{0x026c8c, 4},
+	{0x026cc4, 1},
+	{0x026ccc, 4},
+	{0x026d00, 2},
+	{0x028800, 2},
+	{0x028844, 1},
+	{0x02884c, 4},
+	{0x029004, 7},
+	{0x029b30, 2},
+	{0x029b50, 4},
+	{0x02a004, 1},
+	{0x02a00c, 4},
+	{0x02a040, 6},
+	{0x02a200, 1},
+	{0x02a210, 11},
+	{0x02a240, 8},
+	{0x02a484, 1},
+	{0x02a4c0, 16},
+	{0x02a780, 1},
+	{0x02a7a0, 4},
+	{0x02a7c0, 1},
+	{0x02a900, 1},

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803081521.w28FLudP099465>