aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/usb/usb_device.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r363420:Mark Johnston2020-07-291-0/+2
| | | | | | | usb(4): Stop checking for failures from malloc(M_WAITOK). Notes: svn path=/stable/12/; revision=363664
* MFC r361577:Hans Petter Selasky2020-06-081-1/+1
| | | | | | | | | | Don't allow USB device drivers to parent own interface. It will prevent proper USB device detach. Sponsored by: Mellanox Technologies Notes: svn path=/stable/12/; revision=361906
* MFC r360925:Hans Petter Selasky2020-05-181-70/+93
| | | | | | | | | | Refresh the USB device strings when a USB device is re-enumerated. Submitted by: Horse Ma <Shichun.Ma@dell.com> Sponsored by: Mellanox Technologies Notes: svn path=/stable/12/; revision=361207
* Change the default USB template from the current 0 to -1. The reasonEdward Tomasz Napierala2018-05-281-1/+1
| | | | | | | | | | | | | | | is that current one (mass storage device) doesn't work as it is - it needs to be set to 0 after the LUN is configured, which is what the cfumass rc script does. In other words: the current default does not work, and to actually make it work it had to be set to -1 in /boot/loader.conf. Reviewed by: hselasky@ MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=334292
* Make the handler routine for the hw.usb.template sysctl trigger the USBEdward Tomasz Napierala2018-01-301-2/+132
| | | | | | | | | | | | | | host to reprobe the bus by switching the USB pull up resistors off and back on. In other words - when FreeBSD is configured as a USB device, changing the sysctl will be immediately noticed by the machine it's connected to. Reviewed by: hselasky@ MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=328589
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
* Make the USB attach strings in dmesg include product name.Edward Tomasz Napierala2016-10-251-4/+5
| | | | | | | | | | | Note to self: MFC this to 9 and 8. Reviewed by: hselasky@, imp@ MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D8259 Notes: svn path=/head/; revision=307902
* Fix device delete child function.Hans Petter Selasky2016-10-171-3/+1
| | | | | | | | | | | | | | | | | | | | | | | When detaching device trees parent devices must be detached prior to detaching its children. This is because parent devices can have pointers to the child devices in their softcs which are not invalidated by device_delete_child(). This can cause use after free issues and panic(). Device drivers implementing trees, must ensure its detach function detaches or deletes all its children before returning. While at it remove now redundant device_detach() calls before device_delete_child() and device_delete_children(), mostly in the USB controller drivers. Tested by: Jan Henrik Sylvester <me@janh.de> Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D8070 MFC after: 2 weeks Notes: svn path=/head/; revision=307518
* Improve USB polling mode by not locking any mutexes, asserting anyHans Petter Selasky2016-09-141-2/+2
| | | | | | | | | | | | | | | | | | | | | mutexes or using any callouts when active. Trying to lock a mutex when KDB is active or the scheduler is stopped can result in infinite wait loops. The same goes for calling callout related functions which in turn lock mutexes. If the USB controller at which a USB keyboard is connected is idle when KDB is entered, polling the USB keyboard via USB will always succeed. Else polling may fail depending on which state the USB subsystem and USB interrupt handler is in. This is unavoidable unless KDB can wait for USB interrupt threads to complete before stalling the CPU(s). Tested by: Bruce Evans <bde@freebsd.org> MFC after: 4 weeks Notes: svn path=/head/; revision=305806
* Resolve deadlock between device_detach() and usbd_do_request_flags()Hans Petter Selasky2016-09-051-4/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | by reviving the SX control request lock and refining which lock protects the common scratch area in "struct usb_device". The SX control request lock was removed by r246759 because it caused a lock order reversal with the USB enumeration lock inside usbd_transfer_setup() as a function of r246616. It was thought that reducing the number of locks would resolve the LOR, but because some USB device drivers use usbd_do_request_flags() inside callback functions, like in taskqueues, a deadlock may occur when these are drained from device_detach(). By restoring the SX control request lock usbd_do_request_flags() is allowed to complete its execution when a USB device driver is detaching. By using the SX control request lock to protect the scratch area, the LOR introduced by r246616 is also resolved. Bump the FreeBSD version while at it to force recompilation of all USB kernel modules. Found by: avos@ MFC after: 1 week Notes: svn path=/head/; revision=305421
* Improve error message.Edward Tomasz Napierala2016-07-291-2/+2
| | | | | | | MFC after: 1 month Notes: svn path=/head/; revision=303477
* Check for signals when locking the USB enumeration thread fromHans Petter Selasky2016-05-251-1/+22
| | | | | | | | | | userspace, so that USB applications can be killed if an enumeration thread should be stuck for various reasons. MFC after: 1 week Notes: svn path=/head/; revision=300667
* Extend the UQ_NO_STRINGS quirk to also cover the USB language stringHans Petter Selasky2016-05-041-1/+3
| | | | | | | | | | descriptor. This fixes enumeration of some older Samsung Galaxy S3 phones. MFC after: 1 week Notes: svn path=/head/; revision=299060
* dev/usb: minor spelling fixes in comments.Pedro F. Giffuni2016-05-021-2/+2
| | | | | | | | | No functional change. Reviewed by: hselasky Notes: svn path=/head/; revision=298932
* Use the recently added "make_dev_s()" function to solve old race setting theHans Petter Selasky2016-01-151-6/+9
| | | | | | | si_drv1 field in "struct cdev" when creating new character devices. Notes: svn path=/head/; revision=294088
* Finish process of moving the LinuxKPI module into the default kernel build.Hans Petter Selasky2015-10-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | - Move all files related to the LinuxKPI into sys/compat/linuxkpi and its subfolders. - Update sys/conf/files and some Makefiles to use new file locations. - Added description of COMPAT_LINUXKPI to sys/conf/NOTES which in turn adds the LinuxKPI to all LINT builds. - The LinuxKPI can be added to the kernel by setting the COMPAT_LINUXKPI option. The OFED kernel option no longer builds the LinuxKPI into the kernel. This was done to keep the build rules for the LinuxKPI in sys/conf/files simple. - Extend the LinuxKPI module to include support for USB by moving the Linux USB compat from usb.ko to linuxkpi.ko. - Bump the FreeBSD_version. - A universe kernel build has been done. Reviewed by: np @ (cxgb and cxgbe related changes only) Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=290135
* Improve the realtime properties of USB transfers for embedded systemsHans Petter Selasky2015-08-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | like RPI-B and RPI-2. Description of problem: USB transfers can process data in their callbacks sometimes causing unacceptable latency for other USB transfers. Separate BULK completion callbacks from CONTROL, INTERRUPT and ISOCHRONOUS callbacks, and give BULK completion callbacks lesser execution priority than the others. This way USB audio won't be interfered by heavy USB ethernet usage for example. Further serve USB transfer completion in a round robin fashion, instead of only serving the most CPU hungry. This has been done by adding a third flag to USB transfer queue structure which keeps track of looping callbacks. The "command" callback function then decides what to do when looping. MFC after: 2 weeks Notes: svn path=/head/; revision=286773
* Add support for DYMO LabelWriter PnP.Hans Petter Selasky2015-05-071-0/+6
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=282577
* Add a kernel function to delist our kernel character devices, so thatHans Petter Selasky2015-01-141-1/+4
| | | | | | | | | | | the device name can be re-used right away in case we are destroying the character devices in the background. MFC after: 4 days Reported by: dchagin@ Notes: svn path=/head/; revision=277179
* Resolve a special case deadlock: When two or more threads areHans Petter Selasky2015-01-131-60/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | simultaneously detaching kernel drivers on the same USB device we can get stuck in the "usb_wait_pending_ref_locked()" function because the conditions needed for allowing detach are not met. The "destroy_dev()" function waits for all system calls involving the given character device to return. Character device system calls may lock the USB enumeration lock, which is also held when "destroy_dev()" is called. This can sometimes lead to a deadlock not noticed by WITNESS. The current solution is to ensure the calling thread is the only one holding the USB enumeration lock and prevent other threads from getting refs while a USB device detach is ongoing. This turned out not to be sufficient. To solve this deadlock we could use "destroy_dev_sched()" to schedule the device destruction in the background, but then we don't know when it is safe to free() the private data of the character device. Instead a callback function is executed by the USB explore process to kill off any leftover USB character devices synchronously after the USB device explore code is finished and the USB enumeration lock is no longer locked. This makes porting easier and also ensures us that character devices must eventually go away after a USB device detach. While at it ensure that "flag_iserror" is only written when "priv_mtx" is locked, which is protecting it. MFC after: 5 days Notes: svn path=/head/; revision=277136
* Fix for deadlock in USB device side mode.Hans Petter Selasky2014-08-051-6/+13
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=269566
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-6/+3
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-3/+6
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985
* Extend the meaning of the CTLFLAG_TUN flag to automatically check ifHans Petter Selasky2014-06-271-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there is an environment variable which shall initialize the SYSCTL during early boot. This works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTL NODE type and SYSCTLs which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to be used in the case a tunable sysctl has a custom initialisation function allowing the sysctl to still be marked as a tunable. The kernel SYSCTL API is mostly the same, with a few exceptions for some special operations like iterating childrens of a static/extern SYSCTL node. This operation should probably be made into a factored out common macro, hence some device drivers use this. The reason for changing the SYSCTL API was the need for a SYSCTL parent OID pointer and not only the SYSCTL parent OID list pointer in order to quickly generate the sysctl path. The motivation behind this patch is to avoid parameter loading cludges inside the OFED driver subsystem. Instead of adding special code to the OFED driver subsystem to post-load tunables into dynamically created sysctls, we generalize this in the kernel. Other changes: - Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask" to "hw.pcic.intr_mask". - Removed redundant TUNABLE statements throughout the kernel. - Some minor code rewrites in connection to removing not needed TUNABLE statements. - Added a missing SYSCTL_DECL(). - Wrapped two very long lines. - Avoid malloc()/free() inside sysctl string handling, in case it is called to initialize a sysctl from a tunable, hence malloc()/free() is not ready when sysctls from the sysctl dataset are registered. - Bumped FreeBSD version to indicate SYSCTL API change. MFC after: 2 weeks Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=267961
* Avoid the USB device disconnected and controller shutdown clutter on systemMarius Strobl2014-06-101-6/+10
| | | | | | | | | | | | shutdown by putting the former under !rebooting and turning the latter into debug messages. Reviewed by: hps MFC after: 1 week Sponsored by: Bally Wulff Games & Entertainment GmbH Notes: svn path=/head/; revision=267321
* Try to resolve a possible deadlock when detaching USB devices whichHans Petter Selasky2014-03-201-8/+70
| | | | | | | | | | | | | | | | | create character devices. The deadlock can happen if an application is issuing IOCTLs which require USB refcounting, at the same time the USB device is detaching. There is already a counter in place in the USB device structure to detect this situation, but it was not always checked ahead of invoking functions that might destroy character devices, like detach, set configuration, set alternate interface or detach active kernel driver. Reported by: Daniel O'Connor <doconnor@gsoft.com.au> MFC after: 1 week Notes: svn path=/head/; revision=263423
* Fix a possible memory use after free and leak situation associatedHans Petter Selasky2014-01-171-10/+14
| | | | | | | | | | | | | | with USB device detach when using character device handles. This also includes LibUSB. It turns out that "usb_close()" cannot always get a reference to clean up its USB transfers and such, if called during the kernel USB device detach. Analysis by: hselasky @ Reported by: Juergen Lock <nox@jelal.kn-bremen.de> MFC after: 1 week Notes: svn path=/head/; revision=260814
* Implement better error recovery for Transaction Translators, TTs,Hans Petter Selasky2014-01-131-2/+2
| | | | | | | | | | | | | found in High Speed USB HUBs which translate from High Speed USB into FULL or LOW speed USB. In some rare cases SPLIT transactions might get lost, which might leave the TT in an unknown state. Whenever we detect such an error try to issue either a clear TT buffer request, or if that is not possible reset the whole TT. MFC after: 1 week Notes: svn path=/head/; revision=260589
* USB method structures for USB controllers and USB pipes should beHans Petter Selasky2013-12-111-1/+1
| | | | | | | | constant and does not need to be modified. This also saves a small amount of RAM. Notes: svn path=/head/; revision=259218
* Fix some statical clang analyzer warnings.Hans Petter Selasky2013-05-251-3/+0
| | | | Notes: svn path=/head/; revision=250986
* Fix compile warning.Hans Petter Selasky2013-05-031-1/+2
| | | | Notes: svn path=/head/; revision=250212
* - Add more defines to limit USB memory usage and number of allocationsHans Petter Selasky2013-05-031-2/+2
| | | | | | | | | | | in reduced memory systems. - Split allocation and freeing of the configuration descriptor into a separate function, so that the configuration descriptor can be made fixed size to save memory allocations. This applies for both device and host mode. Notes: svn path=/head/; revision=250207
* Add some defines to limit USB memory usage in reduced memory systems.Hans Petter Selasky2013-05-031-12/+15
| | | | Notes: svn path=/head/; revision=250204
* Allow the default USB template to be specified at compile time.Hans Petter Selasky2013-05-031-1/+5
| | | | Notes: svn path=/head/; revision=250202
* Add missing ifdef's for reduced feature compilations.Hans Petter Selasky2013-04-031-0/+4
| | | | Notes: svn path=/head/; revision=249043
* - Make quirk for reading device descriptor from broken USB devices.Hans Petter Selasky2013-03-131-3/+7
| | | | | | | | | | | | | | Else they won't enumerate at all: hw.usb.full_ddesc=1 - Reduce the USB descriptor read timeout from 1000ms to 500ms. Typical value for LOW speed devices is 50-100ms. - Enumerate USB device a maximum of 3 times when a port connection change event is detected, before giving up. MFC after: 1 month Notes: svn path=/head/; revision=248246
* Resolve a LOR after r246616. Protect control requests using the USB deviceHans Petter Selasky2013-02-131-4/+0
| | | | | | | | | | | | enumeration lock. Make sure all callers of usbd_enum_lock() check the return value. Remove the control transfer specific lock. Bump the FreeBSD version number, hence external USB modules may need to be recompiled due to a USB device structure change. MFC after: 1 week Notes: svn path=/head/; revision=246759
* - Move scratch data from the USB bus structure to the USB device structureHans Petter Selasky2013-02-101-45/+40
| | | | | | | | | | | | | so that simultaneous access cannot happen. Protect scratch area using the enumeration lock. Also reduce stack usage in usbd_transfer_setup() by moving some big stack members to the scratch area. This saves around 200 bytes of stack. - Fix a whitespace. MFC after: 1 week Notes: svn path=/head/; revision=246616
* Add defines to more easily allow a single threaded version of the FreeBSDHans Petter Selasky2013-02-051-1/+1
| | | | | | | USB stack. This is useful for non-kernel purposes, like the loader. Notes: svn path=/head/; revision=246363
* Modify the FreeBSD USB kernel code so that it can be compiled directlyHans Petter Selasky2013-01-301-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | into the FreeBSD boot loader, typically for non-USB aware BIOSes, EFI systems or embedded platforms. This is also useful for out of the system compilation of the FreeBSD USB stack for various purposes. The USB kernel files can now optionally include a global header file which should include all needed definitions required to compile the FreeBSD USB stack. When the global USB header file is included, no other USB header files will be included by default. Add new file containing the USB stack configuration for the FreeBSD loader build. Replace some __FBSDID()'s by /* $FreeBSD$ */ comments. Now all USB files follow the same style. Use cases: - console in loader via USB - loading kernel via USB Discussed with: Hiroki Sato, hrs @ EuroBSDCon Notes: svn path=/head/; revision=246122
* Add missing CTLFLAG_TUN flag to tunable sysctls in USB stack.Hans Petter Selasky2012-10-261-3/+3
| | | | | | | | | | | Rearrange the tunables and belonging sysctl declarations, so that they are next to eachother. Submitted by: n_hibma @ MFC after: 1 week Notes: svn path=/head/; revision=242126
* Fix for missing locks due to recent change.Hans Petter Selasky2012-08-131-1/+11
| | | | | | | | PR: usb/170606 MFC after: 2 weeks Notes: svn path=/head/; revision=239240
* Add support for the so-called streams feature of BULK endpointsHans Petter Selasky2012-08-121-16/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in SUPER-speed mode, USB 3.0. This feature has not been tested yet, due to lack of hardware. This feature is useful when implementing protocols like UASP, USB attached SCSI which promises higher USB mass storage throughput. This patch also implements support for hardware processing of endpoints for increased performance. The switching to hardware processing of an endpoint is done via a callback to the USB controller driver. The stream feature is implemented like a variant of a hardware USB protocol. USB controller drivers implementing device mode needs to be updated to implement the new "xfer_stall" USB controller method and remove the "xfer" argument from the "set_stall" method. The API's toward existing USB drivers are preserved. To setup a USB transfer in stream mode, set the "stream_id" field of the USB config structure to the desired value. The maximum number of BULK streams is currently hardcoded and limited to 8 via a define in usb_freebsd.h. All USB drivers should be re-compiled after this change. LibUSB will be updated next week to support streams mode. A new IOCTL to setup BULK streams as already been implemented. The ugen device nodes currently only supports stream ID zero. The FreeBSD version has been bumped. MFC after: 2 weeks Notes: svn path=/head/; revision=239214
* Style.Hans Petter Selasky2012-08-101-2/+2
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=239177
* Improve support for detaching kernel drivers on a per interface basis.Hans Petter Selasky2012-06-011-4/+10
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=236407
* Fix compiler warnings, mostly signed issues,Hans Petter Selasky2012-04-021-2/+0
| | | | | | | | | when USB modules are compiled with WARNS=9. MFC after: 1 weeks Notes: svn path=/head/; revision=233774
* Improve USB mass storage quirk auto detection.Hans Petter Selasky2011-10-291-1/+2
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=226903
* Refactor auto-quirk solution so that we break as few externalHans Petter Selasky2011-09-101-6/+16
| | | | | | | | | | | | drivers as possible. PR: usb/160299 Approved by: re (kib) Suggested by: rwatson MFC after: 0 days Notes: svn path=/head/; revision=225469
* This patch adds automatic detection of USB mass storage devicesHans Petter Selasky2011-09-021-1/+33
| | | | | | | | | | | | | | | which does not support the no synchronize cache SCSI command. The __FreeBSD_version version macro has been bumped and external kernel modules needs to be recompiled after this patch. Approved by: re (kib) MFC after: 1 week PR: usb/160299 Notes: svn path=/head/; revision=225350
* Use synchronous device destruction instead of asynchronous, so that a newHans Petter Selasky2011-08-111-32/+47
| | | | | | | | | | | | device having the same name like a previous one is not created before the old one is gone. This fixes some panics due to asserts in the devfs code which were added recently. Approved by: re (kib) MFC after: 1 week Notes: svn path=/head/; revision=224777