On Tue, May 7, 2024 at 1:20 AM Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote: > > On Mon, May 06, 2024 at 09:44:52PM +0530, Muni Sekhar wrote: > > On Mon, May 6, 2024 at 7:59 PM Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote: > > > > > > On Mon, May 06, 2024 at 04:44:30PM +0530, Muni Sekhar wrote: > > > > While we have successfully converted most of the USB device driver > > > > functionality from kernel space to user space using libusb, we are now > > > > seeking guidance on how to implement USB device suspend/resume in user > > > > space. Specifically, we would like to know if libusb provides support > > > > for achieving the suspend/resume functionality mentioned above. > > > > Additionally, any insights or suggestions on how to accomplish this > > > > task would be greatly appreciated. > > > > > > Your question is about libusb, right? So you'll get better answers if > > > you post it on the libusb mailing list rather than the linux-usb mailing > > > list. > > Can USB device suspend\resume be implemented in user space driver > > using software other than libusb? > > Yes, a userspace driver can use the usbfs interface and can employ the > ioctl commands listed in /usr/include/linux/usbdevfs.h. It's possible > that libusb also provides facilities for controlling suspend and resume; > I don't know whether it does. > > > If so, what are those methods or techniques to achieve USB device > > suspend\resume , can you please provide clarity on this. > > As far as I know, these usbfs ioctl commands are not documented > anywhere. > > The USBDEVFS_FORBID_SUSPEND ioctl prevents the device from being > suspended, and wakes it up if it is currently suspended. > > The USBDEVFS_ALLOW_SUSPEND ioctl allows the device to be suspended. The > suspend may not happen immediately; it is controlled by the settings in > the device's power/control and power/autosuspend (or > power/autosuspend_delay_ms) sysfs attribute files. > > The USBDEVFS_WAIT_FOR_RESUME ioctl waits until the device resumes, > whether because of a remote wakeup or because another process has > resumed it, and then forbids the device from suspending again until > you perform another USBDEVFS_ALLOW_SUSPEND ioctl. > Thank you, it is very helpful. To verify the USB device suspend\resume functionality, I configured the USB Power Management variables as follows: # cat /sys/bus/usb/devices/2-1.7/power/wakeup enabled # cat /sys/bus/usb/devices/2-1.7/power/control on # cat /sys/bus/usb/devices/2-1.7/power/autosuspend_delay_ms 0 # cat /sys/module/usbcore/parameters/autosuspend 2 So, I configured the system to autosuspend the USB device as soon as it becomes idle, with no transactions running through the USB device. Now, how can I verify that the USB device has entered suspend mode from user space? When checking /var/log/kern.log, there are no relevant print statements. Are there any other log files related to power management or USB subsystems? Please correct me if anything in the test procedure mentioned above is incorrect. > Alan Stern -- Thanks, Sekhar