aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/devctl
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2019-04-05 19:32:26 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2019-04-05 19:32:26 +0000
commit4fbf8e1c2efb16431c174d7a77c23e700af1160b (patch)
treeba86d2ae70d50d38cd895227ea65600ee173de6a /usr.sbin/devctl
parent1d1a5c2b02674c66cc305c465e3ae86dc1e526a1 (diff)
downloadsrc-4fbf8e1c2efb16431c174d7a77c23e700af1160b.tar.gz
src-4fbf8e1c2efb16431c174d7a77c23e700af1160b.zip
Implement devctl(8) command 'reset', using DEV_RESET /dev/devctl2 ioctl.
Reviewed by: imp (previous version), jhb (previous version) Sponsored by: Mellanox Technologies MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D19646
Notes
Notes: svn path=/head/; revision=345966
Diffstat (limited to 'usr.sbin/devctl')
-rw-r--r--usr.sbin/devctl/devctl.834
-rw-r--r--usr.sbin/devctl/devctl.c38
2 files changed, 70 insertions, 2 deletions
diff --git a/usr.sbin/devctl/devctl.8 b/usr.sbin/devctl/devctl.8
index 481a99ec0dc6..9fc3e69b1183 100644
--- a/usr.sbin/devctl/devctl.8
+++ b/usr.sbin/devctl/devctl.8
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd August 29, 2016
+.Dd April 4, 2019
.Dt DEVCTL 8
.Os
.Sh NAME
@@ -66,6 +66,10 @@
.Cm delete
.Op Fl f
.Ar device
+.Nm
+.Cm reset
+.Op Fl d
+.Ar device
.Sh DESCRIPTION
The
.Nm
@@ -166,7 +170,35 @@ the device will be deleted even if it is physically present.
This command should be used with care as a device that is deleted but present
can no longer be used unless the parent bus device rediscovers the device via
a rescan request.
+.It Xo Cm reset
+.Op Fl d
+.Ar device
+.Xc
+Reset the device, using bus-specific reset method.
+Drivers for the devices being reset are suspended around the reset.
+If the
+.Fl d
+option is specified, drivers are detached instead.
+.Pp
+Currently, resets are implemented for PCIe buses and PCI devices.
+For PCIe bus, the link is disabled and then re-trained, causing all
+children of the bus to reset.
+Use
+.Fl p
+option of
+.Xr devinfo 8
+tool to report parent bus for the device.
+For PCI device, if Function-Level Reset is implemented by it, FLR is
+tried first; if failed or not implemented, power reset is tried.
+.Pp
+If you have detached or suspended a child device explicitly and then
+do a reset, the child device will end up attached.
.El
+.Sh BUGS
+Currently there is no administrative flag to prevent re-attach or resume
+of the manually detached or suspended devices after reset.
+Similarly, there is no flag to prevent un-suspending of the the manually
+suspended devices after system resume.
.Sh SEE ALSO
.Xr devctl 3 ,
.Xr devinfo 8
diff --git a/usr.sbin/devctl/devctl.c b/usr.sbin/devctl/devctl.c
index 20c332d89409..32fbb64ef185 100644
--- a/usr.sbin/devctl/devctl.c
+++ b/usr.sbin/devctl/devctl.c
@@ -82,7 +82,9 @@ usage(void)
" devctl rescan device\n"
" devctl delete [-f] device\n"
" devctl freeze\n"
- " devctl thaw\n");
+ " devctl thaw\n"
+ " devctl reset [-d] device\n"
+ );
exit(1);
}
@@ -384,6 +386,40 @@ thaw(int ac, char **av __unused)
}
DEVCTL_COMMAND(top, thaw, thaw);
+static void
+reset_usage(void)
+{
+
+ fprintf(stderr, "usage: devctl reset [-d] device\n");
+ exit(1);
+}
+
+static int
+reset(int ac, char **av)
+{
+ bool detach;
+ int ch;
+
+ detach = false;
+ while ((ch = getopt(ac, av, "d")) != -1)
+ switch (ch) {
+ case 'd':
+ detach = true;
+ break;
+ default:
+ reset_usage();
+ }
+ ac -= optind;
+ av += optind;
+
+ if (ac != 1)
+ reset_usage();
+ if (devctl_reset(av[0], detach) < 0)
+ err(1, "Failed to reset %s", av[0]);
+ return (0);
+}
+DEVCTL_COMMAND(top, reset, reset);
+
int
main(int ac, char *av[])
{