USB_RESET_DEVICE(9F) | Kernel Functions for Drivers | USB_RESET_DEVICE(9F) |
usb_reset_device - reset a USB device according to the reset_level.
#include <sys/usb/usba.h> int usb_reset_device (dev_info_t *dip,
usb_dev_reset_lvl_t reset_level);
illumos DDI specific (illumos DDI)
dip
reset_level
The usb_reset_device() function provides a client driver to request a hardware reset for a USB device, which may be required in some situations such as:
The valid values for the reset_level are:
USB_RESET_LVL_DEFAULT
USB_RESET_LVL_REATTACH
The usb_reset_device() function creates a new helper thread for reattachment. When called from attach(9E), the new thread sets a timer (1 second), and waits until the driver's attach(9E) completes, after which the thread attempts to reattach the driver. When not called from attach(9E), the new thread attempts to reattach the driver immediately.
If the thread fails to reattach to the driver, an error message is printed in system log with the detailed reason. The driver returns to a stable state, depending on where the failure occurred.
The return values for the usb_reset_device() function are:
USB_SUCCESS
USB_FAILURE
USB_INVALID_ARGS
USB_INVALID_PERM
USB_BUSY
USB_INVALID_CONTEXT
Example 1 Resetting a Device
The following example shows how a device is reset to recover it from an error state:
xxx_configure() {
xxx_set_parameter1();
if (xxx_set_parameter2() == USB_FAILURE) {
/* Close all the opened pipes except the default pipe */
xxx_close_all_opened_pipes();
/* Reset the device */
rval = usb_reset_device(dip, USB_RESET_LVL_DEFAULT);
if (rval == USB_SUCCESS) {
/* Re-configure the device */
xxx_set_parameter1();
xxx_set_parameter2();
/* Open the closed pipes if needed */
...
} else {
/* Failed to reset the device, check the return value for
further process */
...
}
} }
Example 2 Resetting a Device After Downloading Firmware
The following example shows how a device is reset after downloading firmware. the device's descriptors change after the reset:
static int xxx_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) {
...
/* Download the firmware to the RAM of the device */
if (firmware_download() == USB_SUCCESS) {
/* Reset the device and re-enumerate it */
rval = usb_reset_device(dip, USB_RESET_LVL_REATTACH);
if (rval == USB_SUCCESS) {
/* The re-enumeration has been started up, just return */
return (DDI_SUCCESS);
} else {
/* Failed to start the re-enumeration, check the return value
for further process*/
...
return (DDI_FAILURE);
} }
The usb_reset_device() function may be called from user or kernel context.
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Architecture | PCI-based systems |
Interface Stability | Committed |
attributes(7), usb_clr_feature(9F), usb_get_cfg(9F), usb_pipe_close(9F), usb_pipe_xopen(9F), usb_pipe_reset(9F),
The messages described below may appear on the system console as well as being logged. All messages are formatted in the following manner:
WARNING: dev_path hubdinstance_num driver_name Error message ...
driver_name instance_num is under bus power management, cannot be reset. Please disconnect and reconnect this device.
Time out when resetting the device driver_name instance_num. Please disconnect and reconnect it to system.
driver_name instance_num cannot be reset due to other applications are using it, please first close these applications, then disconnect and reconnect the device.
Always close all applications before resetting a device.
June 18, 2021 | OmniOS |