summaryrefslogtreecommitdiffstats
path: root/lib/libdevctl
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2016-09-30 22:05:47 +0000
committerjhb <jhb@FreeBSD.org>2016-09-30 22:05:47 +0000
commit96b406e9cc04e8c5edc75ab1cfb0edae6a57b9ab (patch)
tree35007123c9912c6cc8bff3312fac05355298a8f6 /lib/libdevctl
parenta6368448347da338ea1adc921d086119490e1022 (diff)
downloadFreeBSD-src-96b406e9cc04e8c5edc75ab1cfb0edae6a57b9ab.zip
FreeBSD-src-96b406e9cc04e8c5edc75ab1cfb0edae6a57b9ab.tar.gz
MFC 305034: Implement 'devctl clear driver' to undo a previous 'set driver'.
Add a new 'clear driver' command for devctl along with the accompanying ioctl and devctl_clear_driver() library routine to reset a device to use a wildcard devclass instead of a fixed devclass. This can be used to undo a previous 'set driver' command. After the device's name has been reset to permit wildcard names, it is reprobed so that it can attach to newly-available (to it) device drivers. Sponsored by: Chelsio Communications
Diffstat (limited to 'lib/libdevctl')
-rw-r--r--lib/libdevctl/devctl.345
-rw-r--r--lib/libdevctl/devctl.c8
-rw-r--r--lib/libdevctl/devctl.h1
3 files changed, 51 insertions, 3 deletions
diff --git a/lib/libdevctl/devctl.3 b/lib/libdevctl/devctl.3
index 866bb6a..a4fe062 100644
--- a/lib/libdevctl/devctl.3
+++ b/lib/libdevctl/devctl.3
@@ -25,12 +25,13 @@
.\"
.\" $FreeBSD$
.\"
-.Dd April 27, 2016
+.Dd August 29, 2016
.Dt DEVCTL 3
.Os
.Sh NAME
.Nm devctl ,
.Nm devctl_attach ,
+.Nm devctl_clear_driver ,
.Nm devctl_delete ,
.Nm devctl_detach ,
.Nm devctl_disable ,
@@ -47,6 +48,8 @@
.Ft int
.Fn devctl_attach "const char *device"
.Ft int
+.Fn devctl_clear_driver "const char *device" "bool force"
+.Ft int
.Fn devctl_delete "const char *device" "bool force"
.Ft int
.Fn devctl_detach "const char *device" "bool force"
@@ -166,12 +169,30 @@ the device will be detached from its current device driver before it is
attached to the new device driver.
.Pp
The
+.Fn devctl_clear_driver
+function resets a device so that it can be attached to any valid device
+driver rather than only drivers with a previously specified name.
+This function is used to undo a previous call to
+.Fn devctl_set_driver .
+If the device is already attached and
+.Fa force
+is false,
+the request will fail.
+If the device is already attached and
+.Fa force
+is true,
+the device will be detached from its current device driver.
+After the device's name is reset,
+it is reprobed and attached to a suitable device driver if one is found.
+.Pp
+The
.Fn devctl_rescan
function rescans a bus device checking for devices that have been added or
removed.
.Sh RETURN VALUES
-.Rv -std devctl_attach devctl_delete devctl_detach devctl_disable \
-devctl_enable devctl_suspend devctl_rescan devctl_resume devctl_set_driver
+.Rv -std devctl_attach devctl_clear_driver devctl_delete devctl_detach \
+devctl_disable devctl_enable devctl_suspend devctl_rescan devctl_resume \
+devctl_set_driver
.Sh ERRORS
In addition to specific errors noted below,
all of the
@@ -302,6 +323,24 @@ The new device driver failed to attach.
.El
.Pp
The
+.Fn devctl_clear_driver
+function may fail if:
+.Bl -tag -width Er
+.It Bq Er EBUSY
+The device is currently attached to a device driver and
+.Fa force
+is false.
+.It Bq Er EBUSY
+The current device driver for
+.Fa device
+is busy and cannot detach at this time.
+.It Bq Er EINVAL
+The device is not configured for a specific device driver name.
+.It Bq Er ENXIO
+The device driver chosen after reprobing failed to attach.
+.El
+.Pp
+The
.Fn devctl_rescan
function may fail if:
.Bl -tag -width Er
diff --git a/lib/libdevctl/devctl.c b/lib/libdevctl/devctl.c
index 9f275e7..5013fb0 100644
--- a/lib/libdevctl/devctl.c
+++ b/lib/libdevctl/devctl.c
@@ -124,6 +124,14 @@ devctl_set_driver(const char *device, const char *driver, bool force)
}
int
+devctl_clear_driver(const char *device, bool force)
+{
+
+ return (devctl_simple_request(DEV_CLEAR_DRIVER, device, force ?
+ DEVF_CLEAR_DRIVER_DETACH : 0));
+}
+
+int
devctl_rescan(const char *device)
{
diff --git a/lib/libdevctl/devctl.h b/lib/libdevctl/devctl.h
index 670ca1a..d49199a 100644
--- a/lib/libdevctl/devctl.h
+++ b/lib/libdevctl/devctl.h
@@ -38,6 +38,7 @@ int devctl_disable(const char *device, bool force_detach);
int devctl_suspend(const char *device);
int devctl_resume(const char *device);
int devctl_set_driver(const char *device, const char *driver, bool force);
+int devctl_clear_driver(const char *device, bool force);
int devctl_rescan(const char *device);
int devctl_delete(const char *device, bool force);
OpenPOWER on IntegriCloud