49 { .
name =
"xhci.message" };
53 { .
name =
"xhci.stream" };
57 { .
name =
"xhci.event" };
61 { .
name =
"xhci.transfer" };
65 __einfo_error ( EINFO_EIO_DATA ) 66 #define EINFO_EIO_DATA \ 67 __einfo_uniqify ( EINFO_EIO, ( 2 - 0 ), \ 70 __einfo_error ( EINFO_EIO_BABBLE ) 71 #define EINFO_EIO_BABBLE \ 72 __einfo_uniqify ( EINFO_EIO, ( 3 - 0 ), \ 75 __einfo_error ( EINFO_EIO_USB ) 76 #define EINFO_EIO_USB \ 77 __einfo_uniqify ( EINFO_EIO, ( 4 - 0 ), \ 78 "USB transaction error" ) 80 __einfo_error ( EINFO_EIO_TRB ) 81 #define EINFO_EIO_TRB \ 82 __einfo_uniqify ( EINFO_EIO, ( 5 - 0 ), \ 85 __einfo_error ( EINFO_EIO_STALL ) 86 #define EINFO_EIO_STALL \ 87 __einfo_uniqify ( EINFO_EIO, ( 6 - 0 ), \ 89 #define EIO_RESOURCE \ 90 __einfo_error ( EINFO_EIO_RESOURCE ) 91 #define EINFO_EIO_RESOURCE \ 92 __einfo_uniqify ( EINFO_EIO, ( 7 - 0 ), \ 94 #define EIO_BANDWIDTH \ 95 __einfo_error ( EINFO_EIO_BANDWIDTH ) 96 #define EINFO_EIO_BANDWIDTH \ 97 __einfo_uniqify ( EINFO_EIO, ( 8 - 0 ), \ 99 #define EIO_NO_SLOTS \ 100 __einfo_error ( EINFO_EIO_NO_SLOTS ) 101 #define EINFO_EIO_NO_SLOTS \ 102 __einfo_uniqify ( EINFO_EIO, ( 9 - 0 ), \ 103 "No slots available" ) 104 #define EIO_STREAM_TYPE \ 105 __einfo_error ( EINFO_EIO_STREAM_TYPE ) 106 #define EINFO_EIO_STREAM_TYPE \ 107 __einfo_uniqify ( EINFO_EIO, ( 10 - 0 ), \ 108 "Invalid stream type" ) 110 __einfo_error ( EINFO_EIO_SLOT ) 111 #define EINFO_EIO_SLOT \ 112 __einfo_uniqify ( EINFO_EIO, ( 11 - 0 ), \ 114 #define EIO_ENDPOINT \ 115 __einfo_error ( EINFO_EIO_ENDPOINT ) 116 #define EINFO_EIO_ENDPOINT \ 117 __einfo_uniqify ( EINFO_EIO, ( 12 - 0 ), \ 118 "Endpoint not enabled" ) 120 __einfo_error ( EINFO_EIO_SHORT ) 121 #define EINFO_EIO_SHORT \ 122 __einfo_uniqify ( EINFO_EIO, ( 13 - 0 ), \ 124 #define EIO_UNDERRUN \ 125 __einfo_error ( EINFO_EIO_UNDERRUN ) 126 #define EINFO_EIO_UNDERRUN \ 127 __einfo_uniqify ( EINFO_EIO, ( 14 - 0 ), \ 129 #define EIO_OVERRUN \ 130 __einfo_error ( EINFO_EIO_OVERRUN ) 131 #define EINFO_EIO_OVERRUN \ 132 __einfo_uniqify ( EINFO_EIO, ( 15 - 0 ), \ 134 #define EIO_VF_RING_FULL \ 135 __einfo_error ( EINFO_EIO_VF_RING_FULL ) 136 #define EINFO_EIO_VF_RING_FULL \ 137 __einfo_uniqify ( EINFO_EIO, ( 16 - 0 ), \ 138 "Virtual function event ring full" ) 139 #define EIO_PARAMETER \ 140 __einfo_error ( EINFO_EIO_PARAMETER ) 141 #define EINFO_EIO_PARAMETER \ 142 __einfo_uniqify ( EINFO_EIO, ( 17 - 0 ), \ 144 #define EIO_BANDWIDTH_OVERRUN \ 145 __einfo_error ( EINFO_EIO_BANDWIDTH_OVERRUN ) 146 #define EINFO_EIO_BANDWIDTH_OVERRUN \ 147 __einfo_uniqify ( EINFO_EIO, ( 18 - 0 ), \ 148 "Bandwidth overrun" ) 149 #define EIO_CONTEXT \ 150 __einfo_error ( EINFO_EIO_CONTEXT ) 151 #define EINFO_EIO_CONTEXT \ 152 __einfo_uniqify ( EINFO_EIO, ( 19 - 0 ), \ 153 "Context state error" ) 154 #define EIO_NO_PING \ 155 __einfo_error ( EINFO_EIO_NO_PING ) 156 #define EINFO_EIO_NO_PING \ 157 __einfo_uniqify ( EINFO_EIO, ( 20 - 0 ), \ 159 #define EIO_RING_FULL \ 160 __einfo_error ( EINFO_EIO_RING_FULL ) 161 #define EINFO_EIO_RING_FULL \ 162 __einfo_uniqify ( EINFO_EIO, ( 21 - 0 ), \ 164 #define EIO_INCOMPATIBLE \ 165 __einfo_error ( EINFO_EIO_INCOMPATIBLE ) 166 #define EINFO_EIO_INCOMPATIBLE \ 167 __einfo_uniqify ( EINFO_EIO, ( 22 - 0 ), \ 168 "Incompatible device" ) 170 __einfo_error ( EINFO_EIO_MISSED ) 171 #define EINFO_EIO_MISSED \ 172 __einfo_uniqify ( EINFO_EIO, ( 23 - 0 ), \ 173 "Missed service error" ) 174 #define EIO_CMD_STOPPED \ 175 __einfo_error ( EINFO_EIO_CMD_STOPPED ) 176 #define EINFO_EIO_CMD_STOPPED \ 177 __einfo_uniqify ( EINFO_EIO, ( 24 - 0 ), \ 178 "Command ring stopped" ) 179 #define EIO_CMD_ABORTED \ 180 __einfo_error ( EINFO_EIO_CMD_ABORTED ) 181 #define EINFO_EIO_CMD_ABORTED \ 182 __einfo_uniqify ( EINFO_EIO, ( 25 - 0 ), \ 185 __einfo_error ( EINFO_EIO_STOP ) 186 #define EINFO_EIO_STOP \ 187 __einfo_uniqify ( EINFO_EIO, ( 26 - 0 ), \ 189 #define EIO_STOP_LEN \ 190 __einfo_error ( EINFO_EIO_STOP_LEN ) 191 #define EINFO_EIO_STOP_LEN \ 192 __einfo_uniqify ( EINFO_EIO, ( 27 - 0 ), \ 193 "Stopped - length invalid" ) 194 #define EIO_STOP_SHORT \ 195 __einfo_error ( EINFO_EIO_STOP_SHORT ) 196 #define EINFO_EIO_STOP_SHORT \ 197 __einfo_uniqify ( EINFO_EIO, ( 28 - 0 ), \ 198 "Stopped - short packet" ) 199 #define EIO_LATENCY \ 200 __einfo_error ( EINFO_EIO_LATENCY ) 201 #define EINFO_EIO_LATENCY \ 202 __einfo_uniqify ( EINFO_EIO, ( 29 - 0 ), \ 203 "Maximum exit latency too large" ) 205 __einfo_error ( EINFO_EIO_ISOCH ) 206 #define EINFO_EIO_ISOCH \ 207 __einfo_uniqify ( EINFO_EIO, ( 31 - 0 ), \ 208 "Isochronous buffer overrun" ) 209 #define EPROTO_LOST \ 210 __einfo_error ( EINFO_EPROTO_LOST ) 211 #define EINFO_EPROTO_LOST \ 212 __einfo_uniqify ( EINFO_EPROTO, ( 32 - 32 ), \ 214 #define EPROTO_UNDEFINED \ 215 __einfo_error ( EINFO_EPROTO_UNDEFINED ) 216 #define EINFO_EPROTO_UNDEFINED \ 217 __einfo_uniqify ( EINFO_EPROTO, ( 33 - 32 ), \ 219 #define EPROTO_STREAM_ID \ 220 __einfo_error ( EINFO_EPROTO_STREAM_ID ) 221 #define EINFO_EPROTO_STREAM_ID \ 222 __einfo_uniqify ( EINFO_EPROTO, ( 34 - 32 ), \ 223 "Invalid stream ID" ) 224 #define EPROTO_SECONDARY \ 225 __einfo_error ( EINFO_EPROTO_SECONDARY ) 226 #define EINFO_EPROTO_SECONDARY \ 227 __einfo_uniqify ( EINFO_EPROTO, ( 35 - 32 ), \ 228 "Secondary bandwidth error" ) 229 #define EPROTO_SPLIT \ 230 __einfo_error ( EINFO_EPROTO_SPLIT ) 231 #define EINFO_EPROTO_SPLIT \ 232 __einfo_uniqify ( EINFO_EPROTO, ( 36 - 32 ), \ 233 "Split transaction error" ) 234 #define ECODE(code) \ 235 ( ( (code) < 32 ) ? \ 236 EUNIQ ( EINFO_EIO, ( (code) & 31 ), EIO_DATA, EIO_BABBLE, \ 237 EIO_USB, EIO_TRB, EIO_STALL, EIO_RESOURCE, \ 238 EIO_BANDWIDTH, EIO_NO_SLOTS, EIO_STREAM_TYPE, \ 239 EIO_SLOT, EIO_ENDPOINT, EIO_SHORT, EIO_UNDERRUN, \ 240 EIO_OVERRUN, EIO_VF_RING_FULL, EIO_PARAMETER, \ 241 EIO_BANDWIDTH_OVERRUN, EIO_CONTEXT, EIO_NO_PING, \ 242 EIO_RING_FULL, EIO_INCOMPATIBLE, EIO_MISSED, \ 243 EIO_CMD_STOPPED, EIO_CMD_ABORTED, EIO_STOP, \ 244 EIO_STOP_LEN, EIO_STOP_SHORT, EIO_LATENCY, \ 247 EUNIQ ( EINFO_EPROTO, ( (code) & 31 ), EPROTO_LOST, \ 248 EPROTO_UNDEFINED, EPROTO_STREAM_ID, \ 249 EPROTO_SECONDARY, EPROTO_SPLIT ) : \ 281 xhci->
op = ( xhci->
cap + caplength );
282 xhci->
run = ( xhci->
cap + rtsoff );
283 xhci->
db = ( xhci->
cap + dboff );
284 DBGC2 ( xhci,
"XHCI %s cap %08lx op %08lx run %08lx db %08lx\n",
285 xhci->
name, virt_to_phys ( xhci->
cap ),
286 virt_to_phys ( xhci->
op ), virt_to_phys ( xhci->
run ),
287 virt_to_phys ( xhci->
db ) );
294 DBGC ( xhci,
"XHCI %s has %d slots %d intrs %d ports\n",
300 DBGC2 ( xhci,
"XHCI %s needs %d scratchpads\n",
314 DBGC2 ( xhci,
"XHCI %s page size %zd bytes\n",
380 if ( (
value & ~0xffffffffULL ) && ! xhci->
addr64 ) {
381 DBGC ( xhci,
"XHCI %s cannot access address %lx\n",
404 align = ( 1 <<
fls (
len - 1 ) );
462 DBGC ( xhci,
"XHCI %s USBCMD %08x%s%s\n", xhci->
name, usbcmd,
468 DBGC ( xhci,
"XHCI %s USBSTS %08x%s\n", xhci->
name, usbsts,
473 DBGC ( xhci,
"XHCI %s PAGESIZE %08x\n", xhci->
name, pagesize );
477 DBGC ( xhci,
"XHCI %s DNCTRL %08x\n", xhci->
name, dnctrl );
481 DBGC ( xhci,
"XHCI %s CONFIG %08x\n", xhci->
name, config );
491 unsigned int port ) {
503 DBGC ( xhci,
"XHCI %s-%d PORTSC %08x%s%s%s%s psiv=%d\n",
513 DBGC ( xhci,
"XHCI %s-%d PORTPMSC %08x\n", xhci->
name,
port, portpmsc );
517 DBGC ( xhci,
"XHCI %s-%d PORTLI %08x\n", xhci->
name,
port, portli );
521 DBGC ( xhci,
"XHCI %s-%d PORTHLPMC %08x\n",
548 DBGC ( xhci,
"XHCI %s has no USB legacy support capability\n",
557 DBGC ( xhci,
"XHCI %s USB legacy support already disabled\n",
590 DBGC ( xhci,
"XHCI %s claimed ownership from BIOS\n",
595 DBGC ( xhci,
"XHCI %s warning: BIOS retained " 596 "SMIs: %08x\n", xhci->
name, ctlsts );
608 DBGC ( xhci,
"XHCI %s could not claim ownership from BIOS: forcibly " 609 "disabling SMIs\n", xhci->
name );
626 DBGC ( xhci,
"XHCI %s not releasing ownership to BIOS\n",
633 DBGC ( xhci,
"XHCI %s released ownership to BIOS\n", xhci->
name );
650 static const char *exponents[4] = {
"",
"k",
"M",
"G" };
651 static char buf[ 10 ];
652 unsigned int mantissa;
653 unsigned int exponent;
660 snprintf ( buf,
sizeof ( buf ),
"%d%sbps",
661 mantissa, exponents[exponent] );
673 unsigned int port ) {
694 DBGC ( xhci,
"XHCI %s-%d has no supported protocol\n",
707 unsigned int port ) {
738 DBGC2 ( xhci,
"XHCI %s-%d %sv%04x type %d",
743 DBGC2 ( xhci,
" speeds" );
744 for ( i = 0 ; i < psic ; i++ ) {
748 DBGC2 ( xhci,
" %d:%s", psiv,
753 DBGC2 ( xhci,
" (ignored)" );
754 DBGC2 ( xhci,
"\n" );
792 unsigned int psiv ) {
795 unsigned int mantissa;
796 unsigned int exponent;
814 for ( i = 0 ; i < psic ; i++ ) {
820 speed =
USB_SPEED ( mantissa, exponent );
827 DBGC ( xhci,
"XHCI %s-%d spurious PSI value %d: " 828 "assuming PSI table is invalid\n",
841 DBGC ( xhci,
"XHCI %s-%d unrecognised PSI value %d\n",
856 unsigned int speed ) {
859 unsigned int mantissa;
860 unsigned int exponent;
882 DBGC ( xhci,
"XHCI %s-%d non-standard speed %d\n",
889 for ( i = 0 ; i < psic ; i++ ) {
893 if ( speed ==
USB_SPEED ( mantissa, exponent ) ) {
899 DBGC ( xhci,
"XHCI %s-%d unrepresentable speed %#x\n",
931 DBGC ( xhci,
"XHCI %s could not allocate DCBAA\n", xhci->
name );
943 DBGC2 ( xhci,
"XHCI %s DCBAA at [%08lx,%08lx)\n", xhci->
name,
964 for ( i = 0 ; i <= xhci->
slots ; i++ )
997 if ( ! scratch->
count )
1004 if ( ! scratch->
buffer ) {
1005 DBGC ( xhci,
"XHCI %s could not allocate scratchpad buffers\n",
1013 array_len = ( scratch->
count *
sizeof ( scratch->
array[0] ) );
1016 if ( ! scratch->
array ) {
1017 DBGC ( xhci,
"XHCI %s could not allocate scratchpad buffer " 1018 "array\n", xhci->
name );
1020 goto err_alloc_array;
1025 for ( i = 0 ; i < scratch->
count ; i++ ) {
1035 DBGC2 ( xhci,
"XHCI %s scratchpad [%08lx,%08lx) array [%08lx,%08lx)\n",
1036 xhci->
name, virt_to_phys ( scratch->
buffer ),
1037 ( virt_to_phys ( scratch->
buffer ) + buffer_len ),
1038 virt_to_phys ( scratch->
array ),
1039 ( virt_to_phys ( scratch->
array ) + array_len ) );
1060 if ( ! scratch->
count )
1068 array_len = ( scratch->
count *
sizeof ( scratch->
array[0] ) );
1132 DBGC ( xhci,
"XHCI %s timed out waiting for stop\n", xhci->
name );
1170 DBGC ( xhci,
"XHCI %s timed out waiting for reset\n", xhci->
name );
1219 unsigned int shift,
unsigned int slot,
1220 unsigned int target,
unsigned int stream ) {
1229 memset ( ring, 0,
sizeof ( *ring ) );
1230 ring->
shift = shift;
1231 count = ( 1U << shift );
1233 ring->
len = ( (
count + 1 ) *
sizeof ( ring->
trb[0] ) );
1234 ring->
db = ( xhci->
db + (
slot *
sizeof ( ring->
dbval ) ) );
1239 if ( ! ring->
iobuf ) {
1241 goto err_alloc_iobuf;
1247 if ( ! ring->
trb ) {
1296 for ( i = 0 ; i <
count ; i++ )
1332 prod = ring->
prod++;
1335 index = ( prod & mask );
1394 unsigned int count ) {
1426 }
while ( iobuf ==
NULL );
1463 goto err_ring_alloc;
1471 DBGC2 ( xhci,
"XHCI %s CRCR at [%08lx,%08lx)\n", xhci->
name,
1513 len = (
count *
sizeof (
event->trb[0] ) );
1516 if ( ! event->trb ) {
1523 event->segment =
dma_alloc ( xhci->
dma, &event->segment_map,
1524 sizeof ( event->segment[0] ),
1526 if ( ! event->segment ) {
1528 goto err_alloc_segment;
1530 memset ( event->segment, 0, sizeof ( event->segment[0] ) );
1539 goto err_writeq_erdp;
1541 dma ( &event->segment_map, event->segment ),
1543 goto err_writeq_erstba;
1545 DBGC2 ( xhci,
"XHCI %s event ring [%08lx,%08lx) table [%08lx,%08lx)\n",
1546 xhci->
name, virt_to_phys ( event->trb ),
1547 ( virt_to_phys ( event->trb ) +
len ),
1548 virt_to_phys ( event->segment ),
1549 ( virt_to_phys ( event->segment ) +
1550 sizeof ( event->segment[0] ) ) );
1557 dma_free ( &event->segment_map, event->segment,
1558 sizeof ( event->segment[0] ) );
1581 dma_free ( &event->segment_map, event->segment,
1582 sizeof ( event->segment[0] ) );
1586 len = (
count *
sizeof (
event->trb[0] ) );
1609 DBGC ( xhci,
"XHCI %s transfer event invalid slot %d:\n",
1611 DBGC_HDA ( xhci, 0, trb,
sizeof ( *trb ) );
1618 DBGC ( xhci,
"XHCI %s slot %d transfer event invalid epid " 1620 DBGC_HDA ( xhci, 0, trb,
sizeof ( *trb ) );
1637 DBGC ( xhci,
"XHCI %s slot %d ctx %d failed (code %d): %s\n",
1640 DBGC_HDA ( xhci, 0, trb,
sizeof ( *trb ) );
1675 DBGC2 ( xhci,
"XHCI %s command ring stopped\n", xhci->
name );
1682 DBGC ( xhci,
"XHCI %s unexpected completion (code %d): %s\n",
1684 DBGC_HDA ( xhci, 0, trb,
sizeof ( *trb ) );
1736 DBGC ( xhci,
"XHCI %s host controller event (code %d): %s\n",
1749 unsigned int count = ( 1 << shift );
1750 unsigned int mask = (
count - 1 );
1751 unsigned int consumed;
1760 for ( consumed = 0 ; ; consumed++ ) {
1764 trb = &
event->trb[
event->cons & mask ];
1793 DBGC ( xhci,
"XHCI %s unrecognised event %#x\n:",
1794 xhci->
name, ( event->cons - 1 ) );
1795 DBGC_HDA ( xhci, virt_to_phys ( trb ),
1796 trb,
sizeof ( *trb ) );
1819 DBGC2 ( xhci,
"XHCI %s aborting command\n", xhci->
name );
1834 DBGC ( xhci,
"XHCI %s failed to abort command\n", xhci->
name );
1870 DBGC ( xhci,
"XHCI %s command ring busy\n", xhci->
name );
1895 DBGC ( xhci,
"XHCI %s command failed (code " 1896 "%d): %s\n", xhci->
name, complete->
code,
1898 DBGC_HDA ( xhci, 0, trb,
sizeof ( *trb ) );
1909 DBGC ( xhci,
"XHCI %s timed out waiting for completion\n", xhci->
name );
1940 DBGC ( xhci,
"XHCI %s NOP failed: %s\n",
1945 DBGC2 ( xhci,
"XHCI %s NOP completed successfully\n", xhci->
name );
1957 unsigned int type ) {
1965 memset ( enable, 0,
sizeof ( *enable ) );
1971 DBGC ( xhci,
"XHCI %s could not enable new slot: %s\n",
1979 DBGC2 ( xhci,
"XHCI %s slot %d enabled\n", xhci->
name,
slot );
1991 unsigned int slot ) {
1997 memset ( disable, 0,
sizeof ( *disable ) );
2003 DBGC ( xhci,
"XHCI %s could not disable slot %d: %s\n",
2008 DBGC2 ( xhci,
"XHCI %s slot %d disabled\n", xhci->
name,
slot );
2046 populate ( xhci,
slot, endpoint,
input );
2049 memset ( context, 0,
sizeof ( *context ) );
2085 control_ctx =
input;
2124 DBGC ( xhci,
"XHCI %s slot %d could not assign address: %s\n",
2130 slot_ctx = (
slot->context +
2133 DBGC2 ( xhci,
"XHCI %s slot %d assigned address %d to %s\n",
2157 control_ctx =
input;
2159 ( 1 << endpoint->
ctx ) );
2164 (
slot->ports ? 1 : 0 ),
2196 DBGC ( xhci,
"XHCI %s slot %d ctx %d could not configure: %s\n",
2201 DBGC2 ( xhci,
"XHCI %s slot %d ctx %d configured\n",
2223 control_ctx =
input;
2250 DBGC ( xhci,
"XHCI %s slot %d ctx %d could not deconfigure: " 2256 DBGC2 ( xhci,
"XHCI %s slot %d ctx %d deconfigured\n",
2278 control_ctx =
input;
2280 ( 1 << endpoint->
ctx ) );
2309 DBGC ( xhci,
"XHCI %s slot %d ctx %d could not (re-)evaluate: " 2315 DBGC2 ( xhci,
"XHCI %s slot %d ctx %d (re-)evaluated\n",
2336 memset ( reset, 0,
sizeof ( *reset ) );
2343 DBGC ( xhci,
"XHCI %s slot %d ctx %d could not reset endpoint " 2368 memset ( stop, 0,
sizeof ( *stop ) );
2375 DBGC ( xhci,
"XHCI %s slot %d ctx %d could not stop endpoint " 2407 memset ( dequeue, 0,
sizeof ( *dequeue ) );
2420 DBGC ( xhci,
"XHCI %s slot %d ctx %d could not set TR dequeue " 2421 "pointer in state %d: %s\n", xhci->
name,
slot->id,
2471 endpoint =
zalloc (
sizeof ( *endpoint ) );
2477 slot->endpoint[
ctx] = endpoint;
2484 endpoint->
context = ( ( (
void * )
slot->context ) +
2491 goto err_ring_alloc;
2496 goto err_configure_endpoint;
2498 DBGC2 (
xhci,
"XHCI %s slot %d ctx %d ring [%08lx,%08lx)\n",
2504 err_configure_endpoint:
2523 unsigned int ctx = endpoint->
ctx;
2565 DBGC ( xhci,
"XHCI %s slot %d ctx %d reset\n",
2615 memset ( trbs, 0,
sizeof ( trbs ) );
2617 packet = iobuf->
data;
2618 iob_pull ( iobuf,
sizeof ( *packet ) );
2619 setup = &(trb++)->setup;
2652 ( trb - trbs ) ) ) != 0 )
2681 if ( zlp || (
count == 0 ) )
2720 memset ( &trbs, 0,
sizeof ( trbs ) );
2721 for ( i = 0 ; i <
count ; i ++ ) {
2725 if ( trb_len >
len )
2742 if ( zlp && (
count > 1 ) )
2793 DBGC (
xhci,
"XHCI %s-%d has no slot type\n",
2802 goto err_enable_slot;
2804 assert ( (
id > 0 ) && ( (
unsigned int ) id <= xhci->slots ) );
2820 slot->tt_id = tt_slot->
id;
2828 if ( !
slot->context ) {
2830 goto err_alloc_context;
2839 DBGC2 (
xhci,
"XHCI %s slot %d device context [%08lx,%08lx) for %s\n",
2865 unsigned int id =
slot->id;
2878 DBGC ( xhci,
"XHCI %s slot %d leaking context memory\n",
2884 if (
slot->context ) {
2946 if ( ! xhci->
slot ) {
2948 goto err_slot_alloc;
2953 goto err_dcbaa_alloc;
2957 goto err_scratchpad_alloc;
2961 goto err_command_alloc;
2965 goto err_event_alloc;
2978 err_scratchpad_alloc:
2997 for ( i = 0 ; i <= xhci->
slots ; i++ )
3085 for ( i = 1 ; i <= xhci->
ports ; i++ ) {
3098 for ( i = 1 ; i <= xhci->
ports ; i++ ) {
3159 DBGC ( xhci,
"XHCI %s-%d timed out waiting for port to enable\n",
3216 DBGC2 ( xhci,
"XHCI %s-%d status is %08x\n",
3217 xhci->
name,
port->address, portsc );
3224 port->disconnected |= csc;
3249 port->speed = speed;
3266 DBGC ( xhci,
"XHCI %s-%d nonsensical CLEAR_TT for %s %s\n", xhci->
name,
3331 if ( ! xhci->
bus ) {
3339 for ( i = 1 ; i <= xhci->
ports ; i++ ) {
3401 DBGC ( xhci,
"XHCI %s enabling SuperSpeed on ports %08x\n",
3412 DBGC ( xhci,
"XHCI %s routing ports %08x from EHCI to xHCI\n",
3444 unsigned long bar_start;
3449 xhci =
zalloc (
sizeof ( *xhci ) );
3465 if ( ! xhci->
regs ) {
3517 DBGC ( xhci,
"XHCI %s DMA was disabled\n", xhci->
name );
3542 PCI_ROM ( 0xffff, 0xffff,
"xhci",
"xHCI", 0 ),
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
#define iob_pull(iobuf, len)
uint8_t burst
Maximum burst size.
#define XHCI_USBLEGSUP_MAX_WAIT_MS
Maximum time to wait for BIOS to release ownership.
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
A disable slot transfer request block.
static int xhci_root_speed(struct usb_hub *hub, struct usb_port *port)
Update root hub port speed.
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
static void xhci_command_free(struct xhci_device *xhci)
Free command ring.
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
uint8_t type
Endpoint type.
#define PCI_CLASS_ID(base, sub, progif)
Construct PCI class ID.
struct arbelprm_rc_send_wqe rc
#define XHCI_STATUS_IN
Input status direction.
#define DMA_TX
Device will read data from host memory.
A status stage transfer request block.
struct xhci_trb_context context
Input context TRB.
uint64_t command
Command TRB pointer.
A transfer request block.
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
uint32_t dbval
Doorbell register value.
static struct io_buffer * xhci_dequeue(struct xhci_trb_ring *ring)
Dequeue a transfer request block.
struct dma_device dma
DMA device.
struct xhci_trb_common common
Common fields.
static int xhci_root_clear_tt(struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
Clear transaction translator buffer.
static void xhci_evaluate_context_input(struct xhci_device *xhci, struct xhci_slot *slot __unused, struct xhci_endpoint *endpoint, void *input)
Populate evaluate context input context.
static struct profiler xhci_message_profiler __profiler
Message transfer profiler.
unsigned int ports
Number of ports.
#define XHCI_CONFIG_MAX_SLOTS_EN(slots)
Maximum device slots enabled.
void * buffer
Scratchpad buffer area.
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
struct xhci_dcbaa dcbaa
Device context base address array.
static int xhci_device_open(struct usb_device *usb)
Open device.
#define EBUSY
Device or resource busy.
int xhci_register(struct xhci_device *xhci)
Register xHCI controller.
struct arbelprm_completion_queue_entry normal
#define XHCI_TRB_ENABLE_SLOT
An enable slot transfer request block.
static unsigned int unsigned int reg
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
#define XHCI_OP_USBSTS
USB status register.
#define XHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
#define XHCI_PORTSC_PSIV(portsc)
Port speed ID value.
static int xhci_address_device(struct xhci_device *xhci, struct xhci_slot *slot)
Address device.
#define XHCI_CTX_END
End of contexts.
#define XHCI_ICI(ctx)
Input context index.
static void xhci_hub_close(struct usb_hub *hub __unused)
Close hub.
#define XHCI_XECP_NEXT(xecp)
Next xHCI extended capability pointer.
static unsigned int xhci_extended_capability(struct xhci_device *xhci, unsigned int id, unsigned int offset)
Find extended capability.
struct xhci_device * xhci
xHCI device
#define XHCI_TRB_SET_TR_DEQUEUE_POINTER
A set transfer ring dequeue pointer transfer request block.
unsigned int cons
Consumer counter.
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
void * run
Runtime registers.
A set transfer ring dequeue pointer transfer request block.
struct usb_bus * alloc_usb_bus(struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
Allocate USB bus.
#define XHCI_PORT_RESET_MAX_WAIT_MS
Maximum time to wait for a port reset to complete.
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
size_t len
Length of transfer request blocks.
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
An input control context.
#define XHCI_HCSPARAMS1_PORTS(params)
Number of ports.
static size_t xhci_align(size_t len)
Calculate buffer alignment.
unsigned long driver_data
Arbitrary driver data.
struct xhci_trb_ring command
Command ring.
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
A command completion event transfer request block.
#define XHCI_TRB_DISABLE_SLOT
A disable slot transfer request block.
uint8_t state
Endpoint state.
struct pci_device_id * ids
PCI ID table.
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
uint32_t type
Operating system type.
#define XHCI_PCH_XUSB2PR
Intel PCH USB2 port routing register.
struct xhci_trb_transfer transfer
Transfer event.
#define EPIPE
Broken pipe.
A port status change transfer request block.
uint16_t trb_len
Average TRB length.
union xhci_trb * pending
Current command (if any)
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
#define DMA_RX
Device will write data to host memory.
#define XHCI_EP_TYPE(type)
Endpoint type.
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
struct device * dev
Underlying hardware device.
static int xhci_set_tr_dequeue_pointer(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Set transfer ring dequeue pointer.
#define XHCI_XECP_ID_SUPPORTED
Supported protocol extended capability.
static int xhci_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, unsigned int type, void(*populate)(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input))
Issue context-based command and wait for completion.
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
struct dma_mapping map
DMA mapping.
struct pci_driver xhci_driver __pci_driver
XHCI PCI driver.
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
uint8_t code
Completion code.
struct xhci_trb_disable_slot disable
Disable slot TRB.
#define XHCI_HCSPARAMS1_INTRS(params)
Number of interrupters.
#define ENOENT
No such file or directory.
An enable slot transfer request block.
struct usb_device * usb
Currently attached device (if in use)
#define XHCI_SETUP_OUT
Setup stage output data direction.
static void xhci_deconfigure_endpoint_input(struct xhci_device *xhci __unused, struct xhci_slot *slot __unused, struct xhci_endpoint *endpoint, void *input)
Populate deconfigure endpoint input context.
#define XHCI_OP_PORTHLPMC(port)
Port hardware link power management control register.
struct usb_bus * bus
USB bus.
struct xhci_trb_enable_slot enable
Enable slot TRB.
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
struct dma_mapping buffer_map
Buffer DMA mapping.
static int xhci_configure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Configure endpoint.
#define cpu_to_le64(value)
unsigned int count
Number of page-sized scratchpad buffers.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
static int xhci_command_alloc(struct xhci_device *xhci)
Allocate command ring.
A data stage transfer request block.
uint8_t code
Completion code.
void * db
Doorbell register.
#define XHCI_TRB_RESET_ENDPOINT
A reset endpoint transfer request block.
#define PCI_COMMAND
PCI command.
#define XHCI_TRANSFER_TRBS_LOG2
Number of TRBs in a transfer ring.
#define XHCI_DATA_IN
Input data direction.
#define XHCI_TRB_PORT_STATUS
A port status change transfer request block.
static __always_inline int iob_map(struct io_buffer *iobuf, struct dma_device *dma, size_t len, int flags)
Map I/O buffer for DMA.
#define XHCI_PORTSC_CSC
Connect status change.
uint8_t direction
Transfer direction.
struct golan_eq_context ctx
A data structure for storing profiling information.
static int xhci_endpoint_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
Enqueue stream transfer.
#define XHCI_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
static void profile_stop(struct profiler *profiler)
Stop profiling.
#define XHCI_COMMAND_ABORT_DELAY_MS
Time to delay after aborting a command.
#define XHCI_OP_PORTLI(port)
Port link info register.
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
uint8_t endpoint
Endpoint ID.
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
uint64_t dequeue
Dequeue pointer.
struct device dev
Generic device.
#define XHCI_TRB_STATUS
A status stage transfer request block.
static struct pci_device_id xhci_ids[]
XHCI PCI device IDs.
unsigned int slots
Number of device slots.
uint32_t add
Add context flags.
uint16_t enabled
Single-entry bitmask of the enabled option value.
uint64_t dequeue
Transfer ring dequeue pointer.
struct xhci_scratchpad scratch
Scratchpad buffer.
#define XHCI_USBLEGSUP_OS
USB legacy support OS owned semaphore.
unsigned int address
Device address, if assigned.
static unsigned int xhci_ring_remaining(struct xhci_trb_ring *ring)
Calculate space remaining in TRB ring.
#define PCI_CLASS_SERIAL_USB_XHCI
xHCI USB controller
uint64_t * array
Scratchpad array.
static int xhci_endpoint_mtu(struct usb_endpoint *ep)
Update MTU.
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
unsigned int speed
Device speed.
uint8_t address
USB address.
#define ECANCELED
Operation canceled.
#define XHCI_TRB_ADDRESS_DEVICE
An address device transfer request block.
#define ENOTSUP
Operation not supported.
uint8_t ports
Number of downstream ports.
#define STARTUP_LATE
Late startup.
void usb_port_changed(struct usb_port *port)
Report port status change.
Dynamic memory allocation.
static int xhci_port_psiv(struct xhci_device *xhci, unsigned int port, unsigned int speed)
Find protocol speed ID value.
#define XHCI_DATA_OUT
Output data direction.
static void xhci_transfer(struct xhci_device *xhci, struct xhci_trb_transfer *trb)
Handle transfer event.
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
unsigned int type
Endpoint type.
struct xhci_trb_host_controller host
Host controller event.
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
uint64_t input
Input context.
#define XHCI_EP_TYPE_IN
Input endpoint type.
static const char * xhci_speed_name(uint32_t psi)
Transcribe port speed (for debugging)
static int xhci_root_enable(struct usb_hub *hub, struct usb_port *port)
Enable port.
#define XHCI_PORTSC_PP
Port power.
A startup/shutdown function.
#define PCI_COMMAND_MASTER
Bus master.
static void xhci_bus_poll(struct usb_bus *bus)
Poll USB bus.
#define XHCI_PORTSC_CCS
Current connect status.
static void xhci_ring_reset(struct xhci_trb_ring *ring)
Reset transfer request block ring.
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
#define ENOMEM
Not enough space.
#define XHCI_COMMAND_MAX_WAIT_MS
Maximum time to wait for a command to complete.
struct usb_device * usb
Underlying USB device, if any.
struct dma_mapping array_map
Array DMA mapping.
static int xhci_enable_slot(struct xhci_device *xhci, unsigned int type)
Enable slot.
uint8_t endpoint
Endpoint ID.
#define XHCI_OP_CRCR
Command ring control register.
union xhci_trb * trb
Transfer request blocks.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define XHCI_TRB_COMPLETE
A command completion event transfer request block.
void xhci_init(struct xhci_device *xhci)
Initialise device.
static int xhci_probe(struct pci_device *pci)
Probe PCI device.
struct xhci_pch pch
Intel PCH quirk.
#define XHCI_CAP_RTSOFF
Runtime register space offset.
A reset endpoint transfer request block.
static int xhci_port_slot_type(struct xhci_device *xhci, unsigned int port)
Find port slot type.
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
struct usb_port * port
USB port.
union xhci_trb * trb
Transfer request blocks.
uint32_t drop
Drop context flags.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_EP_TYPE_PERIODIC
Periodic endpoint type.
static void xhci_device_close(struct usb_device *usb)
Close device.
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
#define XHCI_TRB_DATA
A data stage transfer request block.
struct xhci_trb_stop_endpoint stop
Stop endpoint TRB.
#define XHCI_MTU
Maximum transfer size.
struct xhci_trb_template template
Template.
static void xhci_dump_port(struct xhci_device *xhci, unsigned int port)
Dump port registers.
unsigned int ctx
Context index.
pseudo_bit_t value[0x00020]
#define __unused
Declare a variable or data structure as unused.
struct usb_device * usb
USB device.
static int xhci_device_address(struct usb_device *usb)
Assign device address.
uint32_t xusb2pr
USB2 port routing register original value.
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
#define XHCI_PORTSC_CHANGE
Port status change mask.
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
uint8_t port
Root hub port number.
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
#define XHCI_TRB_TRANSFER
A transfer event transfer request block.
#define XHCI_USBLEGSUP_CTLSTS
USB legacy support control/status.
A setup stage transfer request block.
uint16_t mtu
Maximum packet size.
A transfer event transfer request block.
unsigned int burst
Maximum burst size.
static void xhci_bus_close(struct usb_bus *bus)
Close USB bus.
#define XHCI_PCH
Intel PCH quirk flag.
#define XHCI_TRB_NOP_CMD
A no-op command transfer request block.
#define XHCI_TRB_SETUP
A setup stage transfer request block.
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
static int xhci_root_open(struct usb_hub *hub)
Open root hub.
u32 link
Link to next descriptor.
static unsigned int count
Number of entries.
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
static int xhci_fail(struct xhci_device *xhci)
Mark xHCI device as permanently failed.
#define USB_DIR_IN
Data transfer is from device to host.
static void profile_start(struct profiler *profiler)
Start profiling.
static void xhci_legacy_claim(struct xhci_device *xhci)
Claim ownership from BIOS.
unsigned int ports
Number of ports.
static void xhci_event_free(struct xhci_device *xhci)
Free event ring.
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
uint32_t info
Device info.
struct xhci_slot * slot
xHCI slot
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
struct xhci_endpoint_context * context
Endpoint context.
#define cpu_to_le32(value)
uint8_t id
Request identifier.
uint32_t revision
Entry point revision.
#define XHCI_PORTSC_LWS
Port link state write strobe.
#define XHCI_DCI(ctx)
Device context index.
static int xhci_deconfigure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Deconfigure endpoint.
#define XHCI_OP_DCBAAP
Device context base address array pointer.
A context transfer request block.
#define XHCI_TRB_STOP_ENDPOINT
A stop endpoint transfer request block.
#define XHCI_TRB_HOST_CONTROLLER
A port status change transfer request block.
#define iob_unput(iobuf, len)
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
static int xhci_bus_open(struct usb_bus *bus)
Open USB bus.
char * strerror(int errno)
Retrieve string representation of error number.
static int xhci_enqueue_multi(struct xhci_trb_ring *ring, struct io_buffer *iobuf, const union xhci_trb *trbs, unsigned int count)
Enqueue multiple transfer request blocks.
static void(* free)(struct refcnt *refcnt))
static void xhci_shutdown(int booting)
Prepare for exit.
static int xhci_root_disable(struct usb_hub *hub, struct usb_port *port)
Disable port.
void * zalloc(size_t size)
Allocate cleared memory.
#define XHCI_XECP_ID(xecp)
xHCI extended capability ID
uint16_t cons
Consumer index.
int failed
Command mechanism has permanently failed.
#define PCI_CLASS_SERIAL_USB
A link transfer request block.
A transfer request block.
static void xhci_dcbaa_free(struct xhci_device *xhci)
Free device context base address array.
unsigned int usb_route_string(struct usb_device *usb)
Get USB route string.
void * dma_umalloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer from external (user) memory.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
static void xhci_root_close(struct usb_hub *hub __unused)
Close root hub.
uint32_t addr
Buffer address.
#define XHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
#define XHCI_USBLEGSUP_OS_OWNED
USB legacy support OS ownership flag.
#define XHCI_OP_PORTPMSC(port)
Port power management status and control register.
uint64_t * context
Context base addresses.
#define ENODEV
No such device.
#define XHCI_HCCPARAMS1_XECP(params)
xHCI extended capabilities pointer
static int xhci_scratchpad_alloc(struct xhci_device *xhci)
Allocate scratchpad buffers.
#define XHCI_BAR
xHCI PCI BAR
#define XHCI_HCCPARAMS1_ADDR64(params)
64-bit addressing capability
#define XHCI_CAP_CAPLENGTH
Capability register length.
static void xhci_dump(struct xhci_device *xhci)
Dump host controller registers.
static int xhci_endpoint_open(struct usb_endpoint *ep)
Open endpoint.
static void xhci_remove(struct pci_device *pci)
Remove PCI device.
unsigned int intrs
Number of interrupters.
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
unsigned int prod
Producer counter.
#define XHCI_EP0_TRB_LEN
Control endpoint average TRB length.
struct xhci_trb_complete complete
Command completion event.
struct xhci_trb_set_tr_dequeue_pointer dequeue
Set transfer ring dequeue pointer TRB.
#define XHCI_SUPPORTED_PORTS_COUNT(ports)
Supported protocol port count.
A PCI device ID list entry.
void dma_ufree(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
static int xhci_endpoint_message(struct usb_endpoint *ep, struct io_buffer *iobuf)
Enqueue message transfer.
#define le16_to_cpu(value)
#define XHCI_HCSPARAMS1_SLOTS(params)
Number of device slots.
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
uint32_t next
Next descriptor address.
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
void * cap
Capability registers.
struct usb_port * usb_root_hub_port(struct usb_device *usb)
Get USB root hub port.
unsigned int xecp
xHCI extended capabilities offset
static void xhci_abort(struct xhci_device *xhci)
Abort command.
#define XHCI_OP_PAGESIZE
Page size register.
#define XHCI_RUN_ERSTBA(intr)
Event ring segment table base address register.
#define XHCI_SUPPORTED_REVISION
Supported protocol revision.
A normal transfer request block.
#define XHCI_TRB_IDT
Transfer request block immediate data flag.
#define XHCI_XECP_ID_LEGACY
USB legacy support extended capability.
int addr64
64-bit addressing capability
size_t mtu
Maximum transfer size.
#define XHCI_USBCMD_HCRST
Host controller reset.
A port status change transfer request block.
struct xhci_trb_normal normal
Normal TRB.
struct startup_fn xhci_startup __startup_fn(STARTUP_LATE)
Startup/shutdown function.
static void xhci_configure_endpoint_input(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input)
Populate configure endpoint input context.
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
static void xhci_run(struct xhci_device *xhci)
Start xHCI device.
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
#define XHCI_DBVAL(target, stream)
Calculate doorbell register value.
static struct io_buffer * xhci_dequeue_multi(struct xhci_trb_ring *ring)
Dequeue multiple transfer request blocks.
#define XHCI_PAGESIZE(pagesize)
Page size.
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
#define XHCI_PORTSC_PLS_RXDETECT
RxDetect port link state.
struct xhci_trb_reset_endpoint reset
Reset endpoint TRB.
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
#define XHCI_SUPPORTED_PORTS_OFFSET(ports)
Supported protocol port offset.
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
#define XHCI_OP_CONFIG
Configure register.
USB eXtensible Host Controller Interface (xHCI) driver.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define XHCI_PCH_USB3PSSEN
Intel PCH SuperSpeed enable register.
#define XHCI_OP_PORTSC(port)
Port status and control register.
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
static int xhci_disable_slot(struct xhci_device *xhci, unsigned int slot)
Disable slot.
uint8_t tt_id
TT hub slot ID.
static void xhci_pch_fix(struct xhci_device *xhci, struct pci_device *pci)
Fix Intel PCH-specific quirks.
struct usb_endpoint * ep
USB endpoint.
static __always_inline int struct dma_mapping * map
#define XHCI_CTX(address)
Calculate context index from USB endpoint address.
#define XHCI_STOP_MAX_WAIT_MS
Maximum time to wait for host controller to stop.
#define XHCI_TRB_NORMAL
A normal transfer request block.
#define ENOBUFS
No buffer space available.
size_t pagesize
Page size.
Universal Serial Bus (USB)
#define XHCI_PORT_POWER_DELAY_MS
Time to delay after enabling power to a port.
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
static void xhci_event_poll(struct xhci_device *xhci)
Poll event ring.
#define XHCI_CRCR_RCS
Command ring cycle state.
A stop endpoint transfer request block.
unsigned int mask
Ring counter mask.
static void xhci_scratchpad_free(struct xhci_device *xhci)
Free scratchpad buffers.
#define XHCI_TRB_TYPE_MASK
Transfer request block type mask.
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
uint8_t interval
Polling interval.
uint8_t tt_port
TT port number.
unsigned int address
Port address.
void * data
Start of data.
static void xhci_host_controller(struct xhci_device *xhci, struct xhci_trb_host_controller *trb)
Handle host controller event.
struct usb_hub * hub
USB hub.
struct dma_mapping map
DMA mapping.
struct io_buffer ** iobuf
I/O buffers.
#define XHCI_TRB_EVALUATE_CONTEXT
An evaluate context transfer request block.
static void xhci_complete(struct xhci_device *xhci, struct xhci_trb_complete *trb)
Handle command completion event.
#define XHCI_CAP_DBOFF
Doorbell offset.
struct usb_endpoint * ep[32]
Endpoint list.
static int xhci_port_speed(struct xhci_device *xhci, unsigned int port, unsigned int psiv)
Find port speed.
struct xhci_trb_ring ring
Transfer ring.
unsigned int interval
Interval (in microframes)
struct pci_device_id * id
Driver device ID.
static int xhci_stop_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Stop endpoint.
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
#define XHCI_HCCPARAMS1_CSZ_SHIFT(params)
Context size shift.
#define XHCI_CRCR_CA
Command abort.
struct usb_endpoint_host_operations endpoint
Endpoint operations.
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define XHCI_PCH_USB3PRM
Intel PCH USB3 port routing mask register.
#define cpu_to_le16(value)
static void xhci_pch_undo(struct xhci_device *xhci, struct pci_device *pci)
Undo Intel PCH-specific quirk fixes.
#define XHCI_USBCMD_RUN
Run/stop.
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
void iounmap(volatile const void *io_addr)
Unmap I/O address.
uint8_t data[48]
Additional event data.
#define XHCI_TRB_CH
Transfer request block chain flag.
#define XHCI_CAP_HCSPARAMS1
Structural parameters 1.
USB host controller operations.
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
struct xhci_trb_port_status port
Port status changed event.
struct dma_device * dma
DMA device.
static int xhci_endpoint_reset(struct usb_endpoint *ep)
Reset endpoint.
static int xhci_enqueue(struct xhci_trb_ring *ring, struct io_buffer *iobuf, const union xhci_trb *trb)
Enqueue a transfer request block.
static int xhci_evaluate_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Evaluate context.
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
static unsigned int xhci_port_protocol(struct xhci_device *xhci, unsigned int port)
Find port protocol.
uint16_t residual
Residual transfer length.
#define XHCI_PORTSC_PR
Port reset.
unsigned int legacy
USB legacy support capability (if present and enabled)
struct usb_hub * hub
Root hub.
#define XHCI_CRCR_CRR
Command ring running.
#define XHCI_CONFIG_MAX_SLOTS_EN_MASK
Maximum device slots enabled mask.
#define XHCI_PORTSC_PED
Port enabled.
struct xhci_trb_link * link
Link TRB (if applicable)
#define XHCI_CAP_HCCPARAMS1
Capability parameters.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
unsigned int shift
Ring size (log2)
A transfer request block command/transfer ring.
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
struct usb_device * usb
USB device.
static void xhci_address_device_input(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input)
Populate address device input context.
uint64_t transfer
Transfer TRB pointer.
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
unsigned int csz_shift
Context size shift.
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
struct usb_setup_packet packet
Setup packet.
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)
Supported protocol PSI mantissa.
#define XHCI_MIN_ALIGN
Minimum alignment required for data structures.
uint16_t protocol
Protocol ID.
void * db
Doorbell registers.
#define XHCI_TRB_LINK
A link transfer request block.
unsigned int interval
Endpoint interval.
#define XHCI_SETUP_IN
Setup stage input data direction.
#define XHCI_PORTSC_PLS_DISABLED
Disabled port link state.
static int xhci_reset_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Reset endpoint.
int(* open)(struct usb_endpoint *ep)
Open endpoint.
#define XHCI_SUPPORTED_REVISION_VER(revision)
Supported protocol minor revision.
#define XHCI_OP_USBCMD
USB command register.
uint16_t offset
Offset to command line.
uint8_t endpoint
Endpoint ID.
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
#define XHCI_HCSPARAMS2_SCRATCHPADS(params)
Number of page-sized scratchpad buffers.
#define XHCI_STATUS_OUT
Output status direction.
uint8_t code
Completion code.
uint16_t supported
Bitmask of supported option values.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define XHCI_PCH_XUSB2PRM
Intel PCH USB2 port routing mask register.
#define XHCI_USBSTS_HCH
Host controller halted.
struct usb_bus * bus
USB bus.
#define fls(x)
Find last (i.e.
#define le64_to_cpu(value)
struct xhci_trb_link link
Link TRB.
static void xhci_legacy_init(struct xhci_device *xhci)
Initialise USB legacy support.
struct xhci_slot ** slot
Device slots, indexed by slot ID.
#define XHCI_TRB_C
Transfer request block cycle bit flag.
#define XHCI_CAP_HCSPARAMS2
Structural parameters 2.
static int xhci_event_alloc(struct xhci_device *xhci)
Allocate event ring.
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
unsigned int quirks
Quirks.
#define NULL
NULL pointer (VOID *)
uint64_t parameter
Parameter.
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
struct xhci_device * xhci
xHCI device
#define ETIMEDOUT
Connection timed out.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
struct xhci_event_ring event
Event ring.
static unsigned int xhci_endpoint_count(size_t len, int zlp)
Calculate number of TRBs.
#define XHCI_LINK_STATE_DELAY_MS
Time to delay after writing the port link state.
unsigned int attributes
Attributes.
static int xhci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
#define XHCI_OP_DNCTRL
Device notifcation control register.
void writeq(uint64_t data, volatile uint64_t *io_addr)
Write 64-bit qword to memory-mapped device.
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
void * op
Operational registers.
unsigned int address
Endpoint address.
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
static int xhci_nop(struct xhci_device *xhci)
Issue NOP and wait for completion.
void xhci_unregister(struct xhci_device *xhci)
Unregister xHCI controller.
#define XHCI_CTX_EP0
Endpoint zero context index.
#define XHCI_PORTSC_PLS_MASK
Port link state mask.
uint8_t endpoint
Endpoint ID.
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
static int xhci_hub_open(struct usb_hub *hub)
Open hub.
static void xhci_port_status(struct xhci_device *xhci, struct xhci_trb_port_status *trb)
Handle port status event.
static int xhci_ring_alloc(struct xhci_device *xhci, struct xhci_trb_ring *ring, unsigned int shift, unsigned int slot, unsigned int target, unsigned int stream)
Allocate transfer request block ring.
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
#define XHCI_ENDPOINT_STATE_MASK
Endpoint state mask.
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
#define XHCI_CMD_TRBS_LOG2
Number of TRBs (excluding Link TRB) in the command ring.
static struct usb_host_operations xhci_operations
USB host controller operations.
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
static void xhci_legacy_release(struct xhci_device *xhci)
Release ownership back to BIOS.
static int xhci_dcbaa_alloc(struct xhci_device *xhci)
Allocate device context base address array.
#define XHCI_SUPPORTED_NAME
Supported protocol name.
void * memset(void *dest, int character, size_t len) __nonnull
#define XHCI_CTX_SLOT
Slot context index.
static void xhci_endpoint_close(struct usb_endpoint *ep)
Close endpoint.