Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 May 2019 18:20:14 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r347869 - in stable/11: share/man/man4 sys/dev/mlx5 sys/dev/mlx5/mlx5_core usr.sbin/mlx5tool
Message-ID:  <201905161820.x4GIKEf8034627@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu May 16 18:20:14 2019
New Revision: 347869
URL: https://svnweb.freebsd.org/changeset/base/347869

Log:
  MFC r347313:
  Implement firmware reset from userspace in mlx5tool(8).
  
  Submitted by:	kib@
  Sponsored by:	Mellanox Technologies

Modified:
  stable/11/share/man/man4/mlx5io.4
  stable/11/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
  stable/11/sys/dev/mlx5/mlx5io.h
  stable/11/usr.sbin/mlx5tool/mlx5tool.8
  stable/11/usr.sbin/mlx5tool/mlx5tool.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/share/man/man4/mlx5io.4
==============================================================================
--- stable/11/share/man/man4/mlx5io.4	Thu May 16 18:19:08 2019	(r347868)
+++ stable/11/share/man/man4/mlx5io.4	Thu May 16 18:20:14 2019	(r347869)
@@ -142,6 +142,11 @@ Image address in memory is passed in
 the length of the image is specified in
 .Dv img_fw_data_len
 field.
+.It Dv MLX5_FW_RESET
+Requests PCIe link-level reset on the device.
+The address of the device is specified by the
+.Vt struct mlx5_tool_addr
+structure, which should be passed as an argument.
 .El
 .Sh FILES
 The

Modified: stable/11/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c
==============================================================================
--- stable/11/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c	Thu May 16 18:19:08 2019	(r347868)
+++ stable/11/sys/dev/mlx5/mlx5_core/mlx5_fwdump.c	Thu May 16 18:20:14 2019	(r347869)
@@ -226,6 +226,24 @@ out:
 }
 
 static int
+mlx5_fw_reset(struct mlx5_core_dev *mdev)
+{
+	device_t dev, bus;
+	int error;
+
+	error = -mlx5_set_mfrl_reg(mdev, MLX5_FRL_LEVEL3);
+	if (error == 0) {
+		dev = mdev->pdev->dev.bsddev;
+		mtx_lock(&Giant);
+		bus = device_get_parent(dev);
+		error = BUS_RESET_CHILD(device_get_parent(bus), bus,
+		    DEVF_RESET_DETACH);
+		mtx_unlock(&Giant);
+	}
+	return (error);
+}
+
+static int
 mlx5_fwdump_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
     struct thread *td)
 {
@@ -306,6 +324,17 @@ mlx5_fwdump_ioctl(struct cdev *dev, u_long cmd, caddr_
 		if (error == 0)
 			error = -mlx5_firmware_flash(mdev, &fake_fw);
 		kmem_free(kmem_arena, (vm_offset_t)fake_fw.data, fu->img_fw_data_len);
+		break;
+	case MLX5_FW_RESET:
+		if ((fflag & FWRITE) == 0) {
+			error = EBADF;
+			break;
+		}
+		devaddr = (struct mlx5_tool_addr *)data;
+		error = mlx5_dbsf_to_core(devaddr, &mdev);
+		if (error != 0)
+			break;
+		error = mlx5_fw_reset(mdev);
 		break;
 	default:
 		error = ENOTTY;

Modified: stable/11/sys/dev/mlx5/mlx5io.h
==============================================================================
--- stable/11/sys/dev/mlx5/mlx5io.h	Thu May 16 18:19:08 2019	(r347868)
+++ stable/11/sys/dev/mlx5/mlx5io.h	Thu May 16 18:20:14 2019	(r347869)
@@ -59,6 +59,7 @@ struct mlx5_fw_update {
 #define	MLX5_FWDUMP_RESET	_IOW('m', 2, struct mlx5_tool_addr)
 #define	MLX5_FWDUMP_FORCE	_IOW('m', 3, struct mlx5_tool_addr)
 #define	MLX5_FW_UPDATE		_IOW('m', 4, struct mlx5_fw_update)
+#define	MLX5_FW_RESET		_IOW('m', 5, struct mlx5_tool_addr)
 
 #ifndef _KERNEL
 #define	MLX5_DEV_PATH	_PATH_DEV"mlx5ctl"

Modified: stable/11/usr.sbin/mlx5tool/mlx5tool.8
==============================================================================
--- stable/11/usr.sbin/mlx5tool/mlx5tool.8	Thu May 16 18:19:08 2019	(r347868)
+++ stable/11/usr.sbin/mlx5tool/mlx5tool.8	Thu May 16 18:20:14 2019	(r347869)
@@ -45,6 +45,9 @@
 .Nm
 .Fl d Ar domain:bus:slot:func
 .Fl f Ar file.mfa2
+.Nm
+.Fl d Ar domain:bus:slot:func
+.Fl z
 .Sh DESCRIPTION
 The
 .Nm
@@ -91,6 +94,14 @@ Flashes the firmware image
 to the specified adapter.
 Image must be in MFA2 pack format and contain a component suitable
 for the adapter hardware.
+.Pp
+Typically, PCIe link-level reset is required to activate the
+newly flashed image, which can be performed by the system reboot
+or using the
+.Fl z
+option.
+.It Fl z
+Performs PCIe link-level reset on the specified device.
 .El
 .Sh FILES
 The

Modified: stable/11/usr.sbin/mlx5tool/mlx5tool.c
==============================================================================
--- stable/11/usr.sbin/mlx5tool/mlx5tool.c	Thu May 16 18:19:08 2019	(r347868)
+++ stable/11/usr.sbin/mlx5tool/mlx5tool.c	Thu May 16 18:20:14 2019	(r347869)
@@ -189,17 +189,29 @@ close_fd:
 	return (res);
 }
 
+static int
+mlx5tool_fw_reset(int ctldev, const struct mlx5_tool_addr *addr)
+{
+
+	if (ioctl(ctldev, MLX5_FW_RESET, addr) == -1) {
+		warn("MLX5_FW_RESET");
+		return (1);
+	}
+	return (0);
+}
+
 static void
 usage(void)
 {
 
 	fprintf(stderr,
 	    "Usage: mlx5tool -d pci<d:b:s:f> [-w -o dump.file | -r |"
-	    "    -e | -f fw.mfa2]\n");
+	    " -e | -f fw.mfa2 | -z]\n");
 	fprintf(stderr, "\t-w - write firmware dump to the specified file\n");
 	fprintf(stderr, "\t-r - reset dump\n");
 	fprintf(stderr, "\t-e - force dump\n");
 	fprintf(stderr, "\t-f fw.img - flash firmware from fw.img\n");
+	fprintf(stderr, "\t-z - initiate firmware reset\n");
 	exit(1);
 }
 
@@ -208,6 +220,7 @@ enum mlx5_action {
 	ACTION_DUMP_RESET,
 	ACTION_DUMP_FORCE,
 	ACTION_FW_UPDATE,
+	ACTION_FW_RESET,
 	ACTION_NONE,
 };
 
@@ -225,7 +238,7 @@ main(int argc, char *argv[])
 	addrstr = NULL;
 	dumpname = NULL;
 	img_fw_path = NULL;
-	while ((c = getopt(argc, argv, "d:ef:ho:rw")) != -1) {
+	while ((c = getopt(argc, argv, "d:ef:ho:rwz")) != -1) {
 		switch (c) {
 		case 'd':
 			addrstr = optarg;
@@ -246,6 +259,9 @@ main(int argc, char *argv[])
 			act = ACTION_FW_UPDATE;
 			img_fw_path = optarg;
 			break;
+		case 'z':
+			act = ACTION_FW_RESET;
+			break;
 		case 'h':
 		default:
 			usage();
@@ -273,6 +289,9 @@ main(int argc, char *argv[])
 		break;
 	case ACTION_FW_UPDATE:
 		res = mlx5tool_fw_update(ctldev, &addr, img_fw_path);
+		break;
+	case ACTION_FW_RESET:
+		res = mlx5tool_fw_reset(ctldev, &addr);
 		break;
 	default:
 		res = 0;



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