Home | History | Annotate | Download | only in usb
History log of /src/sys/dev/usb/ohci.c
RevisionDateAuthorComments
 1.330  31-Mar-2025  riastradh ohci(4): Rework detach logic and justify the ordering.

Handle failed attach when we detach.

This changes the signature of the ohci_detach function, but it is
only ever used by statically linked ohci bus attachments, never by
modules so far, so no kernel revbump.

PR port-amd64/59180: System reboots instead of shutting down
 1.329  22-Sep-2024  jmcneill ohci: Allocate a whole cacheline for all descriptors

Allocate a whole cacheline for all descriptor types such that:

i) they can be alloc'ed without USBMALLOC_COHERENT which can mean they're
now mapped cacheable, and
ii) the "soft" versions are cacheable, and mapped as small as possible.

Patch/idea mainly from Nick (skrll@) with a few fixes from me.
 1.328  28-Apr-2024  skrll Fix some usb_syncmem calls and add some missing ones.
 1.327  28-Apr-2024  skrll Whitespace.
 1.326  05-Apr-2024  riastradh usb *hci: Always set ux_status before usbd_xfer_schedule_timeout.

Add an assert to usbd_xfer_schedule_timeout to enforce this.

Since access to ux_status is serialized by the bus lock, and nothing
releases the bus lock in the interim, this doesn't make a functional
change. But it does reduce confusion by readers, who no longer have
to worry if some callers got the order wrong. It could also now
potentially be factored out in a subsequent commit.
 1.325  09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.324  04-Feb-2024  mrg update my email address.
 1.323  09-Mar-2022  riastradh branches: 1.323.4;
ohci(4): Don't flail around with enabling polling in suspend/resume.

This doesn't work -- polling mode only works when all other CPUs are
quiesced and the current one is running sequentially without
preemption.

Also not clear whether this does anything useful. Maybe we need a
mechanism to block new xfers until resumed, but this wasn't that.
 1.322  09-Mar-2022  riastradh usb: Provisionally release bus lock around ubm_rhctrl.

This isn't quite correct, but it avoids a deadlock:

- *_roothub_ctrl holds bus lock, waits in usb_delay_ms for kpause
- softint waits for bus lock, holds up kpause wakeup

The deadlock is new since recent changes to hold the bus lock over
upm_start/upm_transfer. Making this change regresses to other
problems:

- *_suspend/resume and *_roothub_ctrl often touch the same portsc
registers

- roothub_ctrl_abort needs to wait for ubm_rhctrl to complete.

When the bus lock was held across both, a noop served here, but we
can't hold the bus lock across both, so that doesn't work.

However, these problems -- which we've had for a long time -- seem to
be less bad than the deadlock. So let's avoid the deadlock for now
and then work out another way to serialize suspend/resume/rhctrl and
aborts.

Candidate fix for PR kern/56739.
 1.321  03-Mar-2022  riastradh usb: Hold pipe lock across upm_transfer and upm_start.

This simplifies the code and fixes races with abort. Access to the
pipe's queue is now done exclusively while the pipe is locked.
 1.320  03-Mar-2022  riastradh usb: Factor usb_transfer_complete out of ubm_abortx method.
 1.319  03-Mar-2022  riastradh usb: Factor usb_insert_transfer out of upm_transfer and make private.

Almost every upm_transfer function starts with:

mutex_enter(&sc->sc_lock);
err = usb_insert_transfer(xfer);
mutex_exit(&sc->sc_lock);
if (err)
return err;

Some of them have debug messages sprinkled in here too, or assert
that err == USBD_NORMAL_COMPLETION (alternative is USBD_IN_PROGRESS,
only for pipes with up_running or up_serialise, presumably not
applicable for these types of pipes). Some of them also assert
xfer->ux_status == USBD_NOT_STARTED, which is guaranteed on entry and
preserved by usb_insert_transer.

Exceptions:

- arch/mips/adm5120/dev/ahci.c ahci_device_isoc_transfer just returns
USBD_NORMAL_COMPLETION, but I'm pretty sure this is and always has
been broken anyway, so won't make anything worse (if anything, might
make it better...)

- external/bsd/dwc2/dwc2.c dwc2_device_bulk_transfer and
dwc2_device_isoc_transfer _also_ issue dwc2_device_start(xfer)
under the lock. This is probably a better way to do it, but let's
do it uniformly across all HCIs at once.

- rump/dev/lib/libugenhc/ugenhc.c rumpusb_device_bulk_transfer
sometimes returns USBD_IN_PROGRESS _without_ queueing the transfer,
in the !rump_threads case. Not really sure how this is supposed to
work... If it actually breaks anything, we can figure it out.
 1.318  21-Dec-2021  skrll Change the usb_mem API to take a bus_dma_tag_t in usb_allocmem instead of
a struct usbd_bus *.

This allows an HCD to use more than one tag.
 1.317  24-Jun-2021  mrg turn off ohcidebug by default. none of the other HCs do this.

next up: options to set these by default
 1.316  15-Jun-2021  riastradh ohci(4): Constify a constant debug string table.
 1.315  05-Jan-2021  skrll branches: 1.315.4;
More converstion from usbd_status to int for function error reporting.
This time it's the turn of usb_allocmem.
 1.314  22-Dec-2020  riastradh usb: Omit bogus assertions about struct usbd_pipe::up_intrxfer.

These assertions were only valid for pipes at UE_IN_DIR, UE_INTERRUPT
endpoints created with usbd_open_pipe_intr, which uses up_intrxfer to
pass the struct usbd_xfer object to usbd_close_pipe to free later.

In contrast, for pipes at UE_OUT_DIR, UE_INTERRUPT endpoints,
up_intrxfer is never initialized, so the assertion cannot be right.
In principle we might even have more than one outstanding interrupt
transfer at a time, rendering the point of the assertion moot anyway.

Found by interrupting a uhidev write to a u2f device.

ok nick
 1.313  10-Dec-2020  skrll Another leading space
 1.312  10-Dec-2020  skrll Remove leading space that crept in in the last change
 1.311  09-Dec-2020  skrll Restructure the abort code for TD based transfers (ctrl, bulk, intr).

In PR kern/22646 some TDs can be on the done queue when the abort start
and, if this is the case, they need to processed after the WDH interrupt.
Instead of waiting for WDH we release TDs that have been touched by the
HC and replace them with new ones. Once WDH happens the floating TDs
will be returned to the free list.

Also addresses the issue seen in PR kern/55835

Thanks to both Andreas Gustafsson and Edgar Fuß for testing. Apologies to
Andreas Gustafsson for not committing this to HEAD for 4y6m.w
 1.310  03-Jun-2020  skrll branches: 1.310.2;
Convert ohcireg.h to __BITS. NFCI.
 1.309  26-May-2020  skrll Copyright maintenance
 1.308  24-May-2020  skrll Be more careful with OHCI_PAGE limitations in ohci_reset_std_chain and
ohci_device_isoc_enter

Enable USBMALLOC_MULTISEG
 1.307  19-May-2020  jakllsch ohci(4): always use usb_syncmem() when reading from HCCA
 1.306  19-May-2020  jakllsch ohci_device_isoc_done(): use ux_length rather than ux_bufsize

For consistency. Nick may have missed this in previous because I'd
unexpectedly adjusted it.
 1.305  15-May-2020  skrll Use ux_length in isoc usb_syncmem. Missed in previous commit.
 1.304  15-May-2020  skrll Update ux_length in usbd_setup_isoc_xfer and use this to usb_syncmem
in the HCDs
 1.303  13-May-2020  jakllsch Use ux_bufsize rather than ux_length in isoc path usb_syncmem calls.

ux_length is always 0 for isoc pipes, so it could not be used here.

To do: revisit this for other host controllers, uhci and ehci in particular?
 1.302  13-May-2020  jakllsch ohci_alloc_sed() returns a pointer, so use NULL rather than 0 on bail-out
 1.301  05-Apr-2020  skrll Switch USB to use non-coherent buffers for data transfers in the
same way as OpenBSD.

The use of coherent (uncacheable on ARM and other arches) mappings
for transfer buffers impacts performance, espcially where memcpys
are involved.

Audit the necessary usb_syncmem operations - a few were missing.
 1.300  14-Mar-2020  christos revert the 0x% -> %# change for fixed width formats pointed out by uwe.
 1.299  13-Mar-2020  christos PR/55068: sc.dying: Fix printf formats:
- no %s/%p for kernel log
- 0x% -> %#
- always %j for kernel log
 1.298  05-Mar-2020  skrll Use howmany. NFC.
 1.297  05-Mar-2020  skrll Remove XXX comment. The sync is done one the last sitd after the loop.
 1.296  21-Feb-2020  skrll Fix a memory leak. Spotted by nat@
 1.295  15-Feb-2020  riastradh 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!)
 1.294  12-Feb-2020  riastradh 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.
 1.293  12-Feb-2020  riastradh 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

- vhci -- times transfers out only on detach; could be adapted easily
if we wanted to use the xfer->ux_callout
 1.292  29-Nov-2019  gson branches: 1.292.2;
Preserve the toggleCarry bit in the Endpoint Descriptor in
ohci_abort_xfer(). Fixes the OHCI part of PR kern/50278.
 1.291  29-Nov-2019  gson Preserve the toggleCarry bit in the Endpoint Descriptor when handling
a DataUnderrun condition. Fixes PR kern/54070.
 1.290  11-Aug-2019  mrg relax an assert to be mutex_owned || polling.

half of the patch i sent for netbsd-8 in PR#54331.
the other half is already applied.
 1.289  22-Mar-2019  mrg branches: 1.289.4;
adjust KASSERT() for sc_lock to handle polling case.
should fix usb kdb in ddb. reported by martin.
 1.288  17-Feb-2019  rin Fix assertion failures triggered by usbdi.c,v 1.182, when devices
are detached.

This is because xfers of USBD_NOT_STARTED can be removed from queue
in an invisible way to host controller drivers.

Discussed on tech-kern.
 1.287  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.286  16-Sep-2018  mrg avoid __diagused.
 1.285  03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.284  09-Aug-2018  prlw1 whitespace
 1.283  09-Aug-2018  prlw1 Sprinkle __diagused
 1.282  09-Aug-2018  mrg pull across abort fixes from nick-nhusb. add more abort fixes, using
ideas from Taylor and Nick, and myself. special thanks to both who
inspired much of the code here, if not wrote it directly.

among other problems, this assert should no longer trigger:

panic: kernel diagnostic assertion "xfer->ux_state == XFER_ONQU" failed: file "/current/src/sys/dev/usb/usbdi.c", line 914

using usbhist i was able to track down my instance of it being related
to userland close() beginning, dropping the sc_lock, and then the usb
softintr completes the transfer normally, and when it is done, the
abort path attempts to re-complete the transfer, and the above assert
is tripped.


changes from nhusb were commited with these logs:
--
Move the struct usb_task to struct usbd_xfer for everyone to use.
--
Set device transfer status to USBD_IN_PROGRESS if start methods succeeds
--
Actually set the transfer status on transfers in ohci_abort_xfer and
the controller is dying
--
Don't supply the lock to callout_halt when polling as it won't be held
--
Improve transfer abort
--
Mark device transfers as USBD_IN_PROGRESS appropriately and improve
abort handling
--
#ifdef DIAGNOSTIC -> KASSERT and add another KASSERT
--
Mark device transfers as USBD_IN_PROGRESS appropriately and improve
abort handling
--

additional changes include:
- initialise the usb abort task in the HCI allocx routine, so that it
can be safely usb_rem_task()'d.
- rework the handling of softintr vs cancellation vs timeout abort based
upon a scheme from Taylor:
when completing a transfer normally:
- if the status is not in progress, it must be cancelled or timed out,
and we should not process this xfer.
- set the status as normal.
- unconditionallly callout_stop() and usb_rem_task(). they're safe and
either aren't running, or will run and do nothing.
- finally call usb_transfer_complete().
when aborting a transfer:
- status should be cancelled or timed out.
- if cancelling, callout_halt and usb_rem_task_wait() to make sure the
timer is either done or cancelled.
- at this point, the ux_status must not be cancelled or timed out, and
if it is not in progress we're done.
- set the status.
- if the controller is dying, just return.
- perform HCI-specific tasks to abort this xfer.
- finally call usb_transfer_complete().
for the timeout and timeout task:
- if the HCI is not dying, and the ux_status is in progress, then
trigger the usb abort task.
- remove UXFER_ABORTWAIT and UXFER_ABORTING.

tested on:
- multiple PC systems with several types of devices: ugen/UPS, ucom,
umass with disk, ssd and cdrom backends, kbd, ms, using uhci, ehci
and xhci.
- erlite3: sd@umass on dwc2.
- sunblade2000: kbd/ms and umass disk on ohci.

untested:
- motg, slhci and ahci. motg has some portion of the new scheme
applied, but slhci and ahci require more study.

future work includes pushing a lot of the common abort handling into
usbdi.c and leaving upm_abort() for HC specific tasks, but this change
is pullup-able to netbsd-7 and netbsd-8 as it does not change any
external API, as well as removing over 100 lines of code while adding
over 30 new asserts.

XXX: pullup-7, pullup-8.
 1.281  06-Jun-2018  maya branches: 1.281.2;
Remove duplicate ;
 1.280  09-Apr-2018  jakllsch Stop potential misuse of vendor names and USB vendor IDs in root hub
device and string descriptors.

Firstly: Few vendors have identical PCI-SIG vendor IDs and USB-IF vendor
IDs. As such, using the PCI vendor ID as a USB vendor ID may trample
on whomever is allocated that USB vendor ID.

Secondly: The vendor of the host controller hardware implementation has
little to nothing to do with our usbroothub implementation. Thus we
should not potentially associate any problems therewith to such third
party.

This change will result in root hubs being identified by USB Vendor ID
0x0000. Root hub vendor string will now be "NetBSD" (or, specifically:
ostype). Product ID (0x0000) and product strings remain unchanged.
 1.279  03-Feb-2018  skrll branches: 1.279.2;
Fix non-DIAGNOSTIC build
 1.278  01-Feb-2018  msaitoh Fix KASSERT panic. When detaching USB host controoler, the following panic
occured:
kernel diagnostic assertion "sc->sc_intrxfer == xfer" failed: file "../../../../dev/usb/ohci.c", line 1720
Clear sc_intrxfer correctly. Adviced by Nick and tested by me.
 1.277  01-Feb-2018  msaitoh - Fix panic on shutdown reported by ozaki-r in PR kern/52961. Use callot_halt()
correctly. Tested by me and OK'd by Nick.
- Disable interrupt in och_shutdown() to prevent hangup. OK'd by Nick.
 1.276  17-Nov-2017  skrll s/PR_NOWAIT/PR_WAITOK/ in HCD allocx (allocate xfer) method
 1.275  28-Oct-2017  skrll Update format to report sC
 1.274  28-Oct-2017  pgoyette 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.273  04-Feb-2017  skrll branches: 1.273.6;
More usb_syncmem tweaks. The main one is sync'ing the entire last TD
returned from ohci_reset_std_chain in control transfers.
 1.272  31-Jan-2017  skrll Improve the usb_syncmem calls in ohci_reset_std_chain.

Might help kern/51928: Errors reading a USB pen drive on macppc 7.99.59
 1.271  30-Jan-2017  skrll Update edataphys if we truncate to the maximum TD length possible
 1.270  30-Jan-2017  skrll Sprinkle some const
 1.269  30-Jan-2017  skrll Simplify an expression using the OHCI_PAGE_OFFSET macro
 1.268  30-Jan-2017  skrll Oops missed a )
 1.267  30-Jan-2017  skrll Apply De Morgan's law to the TD maximum transfer length check logic and
wrap the long line
 1.266  30-Jan-2017  skrll Fix the range check for a single TD maximum transfer length

kern/51528 usb_mem.c panic triggered by mounting USB pen drive
 1.265  04-Dec-2016  skrll branches: 1.265.2;
Whitespace
 1.264  14-Aug-2016  skrll 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.263  10-May-2016  pooka branches: 1.263.2;
sprinkle _KERNEL_OPT
 1.262  09-May-2016  skrll Don't forget to use HTOO32 when adding OHCI_TD_R to td_flags for short
reads.

Should fix problems with BE machines and ohci as reported on
current-users by Michael
 1.261  06-May-2016  skrll usb is attached with config_interrupts so we can G/C the code to support
transfers when this wasn't the case.
 1.260  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.259  13-Mar-2016  skrll KNF
 1.258  30-Nov-2015  skrll Trailing whitespace.
 1.257  30-Nov-2015  skrll Fix 10year old bug of mine affecting interrupt IN transfers.
 1.256  19-Aug-2015  skrll More IPL_SCHED -> IPL_USB
 1.255  30-Mar-2015  skrll Replace an if () panic with KASSERT
 1.254  21-Nov-2014  ozaki-r branches: 1.254.2;
Replace callout_stop with callout_halt

In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.

In this case, we need to pass an interlock to callout_halt to wait for
the callout complete.

Reviewed by riastradh@.
 1.253  05-Aug-2014  skrll branches: 1.253.2;
Remove #ifdef DIAGNOSTIC around sc from the root interrupt abort methods
now it's always used.
 1.252  05-Aug-2014  skrll Prevent the root hub sending updates once the root interrupt abort is
called.
 1.251  05-Aug-2014  skrll Simplify the freeing of the interrupt pipe transfer. Inspired by OpenBSD.
 1.250  17-Feb-2014  skrll branches: 1.250.2;
Re-establish the default pipe after the initial reading of the device
descriptor.

This fixes usbd_new_device so that there is no really need to touch
QHs/EDs in [eo]hci_device_request.

KASSERT the address and maximum packet length now.
 1.249  28-Jan-2014  skrll Support the OHCI in the NS "SUPERIO" chip as found in hppa machines by
twiddling the same bits as Linux.
 1.248  16-Dec-2013  skrll Backout the ED/QH change removal in [eo]hci_device_request.

Reports of the KASSERT firing mean this needs more thought/testing.
 1.247  15-Dec-2013  jakllsch Correct a KASSERT's logic (SET vs. GET).
 1.246  15-Dec-2013  skrll Now that usbd_new_device has been fixed there is no need to touch QHs/EDs
in [eo]hci_device_request.

KASSERT the address and maximum packet length just in case.
 1.245  01-Dec-2013  skrll Adjust KASSERT in device_ctrl_done to polling case.

PR/48213: ehci assertion failure during boot
 1.244  28-Oct-2013  matt Add an explicit initialization of .new_device = NULL
 1.243  15-Sep-2013  martin Remove an unused variable, silence a few unused warnings
 1.242  14-Sep-2013  joerg GC OREAD1 and OREAD2
 1.241  04-Apr-2013  skrll branches: 1.241.4;
Handle errors in ohci_open better.
 1.240  04-Apr-2013  skrll Don't take the bus lock in usbd_transfer_complete when polling.

Sprinkle || polling in KASSERTsw
 1.239  04-Apr-2013  skrll Take the bus lock in ohci_poll as it's assumed by ohci_softintr which
will get called by ohci_intr1... I can enter ddb using usb keyboard
attached via ohci now.
 1.238  04-Apr-2013  skrll Slight formatting tweak ro previous
 1.237  04-Apr-2013  skrll Improve/fix TD flags reporting.
 1.236  03-Apr-2013  skrll Don't leak memory if ohci_alloc_std_chain fails.
 1.235  22-Mar-2013  skrll Fix typo in function name in DIAGNOSTIC prinf by using __func__
 1.234  22-Mar-2013  skrll When dumping the done list in ohci_softintr / OHCI_DEBUG use the correct
list next pointer.

PR/33450 and part of PR/35379.
 1.233  22-Mar-2013  skrll Remove 'return' right after 'goto'
 1.232  29-Jan-2013  christos use a pool instead of a linked list to avoid synchronization problems.
 1.231  22-Jan-2013  jmcneill - 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.230  13-Jan-2013  jmcneill fix missing mutex_exit in error path of ohci_waitintr
 1.229  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.228  05-Jan-2013  christos - need opt_usb.h if depending on USB_DEBUG
- remove trailing whitespace
- add missing KERNEL_RCSID
 1.227  02-Jan-2013  skrll Correct a comment
 1.226  23-Dec-2012  skrll PR/41602

Fix a memory leak when ohci_device_setintr didn't return
USBD_NORMAL_COMPLETION.

ohci_setup_isoc always returns USBD_NORMAL_COMPLETION at the moment so
there's no chance of a leak there.
 1.225  20-Nov-2012  skrll KNF whitespace.
 1.224  10-Jun-2012  mrg branches: 1.224.2;
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.223  11-Mar-2012  mrg pull down from usbmp branch:
- remove usbd_bus{} intr_context member, and replace the checks against
it with cpu_intr_p() and cpu_softintr_p().
 1.222  10-Mar-2012  mrg remove checks against "!curproc".
 1.221  06-Mar-2012  mrg pull down from usbmp branch:

- rename usb_detach_{wake,waitup}() to usb_detach_{wake,waitup}old()
- use some c99 struct .initialisers
 1.220  06-Mar-2012  mrg pull down from usbmp:

kill the !USE_USE_SOFTINTR code.
 1.219  06-Mar-2012  mrg pull down from usbmp branch:

- remove SPLUSBCHECK. it has been broken and disabled for ages.
 1.218  07-Aug-2011  jmcneill branches: 1.218.2; 1.218.6; 1.218.8;
PR# kern/30398: panic in ohci_softintr

If the host controller has a TD that the driver doesn't know about, ignore it
instead of calling panic. Patch from Karl Janmar.
 1.217  30-Jul-2011  jmcneill PR# port-i386/18818: cannot enter ddb with usb keyboard

- ohci: when polling, make sure sc_eintrs has the OHCI_WDH flag set
otherwise ohci_intr1 won't actually read data
- usbdi: kick the host controller by calling its soft_intr callback when
switching out of polling mode too

DDB with a USB keyboard works for me now with ohci.
 1.216  09-Jun-2011  matt 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.215  28-May-2011  tsutsui branches: 1.215.2;
Revert changes for PR kern/44907
http://mail-index.NetBSD.org/source-changes/2011/05/27/msg022584.html
for now. It might cause a panic in ehci_freex() on device detach
as reported by Paul Goyette on current-users@.
 1.214  27-May-2011  jakllsch Data toggle accounting for endpoints on OHCI.
 1.213  27-May-2011  tsutsui Apply patch in PR kern/44907 (crash due to race in ehci.c):
- make sure to remove abort_task in ehci_freex
- always initialize abort_task in ehci_allocx,
not in ehci_timeout just before adding the task
Also apply similar fixes to ohci and uhci.

XXX: should we also call abort_task handler before removing it from queue
if *hci_freex() is called for usbd_xfer_handle with queued abort_task?
 1.212  22-Dec-2010  macallan branches: 1.212.2;
don't disable interrpts in ohci_intr1 - now USB works again on my Blade 2500
( hi gimpy )
 1.211  15-Dec-2010  matt Slighty tweak the interrupt debug printfs.
 1.210  13-Nov-2010  uebayasi Don't pull in the whole uvm(9) API to access only PAGE_SIZE and
some other constants. These are provided by sys/param.h now.
 1.209  03-Nov-2010  dyoung 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.208  09-Jun-2010  pgoyette Revert previous - it was committed unintentionally along with other changes.
 1.207  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.206  24-Feb-2010  dyoung branches: 1.206.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.205  08-Jan-2010  dyoung branches: 1.205.2;
Expand PMF_FN_* macros.
 1.204  08-Jan-2010  martin Fix memory barrier in a debug function
 1.203  12-Nov-2009  dyoung Simplify activation hook. (sc_dying must die!)

unifdef -D__NetBSD__ -U__FreeBSD__ -U__OpenBSD__.
 1.202  12-Nov-2009  uebayasi Comment & whitespace.
 1.201  01-Nov-2009  uebayasi Update referencial URLs.
 1.200  16-Oct-2009  enami Since the aprint_normal_dev() several lines above prints a space
after the device name, no need to prepend the space here.
 1.199  01-Sep-2009  jmcneill aprint-ify.
 1.198  18-Apr-2009  cegger Initialize callout and lists before we check for errors.
This fixes crashes in ohci_detach() when ohci_init() failed.
 1.197  16-Dec-2008  christos branches: 1.197.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.196  13-Aug-2008  drochner branches: 1.196.2; 1.196.4; 1.196.14;
free memory on detach, fixes memory leak, from Andreas Jacobs per
PR kern/39322
 1.195  28-Jun-2008  bouyer branches: 1.195.2;
Add appropriate bus_dmamap_sync() calls to uhci(4), ohci(4) and ehci(4),
as proposed on tech-kern@.
While all DMA memory used in the USB framework is mapped BUS_DMAMAP_COHERENT
(including data memory, which is memcpy'd from/to USB-private buffers),
the CPU can reorder loads or stores from/to main memory, causing the
controller to have an incoherent view of the DMA descriptors lists for a
short time. bus_dmamap_sync() should contain memory barriers that prevents
the CPU from reordering load/store. Note that BUS_DMAMAP_COHERENT is
still required for the DMA descriptor lists - these can't work properly
with software cache coherency.
This fixes "host controller process error/host controller halted" errors
I'm occasionally seeing with a umodem device on uhci on x86.
Thanks to Michael Lorenz for testing it on his O2, and Izumi Tsutsui on
his Cobalt Qube 2700.
 1.194  04-Jun-2008  nonaka branches: 1.194.2;
Added missing splx() at ohci_resume().
 1.193  21-May-2008  drochner fix argument to usb_setup_reserve() (called from USB host adapter drivers)
to be device_t consistently, from Quentin Garnier
 1.192  28-Apr-2008  martin branches: 1.192.2;
Remove clause 3 and 4 from TNF licenses
 1.191  29-Mar-2008  nakayama branches: 1.191.2; 1.191.4;
Fix ohci brokenness in previous commit.
 1.190  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.189  07-Mar-2008  dyoung Use device_t and accessors.

In ohci_{pci,cardbus}_attach, do not get the device_t by casting
the softc to void *, but use `self' instead.
 1.188  07-Mar-2008  dyoung Register the shutdown hook using pmf_device_register1().
 1.187  22-Feb-2008  dyoung Add method to detach children.

Temporary: use PMF_FN_PROTO, PMF_FN_ARGS.
 1.186  03-Feb-2008  drochner branches: 1.186.2; 1.186.6;
share some code for USB root hub emulation which is common in the 3
host controller implementations, start with two little functions
which fake up string descriptors (which were inconststent, language
table fetching didn't interoperate with other code in the tree)
 1.185  09-Dec-2007  jmcneill Merge jmcneill-pm branch.
 1.184  19-Oct-2007  ad branches: 1.184.2; 1.184.4; 1.184.6;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.183  15-Aug-2007  kiyohara branches: 1.183.2; 1.183.6;
* 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.182  26-Feb-2007  drochner branches: 1.182.4; 1.182.12; 1.182.14; 1.182.18;
-in root hub emulation, return a sane value as language code
-constify "methods" tables and (partly) descriptor templates
 1.181  10-Feb-2007  mlelstv branches: 1.181.2;
The diagnostic code doesn't track busy_free correctly when a
device gets removed. However, when the diagnostic check fails,
it is much better to complete the free operation than to abort
it, because this just causes an infinite loop.
 1.180  19-Jan-2007  drochner Kill the "bus powered" bit in the configuration descriptor. This doesn't
exist in newer spec revisions, and is recommended to be set to 1.
So call it _MBO and also use it in the fake root hub descriptors, just
for sanity, even if nothing ever looks at it.
 1.179  16-Nov-2006  christos branches: 1.179.2;
__unused removal on arguments; approved by core.
 1.178  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.177  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.176  24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.175  03-Sep-2006  christos branches: 1.175.2; 1.175.4;
use c99 initializers
 1.174  12-May-2006  mrg make [OU]READ[124]() real inline functions instead of macros.
 1.173  15-Apr-2006  christos Revert previous panic change, I'll fix it differently.
 1.172  14-Apr-2006  christos Coverity CID 1115: It is quite pointless to have a DIAGNOSTIC panic that
checks a variable for being NULL, and if we are not in DIAGNOSTIC code, to
just dereference it causing a crash!
 1.171  14-Apr-2006  christos Coverity CID 1132: avoid NULL derefs.
 1.170  30-Mar-2006  christos If dying, return after doing the software part [as noted in the comment
but not done]. Pointed out by Greg Troxel.
 1.169  19-Dec-2005  tron branches: 1.169.4; 1.169.6; 1.169.8; 1.169.10; 1.169.12;
Make OHCI work on Au1500 systems running in big-endian mode.
Patch contributed by Garrett D'Amore in PR port-evbmips/31912.
 1.168  14-Nov-2005  augustss Make it possible to decide endianess dynamically. From port-evbmips/31912
by "Garrett D'Amore" <garrett_damore@tadpole.com>.
 1.167  18-Jul-2005  augustss branches: 1.167.6;
Make sure we don't enable host controller interrupts until all
initialization is finished.
 1.166  31-May-2005  drochner branches: 1.166.2;
cast-qual fallout
 1.165  28-May-2005  skrll Fix interrupt out transfers.

Reviewed by Lennart.
 1.164  08-May-2005  augustss Only look at USBD_FORCE_SHORT_XFER for writes.
 1.163  01-May-2005  augustss In eohci_waitintr, xfer->timeout is in ms, not hz.

From OpenBSD.
 1.162  01-May-2005  augustss Fix some spelling errors.

From OpenBSD.
 1.161  01-May-2005  augustss Preserve any configuration data that may have been set by SMM/BIOS over
chip reset.

From OpenBSD.
 1.160  01-May-2005  augustss If the SMM driver had enabled ownership change interrupts, re-enable them
temporarily before we attempt to take control.

From OpenBSD.
 1.159  30-Apr-2005  augustss Fix a race condition in xfer abort. Derived from a FreeBSD patch.

An xfer could be aborted twice (which means that the second abort might
access deallocated memory). This happened when an xfer timed out and
the timeout started an abort. While that abort was taking place the
xfer could be cancelled (usually by closing the pipe), causing a second
abort to begin.
This is now handled by having flags indicating the abort state of an xfer.

Hopefully this will fix the occasional crashes when printing.
 1.158  17-Apr-2005  toshii Correct status value check for OHCI isoc transfer;
the spec says that "not accessed" is 111x, not 1111.
 1.157  11-Mar-2005  mycroft branches: 1.157.2; 1.157.4;
Restructure interrupt handling a little:
* Only futz with the done list in the soft interrupt handler. In the hard
interrupt handler, do nothing except mask WDH and queue the soft interrupt.
This simplifies a bunch of code, removes two O(n^2) queue manipulations,
and gets rid of some really sketchy stuff around the queue head access.
* Use the auto-masking code at the end of the interrupt handler for both WDH
and RHSC interrupts. Again, this reduces the code a little, and avoids
multiple writebacks to the chip registers.
 1.156  02-Mar-2005  mycroft Copyright maintenance.
 1.155  27-Feb-2005  perry nuke trailing whitespace
 1.154  22-Dec-2004  joff branches: 1.154.2; 1.154.4;
Make sure to ack the interrupt even if we are ignoring it. Otherwise, we will
keep coming back.
 1.153  21-Dec-2004  fvdl Implement an USB memory reserve. Allocate some memory per host controller
in the wanted bus_dma space. If an allocation fails during operation
(i.e. when hotplugging an umass device), fall back to using the reserve.

The amount can be configured as USB_MEM_RESERVE. The default value is
256k.

Ideally, there would be a way to steal pages in the desired area from
UVM, but that's far more complicated, and this is not intrusive, plus
it works.
 1.152  26-Oct-2004  augustss Allow strings descriptor 0 to be fetched. It's the default language index.
 1.151  17-Jul-2004  mycroft Avoid touching the xfer after calling usb_transfer_complete(), as the
driver callback may have recycled it. From PR 25960.
 1.150  06-Jul-2004  mycroft Fix an error in a printf() format.
Swap the order that two items are written; possibly fixes a race condition
that would affect isoc transfers.
 1.149  29-Jun-2004  mycroft Make one message dependent on ohcidebug, so it doesn't interfere with polled
operation; e.g. when entering a root device or in DDB.
 1.148  22-Jun-2004  mycroft Adjust a couple of comments to make it clear WTF is going on.
 1.147  22-Jun-2004  mycroft Failure to properly mask off UE_DIR_IN from the endpoint address was causing
OHCI_ED_FORMAT_ISO and EHCI_QH_HRECL to get set spuriously, causing rather
interesting lossage.

Suddenly I get MUCH better performance with ehci...
 1.146  29-Dec-2003  toshii branches: 1.146.2;
Use the correct wValue to get hub desriptors.
Also, make wValue checks of root hub codes less strict.
 1.145  23-Nov-2003  augustss Try harder to avoid 0 ports woth AMD756. From OpenBSD.
 1.144  23-Nov-2003  augustss Fix swapped lines in cleanup in ohci_init(). From OpenBSD.
 1.143  18-Oct-2003  simonb Remove assigned-to but otherwise unused variables.
Remove unreachable break after return statements.
 1.142  11-Oct-2003  toshii Fix a done list handling bug which exhibits under high shared interrupt
rate and bus traffic. As the interrupt register is read after checking
hcca_done_head, there was a small chance of dropping a done list.
Ignore OHCI_WDH interrupt bit if hcca_done_head is zero so that OHCI_WDH
is processed later.
 1.141  10-Sep-2003  mycroft Update actlen even in the case where a TD returns an error -- this is critical
for the umass bulk-only STALL case.
 1.140  13-May-2003  gson branches: 1.140.2;
Function names printed in debug messages did not always match the
actual name of the function.
 1.139  22-Feb-2003  tsutsui Use mstohz() in <sys/param.h> rather than homegrown MS_TO_TICKS().
 1.138  08-Feb-2003  ichiro change URL pointers of USB[1,2] specification
 1.137  20-Jan-2003  simonb Grrr. So much for my ability to use grep(1) effectively. Pointed out
by Stephen Degler in private mail.
 1.136  20-Jan-2003  simonb The Double-Semi-Colon Police.
 1.135  10-Dec-2002  toshii Add a couple of le32toh which were missing in the previous.
Pointed out by SOMEYA Yoshihiko.
 1.134  07-Dec-2002  toshii Update xfer->frlengths for input isoc transfer. Based on patches from
SOMEYA Yoshihiko.
Also fix error handling for isoc transfer somewhat; usb_transfer_complete
shouldn't be called for more than once.
 1.133  07-Dec-2002  toshii Fix several nits. Mostly from SOMEYA Yoshihiko.
- Call usbd_transfer_complete at splusb.
- Fix a botched for loop in ohci_rem_ed.
- In ohci_close_pipe, wait 1ms after removing an ED to avoid possible race
condition.
 1.132  07-Dec-2002  toshii Remove junk at the end of a DPRINTF. From SOMEYA Yoshihiko.
 1.131  30-Sep-2002  augustss Put some ifdefs around USB_USE_SOFTINTR stuff. From FreeBSD.
 1.130  29-Sep-2002  augustss Remove extra call to ohci_rem_ed(). From kern/18448, Takeshi Nakayama.
 1.129  29-Sep-2002  augustss Add some spl calls to protect critical regions. From kern/18440,
Takeshi Nakayama.
 1.128  27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.127  07-Aug-2002  augustss Fix some braindead calls to free memory (only encountered under low memory
conditions). From OpenBSD.
 1.126  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.125  28-May-2002  augustss Change DMAADDR macro slightly.
 1.124  26-May-2002  minoura Clear done_head in the HCCA *before* acknoledging the interrupt.
Driver lost some completed transfers under heavy loads.
 1.123  19-May-2002  augustss branches: 1.123.2;
Update dma memory access API a little.
 1.122  17-Mar-2002  augustss branches: 1.122.4;
Whitespace fixes.
 1.121  16-Mar-2002  tsutsui Fix a couple of typo:
- s/ehci/ohci/ (in unused arg of macro)
- s/uhci/ohci/ (in debug message)
 1.120  03-Feb-2002  augustss Some white space fixes from FreeBSD.
 1.119  31-Dec-2001  augustss Change xfer abort to wait for the softintr to run.
 1.118  27-Dec-2001  augustss Add some DIAGNOSTIC stuf that I forgot. From Nate Williams.
 1.117  27-Dec-2001  augustss Update a comment.
 1.116  21-Nov-2001  augustss Pay more attention to if the HC is being unplugged.
 1.115  21-Nov-2001  itojun make it compilable without OHCI_DEBUG
 1.114  21-Nov-2001  augustss Use a task to perform the timeout abort so we have a process context when
sleeping.
 1.113  21-Nov-2001  augustss Some more debug stuff.
 1.112  21-Nov-2001  augustss Cast some args to bitmask_snprintf().
 1.111  20-Nov-2001  augustss Don't bother with interrupts when being disconnected.
 1.110  20-Nov-2001  augustss Use longer reset for root hubs (as told in the spec).
 1.109  20-Nov-2001  augustss Keep track of device speed for USB 2.0.
 1.108  13-Nov-2001  lukem add RCSIDs
 1.107  10-Nov-2001  augustss Improve dump routines.
 1.106  09-Nov-2001  augustss Fix a bug in xfer abort processing when the HC executes ahead of what
the driver aborts.
Don't block RHSC interrupts.
 1.105  07-Nov-2001  augustss Improve some debug messages.
 1.104  28-Sep-2001  augustss branches: 1.104.2;
Reenable RHSC interrupt after one second so hot plugging works.
(From OpenBSD.)
 1.103  11-Sep-2001  augustss Don't go top mode OPERATIONAL (before reset) on startup even if BIOS claims to
have initialized the controller.
 1.102  01-Apr-2001  augustss branches: 1.102.2; 1.102.4;
Add two missing splx() (inside DIAGNOSTIC). From OpenBSD.
 1.101  20-Feb-2001  minoura branches: 1.101.2;
Re-initialize some registers after resuming from suspend.
Some APM BIOSes do not restore them.
Reviewd by augustss.
 1.100  28-Jan-2001  augustss Put a rate limiter on the scheduling overrun message.
 1.99  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.98  20-Jan-2001  augustss Change some splusb() to splhardusb().
 1.97  31-Dec-2000  augustss Make the controller survive suspend/resume. Thanks to Steve Woodford
<steve@mctavish.co.uk> for testing.
 1.96  29-Dec-2000  augustss Update many URLs.
 1.95  13-Dec-2000  augustss Make the ohci driver not hang suspend/resume. It still doesn't resume
correctly. From itohy@netbsd.org (ITOH Yasufumi) PR kern/11714.
 1.94  10-Nov-2000  augustss Update frlengths after a isoc transfer.
Suggested by Yuri <yuri@tsoft.com>
 1.93  17-Aug-2000  augustss Add an XXX comment.
 1.92  08-Aug-2000  tv %b -> bitmask_snprintf()

Because this code is shared, add a macro for bitmask_snprintf() that
should expand to the equivalent snprintf() on non-NetBSD systems. This is
only used in ?HCI_DEBUG cases anyway.
 1.91  01-Jun-2000  augustss Bring the coding style into the 80s, i.e., get rid of __P and use
ANSI prototypes and declarations.
 1.90  08-May-2000  thorpej branches: 1.90.2;
Quiet some uninitialized variable warnings that do in fact look legitimate.
 1.89  27-Apr-2000  augustss Change my email address.
 1.88  25-Apr-2000  augustss Insert (very conservative!) bus_space_barrier() calls at all register accesses.
The bus_space(9) man page says you've gotta have them...
 1.87  22-Apr-2000  augustss Add a clarifying comment.
 1.86  21-Apr-2000  augustss Add a comment about a non-obvious use of a #define.
 1.85  01-Apr-2000  augustss Add a delay before reading the number of ports from the controller to
avoid getting 0 from it.
 1.84  29-Mar-2000  augustss Some OpenBSD portability fixes.
 1.83  29-Mar-2000  augustss A first stab at support for isochronous transfers.
 1.82  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.81  25-Mar-2000  augustss Rename and move around callout handles to make it more sane.
Add some DIAGNOSTIC.
Fix buglet in isoc abort on UHCI.
 1.80  24-Mar-2000  augustss Some cleanup and renaming of the callouts used in USB drivers.
 1.79  23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.78  20-Mar-2000  augustss Make sure all packets (except the last) have the maximum packet size even
when using multiple TDs.
 1.77  19-Mar-2000  augustss Make control transfer of over 8K possible by using a chain of TDs.
 1.76  16-Mar-2000  tsutsui Replace LE() macro with le32toh()/le32toh().
 1.75  16-Mar-2000  augustss Fix thinko in the handling of FORCE_SHORT_XFER so that it actually
transfers a 0 length package instead on munging the whole transfer.
The aue driver works now.
 1.74  29-Feb-2000  augustss Distinguish between device and interface classes.
(I finally found a document that said that they were different.)
 1.73  22-Feb-2000  augustss Fix typos in my last commit that caused the driver to panic.
Change some (unrelated) debug messages.
 1.72  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.71  01-Feb-2000  augustss Put some #ifdefs around power and shutdown hooks.
 1.70  31-Jan-2000  augustss Rename TAILMASK to HEADMASK, since it really masks the head pointer.
From FreeBSD.
 1.69  31-Jan-2000  augustss Change where the has table for physical-to-virtual address translation
is handled. Partly from FreeBSD.
 1.68  31-Jan-2000  augustss Fiddle with over-current protect when turning on port power to make
things work for some OHCI controllers.
 1.67  28-Jan-2000  augustss Correct error message list. From Nick Hibma.
 1.66  28-Jan-2000  augustss Fix typo. From Nick Hibma.
 1.65  25-Jan-2000  augustss Add done method for root control transfers.
 1.64  19-Jan-2000  augustss Add an argument to usbd_open_pipe_intr() to specify the polling interval
for an interrupt pipe in case we don't what what the descriptor suggests.
 1.63  18-Jan-2000  augustss Move the zeroing of the xfer to the individual methods.
 1.62  18-Jan-2000  augustss Turn xfer allocation into a method in the HC driver. The reason is that
an HC driver may want to subclass the xfer to have additional private fields.
 1.61  16-Jan-2000  augustss Add a flag, USBD_FORCE_SHORT_XFER, to transfers. Using this flag will
force the last packet of a transfer to be smaller than the maximum
packet size. The only time this matters is if the transfer size is
a multiple of the maximum packet size, in which case a 0 length packet
is sent last.
Some weird devices require this behaviour to determine the end of
a transfer.
 1.60  16-Jan-2000  augustss Add framework for doing isoc transfers. The actual scheduling code
is still missing.
 1.59  16-Jan-2000  augustss Add shutdown hooks to ensure that the host controller is halted when
a reboot occurs.
 1.58  06-Dec-1999  augustss Cosmetics and a couple of diagnostic messages.
 1.57  01-Dec-1999  augustss Some more DIAGNOSTIC.
 1.56  20-Nov-1999  augustss Propagate the USB revision number to the usb driver.
 1.55  18-Nov-1999  augustss Cosmetic changes and some small improvements. From FreeBSD and Nick Hibma.
 1.54  17-Nov-1999  augustss A few more purely stylistic changes that I missed in the last round.
 1.53  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.52  13-Oct-1999  augustss branches: 1.52.2; 1.52.4;
Merge in a large batch of changes from Nick Hibma <hibma@skylink.it> so
the USB stack compiles on FreeBSD again.
 1.51  12-Oct-1999  augustss Fix some bugs in USB controller detach code.
 1.50  12-Oct-1999  augustss Deallocate resources (bus space and interrupts) when detaching from
the bus.
 1.49  18-Sep-1999  augustss branches: 1.49.2;
Make sure the HC deactivation is propagated.
 1.48  15-Sep-1999  augustss Handle the case when a USB transfer is so long that it crosses two page
(4K) boundaries. OHCI cannot do that with a single TD so we make a chain.
 1.47  15-Sep-1999  augustss Add preliminary (untested) code for detaching the USB host controller
(needed for CardBus based controllers).
 1.46  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.45  13-Sep-1999  augustss Make sure timeouts count as interrupt context too.
 1.44  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.43  11-Sep-1999  augustss * Move DMA buffer allocation to HC independent code.
* Remove (almost) unused definitions USBD_XFER_OUT and USBD_XFER_IN.
 1.42  09-Sep-1999  augustss Change the internal API to allow DMA buffers to be pre-allocated by
the device driver instead of happening automagically in the HC driver.
This affects both the HC-USBD interface as well as the USBD-device
interface.
This change will allow DMA buffers to be reused e.g. in isochronous
traffic.

Add isochronous support to the UHCI driver (not for OHCI yet).
 1.41  05-Sep-1999  augustss Change some printf to DPRINTF for consistency. From Nick Hibma, FreeBSD.
 1.40  04-Sep-1999  augustss Change the way the direction is extracted from the endpoint descriptor.
No functional changes to the drivers. From Nick Hibma, FreeBSD.
 1.39  22-Aug-1999  augustss Merge the soft_{td,ed} with the real {td,ed}. This saves time and space.
(And fix typo in corresponding uhci change.)
 1.38  22-Aug-1999  augustss Move more of the transfer completion processing to HC independent code.
Fix some problems with transfer abort & timeout.
 1.37  17-Aug-1999  augustss Redo the UHCI data toggle handling.
Make sure data toggles get synchronized on open and
when clearing an endpoint stall.
 1.36  17-Aug-1999  augustss Make some small changes to make it compile on OpenBSD.
 1.35  16-Aug-1999  augustss Change the way transfers are dequeued so thet we know that they
are removed from the queue before being deallocated.
 1.34  14-Aug-1999  augustss Implement timeout and abort of requests.
Compute length of short transfers correctly.
 1.33  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.32  09-Jun-1999  augustss Fix a bug in bulk input. Discovered by Joel Chen <jchen@liberate.com>.
 1.31  09-Jun-1999  wrstuden Fix use of & when % was appropriate.
 1.30  21-May-1999  augustss Update documentation URLs.
 1.29  20-May-1999  augustss Keep track of vendor id and make sure the vendor string is NUL terminated.
 1.28  09-May-1999  augustss Fix a serious bug in bandwidth accounting that thrashed memory.
Thanks to Joel Chen <jchen@nc.com> for tracking it down.
 1.27  13-Jan-1999  augustss branches: 1.27.2; 1.27.4; 1.27.6;
Back out previous fix and apply the patch from Nick Hibma the right way.
 1.26  13-Jan-1999  augustss Fixes from Nick Hibma.
 1.25  10-Jan-1999  augustss Some patches from FreeBSD.
 1.24  10-Jan-1999  augustss Add back a line that was lost somehow.
 1.23  07-Jan-1999  augustss Ooops, I didn't mean to commit that. Back out.
 1.22  07-Jan-1999  augustss Add another paranoia test in the interrupt routine.
 1.21  01-Jan-1999  augustss Set the correct transfer count on interrupt transfers.
 1.20  30-Dec-1998  augustss Split usbd_delay_ms() into two functions, one can be used in
device drivers.
 1.19  29-Dec-1998  augustss Implement short transfers.
 1.18  29-Dec-1998  augustss Remove part of the bigendian patch that was not supposed to be commited.
 1.17  28-Dec-1998  augustss Change the host controller internal API a little and add some incomplete
support for isochronous transfers.
 1.16  28-Dec-1998  augustss Add a lot of byte swapping to get the code to work on big endian machines.
Patch from Tsubai Masanari <tsubai@iri.co.jp>.
Add an extra controller reset. According to the OHCI spec it shouldn't
be necessary, but without some machines don't work.
 1.15  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.14  10-Dec-1998  augustss Take care of some lines > 80 chars.
 1.13  08-Dec-1998  augustss Print plain text error codes.
 1.12  30-Nov-1998  augustss Do untimeout() for the timeouts we set up.
(How can this ever have worked?)
 1.11  25-Nov-1998  augustss Make the copyright header conform to the NetBSD template.
 1.10  22-Nov-1998  augustss Make sure the Endpoint Descriptor gets the correct maximum packet size.
 1.9  21-Nov-1998  augustss Fix some typos.
 1.8  05-Aug-1998  augustss Fix two pastos.
 1.7  02-Aug-1998  augustss Improve some error messages.
Make some preparations for isochronous transfers.
 1.6  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.5  26-Jul-1998  augustss A first stab att supporting console access with a USB keyboard.
 1.4  24-Jul-1998  augustss Add special memory allocation routines that supports allocation
DMA-able memory in small chunks (USB uses a lot of 8 byte chunks).
Using the bus_dma functions directly is inefficient.
 1.3  23-Jul-1998  augustss Implement bulk transfer for OHCI.
 1.2  23-Jul-1998  augustss Use the pipe maximum packet length rather than the device max length when
setting up a transfer.
Update the UHCI data toggle correctly.
 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.27.6.1  30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.27.4.2  01-Jul-1999  thorpej Sync w/ -current.
 1.27.4.1  21-Jun-1999  thorpej Sync w/ -current.
 1.27.2.1  25-Jun-1999  perry pullup 1.27->1.32 (augustss)
 1.49.2.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.52.4.1  15-Nov-1999  fvdl Sync with -current
 1.52.2.7  21-Apr-2001  bouyer Sync with HEAD
 1.52.2.6  12-Mar-2001  bouyer Sync with HEAD.
 1.52.2.5  11-Feb-2001  bouyer Sync with HEAD.
 1.52.2.4  05-Jan-2001  bouyer Sync with HEAD
 1.52.2.3  13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.52.2.2  22-Nov-2000  bouyer Sync with HEAD.
 1.52.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.90.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.101.2.13  11-Dec-2002  thorpej Sync with HEAD.
 1.101.2.12  18-Oct-2002  nathanw Catch up to -current.
 1.101.2.11  13-Aug-2002  nathanw Catch up to -current.
 1.101.2.10  10-Jul-2002  nathanw Don't need curlwp here.
 1.101.2.9  24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.101.2.8  20-Jun-2002  nathanw Catch up to -current.
 1.101.2.7  01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.101.2.6  28-Feb-2002  nathanw Catch up to -current.
 1.101.2.5  08-Jan-2002  nathanw Catch up to -current.
 1.101.2.4  14-Nov-2001  nathanw Catch up to -current.
 1.101.2.3  08-Oct-2001  nathanw Catch up to -current.
 1.101.2.2  21-Sep-2001  nathanw Catch up to -current.
 1.101.2.1  09-Apr-2001  nathanw Catch up with -current.
 1.102.4.1  01-Oct-2001  fvdl Catch up with -current.
 1.102.2.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.102.2.5  06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.102.2.4  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.102.2.3  11-Feb-2002  jdolecek Sync w/ -current.
 1.102.2.2  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.102.2.1  13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.104.2.1  12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.122.4.3  29-Aug-2002  gehenna catch up with -current.
 1.122.4.2  20-Jun-2002  gehenna catch up with -current.
 1.122.4.1  30-May-2002  gehenna Catch up with -current.
 1.123.2.3  15-Mar-2004  jmc Pullup rev 1.146 (requested by toshii in ticket #1599)

Use the correct wValue to get hub desriptors.
Also, make wValue checks of root hub codes less strict.
 1.123.2.2  10-Oct-2003  tron Pull up revision 1.141 (requested by bad in ticket #1515):
Update actlen even in the case where a TD returns an error -- this is critical
for the umass bulk-only STALL case.
 1.123.2.1  27-Jan-2003  jmc Pullup lots of revisions: 1.123-1.124,1.126-1.127,1.128-1.131,1.132-1.135
(requested by bad in ticket #1104)

Clear done_head in the HCCA *before* acknowledging the interrupt.
Driver lost some completed transfers under heavy loads.
Fix some braindead calls to free memory (only encountered under low
memory conditions).
Add some spl calls to protect critical regions. From PR#18440
Remove extra call to ohci_rem_ed(). From PR#18448
Put some ifdefs around USB_USE_SOFTINTR stuff.
Fix several nits:
- Call usbd_transfer_complete at splusb.
- Fix a botched for loop in ohci_rem_ed.
- In ohci_close_pipe, wait 1ms after removing an ED to avoid possible
race condition.
Update xfer->frlengths for input isoc transfer.
Also fix error handling for isoc transfer somewhat;
usb_transfer_complete shouldn't be called for more than once.
Add a couple of le32toh which were missing in the previous.
 1.140.2.9  11-Dec-2005  christos Sync with head.
 1.140.2.8  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.140.2.7  01-Apr-2005  skrll Sync with HEAD.
 1.140.2.6  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.140.2.5  17-Jan-2005  skrll Sync with HEAD.
 1.140.2.4  02-Nov-2004  skrll Sync with HEAD.
 1.140.2.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.140.2.2  18-Sep-2004  skrll Sync with HEAD.
 1.140.2.1  03-Aug-2004  skrll Sync with HEAD
 1.146.2.5  23-Jul-2004  tron branches: 1.146.2.5.2;
Pull up revision 1.151 (requested by mycroft in ticket #688):
Avoid touching the xfer after calling usb_transfer_complete(), as the
driver callback may have recycled it. From PR 25960.
 1.146.2.4  10-Jul-2004  tron Pull up revision 1.150 (requested by mycroft in ticket #631):
Fix an error in a printf() format.
Swap the order that two items are written; possibly fixes a race condition
that would affect isoc transfers.
 1.146.2.3  02-Jul-2004  he Pull up revision 1.149 (requested by mycroft in ticket #572):
Several fixes mostly related to USB:
o Make a message dependent on ohcidebug, so it does not
interfere with polled operation, e.g. when entering a
root device or in DDB.
 1.146.2.2  24-Jun-2004  tron Pull up revision 1.148 (requested by mycroft in ticket #535):
Adjust a couple of comments to make it clear WTF is going on.
 1.146.2.1  24-Jun-2004  tron Pull up revision 1.147 (requested by mycroft in ticket #535):
Failure to properly mask off UE_DIR_IN from the endpoint address was causing
OHCI_ED_FORMAT_ISO and EHCI_QH_HRECL to get set spuriously, causing rather
interesting lossage.
Suddenly I get MUCH better performance with ehci...
 1.146.2.5.2.1  13-May-2005  riz Pull up revision 1.153 (requested by bad in ticket #1479):
Implement an USB memory reserve. Allocate some memory per host controller
in the wanted bus_dma space. If an allocation fails during operation
(i.e. when hotplugging an umass device), fall back to using the reserve.
The amount can be configured as USB_MEM_RESERVE. The default value is
256k.
Ideally, there would be a way to steal pages in the desired area from
UVM, but that's far more complicated, and this is not intrusive, plus
it works.
 1.154.4.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.154.2.1  29-Apr-2005  kent sync with -current
 1.157.4.1  11-Aug-2006  riz Pull up following revision(s) (requested by abs in ticket #1459):
sys/dev/usb/ehci.c: revision 1.96
sys/dev/usb/uhci.c: revision 1.188
sys/dev/usb/ohci.c: revision 1.159
sys/dev/usb/usbdivar.h: revision 1.74
Fix a race condition in xfer abort. Derived from a FreeBSD patch.
An xfer could be aborted twice (which means that the second abort might
access deallocated memory). This happened when an xfer timed out and
the timeout started an abort. While that abort was taking place the
xfer could be cancelled (usually by closing the pipe), causing a second
abort to begin.
This is now handled by having flags indicating the abort state of an xfer.
Hopefully this will fix the occasional crashes when printing.
 1.157.2.2  28-Sep-2008  jdc Pull up revisions:
sys/dev/usb/ehci.c 1.138 via patch
sys/dev/usb/ehcivar.h 1.31 via patch
sys/dev/usb/ohci.c 1.195 via patch
sys/dev/usb/ohcivar.h 1.45 via patch
sys/dev/usb/uhci.c 1.223 via patch
sys/dev/usb/uhcivar.h 1.45 via patch
sys/dev/usb/usb_mem.c 1.37 via patch
sys/dev/usb/usb_mem.h 1.27 via patch
requested by bouyer in ticket 1946.

Add appropriate bus_dmamap_sync() calls to uhci(4), ohci(4) and ehci(4),
as proposed on tech-kern@.
While all DMA memory used in the USB framework is mapped BUS_DMAMAP_COHERENT
(including data memory, which is memcpy'd from/to USB-private buffers),
the CPU can reorder loads or stores from/to main memory, causing the
controller to have an incoherent view of the DMA descriptors lists for a
short time. bus_dmamap_sync() should contain memory barriers that prevents
the CPU from reordering load/store. Note that BUS_DMAMAP_COHERENT is
still required for the DMA descriptor lists - these can't work properly
with software cache coherency.
This fixes "host controller process error/host controller halted" errors
I'm occasionally seeing with a umodem device on uhci on x86.
Thanks to Michael Lorenz for testing it on his O2, and Izumi Tsutsui on
his Cobalt Qube 2700.
 1.157.2.1  11-Aug-2006  riz Pull up following revision(s) (requested by abs in ticket #1459):
sys/dev/usb/ehci.c: revision 1.96
sys/dev/usb/uhci.c: revision 1.188
sys/dev/usb/ohci.c: revision 1.159
sys/dev/usb/usbdivar.h: revision 1.74
Fix a race condition in xfer abort. Derived from a FreeBSD patch.
An xfer could be aborted twice (which means that the second abort might
access deallocated memory). This happened when an xfer timed out and
the timeout started an abort. While that abort was taking place the
xfer could be cancelled (usually by closing the pipe), causing a second
abort to begin.
This is now handled by having flags indicating the abort state of an xfer.
Hopefully this will fix the occasional crashes when printing.
 1.166.2.9  17-Mar-2008  yamt sync with head.
 1.166.2.8  27-Feb-2008  yamt sync with head.
 1.166.2.7  04-Feb-2008  yamt sync with head.
 1.166.2.6  21-Jan-2008  yamt sync with head
 1.166.2.5  27-Oct-2007  yamt sync with head.
 1.166.2.4  03-Sep-2007  yamt sync with head.
 1.166.2.3  26-Feb-2007  yamt sync with head.
 1.166.2.2  30-Dec-2006  yamt sync with head.
 1.166.2.1  21-Jun-2006  yamt sync with head.
 1.167.6.1  22-Nov-2005  yamt sync with head.
 1.169.12.2  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.169.12.1  31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.169.10.1  19-Apr-2006  elad sync with head.
 1.169.8.3  03-Sep-2006  yamt sync with head.
 1.169.8.2  24-May-2006  yamt sync with head.
 1.169.8.1  01-Apr-2006  yamt sync with head.
 1.169.6.2  01-Jun-2006  kardel Sync with head.
 1.169.6.1  22-Apr-2006  simonb Sync with head.
 1.169.4.1  09-Sep-2006  rpaulo sync with head
 1.175.4.2  10-Dec-2006  yamt sync with head.
 1.175.4.1  22-Oct-2006  yamt sync with head
 1.175.2.2  01-Feb-2007  ad Sync with head.
 1.175.2.1  18-Nov-2006  ad Sync with head.
 1.179.2.2  31-Aug-2008  jdc Pull up revisions:
src/sys/dev/usb/ehci.c:1.138
src/sys/dev/usb/ehcivar.h:1.31
src/sys/dev/usb/ohci.c:1.195
src/sys/dev/usb/ohcivar.h:1.45
src/sys/dev/usb/uhcivar.h:1.45
src/sys/dev/usb/uhci.c:1.223
src/sys/dev/usb/usb_mem.c:1.37
src/sys/dev/usb/usb_mem.h:1.27
via patch (requested by bouyer in ticket #1166).
 1.179.2.1  21-Feb-2007  tron branches: 1.179.2.1.2;
Pull up following revision(s) (requested by mlelstv in ticket #450):
sys/dev/usb/ohci.c: revision 1.181
sys/dev/usb/uhci.c: revision 1.207
sys/dev/usb/ehci.c: revision 1.122
sys/dev/usb/usbdi.c: revision 1.118
The diagnostic code doesn't track busy_free correctly when a
device gets removed. However, when the diagnostic check fails,
it is much better to complete the free operation than to abort
it, because this just causes an infinite loop.
 1.179.2.1.2.1  04-Sep-2008  skrll Sync with netbsd-4.
 1.181.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.182.18.6  07-Nov-2007  joerg Introduce device_has_power to fix a race between resuming a device and
the device enabling interrupts as seen by jmcneill@ with uhci. Change
ehci, ohci, uhci and azalia to use this function to protect the
interrupt handler.
 1.182.18.5  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.182.18.4  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.182.18.3  01-Oct-2007  joerg Extend device API by device_power_private and device_power_set_private.
The latter is a temporary mean until the pnp_register API itself is
overhault. This functions allow a generic power handler to store its
state independent of the driver.

Use this and revamp the PCI power handling. Pretty much all PCI devices
had power handlers that did the same thing, generalize this in
pci_generic_power_register/deregister and the handler. This interface
offers callbacks for the drivers to save and restore state on
transistions. After a long discussion with jmcneill@ it was considered
to be powerful enough until evidence is shown that devices can handle
D1/D2 with less code and higher speed than without the full
save/restore. The generic code is carefully written to handle device
without PCI-PM support and ensure that the correct registers are written
to when D3 loses all state.

Reimplement the generic PCI network device handling on
top of PCI generic power handling.

Introduce pci_disable_retry as used and implemented locally at least by
ath(4) and iwi(4). Use it in this drivers to restore behaviour from
before the introduction of generic PCI network handling.

Convert all PCI drivers that were using pnp_register to the new
framework. The only exception is vga(4) as it is commonly used as
console device. Add a note therein that this should be fixed later.
 1.182.18.2  16-Aug-2007  jmcneill Sync with HEAD.
 1.182.18.1  14-Aug-2007  jmcneill Add ohci power management support, currently untested.
 1.182.14.1  15-Aug-2007  skrll Sync with HEAD.
 1.182.12.6  12-Nov-2009  uebayasi Sort struct usbd_bus_methods member initializers.
 1.182.12.5  12-Nov-2009  uebayasi USB_DEBUG -> OHCI_DEBUG
 1.182.12.4  21-May-2008  itohy cleanup
 1.182.12.3  21-May-2008  itohy Fix aux memory usage.
Implement recovory from isoc error.
Improve DMA sync.
 1.182.12.2  31-May-2007  itohy usbdi(9): Change usbd_map_buffer_mbuf to return the result, since
mbuf(9) chain may be fragmented and mapping failure will happen.
-void usbd_map_buffer_mbuf(usbd_xfer_handle xfer, struct mbuf *chain)
+usbd_status usbd_map_buffer_mbuf(usbd_xfer_handle xfer, struct mbuf *chain)

usbdi(9): Add more diagnostic assertions.
uhci(4): fix aux dma for mbuf mapping.
slhci(4): fix repeated interrupt transfer (not tested).
ehci/slhci/ohci/uhci: Add checks where mbuf(4) transfer is not supported.

usb_port.h: Add some compat macros for FreeBSD.
usb_mem_nodma.c: Fix typos.
 1.182.12.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.182.4.2  23-Oct-2007  ad Sync with head.
 1.182.4.1  20-Aug-2007  ad Sync with HEAD.
 1.183.6.1  25-Oct-2007  bouyer Sync with HEAD.
 1.183.2.3  23-Mar-2008  matt sync with HEAD
 1.183.2.2  09-Jan-2008  matt sync with HEAD
 1.183.2.1  06-Nov-2007  matt sync with HEAD
 1.184.6.1  11-Dec-2007  yamt sync with head.
 1.184.4.1  26-Dec-2007  ad Sync with head.
 1.184.2.1  18-Feb-2008  mjf Sync with HEAD.
 1.186.6.6  17-Jan-2009  mjf Sync with HEAD.
 1.186.6.5  28-Sep-2008  mjf Sync with HEAD.
 1.186.6.4  29-Jun-2008  mjf Sync with HEAD.
 1.186.6.3  05-Jun-2008  mjf Sync with HEAD.

Also fix build.
 1.186.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.186.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.186.2.1  24-Mar-2008  keiichi sync with head.
 1.191.4.4  11-Mar-2010  yamt sync with head
 1.191.4.3  16-Sep-2009  yamt sync with head
 1.191.4.2  04-May-2009  yamt sync with head.
 1.191.4.1  16-May-2008  yamt sync with head.
 1.191.2.3  17-Jun-2008  yamt sync with head.
 1.191.2.2  04-Jun-2008  yamt sync with head
 1.191.2.1  18-May-2008  yamt sync with head.
 1.192.2.2  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.192.2.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.194.2.1  03-Jul-2008  simonb Sync with head.
 1.195.2.1  19-Oct-2008  haad Sync with HEAD.
 1.196.14.1  07-Jan-2011  matt move/change a few debug printfs
 1.196.4.2  19-Aug-2011  riz Pull up following revision(s) (requested by jmcneill in ticket #1663):
sys/dev/usb/ohci.c: patch
Fix the build problem introduced by pullup ticket #1655.
 1.196.4.1  12-Aug-2011  riz Pull up following revision(s) (requested by jmcneill in ticket #1655):
sys/dev/usb/ohci.c: revision 1.218
PR# kern/30398: panic in ohci_softintr
If the host controller has a TD that the driver doesn't know about, ignore it
instead of calling panic. Patch from Karl Janmar.
 1.196.2.2  28-Apr-2009  skrll Sync with HEAD.
 1.196.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.197.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.205.2.2  06-Nov-2010  uebayasi Sync with HEAD.
 1.205.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.206.2.3  12-Jun-2011  rmind sync with head
 1.206.2.2  31-May-2011  rmind sync with head
 1.206.2.1  05-Mar-2011  rmind sync with head
 1.212.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.215.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.218.8.4  13-Jul-2016  snj Pull up following revision(s) (requested by skrll in ticket #1350):
sys/dev/usb/ohci.c: revision 1.257
Fix 10year old bug of mine affecting interrupt IN transfers.
 1.218.8.3  07-Dec-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #1201):
sys/kern/kern_ktrace.c: revision 1.166
sys/dev/isa/aps.c: revision 1.16
sys/dev/sysmon/sysmonvar.h: revision 1.45
sys/dev/ir/irframe_tty.c: revision 1.60
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.111-1.112 (patch)
sys/dev/pci/pccbb.c: revision 1.207
sys/dev/wscons/wskbd.c: revision 1.135
sys/dev/usb/ohci.c: revision 1.254
sys/net/if_ecosubr.c: revision 1.41
sys/dev/pcmcia/btbc.c: revision 1.17
sys/arch/x86/x86/via_padlock.c: revision 1.23
sys/dev/sdmmc/sdmmc.c: revision 1.23 (patch)
sys/dev/bluetooth/btkbd.c: revision 1.17
sys/dev/bluetooth/bcsp.c: revision 1.25
sys/arch/x86/pci/fwhrng.c: revision 1.8
sys/dev/ic/nslm7x.c: revision 1.61
share/man/man9/callout.9: revision 1.28 (patch)

Replace callout_stop with callout_halt and ensure the callout
is not running before destroying it.
 1.218.8.2  20-Apr-2013  bouyer Pull up following revision(s) (requested by skrll in ticket #864):
sys/dev/usb/ohci.c: revision 1.234
sys/dev/usb/ohci.c: revision 1.236
Don't leak memory if ohci_alloc_std_chain fails.
When dumping the done list in ohci_softintr / OHCI_DEBUG use the correct
list next pointer.
PR/33450 and part of PR/35379.
 1.218.8.1  05-Jan-2013  riz Pull up following revision(s) (requested by skrll in ticket #765):
sys/dev/usb/ohci.c: revision 1.226
PR/41602
Fix a memory leak when ohci_device_setintr didn't return
USBD_NORMAL_COMPLETION.
ohci_setup_isoc always returns USBD_NORMAL_COMPLETION at the moment so
there's no chance of a leak there.
PR/41602
Fix a memory leak when ohci_device_setintr didn't return
USBD_NORMAL_COMPLETION.
ohci_setup_isoc always returns USBD_NORMAL_COMPLETION at the moment so
there's no chance of a leak there.
 1.218.6.20  05-Apr-2012  mrg make these compile without DIAGNOSTIC.
 1.218.6.19  11-Mar-2012  mrg sync to latest -current
 1.218.6.18  06-Mar-2012  mrg sync to -current
 1.218.6.17  03-Mar-2012  mrg use usb_delay_ms_locked() in some more places
 1.218.6.16  26-Feb-2012  mrg - add some more "XXXSMP ok" tags
- use cpu_softintr_p() instead of checking LP_INTR directly
 1.218.6.15  25-Feb-2012  mrg replace the (diagnostic-only) intr_context with checks against LP_INTR
and cpu_intr_p().

XXX: there's one check that changes behaviour
 1.218.6.14  25-Feb-2012  mrg remove curproc references
 1.218.6.13  25-Feb-2012  mrg copyright maintenence.
 1.218.6.12  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.218.6.11  20-Feb-2012  mrg remove the intr_lock from the mp usb api, it wasn't used.
 1.218.6.10  20-Feb-2012  mrg adjust some comments to reality. copy some XXX comments from ehci
into uhci/ohci since it's probably right there too
 1.218.6.9  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.218.6.8  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.218.6.7  08-Dec-2011  mrg make ohci mostly work again.
 1.218.6.6  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.218.6.5  07-Dec-2011  macallan make this build without DIAGNOSTIC
 1.218.6.4  06-Dec-2011  mrg don't forget to drop the lock in ohci_intr if we got there when
polling. also don't try to drop a lock we don't have in ohci_open.

XXX: these might apply to ehci as well, i found them when porting
XXX: to uhci.
 1.218.6.3  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.218.6.2  04-Dec-2011  jmcneill branches: 1.218.6.2.2;
adapt ohci, from mrg with some changes by me
 1.218.6.1  04-Dec-2011  jmcneill Make ehci mpsafe.
 1.218.6.2.2.7  08-Dec-2011  mrg pull across a few more of the changes from the main branch.
 1.218.6.2.2.6  08-Dec-2011  mrg merge a few more things from the main branch. uaudio@ohci still works.
 1.218.6.2.2.5  08-Dec-2011  mrg at little closer to the main branch.
 1.218.6.2.2.4  08-Dec-2011  mrg partial sync with main branch
 1.218.6.2.2.3  08-Dec-2011  mrg sync a couple more changes from the main branch, uaudio@ohci still works.
 1.218.6.2.2.2  08-Dec-2011  mrg slightly closer, and still working with uaudio.
 1.218.6.2.2.1  08-Dec-2011  mrg there's something wrong with uaudio@ohci on the usbmp branch.
this is the minimally working port of ohci to mpusb, and it works
with uaudio but is lacking many other changes, yet.
 1.218.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.218.2.4  23-Jan-2013  yamt sync with head
 1.218.2.3  16-Jan-2013  yamt sync with (a bit old) head
 1.218.2.2  30-Oct-2012  yamt sync with head
 1.218.2.1  17-Apr-2012  yamt sync with head
 1.224.2.4  03-Dec-2017  jdolecek update from HEAD
 1.224.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.224.2.2  23-Jun-2013  tls resync from head
 1.224.2.1  25-Feb-2013  tls resync with head
 1.241.4.1  18-May-2014  rmind sync with head
 1.250.2.1  10-Aug-2014  tls Rebase.
 1.253.2.5  25-Aug-2018  martin Pull up following revision(s) (requested by mrg in ticket #1632):

sys/dev/usb/usbdivar.h: revision 1.117
sys/external/bsd/dwc2/dwc2.c: revision 1.52
sys/dev/usb/xhcivar.h: revision 1.10
sys/dev/usb/motg.c: revision 1.22
sys/dev/usb/ehci.c: revision 1.260
sys/dev/usb/ehci.c: revision 1.261
sys/dev/usb/xhci.c: revision 1.96
sys/dev/usb/ohci.c: revision 1.282
sys/dev/usb/ohci.c: revision 1.283
sys/dev/usb/ehcivar.h: revision 1.45
sys/dev/usb/uhci.c: revision 1.281
sys/dev/usb/uhci.c: revision 1.282
sys/dev/usb/usbdi.c: revision 1.177
sys/dev/usb/ohcivar.h: revision 1.60
sys/dev/usb/uhcivar.h: revision 1.55
(all via patch)

pull across abort fixes from nick-nhusb. add more abort fixes, using
ideas from Taylor and Nick, and myself. special thanks to both who
inspired much of the code here, if not wrote it directly.

among other problems, this assert should no longer trigger:

panic: kernel diagnostic assertion "xfer->ux_state == XFER_ONQU" failed: file "/current/src/sys/dev/usb/usbdi.c", line 914

using usbhist i was able to track down my instance of it being related
to userland close() beginning, dropping the sc_lock, and then the usb
softintr completes the transfer normally, and when it is done, the
abort path attempts to re-complete the transfer, and the above assert
is tripped.

changes from nhusb were commited with these logs:
--
Move the struct usb_task to struct usbd_xfer for everyone to use.
--
Set device transfer status to USBD_IN_PROGRESS if start methods succeeds
--
Actually set the transfer status on transfers in ohci_abort_xfer and
the controller is dying
--
Don't supply the lock to callout_halt when polling as it won't be held
--
Improve transfer abort
--
Mark device transfers as USBD_IN_PROGRESS appropriately and improve
abort handling
--
--
Mark device transfers as USBD_IN_PROGRESS appropriately and improve
abort handling
--

additional changes include:
- initialise the usb abort task in the HCI allocx routine, so that it
can be safely usb_rem_task()'d.
- rework the handling of softintr vs cancellation vs timeout abort based
upon a scheme from Taylor:
when completing a transfer normally:
- if the status is not in progress, it must be cancelled or timed out,
and we should not process this xfer.
- set the status as normal.
- unconditionallly callout_stop() and usb_rem_task(). they're safe and
either aren't running, or will run and do nothing.
- finally call usb_transfer_complete().
when aborting a transfer:
- status should be cancelled or timed out.
- if cancelling, callout_halt and usb_rem_task_wait() to make sure the
timer is either done or cancelled.
- at this point, the ux_status must not be cancelled or timed out, and
if it is not in progress we're done.
- set the status.
- if the controller is dying, just return.
- perform HCI-specific tasks to abort this xfer.
- finally call usb_transfer_complete().
for the timeout and timeout task:
- if the HCI is not dying, and the ux_status is in progress, then
trigger the usb abort task.
- remove UXFER_ABORTWAIT and UXFER_ABORTING.

tested on:
- multiple PC systems with several types of devices: ugen/UPS, ucom,
umass with disk, ssd and cdrom backends, kbd, ms, using uhci, ehci
and xhci.
- erlite3: sd@umass on dwc2.
- sunblade2000: kbd/ms and umass disk on ohci.

untested:
- motg, slhci and ahci. motg has some portion of the new scheme
applied, but slhci and ahci require more study.

future work includes pushing a lot of the common abort handling into
usbdi.c and leaving upm_abort() for HC specific tasks, but this change
is pullup-able to netbsd-7 and netbsd-8 as it does not change any
external API, as well as removing over 100 lines of code while adding
over 30 new asserts.

XXX: pullup-7, pullup-8.

fix DIAGNOSTIC build by not copying ub_usepolling to stack before use

Sprinkle __diagused
 1.253.2.4  03-Jan-2018  snj Pull up following revision(s) (requested by skrll in ticket #1529):
sys/dev/usb/ehci.c: revision 1.257
sys/dev/usb/motg.c: revision 1.19
sys/dev/usb/ohci.c: revision 1.276
sys/dev/usb/uhci.c: revision 1.279
sys/dev/usb/xhci.c: revision 1.77
sys/external/bsd/dwc2/dwc2.c: revision 1.47
s/PR_NOWAIT/PR_WAITOK/ in HCD allocx (allocate xfer) method
 1.253.2.3  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.253.2.2  02-Jan-2016  riz branches: 1.253.2.2.2;
Pull up following revision(s) (requested by skrll in ticket #1054):
sys/dev/usb/ohci.c: revision 1.257
Fix 10year old bug of mine affecting interrupt IN transfers.
 1.253.2.1  01-Dec-2014  martin Pull up following revision(s) (requested by ozaki-r in ticket #279):
sys/kern/kern_ktrace.c: revision 1.166
sys/dev/isa/aps.c: revision 1.16
sys/dev/sysmon/sysmonvar.h: revision 1.45
sys/dev/ir/irframe_tty.c: revision 1.60
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.111
sys/dev/sysmon/sysmon_envsys_events.c: revision 1.112
sys/dev/pci/pccbb.c: revision 1.207
sys/dev/wscons/wskbd.c: revision 1.135
sys/dev/usb/ohci.c: revision 1.254
sys/net/if_ecosubr.c: revision 1.41
sys/dev/pcmcia/btbc.c: revision 1.17
sys/arch/x86/x86/via_padlock.c: revision 1.23
sys/dev/sdmmc/sdmmc.c: revision 1.23
sys/dev/bluetooth/btkbd.c: revision 1.17
sys/dev/bluetooth/bcsp.c: revision 1.25
sys/arch/x86/pci/fwhrng.c: revision 1.8
sys/dev/ic/nslm7x.c: revision 1.61
share/man/man9/callout.9: revision 1.28
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
Discussed with martin@ and riastradh@.
Make it clear that we should use not callout_stop but callout_halt
before callout_destroy
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
In this case, we need to pass an interlock to callout_halt to wait for
the callout complete.
Reviewed by riastradh@.
Kill sme_callout_mtx and use sme_mtx instead
We can use sme_mtx for the callout as well. Actually we should do so
because sme_events_list and some other data that are touched in the
callout should be protected by sme_mtx, not sme_callout_mtx.
Discussed with riastradh@ in
http://mail-index.netbsd.org/tech-kern/2014/11/11/msg017956.html
Replace callout_stop with callout_halt
In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.
In this case, we need to pass an interlock to callout_halt to wait for
the callout complete. And also we make sure that SME_CALLOUT_INITIALIZED
is unset before calling callout_halt to prevent the callout from calling
callout_schedule. This is the same as what we did in sys/netinet6/mld6.c@1.61.
Reviewed by riastradh@.
 1.253.2.2.2.2  31-Jan-2017  skrll Sync with HEAD
 1.253.2.2.2.1  06-Sep-2016  skrll First pass at netbsd-7 updated with USB code from HEAD
 1.254.2.86  05-Feb-2017  skrll Sync with HEAD
 1.254.2.85  31-Jan-2017  skrll Sync with HEAD
 1.254.2.84  28-Dec-2016  skrll Set device transfer status to USBD_IN_PROGRESS if start methods succeeds
 1.254.2.83  27-Dec-2016  skrll Actually set the transfer status on transfers in ohci_abort_xfer and
the controller is dying
 1.254.2.82  27-Dec-2016  skrll Don't supply the lock to callout_halt when polling as it won't be held
 1.254.2.81  17-Dec-2016  skrll Wrap a long line.
 1.254.2.80  17-Dec-2016  skrll Tweak a couple of comments
 1.254.2.79  05-Dec-2016  skrll Sync with HEAD
 1.254.2.78  05-Oct-2016  skrll Sync with HEAD
 1.254.2.77  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.254.2.76  30-May-2016  skrll Restructure the abort code for TD based transfers (ctrl, bulk, intr).

In PR/22646 some TDs can be on the done queue when the abort start and,
if this is the case, they need to processed after the WDH interrupt.
Instead of waiting for WDH we release TDs that have been touched by the
HC and replace them with new ones. Once WDH happens the floating TDs
will be returned to the free list.
 1.254.2.75  29-May-2016  skrll Sync with HEAD
 1.254.2.74  29-May-2016  skrll Pull across fix from head for BE short reads
 1.254.2.73  30-Apr-2016  skrll Move the struct usb_task to struct usbd_xfer for everyone to use.
 1.254.2.72  16-Apr-2016  skrll Fix usbd_status vs int in *_alloc_*_chain
 1.254.2.71  16-Apr-2016  skrll Don't leak memory in *_alloc_*td_chain if allocation fails.
 1.254.2.70  04-Apr-2016  skrll Rework {alloc,reset}_*_chain functions to perform all of TD setup in
reset chain. The initial motivation for this was to fix ZLP.
 1.254.2.69  01-Apr-2016  skrll Revert previous as it needs some work.
 1.254.2.68  01-Apr-2016  skrll Deal with ZLP (zero length packets) properly
 1.254.2.67  01-Apr-2016  skrll Damn it... whitespace.
 1.254.2.66  01-Apr-2016  skrll Guess what... whitspace.
 1.254.2.65  01-Apr-2016  skrll More whitespace
 1.254.2.64  01-Apr-2016  skrll More whitespace
 1.254.2.63  01-Apr-2016  skrll Really fix whitespace
 1.254.2.62  01-Apr-2016  skrll Whitespace
 1.254.2.61  01-Apr-2016  skrll constify tdflags in ohci_{alloc,reset}_std_chain
 1.254.2.60  24-Mar-2016  skrll Wait for hardware before removing the TDs from the hash lists.

This is all a bit racey and should be revisited.
 1.254.2.59  17-Mar-2016  skrll All HCDs were fighting the seriaisation of transfers in usbdi.c for isoc
transfers. Instead allow the HCDs to specify which pipes can handle
removing this serialisation and apply it appropriately.

dwctwo(4) can handle this for all transfer types, but only enable
bulk/isoc for now.
 1.254.2.58  13-Mar-2016  skrll KNF (on the right branch this time)
 1.254.2.57  09-Mar-2016  skrll More debug
 1.254.2.56  08-Mar-2016  skrll Whitespace
 1.254.2.55  28-Feb-2016  skrll ohci_hash_rem_itd the sitds in ohci_device_isoc_abort
 1.254.2.54  28-Feb-2016  skrll Centralise the up_repeat handling and use the standard pipe method to
start the next transfer. This allows the removal of a bunch of code
in the upm_done methods for interrupt transfers which had copies of
the upm_start method code.

At the same time we can perform the upm_done method before calling the
transfer callback allowing correct bus_dma(9) operations before
using the transfer DMA buffer.
 1.254.2.53  27-Feb-2016  skrll Do the pipe sitd and loaning properly for isoc transfers
 1.254.2.52  27-Feb-2016  skrll An std is "done" when it's not inflight. Mark it done when it's first
allocated.
 1.254.2.51  27-Feb-2016  skrll Remove some blank lines
 1.254.2.50  27-Feb-2016  skrll Comment on its own line
 1.254.2.49  25-Feb-2016  skrll Remove the big delay / dump ED/TD state debug code.
 1.254.2.48  24-Feb-2016  skrll Move a comment to its own line.
 1.254.2.47  24-Feb-2016  skrll Debug improvements
 1.254.2.46  19-Feb-2016  skrll Fix typo in previous *sigh*
 1.254.2.45  18-Feb-2016  skrll Tweak the usb_syncmem from the previous.
 1.254.2.44  18-Feb-2016  skrll Only mark the last TD as "buffer rounding" when USBD_SHORT_XFER_OK. This
means OHCI_CC_DATA_UNDERRUN is flagged if the device doesn't send enough
data to fill the buffer in the last TD.

Deal with OHCI_CC_DATA_UNDERRUN with the normal error handling, but return
USBD_NORMAL_COMPLETION and let the usb_transfer_complete decide if it
should return USBD_SHORT_XFER
 1.254.2.43  18-Feb-2016  skrll Print cc when debug level is 10.
 1.254.2.42  10-Jan-2016  skrll Do the same loan dance with control transfers as with other transfer
types. That is,

Use the pipe "tail" TD as our first and loan our first TD to the
next transfer.

Sprinkle the above comment where necessary.

Also, remove a TD from the hash list BEFORE calling into
usb_transfer_complete. It might get reused when starting the next
transfer.
 1.254.2.41  09-Jan-2016  skrll Debug improvements
 1.254.2.40  09-Jan-2016  skrll Debug improvements
 1.254.2.39  08-Jan-2016  skrll Consistency with USBHIST_LOGN
 1.254.2.38  28-Dec-2015  skrll ohci_reset_std_chain doesn't sleep so remove the stray ASSERT_SLEEPABLE
 1.254.2.37  23-Dec-2015  skrll Revert previous... I got ahead of myself
 1.254.2.36  23-Dec-2015  skrll Transfer are only ever allocated from thread context now. Change IPL_USB
to IPL_NONE in pool_cache_init for the xfer struct pool.
 1.254.2.35  06-Dec-2015  skrll Restructure the xfer methods of ohci(4) so that minimal work in done in
softint context. Now all memory allocation is done in thread context.

Addresses kern/48308 for ohci(4), might fix some locking bugs around the
*TD free lists, and plugs some memory leaks on error conditions.
 1.254.2.34  02-Dec-2015  skrll Sanity checks in ohci_dump_tds
 1.254.2.33  02-Dec-2015  skrll Group TD/ITD assignments. No functional change.
 1.254.2.32  01-Dec-2015  skrll Comment re-org / wrap long line
 1.254.2.31  01-Dec-2015  skrll Make isdone a bool
 1.254.2.30  01-Dec-2015  skrll Whitespace
 1.254.2.29  29-Nov-2015  skrll Remove #if 0 / #endif debug code that raced hardware
 1.254.2.28  15-Nov-2015  skrll Remove unused fields from ohci_pipe
 1.254.2.27  14-Nov-2015  skrll Collapse ohci_device_request into ohci_device_ctrl_start.

No functional change intended.
 1.254.2.26  14-Nov-2015  skrll Whitespace.
 1.254.2.25  20-Oct-2015  skrll Consistently providei/use *_{XFER,PIPE,BUS}2SC, etc macros
 1.254.2.24  12-Oct-2015  skrll Remove #ifdef DIAGNOSTIC with KASSERT
 1.254.2.23  11-Oct-2015  skrll Update ubm_allocx with the isoc frame count parameter and use it in
dwctwo(4)
 1.254.2.22  22-Sep-2015  skrll Sync with HEAD
 1.254.2.21  06-Apr-2015  skrll Use anonymous unions in various structs and rename the ctl/iso members of
the pipe structs to ctrl/isoc.

No functional change intended.
 1.254.2.20  30-Mar-2015  skrll Replace an if () panic with KASSERT
 1.254.2.19  19-Mar-2015  skrll Do the same as OpenBSD and get rid of the *_handle typedefs and use
plain structures insteads
 1.254.2.18  24-Feb-2015  skrll Convert to USBHIST
 1.254.2.17  22-Feb-2015  skrll KNF
 1.254.2.16  01-Feb-2015  skrll KNF
 1.254.2.15  06-Dec-2014  skrll KNF. Remove argument name from function declarations.

No functional change.
 1.254.2.14  05-Dec-2014  skrll Use int for return type for [eou]chi_init and motg_init.
 1.254.2.13  05-Dec-2014  skrll KNF. Remove ( ) from return statements.
 1.254.2.12  04-Dec-2014  skrll Rework roothub control transfers so that much of the code is shared
across HCDs.

I have retained the vendor/product reporting for each HCD for now,
but it maybe get removed later.

ahci(4) now reports a language table and uses the usb_makestrdesc
function instead of rolling its own version.
 1.254.2.11  03-Dec-2014  skrll Rename usbroothub_subr.[ch] to usbroothub.[ch]
 1.254.2.10  03-Dec-2014  skrll Provide a USETWD macro for use with USB words designated
initialisers.
 1.254.2.9  03-Dec-2014  skrll Use designated initializers for more descriptors.
 1.254.2.8  03-Dec-2014  skrll Use designated initialisers for usb_device_descriptor_t structs.
 1.254.2.7  03-Dec-2014  skrll The grand renaming of structure members.

No functional change.
 1.254.2.6  02-Dec-2014  skrll Step #1 of memory allocation re-organisation.

Centralised the buffer allocation routine which now supports DMA
and non-DMA capable host controllers. Remove the
ubm_{alloc,free}m methods from usbd_bus_methods.

The buffer allocation is only allowed in thread context and,
therefore, negates the usefulness of the reserve dma code which
is removed in this change.

USBD_NO_COPY is also no longer required as usbd_transfer and
usbd_transfer_complete now track buffer usage and handle any
copying.
 1.254.2.5  01-Dec-2014  skrll Add prefixes to method structures member names. No functional change.
 1.254.2.4  01-Dec-2014  skrll Remove usbd_bus no_intrs member it was (virtually) unused.
 1.254.2.3  30-Nov-2014  skrll Use ASSERT_SLEEPABLE.
 1.254.2.2  30-Nov-2014  skrll Whitespace
 1.254.2.1  30-Nov-2014  skrll Use C99 types. u_int{8,16,32,64}_t to uint{8,16,32,64}_t.

No functional change.
 1.263.2.2  20-Mar-2017  pgoyette Sync with HEAD
 1.263.2.1  07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.265.2.1  21-Apr-2017  bouyer Sync with HEAD
 1.273.6.7  12-Dec-2020  martin Pull up following revision(s) (requested by skrll in ticket #1637):

sys/dev/usb/ohci.c: revision 1.311
sys/dev/usb/ohci.c: revision 1.312
sys/dev/usb/ohcivar.h: revision 1.62

Restructure the abort code for TD based transfers (ctrl, bulk, intr).

In PR kern/22646 some TDs can be on the done queue when the abort start
and, if this is the case, they need to processed after the WDH interrupt.
Instead of waiting for WDH we release TDs that have been touched by the
HC and replace them with new ones. Once WDH happens the floating TDs
will be returned to the free list.

Also addresses the issue seen in PR kern/55835

Thanks to both Andreas Gustafsson and Edgar Fu=C3=9F for testing. Apologi=
es to
Andreas Gustafsson for not committing this to HEAD for 4y6m.w

Remove leading space that crept in in the last change
 1.273.6.6  25-Feb-2020  martin Pull up following revision(s) (requested by skrll in ticket #1507):

sys/dev/usb/ohci.c: revision 1.296
sys/dev/usb/uhci.c: revision 1.294
sys/external/bsd/dwc2/dwc2.c: revision 1.72
sys/arch/mips/adm5120/dev/ahci.c: revision 1.21
sys/dev/usb/ehci.c: revision 1.274

Fix a memory leak. Spotted by nat@
 1.273.6.5  12-Aug-2019  martin Pull up following revision(s) (requested by mrg in ticket #1334):

sys/dev/usb/ohci.c: revision 1.289
sys/dev/usb/ohci.c: revision 1.290

adjust KASSERT() for sc_lock to handle polling case.
should fix usb kdb in ddb. reported by martin.

-

relax an assert to be mutex_owned || polling.

half of the patch i sent for netbsd-8 in PR#54331.
the other half is already applied.
 1.273.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.273.6.3  25-Aug-2018  martin Pull up following revision(s) (requested by mrg in ticket #980):

sys/dev/usb/usbdivar.h: revision 1.117
sys/external/bsd/dwc2/dwc2.c: revision 1.52
sys/dev/usb/xhcivar.h: revision 1.10
sys/dev/usb/motg.c: revision 1.22
sys/dev/usb/ehci.c: revision 1.260
sys/dev/usb/ehci.c: revision 1.261
sys/dev/usb/xhci.c: revision 1.96
sys/dev/usb/ohci.c: revision 1.282
sys/dev/usb/ohci.c: revision 1.283
sys/dev/usb/ehcivar.h: revision 1.45
sys/dev/usb/uhci.c: revision 1.281
sys/dev/usb/uhci.c: revision 1.282
sys/dev/usb/usbdi.c: revision 1.177
sys/dev/usb/ohcivar.h: revision 1.60
sys/dev/usb/uhcivar.h: revision 1.55
(all via patch)

pull across abort fixes from nick-nhusb. add more abort fixes, using
ideas from Taylor and Nick, and myself. special thanks to both who
inspired much of the code here, if not wrote it directly.
among other problems, this assert should no longer trigger:

panic: kernel diagnostic assertion "xfer->ux_state == XFER_ONQU" failed: file "/current/src/sys/dev/usb/usbdi.c", line 914

using usbhist i was able to track down my instance of it being related
to userland close() beginning, dropping the sc_lock, and then the usb
softintr completes the transfer normally, and when it is done, the
abort path attempts to re-complete the transfer, and the above assert
is tripped.

changes from nhusb were commited with these logs:
--
Move the struct usb_task to struct usbd_xfer for everyone to use.
--
Set device transfer status to USBD_IN_PROGRESS if start methods succeeds
--
Actually set the transfer status on transfers in ohci_abort_xfer and
the controller is dying
--
Don't supply the lock to callout_halt when polling as it won't be held
--
Improve transfer abort
--
Mark device transfers as USBD_IN_PROGRESS appropriately and improve
abort handling
--
--
Mark device transfers as USBD_IN_PROGRESS appropriately and improve
abort handling
--

additional changes include:
- initialise the usb abort task in the HCI allocx routine, so that it
can be safely usb_rem_task()'d.
- rework the handling of softintr vs cancellation vs timeout abort based
upon a scheme from Taylor:
when completing a transfer normally:
- if the status is not in progress, it must be cancelled or timed out,
and we should not process this xfer.
- set the status as normal.
- unconditionallly callout_stop() and usb_rem_task(). they're safe and
either aren't running, or will run and do nothing.
- finally call usb_transfer_complete().
when aborting a transfer:
- status should be cancelled or timed out.
- if cancelling, callout_halt and usb_rem_task_wait() to make sure the
timer is either done or cancelled.
- at this point, the ux_status must not be cancelled or timed out, and
if it is not in progress we're done.
- set the status.
- if the controller is dying, just return.
- perform HCI-specific tasks to abort this xfer.
- finally call usb_transfer_complete().
for the timeout and timeout task:
- if the HCI is not dying, and the ux_status is in progress, then
trigger the usb abort task.
- remove UXFER_ABORTWAIT and UXFER_ABORTING.

tested on:
- multiple PC systems with several types of devices: ugen/UPS, ucom,
umass with disk, ssd and cdrom backends, kbd, ms, using uhci, ehci
and xhci.
- erlite3: sd@umass on dwc2.
- sunblade2000: kbd/ms and umass disk on ohci.

untested:
- motg, slhci and ahci. motg has some portion of the new scheme
applied, but slhci and ahci require more study.

future work includes pushing a lot of the common abort handling into
usbdi.c and leaving upm_abort() for HC specific tasks, but this change
is pullup-able to netbsd-7 and netbsd-8 as it does not change any
external API, as well as removing over 100 lines of code while adding
over 30 new asserts.

XXX: pullup-7, pullup-8.

fix DIAGNOSTIC build by not copying ub_usepolling to stack before use

Sprinkle __diagused
 1.273.6.2  23-Nov-2017  martin Pull up following revision(s) (requested by skrll in ticket #385):
sys/dev/usb/xhci.c: revision 1.77
sys/external/bsd/dwc2/dwc2.c: revision 1.47
sys/dev/usb/motg.c: revision 1.19
sys/dev/usb/ehci.c: revision 1.257
sys/dev/usb/ohci.c: revision 1.276
sys/dev/usb/uhci.c: revision 1.279

s/PR_NOWAIT/PR_WAITOK/ in HCD allocx (allocate xfer) method
 1.273.6.1  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.279.2.4  30-Sep-2018  pgoyette Ssync with HEAD
 1.279.2.3  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.279.2.2  25-Jun-2018  pgoyette Sync with HEAD
 1.279.2.1  16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.281.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.281.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.281.2.1  10-Jun-2019  christos Sync with HEAD
 1.289.4.7  23-Dec-2020  martin Pull up following revision(s) (requested by riastradh in ticket #1159):

sys/dev/usb/ohci.c: revision 1.314
sys/external/bsd/dwc2/dwc2.c: revision 1.75
sys/dev/usb/ehci.c: revision 1.284
sys/dev/usb/uhci.c: revision 1.305
sys/dev/usb/xhci.c: revision 1.136

usb: Omit bogus assertions about struct usbd_pipe::up_intrxfer.

These assertions were only valid for pipes at UE_IN_DIR, UE_INTERRUPT
endpoints created with usbd_open_pipe_intr, which uses up_intrxfer to
pass the struct usbd_xfer object to usbd_close_pipe to free later.

In contrast, for pipes at UE_OUT_DIR, UE_INTERRUPT endpoints,
up_intrxfer is never initialized, so the assertion cannot be right.
In principle we might even have more than one outstanding interrupt
transfer at a time, rendering the point of the assertion moot anyway.

Found by interrupting a uhidev write to a u2f device.

ok nick
 1.289.4.6  12-Dec-2020  martin Pull up following revision(s) (requested by skrll in ticket #1150):

sys/dev/usb/ohci.c: revision 1.311
sys/dev/usb/ohci.c: revision 1.312
sys/dev/usb/ohcivar.h: revision 1.62

Restructure the abort code for TD based transfers (ctrl, bulk, intr).

In PR kern/22646 some TDs can be on the done queue when the abort start
and, if this is the case, they need to processed after the WDH interrupt.
Instead of waiting for WDH we release TDs that have been touched by the
HC and replace them with new ones. Once WDH happens the floating TDs
will be returned to the free list.

Also addresses the issue seen in PR kern/55835

Thanks to both Andreas Gustafsson and Edgar Fu=C3=9F for testing. Apologi=
es to
Andreas Gustafsson for not committing this to HEAD for 4y6m.w

Remove leading space that crept in in the last change
 1.289.4.5  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.289.4.4  25-Feb-2020  martin Pull up following revision(s) (requested by skrll in ticket #718):

sys/dev/usb/ohci.c: revision 1.296
sys/dev/usb/uhci.c: revision 1.294
sys/external/bsd/dwc2/dwc2.c: revision 1.72
sys/arch/mips/adm5120/dev/ahci.c: revision 1.21
sys/dev/usb/ehci.c: revision 1.274

Fix a memory leak. Spotted by nat@
 1.289.4.3  14-Dec-2019  martin Pull up following revision(s) (requested by gson in ticket #554):

sys/dev/usb/ohci.c: revision 1.292

Preserve the toggleCarry bit in the Endpoint Descriptor in
ohci_abort_xfer(). Fixes the OHCI part of PR kern/50278.
 1.289.4.2  14-Dec-2019  martin Pull up following revision(s) (requested by gson in ticket #553):

sys/dev/usb/ohci.c: revision 1.291

Preserve the toggleCarry bit in the Endpoint Descriptor when handling
a DataUnderrun condition. Fixes PR kern/54070.
 1.289.4.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.292.2.1  29-Feb-2020  ad Sync with head.
 1.310.2.3  03-Apr-2021  thorpej Sync with HEAD.
 1.310.2.2  03-Jan-2021  thorpej Sync w/ HEAD.
 1.310.2.1  14-Dec-2020  thorpej Sync w/ HEAD.
 1.315.4.2  01-Aug-2021  thorpej Sync with HEAD.
 1.315.4.1  17-Jun-2021  thorpej Sync w/ HEAD.
 1.323.4.3  02-Oct-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #910):

sys/arch/evbppc/wii/dev/hollywood.h: revision 1.3
sys/arch/evbppc/wii/dev/hollywood.c: revision 1.3
sys/arch/evbppc/wii/dev/ehci_hollywood.c: revision 1.3
sys/arch/evbppc/wii/dev/sdhc_hollywood.c: revision 1.3
sys/dev/usb/ohcireg.h: revision 1.29
sys/arch/evbppc/include/wii.h: revision 1.8
sys/arch/evbppc/conf/WII: revision 1.6
sys/arch/evbppc/wii/dev/ohci_hollywood.c: revision 1.3
sys/dev/usb/ohcivar.h: revision 1.63
sys/dev/usb/ohci.c: revision 1.329

wii: Restrict IOP access to shared peripherals.

Ensure that the IOP cannot access peripherals by clearing the appropriate
bus access bit. I have observed OHCI reporting completion for TDs living
in ARM reserved memory at runtime, this seems to suppress that.

ohci: Allocate a whole cacheline for all descriptors

Allocate a whole cacheline for all descriptor types such that:
i) they can be alloc'ed without USBMALLOC_COHERENT which can mean they're
now mapped cacheable, and
ii) the "soft" versions are cacheable, and mapped as small as possible.

Patch/idea mainly from Nick (skrll@) with a few fixes from me.

wii: Enable ohci(4) driver.
This seems to be stable now, let's enable support for plugging in LS/FS
devices directly into the system without a hub.
 1.323.4.2  02-Oct-2024  martin Fix previous, pullup of revision 1.328 totally gone wrong, try again:

Pull up following revision(s) (requested by skrll in ticket #926):

sys/dev/usb/ohci.c: revision 1.328

Fix some usb_syncmem calls and add some missing ones.
 1.323.4.1  02-Oct-2024  martin Pull up following revision(s) (requested by skrll in ticket #926):

sys/dev/usb/ohci.c: revision 1.328

Fix some usb_syncmem calls and add some missing ones.

RSS XML Feed