Home | History | Annotate | Download | only in usb
History log of /src/sys/dev/usb/ehci.c
RevisionDateAuthorComments
 1.333  29-Sep-2025  rin ehci: usb_syncmem against qtd **after** KASSERT for that qtd

Otherwise, we end up with stale data for DIAGNOSTIC kernel.

Fix device-probe failures discussed in PR kern/58730 for me.
(The main topic of the PR, NFS client lock-up, is not addressed.)
 1.332  26-Apr-2025  skrll branches: 1.332.2;
Some USBHIST (aka KERNHIST) fixes from sc.dying on current-users. One
fixup from me.
 1.331  16-Feb-2025  jakllsch ehci: wrap long line, add whitespace line to match other similar functions
 1.330  16-Feb-2025  jakllsch ehci(4): only sync isochronous DMA in the necessary direction
 1.329  04-Oct-2024  skrll G/C ehci_dump_qh_qtd
 1.328  03-Oct-2024  hannken Fix fallout from "struct ehci_qh_qtd_t" -> "ehci_qtd_t" conversion.

Kernels ALL/i386 and ALL/amd64 compile again.
 1.327  23-Sep-2024  skrll Ensure the overlay qtd_buffer{,_hi} fields are zeroised when QHs are
allocated/set. The allocation zeroisation was lost in my last commit.

Minor whitespace tweaks while I'm here.
 1.326  23-Sep-2024  skrll Allocate a whole cacheline for all the descriptor types used by ehci so
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.

A quick test of

dd if=/dev/rsd0 of=/dev/null bs=1m count=1024

improved by approximagely 10% on a Banana PI.
 1.325  05-Apr-2024  riastradh branches: 1.325.2;
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.324  10-Feb-2024  andvar fix various typos in comments and log messages.
 1.323  09-Feb-2024  andvar fix spelling mistakes, mainly in comments and log messages.
 1.322  06-Feb-2024  mrg avoid different struct type problem.
 1.321  05-Feb-2024  jmcneill Fix DMA sync flags in ehci_append_sqtd
 1.320  04-Feb-2024  mrg update my email address.
 1.319  28-Oct-2023  riastradh ehci(4): Fix bug causing missed wakeups since ehci.c 1.308.

For reasons beyond me now, I used cv_signal on the same cv that is
used to wait for the doorbell to be available _and_ to wait for the
host controller to acknowledge the doorbell. Which means when the
host controller acknowledges the doorbell, we might wake some thread
waiting for the doorbell to be available -- and leave the thread
waiting for the doorbell acknowledgment hanging indefinitely.

PR port-i386/57662

XXX pullup-10
 1.318  28-Oct-2023  riastradh ehci(4): Fix cv_timedwait loop in ehci_sync_hc.

Stop when

now - starttime >= delta,

i.e., when at least delta ticks have elapsed since the start, not
when

endtime - now > delta,

i.e., more than delta ticks _remain_ to sleep, which is never going
to happen (except on arithmetic overflow).

As is, what will happen in the case that should time out is that we
wake up after delta ticks, and find now = getticks() is exactly
endtime, so we retry cv_timedwait with timo=(endtime - now)=0 which
means sleep indefinitely with no timeout as if with cv_wait.

PR port-i386/57662

XXX pullup-10
 1.317  30-Jul-2023  skrll PR//57518: usb keyboard causes host controller to miss microframe

As per the USB 2.0 specification section 11.18.4; paragraph 3.b

For interrupt IN/OUT full-/low-speed transactions, the host must schedule a
complete-split transaction in each of the two microframes following the first
microframe in which the full-/low-speed transaction is budgeted. An additional
complete-split must also be scheduled in the third following microframe unless
the full-/low-speed transaction was budgeted to start in microframe Y6.
 1.316  20-Jul-2023  mrg various debug updates for some usb drivers

- several new *_DEBUG_DEFAULT options that allow usb debug values to
be set to a default that is non-zero:
EHCI_DEBUG_DEFAULT, UGEN_DEBUG_DEFAULT, URTWN_DEBUG_DEFAULT,
UMS_DEBUG_DEFAULT, and USB_DEBUG_DEFAULT
- ugen debug uses fewer usbhist lines for the same info
- ums.c converted from printf() to usbhist
 1.315  13-Dec-2022  jakllsch branches: 1.315.2;
fix grammar in comment
 1.314  13-Dec-2022  jakllsch ehci_device_isoc_init() returns errno not usbd_error; remove blank line
in ehci_device_fs_isoc_init() to match ehci_device_isoc_init()
 1.313  13-Dec-2022  jakllsch "periodic frame list", not "period frame list" in comments
 1.312  13-Dec-2022  jakllsch Add missing whitespace in error message.
 1.311  06-Apr-2022  mlelstv revert accidental last commit (except ukbd.c)
 1.310  06-Apr-2022  mlelstv remove debug printf
 1.309  13-Mar-2022  riastradh ehci(4): Serialize access to portsc registers.

Both ehci_roothub_ctrl and ehci_suspend/resume do r/m/w on them, so
use a mutex to serialize access to avoid stomping on each other.
 1.308  13-Mar-2022  riastradh ehci(4): Fix doorbell synchronization.

ehci_sync_hc was previously subject to spurious wakeup, in which case
the CPU might proceed from aborting and recycle a DMA buffer before
the hardware was done writing to it. Now the code is not subject to
spurious wakeup -- it waits (up to the 1sec timeout) for the relevant
interrupt to be delivered, not for anything else.
 1.307  09-Mar-2022  riastradh ehci(4): Omit bus lock around ehci_suspend/resume.

This no longer serializes access to the portsc registers, also used
by ehci_roothub_ctrl, but it does pose a potential deadlock with
softints to wake usb_delay_ms. So the bus lock doesn't help here,
and may cause deadlock.
 1.306  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.305  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.304  03-Mar-2022  riastradh usb: Factor usb_transfer_complete out of ubm_abortx method.
 1.303  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.302  12-Feb-2022  macallan initialize ntag with the old dmatag so we never end up with an invalid one
suggested by jmcneill@
 1.301  26-Jan-2022  macallan shut up an unused variable warning
apparently clang gets confused by bus_dmatag_subregion() being EOPNOTSUPP
on powerpc
 1.300  30-Dec-2021  mrg convert the ehci device owner ship change message to display the ehciN as well.
 1.299  24-Dec-2021  nia ehci(4): fix PR kern/56574: uaudio at ehci (not xhci) only outputs
rapid gunfire (patch from nick)
 1.298  23-Dec-2021  skrll Use the correct dmatag for all control structures. Also, don't KASSERT that
we're using the low 4GB for them and simply error out.

kern/56570: ehci panic on boot
 1.297  22-Dec-2021  skrll Three fixes

- pass the 64bit DMA tag if the HCCPARAMS says ehci supports it and the
64bit DMA tag is available/valid. This should help with the
"cannot create xfer" error on 64bit systems.

- restrict the control structure memory allocation to the low 4GB
(CTRLDSSEGMENT was always set to zero anyway)

- if ehci_init fails then tidyup before returning the error.
 1.296  22-Dec-2021  skrll Whitespace
 1.295  21-Dec-2021  skrll Remove an empty line
 1.294  21-Dec-2021  skrll Wrap a long line
 1.293  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.292  21-Dec-2021  skrll KASSERT(BUS_ADDR_HI32(baddr) == 0) in, and apply some consistent code
style to all of ehci_alloc_{sqh,sqtd,itd,sitd}.

While ehci can address memory >4GB for control structures
EHCI_CTRLDSSEGMENT is always set to zero so ehci assumes it's using the
low 4GB.
 1.291  18-Dec-2021  skrll Fix two bugs

i) EHCI_HCSPARAMS should be read with EREAD4 (and not EOREAD4). Spotted by
jmcneill

ii) Apply brackets so that ?: vs | operator precedence doesn't give the
wrong result.
 1.290  07-Dec-2021  skrll Match variable names to register names. Same binary before and after.
 1.289  07-Dec-2021  skrll More usb_status_t -> int
 1.288  07-Dec-2021  skrll Code consistency. NFCI.
 1.287  05-Dec-2021  riastradh ehci: Replace bogus polling during suspend by taking bus lock.

The system is not at high IPL or limited to a single CPU at this
point; it is running essentially normally, just with some devices
suspended. Other threads might be trying to touch EHCI registers,
which might have bad outcomes while we're suspending stuff. Enabling
polling only makes sense if there is a single thread and single CPU
running, such as when we enter ddb on crash.
 1.286  31-Aug-2021  mrg add missing newline and fix conditional for askroot/single user
hand over delay message. PR#56366.
 1.285  05-Jan-2021  skrll More converstion from usbd_status to int for function error reporting.
This time it's the turn of usb_allocmem.
 1.284  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.283  30-Nov-2020  msaitoh s/ we we / we /
 1.282  20-Sep-2020  gson branches: 1.282.2;
Talk Like a Pirate Day was yesterday.
 1.281  17-May-2020  skrll Copyright maintenance
 1.280  17-May-2020  skrll Use BUS_ADDR_{LO,HI}32. NFCI.
 1.279  15-May-2020  skrll Update ux_length in usbd_setup_isoc_xfer and use this to usb_syncmem
in the HCDs
 1.278  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.277  14-Mar-2020  christos revert the 0x% -> %# change for fixed width formats pointed out by uwe.
 1.276  13-Mar-2020  christos PR/55068: sc.dying: Fix printf formats:
- no %s/%p for kernel log
- 0x% -> %#
- always %j for kernel log
 1.275  05-Mar-2020  skrll Use howmany. NFC.
 1.274  21-Feb-2020  skrll Fix a memory leak. Spotted by nat@
 1.273  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.272  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.271  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.270  12-Feb-2020  riastradh 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.
 1.269  04-Feb-2020  mrg don't call usb_syncmem() for zero-length packets.
 1.268  31-Dec-2019  skrll branches: 1.268.2;
Remove a stray '
 1.267  13-Jun-2019  maxv branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.
 1.266  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.265  18-Sep-2018  mrg 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().
 1.264  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.263  16-Sep-2018  skrll interrupt has two 'r's

fix another typo while I'm here (flsah)
 1.262  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.261  09-Aug-2018  jakllsch fix DIAGNOSTIC build by not copying ub_usepolling to stack before use
 1.260  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.259  06-Jun-2018  maya branches: 1.259.2;
Remove duplicate ;
 1.258  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.257  17-Nov-2017  skrll branches: 1.257.2;
s/PR_NOWAIT/PR_WAITOK/ in HCD allocx (allocate xfer) method
 1.256  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.255  08-Jul-2017  jmcneill Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@
 1.254  03-Oct-2016  dholland branches: 1.254.8;
Improve diagnostic print seen in PR 51524.
 1.253  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.252  14-May-2016  skrll branches: 1.252.2;
Only set QH CMASK for FS/LS interrupt transfers
 1.251  06-May-2016  skrll Fix a KASSERT (ub_usepolling || mutex)
 1.250  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.249  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.248  13-Mar-2016  skrll KNF
 1.247  11-Dec-2015  skrll Don't need to nest #ifdef EHCI_DEBUG
 1.246  29-Oct-2015  mrg eliminate USBHIST as a define/option. it was entangled with USB_DEBUG
and only referenced a handful of times. rename any usage in configs.

fixes recent build problems i introduced with the previous files.usb
change.
 1.245  11-Sep-2015  skrll Fix up USBMODE registers in sc_vendor_init functions and not in the ehci
driver.
 1.244  24-Aug-2015  pooka add some _KERNEL_OPT as the finishing touch
 1.243  19-Aug-2015  skrll More IPL_SCHED -> IPL_USB
 1.242  11-Jul-2015  msaitoh Use correct E[O]{READ,WRITE} function.
 1.241  02-Jul-2015  skrll Somehow the ; disappeared from the previouis commit
 1.240  02-Jul-2015  skrll From FreeBSD rev1.30 via OpenBSD:
- always initialise the pipe multiplier to a valid value
- do not unchain the the interrupt QHs immediately after initialisation

Prompted by msaitoh
 1.239  11-May-2015  skrll Remove '\n' from panic message.
 1.238  01-Mar-2015  skrll Fix previous for HEAD
 1.237  01-Mar-2015  skrll Improve debug
 1.236  01-Mar-2015  skrll Whitespace
 1.235  24-Dec-2014  skrll Typo in USBHIST_LOG message
 1.234  22-Sep-2014  skrll branches: 1.234.2;
Wrap a long line
 1.233  16-Sep-2014  skrll Use lower case for USBHIST messages.
 1.232  13-Sep-2014  skrll Whitespace.
 1.231  13-Sep-2014  skrll Fix reversed argument to USBHIST_LOG
 1.230  13-Sep-2014  skrll Fix build when USB_DEBUG is defined and EHCI_DEBUG isn't. The converse is
always true.

PR/49201 (broken build with options USB_DEBUG (latest current))
 1.229  12-Sep-2014  skrll Improve USB debugging with USBHIST based on KERNHIST.

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

Remove the #define mess in usb.h.

This was started by mrg@ and updated by reinoud@
 1.228  05-Aug-2014  skrll branches: 1.228.2; 1.228.6;
Remove #ifdef DIAGNOSTIC around sc from the root interrupt abort methods
now it's always used.
 1.227  05-Aug-2014  skrll Simplify the freeing of the interrupt pipe transfer. Inspired by OpenBSD.
 1.226  04-Aug-2014  skrll Fix duplicate assignment to NULL of sqtdstart in ehci_device_isoc_start
and initialise sqtdend is NULL instead.

From OpenBSD.
 1.225  17-Feb-2014  skrll branches: 1.225.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.224  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.223  15-Dec-2013  para mark variable usage, fix non DIAGNOSTIC non DEBUG build
 1.222  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.221  01-Dec-2013  skrll In ehci_check_qh_intr don't treat a short control transfer as done if the
status phase is still inflight. Let the hardware complete it.

PR/48358: Repeated low-speed USB control transfers returning short data
fail on EHCI

PR/46696: uhub disables port where USB keyboard attached
 1.220  01-Dec-2013  skrll Adjust KASSERT in device_ctrl_done to polling case.

PR/48213: ehci assertion failure during boot
 1.219  26-Nov-2013  skrll Improve DEBUG message.
 1.218  25-Nov-2013  skrll Improve DEBUG output.
 1.217  23-Nov-2013  skrll Simplify debug/DIAGNOSTIC code.
 1.216  23-Nov-2013  skrll Whitespace in DIAGNOSTIC code.
 1.215  04-Nov-2013  christos mark a variable __diagused
 1.214  01-Nov-2013  skrll Style.
 1.213  28-Oct-2013  matt Add an explicit initialization of .new_device = NULL
 1.212  12-Sep-2013  martin Remove unused variables
 1.211  07-Sep-2013  matt add KASSERT to make sure softints are not NULL
 1.210  07-Sep-2013  skrll Typo.
 1.209  25-Aug-2013  skrll Use UE_GET_XFERTYPE. No functional change.
 1.208  21-Aug-2013  jakllsch swap positions of ehci_root_ctrl_done and ehci_root_intr_done so that they
are grouped with their respective transfer types
 1.207  25-Jun-2013  jakllsch branches: 1.207.2;
Change "translater" to "translator" in comment.
 1.206  04-Apr-2013  skrll Don't take the bus lock in usbd_transfer_complete when polling.

Sprinkle || polling in KASSERTsw
 1.205  01-Feb-2013  tsutsui Call usb_syncmem() against descriptors more strictly.
(not sure if the previous ones were fatal though)
 1.204  29-Jan-2013  christos use a pool instead of a linked list to avoid synchronization problems.
 1.203  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.202  15-Jan-2013  christos fix the fix of the fix of the format string.
 1.201  15-Jan-2013  mbalmer Fix a debug printf format.
 1.200  15-Jan-2013  christos fix printf formats
 1.199  15-Jan-2013  christos don't use kprintf() directly, it does not lock so it just garbles the output.
 1.198  09-Jan-2013  skrll Remove unused length member of ctrl xfer in struct ehci_pipe
 1.197  07-Jan-2013  prlw1 Allow USB memory allocation by multiple segments in scatter/gather lists
rather than in a single contiguous block which causes problems with
large USB video frames.
Based on a patch by Jeremy Morse in the thread
http://mail-index.netbsd.org/current-users/2011/01/26/msg015532.html
Tested by developing http://code.opencv.org/issues/2360
OK jmcneill@
 1.196  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.195  05-Jan-2013  christos - need opt_usb.h if depending on USB_DEBUG
- remove trailing whitespace
- add missing KERNEL_RCSID
 1.194  02-Jan-2013  skrll KNF a comment.
 1.193  04-Nov-2012  matt Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.
 1.192  22-Jun-2012  mrg branches: 1.192.2;
fix locking for isoc transfers, as reported (and the fix tested) by prlw1.
 1.191  19-Jun-2012  skrll Typos in comments.
 1.190  10-Jun-2012  mrg merge the jmcneill-usbmp branch. many thanks to jared for the
initial work, and every one else who has tested things for me.
this is largely my fault at this point :-)

the main changes are something like:

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

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

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

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

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

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

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

the TODO.usbmp file has specific details on what is left to
do, including what device-specific changes should be done now
that the whole framework is ready.
 1.189  17-Mar-2012  bouyer Always check index against array bound; keep only the printf under
DIAGNOSTIC. Suggested by matthew green
 1.188  15-Mar-2012  bouyer Do not read array before detecting array overflow, found by gcc -O3
 1.187  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.186  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.185  06-Mar-2012  mrg pull down from usbmp:

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

- remove SPLUSBCHECK. it has been broken and disabled for ages.
 1.183  23-Dec-2011  jakllsch branches: 1.183.2; 1.183.6; 1.183.8;
Revert previous due to active usbmp branch(es).
 1.182  22-Dec-2011  jakllsch Adjust-away inconsistent and trailing whitespace.
 1.181  01-Jul-2011  mrg branches: 1.181.2; 1.181.6;
use an unsigned type for unsigned calcations. avoid GCC 4.5 warnings.
 1.180  30-Jun-2011  wiz dependant -> dependent
 1.179  10-Jun-2011  jmcneill ehci_set_qh_qtd: terminate alternate next qTD pointer with EHCI_NULL, not 0
 1.178  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.177  28-May-2011  tsutsui branches: 1.177.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.176  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.175  27-May-2011  drochner remember the data toggle bit per (bulk) endpoint rather than per
pipe, as required by the spec
This helps in cases where pipes are opened/closed without reconfiguring
the device in between, eg with the ugen driver.
only for UHCI/EHCI, don't have an OHCI to test
 1.174  20-Apr-2011  drochner in alloc_sqtd_chain(), deal with the case where a data packet ends
exactly at a page boundary, and the FORCE_SHORT_XFER was set by the
client (which causes that an empty descriptor is needed to terminate
the transfer), from Gordon McNutt per PR kern/44883
(fixed a bit differently than the proposed patch for aesthetical
reasons -- avoids the page pointer to come into unexpexted area earlier)
 1.173  18-Jan-2011  jmcneill fix port reset for non-ETTF case broken by previous commit
 1.172  18-Jan-2011  matt Add preliminary support for Embedded Transaction Translator Function (as
found on the MPC8536 and AR9334) which allows low/full devices to be
connected to an EHCI root hub.
 1.171  03-Nov-2010  dyoung branches: 1.171.2;
Stop using the compatibility macros USB_ATTACH(), USB_DETACH(),
USB_MATCH(), et cetera. These files produce the same assembly
(according to objdump -d) before and after the change
 1.170  16-Oct-2010  kiyohara Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().
 1.169  07-Jul-2010  msaitoh For interrupt transfer, nak throttling must be disabled, but for the other
transfer type, nak throttling should be enabled from the veiwpoint that
avoids the memory thrashing. Fixes a problem that interrupt transfer stall
on some EHCI controllers (e.g. Geode LX). Fixed by Yamada Katsumi.
 1.168  02-Jun-2010  jakllsch Improve EHCI isochronous code, fix scheduling.

- Create and use symbolic constants.

- Convert some switch statements to functionally-similar caculations.

- Correct scheduling interval of high-speed isochronous transactions.
Previous calculation produced half the intended rate.
 1.167  29-May-2010  jakllsch Nvidia EHCI controllers do not ignore one or more of the "Port Number",
"Hub Address", "Split Completion Mask" fields in the Queue Head marked
"This field is ignored by the host controller unless the EPS field
indicates a full- or low-speed device.".

Therefore, only populate these fields for full- and low-speed devices.

Fixes PR#37884.
 1.166  24-Feb-2010  dyoung branches: 1.166.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.165  08-Jan-2010  dyoung branches: 1.165.2;
Expand PMF_FN_* macros.
 1.164  14-Nov-2009  uebayasi Sprinkle static.
 1.163  12-Nov-2009  dyoung Simplify activation hook.

(sc_dying must die!)
 1.162  01-Nov-2009  uebayasi EHCI_NULL is already little-endian. No htole32() needed. Pointed out by
Tsubai Masanari.
 1.161  01-Nov-2009  uebayasi Fix some whitespaces.
 1.160  01-Nov-2009  uebayasi Update referencial URLs.
 1.159  04-Sep-2009  dyoung Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).
 1.158  27-Jul-2009  sketch Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.
 1.157  18-Mar-2009  cegger Ansify function definitions w/o arguments. Generated with sed.
 1.156  16-Dec-2008  christos branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)
 1.155  28-Nov-2008  jmorse Fixed high-speed isoc USB transfers, 64 bit capable host controllers have a different transfer descriptor to non-capable controllers.

Added dma-sync of data buffer before scheduling transfers
 1.154  14-Oct-2008  jmcneill branches: 1.154.2; 1.154.4;
ehci_dump_itd and _sitd are unused
 1.153  14-Oct-2008  jmcneill kern/39727: race condition in ehci isoc abort xfer path

From Jeremy Morse:

* Serialize access to the ehci intrlist.
* Change the ehci intrlist to a tailq so xfers are not queued out of order.
* In ehci_check_itd_intr, don't treat a transfer error as an indication
that the xfer is no longer active.
 1.152  11-Oct-2008  jmcneill Revert previous.
 1.151  11-Oct-2008  jmcneill ehci_check_itd_intr: correct logic for checking for active itds
 1.150  06-Oct-2008  jmcneill ehci_free_itd: use LIST_INSERT_HEAD rather than
LIST_INSERT_AFTER(LIST_FIRST(..), ..) when returning itds to the freelist
to prevent a crash when the freelist is empty. Reviewed by Jeremy Morse.
 1.149  05-Oct-2008  jmcneill Fix issue where multi-transaction isoc endpoints were forced to single
transactions, from Jeremy Morse.
 1.148  10-Sep-2008  cegger update TODO list: we have isoc support
 1.147  09-Sep-2008  hubertf Sign over copyright of Jeremy Morse's code to TNF, OK'd by Jeremy Morse
(still mention Jeremy as contributor)
 1.146  09-Sep-2008  jmcneill Clarify the message printed by the kernel when a low or full speed
device with isochronous endpoints is attached to a hi-speed hub. Also
silence a printf in ehci_device_isoc_close
 1.145  28-Aug-2008  drochner add a "break" so that the isoc setup code doesn't access uninitialized
data if the frames allocated by a client driver don't use up all the
microframes within a frame
 1.144  21-Aug-2008  drochner use M_NOWAIT in an early allocation for consistency, from Kevin Lo
 1.143  16-Aug-2008  drochner fix my last commit: add missing "break"s, from Marcus Glocker
 1.142  12-Aug-2008  drochner fix an off-by-one in isochronous interval check, and streamline some
frame / microframe calculation, avoiding overestimation of frames needed,
reviewed by Jared D. McNeill
 1.141  03-Aug-2008  cegger make i386 ALL kernel compile
 1.140  02-Aug-2008  jmcneill Update copyright.
 1.139  02-Aug-2008  jmcneill High speed isochronous support, from Jeremy Morse as part of Google
Summer of Code 2008.
 1.138  28-Jun-2008  bouyer branches: 1.138.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.137  16-Jun-2008  drochner fix selective port resume signaling (not used in normal operation,
just for correctness)
 1.136  21-May-2008  drochner branches: 1.136.2;
fix argument to usb_setup_reserve() (called from USB host adapter drivers)
to be device_t consistently, from Quentin Garnier
 1.135  28-Apr-2008  martin branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses
 1.134  28-Mar-2008  drochner branches: 1.134.2; 1.134.4;
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.133  07-Mar-2008  dyoung Use device_t and accessors. Setup power management in the PCI
front-end (XXX needs to look more alike the Cardbus front-end).
Establish the shutdown hook using PMF.
 1.132  22-Feb-2008  dyoung Add a method to detach child.

Cosmetic: use device_t and accessors. Use aprint_*_dev(). Use
PMF_FN_{ARGS,CALL,PROTO}.
 1.131  03-Feb-2008  drochner branches: 1.131.2; 1.131.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.130  28-Jan-2008  jmcneill No need to operate in polling mode in ehci_resume.
 1.129  28-Jan-2008  jmcneill Ensure that we don't clear the EHCI_PS_CLEAR bits by writing 1s to them
when modifying port state in ehci_suspend and ehci_resume.
 1.128  28-Jan-2008  jmcneill Release port ownership on detach, so devices will be routed to companion
controllers. This allows 'drvctl -d ehci0' to disable USB 2.0 mode.
 1.127  09-Dec-2007  jmcneill Merge jmcneill-pm branch.
 1.126  05-Dec-2007  ad branches: 1.126.2;
lockmgr -> mutex
 1.125  19-Oct-2007  ad branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h
 1.124  15-Aug-2007  kiyohara branches: 1.124.2; 1.124.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.123  26-Feb-2007  drochner branches: 1.123.4; 1.123.12; 1.123.14; 1.123.18;
-in root hub emulation, return a sane value as language code
-constify "methods" tables and (partly) descriptor templates
 1.122  10-Feb-2007  mlelstv branches: 1.122.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.121  09-Feb-2007  ad Merge newlock2 to head.
 1.120  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.119  07-Jan-2007  drochner Remove the code which disables port status change interrupts for 1s
when one occured -- this makes that events get lost (or delayed until
the next change), in particular in the handover process from the EHCI
to a companion controller, laeving the port dead under some circumstances.
This fixes the "can't reconnect" symptom for me.
I don't see why the interrupt should be disabled - it is acknowledged
in the interrupt handler and shouldn't be active again until the next
status change.
 1.118  30-Nov-2006  drochner branches: 1.118.2;
in the interrupt endpoint descriptor of the simulated root hub, fix the
poll interval: since this is a highspeed device, it should be a "12"
(just for sanity; this stuff is not used by the kernel, only userland
usb exploration code might see it)
 1.117  28-Nov-2006  drochner Remove the code which tried to guess the toggle bit after a short
transfer. It was wrong because it didn't consider block boundaries.
Instead, use the updated toggle from the transfer descriptor -- this
is supposedly cheaper than modulo arithmetics.
This fixes a problem similar to PR kern/34070 for me.
 1.116  22-Nov-2006  drochner -fix interpretation of the poll interval in interrupt descriptors for
USB2/highspeed: This is an exponent now, not milliseconds.
(There are wrong example descriptors for hubs in the USB2 spec; tolerate
invalid values and assume 256ms which is good for hubs, just in case
someone blindly copied from the book.)
-being here, fix an obvious memory leak
 1.115  16-Nov-2006  christos __unused removal on arguments; approved by core.
 1.114  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.113  12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.112  24-Sep-2006  jmcneill Add "name" parameter to powerhook_establish, to aid debugging. No objections
on tech-kern@
 1.111  30-Aug-2006  christos branches: 1.111.2; 1.111.4;
fix incomplete initializers
 1.110  28-May-2006  blymn Clean up bogus whitespace
 1.109  14-Apr-2006  christos branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.
 1.108  17-Jan-2006  xtraeme branches: 1.108.2; 1.108.4; 1.108.6; 1.108.8; 1.108.10;
From OpenBSD:

--
Add a workaround for VIA EHCI controllers which, under load, signal qTD
completion before they have performed writeback from the overlay qTD.

This condition would exhibit itself as a umass stall that never recovers.
--

This fixes the problem reported by Thomas Klausner on current-users@:
http://mail-index.netbsd.org/current-users/2006/01/17/0000.html
 1.107  21-Nov-2005  augustss branches: 1.107.2;
Make the unused ehci_dump() function non-static.
 1.106  20-Nov-2005  augustss Keep a flag for each port that keeps track of if the port has been reset
instead of having one flag for the controller.

Also, don't try to modify read-only power bits if the controller doesn't
support power cobntrol.
 1.105  18-Jul-2005  augustss branches: 1.105.6;
Make sure we don't enable host controller interrupts until all
initialization is finished.
 1.104  30-May-2005  christos branches: 1.104.2;
- const poisoning
- eliminate variable shadowing
 1.103  05-May-2005  augustss Make sure all physical addresses are filled in the qTD even when we have
a page offset.

From Dan Ellis (as was the previous fix).
 1.102  05-May-2005  augustss Make sure to honor the USBD_FORCE_SHORT_XFER flag and generate an empty
transfer when necessary.
 1.101  01-May-2005  wiz Fix typo.
 1.100  01-May-2005  augustss Update TODO comment and copyright.
 1.99  01-May-2005  augustss Only complain when opening full speed isoc devices, other types seem to
work reasonably (even if there is no proper scheduling of the TT yet).
 1.98  01-May-2005  augustss Fix the error check on completion of an xfer. Just because the qTD status
field has error bits set doesn't mean there has been an error, unless the
HALTED bit is set as well. The old behaviour could result in a transfer
being considered failed by the software, but a success by the device.
This seems to have affected mostly mass storage devices.

Pointed out by Dan Ellis in kern/29731.
 1.97  01-May-2005  augustss Timeout while polling is in ms not ticks.

From OpenBSD.
 1.96  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.95  27-Apr-2005  augustss Get bit reversal table right this time.
 1.94  27-Apr-2005  augustss Interrupt polling was spread very unevenly. Use the same bit reversal
trick as in ohci.c to correct this.
 1.93  27-Apr-2005  augustss With the interrupt fix in the previous commit low and full speed devices
have a chance to work, so allow them (with a warning).
Make a small change to the transaction translator scheduling to make it
at least hobble along (again from Dan Ellis).
 1.92  27-Apr-2005  augustss Don't null the qh_link point in the interrupt tree after it has been
initialized. From Dan Ellis in kern/30003.
 1.91  27-Feb-2005  perry branches: 1.91.2;
nuke trailing whitespace
 1.90  21-Dec-2004  fvdl branches: 1.90.2; 1.90.4;
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.89  03-Dec-2004  augustss Don't error out if the number of companion controllers is wrong, just
omplain a go ahead.
 1.88  26-Oct-2004  augustss Allow strings descriptor 0 to be fetched. It's the default language index.
 1.87  25-Oct-2004  augustss Preserve some bits in the overlay qTD.
 1.86  24-Oct-2004  augustss Add a comment.
 1.85  24-Oct-2004  augustss Follow the spec more closely when updating the overlay qTD in the QH.
 1.84  24-Oct-2004  augustss Only delay interrupt my 2 miucroframes instead of 8. This improves
Ethernet performance.
 1.83  24-Oct-2004  augustss No need to generate an interrupt at the data part of a control transfer,
it's generated by the status transfer.
 1.82  24-Oct-2004  augustss Make sure to update the data toggle on short transfers.
This makes my Ethernet adapter much happier.
 1.81  24-Oct-2004  augustss Don't allow open of low/full speed pipes types that will not work yet.
 1.80  23-Oct-2004  augustss Keep track of what high speed port (if any) a device belongs to so we can
set the transaction translator fields for the transfer.
Add a gross hack for split transaction completion in the ehci driver that
allows control transfers to be translated. Interrupt transfers do not work.
Warn when any low/full speed device is opened.
 1.79  23-Oct-2004  augustss Turn the printf about needing toggle update into a DPRINTF. Things
seem to work even when this message appears.
Why is it there, Charles?
 1.78  22-Oct-2004  augustss Add interrupt transfers. From OpenBSD.
Having interrupt transfers enables some more device types to be used,
most notably USB2 hubs. USB2 hubs still cannot handle anything but
USB2 devices, because there is node code to handle hub Transaction Translation
yet.
XXX This code doesn't do good bw scheduling, but it's certainly better than
nothing. :)
 1.77  22-Oct-2004  augustss Insert from ifdefs for soft interrupt related stuff. From OpenBSD.
 1.76  21-Oct-2004  augustss A little portability stuff.
 1.75  21-Oct-2004  xtraeme Fix typo in comment: compolicated -> complicated.
 1.74  21-Oct-2004  augustss Add suspend/resume support.
From OpenBSD.
 1.73  21-Oct-2004  augustss Use do .. while wrappers for debug print.
From OpenBSD.
 1.72  21-Oct-2004  augustss Match function names in debug messages with real name.
From OpenBSD.
 1.71  21-Oct-2004  augustss ANSIfy.
 1.70  17-Sep-2004  yamt make this compile with OHCI_DEBUG without EHCI_DEBUG.
 1.69  17-Jul-2004  mycroft hcpriv is not actually used here. Remove references to it.
 1.68  09-Jul-2004  mycroft Adjust some silliness that was causing us to do extra work for "frame list
rollover" interrupts, which we pretty much ignore.
 1.67  06-Jul-2004  mycroft Fix a byte order error.
 1.66  30-Jun-2004  mycroft Fix an endianness problem (EHCI_NULL was being double-swapped).
 1.65  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.64  23-Jun-2004  mycroft Further cleanup of toggle handling. Now that we use EHCI_QH_DTC, we don't
need to fiddle with the TOGGLE bit in the overlay descriptor, so minimize
how much we fuss with it.
 1.63  22-Jun-2004  mycroft Fix an error in a debug printf().
 1.62  22-Jun-2004  mycroft Adjust a couple of comments to make it clear WTF is going on.
 1.61  22-Jun-2004  mycroft Update comment.
 1.60  22-Jun-2004  mycroft Remove comment about the data toggle being borked.
 1.59  22-Jun-2004  enami As the ehci_idone() now uses the variable `epipe' unconditionally, always
declare it (in other words, make this file compile w/o EHCI_DEBUG).
 1.58  22-Jun-2004  mycroft Fix a stupid bug in ehci_check_intr() that caused use to try to complete a
transaction that was still running. Now ehci can handle multiple devices
being active at once.
 1.57  22-Jun-2004  mycroft Oops. Remove a couple of printf()s.
 1.56  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.55  22-Jun-2004  mycroft Set the data toggle correctly, and use EHCI_QTD_DTC. This fixes problems with
my ALi-based drive enclosure (it works now, rather than failing to attach).
Also seems to work with a GL811-based enclosure and an ASUS enclosure with a
CD-RW, on both Intel and NEC controllers.

Note: The ALi enclosure is currently very SLOW, due to some issue with taking
too long to notice that the QTD is complete. This requires more investigation.
 1.54  17-Jan-2004  jdolecek branches: 1.54.2;
Michael van Elst reports his USB2 disk works stable after latest Chuck's
ehci.c changes, so remove the item from TODO.
 1.53  09-Jan-2004  chs in ehci_softintr() when looping over the active xfers, save the next pointer
before calling ehci_check_intr(), since that will free the xfer structure
if the xfer is complete.
 1.52  07-Jan-2004  jdolecek add list of known issues, from Lennart Augustsson and Michael van Elst
 1.51  29-Dec-2003  toshii Use the correct wValue to get hub desriptors.
Also, make wValue checks of root hub codes less strict.
 1.50  18-Oct-2003  simonb Remove assigned-to but otherwise unused variables.
Remove unreachable break after return statements.
 1.49  13-Oct-2003  enami KNF the previous commit.
 1.48  12-Oct-2003  mycroft Fix problems with ehci on controllers that support 64-bit addressing. From
Cliff Wright, PR 23128. Thanks!
 1.47  10-May-2003  augustss branches: 1.47.2;
Try to make message about missing companion controllers clearer.
 1.46  09-Mar-2003  augustss Change debug message.
 1.45  22-Feb-2003  tsutsui Use mstohz() in <sys/param.h> rather than homegrown MS_TO_TICKS().
 1.44  16-Feb-2003  augustss Don't take xfers off the interrupt list if they are not on it yet.
 1.43  08-Feb-2003  ichiro change URL pointers of USB[1,2] specification
 1.42  04-Feb-2003  augustss Fix a botched loop copied from the ohci driver (already fixed in ohci.c).
Pointed out by Daniel Ellis <dan@pod51.demon.co.uk>.
 1.41  31-Jan-2003  thorpej Use aprint_*().
 1.40  19-Nov-2002  martin Add a comment describing why ehci_dump() has been added back despite
not being referenced.
Suggested by Perry E. Metzger.
 1.39  11-Nov-2002  martin Ooops, put back ehci_dump() which I accidently removed in the last commit.
Thanks to enami tsugutomo for noticing this.
 1.38  09-Nov-2002  martin Move ehci_dump_exfer into #ifdef DIAGNOSTIC, it's not called w/o.
From FUKAUMI Naoki in PR 18988.
 1.37  27-Sep-2002  provos remove trailing \n in panic(). approved perry.
 1.36  14-Aug-2002  augustss Set segment register if the device is 64 bit capable.
 1.35  13-Aug-2002  enami The revision of new document is 1.0.
 1.34  13-Aug-2002  augustss Increase the timeout waiting for reset to finish.
Update documentation URL.
 1.33  11-Jul-2002  augustss Get rid of trailing white space.
 1.32  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.31  28-May-2002  augustss Change DMAADDR macro slightly.
 1.30  19-May-2002  augustss branches: 1.30.2;
Update dma memory access API a little.
 1.29  31-Dec-2001  augustss branches: 1.29.8;
Change abort slightly.
Change debug output.
 1.28  28-Dec-2001  augustss More DIAGNOSTIC.
 1.27  01-Dec-2001  enami Fix null pointer dereference when EHCI_DEBUG is defined (and
debug is enabled).
 1.26  23-Nov-2001  augustss Improve xfer abort sequence.
Fix another bug in qTD chain allocation.
 1.25  22-Nov-2001  augustss Fix a bug in qTD chain allocation.
Fix a qTD leak.
Handle out of memory conditions better.

My USB 2.0 CD-RW now mounts nicely and I can access files.
Performance is still lacking (it's at about 2Mbyte/s).
 1.24  21-Nov-2001  augustss Make it compile without debug.
 1.23  21-Nov-2001  augustss Follow a safer protocol when updating the QH.
The EHCI driver isn't really working properly, but now the SCSI driver
correctly identifies my CD-RW drive! :-)
 1.22  21-Nov-2001  augustss Implement (incorrect?) data toggle clear method.
Implement allocation of qTD chains.
 1.21  21-Nov-2001  augustss Mask correct interrupt after error interrupt.
 1.20  21-Nov-2001  augustss Mask the correct interrupt after a door bell interrupt.
 1.19  21-Nov-2001  augustss Implement bulk transfers.
 1.18  21-Nov-2001  augustss Add some interrupt processing.
 1.17  21-Nov-2001  augustss Pay more attention to if the HC is being unplugged.
 1.16  21-Nov-2001  augustss Add missing }
 1.15  21-Nov-2001  augustss Set up control xfers.
Handle xfer timeouts.
Better debug messages.
 1.14  20-Nov-2001  augustss Support port indicator light.
 1.13  20-Nov-2001  augustss Use longer reset for root hubs (as told in the spec).
 1.12  20-Nov-2001  augustss Don't wait for door bell interrupt when controller has been disconnected.
 1.11  20-Nov-2001  augustss Use device speed in setup.
Simplify async list handling.
 1.10  19-Nov-2001  augustss Start of pipe open routine.
 1.9  18-Nov-2001  augustss Add more fields to hardware structs.
Add memory allocation for various data structures.
 1.8  16-Nov-2001  augustss Implement port reset sequence correctly.
 1.7  16-Nov-2001  augustss Add some more data structure defs.
 1.6  16-Nov-2001  augustss Recognize port status changes.
Hand over low and full speed devices to companion controller.
 1.5  15-Nov-2001  augustss Add root hub emulation.
 1.4  13-Nov-2001  lukem add RCSIDs
 1.3  10-Nov-2001  augustss Add some register defines.
Print companion controllers.
 1.2  24-Dec-2000  augustss branches: 1.2.2; 1.2.4; 1.2.6; 1.2.10;
Even stubs need improvements.
 1.1  24-Dec-2000  augustss Add some placeholders for the EHCI (USB 2) driver.

Don't get your hopes up. I've not even finished reading the
(100+) page spec, and I have no hardware.
 1.2.10.1  12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.2.6.4  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.2.6.3  06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.6.2  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.6.1  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.10  11-Dec-2002  thorpej Sync with HEAD.
 1.2.4.9  11-Nov-2002  nathanw Catch up to -current
 1.2.4.8  18-Oct-2002  nathanw Catch up to -current.
 1.2.4.7  27-Aug-2002  nathanw Catch up to -current.
 1.2.4.6  01-Aug-2002  nathanw Catch up to -current.
 1.2.4.5  10-Jul-2002  nathanw Don't need curlwp here.
 1.2.4.4  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.2.4.3  20-Jun-2002  nathanw Catch up to -current.
 1.2.4.2  08-Jan-2002  nathanw Catch up to -current.
 1.2.4.1  14-Nov-2001  nathanw Catch up to -current.
 1.2.2.2  05-Jan-2001  bouyer Sync with HEAD
 1.2.2.1  24-Dec-2000  bouyer file ehci.c was added on branch thorpej_scsipi on 2001-01-05 17:36:28 +0000
 1.29.8.4  29-Aug-2002  gehenna catch up with -current.
 1.29.8.3  15-Jul-2002  gehenna catch up with -current.
 1.29.8.2  20-Jun-2002  gehenna catch up with -current.
 1.29.8.1  30-May-2002  gehenna Catch up with -current.
 1.30.2.1  15-Mar-2004  jmc Pullup rev 1.51 (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.47.2.9  11-Dec-2005  christos Sync with head.
 1.47.2.8  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.47.2.7  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.47.2.6  17-Jan-2005  skrll Sync with HEAD.
 1.47.2.5  18-Dec-2004  skrll Sync with HEAD.
 1.47.2.4  02-Nov-2004  skrll Sync with HEAD.
 1.47.2.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.47.2.2  18-Sep-2004  skrll Sync with HEAD.
 1.47.2.1  03-Aug-2004  skrll Sync with HEAD
 1.54.2.13  18-Sep-2004  he branches: 1.54.2.13.2;
Pull up revision 1.70 (requested by yamt in ticket #860):
Make this compile with OHCI_DEBUG and without EHCI_DEBUG.
 1.54.2.12  07-Jul-2004  tron Pull up revision 1.67 (requested by mycroft in ticket #609):
Fix a byte order error.
 1.54.2.11  02-Jul-2004  he Pull up revisions 1.65-1.66 (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.
o Fix an endianness problem in the ehci.c driver.
 1.54.2.10  24-Jun-2004  tron Pull up revision 1.64 (requested by mycroft in ticket #535):
Further cleanup of toggle handling. Now that we use EHCI_QH_DTC, we don't
need to fiddle with the TOGGLE bit in the overlay descriptor, so minimize
how much we fuss with it.
 1.54.2.9  24-Jun-2004  tron Pull up revision 1.63 (requested by mycroft in ticket #535):
Fix an error in a debug printf().
 1.54.2.8  24-Jun-2004  tron Pull up revision 1.62 (requested by mycroft in ticket #535):
Adjust a couple of comments to make it clear WTF is going on.
 1.54.2.7  24-Jun-2004  tron Pull up revision 1.61 (requested by mycroft in ticket #535):
Update comment.
 1.54.2.6  24-Jun-2004  tron Pull up revision 1.60 (requested by mycroft in ticket #535):
Remove comment about the data toggle being borked.
 1.54.2.5  24-Jun-2004  tron Pull up revision 1.59 (requested by mycroft in ticket #535):
As the ehci_idone() now uses the variable `epipe' unconditionally, always
declare it (in other words, make this file compile w/o EHCI_DEBUG).
 1.54.2.4  24-Jun-2004  tron Pull up revision 1.58 (requested by mycroft in ticket #535):
Fix a stupid bug in ehci_check_intr() that caused use to try to complete a
transaction that was still running. Now ehci can handle multiple devices
being active at once.
 1.54.2.3  24-Jun-2004  tron Pull up revision 1.57 (requested by mycroft in ticket #535):
Oops. Remove a couple of printf()s.
 1.54.2.2  24-Jun-2004  tron Pull up revision 1.56 (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.54.2.1  24-Jun-2004  tron Pull up revision 1.55 (requested by mycroft in ticket #535):
Set the data toggle correctly, and use EHCI_QTD_DTC. This fixes problems with
my ALi-based drive enclosure (it works now, rather than failing to attach).
Also seems to work with a GL811-based enclosure and an ASUS enclosure with a
CD-RW, on both Intel and NEC controllers.
Note: The ALi enclosure is currently very SLOW, due to some issue with taking
too long to notice that the QTD is complete. This requires more investigation.
 1.54.2.13.2.2  13-May-2005  riz Pull up revision 1.98 via patch (requested by augustss in ticket #1496):
Fix the error check on completion of an xfer. Just because the qTD status
field has error bits set doesn't mean there has been an error, unless the
HALTED bit is set as well. The old behaviour could result in a transfer
being considered failed by the software, but a success by the device.
This seems to have affected mostly mass storage devices.
Pointed out by Dan Ellis in kern/29731.
 1.54.2.13.2.1  13-May-2005  riz Pull up revision 1.90 (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.90.4.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.90.2.1  29-Apr-2005  kent sync with -current
 1.91.2.10  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.91.2.9  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.91.2.8  22-Jan-2006  tron Pull up following revision(s) (requested by xtraeme in ticket #1123):
sys/dev/usb/ehcivar.h: revision 1.23
sys/dev/pci/ehci_pci.c: revision 1.22
sys/dev/usb/ehci.c: revision 1.108
From OpenBSD:

--
Add a workaround for VIA EHCI controllers which, under load, signal qTD
completion before they have performed writeback from the overlay qTD.
This condition would exhibit itself as a umass stall that never
recovers.
--

This fixes the problem reported by Thomas Klausner on current-users@:
http://mail-index.netbsd.org/current-users/2006/01/17/0000.html
 1.91.2.7  07-May-2005  tron branches: 1.91.2.7.2;
Pull up revision 1.103 (requested by augustss in ticket #249):
Make sure all physical addresses are filled in the qTD even when we have
a page offset.
From Dan Ellis (as was the previous fix).
 1.91.2.6  07-May-2005  tron Pull up revision 1.102 (requested by augustss in ticket #249):
Make sure to honor the USBD_FORCE_SHORT_XFER flag and generate an empty
transfer when necessary.
 1.91.2.5  01-May-2005  tron Pull up revision 1.98 (requested by augustss in ticket #240):
Fix the error check on completion of an xfer. Just because the qTD status
field has error bits set doesn't mean there has been an error, unless the
HALTED bit is set as well. The old behaviour could result in a transfer
being considered failed by the software, but a success by the device.
This seems to have affected mostly mass storage devices.
Pointed out by Dan Ellis in kern/29731.
 1.91.2.4  01-May-2005  tron Pull up revision 1.95 (requested by augustss in ticket #217):
Get bit reversal table right this time.
 1.91.2.3  01-May-2005  tron Pull up revision 1.94 (requested by augustss in ticket #217):
Interrupt polling was spread very unevenly. Use the same bit reversal
trick as in ohci.c to correct this.
 1.91.2.2  01-May-2005  tron Pull up revision 1.93 (requested by augustss in ticket #217):
With the interrupt fix in the previous commit low and full speed devices
have a chance to work, so allow them (with a warning).
Make a small change to the transaction translator scheduling to make it
at least hobble along (again from Dan Ellis).
 1.91.2.1  01-May-2005  tron Pull up revision 1.92 (requested by augustss in ticket #217):
Don't null the qh_link point in the interrupt tree after it has been
initialized. From Dan Ellis in kern/30003.
 1.91.2.7.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.104.2.10  17-Mar-2008  yamt sync with head.
 1.104.2.9  27-Feb-2008  yamt sync with head.
 1.104.2.8  04-Feb-2008  yamt sync with head.
 1.104.2.7  21-Jan-2008  yamt sync with head
 1.104.2.6  07-Dec-2007  yamt sync with head
 1.104.2.5  27-Oct-2007  yamt sync with head.
 1.104.2.4  03-Sep-2007  yamt sync with head.
 1.104.2.3  26-Feb-2007  yamt sync with head.
 1.104.2.2  30-Dec-2006  yamt sync with head.
 1.104.2.1  21-Jun-2006  yamt sync with head.
 1.105.6.1  22-Nov-2005  yamt sync with head.
 1.107.2.1  01-Feb-2006  yamt sync with head.
 1.108.10.1  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.108.8.1  19-Apr-2006  elad sync with head.
 1.108.6.3  03-Sep-2006  yamt sync with head.
 1.108.6.2  26-Jun-2006  yamt sync with head.
 1.108.6.1  24-May-2006  yamt sync with head.
 1.108.4.2  01-Jun-2006  kardel Sync with head.
 1.108.4.1  22-Apr-2006  simonb Sync with head.
 1.108.2.1  09-Sep-2006  rpaulo sync with head
 1.109.2.1  19-Jun-2006  chap Sync with head.
 1.111.4.2  10-Dec-2006  yamt sync with head.
 1.111.4.1  22-Oct-2006  yamt sync with head
 1.111.2.4  06-Feb-2007  ad Quiten noisy boot messages.
 1.111.2.3  01-Feb-2007  ad Sync with head.
 1.111.2.2  12-Jan-2007  ad Sync with head.
 1.111.2.1  18-Nov-2006  ad Sync with head.
 1.118.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.118.2.1  21-Feb-2007  tron branches: 1.118.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.118.2.1.2.1  04-Sep-2008  skrll Sync with netbsd-4.
 1.122.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.123.18.8  09-Dec-2007  jmcneill Sync with HEAD.
 1.123.18.7  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.123.18.6  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.123.18.5  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.123.18.4  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.123.18.3  16-Aug-2007  jmcneill Sync with HEAD.
 1.123.18.2  07-Aug-2007  jmcneill Suspend and resume individual ports, from FreeBSD. With this change, USB
devices no longer detach and reattach on resume.
 1.123.18.1  03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.123.14.1  15-Aug-2007  skrll Sync with HEAD.
 1.123.12.6  13-Nov-2009  uebayasi Reduce the diff a little.
 1.123.12.5  12-Nov-2009  uebayasi Sort struct usbd_bus_methods member initializers.
 1.123.12.4  21-May-2008  itohy cleanup
 1.123.12.3  21-May-2008  itohy Use aux memory.
 1.123.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.123.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.123.4.2  23-Oct-2007  ad Sync with head.
 1.123.4.1  20-Aug-2007  ad Sync with HEAD.
 1.124.6.1  25-Oct-2007  bouyer Sync with HEAD.
 1.124.2.3  23-Mar-2008  matt sync with HEAD
 1.124.2.2  09-Jan-2008  matt sync with HEAD
 1.124.2.1  06-Nov-2007  matt sync with HEAD
 1.125.4.2  26-Dec-2007  ad Sync with head.
 1.125.4.1  08-Dec-2007  ad Sync with head.
 1.125.2.3  18-Feb-2008  mjf Sync with HEAD.
 1.125.2.2  27-Dec-2007  mjf Sync with HEAD.
 1.125.2.1  08-Dec-2007  mjf Sync with HEAD.
 1.126.2.1  11-Dec-2007  yamt sync with head.
 1.131.6.5  17-Jan-2009  mjf Sync with HEAD.
 1.131.6.4  28-Sep-2008  mjf Sync with HEAD.
 1.131.6.3  29-Jun-2008  mjf Sync with HEAD.
 1.131.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.131.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.131.2.1  24-Mar-2008  keiichi sync with head.
 1.134.4.6  11-Aug-2010  yamt sync with head.
 1.134.4.5  11-Mar-2010  yamt sync with head
 1.134.4.4  16-Sep-2009  yamt sync with head
 1.134.4.3  19-Aug-2009  yamt sync with head.
 1.134.4.2  04-May-2009  yamt sync with head.
 1.134.4.1  16-May-2008  yamt sync with head.
 1.134.2.3  17-Jun-2008  yamt sync with head.
 1.134.2.2  04-Jun-2008  yamt sync with head
 1.134.2.1  18-May-2008  yamt sync with head.
 1.135.2.4  10-Oct-2008  skrll Sync with HEAD.
 1.135.2.3  24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.135.2.2  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.135.2.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.136.2.2  03-Jul-2008  simonb Sync with head.
 1.136.2.1  18-Jun-2008  simonb Sync with head.
 1.138.2.2  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.138.2.1  19-Oct-2008  haad Sync with HEAD.
 1.154.4.3  20-May-2011  bouyer Pull up following revision(s) (requested by drochner in ticket #1620):
sys/dev/usb/ehci.c: revision 1.174
in alloc_sqtd_chain(), deal with the case where a data packet ends
exactly at a page boundary, and the FORCE_SHORT_XFER was set by the
client (which causes that an empty descriptor is needed to terminate
the transfer), from Gordon McNutt per PR kern/44883
(fixed a bit differently than the proposed patch for aesthetical
reasons -- avoids the page pointer to come into unexpexted area earlier)
 1.154.4.2  12-Jun-2010  riz branches: 1.154.4.2.4;
Pull up following revision(s) (requested by jakllsch in ticket #1409):
sys/dev/usb/ehci.c: revision 1.167
Nvidia EHCI controllers do not ignore one or more of the "Port Number",
"Hub Address", "Split Completion Mask" fields in the Queue Head marked
"This field is ignored by the host controller unless the EPS field
indicates a full- or low-speed device.".
Therefore, only populate these fields for full- and low-speed devices.
Fixes PR#37884.
 1.154.4.1  29-Nov-2008  bouyer branches: 1.154.4.1.4;
Pull up following revision(s) (requested by jmorse in ticket #138):
sys/dev/usb/ehcireg.h: revision 1.29
sys/dev/usb/ehci.c: revision 1.155
Fixed high-speed isoc USB transfers, 64 bit capable host controllers
have a different transfer descriptor to non-capable controllers.
Added dma-sync of data buffer before scheduling transfers
 1.154.4.2.4.2  02-Aug-2011  matt Pull in ETTF EHCI changes from -current.
 1.154.4.2.4.1  07-Jan-2011  matt Add Embedded Transaction Translator Function support. No proof it works
yet.
 1.154.4.1.4.1  20-May-2011  matt bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
 1.154.2.2  28-Apr-2009  skrll Sync with HEAD.
 1.154.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.156.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.165.2.4  06-Nov-2010  uebayasi Sync with HEAD.
 1.165.2.3  22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.165.2.2  17-Aug-2010  uebayasi Sync with HEAD.
 1.165.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.166.2.6  12-Jun-2011  rmind sync with head
 1.166.2.5  31-May-2011  rmind sync with head
 1.166.2.4  21-Apr-2011  rmind sync with head
 1.166.2.3  05-Mar-2011  rmind sync with head
 1.166.2.2  03-Jul-2010  rmind sync with head
 1.166.2.1  30-May-2010  rmind sync with head
 1.171.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.177.2.1  23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.181.6.20  05-Apr-2012  mrg make these compile without DIAGNOSTIC.
 1.181.6.19  05-Apr-2012  mrg sync to latest -current.
 1.181.6.18  12-Mar-2012  mrg fix detach bugs:
- need to disestablish the ehci softint's.
- need to destroy needs_explore_cv
- note that ehci.c inits locks, but ehci_pci.c destroys them due to the
way that the (pci) front end does softint handling, and can only be
trusted to destroy them. XXX need to fix this, by looking at the many
ehci frontends as well and checking ohci/uhci.
 1.181.6.17  11-Mar-2012  mrg sync to latest -current
 1.181.6.16  04-Mar-2012  mrg minor KNF.
 1.181.6.15  03-Mar-2012  mrg revert a stray splx(s) that somehow got back in here..
 1.181.6.14  26-Feb-2012  mrg - add some more "XXXSMP ok" tags
- use cpu_softintr_p() instead of checking LP_INTR directly
 1.181.6.13  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.181.6.12  25-Feb-2012  mrg copyright maintenence.
 1.181.6.11  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.181.6.10  20-Feb-2012  mrg make sure we have the thread lock when calling usb_transfer_complete()
 1.181.6.9  20-Feb-2012  mrg remove the intr_lock from the mp usb api, it wasn't used.
 1.181.6.8  20-Feb-2012  mrg remove a bunch of superfluous parens.
 1.181.6.7  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.181.6.6  20-Feb-2012  mrg several changes to the MP usb apis, and other misc changes:

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

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

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

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

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

- add many more asserts

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

- convert usb_taskq to use mutex/cv

- convert needs_explore usage into a cv on the thread lock

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

- use IPL_SCHED instead of IPL_USB (aka biglocked) interrupts

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

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

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

- begin to document the locking scheme

- convert usbd_*lock_pipe() into real function-like macros
 1.181.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.181.6.2  04-Dec-2011  jmcneill branches: 1.181.6.2.2;
change callout_stop + usbd_delay_ms to callout_halt + callout_destroy in
ehci_detach
 1.181.6.1  04-Dec-2011  jmcneill Make ehci mpsafe.
 1.181.6.2.2.1  08-Dec-2011  mrg sync a couple more changes from the main branch, uaudio@ohci still works.
 1.181.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.181.2.4  23-Jan-2013  yamt sync with head
 1.181.2.3  16-Jan-2013  yamt sync with (a bit old) head
 1.181.2.2  30-Oct-2012  yamt sync with head
 1.181.2.1  17-Apr-2012  yamt sync with head
 1.183.8.1  26-Sep-2013  riz Pull up following revision(s) (requested by skrll in ticket #950):
sys/dev/usb/uhci.c: revision 1.255
sys/dev/usb/uhci.c: revision 1.256
sys/dev/usb/ehci.c: revision 1.205
sys/dev/usb/uhci.c: revision 1.258
Add missed byteswap ops for BE machines in block added in rev 1.223.
Call usb_syncmem() against descriptors more strictly.
(not sure if the previous ones were fatal though)
Deal with control transfers better by
- removing the UHCI_PTR_VF flag for the setup and status stages
which means they are scheduled less aggressively. Some devices
appear to require this (blymn@ has one). The flag was
introduced as a performance improvement for bulk transfers.
- Checking for short reads and making sure the status stage runs
if they're encountered.
PR/47522 Enumeration of LUFA/Atmel devices on UHCI fails
Thanks to jak@ and blymn@ for testing and mlelstv@ for comments.
 1.183.6.1  26-Sep-2013  riz Pull up following revision(s) (requested by skrll in ticket #950):
sys/dev/usb/uhci.c: revision 1.255
sys/dev/usb/uhci.c: revision 1.256
sys/dev/usb/ehci.c: revision 1.205
sys/dev/usb/uhci.c: revision 1.258
Add missed byteswap ops for BE machines in block added in rev 1.223.
Call usb_syncmem() against descriptors more strictly.
(not sure if the previous ones were fatal though)
Deal with control transfers better by
- removing the UHCI_PTR_VF flag for the setup and status stages
which means they are scheduled less aggressively. Some devices
appear to require this (blymn@ has one). The flag was
introduced as a performance improvement for bulk transfers.
- Checking for short reads and making sure the status stage runs
if they're encountered.
PR/47522 Enumeration of LUFA/Atmel devices on UHCI fails
Thanks to jak@ and blymn@ for testing and mlelstv@ for comments.
 1.183.2.2  14-Dec-2013  bouyer Pull up following revision(s) (requested by skrll in ticket #990):
sys/dev/usb/ehci.c: revision 1.221
In ehci_check_qh_intr don't treat a short control transfer as done if the
status phase is still inflight. Let the hardware complete it.
PR/48358: Repeated low-speed USB control transfers returning short data
fail on EHCI
PR/46696: uhub disables port where USB keyboard attached
 1.183.2.1  26-Sep-2013  riz Pull up following revision(s) (requested by skrll in ticket #950):
sys/dev/usb/uhci.c: revision 1.255
sys/dev/usb/uhci.c: revision 1.256
sys/dev/usb/ehci.c: revision 1.205
sys/dev/usb/uhci.c: revision 1.258
Add missed byteswap ops for BE machines in block added in rev 1.223.
Call usb_syncmem() against descriptors more strictly.
(not sure if the previous ones were fatal though)
Deal with control transfers better by
- removing the UHCI_PTR_VF flag for the setup and status stages
which means they are scheduled less aggressively. Some devices
appear to require this (blymn@ has one). The flag was
introduced as a performance improvement for bulk transfers.
- Checking for short reads and making sure the status stage runs
if they're encountered.
PR/47522 Enumeration of LUFA/Atmel devices on UHCI fails
Thanks to jak@ and blymn@ for testing and mlelstv@ for comments.
 1.192.2.5  03-Dec-2017  jdolecek update from HEAD
 1.192.2.4  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.192.2.3  23-Jun-2013  tls resync from head
 1.192.2.2  25-Feb-2013  tls resync with head
 1.192.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.207.2.2  18-May-2014  rmind sync with head
 1.207.2.1  28-Aug-2013  rmind sync with head
 1.225.2.1  10-Aug-2014  tls Rebase.
 1.228.6.2  26-Jan-2017  skrll Sync with HEAD/nhusb
 1.228.6.1  06-Sep-2016  skrll First pass at netbsd-7 updated with USB code from HEAD
 1.228.2.3  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.228.2.2  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.228.2.1  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.234.2.110  05-Sep-2017  skrll #ifdef DIAGNOSTIC -> KASSERT and add another KASSERT
 1.234.2.109  28-Aug-2017  skrll Sync with HEAD
 1.234.2.108  28-Dec-2016  skrll Whitespace
 1.234.2.107  27-Dec-2016  skrll Reduce scope of variables
 1.234.2.106  27-Dec-2016  skrll Remove a printf
 1.234.2.105  27-Dec-2016  skrll Improve and simplify ehci_abort_xfer. The races should now be removed.
 1.234.2.104  05-Oct-2016  skrll Sync with HEAD
 1.234.2.103  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.234.2.102  29-May-2016  skrll Sync with HEAD
 1.234.2.101  30-Apr-2016  skrll Move the struct usb_task to struct usbd_xfer for everyone to use.
 1.234.2.100  16-Apr-2016  skrll Fix usbd_status vs int in *_alloc_*_chain
 1.234.2.99  16-Apr-2016  skrll Don't leak memory in *_alloc_*td_chain if allocation fails.
 1.234.2.98  16-Apr-2016  skrll KNF
 1.234.2.97  16-Apr-2016  skrll Remove an unnecessary ux_hcpriv assignment
$CVS: ----------------------------------------------------------------------
 1.234.2.96  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.234.2.95  26-Mar-2016  skrll Grab sc_istthreshhold (not used as yet)
 1.234.2.94  26-Mar-2016  skrll Re-org for clarity (sparams vs cparams)
 1.234.2.93  20-Mar-2016  skrll Provide and use DPRINTF{,N} macros in the same way as all other HCDs.

No functional change.
 1.234.2.92  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.234.2.91  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.234.2.90  27-Feb-2016  skrll Why KASSERT when you can KASSERTMSG?wq
 1.234.2.89  27-Feb-2016  skrll Initialise ex_isrunning in ehci_device_isoc_init. No real functional
change as the memory was zeroised.
 1.234.2.88  21-Feb-2016  skrll We need to delete the transfer from the interrupt list in
ehci_abort_isoc_xfer
 1.234.2.87  19-Feb-2016  skrll Add a comment
 1.234.2.86  07-Feb-2016  skrll Unwrap line
 1.234.2.85  06-Feb-2016  skrll KNF comments with whitespace
 1.234.2.84  06-Feb-2016  skrll Missed hunk from previous
 1.234.2.83  06-Feb-2016  skrll Make interrupt handling MP safe by not dropping the bus lock while
traversing the active transfer list. Instead move the complete transfers
from the active list to a complete list and do callbacks on this complete
list.

usbd_transfer_complete can safely drop the bus lock while traversing this
private list.
 1.234.2.82  06-Feb-2016  skrll Improve DEBUG
 1.234.2.81  06-Feb-2016  skrll Whitespace
 1.234.2.80  06-Feb-2016  skrll Fix the fix... look a the correct list of TDs when aborting a transfer
 1.234.2.79  11-Jan-2016  skrll Fix active control transfer aborts - need to run through the entire TD
chain from start to finish and not just on any data phase.
 1.234.2.78  10-Jan-2016  skrll Debug improvements
 1.234.2.77  09-Jan-2016  skrll Consistency with USBHIST_LOGN
 1.234.2.76  05-Jan-2016  skrll Don't leak sqtds in ehci_free_sqtds
 1.234.2.75  03-Jan-2016  skrll In ehci_idone check for timed out or aborted transfer earlier and before
twiddling ex_isdone to avoid KASSERT firing.
 1.234.2.74  28-Dec-2015  skrll Correct KASSERT
 1.234.2.73  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.234.2.72  23-Dec-2015  skrll Revert previous... I got ahead of myself
 1.234.2.71  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.234.2.70  21-Dec-2015  skrll Fix locking botch
 1.234.2.69  08-Dec-2015  skrll Improve ex->ex_sqtds handling a little.
 1.234.2.68  08-Dec-2015  skrll Wrap a long line
 1.234.2.67  14-Nov-2015  skrll Shuffle comment
 1.234.2.66  14-Nov-2015  skrll Not much point printing NULL in a KASSERTMSG, so don't.
 1.234.2.65  14-Nov-2015  skrll Whitespace
 1.234.2.64  25-Oct-2015  skrll Restructure the xfer methods so that (close to) minimal work in done in softint
context. Now all memory allocation is done in thread context.

Addresses kern/48308 for ehci(4), fixes a bunch of locking bugs around the
*TD free lists, and plugs some memory leaks on error conditions.

XXX revisit for isoc caching models (4.7.2.1)
 1.234.2.63  25-Oct-2015  skrll Initialise some variables in their declarations.
 1.234.2.62  24-Oct-2015  skrll One ';' is enough most of the time.
 1.234.2.61  24-Oct-2015  skrll Initialise some variables in their declarations.
 1.234.2.60  24-Oct-2015  skrll KNF a comment
 1.234.2.59  24-Oct-2015  skrll Use #if 0 / #endif instead of comment for disabling code
 1.234.2.58  20-Oct-2015  skrll Consistently providei/use *_{XFER,PIPE,BUS}2SC, etc macros
 1.234.2.57  17-Oct-2015  skrll Whitespace
 1.234.2.56  16-Oct-2015  skrll Whitespace.
 1.234.2.55  16-Oct-2015  skrll Whitespace.
 1.234.2.54  11-Oct-2015  skrll Update ubm_allocx with the isoc frame count parameter and use it in
dwctwo(4)
 1.234.2.53  11-Oct-2015  skrll Remove unused struct entry
 1.234.2.52  10-Oct-2015  skrll Provide and use some macros to access ehci_{xfer,pipe} from
usbd_{xfer,pipe}

No functional change
 1.234.2.51  09-Oct-2015  skrll Wrap/unwrap long lines
 1.234.2.50  22-Sep-2015  skrll Sync with HEAD
 1.234.2.49  06-Jun-2015  skrll Sync with HEAD
 1.234.2.48  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.234.2.47  06-Apr-2015  skrll Use an anonymous union in struct ehci_pipe and rename the ctl member to
ctrl.

No functional change.
 1.234.2.46  21-Mar-2015  skrll G/C unused variable/code
 1.234.2.45  19-Mar-2015  skrll Do the same as OpenBSD and get rid of the *_handle typedefs and use
plain structures insteads
 1.234.2.44  18-Mar-2015  skrll No need to touch ux_done in ehci_device_{fs_,}isoc_start
 1.234.2.43  17-Mar-2015  skrll KNF
 1.234.2.42  16-Mar-2015  skrll Correct / improve some usb_syncmem calls.
 1.234.2.41  15-Mar-2015  skrll Only dump sqtds if we're not isochronous
 1.234.2.40  07-Mar-2015  skrll Add missing locking in ehci_device_fs_isoc_transfer
 1.234.2.39  05-Mar-2015  skrll Remove macro magic. No functional change.
 1.234.2.38  03-Mar-2015  skrll Convert to __BIT and friends.

No functional change.
 1.234.2.37  03-Mar-2015  skrll Improve EHCI_PAGE macros and usage.

No functional change.
 1.234.2.36  02-Mar-2015  skrll Simplify - no functional change.
 1.234.2.35  02-Mar-2015  skrll ex_isdone / ux_state tidyup
 1.234.2.34  01-Mar-2015  skrll Whitespace
 1.234.2.33  01-Mar-2015  skrll Improve debug
 1.234.2.32  01-Mar-2015  skrll Whitespace.
 1.234.2.31  22-Feb-2015  skrll Improvie debugging
 1.234.2.30  01-Feb-2015  skrll Define and use EHCI_QTD_MAXTRANSFER. No functional change.
 1.234.2.29  01-Feb-2015  skrll KNF
 1.234.2.28  02-Jan-2015  skrll KNF - whitespace.
 1.234.2.27  02-Jan-2015  skrll KNF. Comments.
 1.234.2.26  02-Jan-2015  skrll Oops, missed a semicolon in previous
 1.234.2.25  02-Jan-2015  skrll Convert some #ifdef DIAGNOSTIC / #endifs to KASSERT.
 1.234.2.24  02-Jan-2015  skrll Remove #ifdef DIAGNOSTIC / #endif from around a USBHIST_LOG call.
 1.234.2.23  24-Dec-2014  skrll No need for '\n' in USBHIST_LOG message.
 1.234.2.22  24-Dec-2014  skrll Actually log the erroneous bInterval in ehci_device_fs_isoc_start
 1.234.2.21  24-Dec-2014  skrll Typo in USBHIST_LOG message.
 1.234.2.20  24-Dec-2014  skrll Prefix ehci_xfer members with 'ex_'. No functional change.
 1.234.2.19  23-Dec-2014  skrll Remove an item and use a union to reduce the size of ehci_xfer
 1.234.2.18  22-Dec-2014  skrll KNF a comment.
 1.234.2.17  22-Dec-2014  skrll #ifdef DIAGNOSTIC ... panic... #endif -> KASSERT
 1.234.2.16  06-Dec-2014  skrll KNF. Remove argument name from function declarations.

No functional change.
 1.234.2.15  05-Dec-2014  skrll Use int for return type for [eou]chi_init and motg_init.
 1.234.2.14  05-Dec-2014  skrll KNF. Remove ( ) from return statements.
 1.234.2.13  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.234.2.12  03-Dec-2014  skrll Rename usbroothub_subr.[ch] to usbroothub.[ch]
 1.234.2.11  03-Dec-2014  skrll Provide a USETWD macro for use with USB words designated
initialisers.
 1.234.2.10  03-Dec-2014  skrll Use designated initializers for more descriptors.
 1.234.2.9  03-Dec-2014  skrll Use designated initialisers for usb_device_descriptor_t structs.
 1.234.2.8  03-Dec-2014  skrll The grand renaming of structure members.

No functional change.
 1.234.2.7  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.234.2.6  01-Dec-2014  skrll Add prefixes to method structures member names. No functional change.
 1.234.2.5  01-Dec-2014  skrll Remove usbd_bus no_intrs member it was (virtually) unused.
 1.234.2.4  30-Nov-2014  skrll Use ASSERT_SLEEPABLE.
 1.234.2.3  30-Nov-2014  skrll Add full speed isoc support to ehci(4). Based on the patch posted in

https://mail-index.netbsd.org/port-arm/2013/04/14/msg001842.html

From Masao Uebayashi via Sebastien Bocahu
 1.234.2.2  30-Nov-2014  skrll Whitespace
 1.234.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.252.2.1  04-Nov-2016  pgoyette Sync with HEAD
 1.254.8.8  02-Aug-2023  martin Pull up following revision(s) (requested by skrll in ticket #1877):

sys/dev/usb/ehci.c: revision 1.317

PR 57518: usb keyboard causes host controller to miss microframe

As per the USB 2.0 specification section 11.18.4; paragraph 3.b
For interrupt IN/OUT full-/low-speed transactions, the host must schedule a
complete-split transaction in each of the two microframes following the
first microframe in which the full-/low-speed transaction is budgeted. An
additional complete-split must also be scheduled in the third following
microframe unless the full-/low-speed transaction was budgeted to start
in microframe Y6.
 1.254.8.7  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.254.8.6  28-Sep-2018  martin Fixup for ticket #1037 - parts of the patch were accidently missing.
 1.254.8.5  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.254.8.4  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.254.8.3  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.254.8.2  02-Nov-2017  snj Pull up following revision(s) (requested by pgoyette in ticket #335):
share/man/man9/kernhist.9: 1.5-1.8
sys/arch/acorn26/acorn26/pmap.c: 1.39
sys/arch/arm/arm32/fault.c: 1.105 via patch
sys/arch/arm/arm32/pmap.c: 1.350, 1.359
sys/arch/arm/broadcom/bcm2835_bsc.c: 1.7
sys/arch/arm/omap/if_cpsw.c: 1.20
sys/arch/arm/omap/tiotg.c: 1.7
sys/arch/evbarm/conf/RPI2_INSTALL: 1.3
sys/dev/ic/sl811hs.c: 1.98
sys/dev/usb/ehci.c: 1.256
sys/dev/usb/if_axe.c: 1.83
sys/dev/usb/motg.c: 1.18
sys/dev/usb/ohci.c: 1.274
sys/dev/usb/ucom.c: 1.119
sys/dev/usb/uhci.c: 1.277
sys/dev/usb/uhub.c: 1.137
sys/dev/usb/umass.c: 1.160-1.162
sys/dev/usb/umass_quirks.c: 1.100
sys/dev/usb/umass_scsipi.c: 1.55
sys/dev/usb/usb.c: 1.168
sys/dev/usb/usb_mem.c: 1.70
sys/dev/usb/usb_subr.c: 1.221
sys/dev/usb/usbdi.c: 1.175
sys/dev/usb/usbdi_util.c: 1.67-1.70
sys/dev/usb/usbroothub.c: 1.3
sys/dev/usb/xhci.c: 1.75
sys/external/bsd/drm2/dist/drm/i915/i915_gem.c: 1.34
sys/kern/kern_history.c: 1.15
sys/kern/kern_xxx.c: 1.74
sys/kern/vfs_bio.c: 1.275-1.276
sys/miscfs/genfs/genfs_io.c: 1.71
sys/sys/kernhist.h: 1.21
sys/ufs/ffs/ffs_balloc.c: 1.63
sys/ufs/lfs/lfs_vfsops.c: 1.361
sys/ufs/lfs/ulfs_inode.c: 1.21
sys/ufs/lfs/ulfs_vnops.c: 1.52
sys/ufs/ufs/ufs_inode.c: 1.102
sys/ufs/ufs/ufs_vnops.c: 1.239
sys/uvm/pmap/pmap.c: 1.37-1.39
sys/uvm/pmap/pmap_tlb.c: 1.22
sys/uvm/uvm_amap.c: 1.108
sys/uvm/uvm_anon.c: 1.64
sys/uvm/uvm_aobj.c: 1.126
sys/uvm/uvm_bio.c: 1.91
sys/uvm/uvm_device.c: 1.66
sys/uvm/uvm_fault.c: 1.201
sys/uvm/uvm_km.c: 1.144
sys/uvm/uvm_loan.c: 1.85
sys/uvm/uvm_map.c: 1.353
sys/uvm/uvm_page.c: 1.194
sys/uvm/uvm_pager.c: 1.111
sys/uvm/uvm_pdaemon.c: 1.109
sys/uvm/uvm_swap.c: 1.175
sys/uvm/uvm_vnode.c: 1.103
usr.bin/vmstat/vmstat.c: 1.219
Reorder to test for null before null deref in debug code
--
Reorder to test for null before null deref in debug code
--
KNF
--
No need for '\n' in UVMHIST_LOG
--
normalise a BIOHIST log message
--
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3)
format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of
kernhist(9)"
but it is possible that I've missed some of them. I would be glad
to
update any stragglers that anyone identifies.
--
For some reason this single kernel seems to have outgrown its declared
size as a result of the kernhist(9) changes. Bump the size.
XXX The amount of increase may be excessive - anyone with more detailed
XXX knowledge please feel free to further adjust the value
appropriately.
--
Misssed one cast of pointer --> uintptr_t in previous kernhist(9) commit
--
And yet another one. :(
--
Use correct mark-up for NetBSD version.
--
More improvements in grammar and readability.
--
Remove a stray '"' (obvious typo) and add a couple of casts that are
probably needed.
--
And replace an instance of "%p" conversion with "%#jx"
--
Whitespace fix. Give Bl tag table a width. Fix Xr.
 1.254.8.1  18-Jul-2017  snj Pull up following revision(s) (requested by jmcneill in ticket #114):
sys/arch/arm/samsung/exynos_intr.h: revision 1.3
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.2
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.3
sys/arch/arm/sunxi/sunxi_gates.c: revision 1.1
distrib/utils/embedded/mkimage: revision 1.66
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.4
sys/arch/arm/sunxi/sunxi_rsb.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.5
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.6
sys/arch/arm/sunxi/sun8i_h3_ccu.c: revision 1.7
sys/dev/gpio/gpio.c: revision 1.59
sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.1
sys/conf/Makefile.kern.inc: revision 1.257
sys/arch/evbarm/conf/ODROID-XU_INSTALL: file removal
sys/arch/arm/sunxi/sunxi_ccu_prediv.c: revision 1.2
sys/conf/Makefile.kern.inc: revision 1.258
sys/arch/arm/fdt/psci_fdt.h: revision 1.1
sys/arch/arm/sunxi/sunxi_resets.c: revision 1.1
sys/arch/evbarm/conf/files.sunxi: revision 1.1
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.8
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.9
sys/arch/arm/samsung/files.exynos: revision 1.22
distrib/utils/embedded/conf/armv7.conf: revision 1.13
sys/arch/arm/samsung/files.exynos: revision 1.23
sys/arch/evbarm/conf/std.tegra: revision 1.15
distrib/utils/embedded/conf/armv7.conf: revision 1.14
sys/arch/arm/samsung/files.exynos: revision 1.24
distrib/utils/embedded/conf/armv7.conf: revision 1.15
sys/arch/evbarm/sunxi/genassym.cf: revision 1.1
sys/arch/arm/samsung/exynos_fdt.c: file removal
sys/dev/fdt/fdt_pinctrl.c: revision 1.4
sys/arch/arm/samsung/exynos_sysmmu.c: revision 1.2
sys/arch/arm/sunxi/sun8i_h3_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_twi.c: revision 1.1
sys/dev/usb/ehci.c: revision 1.255
sys/arch/arm/sunxi/sunxi_twi.c: revision 1.2
sys/arch/arm/sunxi/sun8i_a83t_ccu.h: revision 1.1
sys/dev/ic/dwc_mmc.c: revision 1.11
sys/arch/arm/cortex/gic.c: revision 1.24
distrib/evbarm/instkernel/ramdisk/Makefile: revision 1.17
etc/etc.evbarm/Makefile.inc: revision 1.87
etc/etc.evbarm/Makefile.inc: revision 1.88
sys/arch/arm/fdt/gic_fdt.c: revision 1.5
etc/Makefile: revision 1.429
sys/arch/arm/fdt/gic_fdt.c: revision 1.6
sys/arch/arm/fdt/gic_fdt.c: revision 1.7
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.2
sys/arch/evbarm/conf/std.sunxi: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.3
sys/arch/evbarm/conf/std.sunxi: revision 1.2
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.4
sys/arch/evbarm/conf/std.sunxi: revision 1.3
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.5
sys/arch/arm/sunxi/sunxi_ccu_div.c: revision 1.1
sys/dev/gpio/gpiovar.h: revision 1.17
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.6
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.7
sys/arch/arm/sunxi/sunxi_gpio.c: revision 1.8
sys/arch/arm/sunxi/sunxi_rsb.h: revision 1.1
sys/arch/arm/samsung/exynos_i2c.c: revision 1.12
sys/dev/fdt/fdtvar.h: revision 1.21
sys/arch/evbarm/sunxi/sunxi_start.S: revision 1.1
sys/arch/arm/samsung/exynos_i2c.c: revision 1.13
sys/dev/fdt/fdtvar.h: revision 1.22
sys/arch/evbarm/conf/SUNXI: revision 1.10
sys/dev/fdt/fdtvar.h: revision 1.23
sys/arch/evbarm/conf/SUNXI: revision 1.11
sys/dev/fdt/gpioleds.c: revision 1.1
sys/dev/fdt/fdtvar.h: revision 1.24
sys/arch/evbarm/conf/SUNXI: revision 1.12
sys/arch/evbarm/conf/SUNXI: revision 1.13
sys/arch/arm/cortex/gic.c: revision 1.30
sys/arch/evbarm/conf/SUNXI: revision 1.14
sys/arch/evbarm/conf/SUNXI: revision 1.15
sys/arch/evbarm/conf/SUNXI: revision 1.16
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.1
etc/Makefile: revision 1.430
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.2
etc/Makefile: revision 1.431
sys/arch/evbarm/conf/VEXPRESS_A15: revision 1.17
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.3
sys/arch/arm/sunxi/sunxi_emac.c: revision 1.4
sys/arch/arm/samsung/exynos5422_clock.c: revision 1.6
sys/arch/arm/samsung/exynos_platform.c: revision 1.1
sys/dev/ofw/ofw_subr.c: revision 1.29
sys/arch/arm/samsung/exynos_platform.c: revision 1.2
sys/arch/evbarm/conf/mk.vexpress: revision 1.3
sys/arch/arm/samsung/exynos_platform.c: revision 1.3
sys/arch/evbarm/conf/mk.vexpress: revision 1.4
sys/arch/arm/samsung/exynos_platform.c: revision 1.4
sys/arch/arm/arm/psci.h: revision 1.1
sys/arch/arm/samsung/exynos_platform.c: revision 1.5
sys/arch/arm/samsung/exynos_platform.c: revision 1.6
sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.10
external/bsd/mdocml/bin/mandoc/Makefile: revision 1.12
sys/dev/fdt/files.fdt: revision 1.17
sys/dev/fdt/files.fdt: revision 1.18
sys/dev/fdt/files.fdt: revision 1.19
sys/arch/arm/samsung/exynos_sscom.c: revision 1.8
sys/arch/arm/sunxi/sun8i_a83t_ccu.c: revision 1.1
sys/arch/arm/sunxi/sunxi_mmc.c: revision 1.1
sys/arch/arm/samsung/exynos_sscom.c: revision 1.9
sys/arch/arm/conf/files.arm: revision 1.133
sys/arch/arm/samsung/mct_var.h: revision 1.5
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.1
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.2
sys/arch/evbarm/conf/std.vexpress: revision 1.6
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.3
sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.1
sys/arch/arm/sunxi/sunxi_platform.c: revision 1.4
sys/arch/arm/sunxi/sun6i_a31_gpio.c: revision 1.2
sys/arch/arm/sunxi/files.sunxi: revision 1.1
sys/dev/ofw/ofw_subr.c: revision 1.30
sys/arch/arm/sunxi/files.sunxi: revision 1.2
sys/dev/ofw/openfirm.h: revision 1.35
sys/arch/arm/sunxi/files.sunxi: revision 1.3
sys/dev/ofw/openfirm.h: revision 1.36
sys/arch/arm/sunxi/files.sunxi: revision 1.4
sys/arch/arm/sunxi/files.sunxi: revision 1.5
sys/arch/evbarm/exynos/exynos_machdep.c: file removal
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.1
sys/arch/arm/samsung/sscom.c: revision 1.9
sys/arch/arm/sunxi/files.sunxi: revision 1.6
sys/dev/fdt/ohci_fdt.c: revision 1.1
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.1
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.2
sys/arch/arm/sunxi/files.sunxi: revision 1.7
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.2
sys/arch/arm/sunxi/sunxi_gpio.h: revision 1.3
sys/arch/arm/sunxi/files.sunxi: revision 1.8
sys/arch/arm/sunxi/sunxi_usbphy.c: revision 1.3
sys/arch/arm/sunxi/files.sunxi: revision 1.9
sys/arch/arm/samsung/exynos_sscom.c: revision 1.10
sys/arch/evbarm/conf/mk.tegra: revision 1.5
sys/arch/arm/samsung/exynos_dwcmmc.c: revision 1.4
sys/arch/evbarm/conf/mk.tegra: revision 1.6
sys/arch/evbarm/conf/EXYNOS: revision 1.15
sys/arch/evbarm/conf/EXYNOS: revision 1.16
sys/arch/evbarm/conf/EXYNOS: revision 1.17
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.1
sys/arch/evbarm/conf/EXYNOS: revision 1.19
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu.c: revision 1.5
sys/arch/arm/sunxi/sunxi_emac.h: revision 1.1
sys/arch/evbarm/conf/mk.sunxi: revision 1.1
sys/arch/evbarm/include/bootconfig.h: revision 1.7
sys/arch/evbarm/conf/TEGRA: revision 1.24
sys/arch/arm/arm/psci.c: revision 1.1
sys/dev/led.c: revision 1.1
sys/dev/led.c: revision 1.2
sys/arch/arm/arm/psci_arm.S: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_gate.c: revision 1.2
sys/dev/fdt/ehci_fdt.c: revision 1.1
sys/dev/fdt/ehci_fdt.c: revision 1.2
sys/arch/arm/sunxi/sun6i_a31_ccu.h: revision 1.1
sys/arch/evbarm/conf/EXYNOS: revision 1.21
sys/arch/arm/sunxi/files.sunxi: revision 1.10
sys/arch/arm/sunxi/files.sunxi: revision 1.11
sys/dev/fdt/fdtbus.c: revision 1.14
sys/arch/arm/sunxi/sunxi_mmc.h: revision 1.1
sys/arch/arm/samsung/exynos5422_dma.c: file removal
usr.bin/config/mkmakefile.c: revision 1.69
sys/conf/files: revision 1.1178
sys/arch/arm/sunxi/sunxi_platform.h: revision 1.1
sys/arch/evbarm/exynos/exynos_start.S: revision 1.4
sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.11
sys/arch/arm/samsung/exynos_pinctrl.c: revision 1.12
sys/arch/arm/sunxi/sunxi_rtc.c: revision 1.1
sys/arch/arm/sunxi/sun8i_h3_ccu.h: revision 1.1
sys/arch/arm/samsung/exynos5410_clock.c: revision 1.1
sys/arch/arm/samsung/exynos5410_clock.c: revision 1.2
sys/arch/evbarm/conf/SUNXI: revision 1.1
external/bsd/elftosb/usr.sbin/elftosb/Makefile: revision 1.5
sys/arch/evbarm/conf/SUNXI: revision 1.2
sys/arch/arm/fdt/psci_fdt.c: revision 1.1
sys/arch/evbarm/conf/SUNXI: revision 1.3
sys/arch/evbarm/conf/SUNXI: revision 1.4
sys/arch/evbarm/conf/files.exynos: revision 1.3
sys/arch/evbarm/conf/SUNXI: revision 1.5
sys/arch/evbarm/conf/SUNXI: revision 1.6
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.1
sys/dev/fdt/fixedfactorclock.c: revision 1.1
sys/dev/fdt/fdt_subr.c: revision 1.14
sys/arch/evbarm/conf/SUNXI: revision 1.7
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.2
sys/arch/arm/sunxi/sun8i_a83t_gpio.c: revision 1.1
sys/dev/fdt/fdt_subr.c: revision 1.15
sys/arch/evbarm/conf/SUNXI: revision 1.8
sys/arch/arm/sunxi/sunxi_ccu_nm.c: revision 1.3
sys/dev/ic/dwc_mmc_reg.h: revision 1.6
sys/dev/fdt/fdt_subr.c: revision 1.16
sys/arch/evbarm/conf/SUNXI: revision 1.9
usr.bin/config/mkmakefile.c: revision 1.70
sys/dev/fdt/fdt_phy.c: revision 1.1
sys/arch/evbarm/conf/ODROID-XU: file removal
sys/arch/arm/fdt/arm_fdt.c: revision 1.4
sys/arch/arm/samsung/exynos_reg.h: revision 1.14
sys/conf/files: revision 1.1180
sys/arch/arm/samsung/exynos_reg.h: revision 1.15
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.4
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.5
sys/arch/arm/sunxi/sunxi_ccu.h: revision 1.6
sys/dev/ic/dwc_mmc_var.h: revision 1.6
sys/arch/arm/samsung/exynos_combiner.c: revision 1.7
sys/arch/evbarm/exynos/platform.h: revision 1.2
sys/arch/arm/fdt/files.fdt: revision 1.12
sys/arch/evbarm/conf/std.exynos: revision 1.2
sys/arch/evbarm/conf/std.exynos: revision 1.3
sys/arch/arm/rockchip/rockchip_dwcmmc.c: revision 1.6
sys/arch/arm/sunxi/sunxi_com.c: revision 1.1
sys/dev/led.h: revision 1.1
sys/arch/evbarm/conf/std.exynos: revision 1.5
sys/arch/arm/sunxi/sunxi_com.c: revision 1.2
sys/arch/evbarm/conf/files.evbarm: revision 1.26
usr.bin/config/defs.h: revision 1.99
sys/arch/arm/fdt/arm_fdtvar.h: revision 1.6
sys/arch/arm/samsung/exynos_soc.c: revision 1.32
sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.1
sys/arch/arm/sunxi/sun6i_a31_ccu.c: revision 1.2
sys/arch/arm/samsung/mct.c: revision 1.11
sys/arch/evbarm/conf/ODROID-U: file removal
sys/arch/arm/samsung/mct.c: revision 1.12
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.1
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.2
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.3
sys/arch/arm/sunxi/sunxi_ccu_nkmp.c: revision 1.4
Get the EXYNOS kernel building again with recent FDT changes. Untested.
Use arm_fdt_cpu_hatch and add mmu entry for DTB
Fix exynos5 devmap, bootstrap, and implement early_putchar.
Calculate UART frequency based on bootloader config.
Fix KERNEL_BASE_PHYS (how did this ever work?)
Avoid divide-by-zero for unconfigured PLLs
Correctly initialize i2cbus attach args.
Add delay and enable mct timecounter.
Fix build w/o VERBOSE_INIT_ARM
Remove ODROID-U and ODROID-XU kernel configs as they no longer work.
- Replace CONSADDR with SSCOM2CONSOLE in example
- Remove gtmr (Exynos5422 uses mct)
- cinclude EXYNOS.local instead of TEGRA.local
Use fdtbus_intr_establish to hook in block interrupts instead of
intr_establish.
Simplify MCT; just enable it and then attach an ARMv7 generic timer.
Add support for building DTB files during kernel build, from christos.
build vexpress-v2p-ca15-tc1.dtb with the kernel
build tegra124-apalis-eval.dtb, tegra124-jetson-tk1.dtb, tegra124-nyan-big.dtb, tegra124-nyan-blaze.dtb, and tegra124-venice2.dtb with the kernel
Allow multiline makeoptions to work by quoting the newline..
Bump for quoting makeoptions with multiple lines.
un-c99
bump required config version for multiline makeoptions feature
Set DTS makeoption in kernel config
Assign DTB files to a variable so we can make -V DTB
put the dtb files with their kernels.
no need for debug printing.
Don't assume that CPU index = GIC CPU interface number. We can determine
the current CPU interface number by reading from the read-only
GICD_ITARGETSR0 through GICD_ITARGETSR7 registers.
This gets interrupts working on Exynos 5422, where the boot processor has
GIC CPU interface #4.
use -v to get the expanded variable.
Use -v to get the expanded variables.
Get baud rate from sclk_uartN instead of uartN. Print IRQ number at attach.
Fix PLL con0 register locations and add uart clocks
Disable exyortc for now, it doesn't work.
More or less a rewrite of dwc_mmc, based on awin_mmc, adding DMA support.
Update for new dwc_mmc driver
Fix dmesg
Add Exynos 5410 clock controller driver.
Fix a few typos in clock parent names for mmc clocks.
From jmcneill@
Update for new dwc_mmc driver
Implement platform reset for exynos5
Attach fdtbus to a /clocks node with no compatible string.
Add support for ARM Power State Coordination Interface (PSCI).
Support interrupt sharing.
Add initial support for Allwinner H3 SoC.
ARM Trusted Firmware reserves SGIs 8-15 for secure use. Even without ATF,
U-Boot on some platforms may use SGIs in this range for the PSCI
implementation.
Change ARMGIC_IPI_BASE to 0 from (16 - NIPI) and add a compile-time assert
to ensure that we don't end up with a conflict.
Add H3 MMC support
SD/MMC clock fixes
Add FDT PHY interface.
Add glue for generic ehci/ohci bindings.
Rename a variable, NFC.
Support parents in different clock domains.
Add USB stuff. Doesn't quite work yet.
Synopsys DesignWare APB UART needs "options COM_AWIN" for now.
Add i2c glue.
Add RTC driver.
PHY registers start at index 1. Now USB works.
Don't allow sharing edge and level triggered interrupts.
Add arm_fdt_memory_dump helper for dumping physical addresses from ddb
Print clocks with aprint_debug
Remove unused defines
Add fdtbus_get_string helper
Add of_search_compatible, which searches an array of compat_data structures
for a matching "compatible" entry matching the supplied OFW node. This
allows us to associate data with compatible strings.
Add driver for Allwinner Gigabit Ethernet (EMAC) as found in sun8i and
later family SoCs.
This is a port of my FreeBSD driver which has been confirmed to work on
Allwinner H3, A83T, and A64 SoCs.
Fix dmesg
Add basic support for Allwinner A31.
Add basic FDT GPIO support.
Fix the pinctrl api to match the spec. A pinctrl config can have more
than one xref, and an xref may have specifier data associated with it.
Enable sunxi pinctrl support
Adjust to new pinctrl API
Add P2WI/RSB driver, based on awin_p2wi.c.
Fix typo in a compat string.
Configure pin defaults at attach
No need to explicitly set pinctrl config 0 now
Fix some register definitions.
Disallow sharing between MPSAFE and non-MPSAFE handlers.
Add of_match_compat_data.
This routine searches an array of compat_data structures for a
matching "compatible" entry matching the supplied OFW node.
Add options __HAVE_CPU_UAREA_ALLOC_IDLELWP
Add support for reserved memory and MEMORY_DISK_DYNAMIC for FDT-based
kernels.
the extent code cannot use the full range of u_long,
so ignore the last page before 4GB too. ok jmcneill@
Copy install ramdisk to releasedir. Provide both a raw ffs and
Legacy U-Boot version of it.
Replace HUMMINGBIRD_A31 with SUNXI kernel on armv7.img and include .dtb
files for SUNXI and TEGRA kernels on the MSDOS partition.
Let the controller provide a default name for pins. This makes pins easier
to locate when we have multiple banks and a variable number of pins per
bank.
Attach gpio(4) to sunxigpio
Test for kernel build directory before reading DTB list
Add support for Allwinner A83T SoC.
Add A83T files
Fixup busdma sync and locking in the RX path. Disable batch RX/TX ints.
Fix AHB2 register definition and explicitly set AHB2 parent to PLL_PERIPH0/2 -- this gives us 50% more bus bandwidth for emac
Restore TX_INTERVAL_DEFAULT to 64
Drop the sunxi_emac_rx_batch feature. It was originally designed to
reduce the amount of mutex unlock/lock cycles during the RX path on
FreeBSD and if_input, but it is not required to drop the lock before
calling if_percpuq_enqueue on NetBSD.
Write back the data value instead of mask in sunxi_gpio_write
Add a helper for exposing LED controls via sysctl.
Add GPIO LED driver.
add gpioleds
Add misc. gates and resets driver, and explicitly enable PIO clocks
at attach.
Add fdtbus_get_string_index helper.
Add driver for fixed-factor clocks.
Add ffclock
Remove the requirement for ehci to attach after companion devices.
"go for it" - skrll@
Remove the hack to find companion devices and just assume 1 companion if
ETTF flag is not set.
Remove pass numbers for ehci/ohci now that the attach order no longer matters
Use unsigned char for ctype functions, suggested by christos
Add : to body of populate_sunxi to appease bash.
port-evbarm/52388: Fix number of args to a debug printf.
 1.257.2.4  30-Sep-2018  pgoyette Ssync with HEAD
 1.257.2.3  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.257.2.2  25-Jun-2018  pgoyette Sync with HEAD
 1.257.2.1  16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.259.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.259.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.259.2.1  10-Jun-2019  christos Sync with HEAD
 1.267.2.7  02-Aug-2023  martin Pull up following revision(s) (requested by skrll in ticket #1698):

sys/dev/usb/ehci.c: revision 1.317

PR 57518: usb keyboard causes host controller to miss microframe

As per the USB 2.0 specification section 11.18.4; paragraph 3.b
For interrupt IN/OUT full-/low-speed transactions, the host must schedule a
complete-split transaction in each of the two microframes following the
first microframe in which the full-/low-speed transaction is budgeted. An
additional complete-split must also be scheduled in the third following
microframe unless the full-/low-speed transaction was budgeted to start
in microframe Y6.
 1.267.2.6  06-Dec-2021  martin Pull up following revision(s) (requested by riastradh in ticket #1386):

sys/dev/usb/ehci.c: revision 1.287

ehci: Replace bogus polling during suspend by taking bus lock.

The system is not at high IPL or limited to a single CPU at this
point; it is running essentially normally, just with some devices
suspended. Other threads might be trying to touch EHCI registers,
which might have bad outcomes while we're suspending stuff. Enabling
polling only makes sense if there is a single thread and single CPU
running, such as when we enter ddb on crash.
 1.267.2.5  03-Sep-2021  martin Pull up following revision(s) (requested by mrg in ticket #1340):

sys/dev/usb/ehci.c: revision 1.286

add missing newline and fix conditional for askroot/single user
hand over delay message. PR#56366.
 1.267.2.4  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.267.2.3  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.267.2.2  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.267.2.1  10-Feb-2020  martin Pull up following revision(s) (requested by mrg in ticket #683):

sys/dev/usb/ehci.c: revision 1.269

don't call usb_syncmem() for zero-length packets.
 1.268.2.1  29-Feb-2020  ad Sync with head.
 1.282.2.3  03-Apr-2021  thorpej Sync with HEAD.
 1.282.2.2  03-Jan-2021  thorpej Sync w/ HEAD.
 1.282.2.1  14-Dec-2020  thorpej Sync w/ HEAD.
 1.315.2.5  01-Oct-2025  martin Pull up following revision(s) (requested by rin in ticket #1169):

sys/dev/usb/ehci.c: revision 1.333 (patch)

ehci: usb_syncmem against qtd **after** KASSERT for that qtd

Otherwise, we end up with stale data for DIAGNOSTIC kernel.

Fix device-probe failures discussed in PR kern/58730 for me.
(The main topic of the PR, NFS client lock-up, is not addressed.)
 1.315.2.4  17-Feb-2024  martin Pull up following revision(s) (requested by gutteridge in ticket #589):

sys/dev/usb/ehci.c: revision 1.322
sys/dev/usb/ehcireg.h: revision 1.39

avoid different struct type problem.
 1.315.2.3  06-Feb-2024  martin Pull up following revision(s) (requested by jmcneill in ticket #585):

sys/dev/usb/ehcireg.h: revision 1.38
sys/dev/usb/ehci.c: revision 1.321

Fix DMA sync flags in ehci_append_sqtd

Ensure proper alignment/padding of EHCI hardware descriptors.

These descriptor structs are embedded in structs that contain additional
context for software. With a non cache coherent device and non-padded
descriptors, the device may issue a read/modify/write past the end of
the descriptor, clobbering software state in the process. This was the
root cause of multiple crashes on evbppc with a non cache coherent EHCI.
 1.315.2.2  30-Oct-2023  martin Pull up following revision(s) (requested by riastradh in ticket #440):

sys/dev/usb/ehci.c: revision 1.318
sys/dev/usb/ehci.c: revision 1.319

ehci(4): Fix cv_timedwait loop in ehci_sync_hc.

Stop when
now - starttime >= delta,
i.e., when at least delta ticks have elapsed since the start, not
when
endtime - now > delta,
i.e., more than delta ticks _remain_ to sleep, which is never going
to happen (except on arithmetic overflow).

As is, what will happen in the case that should time out is that we
wake up after delta ticks, and find now = getticks() is exactly
endtime, so we retry cv_timedwait with timo=(endtime - now)=0 which
means sleep indefinitely with no timeout as if with cv_wait.

PR port-i386/57662

ehci(4): Fix bug causing missed wakeups since ehci.c 1.308.

For reasons beyond me now, I used cv_signal on the same cv that is
used to wait for the doorbell to be available _and_ to wait for the
host controller to acknowledge the doorbell. Which means when the
host controller acknowledges the doorbell, we might wake some thread
waiting for the doorbell to be available -- and leave the thread
waiting for the doorbell acknowledgment hanging indefinitely.

PR port-i386/57662
 1.315.2.1  02-Aug-2023  martin Pull up following revision(s) (requested by skrll in ticket #301):

sys/dev/usb/ehci.c: revision 1.317

PR 57518: usb keyboard causes host controller to miss microframe

As per the USB 2.0 specification section 11.18.4; paragraph 3.b
For interrupt IN/OUT full-/low-speed transactions, the host must schedule a
complete-split transaction in each of the two microframes following the
first microframe in which the full-/low-speed transaction is budgeted. An
additional complete-split must also be scheduled in the third following
microframe unless the full-/low-speed transaction was budgeted to start
in microframe Y6.
 1.325.2.1  02-Aug-2025  perseant Sync with HEAD
 1.332.2.1  01-Oct-2025  martin Pull up following revision(s) (requested by rin in ticket #44):

sys/dev/usb/ehci.c: revision 1.333

ehci: usb_syncmem against qtd **after** KASSERT for that qtd

Otherwise, we end up with stale data for DIAGNOSTIC kernel.

Fix device-probe failures discussed in PR kern/58730 for me.
(The main topic of the PR, NFS client lock-up, is not addressed.)

RSS XML Feed