History log of /netbsd-current/sys/dev/usb/ehci.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.325 05-Apr-2024 riastradh

usb *hci: Always set ux_status before usbd_xfer_schedule_timeout.

Add an assert to usbd_xfer_schedule_timeout to enforce this.

Since access to ux_status is serialized by the bus lock, and nothing
releases the bus lock in the interim, this doesn't make a functional
change. But it does reduce confusion by readers, who no longer have
to worry if some callers got the order wrong. It could also now
potentially be factored out in a subsequent commit.


# 1.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.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 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


Revision tags: netbsd-10-base
# 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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 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


Revision tags: netbsd-10-base
# 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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 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


Revision tags: netbsd-10-base
# 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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 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


Revision tags: netbsd-10-base
# 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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.320 04-Feb-2024 mrg

update my email address.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 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


Revision tags: netbsd-10-base
# 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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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


Revision tags: netbsd-10-base
# 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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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


Revision tags: netbsd-10-base
# 1.315 13-Dec-2022 jakllsch

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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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


Revision tags: netbsd-10-base
# 1.315 13-Dec-2022 jakllsch

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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.315 13-Dec-2022 jakllsch

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.


Revision tags: bouyer-sunxi-drm-base
# 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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.286 31-Aug-2021 mrg

add missing newline and fix conditional for askroot/single user
hand over delay message. PR#56366.


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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


Revision tags: thorpej-futex-base
# 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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.283 30-Nov-2020 msaitoh

s/ we we / we /


Revision tags: thorpej-futex-base
# 1.282 20-Sep-2020 gson

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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.282 20-Sep-2020 gson

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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.279 15-May-2020 skrll

Update ux_length in usbd_setup_isoc_xfer and use this to usb_syncmem
in the HCDs


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base phil-wifi-20200406
# 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.


Revision tags: is-mlppp-base ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.275 05-Mar-2020 skrll

Use howmany. NFC.


Revision tags: ad-namecache-base3
# 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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

branches: 1.268.2;
Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

branches: 1.267.2;
Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.269 04-Feb-2020 mrg

don't call usb_syncmem() for zero-length packets.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base
# 1.268 31-Dec-2019 skrll

Remove a stray '


Revision tags: netbsd-9-0-RC2 netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.268 31-Dec-2019 skrll

Remove a stray '


Revision tags: netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base
# 1.267 13-Jun-2019 maxv

Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.267 13-Jun-2019 maxv

Random style in ehci, also KM_SLEEP does not fail.


Revision tags: phil-wifi-20190609 isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

branches: 1.259.2;
Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.


Revision tags: isaki-audio2-base
# 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.


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930
# 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)


Revision tags: pgoyette-compat-0906
# 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!)


Revision tags: jdolecek-ncqfixes-base
# 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.


Revision tags: pgoyette-compat-0728 phil-wifi-base pgoyette-compat-0625
# 1.259 06-Jun-2018 maya

Remove duplicate ;


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415
# 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.


Revision tags: pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base tls-maxphys-base-20171202
# 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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-2-RELEASE netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.


Revision tags: tls-maxphys-base-20171202
# 1.257 17-Nov-2017 skrll

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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-1-RELEASE netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.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.


Revision tags: nick-nhusb-base-20170825 perseant-stdc-iso10646-base
# 1.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

branches: 1.254.8;
Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.255 08-Jul-2017 jmcneill

Remove the requirement for ehci to attach after companion devices.

"go for it" - skrll@


Revision tags: netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 nick-nhusb-base-20170204 bouyer-socketcan-base pgoyette-localcount-20170107 nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-1-RELEASE netbsd-7-1-RC2 netbsd-7-nhusb-base-20170116 netbsd-7-1-RC1 netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.254 03-Oct-2016 dholland

Improve diagnostic print seen in PR 51524.


Revision tags: localcount-20160914
# 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


Revision tags: pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529
# 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


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.248 13-Mar-2016 skrll

KNF


Revision tags: nick-nhusb-base-20151226
# 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.


Revision tags: nick-nhusb-base-20150921
# 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


Revision tags: nick-nhusb-base-20150606
# 1.239 11-May-2015 skrll

Remove '\n' from panic message.


Revision tags: nick-nhusb-base-20150406
# 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


Revision tags: nick-nhusb-base
# 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@


Revision tags: netbsd-7-0-2-RELEASE netbsd-7-nhusb-base netbsd-7-0-1-RELEASE netbsd-7-0-RELEASE netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 netbsd-7-base tls-earlyentropy-base tls-maxphys-base
# 1.228 05-Aug-2014 skrll

branches: 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.


Revision tags: yamt-pagecache-base9 riastradh-xf86-video-intel-2-7-1-pre-2-21-15 riastradh-drm2-base3 rmind-smpnet-nbase rmind-smpnet-base
# 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


Revision tags: riastradh-drm2-base2 riastradh-drm2-base1 riastradh-drm2-base
# 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


Revision tags: agc-symver-base
# 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.


Revision tags: yamt-pagecache-base8
# 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.


Revision tags: yamt-pagecache-base7
# 1.193 04-Nov-2012 matt

Fix ETTF PSPD definitions and enable the ETTF PORTSC detection.
Fix EHCI portion of PR/47156.


Revision tags: yamt-pagecache-base6
# 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.


Revision tags: jmcneill-usbmp-base10 yamt-pagecache-base5 jmcneill-usbmp-base9 yamt-pagecache-base4 jmcneill-usbmp-base8
# 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


Revision tags: jmcneill-usbmp-base7
# 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().


Revision tags: jmcneill-usbmp-base6
# 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.


Revision tags: netbsd-6-1-1-RELEASE netbsd-6-0-2-RELEASE netbsd-6-1-RELEASE netbsd-6-1-RC4 netbsd-6-1-RC3 netbsd-6-1-RC2 netbsd-6-1-RC1 netbsd-6-0-1-RELEASE matt-nb6-plus-nbase netbsd-6-0-RELEASE netbsd-6-0-RC2 matt-nb6-plus-base netbsd-6-0-RC1 jmcneill-usbmp-base5 jmcneill-usbmp-base4 jmcneill-usbmp-base3 jmcneill-usbmp-base2 netbsd-6-base
# 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.


Revision tags: jmcneill-usbmp-base jmcneill-audiomp3-base yamt-pagecache-base3 yamt-pagecache-base2 yamt-pagecache-base
# 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


Revision tags: rmind-uvmplock-nbase rmind-uvmplock-base
# 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?


Revision tags: cherry-xenmp-base
# 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)


Revision tags: bouyer-quota2-nbase bouyer-quota2-base
# 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.


Revision tags: jruoho-x86intr-base matt-mips64-premerge-20101231 uebayasi-xip-base4
# 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


Revision tags: uebayasi-xip-base3
# 1.170 16-Oct-2010 kiyohara

Add vendor dependent functions.
sc_vendor_init()/sc_vendor_port_status().


Revision tags: yamt-nfs-mp-base11 uebayasi-xip-base2 yamt-nfs-mp-base10
# 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.


Revision tags: uebayasi-xip-base1 yamt-nfs-mp-base9
# 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.


Revision tags: uebayasi-xip-base
# 1.165 08-Jan-2010 dyoung

branches: 1.165.2;
Expand PMF_FN_* macros.


Revision tags: matt-premerge-20091211
# 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.


Revision tags: jym-xensuspend-nbase
# 1.161 01-Nov-2009 uebayasi

Fix some whitespaces.


# 1.160 01-Nov-2009 uebayasi

Update referencial URLs.


Revision tags: yamt-nfs-mp-base8
# 1.159 04-Sep-2009 dyoung

Expand <dev/usb/usb_port.h> definitions, and lightly unifdef(1).


Revision tags: yamt-nfs-mp-base7
# 1.158 27-Jul-2009 sketch

Wrap ehcidebug in EHCI_DEBUG, not USB_DEBUG.


Revision tags: jymxensuspend-base yamt-nfs-mp-base6 yamt-nfs-mp-base5 yamt-nfs-mp-base4 yamt-nfs-mp-base3 nick-hppapmap-base4 nick-hppapmap-base3 jym-xensuspend-base nick-hppapmap-base
# 1.157 18-Mar-2009 cegger

Ansify function definitions w/o arguments. Generated with sed.


Revision tags: nick-hppapmap-base2 mjf-devfs2-base
# 1.156 16-Dec-2008 christos

branches: 1.156.2;
replace bitmask_snprintf(9) with snprintb(3)


Revision tags: haad-dm-base2 haad-nbase2 ad-audiomp2-base haad-dm-base
# 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


Revision tags: netbsd-5-base matt-mips64-base2 haad-dm-base1
# 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


Revision tags: wrstuden-revivesa-base-4
# 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.


Revision tags: wrstuden-revivesa-base-3
# 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


Revision tags: wrstuden-revivesa-base-2
# 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.


Revision tags: simonb-wapbl-nbase simonb-wapbl-base
# 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.


Revision tags: wrstuden-revivesa-base-1 yamt-pf42-base4 wrstuden-revivesa-base
# 1.137 16-Jun-2008 drochner

fix selective port resume signaling (not used in normal operation,
just for correctness)


Revision tags: yamt-pf42-base3
# 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


Revision tags: hpcarm-cleanup-nbase yamt-pf42-base2 yamt-nfs-mp-base2
# 1.135 28-Apr-2008 martin

branches: 1.135.2;
Remove clause 3 and 4 from TNF licenses


Revision tags: yamt-pf42-baseX yamt-nfs-mp-base yamt-pf42-base
# 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


Revision tags: ad-socklock-base1 yamt-lazymbuf-base15 yamt-lazymbuf-base14 keiichi-mipv6-nbase keiichi-mipv6-base matt-armv6-nbase
# 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.


Revision tags: hpcarm-cleanup-base
# 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}.


Revision tags: nick-net80211-sync-base mjf-devfs-base
# 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.


Revision tags: bouyer-xeni386-merge1 vmlocking2-base3 bouyer-xeni386-nbase yamt-kmem-base3 cube-autoconf-base yamt-kmem-base2 bouyer-xeni386-base matt-armv6-base
# 1.127 09-Dec-2007 jmcneill

Merge jmcneill-pm branch.


Revision tags: yamt-kmem-base vmlocking2-base2 reinoud-bufcleanup-nbase jmcneill-pm-base reinoud-bufcleanup-base
# 1.126 05-Dec-2007 ad

branches: 1.126.2;
lockmgr -> mutex


Revision tags: vmlocking2-base1 jmcneill-base bouyer-xenamd64-base2 vmlocking-nbase bouyer-xenamd64-base
# 1.125 19-Oct-2007 ad

branches: 1.125.2; 1.125.4;
machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h


Revision tags: nick-csl-alignment-base5 yamt-x86pmap-base4 yamt-x86pmap-base3 yamt-x86pmap-base2 yamt-x86pmap-base vmlocking-base
# 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


Revision tags: matt-mips64-base nick-csl-alignment-base itohy-usb1-base yamt-idlelwp-base8 thorpej-atomic-base mjf-ufs-trans-base ad-audiomp-base
# 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.


Revision tags: post-newlock2-merge
# 1.121 09-Feb-2007 ad

Merge newlock2 to head.


Revision tags: newlock2-nbase newlock2-base
# 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.


Revision tags: yamt-splraiseipl-base5 yamt-splraiseipl-base4 yamt-splraiseipl-base3 netbsd-4-base
# 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.


Revision tags: yamt-splraiseipl-base2
# 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@


Revision tags: yamt-splraiseipl-base yamt-pdpolicy-base9 yamt-pdpolicy-base8 rpaulo-netinet-merge-pcb-base
# 1.111 30-Aug-2006 christos

branches: 1.111.2; 1.111.4;
fix incomplete initializers


Revision tags: abandoned-netbsd-4-base yamt-pdpolicy-base7 yamt-pdpolicy-base6 chap-midi-nbase gdamore-uart-base chap-midi-base simonb-timecounters-base
# 1.110 28-May-2006 blymn

Clean up bogus whitespace


Revision tags: yamt-pdpolicy-base5 elad-kernelauth-base
# 1.109 14-Apr-2006 christos

branches: 1.109.2;
Coverity CID 1131: Avoid NULL pointer dereference.


Revision tags: yamt-pdpolicy-base4 yamt-pdpolicy-base3 peter-altq-base yamt-pdpolicy-base2 yamt-pdpolicy-base yamt-uio_vmspace-base5
# 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


Revision tags: yamt-readahead-base3 yamt-readahead-base2 ktrace-lwp-base
# 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.


Revision tags: yamt-readahead-pervnode yamt-readahead-perfile yamt-readahead-base yamt-vop-base3 yamt-vop-base2 thorpej-vnode-attr-base yamt-vop-base
# 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.


Revision tags: kent-audio2-base
# 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.


Revision tags: yamt-km-base4 yamt-km-base3 netbsd-3-base
# 1.91 27-Feb-2005 perry

branches: 1.91.2;
nuke trailing whitespace


Revision tags: yamt-km-base2 yamt-km-base kent-audio1-beforemerge
# 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.


Revision tags: kent-audio1-base
# 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.


Revision tags: netbsd-2-0-base
# 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_*().


Revision tags: nathanw_sa_before_merge fvdl_fs64_base gmcgarry_ctxsw_base gmcgarry_ucred_base nathanw_sa_base
# 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.


Revision tags: kqueue-aftermerge kqueue-beforemerge kqueue-base
# 1.37 27-Sep-2002 provos

remove trailing \n in panic(). approved perry.


Revision tags: gehenna-devsw-base
# 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.


Revision tags: netbsd-1-6-PATCH002-RELEASE netbsd-1-6-PATCH002 netbsd-1-6-PATCH002-RC4 netbsd-1-6-PATCH002-RC3 netbsd-1-6-PATCH002-RC2 netbsd-1-6-PATCH002-RC1 netbsd-1-6-PATCH001 netbsd-1-6-PATCH001-RELEASE netbsd-1-6-PATCH001-RC3 netbsd-1-6-PATCH001-RC2 netbsd-1-6-PATCH001-RC1 netbsd-1-6-RELEASE netbsd-1-6-RC3 netbsd-1-6-RC2 netbsd-1-6-RC1 netbsd-1-6-base
# 1.30 19-May-2002 augustss

branches: 1.30.2;
Update dma memory access API a little.


Revision tags: eeh-devprop-base newlock-base ifpoll-base
# 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


Revision tags: thorpej-mips-cache-base
# 1.3 10-Nov-2001 augustss

Add some register defines.
Print companion controllers.


Revision tags: thorpej-devvp-base3 thorpej-devvp-base2 post-chs-ubcperf pre-chs-ubcperf thorpej-devvp-base thorpej_scsipi_beforemerge thorpej_scsipi_nbase thorpej_scsipi_base
# 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.