Home | History | Annotate | Download | only in usb
History log of /src/sys/dev/usb/usb.c
RevisionDateAuthorComments
 1.203  04-Feb-2024  mrg update my email address.
 1.202  31-Jul-2023  christos Don't call versioned stuff "old". Follow the naming convention for versioning
and name them after the last version of the OS they appeared on.
 1.201  20-Jul-2023  mrg various debug updates for some usb drivers

- several new *_DEBUG_DEFAULT options that allow usb debug values to
be set to a default that is non-zero:
EHCI_DEBUG_DEFAULT, UGEN_DEBUG_DEFAULT, URTWN_DEBUG_DEFAULT,
UMS_DEBUG_DEFAULT, and USB_DEBUG_DEFAULT
- ugen debug uses fewer usbhist lines for the same info
- ums.c converted from printf() to usbhist
 1.200  13-Mar-2022  riastradh usb: Fix roothub ctrl xfer aborts.

No mechanism for actually aborting, but at least this now waits for
the xfer to have completed instead of blithely barging ahead whether
it's done or not.
 1.199  06-Mar-2022  riastradh usb(4): Use atomics for usb_async_proc.

This is written under proc_lock and read without it in usb_add_event,
so using atomics pacifies the sanitizer. No memory ordering needed
because the value isn't actually used until the softint runs, using
it under proc_lock. Kind of a micro-optimization, but let's avoid
contention on proc_lock in the common case of no usb_async_proc set
up (why is this a system global, anyway? and why is there a softint
if usb_add_event always runs at IPL_NONE?).

Reported-by: syzbot+1b2fa68535e5b0f3dcaa@syzkaller.appspotmail.com
 1.198  10-Oct-2021  jmcneill usb: usb_event_thread: remove delay at startup for USB >= 2.0 HCs

The delay at the start of usb_event_thread is meant to slow down EHCI
companion controllers. Skip the 500ms delay if the bus that owns this
thread is USB >= 2.0 since those are never companions.
 1.197  26-Sep-2021  thorpej Change the kqueue filterops::f_isfd field to filterops::f_flags, and
define a flag FILTEROP_ISFD that has the meaning of the prior f_isfd.
Field and flag name aligned with OpenBSD.

This does not constitute a functional or ABI change, as the field location
and size, and the value placed in that field, are the same as the previous
code, but we're bumping __NetBSD_Version__ so 3rd-party module source code
can adapt, as needed.

NetBSD 9.99.89
 1.196  13-Jun-2021  riastradh usb(4): Bus exploration is single-threaded -- assert it so.

New usb_in_event_thread(dev) returns true if dev is a USB device --
that is, a device with a usbN ancestor -- and the current thread is
the USB event thread.

(Kinda kludgey to pass around the device_t instead of, say, struct
usbd_bus, but I don't see a good way to get to the usbN device_t or
struct usb_softc from there.)
 1.195  12-Jun-2021  riastradh usb(4): Sprinkle kernel lock assertions.
 1.194  12-Jun-2021  riastradh usb(4): usb event thread is not actually MP-safe.

Still requires a lot of work in usb(4), uhub(4), and autoconf(9).
 1.193  24-Feb-2021  mrg branches: 1.193.4;
fix sparc build: db_expr_t is larger than a pointer.
 1.192  23-Feb-2021  mrg fix the formating for 'show usbxferlist'.
 1.191  23-Feb-2021  mrg introduce DDB_END_CMD and replace more than 20 copies of the same
list of NULLs and 0. idea from rillig@.

all touched ports built, several booted.
 1.190  22-Feb-2021  mrg fix formatting and db_usb_command_table[] static. idea from rillig@.
 1.189  21-Feb-2021  mrg add ddb commands to inspect usb xfer and xferlist structures.
 1.188  18-Dec-2020  thorpej Use sel{record,remove}_knote().
 1.187  27-May-2020  skrll branches: 1.187.2;
Don't allow open of /dev/usb if there are no attached busses.

PR kern/55303 mutex_vector_enter,512: uninitialized lock
 1.186  26-May-2020  skrll s/0/NULL/ for pointer (usb_async_proc)
 1.185  26-May-2020  skrll Misc whitespace
 1.184  23-May-2020  ad Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.
 1.183  19-Feb-2020  riastradh New dtrace usb provider, with a handful of probes in usb.c.
 1.182  12-Feb-2020  riastradh New function usb_task_pending for diagnostic assertions.

Usable only for negative diagnostic assertions:

KASSERT(!usb_task_pending(dev, task))

If you can think of a better name for this than !usb_task_pending,
I'm all ears.
 1.181  12-Feb-2020  riastradh Teach usb_rem_task to return whether removed from queue or not.
 1.180  21-Aug-2019  mrg branches: 1.180.2;
convert pairs of USBHIST_CALLED()+USBHIST_LOG*() into
USBHIST_CALLARGS() calls. this reduces the number of
kernel history lines consumed by these callers, and
for the +LOGN versions, add useful log info to a
message that just says "called!".

reduces the line spam which means the total info in a
full log is significantly increased.
 1.179  05-May-2019  mrg branches: 1.179.2;
remove explicit 'extern struct cfdriver <my>_cd;' and use ioconf.h
 1.178  01-Mar-2019  pgoyette Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.

NFCI intended.

Ride the earlier kernel bump - it;s getting crowded.
 1.177  03-Feb-2019  mrg - add or adjust /* FALLTHROUGH */ where appropriate
- add __unreachable() after functions that can return but won't in
this case, and thus can't be marked __dead easily
 1.176  29-Jan-2019  pgoyette Normalize all the compat hooks' names to the form

<subsystem>_<function>_<version>_hook

NFCI

XXX Note that although this introduces a change in the kernel-to-
XXX module interface, we are NOT bumping the kernel version number.
XXX We will bump the version number once the interface stabilizes.
 1.175  27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.174  18-Sep-2018  mrg remove usb(4)'s "flags 1" code. it has been dead for a while,
as it runs during the interrupts part of configuration now,
and all the devices try attach as early as possible, including
any root or boot required disk or keyboard device, which is
what this flag was for.
 1.173  18-Sep-2018  mrg deal with partial attach failures in usb_attach vs usb_detach aka PR 53598.

- make sure xhci's sc->sc_ios is NULL if failure happens.
- rearrange usb_attach() / usb_doattach() to make it simpler to clean up.
- move usb_async_intr softint into usb_once_init(). previously, each USB
controller would start a new one, and leave the old one leaked.
- handle controller interrupts without a bus attached
 1.172  16-Sep-2018  mrg consolidate the handling of polling across HC drivers, and generic USB:
- don't take mutexes if polling
- normalise the code across all drivers
- add some not yet code to block discovery to/from polling
- minor CSE
- adjust comment for usbd_set_polling() to reality now i properly
understand what it is used for and why.

this, with a hack to make RB_ASKNAME to wait 5 seconds allows boot -a
work with USB keyboards. there are still multiple issues remaining:
- discovery and polling need to be mutually exclusive
- attachment of ukbd and wskbd is not handled by config_pending, and
the 5 second delay isn't going to always be enough.
 1.171  02-Aug-2018  riastradh Fix usb_rem_task_wait API.

- Return whether it removed task from queue or not.
. True if it was on the queue and we intercepted it before it ran.
. False if we could not intercept it: either it wasn't queued,
or it already ran. (Up to caller to distinguish these cases.)
- Pass an optional interlock like callout_halt.

While here, simplify.

ok mrg@
 1.170  29-Jul-2018  riastradh New function usb_rem_task_wait(dev, task, queue).

If task is scheduled to run, removes it from the queue. If it may
have already begun to run, waits for it to complete. Caller must
guarantee it will not switch to another queue. If caller guarantees
it will not be scheduled again, then usb_rem_task_wait guarantees it
is not running on return.

This will enable us to fix a litany of bugs in detach where we
currently fail to wait for a pending task.
 1.169  29-Jun-2018  msaitoh Detect USB 3.1.
 1.168  28-Oct-2017  pgoyette branches: 1.168.2; 1.168.4;
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...

(As proposed on tech-kern@ with additional changes and enhancements.)

Details of changes:

* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)

* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.

* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.

* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."

* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.

* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).

* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).

* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.

* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.

[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".

[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
 1.167  25-Oct-2017  maya Use C99 initializer for filterops

Mostly done with spatch with touchups for indentation

@@
expression a;
identifier b,c,d;
identifier p;
@@
const struct filterops p =
- { a, b, c, d
+ {
+ .f_isfd = a,
+ .f_attach = b,
+ .f_detach = c,
+ .f_event = d,
};
 1.166  01-Sep-2017  skrll Add a missing break that should have been included in revision 1.163.

Spotted by "sc dying" and reported on current-users
 1.165  19-Jan-2017  skrll branches: 1.165.6;
Pull across xhci(4) improvemnts from nick-nhusb
 1.164  14-Aug-2016  skrll branches: 1.164.2;
Change the SOFTINT level from NET to SERIAL for the USB softint handler.
This gives the callback a chance of running when another softint handler
at SOFTINT_NET has blocked holding a lock, e.g. softnet_lock and most of
the network stack.

Should fix/help
kern/49065 - ifconfig tun0 ... sequence locks up system / lockup: softnet_lock held across usb xfr
kern/50491 - unkillable wait in usbd_transfer while using usmsc0 on raspberry pi 2
kern/51395 - USB Ethernet makes xhci hang

and probably others
 1.163  26-Apr-2016  skrll branches: 1.163.2;
Debug
 1.162  23-Apr-2016  skrll Merge nick-nhusb

- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
 1.161  06-Jan-2016  skrll Get the iManufacturer, iProduct, and iSerialNumber strings before probing
for drivers and cache them for later use. This reduces bus transactions
and fixes attachment for at least two of my umass(4)s.
 1.160  29-Oct-2015  mrg eliminate USBHIST as a define/option. it was entangled with USB_DEBUG
and only referenced a handful of times. rename any usage in configs.

fixes recent build problems i introduced with the previous files.usb
change.
 1.159  30-May-2015  skrll Make the non-USBHIST case compile
 1.158  30-May-2015  skrll Add missing KERNHIST_LINK_STATIC(usbhist). Pointed out by t-hash.
 1.157  28-May-2015  skrll Static initialise usbhist - it can be used by controller drivers, i.e.
before usb attaches.
 1.156  12-Sep-2014  skrll branches: 1.156.2;
Improve USB debugging with USBHIST based on KERNHIST.

Convert some DPRINTFs to USBHIST_LOG and allow usbdebug, ehcidebug and
umassdebug to be changed via sysctl.

Remove the #define mess in usb.h.

This was started by mrg@ and updated by reinoud@
 1.155  12-Aug-2014  skrll Some USB3 / SS support - baby steps. From Takahiro HAYASHI.
 1.154  25-Jul-2014  dholland branches: 1.154.2;
Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.153  22-Jul-2014  riastradh Remove (harmless) redundant assignment of task->queue in usb_add_task.
 1.152  17-Jul-2014  riastradh Need <sys/atomic.h> for atomic_cas_uint.
 1.151  17-Jul-2014  riastradh Don't touch task after calling it.
 1.150  17-Jul-2014  riastradh Fix usb task queue locking.
 1.149  16-Mar-2014  dholland branches: 1.149.2;
Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
 1.148  09-Nov-2013  skrll Whitespace
 1.147  07-Nov-2013  skrll bus->lock is always available now. Remove the old code that helped when
it wasn't always available.
 1.146  18-Oct-2013  christos move compat var in compat code.
 1.145  12-Oct-2013  christos Pass the device name in, so we can debug what deferred drivers did not work.
 1.144  14-Sep-2013  jakllsch Allow USB_DEVICEINFO on address 0. Needed for the xhci(4) root hub device.
 1.143  13-Sep-2013  jakllsch Establish host controller softint earlier, in usb_attach rather than
usb_doattach.
 1.142  21-Aug-2013  jakllsch Use usbd_errstr instead of printing non-errno(2) error code.
 1.141  21-Aug-2013  jakllsch Use NULL instead of 0 as appropriate.
 1.140  22-Jan-2013  jmcneill branches: 1.140.2;
- Add a USBD_MPSAFE flag to usbd_open_pipe. If not set, acquire KERNEL_LOCK
before invoking xfer callbacks on this pipe.
- Add an extra flags parameter to usb_init_task. If USBD_TASKQ_MPSAFE is not
present, acquire KERNEL_LOCK before invoking the task callback.
 1.139  08-Jan-2013  skrll Improve a comment slightly
 1.138  05-Jan-2013  christos fix debug variables.
- include opt_usb.h in usb.h so that USB_DEBUG gets set properly in it.
- normalize and sort debugging variables
 1.137  05-Jan-2013  christos - need opt_usb.h if depending on USB_DEBUG
- remove trailing whitespace
- add missing KERNEL_RCSID
 1.136  27-Nov-2012  mrg since usb task add/remove is supposed to be callable in any usb
context, make sure the lock is OK for such. ie, not a sleeping lock.
fixes PR#47244.
 1.135  20-Jul-2012  mrg branches: 1.135.2;
now that the task threads are created earlier, move the call to
usb_create_event_thread() back into usb_doattach(), so that eg,
usb_discover() never operates when the root_hub is not setup.

fixes a crash joerg@ reported.
 1.134  20-Jul-2012  mrg usb task fixes, from jared and myself:

- create the task/event threads in usb_attach() so they're more likely
to be ready when usb_doattach() runs

- move the task thread creation into usb_once_init(), instead of having
some other method of only creating them once
 1.133  20-Jul-2012  christos don't access memory outside the array bounds.
 1.132  17-Jul-2012  cegger revert previous. testing queue number requires lock held.
 1.131  17-Jul-2012  cegger Do not mutex_enter() a usb_taskq[-1].
Fixes LOCKDEBUG panic.
 1.130  10-Jun-2012  mrg merge the jmcneill-usbmp branch. many thanks to jared for the
initial work, and every one else who has tested things for me.
this is largely my fault at this point :-)

the main changes are something like:

- usbd_bus_methods{} gains a get_lock() to enable the
host controller to provide a lock for the USB code.
if the lock isn't provided, old-style protection is
(partially) applied.

- ehci/ohci/uhci have been converted to the new
interfaces, including mutex/cv/etc conversion.

- usbdivar.h contains a discussion about locking and
what locks are held for which method calls. more
to come for usbdi(9) here.

- audio drivers (uaudio, umidi, auvitek) have been
properly SMPified now that USB is ready.

- scsi drivers have been modified to take the kernel
lock explicitly before calling into scsi code.

- usb pipes are associated with a lock, that is the
same as the controller lock. (this could be split
up further in the future.)

- several usbfoo_locked() or usbfoo_unlocked()
functions have been added to the usbdi(9) to
enable functionality with or without the USB
lock (per controller) already being held.

the TODO.usbmp file has specific details on what is left to
do, including what device-specific changes should be done now
that the whole framework is ready.
 1.129  11-Mar-2012  mrg minor cleanups from usbmp:
- move usbd_delay_ms() into usbdivar.h in the usb_subr.c section
- minor rcsid fixes
- copyright maintenence
 1.128  06-Mar-2012  mrg pull down from usbmp:

kill the !USE_USE_SOFTINTR code.
 1.127  23-Dec-2011  jakllsch Revert previous due to active usbmp branch(es).
 1.126  22-Dec-2011  jakllsch Adjust-away inconsistent and trailing whitespace.
 1.125  09-Jun-2011  matt branches: 1.125.2; 1.125.6;
Move EHCI_DEBUG, OHCI_DEBUG, UHCI_DEBUG, USB_DEBUG, UHUB_DEBUG to opt_usb.h
(ya dependencies).
Cleanup usb_mem.c a little more and add block tracking code. Help find
corruption problems.
Comment out the SPEED check for ETTF. XXX why doesn't that work right?
 1.124  23-May-2011  joerg branches: 1.124.2;
Don't use the name of the task queue as format string
 1.123  03-Nov-2010  dyoung branches: 1.123.2;
Stop using the compatibility macros USB_ATTACH(), USB_DETACH(),
USB_MATCH(), et cetera. These files produce the same assembly
(according to objdump -d) before and after the change
 1.122  06-Jun-2010  pgoyette Update usbverbose module to use module_autoload() rather than module_load().
Load the module right before each attempt to use its features, and let the
module subsystem handle unloading.
 1.121  29-May-2010  pgoyette Extract USBVERBOSE into a kernel module. The module can be builtin
by defining 'options USBVERBOSE' in the kernel config file (no change
from current behavior), or it can be loaded at boot time on those
architectures that support the boot loader's "load" command.

The module is built for all architectures, whether or not USB support
exists.
 1.120  19-Dec-2009  pooka branches: 1.120.2; 1.120.4;
Don't impose a compile-time dependency on the kernel containing
ohci/uhci just for the sake of setting a debug variable.
 1.119  12-Nov-2009  dyoung Re-order operations in usb_detach() so that if a usb(4) instance's
children will not detach, the instance is not left in an inconsistent
state.

If uhub(4) port is disconnected, forcefully detach the children on
that port.

Simplify detachment hooks. (sc_dying must die!)

Pass along and respect detachment flags, esp. DETACH_FORCE,
throughout.
 1.118  16-Jun-2009  dyoung Use device_t instead of device_ptr_t. Stop using USB_MATCH() and
USB_ATTACH().
 1.117  12-May-2009  cegger struct cfdata * -> cfdata_t, no functional changes intended.
 1.116  07-Apr-2009  dyoung Detach uhub(4) and usb(4) at shutdown.
 1.115  26-May-2008  drochner branches: 1.115.6; 1.115.12;
some cleanup:
-unifdef
-since the roothub attach doesn't use locators, don't call
config_stdsubmatch() -- it is a no-op in that case
-ifsubmatch has configuration and interface always set to useful values,
remove unnecessary checks
-remove now unused locator definitions from shared header
 1.114  25-May-2008  drochner -make the list of USB child devices a (possibly sparse) array rather
than a zero-terminated list; this makes the code simpler and also
hopefully fixes the recent "childdet" botch, see PR kern/38528
-handle the root hub specially a bit earlier, this allows to kick out
the "submatch" functions completely which needed to second-guess
from the port number (where "0" meant root hub")
(we could handle the root hub specially even earlier, but as done
now big parts of the hub emulation code are exercised regularely,
this would bitrot otherwise)
 1.113  28-Apr-2008  martin branches: 1.113.2;
Remove clause 3 and 4 from TNF licenses
 1.112  24-Apr-2008  ad branches: 1.112.2;
Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
 1.111  03-Apr-2008  drochner branches: 1.111.2;
restore error handling in usbopen() (accidentally removed in a recent
commit), should fix a crash reported by Arto Huusko
 1.110  30-Mar-2008  ad Defer USB configuration until interrupts are enabled.
 1.109  28-Mar-2008  drochner split device/softc for USB host controllers and the usb (control)
device,
this is hairy stuff, and I've only tested with uhci/ehci at pci,
please test the rest and report problems
 1.108  08-Mar-2008  ws Don't leak information from kernel to userland.
(Well, the first 2 changes wouldn't really be neccessary,
however, IMHO this makes it clearer why we don't leak.)
 1.107  01-Mar-2008  rmind Welcome to 4.99.55:

- Add a lot of missing selinit() and seldestroy() calls.

- Merge selwakeup() and selnotify() calls into a single selnotify().

- Add an additional 'events' argument to selnotify() call. It will
indicate which event (POLL_IN, POLL_OUT, etc) happen. If unknown,
zero may be used.

Note: please pass appropriate value of 'events' where possible.
Proposed on: <tech-kern>
 1.106  18-Feb-2008  dyoung branches: 1.106.2; 1.106.6;
Use device_t and its accessor functions.

Register _childdetached methods with drivers that attach children.
Wait to set child references to NULL there, instead of doing that
in the detach method.

Replace many uses of USB_DECLARE_DRIVER() with CFATTACH_DECL2().
 1.105  04-Jan-2008  smb Add calls to pmf_deregister on detach.
 1.104  09-Dec-2007  jmcneill branches: 1.104.2;
Merge jmcneill-pm branch.
 1.103  05-Dec-2007  pooka branches: 1.103.2;
Do not "return 1" from kqfilter for errors. That value is passed
directly to the userland caller and results in a mysterious EPERM.
Instead, return EINVAL or something else sensible depending on the
case.
 1.102  01-Dec-2007  jmcneill branches: 1.102.2;
aprintify
 1.101  19-Oct-2007  ad branches: 1.101.2;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.100  08-Oct-2007  ad branches: 1.100.2;
Use the softint API.
 1.99  15-Aug-2007  kiyohara branches: 1.99.2; 1.99.4;
* splsoftusb, IPL_SOFTUSB, and IPL_HARDUSB defines in usbdi.h
-> the current names are confusing (didn't change other drivers)
* fix invalid memory access in usbd_transfer (kern/24636)
-> needed for this driver
* fix USB HC detach race condition (kern/32011)
-> main patch needed for this driver, sc_dying changes in other drivers
not necessary but seem right to me

Patch from Matthew Orgass.
http://mail-index.netbsd.org/tech-kern/2007/06/26/0001.html
 1.98  14-Jul-2007  ad branches: 1.98.2; 1.98.6;
Generic soft interrupts are mandatory.
 1.97  09-Jul-2007  ad Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.96  04-Mar-2007  christos branches: 1.96.2; 1.96.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.95  26-Feb-2007  drochner branches: 1.95.4;
g/c calls to usbd_init()/usbd_finish() which don't have an effect
 1.94  09-Feb-2007  ad branches: 1.94.2;
Merge newlock2 to head.
 1.93  05-Dec-2006  christos fix compilation issues.
 1.92  03-Dec-2006  pavel Restore compatibility of USB_DEVICEINFO ioctl and reads from /dev/usb with
NetBSD 3.x. Patch from Stephan Thesing provided in
http://mail-index.netbsd.org/current-users/2006/03/21/0002.html, with some
modifications by me.
See also
http://mail-index.netbsd.org/current-users/2006/08/29/0017.html

The code is conditionally compiled depending on COMPAT_30.

Also fix a leak of struct usb_event in usbread() introduced while converting
on-stack variables to dynamic allocation.

Reviewed by martin@.
 1.91  16-Nov-2006  christos branches: 1.91.2;
__unused removal on arguments; approved by core.
 1.90  31-Oct-2006  joerg Split the USB task queue into two parts, one for normal device tasks and
one for tasks of the host controllers. This is needed for drivers like
ural(4) that want to do synchronous USB transfers from the task handler.
Before the split timeouts could not be handled correctly as the task
thread was still blocked. From FreeBSD.
 1.89  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.88  03-Sep-2006  christos branches: 1.88.2; 1.88.4;
add missing initializer.
 1.87  09-Jun-2006  christos stack police: don't allocate usb_events on the stack, malloc them directly.
this saves stack and an extra copy.
 1.86  29-Mar-2006  thorpej branches: 1.86.2;
Use device_cfdata().
 1.85  01-Mar-2006  yamt branches: 1.85.2; 1.85.4; 1.85.6;
merge yamt-uio_vmspace branch.

- use vmspace rather than proc or lwp where appropriate.
the latter is more natural to specify an address space.
(and less likely to be abused for random purposes.)
- fix a swdmover race.
 1.84  11-Dec-2005  christos branches: 1.84.2; 1.84.4; 1.84.6;
merge ktrace-lwp.
 1.83  09-Sep-2005  drochner Allow a NULL pointer as argument to usb_get_next_event(), and don't
allocate a "struct usb_event" on stack in usb_add_event().
This gives just enough breathing space that the box doesn't die
immediately from stack overflow when I insert a
ohci0 at cardbus0 dev 0 function 0: Acer Labs M5237 USB 1.1 Host Controller
 1.82  21-Jun-2005  ws branches: 1.82.2;
PR-30566: Poll must not return <sys/errno.h> values.
Start with those places I can easily test.
 1.81  24-Jan-2005  joff branches: 1.81.6; 1.81.8;
Implementation requirements of usb_needs_reattach(), from OpenBSD and required
for atu(4) to do a USB reconnect after firmware upload.
 1.80  07-Nov-2003  wiz branches: 1.80.8;
URL updates, from Jared Yanovich and jmc@openbsd, forwarded by the latter.
 1.79  29-Jun-2003  fvdl branches: 1.79.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.78  28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.77  01-Jan-2003  thorpej Use aprint_normal() in cfprint routines.
 1.76  30-Dec-2002  dsainty extern references to debugging globals that really exist elsewhere
 1.75  26-Nov-2002  christos si_ -> sel_
 1.74  23-Oct-2002  jdolecek merge kqueue branch into -current

kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
 1.73  23-Sep-2002  simonb Remove breaks after returns, unreachable returns and returns after
returns(!).
 1.72  06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.71  01-Jun-2002  lukem SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field). whilst it's O(n),
this mirrors the functionality of SLIST_REMOVE() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
 1.70  09-May-2002  augustss branches: 1.70.2;
Use callout init macro.
 1.69  23-Apr-2002  augustss Check for write permission for some ioctls.
 1.68  20-Feb-2002  christos Prefix structure members to protect them against clashes with eg. c++ keywords.
Suggested by Alfred Perlstein, from FreeBSD, ok'd by augustss
 1.67  11-Feb-2002  augustss Give usbd_do_request_flags() an extra argument for the timeout.
 1.66  03-Feb-2002  augustss Some white space fixes from FreeBSD.
 1.65  03-Jan-2002  augustss Add a DIAGNOSTIC check. From FreeBSD.
 1.64  02-Jan-2002  augustss Add a comment.
 1.63  02-Jan-2002  augustss Fix typo in last commit.
 1.62  02-Jan-2002  augustss Some more usb_proc_ptr changes.
Also some minor stylistic changes.
 1.61  31-Dec-2001  augustss Delay bus enumeration a little in case the controller is a companion
controller. This way the main controller can gain ownership of the port
before enumeration starts.
 1.60  31-Dec-2001  augustss Make a typedef for struct proc to make portingeasier.
 1.59  26-Nov-2001  augustss Change wchan name for usb task thread.
 1.58  20-Nov-2001  augustss Create a special kernel thread to run the usb short lived tasks (instead
of using the device discovery threads).
 1.57  20-Nov-2001  augustss Keep track of device speed for USB 2.0.
 1.56  13-Nov-2001  augustss Add some #endif comments.
 1.55  13-Nov-2001  lukem add RCSIDs
 1.54  09-Nov-2001  augustss Add a debug message.
 1.53  23-Jan-2001  augustss branches: 1.53.2; 1.53.4; 1.53.6; 1.53.8;
Ad function to remove a usb task.
 1.52  21-Jan-2001  augustss Ad a comment.
 1.51  21-Jan-2001  augustss Change the operation of the USB event thread. Before it only performed
USB device discovery, now it can also perform (short) tasks for device
drivers that need a process context, but don't have one.
This is not pretty, but better than using busy-wait in an interrupt context.
 1.50  21-Jan-2001  augustss Remove `#ifdef FreeBSD'; they maintain their own version.
 1.49  21-Jan-2001  augustss Add code to use soft interrupt to handle USB interrupt processing.
Don't enable the code since it doesn't work with the kludgy Ethernet drivers.
 1.48  13-Dec-2000  augustss Don't try to access a device that is being disconnected when generating
the detach event. Fixes (I hope) PR 11713 from itohy@netbsd.org (ITOH Yasufumi).
 1.47  24-Aug-2000  augustss Removed unnecessary variable declaration.
 1.46  07-Jun-2000  thorpej Deal with the fact that tsleep() may be a macro.
 1.45  01-Jun-2000  augustss Bring the coding style into the 80s, i.e., get rid of __P and use
ANSI prototypes and declarations.
 1.44  27-Apr-2000  augustss branches: 1.44.2;
Change my email address.
 1.43  29-Mar-2000  augustss Some OpenBSD portability fixes.
 1.42  27-Mar-2000  augustss Change (almost) all static to Static. The symbol `Static' can then be defined
to `' or `static' depending on if you want to debug or not.
 1.41  16-Mar-2000  augustss Make the USB event queue longer. Mine overflows before the (user-land)
event handler has started. But then I have about 25 devices connected. :)
 1.40  14-Mar-2000  augustss Make sure the USB event thread discovers all devices first time it call
usb_discover().
It should now be possible to have the root NFS mounted over a USB Ethernet
adapter.
 1.39  22-Feb-2000  augustss Prepare a little for having USB interrupt processing done outside the hard
interrupt level (in a thread or a softintr).
No real soft processing done yet.
 1.38  02-Feb-2000  augustss Change the USB event mechanism to include more information about devices
and drivers. Partly from FreeBSD.
 1.37  24-Jan-2000  thorpej Use config_pending.
 1.36  22-Dec-1999  augustss Use the flags `locator' to govern if devices are detected early or
late during cold boot.
 1.35  20-Dec-1999  augustss Make sure tsleep() is not called during cold boot.
 1.34  26-Nov-1999  augustss Make timeout device exploration optional in debug mode.
 1.33  22-Nov-1999  augustss Don't used extern on uhcidebug and ohidebug variables.
 1.32  20-Nov-1999  augustss Join two lines in the attach message.
 1.31  20-Nov-1999  augustss Propagate the USB revision number to the usb driver.
 1.30  18-Nov-1999  augustss Cosmetic changes and some small improvements. From FreeBSD and Nick Hibma.
 1.29  12-Nov-1999  augustss A number of stylistic changes to increase readability (many suggested
by Nick Hibma):
use NULL not 0
declare all local definitions static
rename s/usbd_request/usbd_xfer/ s/reqh/xfer/
rename s/r/err/
use implicit test for no err
KNF
 1.28  13-Oct-1999  augustss branches: 1.28.2; 1.28.4;
Merge in a large batch of changes from Nick Hibma <hibma@skylink.it> so
the USB stack compiles on FreeBSD again.
 1.27  12-Oct-1999  augustss Fix some bugs in USB controller detach code.
 1.26  12-Oct-1999  augustss Add an event mechanism so that a userland process can watch devices come
and go.
 1.25  18-Sep-1999  augustss branches: 1.25.2;
Make sure the HC deactivation is propagated.
 1.24  15-Sep-1999  augustss Move the code around a little and clearly mark how to delay attachment
(during cold boot) until the interrupts are on.
 1.23  15-Sep-1999  augustss Handle the use_polling flag with a lttle more care and only set it if
we are cold booting.
 1.22  15-Sep-1999  augustss Add preliminary (untested) code for detaching the USB host controller
(needed for CardBus based controllers).
 1.21  13-Sep-1999  augustss * Make sure an aborted pipe is marked as not running.
* Start queued request in the right order.
* Insert some more DIAGNOSTIC sanity checks.
 1.20  13-Sep-1999  augustss Rearrange the code a little so we can decide if we are in process
or interrupt context in a reliable way. Mainly used for DIAGNOSTIC.
 1.19  05-Sep-1999  augustss Change the way the `struct device' base part of all driver softc are
declared and accessed to make it more portable. Idea from Nick Hibma, FreeBSD.
No functional changes.
 1.18  28-Aug-1999  augustss Change some 'struct device' to 'bdevice'. From FreeBSD.
 1.17  17-Aug-1999  augustss Make some small changes to make it compile on OpenBSD.
 1.16  14-Aug-1999  augustss Some changes from FreeBSD (no functional differences).
 1.15  02-Aug-1999  augustss Test return values the right way.
 1.14  06-Jul-1999  thorpej Make the kthread API a bit more friendly to loadable kernel modules.
 1.13  30-Jun-1999  augustss Totally redo the way device detach is done. It now uses a kernel event
thread and the config detach method.
Squish a number of space leaks on detach.
 1.12  10-Jan-1999  augustss branches: 1.12.4;
Some minor updates from FreeBSD.
 1.11  08-Jan-1999  augustss Various little fixes from the FreeBSD version.
 1.10  03-Jan-1999  augustss Add a length paarmeter to usbd_do_request_flags().
 1.9  29-Dec-1998  augustss Make it possible to specify the request flags when issuing a raw USB request.
 1.8  28-Dec-1998  augustss Fix typos.
 1.7  26-Dec-1998  augustss Merge changes to make the USB stack work with FreeBSD. The original
diffs from Nick Hibma <n_hibma@freebsd.org>, but with substantial
changes from me.
XXX Not tested on FreeBSD yet.
 1.6  09-Dec-1998  augustss Improvement to the ugen driver.
Better error checking.
Some code rearrengment.
 1.5  25-Nov-1998  augustss Make the copyright header conform to the NetBSD template.
 1.4  21-Sep-1998  augustss Add missing call to usbd_init().
 1.3  01-Aug-1998  augustss Switch from a global flag to tell if the host controller should use
polling to a local one for each controller.
 1.2  25-Jul-1998  augustss Add an ioctl() to get host controller statistics.
 1.1  12-Jul-1998  augustss Add USB support. Supported so far:
* UHCI and OHCI host controllers on PCI
* Hubs
* HID devices withe special drivers for mouse and keyboard
* Printers
 1.12.4.2  02-Aug-1999  thorpej Update from trunk.
 1.12.4.1  01-Jul-1999  thorpej Sync w/ -current.
 1.25.2.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.28.4.1  15-Nov-1999  fvdl Sync with -current
 1.28.2.3  11-Feb-2001  bouyer Sync with HEAD.
 1.28.2.2  13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.28.2.1  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.44.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.53.8.1  12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.53.6.1  07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.53.4.6  10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.53.4.5  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.53.4.4  16-Mar-2002  jdolecek Catch up with -current.
 1.53.4.3  11-Feb-2002  jdolecek Sync w/ -current.
 1.53.4.2  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.53.4.1  08-Sep-2001  thorpej Add kqueue support.
 1.53.2.10  03-Jan-2003  thorpej Sync with HEAD.
 1.53.2.9  11-Dec-2002  thorpej Sync with HEAD.
 1.53.2.8  11-Nov-2002  nathanw Catch up to -current
 1.53.2.7  18-Oct-2002  nathanw Catch up to -current.
 1.53.2.6  17-Sep-2002  nathanw Catch up to -current.
 1.53.2.5  20-Jun-2002  nathanw Catch up to -current.
 1.53.2.4  28-Feb-2002  nathanw Catch up to -current.
 1.53.2.3  11-Jan-2002  nathanw More catchup.
 1.53.2.2  08-Jan-2002  nathanw Catch up to -current.
 1.53.2.1  14-Nov-2001  nathanw Catch up to -current.
 1.70.2.2  20-Jun-2002  gehenna catch up with -current.
 1.70.2.1  16-May-2002  gehenna Add the character device switch.
 1.79.2.6  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.79.2.5  24-Jan-2005  skrll Sync with HEAD.
 1.79.2.4  21-Sep-2004  skrll Fix the sync with head I botched.
 1.79.2.3  18-Sep-2004  skrll Sync with HEAD.
 1.79.2.2  03-Aug-2004  skrll Sync with HEAD
 1.79.2.1  02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.80.8.1  29-Apr-2005  kent sync with -current
 1.81.8.1  24-Mar-2006  riz Pull up following revision(s) (requested by drochner in ticket #1215):
sys/dev/usb/usb.c: revision 1.83
Allow a NULL pointer as argument to usb_get_next_event(), and don't
allocate a "struct usb_event" on stack in usb_add_event().
This gives just enough breathing space that the box doesn't die
immediately from stack overflow when I insert a
ohci0 at cardbus0 dev 0 function 0: Acer Labs M5237 USB 1.1 Host Controller
 1.81.6.1  24-Mar-2006  riz Pull up following revision(s) (requested by drochner in ticket #1215):
sys/dev/usb/usb.c: revision 1.83
Allow a NULL pointer as argument to usb_get_next_event(), and don't
allocate a "struct usb_event" on stack in usb_add_event().
This gives just enough breathing space that the box doesn't die
immediately from stack overflow when I insert a
ohci0 at cardbus0 dev 0 function 0: Acer Labs M5237 USB 1.1 Host Controller
 1.82.2.9  17-Mar-2008  yamt sync with head.
 1.82.2.8  27-Feb-2008  yamt sync with head.
 1.82.2.7  21-Jan-2008  yamt sync with head
 1.82.2.6  07-Dec-2007  yamt sync with head
 1.82.2.5  27-Oct-2007  yamt sync with head.
 1.82.2.4  03-Sep-2007  yamt sync with head.
 1.82.2.3  26-Feb-2007  yamt sync with head.
 1.82.2.2  30-Dec-2006  yamt sync with head.
 1.82.2.1  21-Jun-2006  yamt sync with head.
 1.84.6.1  22-Apr-2006  simonb Sync with head.
 1.84.4.1  09-Sep-2006  rpaulo sync with head
 1.84.2.1  05-Feb-2006  yamt adapt dev/usb.
 1.85.6.1  31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.85.4.1  19-Apr-2006  elad sync with head.
 1.85.2.3  14-Sep-2006  yamt sync with head.
 1.85.2.2  26-Jun-2006  yamt sync with head.
 1.85.2.1  01-Apr-2006  yamt sync with head.
 1.86.2.1  19-Jun-2006  chap Sync with head.
 1.88.4.2  10-Dec-2006  yamt sync with head.
 1.88.4.1  22-Oct-2006  yamt sync with head
 1.88.2.3  19-Jan-2007  ad Acquire proclist_mutex before sending signals.
 1.88.2.2  12-Jan-2007  ad Sync with head.
 1.88.2.1  18-Nov-2006  ad Sync with head.
 1.91.2.1  06-Apr-2007  bouyer Pull up following revision(s) (requested by pavel in ticket #556):
sys/dev/usb/ugen.c: revision 1.89
sys/dev/usb/usb.c: revisions 1.92, 1.93
sys/dev/usb/usb_subr.c: revision 1.139, 1.140
sys/dev/usb/usb.h: revision 1.75
sys/dev/usb/usbdi.h: revisions 1.71, 1.72
sys/dev/usb/usbdi.c: revision 1.115, 1.116
sys/dev/usb/uhid.c: revision 1.73
Restore compatibility of USB_DEVICEINFO ioctl and reads from /dev/usb with
NetBSD 3.x. The code is conditionally compiled depending on COMPAT_30.
 1.94.2.2  12-Mar-2007  rmind Sync with HEAD.
 1.94.2.1  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.95.4.3  22-Jun-2007  itohy - Introduce USBD_CALLBACK_AS_TASK flag, which causes the callback function
is called as a USB_TASKQ_DRIVER task, with thread context.
This makes sharing Ethernet drivers with FreeBSD (that requires context
for some network-related code) much easier.
The flag is not used by NetBSD/OpenBSD for now.

- Rename xfer->async_task as xfer->task, now used by both async xfer and the
callback above.

- Use 0 as idle task queue ID (definition USB_TASKQ_IDLE added), and
increase USB_TASKQ_HC and USB_TASKQ_DRIVER accordingly.
This makes passing zero-initialized (but not initialized by usb_init_task())
usb_task to usb_rem_task() be ignored, rather than panic the system.
 1.95.4.2  17-Jun-2007  itohy - Pullup 1.96 in a different way.
- Use macro to set vmspace of uio for portability.
 1.95.4.1  22-May-2007  itohy Overhaul of USB stack, mostly DMA related

This applies to NetBSD 4.99.13 (March 1, 2007)

usbdi(9) interface is based on FreeBSD version, excluding
- removal of portability code

Patch most NetBSD changes, excluding
- DMA memory "reserve", since we don't need contiguous buffers any longer
- volatiles in DMA structure, since it should not be needed
with proper bus_dmamap_sync(9)s

DMA/non-DMA memory management overhaul
- Move all DMA related code to usb_mem.[ch]
(add usb_alloc_buffer_dma(), usb_free_buffer_dma(), etc.).
XXX Should usb_mem.[ch] be renamed as usb_mem_dma.[ch] ?
- Add corresponding non-DMA code to usb_mem_nodma.[ch] .
Currently just use malloc(9).
- Above files are conditionally used by config framework (added
attributes to conf/files and dev/usb/files.usb).
- Add diagnostic panics when resource allocation is requested
on interrupt context.
- Change memory allocations (that require context) from NOWAIT to WAITOK.

Allocate DMA/non-DMA buffer per host interface, not globally.
advantage: Buffers can be freed on detaching host interface.
Activity of a host interface does not affect others.
disadvantages: It possibly consumes more memory.

API changes
- usbd_alloc_xfer() is changed:
old: usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle dev);
new: usbd_xfer_handle usbd_alloc_xfer(usbd_device_handle dev,
usbd_pipe_handle pipe);
- pipe argument of usbd_setup_*xfer() are now unused
XXX the pipe argument should be removed?
- add mapping APIs
- async request will be processed as a task (kernel thread context),
and delayed to some extent
- usbdivar.h: struct usbd_xfer: renamed a member "allocbuf" to "hcbuffer"
(mapped/allocated/refered buffer for HCI driver)
- usb_port.h: change usb_proc_ptr from struct ptoc * to struct lwp *
- usb_port.h: add usb_sigproc_ptr for psignal(9) (struct proc *)
- usb.h: add UE_MAXPKTSZ(ep) and UE_MAXPKTSZ_MASK macros for USB 2.0

changes to USB device drivers
- atu, aue, axe, cdce, cue, kue, rum, udav, upl, ural, url,
uaudio, ubt, ucom, ugen, uhidev, uirda, ulpt, umidi, urio,
uscanner, ustir, utoppy:
* catch up API change of usbd_alloc_xfer()
- umass, usscanner:
* catch up API change of usbd_alloc_xfer()
* eliminate memory copy for large transfer

ohci
- free resources on detach
- add lots of bus_dmamap_sync() operations
- simplify the code of loading std chain
- rewrite code of looking up TD/ITD from DMA addr by using allocation chunk
- add workaround for CMD Tech 670 and 673 chipsets
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf

slhci
- allocate xfer and slhci_xfer at once, and simplify relevant code
- add slhci_detach()
- remove second arg of slhci_attach() since it is the same as the first arg.
- add support for "mapping" (no, it doesn't map since it doesn't do DMA)
buffer and mbuf
- add pcmcia frontend
- NOT TESTED, missing hardware

ehci
- add lots of bus_dmamap_sync() operations, possibly too many
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf
- done only simple test

uhci
- add lots of bus_dmamap_sync() operations, possibly too many
- make sure resources are not allocated in interrupt context
- add support for mapping buffer and mbuf

To do
- review, test, debug
- rewrite network drivers to utilize usbd_map_buffer_mbuf()
- rewrite uaudio(4) to eliminate memcpy
- "pipe" argument of usbd_setup_*xfer() should eventually be removed
 1.96.4.1  11-Jul-2007  mjf Sync with head.
 1.96.2.6  23-Oct-2007  ad Sync with head.
 1.96.2.5  20-Aug-2007  ad Sync with HEAD.
 1.96.2.4  15-Jul-2007  ad Sync with head.
 1.96.2.3  17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.96.2.2  13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.96.2.1  09-Apr-2007  ad - Add two new arguments to kthread_create1: pri_t pri, bool mpsafe.
- Fork kthreads off proc0 as new LWPs, not new processes.
 1.98.6.7  09-Dec-2007  jmcneill Sync with HEAD.
 1.98.6.6  08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.98.6.5  01-Dec-2007  jmcneill Sync with HEAD.
 1.98.6.4  06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.98.6.3  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.98.6.2  19-Oct-2007  jmcneill Register generic power handler at attach time.
 1.98.6.1  16-Aug-2007  jmcneill Sync with HEAD.
 1.98.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.99.4.1  14-Oct-2007  yamt sync with head.
 1.99.2.3  23-Mar-2008  matt sync with HEAD
 1.99.2.2  09-Jan-2008  matt sync with HEAD
 1.99.2.1  06-Nov-2007  matt sync with HEAD
 1.100.2.1  25-Oct-2007  bouyer Sync with HEAD.
 1.101.2.3  18-Feb-2008  mjf Sync with HEAD.
 1.101.2.2  27-Dec-2007  mjf Sync with HEAD.
 1.101.2.1  08-Dec-2007  mjf Sync with HEAD.
 1.102.2.2  26-Dec-2007  ad Sync with head.
 1.102.2.1  08-Dec-2007  ad Sync with head.
 1.103.2.1  11-Dec-2007  yamt sync with head.
 1.104.2.1  08-Jan-2008  bouyer Sync with HEAD
 1.106.6.4  02-Jun-2008  mjf Sync with HEAD.
 1.106.6.3  06-Apr-2008  mjf - after some discussion with agc@ i agreed it would be a good idea to move
device_unregister_* to device_deregister_* to be more like the pmf(9)
functions, especially since a lot of the time the function calls are next
to each other.

- add device_register_name() support for dk(4).
 1.106.6.2  05-Apr-2008  mjf - add "file-system DEVFS" and "pseudo-device devfsctl" to conf/std seeing
as these are always needed.

- convert many, many drivers over to the New Devfs World Order. For a
list of device drivers yet to be converted see,
http://www.netbsd.org/~mjf/devfs-todo.html.

- add a new device_unregister_all(device_t) function to remove all device
names associated with a device_t, which saves us having to construct
device names when the driver is detached.

- add a DEV_AUDIO type for devices.
 1.106.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.106.2.1  24-Mar-2008  keiichi sync with head.
 1.111.2.2  04-Jun-2008  yamt sync with head
 1.111.2.1  18-May-2008  yamt sync with head.
 1.112.2.6  11-Aug-2010  yamt sync with head.
 1.112.2.5  11-Mar-2010  yamt sync with head
 1.112.2.4  20-Jun-2009  yamt sync with head
 1.112.2.3  16-May-2009  yamt sync with head
 1.112.2.2  04-May-2009  yamt sync with head.
 1.112.2.1  16-May-2008  yamt sync with head.
 1.113.2.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.115.12.2  23-Jul-2009  jym Sync with HEAD.
 1.115.12.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.115.6.1  28-Apr-2009  skrll Sync with HEAD.
 1.120.4.5  12-Jun-2011  rmind sync with head
 1.120.4.4  31-May-2011  rmind sync with head
 1.120.4.3  05-Mar-2011  rmind sync with head
 1.120.4.2  03-Jul-2010  rmind sync with head
 1.120.4.1  30-May-2010  rmind sync with head
 1.120.2.2  06-Nov-2010  uebayasi Sync with HEAD.
 1.120.2.1  17-Aug-2010  uebayasi Sync with HEAD.
 1.123.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.124.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.125.6.13  12-Mar-2012  mrg fix detach bugs:
- need to disestablish the ehci softint's.
- need to destroy needs_explore_cv
- note that ehci.c inits locks, but ehci_pci.c destroys them due to the
way that the (pci) front end does softint handling, and can only be
trusted to destroy them. XXX need to fix this, by looking at the many
ehci frontends as well and checking ohci/uhci.
 1.125.6.12  26-Feb-2012  mrg - add some more "XXXSMP ok" tags
- use cpu_softintr_p() instead of checking LP_INTR directly
 1.125.6.11  25-Feb-2012  mrg copyright maintenence.
 1.125.6.10  23-Feb-2012  mrg update a bunch of comments for reality. usb lock isn't a "thread lock",
which is terminology we copied from the audiomp code.
 1.125.6.9  20-Feb-2012  mrg remove the intr_lock from the mp usb api, it wasn't used.
 1.125.6.8  20-Feb-2012  mrg task thread and event threads are both MPSAFE now.
 1.125.6.7  20-Feb-2012  mrg convert usb event code to using a mutex and condvar.
 1.125.6.6  20-Feb-2012  mrg several changes to the MP usb apis, and other misc changes:

- usb_transfer_complete()/usb_insert_transfer()/usb_start_next() all
must have the thread lock held

- (*soft_intr) now is called with the thread lock held unless we are
in polling mode. add a usb_soft_intr() to deal with this

- XXX usbd_set_polling() api exists to increase/decrease the polling
count, but only ukbd uses. everyone else open codes it, but this
should probably be changed

- (*abort) is now called with the thread lock held

- update several comments to not refer to splusb() anymore

- add many more asserts

- use more c99 struct initialisers
 1.125.6.5  09-Dec-2011  mrg - make pipe->close method take the thread lock

- convert usb_taskq to use mutex/cv

- convert needs_explore usage into a cv on the thread lock

- remove KERNEL_*LOCK from uaudio and umidi, since we're supposedly
MPSAFE here now

- use IPL_SCHED instead of IPL_USB (aka biglocked) interrupts

- drop the audio thread lock when calling into usb when it may sleep,
avoiding a deadlock between audiowrite and audioioctl. this fixes
mixerctl -a vs. playing hanging the system
XXX probably need to check this in a bunch more places.
 1.125.6.4  08-Dec-2011  mrg - convert usbd_bus_methods{} and usbd_pipe_methods{} to use
c99 struct initialisers

- move the locks from the pipe to the bus, since we'll need
access to them from bus-level ops

- remove dead-for-years SPLUSBCHECK and replaced it with
asserts that the thread lock is held

- begin to document the locking scheme

- convert usbd_*lock_pipe() into real function-like macros
 1.125.6.3  07-Dec-2011  mrg kill some #ifdef USB_DEBUG with some compiler smarts.
 1.125.6.2  06-Dec-2011  mrg need to ensure kpreempt_disable() for softint_schedule().

fix the locking in ohci_timeout_task(), ohci_device_isoc_start(),
ohci_device_isoc_abort() and ohci_device_isoc_close().

uaudio(4) can still play with these, but mixerctl -a against it will
hang the writer. however, mixerctl continues to run in a tight loop
and the system isn't soft-locked up at this point, an advance from
how it is in -current.
 1.125.6.1  04-Dec-2011  jmcneill branches: 1.125.6.1.2;
Make ehci mpsafe.
 1.125.6.1.2.2  08-Dec-2011  mrg merge a few more changes from the main branch.
 1.125.6.1.2.1  08-Dec-2011  mrg mostly in sync with the branch here now.
 1.125.2.5  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.125.2.4  23-Jan-2013  yamt sync with head
 1.125.2.3  16-Jan-2013  yamt sync with (a bit old) head
 1.125.2.2  30-Oct-2012  yamt sync with head
 1.125.2.1  17-Apr-2012  yamt sync with head
 1.135.2.3  03-Dec-2017  jdolecek update from HEAD
 1.135.2.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.135.2.1  25-Feb-2013  tls resync with head
 1.140.2.2  18-May-2014  rmind sync with head
 1.140.2.1  28-Aug-2013  rmind sync with head
 1.149.2.1  10-Aug-2014  tls Rebase.
 1.154.2.4  08-Aug-2018  martin Pull up following revision(s) (requested by riastradh in ticket #1626):

sys/dev/usb/if_cue.c: revision 1.80
sys/dev/usb/umcs.c: revision 1.11
sys/dev/usb/umcs.c: revision 1.12
sys/dev/usb/if_ural.c: revision 1.56
sys/dev/usb/if_run.c: revision 1.28
sys/dev/usb/if_ural.c: revision 1.57
sys/dev/usb/if_run.c: revision 1.29
sys/dev/usb/uatp.c: revision 1.16
sys/dev/usb/uatp.c: revision 1.17
sys/dev/usb/if_axe.c: revision 1.91
sys/dev/usb/if_axe.c: revision 1.92
sys/dev/usb/if_zyd.c: revision 1.49
sys/dev/usb/if_axen.c: revision 1.15
sys/dev/usb/if_url.c: revision 1.60
sys/dev/usb/if_udav.c: revision 1.54
sys/dev/usb/if_axen.c: revision 1.16
sys/dev/usb/if_udav.c: revision 1.55
sys/dev/usb/if_athn_usb.c: revision 1.28
sys/dev/usb/if_athn_usb.c: revision 1.29
sys/dev/usb/if_urtw.c: revision 1.16
sys/dev/usb/if_urtw.c: revision 1.17
sys/dev/usb/if_cue.c: revision 1.79
sys/dev/usb/if_rum.c: revision 1.62
sys/dev/usb/if_urtwn.c: revision 1.61
sys/dev/usb/if_rum.c: revision 1.63
sys/dev/usb/if_urtwn.c: revision 1.63
sys/dev/usb/usb.c: revision 1.170
sys/dev/usb/usb.c: revision 1.171
sys/dev/usb/if_smsc.c: revision 1.35
sys/dev/usb/if_smsc.c: revision 1.36
sys/dev/usb/if_zyd.c: revision 1.50
sys/dev/usb/if_aue.c: revision 1.144
sys/dev/usb/if_aue.c: revision 1.145
sys/dev/usb/usb_subr.c: revision 1.225
sys/dev/usb/usb_subr.c: revision 1.226
sys/dev/usb/if_upgt.c: revision 1.21
sys/dev/usb/usbdi.h: revision 1.93
sys/dev/usb/if_upgt.c: revision 1.22
sys/dev/usb/if_url.c: revision 1.59
sys/dev/usb/usbdi.h: revision 1.95
sys/dev/usb/if_otus.c: revision 1.34
sys/dev/usb/if_atu.c: revision 1.62
sys/dev/usb/if_otus.c: revision 1.35
sys/dev/usb/if_atu.c: revision 1.63

New function usb_rem_task_wait(dev, task, queue).

If task is scheduled to run, removes it from the queue. If it may
have already begun to run, waits for it to complete. Caller must
guarantee it will not switch to another queue. If caller guarantees
it will not be scheduled again, then usb_rem_task_wait guarantees it
is not running on return.

This will enable us to fix a litany of bugs in detach where we
currently fail to wait for a pending task.

Use usb_rem_task_wait in various drivers.
 1.154.2.3  01-Oct-2017  snj Pull up following revision(s) (requested by skrll in ticket #1502):
sys/dev/usb/usb.c: revision 1.166
Add a missing break that should have been included in revision 1.163.
Spotted by "sc dying" and reported on current-users
 1.154.2.2  05-Apr-2017  snj Pull up following revision(s) (requested by skrll in ticket #1395):
share/man/man4/axe.4: netbsd-7-nhusb
share/man/man4/axen.4: netbsd-7-nhusb
share/man/man4/cdce.4: netbsd-7-nhusb
share/man/man4/uaudio.4: netbsd-7-nhusb
share/man/man4/ucom.4: netbsd-7-nhusb
share/man/man4/uep.4: netbsd-7-nhusb
share/man/man4/urtw.4: netbsd-7-nhusb
share/man/man4/usb.4: netbsd-7-nhusb
share/man/man4/uyap.4: netbsd-7-nhusb
share/man/man4/xhci.4: netbsd-7-nhusb
share/man/man9/usbdi.9: netbsd-7-nhusb
sys/arch/amd64/conf/ALL: netbsd-7-nhusb
sys/arch/amd64/conf/GENERIC: netbsd-7-nhusb
sys/arch/amiga/dev/slhci_zbus.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_otg.c: netbsd-7-nhusb
sys/arch/arm/allwinner/awin_usb.c: netbsd-7-nhusb
sys/arch/arm/amlogic/amlogic_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/at91/at91ohci.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm2835_dwctwo.c: netbsd-7-nhusb
sys/arch/arm/broadcom/bcm53xx_usb.c: netbsd-7-nhusb
sys/arch/arm/ep93xx/epohci.c: netbsd-7-nhusb
sys/arch/arm/gemini/obio_ehci.c: netbsd-7-nhusb
sys/arch/arm/imx/files.imx23: netbsd-7-nhusb
sys/arch/arm/imx/imxusb.c: netbsd-7-nhusb
sys/arch/arm/imx/imxusbreg.h: netbsd-7-nhusb
sys/arch/arm/omap/obio_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/omap3_ehci.c: netbsd-7-nhusb
sys/arch/arm/omap/omapl1x_ohci.c: netbsd-7-nhusb
sys/arch/arm/omap/tiotg.c: netbsd-7-nhusb
sys/arch/arm/s3c2xx0/ohci_s3c24x0.c: netbsd-7-nhusb
sys/arch/arm/samsung/exynos_usb.c: netbsd-7-nhusb
sys/arch/arm/xscale/pxa2x0_ohci.c: netbsd-7-nhusb
sys/arch/arm/zynq/zynq_usb.c: netbsd-7-nhusb
sys/arch/hpcarm/dev/nbp_slhci.c: netbsd-7-nhusb
sys/arch/hpcmips/dev/plumohci.c: netbsd-7-nhusb
sys/arch/i386/conf/ALL: netbsd-7-nhusb
sys/arch/i386/conf/GENERIC: netbsd-7-nhusb
sys/arch/i386/pci/gcscehci.c: netbsd-7-nhusb
sys/arch/luna68k/conf/GENERIC: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahci.c: netbsd-7-nhusb
sys/arch/mips/adm5120/dev/ahcivar.h: netbsd-7-nhusb
sys/arch/mips/alchemy/dev/ohci_aubus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ehci_arbus.c: netbsd-7-nhusb
sys/arch/mips/atheros/dev/ohci_arbus.c: netbsd-7-nhusb
sys/arch/mips/conf/files.adm5120: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ehci.c: netbsd-7-nhusb
sys/arch/mips/ralink/ralink_ohci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ehci.c: netbsd-7-nhusb
sys/arch/mips/rmi/rmixl_ohci.c: netbsd-7-nhusb
sys/arch/playstation2/dev/ohci_sbus.c: netbsd-7-nhusb
sys/arch/powerpc/booke/dev/pq3ehci.c: netbsd-7-nhusb
sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c: netbsd-7-nhusb
sys/arch/x68k/dev/slhci_intio.c: netbsd-7-nhusb
sys/conf/files: netbsd-7-nhusb
sys/dev/cardbus/ehci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/ohci_cardbus.c: netbsd-7-nhusb
sys/dev/cardbus/uhci_cardbus.c: netbsd-7-nhusb
sys/dev/ic/sl811hs.c: netbsd-7-nhusb
sys/dev/ic/sl811hsvar.h: netbsd-7-nhusb
sys/dev/isa/slhci_isa.c: netbsd-7-nhusb
sys/dev/marvell/ehci_mv.c: netbsd-7-nhusb
sys/dev/pci/ehci_pci.c: netbsd-7-nhusb
sys/dev/pci/ohci_pci.c: netbsd-7-nhusb
sys/dev/pci/uhci_pci.c: netbsd-7-nhusb
sys/dev/pci/xhci_pci.c: netbsd-7-nhusb
sys/dev/pcmcia/slhci_pcmcia.c: netbsd-7-nhusb
sys/dev/usb/Makefile.usbdevs: netbsd-7-nhusb
sys/dev/usb/TODO: netbsd-7-nhusb
sys/dev/usb/TODO.usbmp: netbsd-7-nhusb
sys/dev/usb/aubtfwl.c: netbsd-7-nhusb
sys/dev/usb/auvitek.c: netbsd-7-nhusb
sys/dev/usb/auvitek_audio.c: netbsd-7-nhusb
sys/dev/usb/auvitek_dtv.c: netbsd-7-nhusb
sys/dev/usb/auvitek_i2c.c: netbsd-7-nhusb
sys/dev/usb/auvitek_video.c: netbsd-7-nhusb
sys/dev/usb/auvitekvar.h: netbsd-7-nhusb
sys/dev/usb/ehci.c: netbsd-7-nhusb
sys/dev/usb/ehcireg.h: netbsd-7-nhusb
sys/dev/usb/ehcivar.h: netbsd-7-nhusb
sys/dev/usb/emdtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_dtv.c: netbsd-7-nhusb
sys/dev/usb/emdtv_ir.c: netbsd-7-nhusb
sys/dev/usb/emdtvvar.h: netbsd-7-nhusb
sys/dev/usb/ezload.c: netbsd-7-nhusb
sys/dev/usb/ezload.h: netbsd-7-nhusb
sys/dev/usb/files.usb: netbsd-7-nhusb
sys/dev/usb/hid.c: netbsd-7-nhusb
sys/dev/usb/hid.h: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.c: netbsd-7-nhusb
sys/dev/usb/if_athn_usb.h: netbsd-7-nhusb
sys/dev/usb/if_atu.c: netbsd-7-nhusb
sys/dev/usb/if_atureg.h: netbsd-7-nhusb
sys/dev/usb/if_aue.c: netbsd-7-nhusb
sys/dev/usb/if_auereg.h: netbsd-7-nhusb
sys/dev/usb/if_axe.c: netbsd-7-nhusb
sys/dev/usb/if_axen.c: netbsd-7-nhusb
sys/dev/usb/if_axenreg.h: netbsd-7-nhusb
sys/dev/usb/if_axereg.h: netbsd-7-nhusb
sys/dev/usb/if_cdce.c: netbsd-7-nhusb
sys/dev/usb/if_cdcereg.h: netbsd-7-nhusb
sys/dev/usb/if_cue.c: netbsd-7-nhusb
sys/dev/usb/if_cuereg.h: netbsd-7-nhusb
sys/dev/usb/if_kue.c: netbsd-7-nhusb
sys/dev/usb/if_kuereg.h: netbsd-7-nhusb
sys/dev/usb/if_otus.c: netbsd-7-nhusb
sys/dev/usb/if_otusvar.h: netbsd-7-nhusb
sys/dev/usb/if_rum.c: netbsd-7-nhusb
sys/dev/usb/if_rumreg.h: netbsd-7-nhusb
sys/dev/usb/if_rumvar.h: netbsd-7-nhusb
sys/dev/usb/if_run.c: netbsd-7-nhusb
sys/dev/usb/if_runvar.h: netbsd-7-nhusb
sys/dev/usb/if_smsc.c: netbsd-7-nhusb
sys/dev/usb/if_smscreg.h: netbsd-7-nhusb
sys/dev/usb/if_smscvar.h: netbsd-7-nhusb
sys/dev/usb/if_udav.c: netbsd-7-nhusb
sys/dev/usb/if_udavreg.h: netbsd-7-nhusb
sys/dev/usb/if_upgt.c: netbsd-7-nhusb
sys/dev/usb/if_upgtvar.h: netbsd-7-nhusb
sys/dev/usb/if_upl.c: netbsd-7-nhusb
sys/dev/usb/if_ural.c: netbsd-7-nhusb
sys/dev/usb/if_uralreg.h: netbsd-7-nhusb
sys/dev/usb/if_uralvar.h: netbsd-7-nhusb
sys/dev/usb/if_url.c: netbsd-7-nhusb
sys/dev/usb/if_urlreg.h: netbsd-7-nhusb
sys/dev/usb/if_urndis.c: netbsd-7-nhusb
sys/dev/usb/if_urndisreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtw.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn.c: netbsd-7-nhusb
sys/dev/usb/if_urtwn_data.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnreg.h: netbsd-7-nhusb
sys/dev/usb/if_urtwnvar.h: netbsd-7-nhusb
sys/dev/usb/if_urtwreg.h: netbsd-7-nhusb
sys/dev/usb/if_zyd.c: netbsd-7-nhusb
sys/dev/usb/if_zydreg.h: netbsd-7-nhusb
sys/dev/usb/irmce.c: netbsd-7-nhusb
sys/dev/usb/moscom.c: netbsd-7-nhusb
sys/dev/usb/motg.c: netbsd-7-nhusb
sys/dev/usb/motgvar.h: netbsd-7-nhusb
sys/dev/usb/ohci.c: netbsd-7-nhusb
sys/dev/usb/ohcireg.h: netbsd-7-nhusb
sys/dev/usb/ohcivar.h: netbsd-7-nhusb
sys/dev/usb/pseye.c: netbsd-7-nhusb
sys/dev/usb/slurm.c: netbsd-7-nhusb
sys/dev/usb/stuirda.c: netbsd-7-nhusb
sys/dev/usb/u3g.c: netbsd-7-nhusb
sys/dev/usb/uark.c: netbsd-7-nhusb
sys/dev/usb/uatp.c: netbsd-7-nhusb
sys/dev/usb/uaudio.c: netbsd-7-nhusb
sys/dev/usb/uberry.c: netbsd-7-nhusb
sys/dev/usb/ubsa.c: netbsd-7-nhusb
sys/dev/usb/ubsa_common.c: netbsd-7-nhusb
sys/dev/usb/ubsavar.h: netbsd-7-nhusb
sys/dev/usb/ubt.c: netbsd-7-nhusb
sys/dev/usb/uchcom.c: netbsd-7-nhusb
sys/dev/usb/ucom.c: netbsd-7-nhusb
sys/dev/usb/ucomvar.h: netbsd-7-nhusb
sys/dev/usb/ucycom.c: netbsd-7-nhusb
sys/dev/usb/udl.c: netbsd-7-nhusb
sys/dev/usb/udl.h: netbsd-7-nhusb
sys/dev/usb/udsbr.c: netbsd-7-nhusb
sys/dev/usb/udsir.c: netbsd-7-nhusb
sys/dev/usb/uep.c: netbsd-7-nhusb
sys/dev/usb/uftdi.c: netbsd-7-nhusb
sys/dev/usb/uftdireg.h: netbsd-7-nhusb
sys/dev/usb/ugen.c: netbsd-7-nhusb
sys/dev/usb/ugensa.c: netbsd-7-nhusb
sys/dev/usb/uhci.c: netbsd-7-nhusb
sys/dev/usb/uhcireg.h: netbsd-7-nhusb
sys/dev/usb/uhcivar.h: netbsd-7-nhusb
sys/dev/usb/uhid.c: netbsd-7-nhusb
sys/dev/usb/uhidev.c: netbsd-7-nhusb
sys/dev/usb/uhidev.h: netbsd-7-nhusb
sys/dev/usb/uhmodem.c: netbsd-7-nhusb
sys/dev/usb/uhso.c: netbsd-7-nhusb
sys/dev/usb/uhub.c: netbsd-7-nhusb
sys/dev/usb/uipad.c: netbsd-7-nhusb
sys/dev/usb/uipaq.c: netbsd-7-nhusb
sys/dev/usb/uirda.c: netbsd-7-nhusb
sys/dev/usb/uirdavar.h: netbsd-7-nhusb
sys/dev/usb/ukbd.c: netbsd-7-nhusb
sys/dev/usb/ukbdmap.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.c: netbsd-7-nhusb
sys/dev/usb/ukyopon.h: netbsd-7-nhusb
sys/dev/usb/ulpt.c: netbsd-7-nhusb
sys/dev/usb/umass.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.c: netbsd-7-nhusb
sys/dev/usb/umass_isdata.h: netbsd-7-nhusb
sys/dev/usb/umass_quirks.c: netbsd-7-nhusb
sys/dev/usb/umass_quirks.h: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.c: netbsd-7-nhusb
sys/dev/usb/umass_scsipi.h: netbsd-7-nhusb
sys/dev/usb/umassvar.h: netbsd-7-nhusb
sys/dev/usb/umcs.c: netbsd-7-nhusb
sys/dev/usb/umct.c: netbsd-7-nhusb
sys/dev/usb/umidi.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.c: netbsd-7-nhusb
sys/dev/usb/umidi_quirks.h: netbsd-7-nhusb
sys/dev/usb/umodem.c: netbsd-7-nhusb
sys/dev/usb/umodem_common.c: netbsd-7-nhusb
sys/dev/usb/umodemvar.h: netbsd-7-nhusb
sys/dev/usb/ums.c: netbsd-7-nhusb
sys/dev/usb/uplcom.c: netbsd-7-nhusb
sys/dev/usb/urio.c: netbsd-7-nhusb
sys/dev/usb/urio.h: netbsd-7-nhusb
sys/dev/usb/usb.c: netbsd-7-nhusb
sys/dev/usb/usb.h: netbsd-7-nhusb
sys/dev/usb/usb_mem.c: netbsd-7-nhusb
sys/dev/usb/usb_mem.h: netbsd-7-nhusb
sys/dev/usb/usb_quirks.c: netbsd-7-nhusb
sys/dev/usb/usb_quirks.h: netbsd-7-nhusb
sys/dev/usb/usb_subr.c: netbsd-7-nhusb
sys/dev/usb/usbdevices.config: netbsd-7-nhusb
sys/dev/usb/usbdevs: netbsd-7-nhusb
sys/dev/usb/usbdevs.h: netbsd-7-nhusb
sys/dev/usb/usbdevs_data.h: netbsd-7-nhusb
sys/dev/usb/usbdi.c: netbsd-7-nhusb
sys/dev/usb/usbdi.h: netbsd-7-nhusb
sys/dev/usb/usbdi_util.c: netbsd-7-nhusb
sys/dev/usb/usbdi_util.h: netbsd-7-nhusb
sys/dev/usb/usbdivar.h: netbsd-7-nhusb
sys/dev/usb/usbhid.h: netbsd-7-nhusb
sys/dev/usb/usbhist.h: netbsd-7-nhusb
sys/dev/usb/usbroothub.c: netbsd-7-nhusb
sys/dev/usb/usbroothub.h: netbsd-7-nhusb
sys/dev/usb/usbroothub_subr.c: delete
sys/dev/usb/usbroothub_subr.h: delete
sys/dev/usb/uscanner.c: netbsd-7-nhusb
sys/dev/usb/uslsa.c: netbsd-7-nhusb
sys/dev/usb/usscanner.c: netbsd-7-nhusb
sys/dev/usb/ustir.c: netbsd-7-nhusb
sys/dev/usb/uthum.c: netbsd-7-nhusb
sys/dev/usb/utoppy.c: netbsd-7-nhusb
sys/dev/usb/uts.c: netbsd-7-nhusb
sys/dev/usb/uvideo.c: netbsd-7-nhusb
sys/dev/usb/uvisor.c: netbsd-7-nhusb
sys/dev/usb/uvscom.c: netbsd-7-nhusb
sys/dev/usb/uyap.c: netbsd-7-nhusb
sys/dev/usb/uyap_firmware.h: netbsd-7-nhusb
sys/dev/usb/uyurex.c: netbsd-7-nhusb
sys/dev/usb/x1input_rdesc.h: netbsd-7-nhusb
sys/dev/usb/xhci.c: netbsd-7-nhusb
sys/dev/usb/xhcireg.h: netbsd-7-nhusb
sys/dev/usb/xhcivar.h: netbsd-7-nhusb
sys/dev/usb/xinput_rdesc.h: netbsd-7-nhusb
sys/external/bsd/common/conf/files.linux: netbsd-7-nhusb
sys/external/bsd/common/include/linux/err.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/kernel.h: netbsd-7-nhusb
sys/external/bsd/common/include/linux/workqueue.h: netbsd-7-nhusb
sys/external/bsd/common/linux/linux_work.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/atombios_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/dist/drm/radeon/radeon_legacy_encoders.c: netbsd-7-nhusb
sys/external/bsd/drm2/drm/files.drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/i915drm/files.i915drmkms: netbsd-7-nhusb
sys/external/bsd/drm2/include/linux/err.h: delete
sys/external/bsd/drm2/include/linux/workqueue.h: delete
sys/external/bsd/drm2/linux/files.drmkms_linux: netbsd-7-nhusb
sys/external/bsd/drm2/linux/linux_work.c: delete
sys/external/bsd/dwc2/dwc2.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwc2var.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dwctwo2netbsd: netbsd-7-nhusb
sys/external/bsd/dwc2/conf/files.dwc2: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_core.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_coreintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcd.h: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdddma.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdintr.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hcdqueue.c: netbsd-7-nhusb
sys/external/bsd/dwc2/dist/dwc2_hw.h: netbsd-7-nhusb
sys/modules/drmkms_linux/Makefile: netbsd-7-nhusb
sys/modules/i915drmkms/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libugenhc/ugenhc.c: netbsd-7-nhusb
sys/rump/dev/lib/libusb/Makefile: netbsd-7-nhusb
sys/rump/dev/lib/libusb/USB.ioconf: netbsd-7-nhusb
sys/rump/dev/lib/libusb/usb_at_ugenhc.c: delete
sys/rump/dev/lib/libusb/opt/opt_usb.h: delete
sys/rump/dev/lib/libusb/opt/opt_usbverbose.h: delete
sys/sys/mbuf.h: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.8: netbsd-7-nhusb
usr.sbin/usbdevs/usbdevs.c: netbsd-7-nhusb
Merge netbsd-7-nhusb:
- API / infrastructure changes to support memory management changes.
- Memory management improvements and bug fixes.
- HCDs should now be MP safe
- conversion to KERNHIST based debug
- FS/LS isoc support on ehci(4).
- conversion to kmem(9)
- Some USB 3 support - mostly from Takahiro HAYASHI (t-hash).
- interrupt transfers now get proper DMA operations
- general bug fixes
- kern/48308
- uhub status notification improvements
- umass(4) probe fix (applied to HEAD already)
- ohci(4) short transfer fix
- Change the SOFTINT level from NET to SERIAL for the USB softint handler.
This gives the callback a chance of running when another softint handler
at SOFTINT_NET has blocked holding a lock, e.g. softnet_lock and most of
the network stack.
- kern/49065 - ifconfig tun0 ... sequence locks up system / lockup:
softnet_lock held across usb xfr
- kern/50491 - unkillable wait in usbd_transfer while using usmsc0
on raspberry pi 2
- kern/51395 - USB Ethernet makes xhci hang
- Various improvements to slhci(4)
- Various improvements to dwc2(4)
 1.154.2.1  06-Feb-2016  snj branches: 1.154.2.1.2;
Pull up following revision(s) (requested by skrll in ticket #1097):
sys/dev/usb/usb.c: revision 1.161
sys/dev/usb/usb_subr.c: revisions 1.207, 1.208
sys/dev/usb/usbdivar.h: revision 1.111
sys/dev/usb/xhci.c: revision 1.33
Get the iManufacturer, iProduct, and iSerialNumber strings before probing
for drivers and cache them for later use. This reduces bus transactions
and fixes attachment for at least two of my umass(4)s.
--
Need sys/kmem.h
 1.154.2.1.2.2  26-Jan-2017  skrll Sync with HEAD/nhusb
 1.154.2.1.2.1  06-Sep-2016  skrll First pass at netbsd-7 updated with USB code from HEAD
 1.156.2.17  03-Jan-2017  skrll Improve handling of roothub device and free up a bus address for LS/FS/HS
controllers.
 1.156.2.16  01-Jan-2017  skrll Whitespace
 1.156.2.15  29-Dec-2016  skrll Whitespae
 1.156.2.14  10-Jun-2016  skrll Use SOFTINT_SERIAL for the USB stack (the 'S' stands for serial).

This is a step in the right direction towards fixing

kern/50491: unkillable wait in usbd_transfer while using usmsc0 on
raspberry pi 2

kern/49065: ifconfig tun0 ... sequence locks up system

but further analysis of locking of the usb drivers is required.
 1.156.2.13  29-May-2016  skrll Sync with HEAD
 1.156.2.12  10-Jan-2016  skrll Bring the following change from HEAD

Get the iManufacturer, iProduct, and iSerialNumber strings before probing
for drivers and cache them for later use. This reduces bus transactions
and fixes attachment for at least two of my umass(4)s.
 1.156.2.11  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.156.2.10  29-Sep-2015  skrll sizeof KNF
 1.156.2.9  06-Jun-2015  skrll Sync with HEAD
 1.156.2.8  28-May-2015  skrll Bring usbhist initialisation change across from HEAD
 1.156.2.7  03-Apr-2015  skrll Fix non-USB_DEBUG compile
 1.156.2.6  21-Mar-2015  skrll Convert to USBHIST
 1.156.2.5  19-Mar-2015  skrll Do the same as OpenBSD and get rid of the *_handle typedefs and use
plain structures insteads
 1.156.2.4  05-Dec-2014  skrll KNF. Remove ( ) from return statements.
 1.156.2.3  03-Dec-2014  skrll Replace malloc(9) with kmem(9)
 1.156.2.2  03-Dec-2014  skrll The grand renaming of structure members.

No functional change.
 1.156.2.1  01-Dec-2014  skrll Add prefixes to method structures member names. No functional change.
 1.163.2.1  20-Mar-2017  pgoyette Sync with HEAD
 1.164.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.165.6.6  31-May-2020  martin Pull up following revision(s) (requested by skrll in ticket #1551):

sys/dev/usb/usb.c: revision 1.187

Don't allow open of /dev/usb if there are no attached busses.
PR kern/55303 mutex_vector_enter,512: uninitialized lock
 1.165.6.5  16-Nov-2019  martin Pull up the following revisions, requested by msaitoh in ticket #1443:

sys/arch/arm/nvidia/tegra_xusb.c 1.13-1.14 via patch
sys/dev/pci/xhci_pci.c 1.13
sys/dev/usb/usb.c 1.169
sys/dev/usb/usbdivar.h 1.116
sys/dev/usb/xhci.c 1.93, 1.95, 1.97
sys/dev/usb/xhcireg.h 1.11-1.12

Detect USB 3.1
 1.165.6.4  27-Sep-2018  martin Pull up following revision(s) (requested by mrg in ticket #1037):

sys/dev/usb/uhub.c: revision 1.139
sys/external/bsd/dwc2/dwc2.c: revision 1.55
sys/ddb/db_output.c: revision 1.34
sys/ddb/db_command.c: revision 1.160
sys/dev/usb/ehci.c: revision 1.264
sys/dev/usb/xhci.c: revision 1.99
sys/dev/usb/ehci.c: revision 1.265
sys/kern/subr_userconf.c: revision 1.27
sys/dev/usb/ehcivar.h: revision 1.46
sys/dev/usb/ohci.c: revision 1.287
sys/dev/usb/uhci.c: revision 1.284
sys/dev/usb/usbdi.c: revision 1.178
sys/dev/usb/usb.c: revision 1.172
sys/dev/pci/xhci_pci.c: revision 1.14
sys/dev/usb/usb.c: revision 1.173
sys/dev/usb/usb.c: revision 1.174
share/man/man4/usb.4: revision 1.110
sys/ddb/db_command.c: revision 1.159
sys/dev/usb/usb_subr.c: revision 1.227
sys/dev/usb/uhcivar.h: revision 1.56
(all via patch)

consolidate the handling of polling across HC drivers, and generic USB:
- don't take mutexes if polling
- normalise the code across all drivers
- add some not yet code to block discovery to/from polling
- minor CSE
- adjust comment for usbd_set_polling() to reality now i properly
understand what it is used for and why.

this, with a hack to make RB_ASKNAME to wait 5 seconds allows boot -a
work with USB keyboards. there are still multiple issues remaining:
- discovery and polling need to be mutually exclusive
- attachment of ukbd and wskbd is not handled by config_pending, and
the 5 second delay isn't going to always be enough.

call cnpollc(1) and cnpollc(0) around cngetc().
(christos has a good idea to add a function that does all 3,
and we should switch all the callers in this sequence to use
it (and fix the MD ones missing it still). not all can, as
eg, line-grabbing functions can use cngetsn(), which only
calls cnpollc() twice.)


When this file is used when not building the kernel (eg: /usr/sbin/crash)
make cnpollc() go away.


reorder some struct members to remove holes.


add config_pending usage to uhub and general USB device attachment.
- call config_pending_incr() and config_pending_decr() around attaching
devices against "usbdevif" attribute.

uhub:
- convert sc_explorepending and sc_running to bool. add new sc_first_explore.
- call config_pending_incr() at the start of uhub_attach(). dropped in
uhub_explore(), if this is the first explore.


implement a gross hack to fix "boot -a" on systems with usb keyboards on
systems with ehci handover to uhci (and maybe ohci), and fix a similar
problem for "boot -s".

there is effort to ensure that all devices attached via USB are probed
before RB_ASKNAME or RB_SINGLE attempts to ask any questions on the console,
and largely this works, often by chance, today, for USB disks and root.
i've recently pushed this more into uhub and general USB device attachment
as well, and kept a config_pending reference across the first explore of
a bus. these fix many issues with directly attached hubs.

however, on systems where devices connected to ehci ports are handed over
to a companion uhci or ohci port, it may not be the first, or even second,
bus explore that finds the device finally before attachment, and at this
point all config_pending references are dropped.

there is no direct communication between drivers, the potentials are
looked up but their device_t is only used for generic things like the name,
so informing the correct companion to expect a device and deal with the
config_pending references is not possible without some fairly ugly layer
violations or multi-level callbacks (eg, we have "ehci0", and usually an
the relevant companion, eg, "uhci2", but it is the uhub that uhci2 has
attached that will deal with the device attachment.)

with the above fixes to generic USB code, the disown happens during the
first explore. the hack works by, at this point, checking if (a) root
is not mounted, (b) single user or ask name are set, and (c) if the hack
as not been triggered already. if all 3 conditions are true, then a
config_pending_incr() is called and a callback is triggered for (default)
5 seconds to call config_pending_decr(). ehci detach pauses waiting for
this callback if scheduled.

this allows enough time for the uhub and the ukbd/wskbd to attach before
the RK_ASKROOT prompts appear. testing shows it takes between 1.5 and
2 seconds for the keyboard to appear after the disown occurs.

Index: dev/usb/ehcivar.c
- new sc_compcallout, sc_compcallout, sc_complock, and a state for th
handover hack.

Index: dev/usb/ehci.c
ehci_init():
- use aprint_normal_dev() instead of manual device_xname().
- initialise sc_compcallout, sc_compcallout, sc_complock, and sc_comp_state.
ehci_detach():
- if there are companion controllers, tear own the above, including waiting
if there is a callback scheduled.
ehci_disown_callback():
- new callout to call config_pending_decr() in the the future.
schedule this ca
ehci_disown_sched_callback():
- if booting to single user or asking names, call config_pending_incr() and
schedule the callout above, default 5 second delay.
ehci_disown():
- if disowning a port call ehci_disown_sched_callback().
deal with partial attach failures in usb_attach vs usb_detach aka PR 53598.
- make sure xhci's sc->sc_ios is NULL if failure happens.
- rearrange usb_attach() / usb_doattach() to make it simpler to clean up.
- move usb_async_intr softint into usb_once_init(). previously, each USB
controller would start a new one, and leave the old one leaked.
- handle controller interrupts without a bus attached


remove usb(4)'s "flags 1" code. it has been dead for a while,
as it runs during the interrupts part of configuration now,
and all the devices try attach as early as possible, including
any root or boot required disk or keyboard device, which is
what this flag was for.
 1.165.6.3  08-Aug-2018  martin Pull up following revision(s) (requested by riastradh in ticket #963):

sys/dev/usb/if_cue.c: revision 1.80
sys/dev/usb/umcs.c: revision 1.11
sys/dev/usb/umcs.c: revision 1.12
sys/dev/usb/if_ural.c: revision 1.56
sys/dev/usb/if_run.c: revision 1.28
sys/dev/usb/if_ural.c: revision 1.57
sys/dev/usb/if_run.c: revision 1.29
sys/dev/usb/uatp.c: revision 1.16
sys/dev/usb/uatp.c: revision 1.17
sys/dev/usb/if_axe.c: revision 1.91
sys/dev/usb/if_axe.c: revision 1.92
sys/dev/usb/if_zyd.c: revision 1.49
sys/dev/usb/if_axen.c: revision 1.15
sys/dev/usb/if_url.c: revision 1.60
sys/dev/usb/if_udav.c: revision 1.54
sys/dev/usb/if_axen.c: revision 1.16
sys/dev/usb/if_udav.c: revision 1.55
sys/dev/usb/if_athn_usb.c: revision 1.28
sys/dev/usb/if_athn_usb.c: revision 1.29
sys/dev/usb/if_urtw.c: revision 1.16
sys/dev/usb/if_urtw.c: revision 1.17
sys/dev/usb/if_cue.c: revision 1.79
sys/dev/usb/if_rum.c: revision 1.62
sys/dev/usb/if_urtwn.c: revision 1.61
sys/dev/usb/if_rum.c: revision 1.63
sys/dev/usb/if_urtwn.c: revision 1.63
sys/dev/usb/usb.c: revision 1.170
sys/dev/usb/usb.c: revision 1.171
sys/dev/usb/if_smsc.c: revision 1.35
sys/dev/usb/if_smsc.c: revision 1.36
sys/dev/usb/if_zyd.c: revision 1.50
sys/dev/usb/if_aue.c: revision 1.144
sys/dev/usb/if_aue.c: revision 1.145
sys/dev/usb/usb_subr.c: revision 1.225
sys/dev/usb/usb_subr.c: revision 1.226
sys/dev/usb/if_upgt.c: revision 1.21
sys/dev/usb/usbdi.h: revision 1.93
sys/dev/usb/if_upgt.c: revision 1.22
sys/dev/usb/if_url.c: revision 1.59
sys/dev/usb/usbdi.h: revision 1.95
sys/dev/usb/if_otus.c: revision 1.34
sys/dev/usb/if_atu.c: revision 1.62
sys/dev/usb/if_otus.c: revision 1.35
sys/dev/usb/if_atu.c: revision 1.63

New function usb_rem_task_wait(dev, task, queue).

If task is scheduled to run, removes it from the queue. If it may
have already begun to run, waits for it to complete. Caller must
guarantee it will not switch to another queue. If caller guarantees
it will not be scheduled again, then usb_rem_task_wait guarantees it
is not running on return.

This will enable us to fix a litany of bugs in detach where we
currently fail to wait for a pending task.

Use usb_rem_task_wait in various drivers.
 1.165.6.2  02-Nov-2017  snj Pull up following revision(s) (requested by pgoyette in ticket #335):
share/man/man9/kernhist.9: 1.5-1.8
sys/arch/acorn26/acorn26/pmap.c: 1.39
sys/arch/arm/arm32/fault.c: 1.105 via patch
sys/arch/arm/arm32/pmap.c: 1.350, 1.359
sys/arch/arm/broadcom/bcm2835_bsc.c: 1.7
sys/arch/arm/omap/if_cpsw.c: 1.20
sys/arch/arm/omap/tiotg.c: 1.7
sys/arch/evbarm/conf/RPI2_INSTALL: 1.3
sys/dev/ic/sl811hs.c: 1.98
sys/dev/usb/ehci.c: 1.256
sys/dev/usb/if_axe.c: 1.83
sys/dev/usb/motg.c: 1.18
sys/dev/usb/ohci.c: 1.274
sys/dev/usb/ucom.c: 1.119
sys/dev/usb/uhci.c: 1.277
sys/dev/usb/uhub.c: 1.137
sys/dev/usb/umass.c: 1.160-1.162
sys/dev/usb/umass_quirks.c: 1.100
sys/dev/usb/umass_scsipi.c: 1.55
sys/dev/usb/usb.c: 1.168
sys/dev/usb/usb_mem.c: 1.70
sys/dev/usb/usb_subr.c: 1.221
sys/dev/usb/usbdi.c: 1.175
sys/dev/usb/usbdi_util.c: 1.67-1.70
sys/dev/usb/usbroothub.c: 1.3
sys/dev/usb/xhci.c: 1.75
sys/external/bsd/drm2/dist/drm/i915/i915_gem.c: 1.34
sys/kern/kern_history.c: 1.15
sys/kern/kern_xxx.c: 1.74
sys/kern/vfs_bio.c: 1.275-1.276
sys/miscfs/genfs/genfs_io.c: 1.71
sys/sys/kernhist.h: 1.21
sys/ufs/ffs/ffs_balloc.c: 1.63
sys/ufs/lfs/lfs_vfsops.c: 1.361
sys/ufs/lfs/ulfs_inode.c: 1.21
sys/ufs/lfs/ulfs_vnops.c: 1.52
sys/ufs/ufs/ufs_inode.c: 1.102
sys/ufs/ufs/ufs_vnops.c: 1.239
sys/uvm/pmap/pmap.c: 1.37-1.39
sys/uvm/pmap/pmap_tlb.c: 1.22
sys/uvm/uvm_amap.c: 1.108
sys/uvm/uvm_anon.c: 1.64
sys/uvm/uvm_aobj.c: 1.126
sys/uvm/uvm_bio.c: 1.91
sys/uvm/uvm_device.c: 1.66
sys/uvm/uvm_fault.c: 1.201
sys/uvm/uvm_km.c: 1.144
sys/uvm/uvm_loan.c: 1.85
sys/uvm/uvm_map.c: 1.353
sys/uvm/uvm_page.c: 1.194
sys/uvm/uvm_pager.c: 1.111
sys/uvm/uvm_pdaemon.c: 1.109
sys/uvm/uvm_swap.c: 1.175
sys/uvm/uvm_vnode.c: 1.103
usr.bin/vmstat/vmstat.c: 1.219
Reorder to test for null before null deref in debug code
--
Reorder to test for null before null deref in debug code
--
KNF
--
No need for '\n' in UVMHIST_LOG
--
normalise a BIOHIST log message
--
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3)
format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of
kernhist(9)"
but it is possible that I've missed some of them. I would be glad
to
update any stragglers that anyone identifies.
--
For some reason this single kernel seems to have outgrown its declared
size as a result of the kernhist(9) changes. Bump the size.
XXX The amount of increase may be excessive - anyone with more detailed
XXX knowledge please feel free to further adjust the value
appropriately.
--
Misssed one cast of pointer --> uintptr_t in previous kernhist(9) commit
--
And yet another one. :(
--
Use correct mark-up for NetBSD version.
--
More improvements in grammar and readability.
--
Remove a stray '"' (obvious typo) and add a couple of casts that are
probably needed.
--
And replace an instance of "%p" conversion with "%#jx"
--
Whitespace fix. Give Bl tag table a width. Fix Xr.
 1.165.6.1  04-Sep-2017  snj Pull up following revision(s) (requested by skrll in ticket #262):
sys/dev/usb/usb.c: revision 1.166
Add a missing break that should have been included in revision 1.163.
Spotted by "sc dying" and reported on current-users
 1.168.4.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.168.4.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.168.4.1  10-Jun-2019  christos Sync with HEAD
 1.168.2.11  22-Jan-2019  pgoyette Convert the MODULE_{,VOID_}HOOK_CALL macros to do everything in-line
rather than defining an intermediate hook##call function. Almost
all of the hooks are called only once, and although we lose the
ability of doing things like

if (MODULE_HOOK_CALL(...) == 0) ...

we simplify things quite a bit. With this change, we no longer need
to have both declaration and definition macros, and the definition
no longer needs to have both prototype argument list and a "real"
argument list.

FWIW, the above if now needs to written as

int ret;

MODULE_HOOK_CALL(..., ret);
if (ret == 0) ...

with appropriate use of braces {}.
 1.168.2.10  18-Jan-2019  pgoyette Don't restrict hooks to having only int or void types. Pass the hook's
type to the various macros, as needed.

Allows us to reduce diffs to original in at least one or two places (we
no longer have to provide an additional parameter to the hook routine
for returning a non-int return value).
 1.168.2.9  14-Jan-2019  pgoyette Create a variant of the HOOK macros that handles hook routines of
type void, and use them where appropriate.
 1.168.2.8  13-Jan-2019  pgoyette Remove the HOOK2 versions of the MODULE_HOOK macros. There were
only a few uses, and using them led to some lack of clarity in the
code. Instead, we now use two separate hooks, with names that
make it clear(er) what we're doing.

This also positions us to start unraveling some of the rtsock_50
mess, which will need (at least) five hooks.
 1.168.2.7  30-Sep-2018  pgoyette Ssync with HEAD
 1.168.2.6  29-Sep-2018  pgoyette In MODULE_HOOK_CALL_DECL we don't need to provide the actual argument
list for calling the hook function, nor do we need to provide the
default value (for when the hook has not been set).
 1.168.2.5  18-Sep-2018  pgoyette The COMPAT_HOOK macros were renamed to MODULE_HOOK, adjust all callers
 1.168.2.4  18-Sep-2018  pgoyette Split the COMPAT_CALL_HOOK to separate the declaration from the
implementation. Some hooks are called from multiple source files,
and the old method resulted in duplicate implementations.

Implement MP-safe hooks for the usb_subr_30 code. Pass the helper
functions as arguments to the compat code so it does not have to
determine if the kernel contains usb code.
 1.168.2.3  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.168.2.2  28-Jul-2018  pgoyette Sync with HEAD
 1.168.2.1  29-Mar-2018  pgoyette Split out the usb compat_30 code and add it to the module
 1.179.2.3  31-May-2020  martin Pull up following revision(s) (requested by skrll in ticket #934):

sys/dev/usb/usb.c: revision 1.187

Don't allow open of /dev/usb if there are no attached busses.
PR kern/55303 mutex_vector_enter,512: uninitialized lock
 1.179.2.2  01-Mar-2020  martin Pull up following revision(s) (requested by riastradh in ticket #744):

sys/dev/usb/uhci.c: revision 1.292
sys/dev/usb/uhci.c: revision 1.293
sys/dev/usb/usbdi.h: revision 1.99
sys/dev/usb/motg.c: revision 1.26
sys/dev/usb/motg.c: revision 1.27
sys/dev/usb/motg.c: revision 1.28
sys/dev/usb/motg.c: revision 1.29
sys/external/bsd/dwc2/dwc2.c: revision 1.70
sys/external/bsd/dwc2/dwc2.c: revision 1.71
sys/dev/usb/usb.c: revision 1.181
sys/arch/mips/adm5120/dev/ahci.c: revision 1.20
sys/dev/usb/usb.c: revision 1.182
sys/dev/usb/xhci.c: revision 1.116
sys/dev/usb/xhci.c: revision 1.117
sys/dev/usb/xhci.c: revision 1.118
sys/dev/usb/uhci.c: revision 1.289
sys/dev/usb/usbdivar.h: revision 1.121
sys/dev/usb/usbdi.c: revision 1.190
sys/dev/usb/usbdivar.h: revision 1.122
sys/dev/usb/usbdi.c: revision 1.191
sys/dev/usb/usbdi.c: revision 1.192
sys/external/bsd/dwc2/dwc2var.h: revision 1.7
sys/dev/usb/motg.c: revision 1.30
sys/dev/usb/motg.c: revision 1.31
sys/dev/usb/motg.c: revision 1.32
sys/dev/usb/motg.c: revision 1.33
sys/external/bsd/dwc2/dwc2.c: revision 1.67
sys/external/bsd/dwc2/dwc2.c: revision 1.68
sys/dev/usb/ehci.c: revision 1.270
sys/external/bsd/dwc2/dwc2.c: revision 1.69
sys/dev/usb/usbdi.h: revision 1.100
sys/dev/usb/ehci.c: revision 1.271
sys/arch/mips/adm5120/dev/ahci.c: revision 1.18
sys/dev/usb/usbdi.h: revision 1.101
sys/dev/usb/ehci.c: revision 1.272
sys/dev/ic/sl811hs.c: revision 1.103
sys/arch/mips/adm5120/dev/ahci.c: revision 1.19
sys/dev/usb/ehci.c: revision 1.273
sys/dev/usb/ohci.c: revision 1.293
sys/dev/usb/uhci.c: revision 1.290
sys/dev/usb/ohci.c: revision 1.294
sys/dev/usb/uhci.c: revision 1.291
sys/dev/usb/ohci.c: revision 1.295

Teach usb_rem_task to return whether removed from queue or not.

New function usb_task_pending for diagnostic assertions.
Usable only for negative diagnostic assertions:

KASSERT(!usb_task_pending(dev, task))

If you can think of a better name for this than !usb_task_pending,
I'm all ears.

-

Nothing guarantees xfer's timeout has completed.

Wait for it when we free the xfer.

-


New xfer state variables ux_timeout_set and ux_timeout_reset.

These are needed because:
- The host controller interrupt cannot wait for the callout or task
to finish running.
- Nothing in the USBD API as is waits for the callout or task to
finish running.
- Callers expect to be able to resubmit USB xfers from xfer callbacks
without waiting for anything to finish running.

The variable ux_timeout_set can be used by a host controller to
decide on submission whether to schedule the callout or to ask an
already-scheduled callout or already-queued task to reschedule the
callout, by setting the variable ux_timeout_reset to true.

When the callout or task runs and sees that ux_timeout_reset is true,
rather than queue the task or abort the xfer, it can instead just
schedule the callout anew.

-

Fix steady state of timeouts in ehci.

This is complicated because:
1. There are three ways that an xfer can be completed:
(a) hardware interrupt completes xfer
(b) software decision aborts xfer with USBD_CANCELLED
(c) timeout aborts xfer with USBD_TIMEOUT
2. The timeout abort can't be done in callout because ehci_sync_hc,
called unconditionally by ehci_abort_xfer to wait until the device
has finished using any references to the xfer, may sleep. So we
have to schedule a callout that, when run, will schedule a usb_task.
3. The hardware completion interrupt can't sleep waiting for a callout
or task to finish -- can't use callout_halt or usb_rem_task_wait.
So the callout and usb_task must be able to run _after_ the hardware
completion interrupt, and recognize that they're late to the party.
(Note, though, that usbd_free_xfer does wait for the callout and
task to complete, so there's no danger they may use themselves after
free.)
4. The xfer may resubmitted -- and the timeout may be rescheduled --
immediately after the hardware completion interrupt, _while_ the
callout and/or usb_task may still be scheduled. Specifically, we
may have the following sequence of events:
(a) hardware completion interrupt
(b) callout or usb_task fires
(c) driver resubmits xfer
(d) callout or usb_task acquires lock and looks around dazed and
bewildered at the firehose of events like reading the news in 2019

The mechanism for sorting this out is that we have two bits of state:
- xfer->ux_timeout_set informs the driver, when submitting an xfer and
setting up its timeout, whether either the callout or usb_task is
already scheduled or not.
- xfer->ux_timeout_reset informs the callout or usb_task whether it
should reschedule the callout, because the xfer got resubmitted, or
not.

-

Factor out HCI-independent xfer completion logic.

New API for HCI drivers to synchronize hardware completion
interrupts, synchronous aborts, and asynchronous timeouts:
- When submitting an xfer to hardware, call
usbd_xfer_schedule_timeout(xfer).
- On HCI completion interrupt for xfer completion:
if (!usbd_xfer_trycomplete(xfer))
return; /* timed out or aborted, ignore it */
- In upm_abort methods, call usbd_xfer_abort(xfer).

For HCI drivers that use this API (not needed in drivers that don't,
or for xfers like root intr xfers that don't use it):
- New ubm_abortx method serves role of former *hci_abort_xfer, but
without any logic for wrangling timeouts/callouts/tasks -- caller
in usbd_xfer_abort has already handled them.
- New ubm_dying method, returns true if the device is in the process
of detaching, used by the timeout logic.

Converted and tested:
- ehci
- ohci

Converted and compile-tested:
- ahci (XXX did this ever work?)
- dwc2
- motg (XXX missing usbd_xfer_schedule_timeout in motg_*_start?)
- uhci
- xhci

Not changed:
- slhci (sys/dev/ic/sl811hs.c) -- doesn't use a separate per-xfer
callout for timeouts (XXX but maybe should?)
- ugenhc (sys/rump/dev/lib/libugenhc/ugenhc.c) -- doesn't manage its
own transfer timeouts

-

Fix steady state of root intr xfers.

Why?
- Avoid completing a root intr xfer multiple times in races.
- Avoid potential use-after-free in poll_hub callouts (uhci, ahci).

How?
- Use sc->sc_intr_xfer or equivalent to store only a pending xfer
that has not yet completed -- whether successfully, by timeout, or
by synchronous abort. When any of those happens, set it to null
under the lock, so the xfer is completed only once.
- For hci drivers that use a callout to poll the root hub (uhci, ahci):
. Pass the softc pointer, not the xfer, to the callout, so the
callout is not even tempted to use xfer after free -- if the
callout fires, but the xfer is synchronously aborted before the
callout can do anything, the xfer might be freed by the time the
callout starts to examine it.
. Teach the callout to do nothing if it is callout_pending after it
has fired. This way:
1. completion or synchronous abort can just callout_stop
2. start can just callout_schedule
If the callout had already fired before (1), and doesn't acquire
the bus lock until after (2), it may be tempted to abort the new
root intr xfer just after submission, which would be wrong -- so
instead we just have the callout do nothing if it notices it has
been rescheduled, since it will fire again after the appropriate
time has elapsed.

-

Initialize xfer->ux_status in uhci_root_intr_start.

Otherwise, it will be USBD_NOT_STARTED, so usbd_ar_pipe will skip
calling upm_abort.
Candidate fix for PR kern/54963, same problem as reported at:
href="https://mail-index.NetBSD.org/current-users/2020/02/13/msg037740.html

-

Set ux_isdone in uhci_poll_hub for DIAGNOSTIC.

-

Fix mistakes in previous sloppy change with root intr xfers.
- Make sure ux_status is set to USBD_IN_PROGRESS when started.
Otherwise, if it is still in flight when we abort the pipe,
usbd_ar_pipe will skip calling upm_abort.
- Initialize ux_status under the lock; in principle a completion
interrupt (or a delay) could race with the initialization.
- KASSERT that the xfer is in progress when we're about to complete
it.

Candidate fix for PR kern/54963 for other HCI drivers than uhci.
ok nick
ok phone
(This is the change that nick evidently MEANT to ok when he ok'd the
previous one!)

-

Fix build

-

Fix non-DIAGNOSTIC builds.

-

Fix wrong KASSERT in motg abort.
This has been wrong since last summer when we did the transition to
xfer->ux_status = USBD_CANCELLED earlier.
XXX pullup-9

-

Fix mistakes in timeout/abort/completion changes in motg(4).
- Call usbd_xfer_schedule_timeout so we actually do time out.
- Don't call usbd_xfer_trycomplete until all the data have been
transferred -- it commits to completion, not timeout.
- Use xfer->ux_status != USBD_IN_PROGRESS to test whether, after a
partial write, an xfer has been interrupted or timed out and need
not be continued.
- Remove wrong assertion.

-

Fix mistake in use of usbd_xfer_schedule_timeout in motg.

This code path is used both for xfers that are new, and xfers that
are being done piece by piece and are partway done. For the latter
case, skip usbd_xfer_schedule_timeout so we schedule it only once per
xfer.

-

Simplify some branches and kassert some redundant assignments.
 1.179.2.1  01-Sep-2019  martin Pull up following revision(s) (requested by mrg in ticket #135):

distrib/sets/lists/comp/mi 1.2279
distrib/sets/lists/modules/mi 1.123
share/man/man9/Makefile 1.438
share/man/man9/usbnet.9 1.1-1.9
sys/dev/ic/rndisreg.h 1.3
sys/dev/usb/TODO 1.47-1.52
sys/dev/usb/TODO.usbmp 1.15,1.16
sys/dev/usb/files.usb 1.157-1.167
sys/dev/usb/if_aue.c 1.155-1.161
sys/dev/usb/if_auereg.h 1.30-1.32
sys/dev/usb/if_axe.c 1.103-1.119
sys/dev/usb/if_axen.c 1.51-1.53,1.55-1.67
sys/dev/usb/if_axenreg.h 1.15
sys/dev/usb/if_cdce.c 1.54-1.67
sys/dev/usb/if_cue.c 1.85,1.86
sys/dev/usb/if_cuereg.h 1.23
sys/dev/usb/if_kue.c 1.97-1.100
sys/dev/usb/if_kuereg.h 1.23,1.24
sys/dev/usb/if_mue.c 1.51-1.55
sys/dev/usb/if_muereg.h 1.6
sys/dev/usb/if_muevar.h 1.9
sys/dev/usb/if_smsc.c 1.46-1.61
sys/dev/usb/if_smscreg.h 1.6
sys/dev/usb/if_smscvar.h delete
sys/dev/usb/if_udav.c 1.60-1.71
sys/dev/usb/if_udavreg.h 1.14,1.15
sys/dev/usb/if_upl.c 1.65,1.66
sys/dev/usb/if_ure.c 1.15-1.31
sys/dev/usb/if_urevar.h 1.4,1.5
sys/dev/usb/if_url.c 1.67-1.70
sys/dev/usb/if_urlreg.h 1.14
sys/dev/usb/if_urndis.c 1.22-1.33
sys/dev/usb/if_urtwn.c 1.72
sys/dev/usb/ohci.c 1.290
sys/dev/usb/uhub.c 1.143
sys/dev/usb/usb.c 1.180
sys/dev/usb/usb.h 1.118
sys/dev/usb/usb_mem.c 1.71
sys/dev/usb/usb_subr.c 1.238,1.239
sys/dev/usb/usbdevs 1.772
sys/dev/usb/usbdi.c 1.183,1.186
sys/dev/usb/usbdi.h 1.97
sys/dev/usb/usbdi_util.c 1.75
sys/dev/usb/usbhist.h 1.5,1.6
sys/dev/usb/usbnet.c 1.1-1.24
sys/dev/usb/usbnet.h 1.1-1.14
sys/dev/usb/usbroothub.c 1.9
sys/dev/usb/xhci.c 1.109,1.110
sys/modules/Makefile 1.223
sys/modules/usbnet/Makefile 1.1

usbnet(9): Add common framework for USB network devices.
This bring various safety fixes to all updated drivers,
and includes locking clean up, detach safety when being
used or not, separate rx/tx locks to improve performance,
porting to NET_MPSAFE, many edge/error case bugs in
drivers fixed, as well as resovling PRs 54303 and 54308.
These drivers are converted: axe(4), axen(4), aue(4),
cdce(4), cue(4), kue(4), mue(4), smsc(4), udav(4),
upl(4), ure(4), url(4), and urndis(4).
 1.180.2.1  29-Feb-2020  ad Sync with head.
 1.187.2.2  03-Apr-2021  thorpej Sync with HEAD.
 1.187.2.1  03-Jan-2021  thorpej Sync w/ HEAD.
 1.193.4.1  17-Jun-2021  thorpej Sync w/ HEAD.

RSS XML Feed