History log of /haiku/src/add-ons/kernel/busses/usb/xhci.cpp
Revision Date Author Comments
# 629f071b 27-Feb-2024 X512 <danger_mail@list.ru>

pci: extend MSI interrupt vector number to 32 bits

Also increase MSI message data size to 32 bits according to PCIe spec.

Remove 0xff check for MSI interrupts because it is potentially valid
interrupt vector number. Reject 0xff only for legacy pin interrupts.

- MSI-X supports up to 2048 interrupts per device that do not fit to
`uint8`.

- Non-x86 systems may use separate interrupt vector ranges for
hard-wired interrupts and MSI interrupts so `uint8` is not enough to
represent all of them.

Change-Id: Iaf9ffb197ec23db0f97ffe3ea756d28d7bfc8705
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7433
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# 62ec2949 31-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Don't double-report completion status for isochronous transfers.


# f4e363ee 31-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Report ring overrun/underrun (isochronous errors) back to drivers.

Since transfer status is reported via the packet descriptors, we
can report the endpoint status through the callback status.

Reduces syslog spam when using the USB audio driver.


# be3ce6d7 31-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

USB: Make "buffer error" reporting consistent.

This error means that the controller failed to read or write data
to/from system memory fast enough. As a result, we should report it
as READ_ERROR/WRITE_ERROR, rather than something that sounds like
an error with the device itself.

Then, make BABBLE reporting consistent: this is a data overrun/underrun
of the device itself, not the buffers passed to the controller.
This then leaves B_DEV_FIFO_OVERRUN/UNDERRUN unused, and thus usable
for reporting ring overrun/underrun on isochronous transfers.

The API documentation already described DATA_OVERRUN/UNDERRUN basically
like they were babble errors, while FIFO_OVERRUN/UNDERRUN are
currently described as "internal errors" at present. No driver actually
checked for these.


# 22f0158a 31-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Move error status conversion to its own function and reuse it.

Also add COMP_MISSED_SERVICE -> B_DEV_TOO_LATE while at it.


# 8c458fc4 29-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

USB: Initialize packet descriptors inside the stack.

Allows deletion of generic code from bus drivers.


# 1f6757e3 29-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Overhaul isochronous transfer handling.

* Each packet needs to be its own TD.

* All transfers are scheduled in frames, not microframes.

Combined with a few fixes to the USB audio driver, this seems
to get things working much better than before.


# 94d33dcb 22-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rework _LinkDescriptorForPipe to avoid double-links.

The previous logic would link from the end of the ring to the start,
and the TRB there would always itself be a link TRB. Now, we avoid this
by linking back to the start from within the TD segments, and putting
the "Event Data" TRB there.

May help with some problems.

Change-Id: I92c4e135ee28c8c89646594a99fb40ee0d6c4484


# aeb3a97a 17-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Properly handle "Length invalid" and erroring TRBs on the endpoint ring.

Should improve #18432 and other tickets.

Change-Id: Iaafe2d9d61bc0514e4dd6283b9e75496d5e2d44a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7341
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# f8bd82e1 05-Jun-2023 X512 <danger_mail@list.ru>

xhci: report link status for USB 3 ports

The values come from XHCI table 5-27.

PS_PLS_MASK is the same as PORT_STATUS_SS_LINK_STATE.

Change-Id: Ie54abcda0c33738fe7dc5caa4e4f3abae3b40adc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6488
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 55a46882 30-May-2023 Augustin Cavalier <waddlesplash@gmail.com>

USB: Support physical-vector bulk requests.

Introduce a new utility method, "generic_memcpy", which takes
generic_addr_t plus indications of whether these specify virtual or
physical addresses (and potentially user addresess) and calls the
appropriate memcpy variant depending.

All bus drivers adjusted to support this at once. We don't actually
take advantage of the physical addresses in any way (yet), as USB
controllers have some pretty specific requirements that would have
to be carefully validated to use these directly.

All bus drivers tested and confirmed to still be working.

Change-Id: I66326667e148091147bb2b3d0843a26fb7e5bda6
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6479
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 99626c29 29-May-2023 Augustin Cavalier <waddlesplash@gmail.com>

USB: Use generic_io_vec in Transfer.

Prepares the way for actual physical-address request support,
which is not yet wired up.

Change-Id: I1b2d04a31e334a79b8361280fa0f3a5fbdb43d2b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6478
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 5c99f966 29-May-2023 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Disable MSI-X for now.

Breaks USB on some hardware. This might be a bug in Haiku's
MSI-X implementation.


# 1886d569 25-May-2023 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Handle an unlikely corner case in CancelQueuedTransfers.

See inline comment with reference to the XHCI specification.


# 769b4ee4 24-May-2023 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Implement support for MSI-X.

Works in QEMU, at least.


# 3b91d73b 16-Dec-2022 X512 <danger_mail@list.ru>

bus & drivers: drop PCI_x86

Change-Id: I494deaf24a4793a5e0fe9fa46ecdce32f65e616a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6226
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>


# 215b685f 11-Dec-2022 X512 <danger_mail@list.ru>

kernel: Drop non-standard GNU inline assignment syntax

* We needed this previously due to our gcc2 compiled kernel.
* Now that our kernel is always latest gcc, we can move to the
c++20 syntax for inline assignment.
* Improves compatibility with clang, less GNU-specific stuff

Change-Id: Ib7272a0a52554a31e9a0e788fd3f031db9049795
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5898
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>


# d2875e7b 16-Nov-2022 Jérôme Duval <jerome.duval@gmail.com>

usb: fix references on the module B_PCI_X86_MODULE_NAME

the dependency is optional, only the device modules depend on it.
should fix #18075

Change-Id: Ifddb9814ff5ff59ee7d80d06b14ba9fded04cd56
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5822
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# e6ce95c5 10-Oct-2022 Jérôme Duval <jerome.duval@gmail.com>

usb: register device nodes for hubs and devices

the device identifier is the USBID. no actual interface to be used by drivers.

Change-Id: I9fd1fdab0d02f1b82380c619b39bc3a12a9e2333
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5736
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>
Reviewed-by: X512 <danger_mail@list.ru>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 6652606f 05-Oct-2022 Jérôme Duval <jerome.duval@gmail.com>

usb: remove debug leftover

Change-Id: Idba6eaecb2c5b5773cd61794ac62fac1f7e3c1f9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5715
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 3d0c08ef 28-Sep-2022 Jérôme Duval <jerome.duval@gmail.com>

xhci: switch to the new driver API

keep the stack loaded when no bus is found

Change-Id: Ic2cf640ead7d94152651cea86a7977caa0920163
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5708
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 6fd4a3ee 29-Jun-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Set the DIR_IN bit on Status Stages even if there is no data.

The referenced section of the specification gives no indication that
the bit should not be set if there was no data; indeed it indicates
it should always be set.

This brings our behavior here in line with other OSes seem to do.

Change-Id: I86b2eb2a6a5fa3af84fd0941e0a3ec601c7037bf
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5421
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 6c675bab 20-May-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Defer writing the cycle bits for the "wrapping" link TRB.

There is already a comment above this that some controllers choke if the
target of a link TRB is invalid, and thus to not write the cycle bit
of the link TRB until said target is valid, but we did not follow that
when writing the link TRB to go back to the beginning of the ring.

Also put in a memory_write_barrier before writing the cycle bits,
just to be sure.

Tested in QEMU. May help with errors seen in #17749.


# 7c97a784 24-Feb-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Handle fragmented transfers failing to submit the next fragment.

Previously they would just get "lost" and never signal completion.
(Considering how rare fragmented transfers are, this may not fix
any real problems.)


# 6711786c 24-Feb-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix a TRACE statement.

Disabled by default anyway.


# 1fc7d773 07-Feb-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Downgrade tracing of CancelQueuedTransfers.

Now we only do it if TRACE_USB is enabled, or force-cancellation is specified.


# 312ea069 07-Feb-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Do not print "transfer error" for COMP_STOPPED.

STOPPED errors are generated by StopEndpoint commands, which we issue,
so presumably we expect that we will get some STOPPED errors when doing
so, thus printing these is not really necessary.


# a8dc67c7 07-Jan-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Print the actual error for some more things in AllocateDevice.

May help with diagnosing #17464 and others.


# d66430ec 07-Jan-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Add missing set-address delay.

The USB < 3.0 init code has this, and the XHCI spec indicates that
software is responsible for dealing with this still, indeed.

Noticed by rudolfc when testing some USB audio devices in #1045.


# a5404eb5 07-Jan-2022 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Use B_PRI macros in one TRACE.

Pointed out by rudolfc on #1045.


# 6ae7f1f1 07-Dec-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Consolidate xhci_device cleanup routine and use it in AllocateDevice.

This also fixes a leak of slots when initializing devices failed.
Fixes #16323, although there is some other underlying problem
which led to that error in the first place.


# 337b483b 28-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Use MutexLocker in _LinkDescriptorForPipe.

No functional change.


# ae61e1b7 27-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

USB bus drivers: Return error when combining other transfers with a fragmented one.

The drivers do not support this properly at present, they would
run the other transfers interspersed with fragments from the fragemented one,
which is obviously the wrong thing to do.

No USB device drivers seem to do this at present (it would cause data
corruption if they had.)

Fixes #17275.


# 3e0eea85 19-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Add support for fragmented transfers.

I was not actually aware that our USB stack already supported
breaking (bulk) transfers up into smaller units as necessary;
these APIs are not very well documented.

This makes #15569 occur far less often, though it is still
more than possible to trigger.


# b3683d8a 17-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Get rid of the PortSlots array and use ControllerCookie in FreeDevice.

This array was introduced by korli in hrev44089~1 (2012). It "mapped"
ports to slots using a device's HubPort, and then used this value in
FreeDevice() to locate the xhci_device struct in question.

Well, when there are non-root hubs in use, the HubPort values can
of course collide, leading us to tear down the wrong device in many
circumstances. This appears to have been the true cause of #16794,
and probably also #16878 and #17266, and maybe even some others.


# 4d21f567 15-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix up 3a71862e998410fd3b2b823b26281be81dfa5b70.

Now the logic is actually identical.


# 1da090bc 15-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Add assert that the context is really page-aligned if needed.

_OffsetContextAddr assumes it will be in order to do some rather
annoying pointer arithmetic, but that was never actually asserted.


# 2296578c 15-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Put speeds in order.

No functional change.


# 3a71862e 15-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rework port route computation code.

The new code should be functionally identical to the old,
but it uses fewer variables and should be significantly easier
to understand than the old.


# f20f5569 15-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: The root hub address is always 1.

AllocateAddress() is the pre-USB3 way of doing things;
as we never use it anywhere else and it is specific to
each BusManager, we always just got 1, which is what
the root hub will always be anyway.

Additionally, clarify the logic in _InsertEndpointForPipe
that is special-casing the root hub.

No functional change intended.


# 17f42bc1 09-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Check earlier on that the endpoint is actually valid.

This may catch the "division by zero" KDLs earlier.
Related to #14943, #16794, and #16878.


# cadaf758 04-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Resolve TODO about referencing the specification in isochronous handling.


# 625b5fc8 03-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Use a more approriate error code.

Stalls cause "HALTED" conditions on endpoints, so use B_DEV_STALLED.
Also clarify the comment referencing the specification, and add a
missing linebreak to the error message.


# 2331cde8 01-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix RemoveEndpointForPipe.

It seems this has been broken since I originally wrote it in 2019,
but it only gets called in two scenarios: on device unplug (where
it does not really matter), and on interface changes (where it does.)
Apparently very few people tried to use devices that depend on interface
changes, because those would have been totally broken by this.

There were actually two bugs here:

1. ConfigureEndpoint should not be called with the Deconfigure bit set.
(See inline comment.)

2. The first bit must be set in the context add flags.

Fixes #14971 at least, and possibly others as well.


# 1029af17 01-Sep-2021 Augustin Cavalier <waddlesplash@gmail.com>

Add missing includes following previous commit.

All these files were making use of headers included indirectly
through AutoLock.h that are now no longer following the previous commit.


# 37db8e9a 24-May-2021 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Enhance endpoint state handling

* Expands on previous change to no enter a stopped
state on an endpoint teardown.
* Doorbells could re-awaken the port in a stopped state

Change-Id: Ib5d9c89c4b721ea36ca22aaaf3ff92760a3ec2ff
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3996
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# 53d03234 20-May-2021 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Check endpoint state before stop

* As per the spec, the only exit from an endpoint in a halt
state is to issue a restart command. (restart puts the endpoint
into a stop state.. it's named poorly)

Change-Id: I4a1a556374ad7f564a562d995d1a2e29230a50c3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3959
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# f9b26e4c 08-Jan-2021 Jérôme Duval <jerome.duval@gmail.com>

xhci: SubmitNormalRequest: divide exception on zero trbSize

workaround for #16586

Change-Id: Id9d538f46b62585f4a12c3796781ae1207ed2454
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3611
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 913f009e 19-Jul-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Add a few comments and remove the documentation file.

The documentation file (which PulkoMandy only merged today) was created
over a year ago from a short conversation I had with him, and by now
a lot of its information is already outdated or has been merged into
comments in the driver already (specifically, the notes at the end about
error messages no longer apply as there are different ones, and the
bugs causing those errors have since been fixed.)

A few of the statements in it were not noted in the driver, though,
so I have added those as comments.


# 733e150b 11-Jul-2020 Michael Lotz <mmlr@mlotz.ch>

drivers: Fix 64 bit BAR checks and remove redundant masking.

Fix address type mask to use the right bits via PCI_address_type. The
previous 0xc value applies to the upper of the two address type and
the prefetchable bit instead of the two adddress type bits. This would
cause prefetchable 64 bit BARs to be misidentified as not being 64 bit.

Remove address masking as this is already done on the field in pci_info.

Use uint64 instead of phys_addr_t explicitly as on pure 32 bit platforms
this would otherwise result in a shift greater than type size.

Note that the sizes should theoretically be adjusted as well, but in all
of these cases a size needing the upper 32 bits doesn't make much sense.

Change-Id: Idd0d6e9a6cc18656b43cafcac720b132fc1f2ad3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3024
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 51d0d6e2 01-Mar-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Remove logically dead code.

This is inside a "endpointId > 0" block, and endpointNum=id+1,
so we will never call EvaluateContext here. (Endpoint "1" is
configured by AllocateDevice.)

Spotted by Coverity.


# 0d3250fd 18-Feb-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Round TD Size up instead of down.

This is what the specification dictates.


# cce89fa8 17-Feb-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Correct computation of TD Size field.

This was broken during the refactor in hrev53672. May help with #15657.


# b1970a84 17-Feb-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Do not try to use hardware with unknown interface versions.

Should fix the crash in #15717.


# 357adccf 17-Feb-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rearrange RemoveEndpointForPipe to fix crashes and deadlocks.

* As we were clearing out the endpoint structures before detaching
the xhci_endpoint from the Pipe, it was possible for SubmitRequest
to be called while we were being destroyed and then use the half-
torn-down endpoint, leading to crashes. Instead, we now call
SetControllerCookie first, so that SubmitRequest will thus
fail.

* Lock the endpoint after calling StopEndpoint, for the same
reasons that this is now the order of operations in CancelQueuedTransfers.

Probably fixes #15710, and maybe other issues.


# 41e5cf01 17-Feb-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Remove unnecessary xhci_device::state field.

It was only actually used to determine if a device was disabled
or not, which can be determined by checking the "slot" field
is "0" instead, as 0 is an invalid slot number.

No functional change (intended.)


# 2591d679 08-Feb-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix endpoint deadlock in CancelQueuedTransfers.

If a transfer completed before the StopEndpoint did,
HandleTransferComplete would try to lock the endpoint,
resulting in a deadlock, and so StopEndpoint would
always time out in this case.

May help with #15161, #15141, #15215, #15416, #15657.


# b8852a24 08-Feb-2020 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Do not set "Interrupt Short Packet" on transfers.

Before the refactor to use Event Data TRBs, this was necessary
to detect short packet conditions. Now that we use Event Data
TRBs, the hardware will send us an Event Data event even on
Short Packet conditions, so this is redundant.

Fixes log spam of "TRB ... not found in the endpoint", as
this was causing duplicate event postings. Also potentially
fixes instability seen when those messages were present.


# 726445b7 31-Dec-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Clean up TRACE() statements.


# 0981cb86 31-Dec-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rework TRB size handling.

There is a section of the spec that dictates how TRBs need to be
sized within a TD, and we were not following that. This should
bring us into compliance.

See inline comments for more details.


# 84fc8327 31-Dec-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Update all references from the specification 1.1 to 1.2.

Only comments changed, no functional.


# 21a5c628 23-Dec-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Add buffer count to "unable to allocate" trace, fix freeing.

FreeDescriptor needs to know buffer_size and buffer_count,
so we have to initialize these for the fail-exit case to work.


# 19e017cb 13-Sep-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Clarify a comment.

No functional change.


# c8e11499 10-Aug-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Force an event ring poll if a first timeout occurs on commands.

FreeBSD does something similar here. May help with some of the
stranger event ring lockups.


# 8bfe3d25 10-Aug-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rename ERST_EHB to ERDP_BUSY for clarity's sake.

No functional change intended.


# 538a30f8 27-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix use-after-free in FreeDevice.

Spotted by PVS-Studio.


# c5ec5c0c 21-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Implement isochronous transfers support (!!).

Only out-bound isochronous transfers are tested right now, but in
theory inbound ones "should" work just fine, too. The frame calculation
has a bunch of TODOs around it, because I'm probably not doing it
entirely correctly...

But hey, I made this commit while listening to some glitchy (audio
only in left channel, strange pops occurring intermittently, but
otherwise it sounds 100% correct) music over my USB audio device!
(I'm willing to blame the above problems on our rather buggy
usb_audio driver.)


# a3dca298 21-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Make CancelQueuedTransfers logic much more robust.

* If we fail to stop the endpoint: don't leave things in a valid
but broken state (i.e. the "used" field will get 'leaked', which may
prevent transfers from occurring in the future.)
* Free transfers when cleaning up the endpoint, to avoid memory leaks.
* A few other miscellaneous cleanups.

My work-in-progress isochronous support seems to trigger instances
of the StopEndpoint command either failing or taking longer than
our timeouts allow, so maybe this will improve things enough for things
to work just a bit more.


# 736adc5a 20-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Tweak formatting of FinishTransfers logic.

No functional change intended.


# 2f044f2a 19-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Check return status of PrepareKernelAccess.

Potentially fixes #15172.


# 553ff675 14-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Print errors when transfers have non-success completion codes.


# 9cd2907d 14-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Trace an error when we receive command events for unknown commands.

This revealed that StopEndpoint commands on QEMU were returning ...
after the semaphore timeout was already hit. Now to figure out
why that is the case...


# 60f15f5a 14-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Turn failure to stop the endpoint into a TRACE_ERROR.


# c8375b00 14-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Tweak priorities a bit more.

Put the EventThread as URGENT_PRIORITY and the downstream FinishThread
as URGENT - 1. Hopefully this will serve as a better hint to the
scheduler as to what we want to occur here.


# 4a6a2fbf 13-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Increase priorities of the event and finish threads.

The "event" thread is what is woken up after interrupts, and
the "finish" thread handles the results of the "event" thread,
so prioritize them accordingly. Probably increases responsiveness
of USB input and disk devices visibly on heavily loaded systems.


# f1e99f16 13-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Use PRI to appease GCC2.


# 1bccd6b2 13-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Always trace non-standard port speeds.


# 6e2bbbb1 12-Jul-2019 Augustin Cavalier <waddlesplash@gmail.com>

USB: Rename USB_SPEED_SUPER to USB_SPEED_SUPERSPEED.

For consistency's sake with the others.


# 8b19fb0f 03-Jul-2019 waddlesplash <waddlesplash@gmail.com>

Partially revert "XHCI: Set the TRB_3_ENT_BIT on the final Link TRB, also."

This reverts commit 63895cb5f2984b433d7f188c52e3f21e6723f610.

This does go against the specification, and on a very small set of
XHCI hardware, seems to break booting (#15137). So, let's revert it;
the buggy hardware it potentially helped will just have to deal with
it.


# 63895cb5 29-Jun-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Set the TRB_3_ENT_BIT on the final Link TRB, also.

This should not be necessary due to a note in the specification,
but it seems some controllers may not obey that; see inline comment.

Possibly fixes the "mouse slowness" of #15115 that began following
the Event Data changes.


# f861a859 17-Jun-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Set the ENT bit on the Status stage TRB for Control transfers.

Otherwise, it may deschedule this pipe without evaluating the
Event Data TRB and generating the interrupt. Should fix the
"slowness" issue of #15115.


# 581a586f 16-Jun-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Change ADDR print to PHYSADDR to appease GCC.


# 6a2133b1 16-Jun-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Overhaul endpoint ring logic.

The changes in this commit are large but also subtle, so
an explanation of how they came to be seems to make sense:

Earlier today I tried booting Haiku on QEMU under USB3 ... and
discovered that it didn't work, with the "Operation timed out"
message from in usb_disk upon failing a data transfer. Indeed,
turning on tracing showed no event was being posted for the
transfer. So, I downloaded QEMU's source code, turned on XHCI
debugging, and began tracing what was going on.

Eventually I determined by adding more and more printfs into QEMU's
XHCI implementation that what was occuring was that it was evaluating
a Link TRB, hitting an empty TRB, and then deciding that the TD (aka.,
the "run" of TRBs) was not ready to be consumed, and bailing.

In fact, that very condition (a link TRB leading to an empty TRB)
is precisely what _LinkDescriptorForPipe did before this commit.
We allocate only a small (8 before this commit, 16 + 1 after this
commit) TRB ring for each *endpoint*, and larger ones on a per-*transfer*
basis; and just write Link TRBs onto the Endpoint ring pointing to
the transfer TD, and then one at the end of each transfer TD leading
back to the endpoint ring.

The reason this occured inside usb_disk, and not earlier (e.g.
during descriptor fetching), is that QEMU has special logic around
determining transfer lengths of control transfers which made it
not perform the "TRB valid?" check after evaluating the Link TRB.
So, being implementation-defined behavior, I am guessing that
this same problem was also the cause of boot failures on real
hardware.

This also means that the problem was essentially a race condition,
as if we posted another transfer to the ring before it evaluated
the TRB, it would always work.

The solution of course is to put some valid TRB at the end of
every transfer on the Endpoint ring. A "no-op" would have done
the job (well, maybe not, it appears QEMU does not implement "no-op"
TRBs for some reason), but there was another feature of XHCI
that we did not take advantage of: Event Data TRBs. These provide
the "total transferred length" as well as the status, instead of
the "remaining length" of the final TRB.

This of course required refactoring the use of the CHAIN bit
and the IOC bit (namely, more or less all TRBs save the Event Data
get the CHAIN bit set, and none save Event Data get the IOC bit.)

There was also an update to the XHCI spec since I've last committed here,
so the new comments are in reference to the "XHCI 1.2" spec. (I'll
eventually find time to update the old ones.)

Fixes booting from USB3 on QEMU, and most likely also on
bare metal, where it at least got to usb_disk (it does
not seem to fix the case where usb_disk does not even start.) Whew!


# 9be728de 16-Jun-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Set the DCS bit in SetTRDequeue.

It is needed here as in ConfigureEndpoint. See inline comment.
This matches FreeBSD's behavior.


# 4029b219 16-Jun-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix a -Werror=format.


# 086528f6 16-May-2019 Augustin Cavalier <waddlesplash@gmail.com>

USB & XHCI: Refactor endpoint initialization to support SuperSpeed better.

SuperSpeed (USB3) devices have a "companion descriptor" along with the
endpoint descriptors that describes certain other attributes they have,
which are important for the controller to schedule transfers properly.
Previously we were just using USB2 values; now we are properly using USB3
ones.

Tested on an Intel Lynx Point controller. As far as I can tell, no
regressions, but #15000 is not fixed anyway.


# 49f507c4 15-May-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Remove unused parameter to ConfigureEndpoint.

No functional change intended.


# e8b2085d 18-Apr-2019 Augustin Cavalier <waddlesplash@gmail.com>

busses/usb: Print the PCI ID of the device with an invalid IRQ.


# 716ccf04 14-Apr-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: If the capability parameters are invalid, bail.

This is the cause of #14557. It seems that OpenBSD does the same thing.
I didn't read the spec yet to determine precisely what this means,
so for now, just do what OpenBSD does and bail.

This only seems to happen with a secondary XHCI controller on that
device, so hopefully most USB ports will still work.


# 6be54385 13-Apr-2019 Augustin Cavalier <waddlesplash@gmail.com>

busses/usb: Handle getting/putting the PCI modules properly.

Previously it was possible that we put() them twice, leading to
assert-failure panics as their ref-counts would go below 0.
Now we get() them once for every bus object that we create, as
the destructors put() them.

Should fix the panic in #15004.


# 77b171dc 09-Apr-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rename fields of xhci_trb to match their actual purposes.

FreeBSD has the names we used before this commit; OpenBSD has names
more similar to the ones used in this commit (though following their
conventions of course.)

This makes the code significantly more readable.


# c05742c8 09-Apr-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Do all endianness conversion of TRBs in LinkDescriptorForPipe.


# fef60ce6 17-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Reworking locking behavior and check for lock failures.

Should fix #14959.


# dda9c027 12-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Use MutexLocker in HandleTransferComplete.


# 1d79fe61 12-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Implement CancelQueuedTransfers and RemoveEndpointForPipe.

Seems to work OK on my hardware now. Possibly helps with device unplug/replug
issues; though that worked on my hardware before this change, too. This is
now more correct at least.


# 7356f1de 09-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Properly handle partially-failed transfers.


# e6a55c69 09-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Miscellaneous tweaks and cleanups.

* Check "endpoint == NULL" instead of the ID for this pipe; as
_InsertEndpointForPipe will have already done the check for us.
* Store the endpoint's ID (our internal ID) in the structure, and
then move the doorbell-ring into _LinkDescriptorForPipe. Now all
variables named "id" are actually that, and not the endpoint number
(which is "id + 1".)
* Return actual statuses in NotifyPipeChange, among other tweaks.
* All things which set the usb_request_data structure also set data,
so we can just use ReadDescriptor to do copies like normal, simplifying
the finish-transfers code.

No (major) functional change intended.


# 6aae8d5a 09-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Improve tracing in CreateDescriptor.


# 3131c130 08-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Implement the debug transfer hooks.

This requires a bit of massaging around the locking code. Probably
we shouldn't be able to do this, and there should be a "mutex_unlock_etc"
for use in interrupt contexts, but at present there is not.

This makes it possible to use XHCI-attached keyboards from within KDL!


# 9bdd88eb 08-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Granularize locking.

This is not so important now (though it is a mild performance improvement
when running transfers during commands), but it will be when the debug
transfer hooks are implemented, as we will need to use these to determine
if it is safe to queue and poll for transfers or not.


# 187a2c6c 08-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Completely overhaul endpoint configuration logic.

The code as it was before was very hard to follow and incorrect in
a number of corner cases, as well as not being very clear about what
the TODOs were.

It now follows the spec much more closely (especially in interval
computation) and contains more details on where it is still lacking.

This probably does not fix much (if anything) as is, but it paves the
way for future isochronous support.


# 57608a81 05-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix a race condition in request submission.

See inline comments. At least in brief testing I couldn't cause the
USB-HID stalls anymore, but they were very intermittent for me anyway.
But it was doubtless the case that the logic as it was before was
very much incorrect.


# 2df34466 04-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Allocate one physical chunk for all buffers if possible.

Besides calling the allocator fewer times, this also helps break up
the size classes we are allocating chunks from, reducing memory pressure.

As most transfers are smaller than 128KB, this is a major performance
optimization for them.


# ee0d30cf 04-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix fencepost logic error in _LinkDescriptorForPipe.

See inline comment. This is very subtle stuff...

I didn't manage to trigger this in my brief testing, and the USB-HID
stall during USB Disk access is still not very difficult to reproduce.
So, this doesn't seem to have been the issue.


# bae7f6d5 04-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Completely rewrite Transfer Descriptor and related logic.

This is essentially a complete rewrite of the way TDs work, and a
significant change to how "normal" requests are submitted. In summation:
* There is now no such thing as a "descriptor chain". This was a concept
mostly carried over from EHCI and previous controllers that does not
really map to XHCI properly, as one "transfer descriptor" can contain
as many TRBs as are necessary to complete the transfer.

What we were really doing before was setting up multiple TRB sequences
owned by our xhci_td structure, and then linking them together with the
CHAIN bit set on each TRB, which in XHCI terms is *one* descriptor,
not multiple ones as we had it, and we were allocating the same amount
of memory anyway, so we might as well do it all in one structure.

So now xhci_td does not have a fixed size of TRBs, but rather a dynamic
one, and thus also a dynamic number of buffers. As part of this refactor,
xhci_td is now a data structure for our own use only, and so it is allocated
from the normal heap instead of as physical memory, and TRBs separately.
* Removing the distinction between "descriptor" and "descriptor chain" greatly
simplifies quite a lot of logic related to transfer handling, especially
in WriteDescriptor and ReadDescriptor, which no longer need to handle
writing to buffers across xhci_td boundaries.
* There is now a proper split between "trb_count" and "trb_used". The former
is the actual number of TRBs allocated in the data structure; the latter
is the number presently used in said data structure. This clarifies
quite a lot of code.

As part of this refactor, a number of other related issues were also cleaned up:
* TRB buffer sizes are now hard-coded to be 4x the Max Packet Size for the
given pipe. Previously they were 64KB, which is much larger than the spec
suggests. As we now size them exactly this way, we can set the endpoint's
Average TRB Length to this value also, which allows the controller to
better schedule transfers for us. This logic can probably be cleaned up
further in the future, even.
* We now write the "TD Size" field of Normal transfers (i.e. packet count,
not TRB count) properly, as it is now much easier to compute based on
our new TRB sizing logic.
* We now record the Max Packet Size for the endpoint in the endpoint
structure. (This will probably be more useful when we are dealing
with isochronous transfers later on.)
* Write the last cycle bit in _LinkDescriptorForPipe after everything else
has been written. This probably does not affect anything too seriously,
but it is technically more correct.
* Added section & page references to the specification in various comments.
* Added more error checking where applicable.

Some things still to be done that I noticed while working on this change:
* When we use a single large buffer and manually segment it rather than
calling AllocateChunk() for each one, there is a massive performance
gain (I saw 50MB/s -> 95MB/s in testing on some USB devices.) However,
we can't do this unconditionally, as the stack doesn't allocate physical
chunks larger than 32 * B_PAGE_SIZE, which is a problem for some filesystems
which can read/write in chunks of 1MB. I'll implement this in a later commit.
* Setting the IOC bit on the last TRB in a transfer is acceptable to find
out when the transfer is finished, but it isn't enough to get a proper
tally of how much data was transfered. This is what Event Status TRBs
are for; we should implement them.
* _LinkDescriptorForPipe has an overflow condition. I'll fix that in the
next commit.

Tested on a ThinkPad E550 (Intel Broadwell) with usb_disk and usb_hid.


# dc9a81f0 04-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Partially fix TD size computation.

Previously we were sending the hardware completely garbage values,
as CreateDescriptorChain clobbered the trbCount value it had set
by using it to determine how many more TRBs it needed to allocate,
and so it usually returned with the value set to 0.

Then SubmitNormalRequest() would immediately subtract 1, causing it
to become negative, and the loop would continue doing this, which also
violated the spec's notice that the field should be 31 if its "true
value" was >= 31, and of course 0 for the last TRB in the transfer.

The spec also says this should be the number of packets remaining, not
the number of TRBs remaining, which we also do not obey; but that
will be a problem for another time, so just add a TODO.


# 10230c7a 04-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Reorder some functions and tweak class definition.

No functional change intended (some methods are now private,
but nothing outside this class used them, so no change.)


# a40a4c0d 04-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Don't try to submit transfers to non-existent endpoints.

Fixes #12929. The underlying issue that caused it still remains, though.


# 6b4d0adc 04-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Clear the device struct after tearing down its state.

This clears out the area_ids, the pointers to them, and a variety
of other state information that will be invalid following the
deletion of the device.

Turns #12929 from a use-after-free into a NULL dereference panic.


# 1533bd88 03-Mar-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Style cleanup and dead code removal.

No functional change (besides some tweaked tracing) intended.


# 695f50f6 02-Mar-2019 Greg Crain <gcrain70@gmail.com>

XHCI: Adjust timeouts in WaitOpBits.

Operations that succeed should not take longer; ones that fail will.

Should get rid of ControllerReset() failed CMD_HCRST.

Change-Id: I4981a319bd64a076f2f404214a96d9909f0676de
Reviewed-on: https://review.haiku-os.org/c/1135
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 9cd89439 24-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rework locking in HandleTransferComplete.

We need to hold the endpoint lock while reading the TD list on
the endpoint, as otherwise we have no guarantee that the pointers
will not be modified while we are looking at them.

Since this is the only consumer of _UnlinkDescriptorForPipe, just
make that function assume a lock, and then do all locking within
HandleTransferComplete.


# 65ceb4c9 23-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rewrite transfer-complete handling code.

* Don't set the IOC bit on the link TRB in LinkDescriptorForPipe. We don't
want to know about this' completion, only about the other transfers
completion and statuses. This should halve the interrupt rate.
* Check if this is an Event Data TRB, and return an error if it is.
(I haven't managed to trigger this code, but it is theoretically possible.)
* Rewrite loops for clarity and consistency.
* Use the correct offset when checking for the TRB.
- Don't rely on the trb_count to tell us whether the TRB is in the TD,
but just check the address based on MAX_TRBS_PER_TD.
- Previously, as the link TRB would trigger an interrupt, we could rely
on that to determine when the transfer finished. But that of course
did not tell us the correct status, as the link TRB is techically in a
different TD, as it isn't linked to the previous TRBs. Now we always use
"count - 1", which will be the final TRB in the TD, properly speaking.
* Print errors when we fail to find the TRB for any reason.

Reading multiple GB and abusing "stat" on a usb_disk following this commit
only managed to stall my usb_hid attached mouse once in multiple rounds of
testing, which seems a marked improvement; previously only a few hundred MB
and not that much abuse of "stat" were needed to actually trigger the stall.
So it seems this improves the stall situation considerably.


# 6a00da68 23-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Tweak comment in SubmitControlRequest.

Re-add page number, and fix verb tense while I'm at it.


# 150ce798 23-Feb-2019 Jérôme Duval <jerome.duval@gmail.com>

XHCI: calls FreeDescriptor before returning.

introduced in the previous commit.


# 342c9976 23-Feb-2019 Jérôme Duval <jerome.duval@gmail.com>

XHCI: revert part of c409803d6f4a0577547c05938c6fecd1a43aec4a

The TRB_3_DIR bit on the Status Stage was previously correctly set as per the spec:
Table 4-6: Status Stage TRB and Device-to-host and wLength > 0 means DIR OUT.

Also free descriptors when _LinkDescriptorForPipe fails.


# 88180e2f 22-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Allow commands to time out after 1s instead of stalling forever.

This seems to occur when trying to stop endpoints in certain scenarios,
at least.


# 358dd70e 22-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Initialize all fields during endpoint setup.

As we reuse memory on a device for endpoints, this is potentially a
functional change.


# c4db8aba 22-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Delete the device in FreeDevice() before tearing down internal state.

We don't properly tear down endpoints, etc. yet, but when we do, this will
be important as the device destructors are what tells us to do that.


# 1464b156 22-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Minor non-functional cleanups.


# 7b53b3c2 22-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Don't compute the error code twice.

No functional change.


# c409803d 22-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Refactoring and fixes to SubmitControlRequest.

* Rearrange some basic setup to be more towards the top of the function,
so we have less things to tear down upon failures.
* Don't double-initialize qwtrb0 of the Setup Stage (no functional change.)
* Rework Data Stage initialization considerably:
- TD_SIZE refers to the number of remaining TRBs in this TD. As we only
use 1 TRB for the Data Stage TD at present, this should be 0, not 1.
- Actually copy data for outbound transfers. (This code does get hit,
so I'm not sure how it wasn't a problem previously.)
* Initialize the first quadbit of the Status Stage. (Potentially a
functional change.)
* Set the TRB_3_DIR bit on the Status Stage correctly as per the spec.
(See inline comment.)

Device initialization seems to behave much more smoothly now; at least on
my hardware, the "error Parameter" doesn't happen anymore, and of course
anything depending on outbound Control transfers will now work correctly.
I now get much better speeds from usb_disk, but I still see usb_hid stalls
after this patch.


# a54fc27a 21-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Check the device object initialized successfully before adding it.

Fixes various NULL dereferences in other parts of the USB stack
when the XHCI controller is not behaving quite as expected.

Possibly related to #13403.


# c7f186b2 21-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Make some errors more descriptive.

Also contains some minor coding style cleanup.


# 5fd80233 20-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Disable Stop/SetTRD/Reset again.

They don't seem to particularly help, and there are reports
that this broke XHCI completely on some devices.

This reverts commit a21f7b525b2c030a07592354bc51eb186206392b.


# a21f7b52 19-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Move and reorder Stop/SetTRD/Reset during endpoint creation.

Fixes a lot of "command failed: invalid context" errors on a variety
of devices following previous commits. Does not seem to affect much,
though.


# a182f193 19-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

USB: Properly assign IDs to USB Bus Managers (HCI drivers).

Previously they would just get -1, as the BusManager class
would request their ID before they had been added to the Stack.
Now we add them to the stack inside ::Start(), rather than letting
the individual drivers do that just after ::Start(), and then assign
the ID there directly.


# d6f3954f 19-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Tweak copyright header.

* List authors in alphabetical order.
* Add myself.
* Make first copyright year the actual year the file was created.


# d47cf79f 18-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Rework endpoint-for-pipe setup and initialization.

* Stop/Reset/Set was commented out because it caused invalid context
states. This was because we cannot run those commands until after
we have configured the endpoint. Moving them to after that
makes it work properly.
* Add the endpoint to the context after configuring it, not before.
* After configuration, we need to issue either an EvaluateContext
or a ConfigureEndpoint, but not both, depending on whether
this is endpoint number 1 (Control) or not.

All cross-checked against FreeBSD (the last change in particular comes
directly from a change of theirs.)

Tested with usb_disk and usb_hid on already-working hardware, no
obvious regressions. Possibly helps with #13834, among other
initialization problems.


# 0ca15910 18-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Check return value of _LinkDescriptorForPipe.


# db360a20 18-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Make sure we have at least one TRB in CreateDescriptorChain.

Linux seems to do the same thing. Confirmed as correct by korli
in #12929.


# eae896c7 18-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Print command code in "unsuccessful command" log message.

This should help with debugging #13772.


# a881209f 18-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Minor tweaks and other changes.

* Cap fSlotCount at the hardware level, not just at the software
level.
* Clear interrupts in init routine.
* Write high DMA address of DCBAAP.

Found by cross-comparing with DragonFlyBSD and OpenBSD.


# 6554cc22 18-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Fix the build of tracing code.


# f7e23917 31-Jan-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Use InitKernelAccess/PrepareKernelAccess properly.

* Actually check return codes of InitKernelAccess().
* WriteDescriptorChain accesses the memory in the IO vectors, so
we need to PrepareKernelAccess before calling it.

Fixes #14752.


# 8fa626d0 16-Jan-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Refactor register area access and handling.

* Don't bother aligning the PCI memory addresses; they will already
be aligned, and even if by some mystery they aren't, map_physical_memory
should be able to handle that. This greatly simplifies the code.
* Use one pointer and then four different offset fields instead of four
different pointers. This is what DragonFlyBSD and FreeBSD do; it's
a negligible loss in performance (or none at all, depending on arch
and compiler) as it requires only one more add, and greatly clarifies
the code as to what's going on.
* Remove (both previously and now) unused fields from the header.
* Compute runtime and doorbell register offsets correctly (there
was a missing bitmask.) This is how it's done on FreeBSD and
DragonFlyBSD.
* Actually write the high bits of the DMA addresses. Checked against
FreeBSD and DragonFlyBSD.
* Tweak error message.

Possibly fixes the "invalid bus space memory access" crash, but
I don't have any hardware that occurs on so I couldn't check.

Tested in VMware, VirtualBox, and on a ThinkPad E550 (Broadwell).


# daa6582a 10-Jan-2019 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Don't reject devices with "invalid" IRQs immediately.

It seems some controllers are assigned "invalid" interrupt lines under
the expectation they will be allocated an MSI. So, don't reject
these devices for having an invalid interrupt line until after
we have tried to allocate an MSI for them.

Should fix #14792.


# f203f99d 20-Oct-2018 Murai Takashi <tmurai01@gmail.com>

xhci: Fix -Wtautological-pointer-compare

Modify if condition, since:
1) Comparison of array 'current->buffer_log' equal to a null pointer
is always false. Pointed out by clang.
2) XHCI::CreateDescriptor() sets buffer_log[0] to NULL,
when bufferSize <= 0.

Change-Id: I9a632dcf9c41435653b0556ed981d78bab846038
Reviewed-on: https://review.haiku-os.org/638
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 642ac9c9 10-Oct-2018 Peter Kosyh <p.kosyh@gmail.com>

xhci: GetPortStatus, ClearPortFeature (PS_PLC, PS_WRC) fix

Fixes #13768.

Change-Id: Ia783e62a15917a2c8f7b3169ee5204a8d8d6f5ef
Reviewed-on: https://review.haiku-os.org/622
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: Alexander von Gluck IV <kallisti5@unixzen.com>


# 7f644d10 09-Sep-2018 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: gcc2 buildfix from hrev52319

Change-Id: I5d82059bd002c26ba372d55f5a5538ce7d19ffb2


# bd234de1 07-Sep-2018 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Turn OpsReg waits into common function

Change-Id: I52ada3447b638db07622fa51746e75ce6cce7a46
Reviewed-on: https://review.haiku-os.org/518
Reviewed-by: Alexander von Gluck IV <kallisti5@unixzen.com>


# 05a859eb 14-Jan-2018 Jérôme Duval <jerome.duval@gmail.com>

usb: map registers or allocate area for the kernel only.


# af0c1fa6 29-Nov-2017 Greg Crain <gcrain70@gmail.com>

xhci: fix hub descriptor command request

The command to get the hub descriptor needs to be a class request and was incorrect causing a Stall error for the hub. The the driver does not handle a stall error yet, causing odd behavior.

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>


# fd6ef337 08-Nov-2017 Jérôme Duval <jerome.duval@gmail.com>

xhci: HandleTransferComplete: adjust the lower check.

after the previous commit.


# c5ea0115 08-Nov-2017 Greg Crain <gcrain70@gmail.com>

xhci: Fix incorrect TRB offset; solves #13343

* The incorrect offset would result in semaphores timing out

Signed-off-by: Alexander von Gluck IV <kallisti5@unixzen.com>


# e3441678 08-Nov-2017 Greg Crain <gcrain70@gmail.com>

xhci: the command ring must be stopped when setting its address.

* send stop and cancel commands.

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>


# 5ed6ef8e 08-Nov-2017 Greg Crain <gcrain70@gmail.com>

xhci: SubmitControlRequest: init 1st quadbit in SetupStage

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>


# 4d5934a2 02-Aug-2017 Jérôme Duval <jerome.duval@gmail.com>

xhci: handle 64 bytes context structures.

* it shouldn't harm controllers with 32-bytes context size.


# 30bcd372 01-Aug-2017 Jérôme Duval <jerome.duval@gmail.com>

xhci: always trace version, structural and capability params.


# 979a0b6a 30-Jul-2017 Adrien Destugues <pulkomandy@pulkomandy.tk>

xhci: Fix fuplicate trace.

Makes reading the logs a little less confusing.


# 6f1ae3c8 30-Jul-2017 Adrien Destugues <pulkomandy@pulkomandy.tk>

XHCI: fix tracing

- The XHCI version register is at offset 2, but we can't do a 32-bit
read at that address. Instead read at address 0 and shift. Fix a freeze
on my system (this register is currently used only for tracing, but I
noticed my USB controller implements version 0.96 and not 1.0 of the
spec, so maybe this will have to change). All other registers in the
capability area are already properly aligned.
- Usual printf type mismatch error in xhci.cpp.


# a2be272b 27-Apr-2017 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Clean up command register defines

* Ensure their naming match Intel xhci datasheets


# deb50a89 28-Mar-2017 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Cleanup tracing, add trb ring dump

* Cleanup trace output. Don't print hex without 0x prefix.


# 45ce7ea8 27-Mar-2017 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Improve No-Op tracing


# 8629d82e 27-Mar-2017 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Cleanup double endian conversions

* The previous xhci endian fixes performed some double
conversions.
* Tighten down conversions to only where the driver interacts
with raw trb3 data in the ring buffer
* No impact to x86*


# b3a29dbd 24-Feb-2017 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Ensure trb3 is correct endian


# c6bd5d1e 02-Nov-2016 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Use 64-bit pci addresses when requested

* My skylake requests 64-bit addressing.. so I think
Intel might start leveraging this soon.
* Hopefully won't break any builds, might have to wrap
that << 32 shift if phys_addr_t is 32-bits anywhere.


# 06bb9887 30-Oct-2016 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Check and report interface version

* We could also check to make sure it isn't 0xffff and
bail if it is... not really a solution but helps
prevent kdl's if our mapped memory is corrupted.
* That seems like more of a hack though, i'd like to
solve the real problem.


# 59e33163 29-Oct-2016 Alexander von Gluck IV <kallisti5@unixzen.com>

xhci: Trace eecp register before access, not after


# 8a12a74e 27-Jul-2016 Jérôme Duval <jerome.duval@gmail.com>

XHCI: fix KDL for transfers using more than 1TD.

* TD chains were broken, any transfer above ~1MB would trigger a KDL.
* _LinkDescriptorForPipe() links the last TD of the chain instead of the first.
* Still buggy: the transfer ring can still block and transfers then fail.
* Enable TRB_3_ISP_BIT where appropriate (Interrupt on Short Packet).
* Also fix WriteDescriptorChain() and ReadDescriptorChain() for multiple-TD chains.


# b267679b 25-Jul-2016 Augustin Cavalier <waddlesplash@gmail.com>

XHCI: Remove the whitelist and enable by default for all controllers.

Discussed with kallisti5 and PulkoMandy before committing. So far, the
only bugs since korli's recent changes either are minor ones that don't
appear to affect functionality (e.g. #12860), or so bad that nothing works
(so, just as good as if the controller was disabled.) PulkoMandy reports
that his controller works but wasn't whitelisted, as have some other users,
so I'm enabling it by default.

If there turn out to be too many broken devices, we can revert this. Or only
revert it in the beta branch, if needed.


# e3d81394 01-Jul-2016 Jérôme Duval <jerome.duval@gmail.com>

XHCI: whitelist 0x9c31 Haswell/Panther Point.

* works nicely (~150 MB/s, 22GB read in about 145s, Linux does 410MB/s).
* also tested Fresco Logic FL1009 OK, but segfaults seem to happen once in a while.


# 936696c7 30-Jun-2016 Jérôme Duval <jerome.duval@gmail.com>

XHCI: fix handling of transfer events.

* previously processing of transfer began when an event on the transfer descriptor happened. Now wait until the last TRB to be processed to process and free the descriptor. Chains are probably not handled correcly yet, but usual transfers happen on a single TD.
* use a specific link pointer for transfer descriptor chains.
* tested on VirtualBox passthrough with mounting an external SSD enclosure. It doesn't scale well with SMP: 1CPU ~115MB/s, 2CPU ~65MB/s, 4 CPU ~50MB/s.
* whitelist controller Intel product ID 0x1e31 (found on VB5).


# 9ff90257 18-Jun-2016 Murai Takashi <tmurai01@gmail.com>

XHCI: Increase fScratchpadCount size

* To fix clang's '-Wtautological-constant-out-of-range-compare' warnings in xhci.cpp.
* by korli: adjust trace print macro.
Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>


# f91361e0 02-Aug-2014 Akshay Jaggi <akshay1994.leo@gmail.com>

XHCI: Even more fixes.

* Fix Endpoint Context Initialisation (Refer xHCI v1.1 - 6.2.3)
* Fix Interval Calculation (Refer xHCI v1.1 - 6.2.3.6 , USB 2.0 - 9.6.6 page 271)
* Fix MaxBurst, MaxPacketSize Calculation (Refer xHCI v1.1 - 6.2.3.5, USB 2.0 - 9.6.6 page 271)
* Fix MaxESITPayload Calculation (Refer xHCI v1.1 - 4.14.2)
* Remove Link TRBs as they were never being used
* Increase Number of TRBs per endpoint (to utilise the whole area allocated for Device TRBs)
* Fix usage of XHCI_MAX_ENDPOINTS (most of the checks were failing at corner cases)
* Some coding style fixes.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
Before this patch, writes to USB disks on XHCI in VirtualBox (which emulates
an Intel C210) stalled or failed. After this patch, they apparently work,
although I got mixed results - a BFS disk seemed to work perfectly, a FAT32
one also seemed to work OK but after a reboot there was data corruption. USB
mouse is still as busted as ever.


# 3cc63261 28-Dec-2015 Augustin Cavalier <waddlesplash@gmail.com>

busses/usb: Trim trailing whitespace.


# 2bc202c4 23-Nov-2015 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: Add port routing for Intel WildcatPoint LP USB.

* from FreeBSD.


# 81768f44 09-Nov-2015 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: include in the Haiku package, only enabled two devices

for now.


# 7dc8098a 21-Dec-2014 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: Add port routing for Intel WildcaPoint USB device.

* from FreeBSD.


# 5ce63aed 21-Oct-2014 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: Add port routing for Intel BayTrail USB device.

* from FreeBSD.


# 192f01c6 11-Jul-2014 Akshay Jaggi <akshay1994.leo@gmail.com>

XHCI USB: Some more fixes.

* Fix device speed identification.
* Fix Max Packet Size for Full-Speed devices.
* Fix IRQ rate.
* Update slot context for LS/FS devices connected to non-root HS hub.
* Fix typo.

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>


# 17aa359b 28-Jun-2014 Akshay Jaggi <akshay1994.leo@gmail.com>

XHCI USB: Fixes.

* Add support for hubs in AllocateDevice().
* Prevent page fault in FinishTransfers().
* Set fCapabilityLength
* Correct in BIOS ownership code
* Fix context errors in _InsertEndpointForPipe().
* Update constants according to latest Specification (v1.1)
* Fix SMI code (reference
http://lkml.iu.edu/hypermail/linux/kernel/1204.2/02460.html).
* Fix Memory/Device-Slot leaks.
* Fix area allocation for TRBs.
* Fix for Intel Lynx Point and Panther Point chipsets. Also move init
of xhci before ehci, to switch USB 2.0 ports before the ehci module
discovers them.

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>


# 735f58f3 30-May-2014 Jérôme Duval <jerome.duval@gmail.com>

xhci: build fix


# eea62153 24-Nov-2013 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: disabled traces.


# f584c0ca 15-Nov-2013 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: some fixes.

* AllocateDevice(): don't include the root port in the route.
* SubmitNormalRequest(): fail if we couldn't allocate the a descriptor.


# a17e9da1 09-Aug-2013 Jerome Duval <jerome.duval@gmail.com>

XHCI/UHCI USB: forgot to get the x86 PCI module.


# 96adf3ff 30-Jul-2013 Jerome Duval <jerome.duval@gmail.com>

XHCI USB: add MSI support

* similar to OHCI support by mmlr.
* interrupt handler is removed on destruction.


# b9a31d3e 26-Jun-2013 Jérôme Duval <jerome.duval@gmail.com>

xhci: 64bit fixes.

* some coding style fixes.
* adjustments to make use of phys_addr_t where needed.


# 411272ad 03-Jun-2012 Jérôme Duval <jerome.duval@gmail.com>

Work in progress on xHCI bus driver

* added a thread to handle events, locking wasn't easy in an interrupt
handler
* the td struct can now track several buffers instead of just one.
* use Transfer::Data*() instead of Vector*() for the time being
until support for fragmented transfers is done
* added CreateDescriptorChain, WriteDescriptorChain and ReadDescriptorChain,
chained tds not working yet though.
* added a mutex lock per enabled endpoint, lock when touching the endpoint
transfer ring.
* correctly configure interval and average trb length for endpoint contexts.
* interrupt transfers seem to work on real hardware
* xhci qemu driver doesn't advance ring dequeue pointers on link trbs, thus
accessing freed trbs that could already be reused, leading to crash.


# 77a7e76c 02-May-2012 Jérôme Duval <jerome.duval@gmail.com>

Work in progress on xHCI bus driver, testing on emulation.

* Initial testing with QEmu emulation works with interrupt/bulk,
testing on real hardware still not working. Small bulk requests work
OK, not bigger ones (for instance it can't load the MediaPlayer
application at 800KB).
* QEmu doesn't support byte read in the MMIO space, switch to double word.
* added SubmitNormalRequest() for interrupt and bulk endpoints.
* AllocateDevice(): fixed the physical address of the link TRB pointing
to the beginning of the ring.
* _InsertEndpointForPipe(): setup context for non-default endpoints
on creation. This should get the device to the configured state.
* _UnlinkDescriptorForPipe(): the next pointer wasn't null after unlinking.
* HandleTransferComplete(): add descriptor to a list to be processed by the
finisher thread.
* FinishThread(): process finished transfers and call the callback,
then free the TRB.


# 2b31b4a8 01-May-2012 Jérôme Duval <jerome.duval@gmail.com>

Work in progress on xHCI bus driver.

* added more traces, coding style
* added xhci_td, xhci_endpoint structs.
* SubmitRequest: this links a 3-stage TD control request into
the endpoint ring.
* _InsertEndpointForPipe: when a pipe is created, configure the
endpoint and set up the controller cookie.
* CreateDescriptor and FreeDescriptor: allocates memory for a TD.
* _LinkDescriptorForPipe: link a TD in an endpoint ring.
* _UnlinkDescriptorForPipe: unlink a TD
* AllocateDevice:
slot number zero isn't valid.
stick the slot number to the device struct.
configure the default endpoint before calling SetAddress.
address is found in the device context instead of the input context.
device address passed to the USB stack has to begin with 1.
* Ring:
check for invalid slot/endpoint combination.
ring the slot doorbell instead of the doorbell 0.
* Root hub: fixed USB version.
* HandleTransferComplete: finds out the TD which submitted a
transfer.


# 319a3798 22-Dec-2011 Jérôme Duval <jerome.duval@gmail.com>

Work in progress on XHCI bus driver.

* USB Core:
Hub: pass more correct speed, port and address for USB3 devices.
Transfer: doesn't care for bandwidth computation for super speed.
BusManager: Make AllocateDevice() and FreeDevice() virtual, XHCI needs to setup
a slot and an address for the device.
Add USB_SPEED_WIRELESS usb_speed definition.
Add USB2.0 erratum definition and some USB3 definitions
* XHCI:
Find outs which port supports SuperSpeed or not.
Override AllocateDevice() to configure slot and address for a connected device.
Override FreeDevice() to free ressources associated to a slot.
Add context struct definitions.


# d11be975 15-Dec-2011 Jérôme Duval <jerome.duval@gmail.com>

XHCI improvements

* remove the xhci cmd complete thread
* creation of the scratchpad area
* wait for running status after starting the controller
* increase delays on controller reset (250ms instead of 100ms)
* use of SpinLocker from AutoLock.h
* add a DoCommand() method to queue a command, ring and wait for the event
response
* add a method for each command
* XHCI_PORTSC macro was off 1 port
* add definitions for TRB types, Completion Codes.


# d6e4f54f 29-Jul-2011 Jérôme Duval <korli@users.berlios.de>

Patch by Jian Chiang as part of his GSoc Project (coding style fixes by myself):
* xhci controller start operation
* command ring and event ring initialization
* No-Op Command test and real xhci irq handle
* xhci root hub support
* add Super Speed enumeration and xhci_rh.cpp into jamfile


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42511 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 18451a0c 30-Mar-2011 Jérôme Duval <korli@users.berlios.de>

Added skeleton XHCI driver by Jian Chiang, based on the specs and the EHCI driver.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41142 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7dc8098ada07aa48c35f30638d89c49d7ff84fca 21-Dec-2014 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: Add port routing for Intel WildcaPoint USB device.

* from FreeBSD.


# 5ce63aed59b871186f0c4a966a4d447c9fc5e757 21-Oct-2014 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: Add port routing for Intel BayTrail USB device.

* from FreeBSD.


# 192f01c669102651bdc81273811079e90e0a29e5 11-Jul-2014 Akshay Jaggi <akshay1994.leo@gmail.com>

XHCI USB: Some more fixes.

* Fix device speed identification.
* Fix Max Packet Size for Full-Speed devices.
* Fix IRQ rate.
* Update slot context for LS/FS devices connected to non-root HS hub.
* Fix typo.

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>


# 17aa359b5df69f658b4b33e29546c9fb2f0cfce3 28-Jun-2014 Akshay Jaggi <akshay1994.leo@gmail.com>

XHCI USB: Fixes.

* Add support for hubs in AllocateDevice().
* Prevent page fault in FinishTransfers().
* Set fCapabilityLength
* Correct in BIOS ownership code
* Fix context errors in _InsertEndpointForPipe().
* Update constants according to latest Specification (v1.1)
* Fix SMI code (reference
http://lkml.iu.edu/hypermail/linux/kernel/1204.2/02460.html).
* Fix Memory/Device-Slot leaks.
* Fix area allocation for TRBs.
* Fix for Intel Lynx Point and Panther Point chipsets. Also move init
of xhci before ehci, to switch USB 2.0 ports before the ehci module
discovers them.

Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>


# 735f58f3e431523b88c4a44375417582e12d8bd8 30-May-2014 Jérôme Duval <jerome.duval@gmail.com>

xhci: build fix


# eea621534b5fe65a17bc91548d22819b4da35f85 24-Nov-2013 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: disabled traces.


# f584c0ca5f5b2035d241cc5ef9c5ebf4fa4de9ad 15-Nov-2013 Jérôme Duval <jerome.duval@gmail.com>

XHCI USB: some fixes.

* AllocateDevice(): don't include the root port in the route.
* SubmitNormalRequest(): fail if we couldn't allocate the a descriptor.


# a17e9da139e1c52635143c4adcda172513d28c19 09-Aug-2013 Jerome Duval <jerome.duval@gmail.com>

XHCI/UHCI USB: forgot to get the x86 PCI module.


# 96adf3ffad2c81bd60876fff16f8768e2c035c9f 30-Jul-2013 Jerome Duval <jerome.duval@gmail.com>

XHCI USB: add MSI support

* similar to OHCI support by mmlr.
* interrupt handler is removed on destruction.


# b9a31d3e18c1f6f1ad49d6d2ebfa5cfa7d7b2cb8 26-Jun-2013 Jérôme Duval <jerome.duval@gmail.com>

xhci: 64bit fixes.

* some coding style fixes.
* adjustments to make use of phys_addr_t where needed.


# 411272adfd60dcab0a42879cc617b59d9c333ca3 03-Jun-2012 Jérôme Duval <jerome.duval@gmail.com>

Work in progress on xHCI bus driver

* added a thread to handle events, locking wasn't easy in an interrupt
handler
* the td struct can now track several buffers instead of just one.
* use Transfer::Data*() instead of Vector*() for the time being
until support for fragmented transfers is done
* added CreateDescriptorChain, WriteDescriptorChain and ReadDescriptorChain,
chained tds not working yet though.
* added a mutex lock per enabled endpoint, lock when touching the endpoint
transfer ring.
* correctly configure interval and average trb length for endpoint contexts.
* interrupt transfers seem to work on real hardware
* xhci qemu driver doesn't advance ring dequeue pointers on link trbs, thus
accessing freed trbs that could already be reused, leading to crash.


# 77a7e76cc13ba10f354d1cf43467b612149e04ab 02-May-2012 Jérôme Duval <jerome.duval@gmail.com>

Work in progress on xHCI bus driver, testing on emulation.

* Initial testing with QEmu emulation works with interrupt/bulk,
testing on real hardware still not working. Small bulk requests work
OK, not bigger ones (for instance it can't load the MediaPlayer
application at 800KB).
* QEmu doesn't support byte read in the MMIO space, switch to double word.
* added SubmitNormalRequest() for interrupt and bulk endpoints.
* AllocateDevice(): fixed the physical address of the link TRB pointing
to the beginning of the ring.
* _InsertEndpointForPipe(): setup context for non-default endpoints
on creation. This should get the device to the configured state.
* _UnlinkDescriptorForPipe(): the next pointer wasn't null after unlinking.
* HandleTransferComplete(): add descriptor to a list to be processed by the
finisher thread.
* FinishThread(): process finished transfers and call the callback,
then free the TRB.


# 2b31b4a88cdcc94b3db80cd453b9fd366420873c 01-May-2012 Jérôme Duval <jerome.duval@gmail.com>

Work in progress on xHCI bus driver.

* added more traces, coding style
* added xhci_td, xhci_endpoint structs.
* SubmitRequest: this links a 3-stage TD control request into
the endpoint ring.
* _InsertEndpointForPipe: when a pipe is created, configure the
endpoint and set up the controller cookie.
* CreateDescriptor and FreeDescriptor: allocates memory for a TD.
* _LinkDescriptorForPipe: link a TD in an endpoint ring.
* _UnlinkDescriptorForPipe: unlink a TD
* AllocateDevice:
slot number zero isn't valid.
stick the slot number to the device struct.
configure the default endpoint before calling SetAddress.
address is found in the device context instead of the input context.
device address passed to the USB stack has to begin with 1.
* Ring:
check for invalid slot/endpoint combination.
ring the slot doorbell instead of the doorbell 0.
* Root hub: fixed USB version.
* HandleTransferComplete: finds out the TD which submitted a
transfer.


# 319a3798bc05579e8be813c2524bc89864bae489 22-Dec-2011 Jérôme Duval <jerome.duval@gmail.com>

Work in progress on XHCI bus driver.

* USB Core:
Hub: pass more correct speed, port and address for USB3 devices.
Transfer: doesn't care for bandwidth computation for super speed.
BusManager: Make AllocateDevice() and FreeDevice() virtual, XHCI needs to setup
a slot and an address for the device.
Add USB_SPEED_WIRELESS usb_speed definition.
Add USB2.0 erratum definition and some USB3 definitions
* XHCI:
Find outs which port supports SuperSpeed or not.
Override AllocateDevice() to configure slot and address for a connected device.
Override FreeDevice() to free ressources associated to a slot.
Add context struct definitions.


# d11be9757252d31dfc4d9cdbc6ec17737c30c217 15-Dec-2011 Jérôme Duval <jerome.duval@gmail.com>

XHCI improvements

* remove the xhci cmd complete thread
* creation of the scratchpad area
* wait for running status after starting the controller
* increase delays on controller reset (250ms instead of 100ms)
* use of SpinLocker from AutoLock.h
* add a DoCommand() method to queue a command, ring and wait for the event
response
* add a method for each command
* XHCI_PORTSC macro was off 1 port
* add definitions for TRB types, Completion Codes.


# d6e4f54f2de4c76fbfbe85fc348a8fde8c296dc6 29-Jul-2011 Jérôme Duval <korli@users.berlios.de>

Patch by Jian Chiang as part of his GSoc Project (coding style fixes by myself):
* xhci controller start operation
* command ring and event ring initialization
* No-Op Command test and real xhci irq handle
* xhci root hub support
* add Super Speed enumeration and xhci_rh.cpp into jamfile


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42511 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 18451a0c360c0db068891588dc0f6d97c5ee9cb9 30-Mar-2011 Jérôme Duval <korli@users.berlios.de>

Added skeleton XHCI driver by Jian Chiang, based on the specs and the EHCI driver.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41142 a95241bf-73f2-0310-859d-f6bbb57e9c96