iPXE
xhci.c File Reference

USB eXtensible Host Controller Interface (xHCI) driver. More...

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/usb.h>
#include <ipxe/init.h>
#include <ipxe/profile.h>
#include <ipxe/xhci.h>

Go to the source code of this file.

Macros

#define EIO_DATA   __einfo_error ( EINFO_EIO_DATA )
#define EINFO_EIO_DATA
#define EIO_BABBLE   __einfo_error ( EINFO_EIO_BABBLE )
#define EINFO_EIO_BABBLE
#define EIO_USB   __einfo_error ( EINFO_EIO_USB )
#define EINFO_EIO_USB
#define EIO_TRB   __einfo_error ( EINFO_EIO_TRB )
#define EINFO_EIO_TRB
#define EIO_STALL   __einfo_error ( EINFO_EIO_STALL )
#define EINFO_EIO_STALL
#define EIO_RESOURCE   __einfo_error ( EINFO_EIO_RESOURCE )
#define EINFO_EIO_RESOURCE
#define EIO_BANDWIDTH   __einfo_error ( EINFO_EIO_BANDWIDTH )
#define EINFO_EIO_BANDWIDTH
#define EIO_NO_SLOTS   __einfo_error ( EINFO_EIO_NO_SLOTS )
#define EINFO_EIO_NO_SLOTS
#define EIO_STREAM_TYPE   __einfo_error ( EINFO_EIO_STREAM_TYPE )
#define EINFO_EIO_STREAM_TYPE
#define EIO_SLOT   __einfo_error ( EINFO_EIO_SLOT )
#define EINFO_EIO_SLOT
#define EIO_ENDPOINT   __einfo_error ( EINFO_EIO_ENDPOINT )
#define EINFO_EIO_ENDPOINT
#define EIO_SHORT   __einfo_error ( EINFO_EIO_SHORT )
#define EINFO_EIO_SHORT
#define EIO_UNDERRUN   __einfo_error ( EINFO_EIO_UNDERRUN )
#define EINFO_EIO_UNDERRUN
#define EIO_OVERRUN   __einfo_error ( EINFO_EIO_OVERRUN )
#define EINFO_EIO_OVERRUN
#define EIO_VF_RING_FULL   __einfo_error ( EINFO_EIO_VF_RING_FULL )
#define EINFO_EIO_VF_RING_FULL
#define EIO_PARAMETER   __einfo_error ( EINFO_EIO_PARAMETER )
#define EINFO_EIO_PARAMETER
#define EIO_BANDWIDTH_OVERRUN   __einfo_error ( EINFO_EIO_BANDWIDTH_OVERRUN )
#define EINFO_EIO_BANDWIDTH_OVERRUN
#define EIO_CONTEXT   __einfo_error ( EINFO_EIO_CONTEXT )
#define EINFO_EIO_CONTEXT
#define EIO_NO_PING   __einfo_error ( EINFO_EIO_NO_PING )
#define EINFO_EIO_NO_PING
#define EIO_RING_FULL   __einfo_error ( EINFO_EIO_RING_FULL )
#define EINFO_EIO_RING_FULL
#define EIO_INCOMPATIBLE   __einfo_error ( EINFO_EIO_INCOMPATIBLE )
#define EINFO_EIO_INCOMPATIBLE
#define EIO_MISSED   __einfo_error ( EINFO_EIO_MISSED )
#define EINFO_EIO_MISSED
#define EIO_CMD_STOPPED   __einfo_error ( EINFO_EIO_CMD_STOPPED )
#define EINFO_EIO_CMD_STOPPED
#define EIO_CMD_ABORTED   __einfo_error ( EINFO_EIO_CMD_ABORTED )
#define EINFO_EIO_CMD_ABORTED
#define EIO_STOP   __einfo_error ( EINFO_EIO_STOP )
#define EINFO_EIO_STOP
#define EIO_STOP_LEN   __einfo_error ( EINFO_EIO_STOP_LEN )
#define EINFO_EIO_STOP_LEN
#define EIO_STOP_SHORT   __einfo_error ( EINFO_EIO_STOP_SHORT )
#define EINFO_EIO_STOP_SHORT
#define EIO_LATENCY   __einfo_error ( EINFO_EIO_LATENCY )
#define EINFO_EIO_LATENCY
#define EIO_ISOCH   __einfo_error ( EINFO_EIO_ISOCH )
#define EINFO_EIO_ISOCH
#define EPROTO_LOST   __einfo_error ( EINFO_EPROTO_LOST )
#define EINFO_EPROTO_LOST
#define EPROTO_UNDEFINED   __einfo_error ( EINFO_EPROTO_UNDEFINED )
#define EINFO_EPROTO_UNDEFINED
#define EPROTO_STREAM_ID   __einfo_error ( EINFO_EPROTO_STREAM_ID )
#define EINFO_EPROTO_STREAM_ID
#define EPROTO_SECONDARY   __einfo_error ( EINFO_EPROTO_SECONDARY )
#define EINFO_EPROTO_SECONDARY
#define EPROTO_SPLIT   __einfo_error ( EINFO_EPROTO_SPLIT )
#define EINFO_EPROTO_SPLIT
#define ECODE(code)

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
void xhci_init (struct xhci_device *xhci)
 Initialise device.
static unsigned int xhci_extended_capability (struct xhci_device *xhci, unsigned int id, unsigned int offset)
 Find extended capability.
static int xhci_writeq (struct xhci_device *xhci, physaddr_t value, void *reg)
 Write potentially 64-bit register.
static size_t xhci_align (size_t len)
 Calculate buffer alignment.
static size_t xhci_device_context_offset (struct xhci_device *xhci, unsigned int ctx)
 Calculate device context offset.
static size_t xhci_input_context_offset (struct xhci_device *xhci, unsigned int ctx)
 Calculate input context offset.
static void xhci_dump (struct xhci_device *xhci)
 Dump host controller registers.
static void xhci_dump_port (struct xhci_device *xhci, unsigned int port)
 Dump port registers.
static void xhci_legacy_init (struct xhci_device *xhci)
 Initialise USB legacy support.
static void xhci_legacy_claim (struct xhci_device *xhci)
 Claim ownership from BIOS.
static void xhci_legacy_release (struct xhci_device *xhci)
 Release ownership back to BIOS.
static const char * xhci_speed_name (uint32_t psi)
 Transcribe port speed (for debugging).
static unsigned int xhci_supported_protocol (struct xhci_device *xhci, unsigned int port)
 Find supported protocol extended capability for a port.
static unsigned int xhci_port_protocol (struct xhci_device *xhci, unsigned int port)
 Find port protocol.
static int xhci_port_slot_type (struct xhci_device *xhci, unsigned int port)
 Find port slot type.
static int xhci_port_speed (struct xhci_device *xhci, unsigned int port, unsigned int psiv)
 Find port speed.
static int xhci_port_psiv (struct xhci_device *xhci, unsigned int port, unsigned int speed)
 Find protocol speed ID value.
static int xhci_dcbaa_alloc (struct xhci_device *xhci)
 Allocate device context base address array.
static void xhci_dcbaa_free (struct xhci_device *xhci)
 Free device context base address array.
static int xhci_scratchpad_alloc (struct xhci_device *xhci)
 Allocate scratchpad buffers.
static void xhci_scratchpad_free (struct xhci_device *xhci)
 Free scratchpad buffers.
static void xhci_run (struct xhci_device *xhci)
 Start xHCI device.
static int xhci_stop (struct xhci_device *xhci)
 Stop xHCI device.
static int xhci_reset (struct xhci_device *xhci)
 Reset xHCI device.
static int xhci_fail (struct xhci_device *xhci)
 Mark xHCI device as permanently failed.
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.
static void xhci_ring_reset (struct xhci_trb_ring *ring)
 Reset transfer request block ring.
static void xhci_ring_free (struct xhci_trb_ring *ring)
 Free transfer request block ring.
static int xhci_enqueue (struct xhci_trb_ring *ring, struct io_buffer *iobuf, const union xhci_trb *trb)
 Enqueue a transfer request block.
static struct io_bufferxhci_dequeue (struct xhci_trb_ring *ring)
 Dequeue a transfer request block.
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 struct io_bufferxhci_dequeue_multi (struct xhci_trb_ring *ring)
 Dequeue multiple transfer request blocks.
static void xhci_doorbell (struct xhci_trb_ring *ring)
 Ring doorbell register.
static int xhci_command_alloc (struct xhci_device *xhci)
 Allocate command ring.
static void xhci_command_free (struct xhci_device *xhci)
 Free command ring.
static int xhci_event_alloc (struct xhci_device *xhci)
 Allocate event ring.
static void xhci_event_free (struct xhci_device *xhci)
 Free event ring.
static void xhci_transfer (struct xhci_device *xhci, struct xhci_trb_transfer *trb)
 Handle transfer event.
static void xhci_complete (struct xhci_device *xhci, struct xhci_trb_complete *trb)
 Handle command completion event.
static void xhci_port_status (struct xhci_device *xhci, struct xhci_trb_port_status *trb)
 Handle port status event.
static void xhci_host_controller (struct xhci_device *xhci, struct xhci_trb_host_controller *trb)
 Handle host controller event.
static void xhci_event_poll (struct xhci_device *xhci)
 Poll event ring.
static void xhci_abort (struct xhci_device *xhci)
 Abort command.
static int xhci_command (struct xhci_device *xhci, union xhci_trb *trb)
 Issue command and wait for completion.
static int xhci_nop (struct xhci_device *xhci)
 Issue NOP and wait for completion.
static int xhci_enable_slot (struct xhci_device *xhci, unsigned int type)
 Enable slot.
static int xhci_disable_slot (struct xhci_device *xhci, unsigned int slot)
 Disable slot.
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.
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.
static int xhci_address_device (struct xhci_device *xhci, struct xhci_slot *slot)
 Address device.
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_configure_endpoint (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Configure endpoint.
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.
static int xhci_deconfigure_endpoint (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Deconfigure endpoint.
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 int xhci_evaluate_context (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Evaluate context.
static int xhci_reset_endpoint (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Reset endpoint.
static int xhci_stop_endpoint (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Stop endpoint.
static int xhci_set_tr_dequeue_pointer (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Set transfer ring dequeue pointer.
static int xhci_endpoint_open (struct usb_endpoint *ep)
 Open endpoint.
static void xhci_endpoint_close (struct usb_endpoint *ep)
 Close endpoint.
static int xhci_endpoint_reset (struct usb_endpoint *ep)
 Reset endpoint.
static int xhci_endpoint_mtu (struct usb_endpoint *ep)
 Update MTU.
static int xhci_endpoint_message (struct usb_endpoint *ep, struct io_buffer *iobuf)
 Enqueue message transfer.
static unsigned int xhci_endpoint_count (size_t len, int zlp)
 Calculate number of TRBs.
static int xhci_endpoint_stream (struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
 Enqueue stream transfer.
static int xhci_device_open (struct usb_device *usb)
 Open device.
static void xhci_device_close (struct usb_device *usb)
 Close device.
static int xhci_device_address (struct usb_device *usb)
 Assign device address.
static int xhci_bus_open (struct usb_bus *bus)
 Open USB bus.
static void xhci_bus_close (struct usb_bus *bus)
 Close USB bus.
static void xhci_bus_poll (struct usb_bus *bus)
 Poll USB bus.
static int xhci_hub_open (struct usb_hub *hub)
 Open hub.
static void xhci_hub_close (struct usb_hub *hub __unused)
 Close hub.
static int xhci_root_open (struct usb_hub *hub)
 Open root hub.
static void xhci_root_close (struct usb_hub *hub __unused)
 Close root hub.
static int xhci_root_enable (struct usb_hub *hub, struct usb_port *port)
 Enable port.
static int xhci_root_disable (struct usb_hub *hub, struct usb_port *port)
 Disable port.
static int xhci_root_speed (struct usb_hub *hub, struct usb_port *port)
 Update root hub port speed.
static int xhci_root_clear_tt (struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
 Clear transaction translator buffer.
int xhci_register (struct xhci_device *xhci)
 Register xHCI controller.
void xhci_unregister (struct xhci_device *xhci)
 Unregister xHCI controller.
static void xhci_pch_fix (struct xhci_device *xhci, struct pci_device *pci)
 Fix Intel PCH-specific quirks.
static void xhci_pch_undo (struct xhci_device *xhci, struct pci_device *pci)
 Undo Intel PCH-specific quirk fixes.
static int xhci_probe (struct pci_device *pci)
 Probe PCI device.
static void xhci_remove (struct pci_device *pci)
 Remove PCI device.
static void xhci_shutdown (int booting)
 Prepare for exit.
struct startup_fn xhci_startup __startup_fn (STARTUP_LATE)
 Startup/shutdown function.

Variables

static struct profiler xhci_message_profiler __profiler
 Message transfer profiler.
static int xhci_legacy_prevent_release
 Prevent the release of ownership back to BIOS.
static struct usb_host_operations xhci_operations
 USB host controller operations.
static struct pci_device_id xhci_ids []
 XHCI PCI device IDs.
struct pci_driver xhci_driver __pci_driver
 XHCI PCI driver.

Detailed Description

USB eXtensible Host Controller Interface (xHCI) driver.

Definition in file xhci.c.

Macro Definition Documentation

◆ EIO_DATA

#define EIO_DATA   __einfo_error ( EINFO_EIO_DATA )

Definition at line 64 of file xhci.c.

64#define EIO_DATA \
65 __einfo_error ( EINFO_EIO_DATA )

◆ EINFO_EIO_DATA

#define EINFO_EIO_DATA
Value:
__einfo_uniqify ( EINFO_EIO, ( 2 - 0 ), \
"Data buffer error" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition errno.h:224
#define EINFO_EIO
Definition errno.h:478

Definition at line 66 of file xhci.c.

66#define EINFO_EIO_DATA \
67 __einfo_uniqify ( EINFO_EIO, ( 2 - 0 ), \
68 "Data buffer error" )

◆ EIO_BABBLE

#define EIO_BABBLE   __einfo_error ( EINFO_EIO_BABBLE )

Definition at line 69 of file xhci.c.

69#define EIO_BABBLE \
70 __einfo_error ( EINFO_EIO_BABBLE )

◆ EINFO_EIO_BABBLE

#define EINFO_EIO_BABBLE
Value:
__einfo_uniqify ( EINFO_EIO, ( 3 - 0 ), \
"Babble detected" )

Definition at line 71 of file xhci.c.

71#define EINFO_EIO_BABBLE \
72 __einfo_uniqify ( EINFO_EIO, ( 3 - 0 ), \
73 "Babble detected" )

◆ EIO_USB

#define EIO_USB   __einfo_error ( EINFO_EIO_USB )

Definition at line 74 of file xhci.c.

74#define EIO_USB \
75 __einfo_error ( EINFO_EIO_USB )

◆ EINFO_EIO_USB

#define EINFO_EIO_USB
Value:
__einfo_uniqify ( EINFO_EIO, ( 4 - 0 ), \
"USB transaction error" )

Definition at line 76 of file xhci.c.

76#define EINFO_EIO_USB \
77 __einfo_uniqify ( EINFO_EIO, ( 4 - 0 ), \
78 "USB transaction error" )

◆ EIO_TRB

#define EIO_TRB   __einfo_error ( EINFO_EIO_TRB )

Definition at line 79 of file xhci.c.

79#define EIO_TRB \
80 __einfo_error ( EINFO_EIO_TRB )

◆ EINFO_EIO_TRB

#define EINFO_EIO_TRB
Value:
__einfo_uniqify ( EINFO_EIO, ( 5 - 0 ), \
"TRB error" )

Definition at line 81 of file xhci.c.

81#define EINFO_EIO_TRB \
82 __einfo_uniqify ( EINFO_EIO, ( 5 - 0 ), \
83 "TRB error" )

◆ EIO_STALL

#define EIO_STALL   __einfo_error ( EINFO_EIO_STALL )

Definition at line 84 of file xhci.c.

84#define EIO_STALL \
85 __einfo_error ( EINFO_EIO_STALL )

◆ EINFO_EIO_STALL

#define EINFO_EIO_STALL
Value:
__einfo_uniqify ( EINFO_EIO, ( 6 - 0 ), \
"Stall error" )

Definition at line 86 of file xhci.c.

86#define EINFO_EIO_STALL \
87 __einfo_uniqify ( EINFO_EIO, ( 6 - 0 ), \
88 "Stall error" )

◆ EIO_RESOURCE

#define EIO_RESOURCE   __einfo_error ( EINFO_EIO_RESOURCE )

Definition at line 89 of file xhci.c.

89#define EIO_RESOURCE \
90 __einfo_error ( EINFO_EIO_RESOURCE )

◆ EINFO_EIO_RESOURCE

#define EINFO_EIO_RESOURCE
Value:
__einfo_uniqify ( EINFO_EIO, ( 7 - 0 ), \
"Resource error" )

Definition at line 91 of file xhci.c.

91#define EINFO_EIO_RESOURCE \
92 __einfo_uniqify ( EINFO_EIO, ( 7 - 0 ), \
93 "Resource error" )

◆ EIO_BANDWIDTH

#define EIO_BANDWIDTH   __einfo_error ( EINFO_EIO_BANDWIDTH )

Definition at line 94 of file xhci.c.

94#define EIO_BANDWIDTH \
95 __einfo_error ( EINFO_EIO_BANDWIDTH )

◆ EINFO_EIO_BANDWIDTH

#define EINFO_EIO_BANDWIDTH
Value:
__einfo_uniqify ( EINFO_EIO, ( 8 - 0 ), \
"Bandwidth error" )

Definition at line 96 of file xhci.c.

96#define EINFO_EIO_BANDWIDTH \
97 __einfo_uniqify ( EINFO_EIO, ( 8 - 0 ), \
98 "Bandwidth error" )

◆ EIO_NO_SLOTS

#define EIO_NO_SLOTS   __einfo_error ( EINFO_EIO_NO_SLOTS )

Definition at line 99 of file xhci.c.

99#define EIO_NO_SLOTS \
100 __einfo_error ( EINFO_EIO_NO_SLOTS )

◆ EINFO_EIO_NO_SLOTS

#define EINFO_EIO_NO_SLOTS
Value:
__einfo_uniqify ( EINFO_EIO, ( 9 - 0 ), \
"No slots available" )

Definition at line 101 of file xhci.c.

101#define EINFO_EIO_NO_SLOTS \
102 __einfo_uniqify ( EINFO_EIO, ( 9 - 0 ), \
103 "No slots available" )

◆ EIO_STREAM_TYPE

#define EIO_STREAM_TYPE   __einfo_error ( EINFO_EIO_STREAM_TYPE )

Definition at line 104 of file xhci.c.

104#define EIO_STREAM_TYPE \
105 __einfo_error ( EINFO_EIO_STREAM_TYPE )

◆ EINFO_EIO_STREAM_TYPE

#define EINFO_EIO_STREAM_TYPE
Value:
__einfo_uniqify ( EINFO_EIO, ( 10 - 0 ), \
"Invalid stream type" )

Definition at line 106 of file xhci.c.

106#define EINFO_EIO_STREAM_TYPE \
107 __einfo_uniqify ( EINFO_EIO, ( 10 - 0 ), \
108 "Invalid stream type" )

◆ EIO_SLOT

#define EIO_SLOT   __einfo_error ( EINFO_EIO_SLOT )

Definition at line 109 of file xhci.c.

109#define EIO_SLOT \
110 __einfo_error ( EINFO_EIO_SLOT )

◆ EINFO_EIO_SLOT

#define EINFO_EIO_SLOT
Value:
__einfo_uniqify ( EINFO_EIO, ( 11 - 0 ), \
"Slot not enabled" )

Definition at line 111 of file xhci.c.

111#define EINFO_EIO_SLOT \
112 __einfo_uniqify ( EINFO_EIO, ( 11 - 0 ), \
113 "Slot not enabled" )

◆ EIO_ENDPOINT

#define EIO_ENDPOINT   __einfo_error ( EINFO_EIO_ENDPOINT )

Definition at line 114 of file xhci.c.

114#define EIO_ENDPOINT \
115 __einfo_error ( EINFO_EIO_ENDPOINT )

◆ EINFO_EIO_ENDPOINT

#define EINFO_EIO_ENDPOINT
Value:
__einfo_uniqify ( EINFO_EIO, ( 12 - 0 ), \
"Endpoint not enabled" )

Definition at line 116 of file xhci.c.

116#define EINFO_EIO_ENDPOINT \
117 __einfo_uniqify ( EINFO_EIO, ( 12 - 0 ), \
118 "Endpoint not enabled" )

◆ EIO_SHORT

#define EIO_SHORT   __einfo_error ( EINFO_EIO_SHORT )

Definition at line 119 of file xhci.c.

119#define EIO_SHORT \
120 __einfo_error ( EINFO_EIO_SHORT )

◆ EINFO_EIO_SHORT

#define EINFO_EIO_SHORT
Value:
__einfo_uniqify ( EINFO_EIO, ( 13 - 0 ), \
"Short packet" )

Definition at line 121 of file xhci.c.

121#define EINFO_EIO_SHORT \
122 __einfo_uniqify ( EINFO_EIO, ( 13 - 0 ), \
123 "Short packet" )

◆ EIO_UNDERRUN

#define EIO_UNDERRUN   __einfo_error ( EINFO_EIO_UNDERRUN )

Definition at line 124 of file xhci.c.

124#define EIO_UNDERRUN \
125 __einfo_error ( EINFO_EIO_UNDERRUN )

◆ EINFO_EIO_UNDERRUN

#define EINFO_EIO_UNDERRUN
Value:
__einfo_uniqify ( EINFO_EIO, ( 14 - 0 ), \
"Ring underrun" )

Definition at line 126 of file xhci.c.

126#define EINFO_EIO_UNDERRUN \
127 __einfo_uniqify ( EINFO_EIO, ( 14 - 0 ), \
128 "Ring underrun" )

◆ EIO_OVERRUN

#define EIO_OVERRUN   __einfo_error ( EINFO_EIO_OVERRUN )

Definition at line 129 of file xhci.c.

129#define EIO_OVERRUN \
130 __einfo_error ( EINFO_EIO_OVERRUN )

◆ EINFO_EIO_OVERRUN

#define EINFO_EIO_OVERRUN
Value:
__einfo_uniqify ( EINFO_EIO, ( 15 - 0 ), \
"Ring overrun" )

Definition at line 131 of file xhci.c.

131#define EINFO_EIO_OVERRUN \
132 __einfo_uniqify ( EINFO_EIO, ( 15 - 0 ), \
133 "Ring overrun" )

◆ EIO_VF_RING_FULL

#define EIO_VF_RING_FULL   __einfo_error ( EINFO_EIO_VF_RING_FULL )

Definition at line 134 of file xhci.c.

134#define EIO_VF_RING_FULL \
135 __einfo_error ( EINFO_EIO_VF_RING_FULL )

◆ EINFO_EIO_VF_RING_FULL

#define EINFO_EIO_VF_RING_FULL
Value:
__einfo_uniqify ( EINFO_EIO, ( 16 - 0 ), \
"Virtual function event ring full" )

Definition at line 136 of file xhci.c.

136#define EINFO_EIO_VF_RING_FULL \
137 __einfo_uniqify ( EINFO_EIO, ( 16 - 0 ), \
138 "Virtual function event ring full" )

◆ EIO_PARAMETER

#define EIO_PARAMETER   __einfo_error ( EINFO_EIO_PARAMETER )

Definition at line 139 of file xhci.c.

139#define EIO_PARAMETER \
140 __einfo_error ( EINFO_EIO_PARAMETER )

◆ EINFO_EIO_PARAMETER

#define EINFO_EIO_PARAMETER
Value:
__einfo_uniqify ( EINFO_EIO, ( 17 - 0 ), \
"Parameter error" )

Definition at line 141 of file xhci.c.

141#define EINFO_EIO_PARAMETER \
142 __einfo_uniqify ( EINFO_EIO, ( 17 - 0 ), \
143 "Parameter error" )

◆ EIO_BANDWIDTH_OVERRUN

#define EIO_BANDWIDTH_OVERRUN   __einfo_error ( EINFO_EIO_BANDWIDTH_OVERRUN )

Definition at line 144 of file xhci.c.

144#define EIO_BANDWIDTH_OVERRUN \
145 __einfo_error ( EINFO_EIO_BANDWIDTH_OVERRUN )

◆ EINFO_EIO_BANDWIDTH_OVERRUN

#define EINFO_EIO_BANDWIDTH_OVERRUN
Value:
__einfo_uniqify ( EINFO_EIO, ( 18 - 0 ), \
"Bandwidth overrun" )

Definition at line 146 of file xhci.c.

146#define EINFO_EIO_BANDWIDTH_OVERRUN \
147 __einfo_uniqify ( EINFO_EIO, ( 18 - 0 ), \
148 "Bandwidth overrun" )

◆ EIO_CONTEXT

#define EIO_CONTEXT   __einfo_error ( EINFO_EIO_CONTEXT )

Definition at line 149 of file xhci.c.

149#define EIO_CONTEXT \
150 __einfo_error ( EINFO_EIO_CONTEXT )

◆ EINFO_EIO_CONTEXT

#define EINFO_EIO_CONTEXT
Value:
__einfo_uniqify ( EINFO_EIO, ( 19 - 0 ), \
"Context state error" )

Definition at line 151 of file xhci.c.

151#define EINFO_EIO_CONTEXT \
152 __einfo_uniqify ( EINFO_EIO, ( 19 - 0 ), \
153 "Context state error" )

◆ EIO_NO_PING

#define EIO_NO_PING   __einfo_error ( EINFO_EIO_NO_PING )

Definition at line 154 of file xhci.c.

154#define EIO_NO_PING \
155 __einfo_error ( EINFO_EIO_NO_PING )

◆ EINFO_EIO_NO_PING

#define EINFO_EIO_NO_PING
Value:
__einfo_uniqify ( EINFO_EIO, ( 20 - 0 ), \
"No ping response" )

Definition at line 156 of file xhci.c.

156#define EINFO_EIO_NO_PING \
157 __einfo_uniqify ( EINFO_EIO, ( 20 - 0 ), \
158 "No ping response" )

◆ EIO_RING_FULL

#define EIO_RING_FULL   __einfo_error ( EINFO_EIO_RING_FULL )

Definition at line 159 of file xhci.c.

159#define EIO_RING_FULL \
160 __einfo_error ( EINFO_EIO_RING_FULL )

◆ EINFO_EIO_RING_FULL

#define EINFO_EIO_RING_FULL
Value:
__einfo_uniqify ( EINFO_EIO, ( 21 - 0 ), \
"Event ring full" )

Definition at line 161 of file xhci.c.

161#define EINFO_EIO_RING_FULL \
162 __einfo_uniqify ( EINFO_EIO, ( 21 - 0 ), \
163 "Event ring full" )

◆ EIO_INCOMPATIBLE

#define EIO_INCOMPATIBLE   __einfo_error ( EINFO_EIO_INCOMPATIBLE )

Definition at line 164 of file xhci.c.

164#define EIO_INCOMPATIBLE \
165 __einfo_error ( EINFO_EIO_INCOMPATIBLE )

◆ EINFO_EIO_INCOMPATIBLE

#define EINFO_EIO_INCOMPATIBLE
Value:
__einfo_uniqify ( EINFO_EIO, ( 22 - 0 ), \
"Incompatible device" )

Definition at line 166 of file xhci.c.

166#define EINFO_EIO_INCOMPATIBLE \
167 __einfo_uniqify ( EINFO_EIO, ( 22 - 0 ), \
168 "Incompatible device" )

◆ EIO_MISSED

#define EIO_MISSED   __einfo_error ( EINFO_EIO_MISSED )

Definition at line 169 of file xhci.c.

169#define EIO_MISSED \
170 __einfo_error ( EINFO_EIO_MISSED )

◆ EINFO_EIO_MISSED

#define EINFO_EIO_MISSED
Value:
__einfo_uniqify ( EINFO_EIO, ( 23 - 0 ), \
"Missed service error" )

Definition at line 171 of file xhci.c.

171#define EINFO_EIO_MISSED \
172 __einfo_uniqify ( EINFO_EIO, ( 23 - 0 ), \
173 "Missed service error" )

◆ EIO_CMD_STOPPED

#define EIO_CMD_STOPPED   __einfo_error ( EINFO_EIO_CMD_STOPPED )

Definition at line 174 of file xhci.c.

174#define EIO_CMD_STOPPED \
175 __einfo_error ( EINFO_EIO_CMD_STOPPED )

◆ EINFO_EIO_CMD_STOPPED

#define EINFO_EIO_CMD_STOPPED
Value:
__einfo_uniqify ( EINFO_EIO, ( 24 - 0 ), \
"Command ring stopped" )

Definition at line 176 of file xhci.c.

176#define EINFO_EIO_CMD_STOPPED \
177 __einfo_uniqify ( EINFO_EIO, ( 24 - 0 ), \
178 "Command ring stopped" )

◆ EIO_CMD_ABORTED

#define EIO_CMD_ABORTED   __einfo_error ( EINFO_EIO_CMD_ABORTED )

Definition at line 179 of file xhci.c.

179#define EIO_CMD_ABORTED \
180 __einfo_error ( EINFO_EIO_CMD_ABORTED )

◆ EINFO_EIO_CMD_ABORTED

#define EINFO_EIO_CMD_ABORTED
Value:
__einfo_uniqify ( EINFO_EIO, ( 25 - 0 ), \
"Command aborted" )

Definition at line 181 of file xhci.c.

181#define EINFO_EIO_CMD_ABORTED \
182 __einfo_uniqify ( EINFO_EIO, ( 25 - 0 ), \
183 "Command aborted" )

◆ EIO_STOP

#define EIO_STOP   __einfo_error ( EINFO_EIO_STOP )

Definition at line 184 of file xhci.c.

184#define EIO_STOP \
185 __einfo_error ( EINFO_EIO_STOP )

◆ EINFO_EIO_STOP

#define EINFO_EIO_STOP
Value:
__einfo_uniqify ( EINFO_EIO, ( 26 - 0 ), \
"Stopped" )

Definition at line 186 of file xhci.c.

186#define EINFO_EIO_STOP \
187 __einfo_uniqify ( EINFO_EIO, ( 26 - 0 ), \
188 "Stopped" )

◆ EIO_STOP_LEN

#define EIO_STOP_LEN   __einfo_error ( EINFO_EIO_STOP_LEN )

Definition at line 189 of file xhci.c.

189#define EIO_STOP_LEN \
190 __einfo_error ( EINFO_EIO_STOP_LEN )

◆ EINFO_EIO_STOP_LEN

#define EINFO_EIO_STOP_LEN
Value:
__einfo_uniqify ( EINFO_EIO, ( 27 - 0 ), \
"Stopped - length invalid" )

Definition at line 191 of file xhci.c.

191#define EINFO_EIO_STOP_LEN \
192 __einfo_uniqify ( EINFO_EIO, ( 27 - 0 ), \
193 "Stopped - length invalid" )

◆ EIO_STOP_SHORT

#define EIO_STOP_SHORT   __einfo_error ( EINFO_EIO_STOP_SHORT )

Definition at line 194 of file xhci.c.

194#define EIO_STOP_SHORT \
195 __einfo_error ( EINFO_EIO_STOP_SHORT )

◆ EINFO_EIO_STOP_SHORT

#define EINFO_EIO_STOP_SHORT
Value:
__einfo_uniqify ( EINFO_EIO, ( 28 - 0 ), \
"Stopped - short packet" )

Definition at line 196 of file xhci.c.

196#define EINFO_EIO_STOP_SHORT \
197 __einfo_uniqify ( EINFO_EIO, ( 28 - 0 ), \
198 "Stopped - short packet" )

◆ EIO_LATENCY

#define EIO_LATENCY   __einfo_error ( EINFO_EIO_LATENCY )

Definition at line 199 of file xhci.c.

199#define EIO_LATENCY \
200 __einfo_error ( EINFO_EIO_LATENCY )

◆ EINFO_EIO_LATENCY

#define EINFO_EIO_LATENCY
Value:
__einfo_uniqify ( EINFO_EIO, ( 29 - 0 ), \
"Maximum exit latency too large" )

Definition at line 201 of file xhci.c.

201#define EINFO_EIO_LATENCY \
202 __einfo_uniqify ( EINFO_EIO, ( 29 - 0 ), \
203 "Maximum exit latency too large" )

◆ EIO_ISOCH

#define EIO_ISOCH   __einfo_error ( EINFO_EIO_ISOCH )

Definition at line 204 of file xhci.c.

204#define EIO_ISOCH \
205 __einfo_error ( EINFO_EIO_ISOCH )

◆ EINFO_EIO_ISOCH

#define EINFO_EIO_ISOCH
Value:
__einfo_uniqify ( EINFO_EIO, ( 31 - 0 ), \
"Isochronous buffer overrun" )

Definition at line 206 of file xhci.c.

206#define EINFO_EIO_ISOCH \
207 __einfo_uniqify ( EINFO_EIO, ( 31 - 0 ), \
208 "Isochronous buffer overrun" )

◆ EPROTO_LOST

#define EPROTO_LOST   __einfo_error ( EINFO_EPROTO_LOST )

Definition at line 209 of file xhci.c.

209#define EPROTO_LOST \
210 __einfo_error ( EINFO_EPROTO_LOST )

◆ EINFO_EPROTO_LOST

#define EINFO_EPROTO_LOST
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 32 - 32 ), \
"Event lost" )
#define EINFO_EPROTO
Definition errno.h:669

Definition at line 211 of file xhci.c.

211#define EINFO_EPROTO_LOST \
212 __einfo_uniqify ( EINFO_EPROTO, ( 32 - 32 ), \
213 "Event lost" )

◆ EPROTO_UNDEFINED

#define EPROTO_UNDEFINED   __einfo_error ( EINFO_EPROTO_UNDEFINED )

Definition at line 214 of file xhci.c.

214#define EPROTO_UNDEFINED \
215 __einfo_error ( EINFO_EPROTO_UNDEFINED )

◆ EINFO_EPROTO_UNDEFINED

#define EINFO_EPROTO_UNDEFINED
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 33 - 32 ), \
"Undefined error" )

Definition at line 216 of file xhci.c.

216#define EINFO_EPROTO_UNDEFINED \
217 __einfo_uniqify ( EINFO_EPROTO, ( 33 - 32 ), \
218 "Undefined error" )

◆ EPROTO_STREAM_ID

#define EPROTO_STREAM_ID   __einfo_error ( EINFO_EPROTO_STREAM_ID )

Definition at line 219 of file xhci.c.

219#define EPROTO_STREAM_ID \
220 __einfo_error ( EINFO_EPROTO_STREAM_ID )

◆ EINFO_EPROTO_STREAM_ID

#define EINFO_EPROTO_STREAM_ID
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 34 - 32 ), \
"Invalid stream ID" )

Definition at line 221 of file xhci.c.

221#define EINFO_EPROTO_STREAM_ID \
222 __einfo_uniqify ( EINFO_EPROTO, ( 34 - 32 ), \
223 "Invalid stream ID" )

◆ EPROTO_SECONDARY

#define EPROTO_SECONDARY   __einfo_error ( EINFO_EPROTO_SECONDARY )

Definition at line 224 of file xhci.c.

224#define EPROTO_SECONDARY \
225 __einfo_error ( EINFO_EPROTO_SECONDARY )

◆ EINFO_EPROTO_SECONDARY

#define EINFO_EPROTO_SECONDARY
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 35 - 32 ), \
"Secondary bandwidth error" )

Definition at line 226 of file xhci.c.

226#define EINFO_EPROTO_SECONDARY \
227 __einfo_uniqify ( EINFO_EPROTO, ( 35 - 32 ), \
228 "Secondary bandwidth error" )

◆ EPROTO_SPLIT

#define EPROTO_SPLIT   __einfo_error ( EINFO_EPROTO_SPLIT )

Definition at line 229 of file xhci.c.

229#define EPROTO_SPLIT \
230 __einfo_error ( EINFO_EPROTO_SPLIT )

◆ EINFO_EPROTO_SPLIT

#define EINFO_EPROTO_SPLIT
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 36 - 32 ), \
"Split transaction error" )

Definition at line 231 of file xhci.c.

231#define EINFO_EPROTO_SPLIT \
232 __einfo_uniqify ( EINFO_EPROTO, ( 36 - 32 ), \
233 "Split transaction error" )

◆ ECODE

#define ECODE ( code)
Value:
( ( (code) < 32 ) ? \
EUNIQ ( EINFO_EIO, ( (code) & 31 ), EIO_DATA, EIO_BABBLE, \
EIO_ISOCH ) : \
( (code) < 64 ) ? \
EUNIQ ( EINFO_EPROTO, ( (code) & 31 ), EPROTO_LOST, \
static unsigned int code
Definition hyperv.h:26
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition errno.h:269
#define EFAULT
Bad address.
Definition errno.h:437
#define EIO_ENDPOINT
Definition xhci.c:114
#define EIO_RING_FULL
Definition xhci.c:159
#define EIO_MISSED
Definition xhci.c:169
#define EIO_STREAM_TYPE
Definition xhci.c:104
#define EIO_ISOCH
Definition xhci.c:204
#define EIO_OVERRUN
Definition xhci.c:129
#define EIO_DATA
Definition xhci.c:64
#define EPROTO_UNDEFINED
Definition xhci.c:214
#define EIO_VF_RING_FULL
Definition xhci.c:134
#define EIO_SHORT
Definition xhci.c:119
#define EIO_STOP_SHORT
Definition xhci.c:194
#define EIO_CMD_STOPPED
Definition xhci.c:174
#define EPROTO_SPLIT
Definition xhci.c:229
#define EIO_STOP
Definition xhci.c:184
#define EIO_BANDWIDTH_OVERRUN
Definition xhci.c:144
#define EIO_STOP_LEN
Definition xhci.c:189
#define EIO_STALL
Definition xhci.c:84
#define EIO_BANDWIDTH
Definition xhci.c:94
#define EIO_NO_PING
Definition xhci.c:154
#define EIO_BABBLE
Definition xhci.c:69
#define EIO_LATENCY
Definition xhci.c:199
#define EIO_USB
Definition xhci.c:74
#define EPROTO_STREAM_ID
Definition xhci.c:219
#define EIO_CMD_ABORTED
Definition xhci.c:179
#define EPROTO_SECONDARY
Definition xhci.c:224
#define EIO_RESOURCE
Definition xhci.c:89
#define EIO_INCOMPATIBLE
Definition xhci.c:164
#define EPROTO_LOST
Definition xhci.c:209
#define EIO_CONTEXT
Definition xhci.c:149
#define EIO_NO_SLOTS
Definition xhci.c:99
#define EIO_PARAMETER
Definition xhci.c:139
#define EIO_SLOT
Definition xhci.c:109
#define EIO_UNDERRUN
Definition xhci.c:124
#define EIO_TRB
Definition xhci.c:79

Definition at line 234 of file xhci.c.

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, \
245 EIO_ISOCH ) : \
246 ( (code) < 64 ) ? \
247 EUNIQ ( EINFO_EPROTO, ( (code) & 31 ), EPROTO_LOST, \
248 EPROTO_UNDEFINED, EPROTO_STREAM_ID, \
249 EPROTO_SECONDARY, EPROTO_SPLIT ) : \
250 EFAULT )

Referenced by xhci_command(), xhci_complete(), xhci_host_controller(), and xhci_transfer().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ xhci_init()

void xhci_init ( struct xhci_device * xhci)

Initialise device.

Parameters
xhcixHCI device

Definition at line 264 of file xhci.c.

264 {
265 uint32_t hcsparams1;
266 uint32_t hcsparams2;
267 uint32_t hccparams1;
268 uint32_t pagesize;
269 size_t caplength;
270 size_t rtsoff;
271 size_t dboff;
272
273 /* Set device name */
274 xhci->name = xhci->dev->name;
275
276 /* Locate capability, operational, runtime, and doorbell registers */
277 xhci->cap = xhci->regs;
278 caplength = readb ( xhci->cap + XHCI_CAP_CAPLENGTH );
279 rtsoff = readl ( xhci->cap + XHCI_CAP_RTSOFF );
280 dboff = readl ( xhci->cap + XHCI_CAP_DBOFF );
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 ) );
288
289 /* Read structural parameters 1 */
290 hcsparams1 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS1 );
291 xhci->slots = XHCI_HCSPARAMS1_SLOTS ( hcsparams1 );
292 xhci->intrs = XHCI_HCSPARAMS1_INTRS ( hcsparams1 );
293 xhci->ports = XHCI_HCSPARAMS1_PORTS ( hcsparams1 );
294 DBGC ( xhci, "XHCI %s has %d slots %d intrs %d ports\n",
295 xhci->name, xhci->slots, xhci->intrs, xhci->ports );
296
297 /* Read structural parameters 2 */
298 hcsparams2 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS2 );
299 xhci->scratch.count = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
300 DBGC2 ( xhci, "XHCI %s needs %d scratchpads\n",
301 xhci->name, xhci->scratch.count );
302
303 /* Read capability parameters 1 */
304 hccparams1 = readl ( xhci->cap + XHCI_CAP_HCCPARAMS1 );
305 xhci->addr64 = XHCI_HCCPARAMS1_ADDR64 ( hccparams1 );
306 xhci->csz_shift = XHCI_HCCPARAMS1_CSZ_SHIFT ( hccparams1 );
307 xhci->xecp = XHCI_HCCPARAMS1_XECP ( hccparams1 );
308
309 /* Read page size */
310 pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
311 xhci->pagesize = XHCI_PAGESIZE ( pagesize );
312 assert ( xhci->pagesize != 0 );
313 assert ( ( ( xhci->pagesize ) & ( xhci->pagesize - 1 ) ) == 0 );
314 DBGC2 ( xhci, "XHCI %s page size %zd bytes\n",
315 xhci->name, xhci->pagesize );
316
317 /* Configure DMA device */
318 if ( xhci->dma && xhci->addr64 )
319 dma_set_mask_64bit ( xhci->dma );
320}
unsigned int uint32_t
Definition stdint.h:12
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:61
#define DBGC2(...)
Definition compiler.h:547
#define DBGC(...)
Definition compiler.h:530
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
Definition dma.h:467
char name[40]
Name.
Definition device.h:79
unsigned int csz_shift
Context size shift.
Definition xhci.h:1100
unsigned int xecp
xHCI extended capabilities offset
Definition xhci.h:1102
struct device * dev
Underlying hardware device.
Definition xhci.h:1073
const char * name
Name.
Definition xhci.h:1077
void * db
Doorbell registers.
Definition xhci.h:1088
void * op
Operational registers.
Definition xhci.h:1084
void * run
Runtime registers.
Definition xhci.h:1086
unsigned int intrs
Number of interrupters.
Definition xhci.h:1093
unsigned int slots
Number of device slots.
Definition xhci.h:1091
int addr64
64-bit addressing capability
Definition xhci.h:1098
size_t pagesize
Page size.
Definition xhci.h:1105
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition xhci.h:1114
void * regs
Registers.
Definition xhci.h:1071
struct dma_device * dma
DMA device.
Definition xhci.h:1075
void * cap
Capability registers.
Definition xhci.h:1082
unsigned int ports
Number of ports.
Definition xhci.h:1095
unsigned int count
Number of page-sized scratchpad buffers.
Definition xhci.h:1057
#define readl
Definition w89c840.c:157
#define readb
Definition w89c840.c:155
#define XHCI_CAP_HCSPARAMS1
Structural parameters 1.
Definition xhci.h:40
#define XHCI_HCCPARAMS1_ADDR64(params)
64-bit addressing capability
Definition xhci.h:62
#define XHCI_OP_PAGESIZE
Page size register.
Definition xhci.h:170
#define XHCI_HCSPARAMS1_SLOTS(params)
Number of device slots.
Definition xhci.h:43
#define XHCI_CAP_DBOFF
Doorbell offset.
Definition xhci.h:71
#define XHCI_CAP_HCSPARAMS2
Structural parameters 2.
Definition xhci.h:52
#define XHCI_PAGESIZE(pagesize)
Page size.
Definition xhci.h:173
#define XHCI_CAP_RTSOFF
Runtime register space offset.
Definition xhci.h:74
#define XHCI_HCCPARAMS1_XECP(params)
xHCI extended capabilities pointer
Definition xhci.h:68
#define XHCI_HCSPARAMS1_INTRS(params)
Number of interrupters.
Definition xhci.h:46
#define XHCI_HCSPARAMS2_SCRATCHPADS(params)
Number of page-sized scratchpad buffers.
Definition xhci.h:55
#define XHCI_CAP_HCCPARAMS1
Capability parameters.
Definition xhci.h:59
#define XHCI_HCCPARAMS1_CSZ_SHIFT(params)
Context size shift.
Definition xhci.h:65
#define XHCI_HCSPARAMS1_PORTS(params)
Number of ports.
Definition xhci.h:49
#define XHCI_CAP_CAPLENGTH
Capability register length.
Definition xhci.h:34

References xhci_device::addr64, assert, xhci_device::cap, xhci_scratchpad::count, xhci_device::csz_shift, xhci_device::db, DBGC, DBGC2, xhci_device::dev, xhci_device::dma, dma_set_mask_64bit(), xhci_device::intrs, device::name, xhci_device::name, xhci_device::op, xhci_device::pagesize, xhci_device::ports, readb, readl, xhci_device::regs, xhci_device::run, xhci_device::scratch, xhci_device::slots, xhci_device::xecp, XHCI_CAP_CAPLENGTH, XHCI_CAP_DBOFF, XHCI_CAP_HCCPARAMS1, XHCI_CAP_HCSPARAMS1, XHCI_CAP_HCSPARAMS2, XHCI_CAP_RTSOFF, XHCI_HCCPARAMS1_ADDR64, XHCI_HCCPARAMS1_CSZ_SHIFT, XHCI_HCCPARAMS1_XECP, XHCI_HCSPARAMS1_INTRS, XHCI_HCSPARAMS1_PORTS, XHCI_HCSPARAMS1_SLOTS, XHCI_HCSPARAMS2_SCRATCHPADS, XHCI_OP_PAGESIZE, and XHCI_PAGESIZE.

Referenced by dwusb_probe(), and xhci_probe().

◆ xhci_extended_capability()

unsigned int xhci_extended_capability ( struct xhci_device * xhci,
unsigned int id,
unsigned int offset )
static

Find extended capability.

Parameters
xhcixHCI device
idCapability ID
offsetOffset to previous extended capability instance, or zero
Return values
offsetOffset to extended capability, or zero if not found

Definition at line 330 of file xhci.c.

332 {
333 uint32_t xecp;
334 unsigned int next;
335
336 /* Locate the extended capability */
337 while ( 1 ) {
338
339 /* Locate first or next capability as applicable */
340 if ( offset ) {
341 xecp = readl ( xhci->cap + offset );
342 next = XHCI_XECP_NEXT ( xecp );
343 } else {
344 next = xhci->xecp;
345 }
346 if ( ! next )
347 return 0;
348 offset += next;
349
350 /* Check if this is the requested capability */
351 xecp = readl ( xhci->cap + offset );
352 if ( XHCI_XECP_ID ( xecp ) == id )
353 return offset;
354 }
355}
uint16_t offset
Offset to command line.
Definition bzimage.h:3
uint32_t next
Next descriptor address.
Definition dwmac.h:11
#define XHCI_XECP_ID(xecp)
xHCI extended capability ID
Definition xhci.h:77
#define XHCI_XECP_NEXT(xecp)
Next xHCI extended capability pointer.
Definition xhci.h:80

References xhci_device::cap, next, offset, readl, xhci_device::xecp, XHCI_XECP_ID, and XHCI_XECP_NEXT.

Referenced by xhci_legacy_init(), and xhci_supported_protocol().

◆ xhci_writeq()

int xhci_writeq ( struct xhci_device * xhci,
physaddr_t value,
void * reg )
inlinestatic

Write potentially 64-bit register.

Parameters
xhcixHCI device
valueValue
regRegister address
Return values
rcReturn status code

Definition at line 366 of file xhci.c.

366 {
367
368 /* If this is a 32-bit build, then this can never fail
369 * (allowing the compiler to optimise out the error path).
370 */
371 if ( sizeof ( value ) <= sizeof ( uint32_t ) ) {
372 writel ( value, reg );
373 writel ( 0, ( reg + sizeof ( uint32_t ) ) );
374 return 0;
375 }
376
377 /* If the device does not support 64-bit addresses and this
378 * address is outside the 32-bit address space, then fail.
379 */
380 if ( ( value & ~0xffffffffULL ) && ! xhci->addr64 ) {
381 DBGC ( xhci, "XHCI %s cannot access address %lx\n",
382 xhci->name, value );
383 return -ENOTSUP;
384 }
385
386 /* If this is a 64-bit build, then writeq() is available */
387 writeq ( value, reg );
388 return 0;
389}
pseudo_bit_t value[0x00020]
Definition arbel.h:2
#define ENOTSUP
Operation not supported.
Definition errno.h:633
#define writeq(data, io_addr)
Definition io.h:273
static unsigned int unsigned int reg
Definition myson.h:162
#define writel
Definition w89c840.c:160

References xhci_device::addr64, DBGC, ENOTSUP, xhci_device::name, reg, value, writel, and writeq.

Referenced by xhci_abort(), xhci_command_alloc(), xhci_command_free(), xhci_dcbaa_alloc(), xhci_dcbaa_free(), xhci_event_alloc(), xhci_event_free(), and xhci_event_poll().

◆ xhci_align()

size_t xhci_align ( size_t len)
inlinestatic

Calculate buffer alignment.

Parameters
lenLength
Return values
alignBuffer alignment

Determine alignment required for a buffer which must be aligned to at least XHCI_MIN_ALIGN and which must not cross a page boundary.

Definition at line 400 of file xhci.c.

400 {
401 size_t align;
402
403 /* Align to own length (rounded up to a power of two) */
404 align = ( 1 << fls ( len - 1 ) );
405
406 /* Round up to XHCI_MIN_ALIGN if needed */
407 if ( align < XHCI_MIN_ALIGN )
408 align = XHCI_MIN_ALIGN;
409
410 return align;
411}
ring len
Length.
Definition dwmac.h:226
#define fls(x)
Find last (i.e.
Definition strings.h:167
#define XHCI_MIN_ALIGN
Minimum alignment required for data structures.
Definition xhci.h:25

References fls, len, and XHCI_MIN_ALIGN.

Referenced by xhci_context(), xhci_dcbaa_alloc(), xhci_device_open(), xhci_event_alloc(), xhci_ring_alloc(), and xhci_scratchpad_alloc().

◆ xhci_device_context_offset()

size_t xhci_device_context_offset ( struct xhci_device * xhci,
unsigned int ctx )
inlinestatic

Calculate device context offset.

Parameters
xhcixHCI device
ctxContext index

Definition at line 419 of file xhci.c.

420 {
421
422 return ( XHCI_DCI ( ctx ) << xhci->csz_shift );
423}
struct golan_eq_context ctx
Definition CIB_PRM.h:0
#define XHCI_DCI(ctx)
Device context index.
Definition xhci.h:959

References xhci_device::csz_shift, ctx, and XHCI_DCI.

Referenced by xhci_address_device(), xhci_device_close(), xhci_device_open(), and xhci_endpoint_open().

◆ xhci_input_context_offset()

size_t xhci_input_context_offset ( struct xhci_device * xhci,
unsigned int ctx )
inlinestatic

Calculate input context offset.

Parameters
xhcixHCI device
ctxContext index

Definition at line 431 of file xhci.c.

432 {
433
434 return ( XHCI_ICI ( ctx ) << xhci->csz_shift );
435}
#define XHCI_ICI(ctx)
Input context index.
Definition xhci.h:962

References xhci_device::csz_shift, ctx, and XHCI_ICI.

Referenced by xhci_address_device_input(), xhci_configure_endpoint_input(), xhci_context(), xhci_deconfigure_endpoint_input(), and xhci_evaluate_context_input().

◆ xhci_dump()

void xhci_dump ( struct xhci_device * xhci)
inlinestatic

Dump host controller registers.

Parameters
xhcixHCI device

Definition at line 449 of file xhci.c.

449 {
450 uint32_t usbcmd;
451 uint32_t usbsts;
452 uint32_t pagesize;
453 uint32_t dnctrl;
454 uint32_t config;
455
456 /* Do nothing unless debugging is enabled */
457 if ( ! DBG_LOG )
458 return;
459
460 /* Dump USBCMD */
461 usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
462 DBGC ( xhci, "XHCI %s USBCMD %08x%s%s\n", xhci->name, usbcmd,
463 ( ( usbcmd & XHCI_USBCMD_RUN ) ? " run" : "" ),
464 ( ( usbcmd & XHCI_USBCMD_HCRST ) ? " hcrst" : "" ) );
465
466 /* Dump USBSTS */
467 usbsts = readl ( xhci->op + XHCI_OP_USBSTS );
468 DBGC ( xhci, "XHCI %s USBSTS %08x%s\n", xhci->name, usbsts,
469 ( ( usbsts & XHCI_USBSTS_HCH ) ? " hch" : "" ) );
470
471 /* Dump PAGESIZE */
472 pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
473 DBGC ( xhci, "XHCI %s PAGESIZE %08x\n", xhci->name, pagesize );
474
475 /* Dump DNCTRL */
476 dnctrl = readl ( xhci->op + XHCI_OP_DNCTRL );
477 DBGC ( xhci, "XHCI %s DNCTRL %08x\n", xhci->name, dnctrl );
478
479 /* Dump CONFIG */
480 config = readl ( xhci->op + XHCI_OP_CONFIG );
481 DBGC ( xhci, "XHCI %s CONFIG %08x\n", xhci->name, config );
482}
#define DBG_LOG
Definition compiler.h:342
#define XHCI_OP_CONFIG
Configure register.
Definition xhci.h:194
#define XHCI_USBCMD_RUN
Run/stop.
Definition xhci.h:158
#define XHCI_USBCMD_HCRST
Host controller reset.
Definition xhci.h:161
#define XHCI_OP_DNCTRL
Device notifcation control register.
Definition xhci.h:176
#define XHCI_OP_USBCMD
USB command register.
Definition xhci.h:155
#define XHCI_OP_USBSTS
USB status register.
Definition xhci.h:164
#define XHCI_USBSTS_HCH
Host controller halted.
Definition xhci.h:167

References DBG_LOG, DBGC, xhci_device::name, xhci_device::op, readl, XHCI_OP_CONFIG, XHCI_OP_DNCTRL, XHCI_OP_PAGESIZE, XHCI_OP_USBCMD, XHCI_OP_USBSTS, XHCI_USBCMD_HCRST, XHCI_USBCMD_RUN, and XHCI_USBSTS_HCH.

◆ xhci_dump_port()

void xhci_dump_port ( struct xhci_device * xhci,
unsigned int port )
inlinestatic

Dump port registers.

Parameters
xhcixHCI device
portPort number

Definition at line 490 of file xhci.c.

491 {
492 uint32_t portsc;
493 uint32_t portpmsc;
494 uint32_t portli;
495 uint32_t porthlpmc;
496
497 /* Do nothing unless debugging is enabled */
498 if ( ! DBG_LOG )
499 return;
500
501 /* Dump PORTSC */
502 portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port ) );
503 DBGC ( xhci, "XHCI %s-%d PORTSC %08x%s%s%s%s psiv=%d\n",
504 xhci->name, port, portsc,
505 ( ( portsc & XHCI_PORTSC_CCS ) ? " ccs" : "" ),
506 ( ( portsc & XHCI_PORTSC_PED ) ? " ped" : "" ),
507 ( ( portsc & XHCI_PORTSC_PR ) ? " pr" : "" ),
508 ( ( portsc & XHCI_PORTSC_PP ) ? " pp" : "" ),
509 XHCI_PORTSC_PSIV ( portsc ) );
510
511 /* Dump PORTPMSC */
512 portpmsc = readl ( xhci->op + XHCI_OP_PORTPMSC ( port ) );
513 DBGC ( xhci, "XHCI %s-%d PORTPMSC %08x\n", xhci->name, port, portpmsc );
514
515 /* Dump PORTLI */
516 portli = readl ( xhci->op + XHCI_OP_PORTLI ( port ) );
517 DBGC ( xhci, "XHCI %s-%d PORTLI %08x\n", xhci->name, port, portli );
518
519 /* Dump PORTHLPMC */
520 porthlpmc = readl ( xhci->op + XHCI_OP_PORTHLPMC ( port ) );
521 DBGC ( xhci, "XHCI %s-%d PORTHLPMC %08x\n",
522 xhci->name, port, porthlpmc );
523}
u8 port
Port number.
Definition CIB_PRM.h:3
#define XHCI_PORTSC_PP
Port power.
Definition xhci.h:228
#define XHCI_OP_PORTPMSC(port)
Port power management status and control register.
Definition xhci.h:287
#define XHCI_OP_PORTHLPMC(port)
Port hardware link power management control register.
Definition xhci.h:293
#define XHCI_PORTSC_PSIV(portsc)
Port speed ID value.
Definition xhci.h:234
#define XHCI_OP_PORTLI(port)
Port link info register.
Definition xhci.h:290
#define XHCI_PORTSC_CCS
Current connect status.
Definition xhci.h:207
#define XHCI_PORTSC_PED
Port enabled.
Definition xhci.h:210
#define XHCI_PORTSC_PR
Port reset.
Definition xhci.h:213
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition xhci.h:204

References DBG_LOG, DBGC, xhci_device::name, xhci_device::op, port, readl, XHCI_OP_PORTHLPMC, XHCI_OP_PORTLI, XHCI_OP_PORTPMSC, XHCI_OP_PORTSC, XHCI_PORTSC_CCS, XHCI_PORTSC_PED, XHCI_PORTSC_PP, XHCI_PORTSC_PR, and XHCI_PORTSC_PSIV.

◆ xhci_legacy_init()

void xhci_legacy_init ( struct xhci_device * xhci)
static

Initialise USB legacy support.

Parameters
xhcixHCI device

Definition at line 540 of file xhci.c.

540 {
541 unsigned int legacy;
542 uint8_t bios;
543
544 /* Locate USB legacy support capability (if present) */
545 legacy = xhci_extended_capability ( xhci, XHCI_XECP_ID_LEGACY, 0 );
546 if ( ! legacy ) {
547 /* Not an error; capability may not be present */
548 DBGC ( xhci, "XHCI %s has no USB legacy support capability\n",
549 xhci->name );
550 return;
551 }
552
553 /* Check if legacy USB support is enabled */
554 bios = readb ( xhci->cap + legacy + XHCI_USBLEGSUP_BIOS );
555 if ( ! ( bios & XHCI_USBLEGSUP_BIOS_OWNED ) ) {
556 /* Not an error; already owned by OS */
557 DBGC ( xhci, "XHCI %s USB legacy support already disabled\n",
558 xhci->name );
559 return;
560 }
561
562 /* Record presence of USB legacy support capability */
563 xhci->legacy = legacy;
564}
unsigned char uint8_t
Definition stdint.h:10
unsigned int legacy
USB legacy support capability (if present and enabled).
Definition xhci.h:1108
static unsigned int xhci_extended_capability(struct xhci_device *xhci, unsigned int id, unsigned int offset)
Find extended capability.
Definition xhci.c:330
#define XHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
Definition xhci.h:89
#define XHCI_XECP_ID_LEGACY
USB legacy support extended capability.
Definition xhci.h:83
#define XHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition xhci.h:86

References xhci_device::cap, DBGC, xhci_device::legacy, xhci_device::name, readb, xhci_extended_capability(), XHCI_USBLEGSUP_BIOS, XHCI_USBLEGSUP_BIOS_OWNED, and XHCI_XECP_ID_LEGACY.

Referenced by xhci_probe().

◆ xhci_legacy_claim()

void xhci_legacy_claim ( struct xhci_device * xhci)
static

Claim ownership from BIOS.

Parameters
xhcixHCI device

Definition at line 571 of file xhci.c.

571 {
572 uint32_t ctlsts;
573 uint8_t bios;
574 unsigned int i;
575
576 /* Do nothing unless legacy support capability is present */
577 if ( ! xhci->legacy )
578 return;
579
580 /* Claim ownership */
582 xhci->cap + xhci->legacy + XHCI_USBLEGSUP_OS );
583
584 /* Wait for BIOS to release ownership */
585 for ( i = 0 ; i < XHCI_USBLEGSUP_MAX_WAIT_MS ; i++ ) {
586
587 /* Check if BIOS has released ownership */
588 bios = readb ( xhci->cap + xhci->legacy + XHCI_USBLEGSUP_BIOS );
589 if ( ! ( bios & XHCI_USBLEGSUP_BIOS_OWNED ) ) {
590 DBGC ( xhci, "XHCI %s claimed ownership from BIOS\n",
591 xhci->name );
592 ctlsts = readl ( xhci->cap + xhci->legacy +
594 if ( ctlsts ) {
595 DBGC ( xhci, "XHCI %s warning: BIOS retained "
596 "SMIs: %08x\n", xhci->name, ctlsts );
597 }
598 return;
599 }
600
601 /* Delay */
602 mdelay ( 1 );
603 }
604
605 /* BIOS did not release ownership. Claim it forcibly by
606 * disabling all SMIs.
607 */
608 DBGC ( xhci, "XHCI %s could not claim ownership from BIOS: forcibly "
609 "disabling SMIs\n", xhci->name );
610 writel ( 0, xhci->cap + xhci->legacy + XHCI_USBLEGSUP_CTLSTS );
611}
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79
#define writeb
Definition w89c840.c:158
#define XHCI_USBLEGSUP_MAX_WAIT_MS
Maximum time to wait for BIOS to release ownership.
Definition xhci.h:986
#define XHCI_USBLEGSUP_CTLSTS
USB legacy support control/status.
Definition xhci.h:98
#define XHCI_USBLEGSUP_OS_OWNED
USB legacy support OS ownership flag.
Definition xhci.h:95
#define XHCI_USBLEGSUP_OS
USB legacy support OS owned semaphore.
Definition xhci.h:92

References xhci_device::cap, DBGC, xhci_device::legacy, mdelay(), xhci_device::name, readb, readl, writeb, writel, XHCI_USBLEGSUP_BIOS, XHCI_USBLEGSUP_BIOS_OWNED, XHCI_USBLEGSUP_CTLSTS, XHCI_USBLEGSUP_MAX_WAIT_MS, XHCI_USBLEGSUP_OS, and XHCI_USBLEGSUP_OS_OWNED.

Referenced by xhci_probe().

◆ xhci_legacy_release()

void xhci_legacy_release ( struct xhci_device * xhci)
static

Release ownership back to BIOS.

Parameters
xhcixHCI device

Definition at line 618 of file xhci.c.

618 {
619
620 /* Do nothing unless legacy support capability is present */
621 if ( ! xhci->legacy )
622 return;
623
624 /* Do nothing if releasing ownership is prevented */
626 DBGC ( xhci, "XHCI %s not releasing ownership to BIOS\n",
627 xhci->name );
628 return;
629 }
630
631 /* Release ownership */
632 writeb ( 0, xhci->cap + xhci->legacy + XHCI_USBLEGSUP_OS );
633 DBGC ( xhci, "XHCI %s released ownership to BIOS\n", xhci->name );
634}
static int xhci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
Definition xhci.c:533

References xhci_device::cap, DBGC, xhci_device::legacy, xhci_device::name, writeb, xhci_legacy_prevent_release, and XHCI_USBLEGSUP_OS.

Referenced by xhci_probe(), and xhci_remove().

◆ xhci_speed_name()

const char * xhci_speed_name ( uint32_t psi)
inlinestatic

Transcribe port speed (for debugging).

Parameters
psiProtocol speed ID
Return values
speedTranscribed speed

Definition at line 649 of file xhci.c.

649 {
650 static const char *exponents[4] = { "", "k", "M", "G" };
651 static char buf[ 10 /* "xxxxxXbps" + NUL */ ];
652 unsigned int mantissa;
653 unsigned int exponent;
654
655 /* Extract mantissa and exponent */
656 mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
657 exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
658
659 /* Transcribe speed */
660 snprintf ( buf, sizeof ( buf ), "%d%sbps",
661 mantissa, exponents[exponent] );
662 return buf;
663}
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)
Supported protocol PSI mantissa.
Definition xhci.h:137
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
Definition xhci.h:140

References snprintf(), XHCI_SUPPORTED_PSI_EXPONENT, and XHCI_SUPPORTED_PSI_MANTISSA.

Referenced by xhci_port_protocol().

◆ xhci_supported_protocol()

unsigned int xhci_supported_protocol ( struct xhci_device * xhci,
unsigned int port )
static

Find supported protocol extended capability for a port.

Parameters
xhcixHCI device
portPort number
Return values
supportedOffset to extended capability, or zero if not found

Definition at line 672 of file xhci.c.

673 {
674 unsigned int supported = 0;
675 unsigned int offset;
676 unsigned int count;
677 uint32_t ports;
678
679 /* Iterate over all supported protocol structures */
680 while ( ( supported = xhci_extended_capability ( xhci,
682 supported ) ) ) {
683
684 /* Determine port range */
685 ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
688
689 /* Check if port lies within this range */
690 if ( ( port - offset ) < count )
691 return supported;
692 }
693
694 DBGC ( xhci, "XHCI %s-%d has no supported protocol\n",
695 xhci->name, port );
696 return 0;
697}
uint16_t supported
Bitmask of supported option values.
Definition ena.h:1
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition xhci.h:113
#define XHCI_XECP_ID_SUPPORTED
Supported protocol extended capability.
Definition xhci.h:101
#define XHCI_SUPPORTED_PORTS_COUNT(ports)
Supported protocol port count.
Definition xhci.h:119
#define XHCI_SUPPORTED_PORTS_OFFSET(ports)
Supported protocol port offset.
Definition xhci.h:116

References xhci_device::cap, count, DBGC, xhci_device::name, offset, port, readl, supported, xhci_extended_capability(), XHCI_SUPPORTED_PORTS, XHCI_SUPPORTED_PORTS_COUNT, XHCI_SUPPORTED_PORTS_OFFSET, and XHCI_XECP_ID_SUPPORTED.

Referenced by xhci_port_protocol(), xhci_port_psiv(), xhci_port_slot_type(), and xhci_port_speed().

◆ xhci_port_protocol()

unsigned int xhci_port_protocol ( struct xhci_device * xhci,
unsigned int port )
static

Find port protocol.

Parameters
xhcixHCI device
portPort number
Return values
protocolUSB protocol, or zero if not found

Definition at line 706 of file xhci.c.

707 {
708 unsigned int supported = xhci_supported_protocol ( xhci, port );
709 union {
711 char text[5];
712 } name;
713 unsigned int protocol;
714 unsigned int type;
715 unsigned int psic;
716 unsigned int psiv;
717 unsigned int i;
719 uint32_t ports;
721 uint32_t psi;
722
723 /* Fail if there is no supported protocol */
724 if ( ! supported )
725 return 0;
726
727 /* Determine protocol version */
730
731 /* Describe port protocol */
732 if ( DBG_EXTRA ) {
733 name.raw = cpu_to_le32 ( readl ( xhci->cap + supported +
735 name.text[4] = '\0';
738 DBGC2 ( xhci, "XHCI %s-%d %sv%04x type %d",
739 xhci->name, port, name.text, protocol, type );
740 ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
741 psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
742 if ( psic ) {
743 DBGC2 ( xhci, " speeds" );
744 for ( i = 0 ; i < psic ; i++ ) {
745 psi = readl ( xhci->cap + supported +
746 XHCI_SUPPORTED_PSI ( i ) );
747 psiv = XHCI_SUPPORTED_PSI_VALUE ( psi );
748 DBGC2 ( xhci, " %d:%s", psiv,
749 xhci_speed_name ( psi ) );
750 }
751 }
752 if ( xhci->quirks & XHCI_BAD_PSIV )
753 DBGC2 ( xhci, " (ignored)" );
754 DBGC2 ( xhci, "\n" );
755 }
756
757 return protocol;
758}
__be32 raw[7]
Definition CIB_PRM.h:0
const char * name
Definition ath9k_hw.c:1986
uint8_t slot
Slot.
Definition edd.h:3
uint32_t type
Operating system type.
Definition ena.h:1
#define DBG_EXTRA
Definition compiler.h:344
uint32_t revision
Entry point revision.
Definition ib_mad.h:9
#define cpu_to_le32(value)
Definition byteswap.h:108
uint16_t protocol
Protocol ID.
Definition stp.h:7
unsigned int quirks
Quirks.
Definition xhci.h:1079
static const char * xhci_speed_name(uint32_t psi)
Transcribe port speed (for debugging).
Definition xhci.c:649
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition xhci.c:672
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition xhci.h:1044
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition xhci.h:128
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
Definition xhci.h:122
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition xhci.h:125
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition xhci.h:131
#define XHCI_SUPPORTED_NAME
Supported protocol name.
Definition xhci.h:110
#define XHCI_SUPPORTED_REVISION_VER(revision)
Supported protocol minor revision.
Definition xhci.h:107
#define XHCI_SUPPORTED_REVISION
Supported protocol revision.
Definition xhci.h:104
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition xhci.h:134

References xhci_device::cap, cpu_to_le32, DBG_EXTRA, DBGC2, name, xhci_device::name, port, protocol, xhci_device::quirks, raw, readl, revision, slot, supported, type, XHCI_BAD_PSIV, xhci_speed_name(), XHCI_SUPPORTED_NAME, XHCI_SUPPORTED_PORTS, XHCI_SUPPORTED_PORTS_PSIC, xhci_supported_protocol(), XHCI_SUPPORTED_PSI, XHCI_SUPPORTED_PSI_VALUE, XHCI_SUPPORTED_REVISION, XHCI_SUPPORTED_REVISION_VER, XHCI_SUPPORTED_SLOT, and XHCI_SUPPORTED_SLOT_TYPE.

Referenced by xhci_register().

◆ xhci_port_slot_type()

int xhci_port_slot_type ( struct xhci_device * xhci,
unsigned int port )
static

Find port slot type.

Parameters
xhcixHCI device
portPort number
Return values
typeSlot type, or negative error

Definition at line 767 of file xhci.c.

767 {
768 unsigned int supported = xhci_supported_protocol ( xhci, port );
769 unsigned int type;
771
772 /* Fail if there is no supported protocol */
773 if ( ! supported )
774 return -ENOTSUP;
775
776 /* Get slot type */
779
780 return type;
781}

References xhci_device::cap, ENOTSUP, port, readl, slot, supported, type, xhci_supported_protocol(), XHCI_SUPPORTED_SLOT, and XHCI_SUPPORTED_SLOT_TYPE.

Referenced by xhci_device_open().

◆ xhci_port_speed()

int xhci_port_speed ( struct xhci_device * xhci,
unsigned int port,
unsigned int psiv )
static

Find port speed.

Parameters
xhcixHCI device
portPort number
psivProtocol speed ID value
Return values
speedPort speed, or negative error

Definition at line 791 of file xhci.c.

792 {
793 unsigned int supported = xhci_supported_protocol ( xhci, port );
794 unsigned int psic;
795 unsigned int mantissa;
796 unsigned int exponent;
797 unsigned int speed;
798 unsigned int i;
799 uint32_t ports;
800 uint32_t psi;
801
802 /* Fail if there is no supported protocol */
803 if ( ! supported )
804 return -ENOTSUP;
805
806 /* Get protocol speed ID count */
807 ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
808 psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
809
810 /* Use protocol speed ID table unless device is known to be faulty */
811 if ( ! ( xhci->quirks & XHCI_BAD_PSIV ) ) {
812
813 /* Iterate over PSI dwords looking for a match */
814 for ( i = 0 ; i < psic ; i++ ) {
815 psi = readl ( xhci->cap + supported +
816 XHCI_SUPPORTED_PSI ( i ) );
817 if ( psiv == XHCI_SUPPORTED_PSI_VALUE ( psi ) ) {
818 mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
819 exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
820 speed = USB_SPEED ( mantissa, exponent );
821 return speed;
822 }
823 }
824
825 /* Record device as faulty if no match is found */
826 if ( psic != 0 ) {
827 DBGC ( xhci, "XHCI %s-%d spurious PSI value %d: "
828 "assuming PSI table is invalid\n",
829 xhci->name, port, psiv );
830 xhci->quirks |= XHCI_BAD_PSIV;
831 }
832 }
833
834 /* Use the default mappings */
835 switch ( psiv ) {
836 case XHCI_SPEED_LOW : return USB_SPEED_LOW;
837 case XHCI_SPEED_FULL : return USB_SPEED_FULL;
838 case XHCI_SPEED_HIGH : return USB_SPEED_HIGH;
839 case XHCI_SPEED_SUPER : return USB_SPEED_SUPER;
840 default:
841 DBGC ( xhci, "XHCI %s-%d unrecognised PSI value %d\n",
842 xhci->name, port, psiv );
843 return -ENOTSUP;
844 }
845}
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
Definition usb.h:36
@ USB_SPEED_LOW
Low speed (1.5Mbps).
Definition usb.h:49
@ USB_SPEED_FULL
Full speed (12Mbps).
Definition usb.h:51
@ USB_SPEED_HIGH
High speed (480Mbps).
Definition usb.h:53
@ USB_SPEED_SUPER
Super speed (5Gbps).
Definition usb.h:55
@ XHCI_SPEED_SUPER
Super speed.
Definition xhci.h:151
@ XHCI_SPEED_FULL
Full speed (12Mbps).
Definition xhci.h:145
@ XHCI_SPEED_LOW
Low speed (1.5Mbps).
Definition xhci.h:147
@ XHCI_SPEED_HIGH
High speed (480Mbps).
Definition xhci.h:149

References xhci_device::cap, DBGC, ENOTSUP, xhci_device::name, port, xhci_device::quirks, readl, supported, USB_SPEED, USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_LOW, USB_SPEED_SUPER, XHCI_BAD_PSIV, XHCI_SPEED_FULL, XHCI_SPEED_HIGH, XHCI_SPEED_LOW, XHCI_SPEED_SUPER, XHCI_SUPPORTED_PORTS, XHCI_SUPPORTED_PORTS_PSIC, xhci_supported_protocol(), XHCI_SUPPORTED_PSI, XHCI_SUPPORTED_PSI_EXPONENT, XHCI_SUPPORTED_PSI_MANTISSA, and XHCI_SUPPORTED_PSI_VALUE.

Referenced by xhci_root_speed().

◆ xhci_port_psiv()

int xhci_port_psiv ( struct xhci_device * xhci,
unsigned int port,
unsigned int speed )
static

Find protocol speed ID value.

Parameters
xhcixHCI device
portPort number
speedUSB speed
Return values
psivProtocol speed ID value, or negative error

Definition at line 855 of file xhci.c.

856 {
857 unsigned int supported = xhci_supported_protocol ( xhci, port );
858 unsigned int psic;
859 unsigned int mantissa;
860 unsigned int exponent;
861 unsigned int psiv;
862 unsigned int i;
863 uint32_t ports;
864 uint32_t psi;
865
866 /* Fail if there is no supported protocol */
867 if ( ! supported )
868 return -ENOTSUP;
869
870 /* Get protocol speed ID count */
871 ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
872 psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
873
874 /* Use the default mappings if applicable */
875 if ( ( psic == 0 ) || ( xhci->quirks & XHCI_BAD_PSIV ) ) {
876 switch ( speed ) {
877 case USB_SPEED_LOW : return XHCI_SPEED_LOW;
878 case USB_SPEED_FULL : return XHCI_SPEED_FULL;
879 case USB_SPEED_HIGH : return XHCI_SPEED_HIGH;
880 case USB_SPEED_SUPER : return XHCI_SPEED_SUPER;
881 default:
882 DBGC ( xhci, "XHCI %s-%d non-standard speed %d\n",
883 xhci->name, port, speed );
884 return -ENOTSUP;
885 }
886 }
887
888 /* Iterate over PSI dwords looking for a match */
889 for ( i = 0 ; i < psic ; i++ ) {
890 psi = readl ( xhci->cap + supported + XHCI_SUPPORTED_PSI ( i ));
891 mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
892 exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
893 if ( speed == USB_SPEED ( mantissa, exponent ) ) {
894 psiv = XHCI_SUPPORTED_PSI_VALUE ( psi );
895 return psiv;
896 }
897 }
898
899 DBGC ( xhci, "XHCI %s-%d unrepresentable speed %#x\n",
900 xhci->name, port, speed );
901 return -ENOENT;
902}
#define ENOENT
No such file or directory.
Definition errno.h:558

References xhci_device::cap, DBGC, ENOENT, ENOTSUP, xhci_device::name, port, xhci_device::quirks, readl, supported, USB_SPEED, USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_LOW, USB_SPEED_SUPER, XHCI_BAD_PSIV, XHCI_SPEED_FULL, XHCI_SPEED_HIGH, XHCI_SPEED_LOW, XHCI_SPEED_SUPER, XHCI_SUPPORTED_PORTS, XHCI_SUPPORTED_PORTS_PSIC, xhci_supported_protocol(), XHCI_SUPPORTED_PSI, XHCI_SUPPORTED_PSI_EXPONENT, XHCI_SUPPORTED_PSI_MANTISSA, and XHCI_SUPPORTED_PSI_VALUE.

Referenced by xhci_device_address().

◆ xhci_dcbaa_alloc()

int xhci_dcbaa_alloc ( struct xhci_device * xhci)
static

Allocate device context base address array.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 917 of file xhci.c.

917 {
918 size_t len;
919 physaddr_t dcbaap;
920 int rc;
921
922 /* Allocate and initialise structure. Must be at least
923 * 64-byte aligned and must not cross a page boundary, so
924 * align on its own size (rounded up to a power of two and
925 * with a minimum of 64 bytes).
926 */
927 len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
928 xhci->dcbaa.context = dma_alloc ( xhci->dma, &xhci->dcbaa.map, len,
929 xhci_align ( len ) );
930 if ( ! xhci->dcbaa.context ) {
931 DBGC ( xhci, "XHCI %s could not allocate DCBAA\n", xhci->name );
932 rc = -ENOMEM;
933 goto err_alloc;
934 }
935 memset ( xhci->dcbaa.context, 0, len );
936
937 /* Program DCBAA pointer */
938 dcbaap = dma ( &xhci->dcbaa.map, xhci->dcbaa.context );
939 if ( ( rc = xhci_writeq ( xhci, dcbaap,
940 xhci->op + XHCI_OP_DCBAAP ) ) != 0 )
941 goto err_writeq;
942
943 DBGC2 ( xhci, "XHCI %s DCBAA at [%08lx,%08lx)\n", xhci->name,
944 virt_to_phys ( xhci->dcbaa.context ),
945 ( virt_to_phys ( xhci->dcbaa.context ) + len ) );
946 return 0;
947
948 err_writeq:
949 dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
950 err_alloc:
951 return rc;
952}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned long physaddr_t
Definition stdint.h:20
#define ENOMEM
Not enough space.
Definition errno.h:578
void * memset(void *dest, int character, size_t len) __nonnull
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
struct dma_mapping map
DMA mapping.
Definition xhci.h:1051
uint64_t * context
Context base addresses.
Definition xhci.h:1049
struct xhci_dcbaa dcbaa
Device context base address array.
Definition xhci.h:1111
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition xhci.c:366
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition xhci.c:400
#define XHCI_OP_DCBAAP
Device context base address array pointer.
Definition xhci.h:191

References xhci_dcbaa::context, DBGC, DBGC2, xhci_device::dcbaa, dma(), xhci_device::dma, dma_alloc(), dma_free(), ENOMEM, len, xhci_dcbaa::map, memset(), xhci_device::name, xhci_device::op, rc, xhci_device::slots, xhci_align(), XHCI_OP_DCBAAP, and xhci_writeq().

Referenced by xhci_bus_open().

◆ xhci_dcbaa_free()

void xhci_dcbaa_free ( struct xhci_device * xhci)
static

Free device context base address array.

Parameters
xhcixHCI device

Definition at line 959 of file xhci.c.

959 {
960 size_t len;
961 unsigned int i;
962
963 /* Sanity check */
964 for ( i = 0 ; i <= xhci->slots ; i++ )
965 assert ( xhci->dcbaa.context[i] == 0 );
966
967 /* Clear DCBAA pointer */
968 xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_DCBAAP );
969
970 /* Free DCBAA */
971 len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
972 dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
973}

References assert, xhci_dcbaa::context, xhci_device::dcbaa, dma_free(), len, xhci_dcbaa::map, xhci_device::op, xhci_device::slots, XHCI_OP_DCBAAP, and xhci_writeq().

Referenced by xhci_bus_close(), and xhci_bus_open().

◆ xhci_scratchpad_alloc()

int xhci_scratchpad_alloc ( struct xhci_device * xhci)
static

Allocate scratchpad buffers.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 988 of file xhci.c.

988 {
989 struct xhci_scratchpad *scratch = &xhci->scratch;
990 size_t buffer_len;
991 size_t array_len;
993 unsigned int i;
994 int rc;
995
996 /* Do nothing if no scratchpad buffers are used */
997 if ( ! scratch->count )
998 return 0;
999
1000 /* Allocate scratchpad buffers */
1001 buffer_len = ( scratch->count * xhci->pagesize );
1002 scratch->buffer = dma_umalloc ( xhci->dma, &scratch->buffer_map,
1003 buffer_len, xhci->pagesize );
1004 if ( ! scratch->buffer ) {
1005 DBGC ( xhci, "XHCI %s could not allocate scratchpad buffers\n",
1006 xhci->name );
1007 rc = -ENOMEM;
1008 goto err_alloc;
1009 }
1010 memset ( scratch->buffer, 0, buffer_len );
1011
1012 /* Allocate scratchpad array */
1013 array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
1014 scratch->array = dma_alloc ( xhci->dma, &scratch->array_map,
1015 array_len, xhci_align ( array_len ) );
1016 if ( ! scratch->array ) {
1017 DBGC ( xhci, "XHCI %s could not allocate scratchpad buffer "
1018 "array\n", xhci->name );
1019 rc = -ENOMEM;
1020 goto err_alloc_array;
1021 }
1022
1023 /* Populate scratchpad array */
1024 addr = dma ( &scratch->buffer_map, scratch->buffer );
1025 for ( i = 0 ; i < scratch->count ; i++ ) {
1026 scratch->array[i] = cpu_to_le64 ( addr );
1027 addr += xhci->pagesize;
1028 }
1029
1030 /* Set scratchpad array pointer */
1031 assert ( xhci->dcbaa.context != NULL );
1032 xhci->dcbaa.context[0] = cpu_to_le64 ( dma ( &scratch->array_map,
1033 scratch->array ) );
1034
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 ) );
1040 return 0;
1041
1042 dma_free ( &scratch->array_map, scratch->array, array_len );
1043 err_alloc_array:
1044 dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
1045 err_alloc:
1046 return rc;
1047}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
uint32_t addr
Buffer address.
Definition dwmac.h:9
#define cpu_to_le64(value)
Definition byteswap.h:109
void dma_ufree(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
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.
Scratchpad buffer.
Definition xhci.h:1055
struct dma_mapping buffer_map
Buffer DMA mapping.
Definition xhci.h:1061
struct dma_mapping array_map
Array DMA mapping.
Definition xhci.h:1065
void * buffer
Scratchpad buffer area.
Definition xhci.h:1059
uint64_t * array
Scratchpad array.
Definition xhci.h:1063

References addr, xhci_scratchpad::array, xhci_scratchpad::array_map, assert, xhci_scratchpad::buffer, xhci_scratchpad::buffer_map, xhci_dcbaa::context, xhci_scratchpad::count, cpu_to_le64, DBGC, DBGC2, xhci_device::dcbaa, dma(), xhci_device::dma, dma_alloc(), dma_free(), dma_ufree(), dma_umalloc(), ENOMEM, memset(), xhci_device::name, NULL, xhci_device::pagesize, rc, xhci_device::scratch, and xhci_align().

Referenced by xhci_bus_open().

◆ xhci_scratchpad_free()

void xhci_scratchpad_free ( struct xhci_device * xhci)
static

Free scratchpad buffers.

Parameters
xhcixHCI device

Definition at line 1054 of file xhci.c.

1054 {
1055 struct xhci_scratchpad *scratch = &xhci->scratch;
1056 size_t array_len;
1057 size_t buffer_len;
1058
1059 /* Do nothing if no scratchpad buffers are used */
1060 if ( ! scratch->count )
1061 return;
1062
1063 /* Clear scratchpad array pointer */
1064 assert ( xhci->dcbaa.context != NULL );
1065 xhci->dcbaa.context[0] = 0;
1066
1067 /* Free scratchpad array */
1068 array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
1069 dma_free ( &scratch->array_map, scratch->array, array_len );
1070
1071 /* Free scratchpad buffers */
1072 buffer_len = ( scratch->count * xhci->pagesize );
1073 dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
1074}

References xhci_scratchpad::array, xhci_scratchpad::array_map, assert, xhci_scratchpad::buffer, xhci_scratchpad::buffer_map, xhci_dcbaa::context, xhci_scratchpad::count, xhci_device::dcbaa, dma_free(), dma_ufree(), NULL, xhci_device::pagesize, and xhci_device::scratch.

Referenced by xhci_bus_close(), and xhci_bus_open().

◆ xhci_run()

void xhci_run ( struct xhci_device * xhci)
static

Start xHCI device.

Parameters
xhcixHCI device

Definition at line 1088 of file xhci.c.

1088 {
1089 uint32_t config;
1090 uint32_t usbcmd;
1091
1092 /* Configure number of device slots */
1093 config = readl ( xhci->op + XHCI_OP_CONFIG );
1095 config |= XHCI_CONFIG_MAX_SLOTS_EN ( xhci->slots );
1096 writel ( config, xhci->op + XHCI_OP_CONFIG );
1097
1098 /* Set run/stop bit */
1099 usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1100 usbcmd |= XHCI_USBCMD_RUN;
1101 writel ( usbcmd, xhci->op + XHCI_OP_USBCMD );
1102}
#define XHCI_CONFIG_MAX_SLOTS_EN_MASK
Maximum device slots enabled mask.
Definition xhci.h:200
#define XHCI_CONFIG_MAX_SLOTS_EN(slots)
Maximum device slots enabled.
Definition xhci.h:197

References xhci_device::op, readl, xhci_device::slots, writel, XHCI_CONFIG_MAX_SLOTS_EN, XHCI_CONFIG_MAX_SLOTS_EN_MASK, XHCI_OP_CONFIG, XHCI_OP_USBCMD, and XHCI_USBCMD_RUN.

Referenced by xhci_bus_open().

◆ xhci_stop()

int xhci_stop ( struct xhci_device * xhci)
static

Stop xHCI device.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1110 of file xhci.c.

1110 {
1111 uint32_t usbcmd;
1112 uint32_t usbsts;
1113 unsigned int i;
1114
1115 /* Clear run/stop bit */
1116 usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1117 usbcmd &= ~XHCI_USBCMD_RUN;
1118 writel ( usbcmd, xhci->op + XHCI_OP_USBCMD );
1119
1120 /* Wait for device to stop */
1121 for ( i = 0 ; i < XHCI_STOP_MAX_WAIT_MS ; i++ ) {
1122
1123 /* Check if device is stopped */
1124 usbsts = readl ( xhci->op + XHCI_OP_USBSTS );
1125 if ( usbsts & XHCI_USBSTS_HCH )
1126 return 0;
1127
1128 /* Delay */
1129 mdelay ( 1 );
1130 }
1131
1132 DBGC ( xhci, "XHCI %s timed out waiting for stop\n", xhci->name );
1133 return -ETIMEDOUT;
1134}
#define ETIMEDOUT
Connection timed out.
Definition errno.h:713
#define XHCI_STOP_MAX_WAIT_MS
Maximum time to wait for host controller to stop.
Definition xhci.h:992

References DBGC, ETIMEDOUT, mdelay(), xhci_device::name, xhci_device::op, readl, writel, XHCI_OP_USBCMD, XHCI_OP_USBSTS, XHCI_STOP_MAX_WAIT_MS, XHCI_USBCMD_RUN, and XHCI_USBSTS_HCH.

Referenced by xhci_bus_close(), xhci_bus_open(), and xhci_reset().

◆ xhci_reset()

int xhci_reset ( struct xhci_device * xhci)
static

Reset xHCI device.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1142 of file xhci.c.

1142 {
1143 uint32_t usbcmd;
1144 unsigned int i;
1145 int rc;
1146
1147 /* The xHCI specification states that resetting a running
1148 * device may result in undefined behaviour, so try stopping
1149 * it first.
1150 */
1151 if ( ( rc = xhci_stop ( xhci ) ) != 0 ) {
1152 /* Ignore errors and attempt to reset the device anyway */
1153 }
1154
1155 /* Reset device */
1157
1158 /* Wait for reset to complete */
1159 for ( i = 0 ; i < XHCI_RESET_MAX_WAIT_MS ; i++ ) {
1160
1161 /* Check if reset is complete */
1162 usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1163 if ( ! ( usbcmd & XHCI_USBCMD_HCRST ) )
1164 return 0;
1165
1166 /* Delay */
1167 mdelay ( 1 );
1168 }
1169
1170 DBGC ( xhci, "XHCI %s timed out waiting for reset\n", xhci->name );
1171 return -ETIMEDOUT;
1172}
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition xhci.c:1110
#define XHCI_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
Definition xhci.h:998

References DBGC, ETIMEDOUT, mdelay(), xhci_device::name, xhci_device::op, rc, readl, writel, XHCI_OP_USBCMD, XHCI_RESET_MAX_WAIT_MS, xhci_stop(), and XHCI_USBCMD_HCRST.

Referenced by xhci_fail(), xhci_register(), and xhci_unregister().

◆ xhci_fail()

int xhci_fail ( struct xhci_device * xhci)
static

Mark xHCI device as permanently failed.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1180 of file xhci.c.

1180 {
1181 size_t len;
1182 int rc;
1183
1184 /* Mark command mechanism as permanently failed */
1185 xhci->failed = 1;
1186
1187 /* Reset device */
1188 if ( ( rc = xhci_reset ( xhci ) ) != 0 )
1189 return rc;
1190
1191 /* Discard DCBAA entries since DCBAAP has been cleared */
1192 assert ( xhci->dcbaa.context != NULL );
1193 len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
1194 memset ( xhci->dcbaa.context, 0, len );
1195
1196 return 0;
1197}
int failed
Command mechanism has permanently failed.
Definition xhci.h:1123
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition xhci.c:1142

References assert, xhci_dcbaa::context, xhci_device::dcbaa, xhci_device::failed, len, memset(), NULL, rc, xhci_device::slots, and xhci_reset().

Referenced by xhci_abort(), and xhci_remove().

◆ xhci_ring_alloc()

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 )
static

Allocate transfer request block ring.

Parameters
xhcixHCI device
ringTRB ring
shiftRing size (log2)
slotDevice slot
targetDoorbell target
streamDoorbell stream ID
Return values
rcReturn status code

Definition at line 1217 of file xhci.c.

1220 {
1221 struct xhci_trb_link *link;
1222 unsigned int count;
1223 int rc;
1224
1225 /* Sanity check */
1226 assert ( shift > 0 );
1227
1228 /* Initialise structure */
1229 memset ( ring, 0, sizeof ( *ring ) );
1230 ring->shift = shift;
1231 count = ( 1U << shift );
1232 ring->mask = ( count - 1 );
1233 ring->len = ( ( count + 1 /* Link TRB */ ) * sizeof ( ring->trb[0] ) );
1234 ring->db = ( xhci->db + ( slot * sizeof ( ring->dbval ) ) );
1235 ring->dbval = XHCI_DBVAL ( target, stream );
1236
1237 /* Allocate I/O buffers */
1238 ring->iobuf = zalloc ( count * sizeof ( ring->iobuf[0] ) );
1239 if ( ! ring->iobuf ) {
1240 rc = -ENOMEM;
1241 goto err_alloc_iobuf;
1242 }
1243
1244 /* Allocate TRBs */
1245 ring->trb = dma_alloc ( xhci->dma, &ring->map, ring->len,
1246 xhci_align ( ring->len ) );
1247 if ( ! ring->trb ) {
1248 rc = -ENOMEM;
1249 goto err_alloc_trb;
1250 }
1251 memset ( ring->trb, 0, ring->len );
1252
1253 /* Initialise Link TRB */
1254 link = &ring->trb[count].link;
1255 link->next = cpu_to_le64 ( dma ( &ring->map, ring->trb ) );
1256 link->flags = XHCI_TRB_TC;
1257 link->type = XHCI_TRB_LINK;
1258 ring->link = link;
1259
1260 return 0;
1261
1262 dma_free ( &ring->map, ring->trb, ring->len );
1263 err_alloc_trb:
1264 free ( ring->iobuf );
1265 err_alloc_iobuf:
1266 return rc;
1267}
u32 link
Link to next descriptor.
Definition ar9003_mac.h:1
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:718
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
unsigned int shift
Ring size (log2).
Definition xhci.h:848
struct xhci_trb_link * link
Link TRB (if applicable).
Definition xhci.h:862
void * db
Doorbell register.
Definition xhci.h:865
struct io_buffer ** iobuf
I/O buffers.
Definition xhci.h:853
union xhci_trb * trb
Transfer request blocks.
Definition xhci.h:856
size_t len
Length of transfer request blocks.
Definition xhci.h:858
unsigned int mask
Ring counter mask.
Definition xhci.h:850
uint32_t dbval
Doorbell register value.
Definition xhci.h:867
struct dma_mapping map
DMA mapping.
Definition xhci.h:860
struct xhci_trb_link link
Link TRB.
Definition xhci.h:699
#define XHCI_DBVAL(target, stream)
Calculate doorbell register value.
Definition xhci.h:891
#define XHCI_TRB_LINK
A link transfer request block.
Definition xhci.h:460
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
Definition xhci.h:332

References assert, count, cpu_to_le64, xhci_device::db, xhci_trb_ring::db, xhci_trb_ring::dbval, dma(), xhci_device::dma, dma_alloc(), dma_free(), ENOMEM, free, xhci_trb_ring::iobuf, xhci_trb_ring::len, link, xhci_trb::link, xhci_trb_ring::link, xhci_trb_ring::map, xhci_trb_ring::mask, memset(), rc, xhci_trb_ring::shift, slot, xhci_trb_ring::trb, xhci_align(), XHCI_DBVAL, XHCI_TRB_LINK, XHCI_TRB_TC, and zalloc().

Referenced by xhci_command_alloc(), and xhci_endpoint_open().

◆ xhci_ring_reset()

void xhci_ring_reset ( struct xhci_trb_ring * ring)
static

Reset transfer request block ring.

Parameters
ringTRB ring

Definition at line 1274 of file xhci.c.

1274 {
1275 unsigned int count = ( 1U << ring->shift );
1276
1277 /* Reset producer and consumer counters */
1278 ring->prod = 0;
1279 ring->cons = 0;
1280
1281 /* Reset TRBs (except Link TRB) */
1282 memset ( ring->trb, 0, ( count * sizeof ( ring->trb[0] ) ) );
1283}
unsigned int cons
Consumer counter.
Definition xhci.h:846
unsigned int prod
Producer counter.
Definition xhci.h:844

References xhci_trb_ring::cons, count, memset(), xhci_trb_ring::prod, xhci_trb_ring::shift, and xhci_trb_ring::trb.

Referenced by xhci_abort().

◆ xhci_ring_free()

void xhci_ring_free ( struct xhci_trb_ring * ring)
static

Free transfer request block ring.

Parameters
ringTRB ring

Definition at line 1290 of file xhci.c.

1290 {
1291 unsigned int count = ( 1U << ring->shift );
1292 unsigned int i;
1293
1294 /* Sanity checks */
1295 assert ( ring->cons == ring->prod );
1296 for ( i = 0 ; i < count ; i++ )
1297 assert ( ring->iobuf[i] == NULL );
1298
1299 /* Free TRBs */
1300 dma_free ( &ring->map, ring->trb, ring->len );
1301
1302 /* Free I/O buffers */
1303 free ( ring->iobuf );
1304}

References assert, xhci_trb_ring::cons, count, dma_free(), free, xhci_trb_ring::iobuf, xhci_trb_ring::len, xhci_trb_ring::map, NULL, xhci_trb_ring::prod, xhci_trb_ring::shift, and xhci_trb_ring::trb.

Referenced by xhci_command_alloc(), xhci_command_free(), xhci_endpoint_close(), and xhci_endpoint_open().

◆ xhci_enqueue()

int xhci_enqueue ( struct xhci_trb_ring * ring,
struct io_buffer * iobuf,
const union xhci_trb * trb )
static

Enqueue a transfer request block.

Parameters
ringTRB ring
iobufI/O buffer (if any)
trbTransfer request block (with empty Cycle flag)
Return values
rcReturn status code

This operation does not implicitly ring the doorbell register.

Definition at line 1316 of file xhci.c.

1317 {
1318 union xhci_trb *dest;
1319 unsigned int prod;
1320 unsigned int mask;
1321 unsigned int index;
1322 unsigned int cycle;
1323
1324 /* Sanity check */
1325 assert ( ! ( trb->common.flags & XHCI_TRB_C ) );
1326
1327 /* Fail if ring is full */
1328 if ( ! xhci_ring_remaining ( ring ) )
1329 return -ENOBUFS;
1330
1331 /* Update producer counter (and link TRB, if applicable) */
1332 prod = ring->prod++;
1333 mask = ring->mask;
1334 cycle = ( ( ~( prod >> ring->shift ) ) & XHCI_TRB_C );
1335 index = ( prod & mask );
1336 if ( index == 0 )
1337 ring->link->flags = ( XHCI_TRB_TC | ( cycle ^ XHCI_TRB_C ) );
1338
1339 /* Record I/O buffer */
1340 ring->iobuf[index] = iobuf;
1341
1342 /* Enqueue TRB */
1343 dest = &ring->trb[index];
1344 dest->template.parameter = trb->template.parameter;
1345 dest->template.status = trb->template.status;
1346 wmb();
1347 dest->template.control = ( trb->template.control |
1348 cpu_to_le32 ( cycle ) );
1349
1350 return 0;
1351}
long index
Definition bigint.h:30
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" retur dest)
Definition string.h:151
#define ENOBUFS
No buffer space available.
Definition errno.h:542
#define wmb()
Definition io.h:546
uint8_t flags
Flags.
Definition xhci.h:321
uint32_t status
Status.
Definition xhci.h:309
uint64_t parameter
Parameter.
Definition xhci.h:307
uint32_t control
Control.
Definition xhci.h:311
A transfer request block.
Definition xhci.h:685
struct xhci_trb_template template
Template.
Definition xhci.h:687
struct xhci_trb_common common
Common fields.
Definition xhci.h:689
static unsigned int xhci_ring_remaining(struct xhci_trb_ring *ring)
Calculate space remaining in TRB ring.
Definition xhci.h:915
#define XHCI_TRB_C
Transfer request block cycle bit flag.
Definition xhci.h:329

References assert, xhci_trb::common, xhci_trb_template::control, cpu_to_le32, dest, ENOBUFS, xhci_trb_common::flags, xhci_trb_link::flags, index, xhci_trb_ring::iobuf, xhci_trb_ring::link, xhci_trb_ring::mask, xhci_trb_template::parameter, xhci_trb_ring::prod, xhci_trb_ring::shift, xhci_trb_template::status, xhci_trb::template, xhci_trb_ring::trb, wmb, xhci_ring_remaining(), XHCI_TRB_C, and XHCI_TRB_TC.

Referenced by xhci_command(), and xhci_enqueue_multi().

◆ xhci_dequeue()

struct io_buffer * xhci_dequeue ( struct xhci_trb_ring * ring)
static

Dequeue a transfer request block.

Parameters
ringTRB ring
Return values
iobufI/O buffer

Definition at line 1359 of file xhci.c.

1359 {
1360 struct io_buffer *iobuf;
1361 unsigned int cons;
1362 unsigned int mask;
1363 unsigned int index;
1364
1365 /* Sanity check */
1366 assert ( xhci_ring_fill ( ring ) != 0 );
1367
1368 /* Update consumer counter */
1369 cons = ring->cons++;
1370 mask = ring->mask;
1371 index = ( cons & mask );
1372
1373 /* Retrieve I/O buffer */
1374 iobuf = ring->iobuf[index];
1375 ring->iobuf[index] = NULL;
1376
1377 return iobuf;
1378}
uint16_t cons
Consumer index.
Definition ena.h:11
A persistent I/O buffer.
Definition iobuf.h:98
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition xhci.h:900

References assert, cons, xhci_trb_ring::cons, index, xhci_trb_ring::iobuf, xhci_trb_ring::mask, NULL, and xhci_ring_fill().

Referenced by xhci_complete(), and xhci_dequeue_multi().

◆ xhci_enqueue_multi()

int xhci_enqueue_multi ( struct xhci_trb_ring * ring,
struct io_buffer * iobuf,
const union xhci_trb * trbs,
unsigned int count )
static

Enqueue multiple transfer request blocks.

Parameters
ringTRB ring
iobufI/O buffer
trbsTransfer request blocks (with empty Cycle flag)
countNumber of transfer request blocks
Return values
rcReturn status code

This operation does not implicitly ring the doorbell register.

Definition at line 1391 of file xhci.c.

1394 {
1395 const union xhci_trb *trb = trbs;
1396 int rc;
1397
1398 /* Sanity check */
1399 assert ( iobuf != NULL );
1400
1401 /* Fail if ring does not have sufficient space */
1402 if ( xhci_ring_remaining ( ring ) < count )
1403 return -ENOBUFS;
1404
1405 /* Enqueue each TRB, recording the I/O buffer with the final TRB */
1406 while ( count-- ) {
1407 rc = xhci_enqueue ( ring, ( count ? NULL : iobuf ), trb++ );
1408 assert ( rc == 0 ); /* Should never be able to fail */
1409 }
1410
1411 return 0;
1412}
static int xhci_enqueue(struct xhci_trb_ring *ring, struct io_buffer *iobuf, const union xhci_trb *trb)
Enqueue a transfer request block.
Definition xhci.c:1316

References assert, count, ENOBUFS, NULL, rc, xhci_enqueue(), and xhci_ring_remaining().

Referenced by xhci_endpoint_message(), and xhci_endpoint_stream().

◆ xhci_dequeue_multi()

struct io_buffer * xhci_dequeue_multi ( struct xhci_trb_ring * ring)
static

Dequeue multiple transfer request blocks.

Parameters
ringTRB ring
Return values
iobufI/O buffer

Definition at line 1420 of file xhci.c.

1420 {
1421 struct io_buffer *iobuf;
1422
1423 /* Dequeue TRBs until we reach the final TRB for an I/O buffer */
1424 do {
1425 iobuf = xhci_dequeue ( ring );
1426 } while ( iobuf == NULL );
1427
1428 return iobuf;
1429}
static struct io_buffer * xhci_dequeue(struct xhci_trb_ring *ring)
Dequeue a transfer request block.
Definition xhci.c:1359

References NULL, and xhci_dequeue().

Referenced by xhci_endpoint_close(), and xhci_transfer().

◆ xhci_doorbell()

void xhci_doorbell ( struct xhci_trb_ring * ring)
inlinestatic

Ring doorbell register.

Parameters
ringTRB ring

Definition at line 1437 of file xhci.c.

1437 {
1438
1439 wmb();
1440 writel ( ring->dbval, ring->db );
1441}

References xhci_trb_ring::db, xhci_trb_ring::dbval, wmb, and writel.

Referenced by xhci_command(), xhci_endpoint_message(), xhci_endpoint_reset(), and xhci_endpoint_stream().

◆ xhci_command_alloc()

int xhci_command_alloc ( struct xhci_device * xhci)
static

Allocate command ring.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1456 of file xhci.c.

1456 {
1457 physaddr_t crp;
1458 int rc;
1459
1460 /* Allocate TRB ring */
1461 if ( ( rc = xhci_ring_alloc ( xhci, &xhci->command, XHCI_CMD_TRBS_LOG2,
1462 0, 0, 0 ) ) != 0 )
1463 goto err_ring_alloc;
1464
1465 /* Program command ring control register */
1466 crp = dma ( &xhci->command.map, xhci->command.trb );
1467 if ( ( rc = xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ),
1468 xhci->op + XHCI_OP_CRCR ) ) != 0 )
1469 goto err_writeq;
1470
1471 DBGC2 ( xhci, "XHCI %s CRCR at [%08lx,%08lx)\n", xhci->name,
1472 virt_to_phys ( xhci->command.trb ),
1473 ( virt_to_phys ( xhci->command.trb ) + xhci->command.len ) );
1474 return 0;
1475
1476 err_writeq:
1477 xhci_ring_free ( &xhci->command );
1478 err_ring_alloc:
1479 return rc;
1480}
struct xhci_trb_ring command
Command ring.
Definition xhci.h:1117
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.
Definition xhci.c:1217
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition xhci.c:1290
#define XHCI_CRCR_RCS
Command ring cycle state.
Definition xhci.h:182
#define XHCI_CMD_TRBS_LOG2
Number of TRBs (excluding Link TRB) in the command ring.
Definition xhci.h:968
#define XHCI_OP_CRCR
Command ring control register.
Definition xhci.h:179

References xhci_device::command, DBGC2, dma(), xhci_trb_ring::len, xhci_trb_ring::map, xhci_device::name, xhci_device::op, rc, xhci_trb_ring::trb, XHCI_CMD_TRBS_LOG2, XHCI_CRCR_RCS, XHCI_OP_CRCR, xhci_ring_alloc(), xhci_ring_free(), and xhci_writeq().

Referenced by xhci_bus_open().

◆ xhci_command_free()

void xhci_command_free ( struct xhci_device * xhci)
static

Free command ring.

Parameters
xhcixHCI device

Definition at line 1487 of file xhci.c.

1487 {
1488
1489 /* Sanity check */
1490 assert ( ( readl ( xhci->op + XHCI_OP_CRCR ) & XHCI_CRCR_CRR ) == 0 );
1491
1492 /* Clear command ring control register */
1493 xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_CRCR );
1494
1495 /* Free TRB ring */
1496 xhci_ring_free ( &xhci->command );
1497}
#define XHCI_CRCR_CRR
Command ring running.
Definition xhci.h:188

References assert, xhci_device::command, xhci_device::op, readl, XHCI_CRCR_CRR, XHCI_OP_CRCR, xhci_ring_free(), and xhci_writeq().

Referenced by xhci_bus_close(), and xhci_bus_open().

◆ xhci_event_alloc()

int xhci_event_alloc ( struct xhci_device * xhci)
static

Allocate event ring.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1505 of file xhci.c.

1505 {
1506 struct xhci_event_ring *event = &xhci->event;
1507 unsigned int count;
1508 size_t len;
1509 int rc;
1510
1511 /* Allocate event ring */
1512 count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
1513 len = ( count * sizeof ( event->trb[0] ) );
1514 event->trb = dma_alloc ( xhci->dma, &event->trb_map, len,
1515 xhci_align ( len ) );
1516 if ( ! event->trb ) {
1517 rc = -ENOMEM;
1518 goto err_alloc_trb;
1519 }
1520 memset ( event->trb, 0, len );
1521
1522 /* Allocate event ring segment table */
1523 event->segment = dma_alloc ( xhci->dma, &event->segment_map,
1524 sizeof ( event->segment[0] ),
1525 xhci_align ( sizeof (event->segment[0])));
1526 if ( ! event->segment ) {
1527 rc = -ENOMEM;
1528 goto err_alloc_segment;
1529 }
1530 memset ( event->segment, 0, sizeof ( event->segment[0] ) );
1531 event->segment[0].base = cpu_to_le64 ( dma ( &event->trb_map,
1532 event->trb ) );
1533 event->segment[0].count = cpu_to_le32 ( count );
1534
1535 /* Program event ring registers */
1536 writel ( 1, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
1537 if ( ( rc = xhci_writeq ( xhci, dma ( &event->trb_map, event->trb ),
1538 xhci->run + XHCI_RUN_ERDP ( 0 ) ) ) != 0 )
1539 goto err_writeq_erdp;
1540 if ( ( rc = xhci_writeq ( xhci,
1541 dma ( &event->segment_map, event->segment ),
1542 xhci->run + XHCI_RUN_ERSTBA ( 0 ) ) ) != 0 )
1543 goto err_writeq_erstba;
1544
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] ) ) );
1551 return 0;
1552
1553 xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
1554 err_writeq_erstba:
1555 xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
1556 err_writeq_erdp:
1557 dma_free ( &event->segment_map, event->segment,
1558 sizeof ( event->segment[0] ) );
1559 err_alloc_segment:
1560 dma_free ( &event->trb_map, event->trb, len );
1561 err_alloc_trb:
1562 return rc;
1563}
struct xhci_event_ring event
Event ring.
Definition xhci.h:1119
An event ring.
Definition xhci.h:871
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition xhci.h:296
#define XHCI_RUN_ERSTBA(intr)
Event ring segment table base address register.
Definition xhci.h:299
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition xhci.h:302
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition xhci.h:974

References count, cpu_to_le32, cpu_to_le64, DBGC2, dma(), xhci_device::dma, dma_alloc(), dma_free(), ENOMEM, xhci_device::event, len, memset(), xhci_device::name, rc, xhci_device::run, writel, xhci_align(), XHCI_EVENT_TRBS_LOG2, XHCI_RUN_ERDP, XHCI_RUN_ERSTBA, XHCI_RUN_ERSTSZ, and xhci_writeq().

Referenced by xhci_bus_open().

◆ xhci_event_free()

void xhci_event_free ( struct xhci_device * xhci)
static

Free event ring.

Parameters
xhcixHCI device

Definition at line 1570 of file xhci.c.

1570 {
1571 struct xhci_event_ring *event = &xhci->event;
1572 unsigned int count;
1573 size_t len;
1574
1575 /* Clear event ring registers */
1576 writel ( 0, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
1577 xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
1578 xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
1579
1580 /* Free event ring segment table */
1581 dma_free ( &event->segment_map, event->segment,
1582 sizeof ( event->segment[0] ) );
1583
1584 /* Free event ring */
1585 count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
1586 len = ( count * sizeof ( event->trb[0] ) );
1587 dma_free ( &event->trb_map, event->trb, len );
1588}

References count, dma_free(), xhci_device::event, len, xhci_device::run, writel, XHCI_EVENT_TRBS_LOG2, XHCI_RUN_ERDP, XHCI_RUN_ERSTBA, XHCI_RUN_ERSTSZ, and xhci_writeq().

Referenced by xhci_bus_close(), and xhci_bus_open().

◆ xhci_transfer()

void xhci_transfer ( struct xhci_device * xhci,
struct xhci_trb_transfer * trb )
static

Handle transfer event.

Parameters
xhcixHCI device
trbTransfer event TRB

Definition at line 1596 of file xhci.c.

1597 {
1598 struct xhci_slot *slot;
1599 struct xhci_endpoint *endpoint;
1600 struct io_buffer *iobuf;
1601 uint32_t cmplt;
1602 unsigned int code;
1603 int rc;
1604
1605 /* Profile transfer events */
1606 profile_start ( &xhci_transfer_profiler );
1607
1608 /* Identify slot */
1609 if ( ( trb->slot > xhci->slots ) ||
1610 ( ( slot = xhci->slot[trb->slot] ) == NULL ) ) {
1611 DBGC ( xhci, "XHCI %s transfer event invalid slot %d:\n",
1612 xhci->name, trb->slot );
1613 DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1614 return;
1615 }
1616
1617 /* Identify endpoint */
1618 if ( ( trb->endpoint >= XHCI_CTX_END ) ||
1619 ( ( endpoint = slot->endpoint[trb->endpoint] ) == NULL ) ) {
1620 DBGC ( xhci, "XHCI %s slot %d transfer event invalid epid "
1621 "%d:\n", xhci->name, slot->id, trb->endpoint );
1622 DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1623 return;
1624 }
1625
1626 /* Dequeue TRB(s) */
1627 iobuf = xhci_dequeue_multi ( &endpoint->ring );
1628 assert ( iobuf != NULL );
1629
1630 /* Unmap I/O buffer */
1631 iob_unmap ( iobuf );
1632
1633 /* Parse completion */
1634 cmplt = le32_to_cpu ( trb->cmplt );
1635 code = XHCI_CMPLT_CODE ( cmplt );
1636
1637 /* Check for errors */
1638 if ( ! ( ( code == XHCI_CMPLT_SUCCESS ) ||
1639 ( code == XHCI_CMPLT_SHORT ) ) ) {
1640
1641 /* Construct error */
1642 rc = -ECODE ( code );
1643 DBGC ( xhci, "XHCI %s slot %d ctx %d failed (code %d): %s\n",
1644 xhci->name, slot->id, endpoint->ctx, code,
1645 strerror ( rc ) );
1646 DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1647
1648 /* Sanity check */
1649 assert ( ( endpoint->context->state & XHCI_ENDPOINT_STATE_MASK )
1651
1652 /* Report failure to USB core */
1653 usb_complete_err ( endpoint->ep, iobuf, rc );
1654 return;
1655 }
1656
1657 /* Record actual transfer size */
1658 iob_unput ( iobuf, XHCI_CMPLT_RESIDUAL ( cmplt ) );
1659
1660 /* Sanity check (for successful completions only) */
1661 assert ( xhci_ring_consumed ( &endpoint->ring ) ==
1662 le64_to_cpu ( trb->transfer ) );
1663
1664 /* Report completion to USB core */
1665 usb_complete ( endpoint->ep, iobuf );
1666 profile_stop ( &xhci_transfer_profiler );
1667}
#define DBGC_HDA(...)
Definition compiler.h:531
#define le64_to_cpu(value)
Definition byteswap.h:115
#define le32_to_cpu(value)
Definition byteswap.h:114
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition profile.h:174
static void profile_start(struct profiler *profiler)
Start profiling.
Definition profile.h:161
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error).
Definition usb.h:1097
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition iobuf.h:339
#define iob_unput(iobuf, len)
Definition iobuf.h:200
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition xhci.h:1126
uint8_t state
Endpoint state.
Definition xhci.h:773
An xHCI endpoint.
Definition xhci.h:1164
struct usb_endpoint * ep
USB endpoint.
Definition xhci.h:1170
struct xhci_trb_ring ring
Transfer ring.
Definition xhci.h:1180
unsigned int ctx
Context index.
Definition xhci.h:1172
struct xhci_endpoint_context * context
Endpoint context.
Definition xhci.h:1178
An xHCI device slot.
Definition xhci.h:1136
uint8_t endpoint
Endpoint ID.
Definition xhci.h:599
uint32_t cmplt
Completion status.
Definition xhci.h:593
uint8_t slot
Slot ID.
Definition xhci.h:601
uint64_t transfer
Transfer TRB pointer.
Definition xhci.h:591
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error).
Definition usb.c:586
static struct io_buffer * xhci_dequeue_multi(struct xhci_trb_ring *ring)
Dequeue multiple transfer request blocks.
Definition xhci.c:1420
#define ECODE(code)
Definition xhci.c:234
@ XHCI_ENDPOINT_RUNNING
Endpoint is running.
Definition xhci.h:801
@ XHCI_CMPLT_SUCCESS
Success.
Definition xhci.h:637
@ XHCI_CMPLT_SHORT
Short packet.
Definition xhci.h:639
#define XHCI_CMPLT_RESIDUAL(cmplt)
Residual bytes not transferred.
Definition xhci.h:611
#define XHCI_CTX_END
End of contexts.
Definition xhci.h:956
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
Definition xhci.h:938
#define XHCI_ENDPOINT_STATE_MASK
Endpoint state mask.
Definition xhci.h:811
#define XHCI_CMPLT_CODE(cmplt)
Completion code.
Definition xhci.h:608

References assert, xhci_trb_transfer::cmplt, code, xhci_endpoint::context, xhci_endpoint::ctx, DBGC, DBGC_HDA, ECODE, xhci_trb_transfer::endpoint, xhci_endpoint::ep, iob_unmap(), iob_unput, le32_to_cpu, le64_to_cpu, xhci_device::name, NULL, profile_start(), profile_stop(), rc, xhci_endpoint::ring, slot, xhci_device::slot, xhci_trb_transfer::slot, xhci_device::slots, xhci_endpoint_context::state, strerror(), xhci_trb_transfer::transfer, usb_complete(), usb_complete_err(), XHCI_CMPLT_CODE, XHCI_CMPLT_RESIDUAL, XHCI_CMPLT_SHORT, XHCI_CMPLT_SUCCESS, XHCI_CTX_END, xhci_dequeue_multi(), XHCI_ENDPOINT_RUNNING, XHCI_ENDPOINT_STATE_MASK, and xhci_ring_consumed().

Referenced by xhci_event_poll().

◆ xhci_complete()

void xhci_complete ( struct xhci_device * xhci,
struct xhci_trb_complete * trb )
static

Handle command completion event.

Parameters
xhcixHCI device
trbCommand completion event

Definition at line 1675 of file xhci.c.

1676 {
1677 int rc;
1678
1679 /* Ignore "command ring stopped" notifications */
1680 if ( trb->code == XHCI_CMPLT_CMD_STOPPED ) {
1681 DBGC2 ( xhci, "XHCI %s command ring stopped\n", xhci->name );
1682 return;
1683 }
1684
1685 /* Ignore unexpected completions */
1686 if ( ! xhci->pending ) {
1687 rc = -ECODE ( trb->code );
1688 DBGC ( xhci, "XHCI %s unexpected completion (code %d): %s\n",
1689 xhci->name, trb->code, strerror ( rc ) );
1690 DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1691 return;
1692 }
1693
1694 /* Dequeue command TRB */
1695 xhci_dequeue ( &xhci->command );
1696
1697 /* Sanity check */
1698 assert ( xhci_ring_consumed ( &xhci->command ) ==
1699 le64_to_cpu ( trb->command ) );
1700
1701 /* Record completion */
1702 memcpy ( xhci->pending, trb, sizeof ( *xhci->pending ) );
1703 xhci->pending = NULL;
1704}
void * memcpy(void *dest, const void *src, size_t len) __nonnull
union xhci_trb * pending
Current command (if any).
Definition xhci.h:1121
uint8_t code
Completion code.
Definition xhci.h:620
uint64_t command
Command TRB pointer.
Definition xhci.h:616
@ XHCI_CMPLT_CMD_STOPPED
Command ring stopped.
Definition xhci.h:641

References assert, xhci_trb_complete::code, xhci_device::command, xhci_trb_complete::command, DBGC, DBGC2, DBGC_HDA, ECODE, le64_to_cpu, memcpy(), xhci_device::name, NULL, xhci_device::pending, rc, strerror(), XHCI_CMPLT_CMD_STOPPED, xhci_dequeue(), and xhci_ring_consumed().

Referenced by xhci_event_poll().

◆ xhci_port_status()

void xhci_port_status ( struct xhci_device * xhci,
struct xhci_trb_port_status * trb )
static

Handle port status event.

Parameters
xhcixHCI device
trbPort status event

Definition at line 1712 of file xhci.c.

1713 {
1714 struct usb_port *port = usb_port ( xhci->bus->hub, trb->port );
1715 uint32_t portsc;
1716
1717 /* Sanity check */
1718 assert ( ( trb->port > 0 ) && ( trb->port <= xhci->ports ) );
1719
1720 /* Record disconnections and clear changes */
1721 portsc = readl ( xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1722 port->disconnected |= ( portsc & XHCI_PORTSC_CSC );
1724 writel ( portsc, xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1725
1726 /* Report port status change */
1728}
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition usb.h:970
struct usb_hub * hub
Root hub.
Definition usb.h:1005
A USB port.
Definition usb.h:823
struct usb_bus * bus
USB bus.
Definition xhci.h:1129
uint8_t port
Port ID.
Definition xhci.h:649
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition usb.c:1857
#define XHCI_PORTSC_CSC
Connect status change.
Definition xhci.h:249
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
Definition xhci.h:284
#define XHCI_PORTSC_CHANGE
Port status change mask.
Definition xhci.h:270

References assert, xhci_device::bus, usb_bus::hub, xhci_device::op, port, xhci_trb_port_status::port, xhci_device::ports, readl, usb_port(), usb_port_changed(), writel, XHCI_OP_PORTSC, XHCI_PORTSC_CHANGE, XHCI_PORTSC_CSC, and XHCI_PORTSC_PRESERVE.

Referenced by xhci_event_poll().

◆ xhci_host_controller()

void xhci_host_controller ( struct xhci_device * xhci,
struct xhci_trb_host_controller * trb )
static

Handle host controller event.

Parameters
xhcixHCI device
trbHost controller event

Definition at line 1736 of file xhci.c.

1737 {
1738 int rc;
1739
1740 /* Construct error */
1741 rc = -ECODE ( trb->code );
1742 DBGC ( xhci, "XHCI %s host controller event (code %d): %s\n",
1743 xhci->name, trb->code, strerror ( rc ) );
1744}
uint8_t code
Completion code.
Definition xhci.h:672

References xhci_trb_host_controller::code, DBGC, ECODE, xhci_device::name, rc, and strerror().

Referenced by xhci_event_poll().

◆ xhci_event_poll()

void xhci_event_poll ( struct xhci_device * xhci)
static

Poll event ring.

Parameters
xhcixHCI device

Definition at line 1751 of file xhci.c.

1751 {
1752 struct xhci_event_ring *event = &xhci->event;
1753 union xhci_trb *trb;
1754 unsigned int shift = XHCI_EVENT_TRBS_LOG2;
1755 unsigned int count = ( 1 << shift );
1756 unsigned int mask = ( count - 1 );
1757 unsigned int consumed;
1758 unsigned int type;
1759
1760 /* Do nothing if device has permanently failed */
1761 if ( xhci->failed )
1762 return;
1763
1764 /* Poll for events */
1765 profile_start ( &xhci_event_profiler );
1766 for ( consumed = 0 ; ; consumed++ ) {
1767
1768 /* Stop if we reach an empty TRB */
1769 rmb();
1770 trb = &event->trb[ event->cons & mask ];
1771 if ( ! ( ( trb->common.flags ^
1772 ( event->cons >> shift ) ) & XHCI_TRB_C ) )
1773 break;
1774
1775 /* Consume this TRB */
1776 event->cons++;
1777
1778 /* Handle TRB */
1779 type = ( trb->common.type & XHCI_TRB_TYPE_MASK );
1780 switch ( type ) {
1781
1782 case XHCI_TRB_TRANSFER :
1783 xhci_transfer ( xhci, &trb->transfer );
1784 break;
1785
1786 case XHCI_TRB_COMPLETE :
1787 xhci_complete ( xhci, &trb->complete );
1788 break;
1789
1791 xhci_port_status ( xhci, &trb->port );
1792 break;
1793
1795 xhci_host_controller ( xhci, &trb->host );
1796 break;
1797
1798 default:
1799 DBGC ( xhci, "XHCI %s unrecognised event %#x\n:",
1800 xhci->name, ( event->cons - 1 ) );
1801 DBGC_HDA ( xhci, virt_to_phys ( trb ),
1802 trb, sizeof ( *trb ) );
1803 break;
1804 }
1805 }
1806
1807 /* Update dequeue pointer if applicable */
1808 if ( consumed ) {
1809 xhci_writeq ( xhci, dma ( &event->trb_map, trb ),
1810 xhci->run + XHCI_RUN_ERDP ( 0 ) );
1811 profile_stop ( &xhci_event_profiler );
1812 }
1813}
#define rmb()
Definition io.h:545
uint8_t type
Type.
Definition xhci.h:323
struct xhci_trb_port_status port
Port status changed event.
Definition xhci.h:717
struct xhci_trb_host_controller host
Host controller event.
Definition xhci.h:719
struct xhci_trb_transfer transfer
Transfer event.
Definition xhci.h:713
struct xhci_trb_complete complete
Command completion event.
Definition xhci.h:715
static void xhci_transfer(struct xhci_device *xhci, struct xhci_trb_transfer *trb)
Handle transfer event.
Definition xhci.c:1596
static void xhci_host_controller(struct xhci_device *xhci, struct xhci_trb_host_controller *trb)
Handle host controller event.
Definition xhci.c:1736
static void xhci_port_status(struct xhci_device *xhci, struct xhci_trb_port_status *trb)
Handle port status event.
Definition xhci.c:1712
static void xhci_complete(struct xhci_device *xhci, struct xhci_trb_complete *trb)
Handle command completion event.
Definition xhci.c:1675
#define XHCI_TRB_HOST_CONTROLLER
A port status change transfer request block.
Definition xhci.h:682
#define XHCI_TRB_PORT_STATUS
A port status change transfer request block.
Definition xhci.h:663
#define XHCI_TRB_TRANSFER
A transfer event transfer request block.
Definition xhci.h:605
#define XHCI_TRB_COMPLETE
A command completion event transfer request block.
Definition xhci.h:632
#define XHCI_TRB_TYPE_MASK
Transfer request block type mask.
Definition xhci.h:347

References xhci_trb::common, xhci_trb::complete, count, DBGC, DBGC_HDA, dma(), xhci_device::event, xhci_device::failed, xhci_trb_common::flags, xhci_trb::host, xhci_device::name, xhci_trb::port, profile_start(), profile_stop(), rmb, xhci_device::run, xhci_trb::transfer, type, xhci_trb_common::type, xhci_complete(), XHCI_EVENT_TRBS_LOG2, xhci_host_controller(), xhci_port_status(), XHCI_RUN_ERDP, xhci_transfer(), XHCI_TRB_C, XHCI_TRB_COMPLETE, XHCI_TRB_HOST_CONTROLLER, XHCI_TRB_PORT_STATUS, XHCI_TRB_TRANSFER, XHCI_TRB_TYPE_MASK, and xhci_writeq().

Referenced by xhci_abort(), xhci_bus_poll(), and xhci_command().

◆ xhci_abort()

void xhci_abort ( struct xhci_device * xhci)
static

Abort command.

Parameters
xhcixHCI device

Definition at line 1820 of file xhci.c.

1820 {
1821 physaddr_t crp;
1822 uint32_t crcr;
1823
1824 /* Abort the command */
1825 DBGC2 ( xhci, "XHCI %s aborting command\n", xhci->name );
1826 xhci_writeq ( xhci, XHCI_CRCR_CA, xhci->op + XHCI_OP_CRCR );
1827
1828 /* Allow time for command to abort */
1830
1831 /* Check for failure to abort */
1832 crcr = readl ( xhci->op + XHCI_OP_CRCR );
1833 if ( crcr & XHCI_CRCR_CRR ) {
1834
1835 /* Device has failed to abort a command and is almost
1836 * certainly beyond repair. Reset device, abandoning
1837 * all state, and mark device as failed to avoid
1838 * delays on any future command attempts.
1839 */
1840 DBGC ( xhci, "XHCI %s failed to abort command\n", xhci->name );
1841 xhci_fail ( xhci );
1842 }
1843
1844 /* Consume (and ignore) any final command status */
1845 xhci_event_poll ( xhci );
1846
1847 /* Reset the command ring control register */
1848 xhci_ring_reset ( &xhci->command );
1849 crp = dma ( &xhci->command.map, xhci->command.trb );
1850 xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ), xhci->op + XHCI_OP_CRCR );
1851}
static void xhci_ring_reset(struct xhci_trb_ring *ring)
Reset transfer request block ring.
Definition xhci.c:1274
static void xhci_event_poll(struct xhci_device *xhci)
Poll event ring.
Definition xhci.c:1751
static int xhci_fail(struct xhci_device *xhci)
Mark xHCI device as permanently failed.
Definition xhci.c:1180
#define XHCI_CRCR_CA
Command abort.
Definition xhci.h:185
#define XHCI_COMMAND_ABORT_DELAY_MS
Time to delay after aborting a command.
Definition xhci.h:1012

References xhci_device::command, DBGC, DBGC2, dma(), xhci_trb_ring::map, mdelay(), xhci_device::name, xhci_device::op, readl, xhci_trb_ring::trb, XHCI_COMMAND_ABORT_DELAY_MS, XHCI_CRCR_CA, XHCI_CRCR_CRR, XHCI_CRCR_RCS, xhci_event_poll(), xhci_fail(), XHCI_OP_CRCR, xhci_ring_reset(), and xhci_writeq().

Referenced by xhci_command().

◆ xhci_command()

int xhci_command ( struct xhci_device * xhci,
union xhci_trb * trb )
static

Issue command and wait for completion.

Parameters
xhcixHCI device
trbTransfer request block (with empty Cycle flag)
Return values
rcReturn status code

On a successful completion, the TRB will be overwritten with the completion.

Definition at line 1863 of file xhci.c.

1863 {
1864 struct xhci_trb_complete *complete = &trb->complete;
1865 unsigned int i;
1866 int rc;
1867
1868 /* Immediately fail all commands if command mechanism has failed */
1869 if ( xhci->failed ) {
1870 rc = -EPIPE;
1871 goto err_failed;
1872 }
1873
1874 /* Sanity check */
1875 if ( xhci->pending ) {
1876 DBGC ( xhci, "XHCI %s command ring busy\n", xhci->name );
1877 rc = -EBUSY;
1878 goto err_pending;
1879 }
1880
1881 /* Record the pending command */
1882 xhci->pending = trb;
1883
1884 /* Enqueue the command */
1885 if ( ( rc = xhci_enqueue ( &xhci->command, NULL, trb ) ) != 0 )
1886 goto err_enqueue;
1887
1888 /* Ring the command doorbell */
1889 xhci_doorbell ( &xhci->command );
1890
1891 /* Wait for the command to complete */
1892 for ( i = 0 ; i < XHCI_COMMAND_MAX_WAIT_MS ; i++ ) {
1893
1894 /* Poll event ring */
1895 xhci_event_poll ( xhci );
1896
1897 /* Check for completion */
1898 if ( ! xhci->pending ) {
1899 if ( complete->code != XHCI_CMPLT_SUCCESS ) {
1900 rc = -ECODE ( complete->code );
1901 DBGC ( xhci, "XHCI %s command failed (code "
1902 "%d): %s\n", xhci->name, complete->code,
1903 strerror ( rc ) );
1904 DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1905 return rc;
1906 }
1907 return 0;
1908 }
1909
1910 /* Delay */
1911 mdelay ( 1 );
1912 }
1913
1914 /* Timeout */
1915 DBGC ( xhci, "XHCI %s timed out waiting for completion\n", xhci->name );
1916 rc = -ETIMEDOUT;
1917
1918 /* Abort command */
1919 xhci_abort ( xhci );
1920
1921 err_enqueue:
1922 xhci->pending = NULL;
1923 err_pending:
1924 err_failed:
1925 return rc;
1926}
#define EPIPE
Broken pipe.
Definition errno.h:663
#define EBUSY
Device or resource busy.
Definition errno.h:382
A command completion event transfer request block.
Definition xhci.h:614
static void xhci_abort(struct xhci_device *xhci)
Abort command.
Definition xhci.c:1820
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition xhci.c:1437
#define XHCI_COMMAND_MAX_WAIT_MS
Maximum time to wait for a command to complete.
Definition xhci.h:1006

References xhci_trb_complete::code, xhci_device::command, xhci_trb::complete, DBGC, DBGC_HDA, EBUSY, ECODE, EPIPE, ETIMEDOUT, xhci_device::failed, mdelay(), xhci_device::name, NULL, xhci_device::pending, rc, strerror(), xhci_abort(), XHCI_CMPLT_SUCCESS, XHCI_COMMAND_MAX_WAIT_MS, xhci_doorbell(), xhci_enqueue(), and xhci_event_poll().

Referenced by xhci_context(), xhci_disable_slot(), xhci_enable_slot(), xhci_nop(), xhci_reset_endpoint(), xhci_set_tr_dequeue_pointer(), and xhci_stop_endpoint().

◆ xhci_nop()

int xhci_nop ( struct xhci_device * xhci)
inlinestatic

Issue NOP and wait for completion.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1934 of file xhci.c.

1934 {
1935 union xhci_trb trb;
1936 struct xhci_trb_common *nop = &trb.common;
1937 int rc;
1938
1939 /* Construct command */
1940 memset ( nop, 0, sizeof ( *nop ) );
1941 nop->flags = XHCI_TRB_IOC;
1942 nop->type = XHCI_TRB_NOP_CMD;
1943
1944 /* Issue command and wait for completion */
1945 if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1946 DBGC ( xhci, "XHCI %s NOP failed: %s\n",
1947 xhci->name, strerror ( rc ) );
1948 return rc;
1949 }
1950
1951 DBGC2 ( xhci, "XHCI %s NOP completed successfully\n", xhci->name );
1952 return 0;
1953}
A transfer request block.
Definition xhci.h:315
uint8_t nop
Definition tcp.h:0
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition xhci.c:1863
#define XHCI_TRB_NOP_CMD
A no-op command transfer request block.
Definition xhci.h:586
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
Definition xhci.h:338

References xhci_trb::common, DBGC, DBGC2, memset(), xhci_device::name, nop, rc, strerror(), xhci_command(), XHCI_TRB_IOC, and XHCI_TRB_NOP_CMD.

◆ xhci_enable_slot()

int xhci_enable_slot ( struct xhci_device * xhci,
unsigned int type )
inlinestatic

Enable slot.

Parameters
xhcixHCI device
typeSlot type
Return values
slotDevice slot ID, or negative error

Definition at line 1962 of file xhci.c.

1963 {
1964 union xhci_trb trb;
1965 struct xhci_trb_enable_slot *enable = &trb.enable;
1966 struct xhci_trb_complete *enabled = &trb.complete;
1967 unsigned int slot;
1968 int rc;
1969
1970 /* Construct command */
1971 memset ( enable, 0, sizeof ( *enable ) );
1972 enable->slot = type;
1973 enable->type = XHCI_TRB_ENABLE_SLOT;
1974
1975 /* Issue command and wait for completion */
1976 if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1977 DBGC ( xhci, "XHCI %s could not enable new slot: %s\n",
1978 xhci->name, strerror ( rc ) );
1979 return rc;
1980 }
1981
1982 /* Extract slot number */
1983 slot = enabled->slot;
1984
1985 DBGC2 ( xhci, "XHCI %s slot %d enabled\n", xhci->name, slot );
1986 return slot;
1987}
uint16_t enabled
Single-entry bitmask of the enabled option value.
Definition ena.h:3
An enable slot transfer request block.
Definition xhci.h:466
uint8_t slot
Slot type.
Definition xhci.h:476
uint8_t type
Type.
Definition xhci.h:474
#define XHCI_TRB_ENABLE_SLOT
An enable slot transfer request block.
Definition xhci.h:482

References xhci_trb::complete, DBGC, DBGC2, xhci_trb::enable, enabled, memset(), xhci_device::name, rc, slot, xhci_trb_enable_slot::slot, strerror(), type, xhci_trb_enable_slot::type, xhci_command(), and XHCI_TRB_ENABLE_SLOT.

Referenced by xhci_device_open().

◆ xhci_disable_slot()

int xhci_disable_slot ( struct xhci_device * xhci,
unsigned int slot )
inlinestatic

Disable slot.

Parameters
xhcixHCI device
slotDevice slot
Return values
rcReturn status code

Definition at line 1996 of file xhci.c.

1997 {
1998 union xhci_trb trb;
1999 struct xhci_trb_disable_slot *disable = &trb.disable;
2000 int rc;
2001
2002 /* Construct command */
2003 memset ( disable, 0, sizeof ( *disable ) );
2004 disable->type = XHCI_TRB_DISABLE_SLOT;
2005 disable->slot = slot;
2006
2007 /* Issue command and wait for completion */
2008 if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2009 DBGC ( xhci, "XHCI %s could not disable slot %d: %s\n",
2010 xhci->name, slot, strerror ( rc ) );
2011 return rc;
2012 }
2013
2014 DBGC2 ( xhci, "XHCI %s slot %d disabled\n", xhci->name, slot );
2015 return 0;
2016}
A disable slot transfer request block.
Definition xhci.h:485
uint8_t slot
Slot ID.
Definition xhci.h:497
uint8_t type
Type.
Definition xhci.h:493
#define XHCI_TRB_DISABLE_SLOT
A disable slot transfer request block.
Definition xhci.h:501

References DBGC, DBGC2, xhci_trb::disable, memset(), xhci_device::name, rc, slot, xhci_trb_disable_slot::slot, strerror(), xhci_trb_disable_slot::type, xhci_command(), and XHCI_TRB_DISABLE_SLOT.

Referenced by xhci_device_close(), and xhci_device_open().

◆ xhci_context()

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) )
static

Issue context-based command and wait for completion.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
typeTRB type
populateInput context populater
Return values
rcReturn status code

Definition at line 2028 of file xhci.c.

2033 {
2034 union xhci_trb trb;
2035 struct xhci_trb_context *context = &trb.context;
2036 struct dma_mapping map;
2037 size_t len;
2038 void *input;
2039 int rc;
2040
2041 /* Allocate an input context */
2042 memset ( &map, 0, sizeof ( map ) );
2044 input = dma_alloc ( xhci->dma, &map, len, xhci_align ( len ) );
2045 if ( ! input ) {
2046 rc = -ENOMEM;
2047 goto err_alloc;
2048 }
2049 memset ( input, 0, len );
2050
2051 /* Populate input context */
2052 populate ( xhci, slot, endpoint, input );
2053
2054 /* Construct command */
2055 memset ( context, 0, sizeof ( *context ) );
2056 context->type = type;
2057 context->input = cpu_to_le64 ( dma ( &map, input ) );
2058 context->slot = slot->id;
2059
2060 /* Issue command and wait for completion */
2061 if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 )
2062 goto err_command;
2063
2064 err_command:
2065 dma_free ( &map, input, len );
2066 err_alloc:
2067 return rc;
2068}
static __always_inline int struct dma_mapping * map
Definition dma.h:184
A DMA mapping.
Definition dma.h:33
A context transfer request block.
Definition xhci.h:504
uint64_t input
Input context.
Definition xhci.h:506
uint8_t type
Type.
Definition xhci.h:512
uint8_t slot
Slot ID.
Definition xhci.h:516
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition xhci.c:431

References xhci_trb::context, cpu_to_le64, dma(), xhci_device::dma, dma_alloc(), dma_free(), ENOMEM, xhci_trb_context::input, len, map, memset(), rc, slot, xhci_trb_context::slot, type, xhci_trb_context::type, xhci_align(), xhci_command(), XHCI_CTX_END, and xhci_input_context_offset().

Referenced by xhci_address_device(), xhci_configure_endpoint(), xhci_deconfigure_endpoint(), and xhci_evaluate_context().

◆ xhci_address_device_input()

void xhci_address_device_input ( struct xhci_device * xhci,
struct xhci_slot * slot,
struct xhci_endpoint * endpoint,
void * input )
static

Populate address device input context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
inputInput context

Definition at line 2078 of file xhci.c.

2081 {
2082 struct xhci_trb_ring *ring = &endpoint->ring;
2083 struct xhci_control_context *control_ctx;
2084 struct xhci_slot_context *slot_ctx;
2085 struct xhci_endpoint_context *ep_ctx;
2086
2087 /* Sanity checks */
2088 assert ( endpoint->ctx == XHCI_CTX_EP0 );
2089
2090 /* Populate control context */
2091 control_ctx = input;
2092 control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2093 ( 1 << XHCI_CTX_EP0 ) );
2094
2095 /* Populate slot context */
2096 slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2097 slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( 1, 0, slot->psiv,
2098 slot->route ) );
2099 slot_ctx->port = slot->port;
2100 slot_ctx->tt_id = slot->tt_id;
2101 slot_ctx->tt_port = slot->tt_port;
2102
2103 /* Populate control endpoint context */
2104 ep_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_EP0 ) );
2105 ep_ctx->type = XHCI_EP_TYPE_CONTROL;
2106 ep_ctx->burst = endpoint->ep->burst;
2107 ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2108 ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
2109 XHCI_EP_DCS );
2110 ep_ctx->trb_len = cpu_to_le16 ( XHCI_EP0_TRB_LEN );
2111}
#define cpu_to_le16(value)
Definition byteswap.h:107
size_t mtu
Maximum transfer size.
Definition usb.h:422
unsigned int burst
Maximum burst size.
Definition usb.h:424
An input control context.
Definition xhci.h:723
uint32_t add
Add context flags.
Definition xhci.h:727
An endpoint context.
Definition xhci.h:771
uint16_t trb_len
Average TRB length.
Definition xhci.h:789
uint8_t burst
Maximum burst size.
Definition xhci.h:783
uint64_t dequeue
Transfer ring dequeue pointer.
Definition xhci.h:787
uint16_t mtu
Maximum packet size.
Definition xhci.h:785
uint8_t type
Endpoint type.
Definition xhci.h:781
A slot context.
Definition xhci.h:741
uint8_t tt_id
TT hub slot ID.
Definition xhci.h:751
uint8_t port
Root hub port number.
Definition xhci.h:747
uint32_t info
Device info.
Definition xhci.h:743
uint8_t tt_port
TT port number.
Definition xhci.h:753
A transfer request block command/transfer ring.
Definition xhci.h:842
#define XHCI_CTX_SLOT
Slot context index.
Definition xhci.h:945
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition xhci.h:826
#define XHCI_EP0_TRB_LEN
Control endpoint average TRB length.
Definition xhci.h:829
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition xhci.h:767
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition xhci.h:953
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
Definition xhci.h:817

References xhci_control_context::add, assert, usb_endpoint::burst, xhci_endpoint_context::burst, cpu_to_le16, cpu_to_le32, cpu_to_le64, xhci_endpoint::ctx, xhci_endpoint_context::dequeue, dma(), xhci_endpoint::ep, xhci_slot_context::info, xhci_trb_ring::map, usb_endpoint::mtu, xhci_endpoint_context::mtu, xhci_slot_context::port, xhci_endpoint::ring, slot, xhci_trb_ring::trb, xhci_endpoint_context::trb_len, xhci_slot_context::tt_id, xhci_slot_context::tt_port, xhci_endpoint_context::type, XHCI_CTX_EP0, XHCI_CTX_SLOT, XHCI_EP0_TRB_LEN, XHCI_EP_DCS, XHCI_EP_TYPE_CONTROL, xhci_input_context_offset(), and XHCI_SLOT_INFO.

Referenced by xhci_address_device().

◆ xhci_address_device()

int xhci_address_device ( struct xhci_device * xhci,
struct xhci_slot * slot )
inlinestatic

Address device.

Parameters
xhcixHCI device
slotDevice slot
Return values
rcReturn status code

Definition at line 2120 of file xhci.c.

2121 {
2122 struct usb_device *usb = slot->usb;
2123 struct xhci_slot_context *slot_ctx;
2124 int rc;
2125
2126 /* Assign device address */
2127 if ( ( rc = xhci_context ( xhci, slot, slot->endpoint[XHCI_CTX_EP0],
2129 xhci_address_device_input ) ) != 0 ) {
2130 DBGC ( xhci, "XHCI %s slot %d could not assign address: %s\n",
2131 xhci->name, slot->id, strerror ( rc ) );
2132 return rc;
2133 }
2134
2135 /* Get assigned address */
2136 slot_ctx = ( slot->context +
2138 usb->address = slot_ctx->address;
2139 DBGC2 ( xhci, "XHCI %s slot %d assigned address %d to %s\n",
2140 xhci->name, slot->id, usb->address, usb->name );
2141
2142 return 0;
2143}
A USB device.
Definition usb.h:733
char name[32]
Name.
Definition usb.h:735
unsigned int address
Device address, if assigned.
Definition usb.h:743
uint8_t address
USB address.
Definition xhci.h:757
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.
Definition xhci.c:2028
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
Definition xhci.c:419
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.
Definition xhci.c:2078
#define XHCI_TRB_ADDRESS_DEVICE
An address device transfer request block.
Definition xhci.h:520

References usb_device::address, xhci_slot_context::address, DBGC, DBGC2, usb_device::name, xhci_device::name, rc, slot, strerror(), xhci_address_device_input(), xhci_context(), XHCI_CTX_EP0, XHCI_CTX_SLOT, xhci_device_context_offset(), and XHCI_TRB_ADDRESS_DEVICE.

Referenced by xhci_device_address().

◆ xhci_configure_endpoint_input()

void xhci_configure_endpoint_input ( struct xhci_device * xhci,
struct xhci_slot * slot,
struct xhci_endpoint * endpoint,
void * input )
static

Populate configure endpoint input context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
inputInput context

Definition at line 2153 of file xhci.c.

2156 {
2157 struct xhci_trb_ring *ring = &endpoint->ring;
2158 struct xhci_control_context *control_ctx;
2159 struct xhci_slot_context *slot_ctx;
2160 struct xhci_endpoint_context *ep_ctx;
2161
2162 /* Populate control context */
2163 control_ctx = input;
2164 control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2165 ( 1 << endpoint->ctx ) );
2166
2167 /* Populate slot context */
2168 slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2169 slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1U ),
2170 ( slot->ports ? 1 : 0 ),
2171 slot->psiv, 0 ) );
2172 slot_ctx->ports = slot->ports;
2173
2174 /* Populate endpoint context */
2175 ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2176 ep_ctx->interval = endpoint->interval;
2177 ep_ctx->type = endpoint->type;
2178 ep_ctx->burst = endpoint->ep->burst;
2179 ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2180 ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
2181 XHCI_EP_DCS );
2182 ep_ctx->trb_len = cpu_to_le16 ( endpoint->ep->mtu ); /* best guess */
2183}
uint8_t interval
Polling interval.
Definition xhci.h:777
unsigned int interval
Endpoint interval.
Definition xhci.h:1176
unsigned int type
Endpoint type.
Definition xhci.h:1174
uint8_t ports
Number of downstream ports.
Definition xhci.h:749

References xhci_control_context::add, usb_endpoint::burst, xhci_endpoint_context::burst, cpu_to_le16, cpu_to_le32, cpu_to_le64, xhci_endpoint::ctx, xhci_endpoint_context::dequeue, dma(), xhci_endpoint::ep, xhci_slot_context::info, xhci_endpoint::interval, xhci_endpoint_context::interval, xhci_trb_ring::map, usb_endpoint::mtu, xhci_endpoint_context::mtu, xhci_slot_context::ports, xhci_endpoint::ring, slot, xhci_trb_ring::trb, xhci_endpoint_context::trb_len, xhci_endpoint::type, xhci_endpoint_context::type, XHCI_CTX_END, XHCI_CTX_SLOT, XHCI_EP_DCS, xhci_input_context_offset(), and XHCI_SLOT_INFO.

Referenced by xhci_configure_endpoint().

◆ xhci_configure_endpoint()

int xhci_configure_endpoint ( struct xhci_device * xhci,
struct xhci_slot * slot,
struct xhci_endpoint * endpoint )
inlinestatic

Configure endpoint.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2193 of file xhci.c.

2195 {
2196 int rc;
2197
2198 /* Configure endpoint */
2199 if ( ( rc = xhci_context ( xhci, slot, endpoint,
2202 DBGC ( xhci, "XHCI %s slot %d ctx %d could not configure: %s\n",
2203 xhci->name, slot->id, endpoint->ctx, strerror ( rc ) );
2204 return rc;
2205 }
2206
2207 DBGC2 ( xhci, "XHCI %s slot %d ctx %d configured\n",
2208 xhci->name, slot->id, endpoint->ctx );
2209 return 0;
2210}
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.
Definition xhci.c:2153
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
Definition xhci.h:523

References xhci_endpoint::ctx, DBGC, DBGC2, xhci_device::name, rc, slot, strerror(), xhci_configure_endpoint_input(), xhci_context(), and XHCI_TRB_CONFIGURE_ENDPOINT.

Referenced by xhci_endpoint_open().

◆ xhci_deconfigure_endpoint_input()

void xhci_deconfigure_endpoint_input ( struct xhci_device *xhci __unused,
struct xhci_slot *slot __unused,
struct xhci_endpoint * endpoint,
void * input )
static

Populate deconfigure endpoint input context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
inputInput context

Definition at line 2221 of file xhci.c.

2224 {
2225 struct xhci_control_context *control_ctx;
2226 struct xhci_slot_context *slot_ctx;
2227
2228 /* Populate control context */
2229 control_ctx = input;
2230 control_ctx->add = cpu_to_le32 ( 1 << XHCI_CTX_SLOT );
2231 control_ctx->drop = cpu_to_le32 ( 1 << endpoint->ctx );
2232
2233 /* Populate slot context */
2234 slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2235 slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1U ),
2236 0, 0, 0 ) );
2237}
uint32_t drop
Drop context flags.
Definition xhci.h:725

References __unused, xhci_control_context::add, cpu_to_le32, xhci_endpoint::ctx, xhci_control_context::drop, xhci_slot_context::info, slot, XHCI_CTX_END, XHCI_CTX_SLOT, xhci_input_context_offset(), and XHCI_SLOT_INFO.

Referenced by xhci_deconfigure_endpoint().

◆ xhci_deconfigure_endpoint()

int xhci_deconfigure_endpoint ( struct xhci_device * xhci,
struct xhci_slot * slot,
struct xhci_endpoint * endpoint )
inlinestatic

Deconfigure endpoint.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2247 of file xhci.c.

2249 {
2250 int rc;
2251
2252 /* Deconfigure endpoint */
2253 if ( ( rc = xhci_context ( xhci, slot, endpoint,
2256 DBGC ( xhci, "XHCI %s slot %d ctx %d could not deconfigure: "
2257 "%s\n", xhci->name, slot->id, endpoint->ctx,
2258 strerror ( rc ) );
2259 return rc;
2260 }
2261
2262 DBGC2 ( xhci, "XHCI %s slot %d ctx %d deconfigured\n",
2263 xhci->name, slot->id, endpoint->ctx );
2264 return 0;
2265}
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.
Definition xhci.c:2221

References xhci_endpoint::ctx, DBGC, DBGC2, xhci_device::name, rc, slot, strerror(), xhci_context(), xhci_deconfigure_endpoint_input(), and XHCI_TRB_CONFIGURE_ENDPOINT.

Referenced by xhci_endpoint_close(), and xhci_endpoint_open().

◆ xhci_evaluate_context_input()

void xhci_evaluate_context_input ( struct xhci_device * xhci,
struct xhci_slot *slot __unused,
struct xhci_endpoint * endpoint,
void * input )
static

Populate evaluate context input context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
inputInput context

Definition at line 2275 of file xhci.c.

2278 {
2279 struct xhci_control_context *control_ctx;
2280 struct xhci_slot_context *slot_ctx;
2281 struct xhci_endpoint_context *ep_ctx;
2282
2283 /* Populate control context */
2284 control_ctx = input;
2285 control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2286 ( 1 << endpoint->ctx ) );
2287
2288 /* Populate slot context */
2289 slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2290 slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1U ),
2291 0, 0, 0 ) );
2292
2293 /* Populate endpoint context */
2294 ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2295 ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2296}

References __unused, xhci_control_context::add, cpu_to_le16, cpu_to_le32, xhci_endpoint::ctx, xhci_endpoint::ep, xhci_slot_context::info, usb_endpoint::mtu, xhci_endpoint_context::mtu, slot, XHCI_CTX_END, XHCI_CTX_SLOT, xhci_input_context_offset(), and XHCI_SLOT_INFO.

Referenced by xhci_evaluate_context().

◆ xhci_evaluate_context()

int xhci_evaluate_context ( struct xhci_device * xhci,
struct xhci_slot * slot,
struct xhci_endpoint * endpoint )
inlinestatic

Evaluate context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2306 of file xhci.c.

2308 {
2309 int rc;
2310
2311 /* Configure endpoint */
2312 if ( ( rc = xhci_context ( xhci, slot, endpoint,
2314 xhci_evaluate_context_input ) ) != 0 ) {
2315 DBGC ( xhci, "XHCI %s slot %d ctx %d could not (re-)evaluate: "
2316 "%s\n", xhci->name, slot->id, endpoint->ctx,
2317 strerror ( rc ) );
2318 return rc;
2319 }
2320
2321 DBGC2 ( xhci, "XHCI %s slot %d ctx %d (re-)evaluated\n",
2322 xhci->name, slot->id, endpoint->ctx );
2323 return 0;
2324}
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.
Definition xhci.c:2275
#define XHCI_TRB_EVALUATE_CONTEXT
An evaluate context transfer request block.
Definition xhci.h:526

References xhci_endpoint::ctx, DBGC, DBGC2, xhci_device::name, rc, slot, strerror(), xhci_context(), xhci_evaluate_context_input(), and XHCI_TRB_EVALUATE_CONTEXT.

Referenced by xhci_endpoint_mtu().

◆ xhci_reset_endpoint()

int xhci_reset_endpoint ( struct xhci_device * xhci,
struct xhci_slot * slot,
struct xhci_endpoint * endpoint )
inlinestatic

Reset endpoint.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2334 of file xhci.c.

2336 {
2337 union xhci_trb trb;
2338 struct xhci_trb_reset_endpoint *reset = &trb.reset;
2339 int rc;
2340
2341 /* Construct command */
2342 memset ( reset, 0, sizeof ( *reset ) );
2343 reset->slot = slot->id;
2344 reset->endpoint = endpoint->ctx;
2346
2347 /* Issue command and wait for completion */
2348 if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2349 DBGC ( xhci, "XHCI %s slot %d ctx %d could not reset endpoint "
2350 "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2351 endpoint->context->state, strerror ( rc ) );
2352 return rc;
2353 }
2354
2355 return 0;
2356}
A reset endpoint transfer request block.
Definition xhci.h:529
uint8_t slot
Slot ID.
Definition xhci.h:541
uint8_t type
Type.
Definition xhci.h:537
uint8_t endpoint
Endpoint ID.
Definition xhci.h:539
#define XHCI_TRB_RESET_ENDPOINT
A reset endpoint transfer request block.
Definition xhci.h:545

References DBGC, xhci_trb_reset_endpoint::endpoint, memset(), xhci_device::name, rc, xhci_trb::reset, slot, xhci_trb_reset_endpoint::slot, strerror(), xhci_trb_reset_endpoint::type, xhci_command(), and XHCI_TRB_RESET_ENDPOINT.

Referenced by xhci_endpoint_reset().

◆ xhci_stop_endpoint()

int xhci_stop_endpoint ( struct xhci_device * xhci,
struct xhci_slot * slot,
struct xhci_endpoint * endpoint )
inlinestatic

Stop endpoint.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2366 of file xhci.c.

2368 {
2369 union xhci_trb trb;
2370 struct xhci_trb_stop_endpoint *stop = &trb.stop;
2371 int rc;
2372
2373 /* Construct command */
2374 memset ( stop, 0, sizeof ( *stop ) );
2375 stop->slot = slot->id;
2376 stop->endpoint = endpoint->ctx;
2378
2379 /* Issue command and wait for completion */
2380 if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2381 DBGC ( xhci, "XHCI %s slot %d ctx %d could not stop endpoint "
2382 "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2383 endpoint->context->state, strerror ( rc ) );
2384 return rc;
2385 }
2386
2387 return 0;
2388}
A stop endpoint transfer request block.
Definition xhci.h:548
uint8_t slot
Slot ID.
Definition xhci.h:560
uint8_t type
Type.
Definition xhci.h:556
uint8_t endpoint
Endpoint ID.
Definition xhci.h:558
#define XHCI_TRB_STOP_ENDPOINT
A stop endpoint transfer request block.
Definition xhci.h:564

References DBGC, xhci_trb_stop_endpoint::endpoint, memset(), xhci_device::name, rc, slot, xhci_trb_stop_endpoint::slot, xhci_trb::stop, strerror(), xhci_trb_stop_endpoint::type, xhci_command(), and XHCI_TRB_STOP_ENDPOINT.

◆ xhci_set_tr_dequeue_pointer()

int xhci_set_tr_dequeue_pointer ( struct xhci_device * xhci,
struct xhci_slot * slot,
struct xhci_endpoint * endpoint )
inlinestatic

Set transfer ring dequeue pointer.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2399 of file xhci.c.

2401 {
2402 union xhci_trb trb;
2403 struct xhci_trb_set_tr_dequeue_pointer *dequeue = &trb.dequeue;
2404 struct xhci_trb_ring *ring = &endpoint->ring;
2405 unsigned int cons;
2406 unsigned int mask;
2407 unsigned int index;
2408 unsigned int dcs;
2410 int rc;
2411
2412 /* Construct command */
2413 memset ( dequeue, 0, sizeof ( *dequeue ) );
2414 cons = ring->cons;
2415 mask = ring->mask;
2416 dcs = ( ( ~( cons >> ring->shift ) ) & XHCI_EP_DCS );
2417 index = ( cons & mask );
2418 addr = dma ( &ring->map, &ring->trb[index] );
2419 dequeue->dequeue = cpu_to_le64 ( addr | dcs );
2420 dequeue->slot = slot->id;
2421 dequeue->endpoint = endpoint->ctx;
2423
2424 /* Issue command and wait for completion */
2425 if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2426 DBGC ( xhci, "XHCI %s slot %d ctx %d could not set TR dequeue "
2427 "pointer in state %d: %s\n", xhci->name, slot->id,
2428 endpoint->ctx, endpoint->context->state, strerror ( rc));
2429 return rc;
2430 }
2431
2432 return 0;
2433}
A set transfer ring dequeue pointer transfer request block.
Definition xhci.h:567
uint8_t endpoint
Endpoint ID.
Definition xhci.h:577
uint64_t dequeue
Dequeue pointer.
Definition xhci.h:569
#define XHCI_TRB_SET_TR_DEQUEUE_POINTER
A set transfer ring dequeue pointer transfer request block.
Definition xhci.h:583

References addr, cons, xhci_trb_ring::cons, xhci_endpoint::context, cpu_to_le64, xhci_endpoint::ctx, DBGC, xhci_trb::dequeue, xhci_trb_set_tr_dequeue_pointer::dequeue, dma(), xhci_trb_set_tr_dequeue_pointer::endpoint, index, xhci_trb_ring::map, xhci_trb_ring::mask, memset(), xhci_device::name, rc, xhci_endpoint::ring, xhci_trb_ring::shift, slot, xhci_trb_set_tr_dequeue_pointer::slot, xhci_endpoint_context::state, strerror(), xhci_trb_ring::trb, xhci_trb_set_tr_dequeue_pointer::type, xhci_command(), XHCI_EP_DCS, and XHCI_TRB_SET_TR_DEQUEUE_POINTER.

Referenced by xhci_endpoint_reset().

◆ xhci_endpoint_open()

int xhci_endpoint_open ( struct usb_endpoint * ep)
static

Open endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2448 of file xhci.c.

2448 {
2449 struct usb_device *usb = ep->usb;
2450 struct xhci_slot *slot = usb_get_hostdata ( usb );
2451 struct xhci_device *xhci = slot->xhci;
2452 struct xhci_endpoint *endpoint;
2453 unsigned int ctx;
2454 unsigned int type;
2455 unsigned int interval;
2456 int rc;
2457
2458 /* Calculate context index */
2459 ctx = XHCI_CTX ( ep->address );
2460 assert ( slot->endpoint[ctx] == NULL );
2461
2462 /* Calculate endpoint type */
2466 if ( ep->address & USB_DIR_IN )
2468
2469 /* Calculate interval */
2470 if ( type & XHCI_EP_TYPE_PERIODIC ) {
2471 interval = ( fls ( ep->interval ) - 1 );
2472 } else {
2473 interval = ep->interval;
2474 }
2475
2476 /* Allocate and initialise structure */
2477 endpoint = zalloc ( sizeof ( *endpoint ) );
2478 if ( ! endpoint ) {
2479 rc = -ENOMEM;
2480 goto err_alloc;
2481 }
2482 usb_endpoint_set_hostdata ( ep, endpoint );
2483 slot->endpoint[ctx] = endpoint;
2484 endpoint->xhci = xhci;
2485 endpoint->slot = slot;
2486 endpoint->ep = ep;
2487 endpoint->ctx = ctx;
2488 endpoint->type = type;
2489 endpoint->interval = interval;
2490 endpoint->context = ( ( ( void * ) slot->context ) +
2492
2493 /* Allocate transfer ring */
2494 if ( ( rc = xhci_ring_alloc ( xhci, &endpoint->ring,
2496 slot->id, ctx, 0 ) ) != 0 )
2497 goto err_ring_alloc;
2498
2499 /* Configure endpoint, if applicable */
2500 if ( ( ctx != XHCI_CTX_EP0 ) &&
2501 ( ( rc = xhci_configure_endpoint ( xhci, slot, endpoint ) ) != 0 ))
2502 goto err_configure_endpoint;
2503
2504 DBGC2 ( xhci, "XHCI %s slot %d ctx %d ring [%08lx,%08lx)\n",
2505 xhci->name, slot->id, ctx, virt_to_phys ( endpoint->ring.trb ),
2506 ( virt_to_phys ( endpoint->ring.trb ) + endpoint->ring.len ) );
2507 return 0;
2508
2509 xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2510 err_configure_endpoint:
2511 xhci_ring_free ( &endpoint->ring );
2512 err_ring_alloc:
2513 slot->endpoint[ctx] = NULL;
2514 free ( endpoint );
2515 err_alloc:
2516 return rc;
2517}
#define USB_DIR_IN
Data transfer is from device to host.
Definition usb.h:98
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition usb.h:805
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
Definition usb.h:586
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition usb.h:281
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
Definition usb.h:287
struct usb_endpoint * ep[32]
Endpoint list.
Definition usb.h:755
struct usb_device * usb
USB device.
Definition usb.h:416
unsigned int attributes
Attributes.
Definition usb.h:420
unsigned int interval
Interval (in microframes).
Definition usb.h:426
unsigned int address
Endpoint address.
Definition usb.h:418
An xHCI device.
Definition xhci.h:1069
struct xhci_slot * slot
xHCI slot
Definition xhci.h:1168
struct xhci_device * xhci
xHCI device
Definition xhci.h:1166
struct usb_device * usb
USB device.
Definition xhci.h:1140
static int xhci_configure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Configure endpoint.
Definition xhci.c:2193
static int xhci_deconfigure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Deconfigure endpoint.
Definition xhci.c:2247
#define XHCI_TRANSFER_TRBS_LOG2
Number of TRBs in a transfer ring.
Definition xhci.h:980
#define XHCI_EP_TYPE_IN
Input endpoint type.
Definition xhci.h:820
#define XHCI_CTX(address)
Calculate context index from USB endpoint address.
Definition xhci.h:948
#define XHCI_EP_TYPE(type)
Endpoint type.
Definition xhci.h:814
#define XHCI_EP_TYPE_PERIODIC
Periodic endpoint type.
Definition xhci.h:823

References usb_endpoint::address, assert, usb_endpoint::attributes, xhci_endpoint::context, ctx, xhci_endpoint::ctx, DBGC2, ENOMEM, usb_device::ep, xhci_endpoint::ep, fls, free, usb_endpoint::interval, xhci_endpoint::interval, xhci_trb_ring::len, xhci_device::name, NULL, rc, xhci_endpoint::ring, slot, xhci_endpoint::slot, xhci_trb_ring::trb, type, xhci_endpoint::type, usb_endpoint::usb, xhci_slot::usb, USB_DIR_IN, USB_ENDPOINT_ATTR_CONTROL, USB_ENDPOINT_ATTR_TYPE_MASK, usb_endpoint_set_hostdata(), usb_get_hostdata(), xhci_endpoint::xhci, xhci_configure_endpoint(), XHCI_CTX, XHCI_CTX_EP0, xhci_deconfigure_endpoint(), xhci_device_context_offset(), XHCI_EP_TYPE, XHCI_EP_TYPE_CONTROL, XHCI_EP_TYPE_IN, XHCI_EP_TYPE_PERIODIC, xhci_ring_alloc(), xhci_ring_free(), XHCI_TRANSFER_TRBS_LOG2, and zalloc().

◆ xhci_endpoint_close()

void xhci_endpoint_close ( struct usb_endpoint * ep)
static

Close endpoint.

Parameters
epUSB endpoint

Definition at line 2524 of file xhci.c.

2524 {
2525 struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2526 struct xhci_slot *slot = endpoint->slot;
2527 struct xhci_device *xhci = slot->xhci;
2528 struct io_buffer *iobuf;
2529 unsigned int ctx = endpoint->ctx;
2530
2531 /* Deconfigure endpoint, if applicable */
2532 if ( ctx != XHCI_CTX_EP0 )
2533 xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2534
2535 /* Cancel any incomplete transfers */
2536 while ( xhci_ring_fill ( &endpoint->ring ) ) {
2537 iobuf = xhci_dequeue_multi ( &endpoint->ring );
2538 iob_unmap ( iobuf );
2539 usb_complete_err ( ep, iobuf, -ECANCELED );
2540 }
2541
2542 /* Free endpoint */
2543 xhci_ring_free ( &endpoint->ring );
2544 slot->endpoint[ctx] = NULL;
2545 free ( endpoint );
2546}
#define ECANCELED
Operation canceled.
Definition errno.h:387
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition usb.h:597
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition xhci.h:1160

References ctx, xhci_endpoint::ctx, ECANCELED, xhci_slot::endpoint, xhci_endpoint::ep, free, iob_unmap(), NULL, xhci_endpoint::ring, slot, xhci_endpoint::slot, usb_complete_err(), usb_endpoint_get_hostdata(), XHCI_CTX_EP0, xhci_deconfigure_endpoint(), xhci_dequeue_multi(), xhci_ring_fill(), and xhci_ring_free().

◆ xhci_endpoint_reset()

int xhci_endpoint_reset ( struct usb_endpoint * ep)
static

Reset endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2554 of file xhci.c.

2554 {
2555 struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2556 struct xhci_slot *slot = endpoint->slot;
2557 struct xhci_device *xhci = slot->xhci;
2558 int rc;
2559
2560 /* Reset endpoint context */
2561 if ( ( rc = xhci_reset_endpoint ( xhci, slot, endpoint ) ) != 0 )
2562 return rc;
2563
2564 /* Set transfer ring dequeue pointer */
2565 if ( ( rc = xhci_set_tr_dequeue_pointer ( xhci, slot, endpoint ) ) != 0)
2566 return rc;
2567
2568 /* Ring doorbell to resume processing */
2569 xhci_doorbell ( &endpoint->ring );
2570
2571 DBGC ( xhci, "XHCI %s slot %d ctx %d reset\n",
2572 xhci->name, slot->id, endpoint->ctx );
2573 return 0;
2574}
static int xhci_reset_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Reset endpoint.
Definition xhci.c:2334
static int xhci_set_tr_dequeue_pointer(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Set transfer ring dequeue pointer.
Definition xhci.c:2399

References xhci_endpoint::ctx, DBGC, xhci_slot::endpoint, xhci_endpoint::ep, xhci_device::name, rc, xhci_endpoint::ring, slot, xhci_endpoint::slot, usb_endpoint_get_hostdata(), xhci_doorbell(), xhci_reset_endpoint(), and xhci_set_tr_dequeue_pointer().

◆ xhci_endpoint_mtu()

int xhci_endpoint_mtu ( struct usb_endpoint * ep)
static

Update MTU.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2582 of file xhci.c.

2582 {
2583 struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2584 struct xhci_slot *slot = endpoint->slot;
2585 struct xhci_device *xhci = slot->xhci;
2586 int rc;
2587
2588 /* Evalulate context */
2589 if ( ( rc = xhci_evaluate_context ( xhci, slot, endpoint ) ) != 0 )
2590 return rc;
2591
2592 return 0;
2593}
static int xhci_evaluate_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Evaluate context.
Definition xhci.c:2306

References xhci_slot::endpoint, xhci_endpoint::ep, rc, slot, xhci_endpoint::slot, usb_endpoint_get_hostdata(), and xhci_evaluate_context().

◆ xhci_endpoint_message()

int xhci_endpoint_message ( struct usb_endpoint * ep,
struct io_buffer * iobuf )
static

Enqueue message transfer.

Parameters
epUSB endpoint
iobufI/O buffer
Return values
rcReturn status code

Definition at line 2602 of file xhci.c.

2603 {
2604 struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2605 struct xhci_device *xhci = endpoint->xhci;
2606 struct usb_setup_packet *packet;
2607 unsigned int input;
2608 size_t len;
2609 union xhci_trb trbs[ 1 /* setup */ + 1 /* possible data */ +
2610 1 /* status */ ];
2611 union xhci_trb *trb = trbs;
2612 struct xhci_trb_setup *setup;
2613 struct xhci_trb_data *data;
2614 struct xhci_trb_status *status;
2615 int rc;
2616
2617 /* Profile message transfers */
2618 profile_start ( &xhci_message_profiler );
2619
2620 /* Construct setup stage TRB */
2621 memset ( trbs, 0, sizeof ( trbs ) );
2622 assert ( iob_len ( iobuf ) >= sizeof ( *packet ) );
2623 packet = iobuf->data;
2624 iob_pull ( iobuf, sizeof ( *packet ) );
2625 setup = &(trb++)->setup;
2626 memcpy ( &setup->packet, packet, sizeof ( setup->packet ) );
2627 setup->len = cpu_to_le32 ( sizeof ( *packet ) );
2628 setup->flags = XHCI_TRB_IDT;
2629 setup->type = XHCI_TRB_SETUP;
2630 len = iob_len ( iobuf );
2631 input = ( packet->request & cpu_to_le16 ( USB_DIR_IN ) );
2632 if ( len )
2634
2635 /* Map I/O buffer */
2636 if ( ( rc = iob_map ( iobuf, xhci->dma, len,
2637 ( input ? DMA_RX : DMA_TX ) ) ) != 0 )
2638 goto err_map;
2639
2640 /* Construct data stage TRB, if applicable */
2641 if ( len ) {
2642 data = &(trb++)->data;
2643 data->data = cpu_to_le64 ( iob_dma ( iobuf ) );
2644 data->len = cpu_to_le32 ( len );
2645 data->type = XHCI_TRB_DATA;
2646 data->direction = ( input ? XHCI_DATA_IN : XHCI_DATA_OUT );
2647 }
2648
2649 /* Construct status stage TRB */
2650 status = &(trb++)->status;
2651 status->flags = XHCI_TRB_IOC;
2652 status->type = XHCI_TRB_STATUS;
2653 status->direction =
2654 ( ( len && input ) ? XHCI_STATUS_OUT : XHCI_STATUS_IN );
2655
2656 /* Enqueue TRBs */
2657 if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
2658 ( trb - trbs ) ) ) != 0 )
2659 goto err_enqueue;
2660
2661 /* Ring the doorbell */
2662 xhci_doorbell ( &endpoint->ring );
2663
2664 profile_stop ( &xhci_message_profiler );
2665 return 0;
2666
2667 err_enqueue:
2668 iob_unmap ( iobuf );
2669 err_map:
2670 return rc;
2671}
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t status
Status.
Definition ena.h:5
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
Definition iobuf.h:328
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:220
#define iob_pull(iobuf, len)
Definition iobuf.h:167
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.
Definition iobuf.h:291
#define DMA_TX
Device will read data from host memory.
Definition dma.h:135
#define DMA_RX
Device will write data to host memory.
Definition dma.h:138
void * data
Start of data.
Definition iobuf.h:113
A USB setup data packet.
Definition usb.h:83
uint16_t request
Request.
Definition usb.h:85
A data stage transfer request block.
Definition xhci.h:396
A setup stage transfer request block.
Definition xhci.h:371
uint8_t type
Type.
Definition xhci.h:379
uint8_t flags
Flags.
Definition xhci.h:377
uint32_t len
Length.
Definition xhci.h:375
uint8_t direction
Transfer direction.
Definition xhci.h:381
struct usb_setup_packet packet
Setup packet.
Definition xhci.h:373
A status stage transfer request block.
Definition xhci.h:421
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.
Definition xhci.c:1391
#define XHCI_DATA_IN
Input data direction.
Definition xhci.h:415
#define XHCI_STATUS_OUT
Output status direction.
Definition xhci.h:443
#define XHCI_TRB_SETUP
A setup stage transfer request block.
Definition xhci.h:387
#define XHCI_SETUP_IN
Setup stage input data direction.
Definition xhci.h:390
#define XHCI_TRB_IDT
Transfer request block immediate data flag.
Definition xhci.h:341
#define XHCI_TRB_DATA
A data stage transfer request block.
Definition xhci.h:412
#define XHCI_SETUP_OUT
Setup stage output data direction.
Definition xhci.h:393
#define XHCI_STATUS_IN
Input status direction.
Definition xhci.h:440
#define XHCI_TRB_STATUS
A status stage transfer request block.
Definition xhci.h:437
#define XHCI_DATA_OUT
Output data direction.
Definition xhci.h:418

References assert, cpu_to_le16, cpu_to_le32, cpu_to_le64, data, io_buffer::data, xhci_trb_setup::direction, xhci_device::dma, DMA_RX, DMA_TX, xhci_endpoint::ep, xhci_trb_setup::flags, iob_dma(), iob_len(), iob_map(), iob_pull, iob_unmap(), len, xhci_trb_setup::len, memcpy(), memset(), xhci_trb_setup::packet, profile_start(), profile_stop(), rc, usb_setup_packet::request, xhci_endpoint::ring, status, xhci_trb_setup::type, USB_DIR_IN, usb_endpoint_get_hostdata(), xhci_endpoint::xhci, XHCI_DATA_IN, XHCI_DATA_OUT, xhci_doorbell(), xhci_enqueue_multi(), XHCI_SETUP_IN, XHCI_SETUP_OUT, XHCI_STATUS_IN, XHCI_STATUS_OUT, XHCI_TRB_DATA, XHCI_TRB_IDT, XHCI_TRB_IOC, XHCI_TRB_SETUP, and XHCI_TRB_STATUS.

◆ xhci_endpoint_count()

unsigned int xhci_endpoint_count ( size_t len,
int zlp )
static

Calculate number of TRBs.

Parameters
lenLength of data
zlpAppend a zero-length packet
Return values
countNumber of transfer descriptors

Definition at line 2680 of file xhci.c.

2680 {
2681 unsigned int count;
2682
2683 /* Split into 64kB TRBs */
2684 count = ( ( len + XHCI_MTU - 1 ) / XHCI_MTU );
2685
2686 /* Append a zero-length TRB if applicable */
2687 if ( zlp || ( count == 0 ) )
2688 count++;
2689
2690 return count;
2691}
#define XHCI_MTU
Maximum transfer size.
Definition xhci.h:28

References count, len, and XHCI_MTU.

Referenced by xhci_endpoint_stream().

◆ xhci_endpoint_stream()

int xhci_endpoint_stream ( struct usb_endpoint * ep,
struct io_buffer * iobuf,
int zlp )
static

Enqueue stream transfer.

Parameters
epUSB endpoint
iobufI/O buffer
zlpAppend a zero-length packet
Return values
rcReturn status code

Definition at line 2701 of file xhci.c.

2702 {
2703 struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2704 struct xhci_device *xhci = endpoint->xhci;
2705 size_t len = iob_len ( iobuf );
2706 unsigned int count = xhci_endpoint_count ( len, zlp );
2707 union xhci_trb trbs[count];
2708 union xhci_trb *trb = trbs;
2709 struct xhci_trb_normal *normal;
2711 unsigned int i;
2712 size_t trb_len;
2713 int rc;
2714
2715 /* Profile stream transfers */
2716 profile_start ( &xhci_stream_profiler );
2717
2718 /* Map I/O buffer */
2719 if ( ( rc = iob_map ( iobuf, xhci->dma, len,
2720 ( ( ep->address & USB_DIR_IN ) ?
2721 DMA_RX : DMA_TX ) ) ) != 0 )
2722 goto err_map;
2723 data = iob_dma ( iobuf );
2724
2725 /* Construct normal TRBs */
2726 memset ( &trbs, 0, sizeof ( trbs ) );
2727 for ( i = 0 ; i < count ; i ++ ) {
2728
2729 /* Calculate TRB length */
2730 trb_len = XHCI_MTU;
2731 if ( trb_len > len )
2732 trb_len = len;
2733
2734 /* Construct normal TRB */
2735 normal = &trb->normal;
2736 normal->data = cpu_to_le64 ( data );
2737 normal->len = cpu_to_le32 ( trb_len );
2738 normal->type = XHCI_TRB_NORMAL;
2739 normal->flags = XHCI_TRB_CH;
2740
2741 /* Move to next TRB */
2742 data += trb_len;
2743 len -= trb_len;
2744 trb++;
2745 }
2746
2747 /* Mark zero-length packet (if present) as a separate transfer */
2748 if ( zlp && ( count > 1 ) )
2749 trb[-2].normal.flags = 0;
2750
2751 /* Generate completion for final TRB */
2752 trb[-1].normal.flags = XHCI_TRB_IOC;
2753
2754 /* Enqueue TRBs */
2755 if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
2756 count ) ) != 0 )
2757 goto err_enqueue;
2758
2759 /* Ring the doorbell */
2760 xhci_doorbell ( &endpoint->ring );
2761
2762 profile_stop ( &xhci_stream_profiler );
2763 return 0;
2764
2765 err_enqueue:
2766 iob_unmap ( iobuf );
2767 err_map:
2768 return rc;
2769}
struct arbelprm_completion_queue_entry normal
Definition arbel.h:0
A normal transfer request block.
Definition xhci.h:350
uint8_t flags
Flags.
Definition xhci.h:356
struct xhci_trb_normal normal
Normal TRB.
Definition xhci.h:691
static unsigned int xhci_endpoint_count(size_t len, int zlp)
Calculate number of TRBs.
Definition xhci.c:2680
#define XHCI_TRB_NORMAL
A normal transfer request block.
Definition xhci.h:364
#define XHCI_TRB_CH
Transfer request block chain flag.
Definition xhci.h:335

References usb_endpoint::address, count, cpu_to_le32, cpu_to_le64, data, xhci_device::dma, DMA_RX, DMA_TX, xhci_endpoint::ep, xhci_trb_normal::flags, iob_dma(), iob_len(), iob_map(), iob_unmap(), len, memset(), normal, xhci_trb::normal, profile_start(), profile_stop(), rc, xhci_endpoint::ring, USB_DIR_IN, usb_endpoint_get_hostdata(), xhci_endpoint::xhci, xhci_doorbell(), xhci_endpoint_count(), xhci_enqueue_multi(), XHCI_MTU, XHCI_TRB_CH, XHCI_TRB_IOC, and XHCI_TRB_NORMAL.

◆ xhci_device_open()

int xhci_device_open ( struct usb_device * usb)
static

Open device.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 2784 of file xhci.c.

2784 {
2785 struct xhci_device *xhci = usb_bus_get_hostdata ( usb->port->hub->bus );
2786 struct usb_port *root_port = usb_root_hub_port ( usb );
2787 struct usb_port *tt = usb_transaction_translator ( usb );
2788 struct xhci_slot *slot;
2789 struct xhci_slot *tt_slot;
2790 size_t len;
2791 int type;
2792 int id;
2793 int rc;
2794
2795 /* Determine applicable slot type */
2796 type = xhci_port_slot_type ( xhci, root_port->address );
2797 if ( type < 0 ) {
2798 rc = type;
2799 DBGC ( xhci, "XHCI %s-%d has no slot type\n",
2800 xhci->name, usb->port->address );
2801 goto err_type;
2802 }
2803
2804 /* Allocate a device slot number */
2805 id = xhci_enable_slot ( xhci, type );
2806 if ( id < 0 ) {
2807 rc = id;
2808 goto err_enable_slot;
2809 }
2810 assert ( ( id > 0 ) && ( ( unsigned int ) id <= xhci->slots ) );
2811 assert ( xhci->slot[id] == NULL );
2812
2813 /* Allocate and initialise structure */
2814 slot = zalloc ( sizeof ( *slot ) );
2815 if ( ! slot ) {
2816 rc = -ENOMEM;
2817 goto err_alloc;
2818 }
2820 xhci->slot[id] = slot;
2821 slot->xhci = xhci;
2822 slot->usb = usb;
2823 slot->id = id;
2824 if ( tt ) {
2825 tt_slot = usb_get_hostdata ( tt->hub->usb );
2826 slot->tt_id = tt_slot->id;
2827 slot->tt_port = tt->address;
2828 }
2829
2830 /* Allocate a device context */
2832 slot->context = dma_alloc ( xhci->dma, &slot->map, len,
2833 xhci_align ( len ) );
2834 if ( ! slot->context ) {
2835 rc = -ENOMEM;
2836 goto err_alloc_context;
2837 }
2838 memset ( slot->context, 0, len );
2839
2840 /* Set device context base address */
2841 assert ( xhci->dcbaa.context[id] == 0 );
2842 xhci->dcbaa.context[id] = cpu_to_le64 ( dma ( &slot->map,
2843 slot->context ) );
2844
2845 DBGC2 ( xhci, "XHCI %s slot %d device context [%08lx,%08lx) for %s\n",
2846 xhci->name, slot->id, virt_to_phys ( slot->context ),
2847 ( virt_to_phys ( slot->context ) + len ), usb->name );
2848 return 0;
2849
2850 xhci->dcbaa.context[id] = 0;
2851 dma_free ( &slot->map, slot->context, len );
2852 err_alloc_context:
2853 xhci->slot[id] = NULL;
2854 free ( slot );
2855 err_alloc:
2856 xhci_disable_slot ( xhci, id );
2857 err_enable_slot:
2858 err_type:
2859 return rc;
2860}
uint8_t id
Request identifier.
Definition ena.h:1
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition usb.h:1072
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition usb.h:794
struct usb_port * port
USB port.
Definition usb.h:737
struct usb_bus * bus
USB bus.
Definition usb.h:855
struct usb_device * usb
Underlying USB device, if any.
Definition usb.h:857
struct usb_hub * hub
USB hub.
Definition usb.h:825
struct usb_device * usb
Currently attached device (if in use).
Definition usb.h:845
unsigned int address
Port address.
Definition usb.h:827
struct xhci_device * xhci
xHCI device
Definition xhci.h:1138
unsigned int id
Slot ID.
Definition xhci.h:1142
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
Definition usb.c:2371
struct usb_port * usb_root_hub_port(struct usb_device *usb)
Get USB root hub port.
Definition usb.c:2355
static int xhci_port_slot_type(struct xhci_device *xhci, unsigned int port)
Find port slot type.
Definition xhci.c:767
static int xhci_disable_slot(struct xhci_device *xhci, unsigned int slot)
Disable slot.
Definition xhci.c:1996
static int xhci_enable_slot(struct xhci_device *xhci, unsigned int type)
Enable slot.
Definition xhci.c:1962

References usb_port::address, assert, usb_hub::bus, xhci_dcbaa::context, cpu_to_le64, DBGC, DBGC2, xhci_device::dcbaa, dma(), xhci_device::dma, dma_alloc(), dma_free(), ENOMEM, free, usb_port::hub, id, xhci_slot::id, len, memset(), usb_device::name, xhci_device::name, NULL, usb_device::port, rc, slot, xhci_device::slot, type, usb_hub::usb, usb_port::usb, xhci_slot::usb, usb_bus_get_hostdata(), usb_get_hostdata(), usb_root_hub_port(), usb_set_hostdata(), usb_transaction_translator(), xhci_slot::xhci, xhci_align(), XHCI_CTX_END, xhci_device_context_offset(), xhci_disable_slot(), xhci_enable_slot(), xhci_port_slot_type(), and zalloc().

◆ xhci_device_close()

void xhci_device_close ( struct usb_device * usb)
static

Close device.

Parameters
usbUSB device

Definition at line 2867 of file xhci.c.

2867 {
2868 struct xhci_slot *slot = usb_get_hostdata ( usb );
2869 struct xhci_device *xhci = slot->xhci;
2870 size_t len = xhci_device_context_offset ( xhci, XHCI_CTX_END );
2871 unsigned int id = slot->id;
2872 int rc;
2873
2874 /* Disable slot */
2875 if ( ( rc = xhci_disable_slot ( xhci, id ) ) != 0 ) {
2876 /* Slot is still enabled. Leak the slot context,
2877 * since the controller may still write to this
2878 * memory, and leave the DCBAA entry intact.
2879 *
2880 * If the controller later reports that this same slot
2881 * has been re-enabled, then some assertions will be
2882 * triggered.
2883 */
2884 DBGC ( xhci, "XHCI %s slot %d leaking context memory\n",
2885 xhci->name, slot->id );
2886 slot->context = NULL;
2887 }
2888
2889 /* Free slot */
2890 if ( slot->context ) {
2891 dma_free ( &slot->map, slot->context, len );
2892 xhci->dcbaa.context[id] = 0;
2893 }
2894 xhci->slot[id] = NULL;
2895 free ( slot );
2896}

References xhci_dcbaa::context, DBGC, xhci_device::dcbaa, dma_free(), free, id, len, xhci_device::name, NULL, rc, slot, xhci_device::slot, xhci_slot::usb, usb_get_hostdata(), XHCI_CTX_END, xhci_device_context_offset(), and xhci_disable_slot().

◆ xhci_device_address()

int xhci_device_address ( struct usb_device * usb)
static

Assign device address.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 2904 of file xhci.c.

2904 {
2905 struct xhci_slot *slot = usb_get_hostdata ( usb );
2906 struct xhci_device *xhci = slot->xhci;
2907 struct usb_port *root_port;
2908 int psiv;
2909 int rc;
2910
2911 /* Calculate route string */
2912 slot->route = usb_route_string ( usb );
2913
2914 /* Calculate root hub port number */
2915 root_port = usb_root_hub_port ( usb );
2916 slot->port = root_port->address;
2917
2918 /* Calculate protocol speed ID */
2919 psiv = xhci_port_psiv ( xhci, slot->port, usb->speed );
2920 if ( psiv < 0 ) {
2921 rc = psiv;
2922 return rc;
2923 }
2924 slot->psiv = psiv;
2925
2926 /* Address device */
2927 if ( ( rc = xhci_address_device ( xhci, slot ) ) != 0 )
2928 return rc;
2929
2930 return 0;
2931}
unsigned int speed
Device speed.
Definition usb.h:739
unsigned int usb_route_string(struct usb_device *usb)
Get USB route string.
Definition usb.c:2335
static int xhci_address_device(struct xhci_device *xhci, struct xhci_slot *slot)
Address device.
Definition xhci.c:2120
static int xhci_port_psiv(struct xhci_device *xhci, unsigned int port, unsigned int speed)
Find protocol speed ID value.
Definition xhci.c:855

References usb_port::address, rc, slot, usb_device::speed, usb_port::usb, xhci_slot::usb, usb_get_hostdata(), usb_root_hub_port(), usb_route_string(), xhci_address_device(), and xhci_port_psiv().

◆ xhci_bus_open()

int xhci_bus_open ( struct usb_bus * bus)
static

Open USB bus.

Parameters
busUSB bus
Return values
rcReturn status code

Definition at line 2946 of file xhci.c.

2946 {
2947 struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
2948 int rc;
2949
2950 /* Allocate device slot array */
2951 xhci->slot = zalloc ( ( xhci->slots + 1 ) * sizeof ( xhci->slot[0] ) );
2952 if ( ! xhci->slot ) {
2953 rc = -ENOMEM;
2954 goto err_slot_alloc;
2955 }
2956
2957 /* Allocate device context base address array */
2958 if ( ( rc = xhci_dcbaa_alloc ( xhci ) ) != 0 )
2959 goto err_dcbaa_alloc;
2960
2961 /* Allocate scratchpad buffers */
2962 if ( ( rc = xhci_scratchpad_alloc ( xhci ) ) != 0 )
2963 goto err_scratchpad_alloc;
2964
2965 /* Allocate command ring */
2966 if ( ( rc = xhci_command_alloc ( xhci ) ) != 0 )
2967 goto err_command_alloc;
2968
2969 /* Allocate event ring */
2970 if ( ( rc = xhci_event_alloc ( xhci ) ) != 0 )
2971 goto err_event_alloc;
2972
2973 /* Start controller */
2974 xhci_run ( xhci );
2975
2976 return 0;
2977
2978 xhci_stop ( xhci );
2979 xhci_event_free ( xhci );
2980 err_event_alloc:
2981 xhci_command_free ( xhci );
2982 err_command_alloc:
2983 xhci_scratchpad_free ( xhci );
2984 err_scratchpad_alloc:
2985 xhci_dcbaa_free ( xhci );
2986 err_dcbaa_alloc:
2987 free ( xhci->slot );
2988 err_slot_alloc:
2989 return rc;
2990}
uint8_t bus
Bus.
Definition edd.h:1
static int xhci_command_alloc(struct xhci_device *xhci)
Allocate command ring.
Definition xhci.c:1456
static int xhci_scratchpad_alloc(struct xhci_device *xhci)
Allocate scratchpad buffers.
Definition xhci.c:988
static int xhci_event_alloc(struct xhci_device *xhci)
Allocate event ring.
Definition xhci.c:1505
static void xhci_scratchpad_free(struct xhci_device *xhci)
Free scratchpad buffers.
Definition xhci.c:1054
static int xhci_dcbaa_alloc(struct xhci_device *xhci)
Allocate device context base address array.
Definition xhci.c:917
static void xhci_event_free(struct xhci_device *xhci)
Free event ring.
Definition xhci.c:1570
static void xhci_command_free(struct xhci_device *xhci)
Free command ring.
Definition xhci.c:1487
static void xhci_run(struct xhci_device *xhci)
Start xHCI device.
Definition xhci.c:1088
static void xhci_dcbaa_free(struct xhci_device *xhci)
Free device context base address array.
Definition xhci.c:959

References bus, ENOMEM, free, rc, xhci_device::slot, xhci_device::slots, usb_bus_get_hostdata(), xhci_command_alloc(), xhci_command_free(), xhci_dcbaa_alloc(), xhci_dcbaa_free(), xhci_event_alloc(), xhci_event_free(), xhci_run(), xhci_scratchpad_alloc(), xhci_scratchpad_free(), xhci_stop(), and zalloc().

◆ xhci_bus_close()

void xhci_bus_close ( struct usb_bus * bus)
static

Close USB bus.

Parameters
busUSB bus

Definition at line 2997 of file xhci.c.

2997 {
2998 struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
2999 unsigned int i;
3000
3001 /* Sanity checks */
3002 assert ( xhci->slot != NULL );
3003 for ( i = 0 ; i <= xhci->slots ; i++ )
3004 assert ( xhci->slot[i] == NULL );
3005
3006 xhci_stop ( xhci );
3007 xhci_event_free ( xhci );
3008 xhci_command_free ( xhci );
3009 xhci_scratchpad_free ( xhci );
3010 xhci_dcbaa_free ( xhci );
3011 free ( xhci->slot );
3012}

References assert, bus, free, NULL, xhci_device::slot, xhci_device::slots, usb_bus_get_hostdata(), xhci_command_free(), xhci_dcbaa_free(), xhci_event_free(), xhci_scratchpad_free(), and xhci_stop().

◆ xhci_bus_poll()

void xhci_bus_poll ( struct usb_bus * bus)
static

Poll USB bus.

Parameters
busUSB bus

Definition at line 3019 of file xhci.c.

3019 {
3020 struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
3021
3022 /* Poll event ring */
3023 xhci_event_poll ( xhci );
3024}

References bus, usb_bus_get_hostdata(), and xhci_event_poll().

◆ xhci_hub_open()

int xhci_hub_open ( struct usb_hub * hub)
static

Open hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 3039 of file xhci.c.

3039 {
3040 struct xhci_slot *slot;
3041
3042 /* Do nothing if this is the root hub */
3043 if ( ! hub->usb )
3044 return 0;
3045
3046 /* Get device slot */
3047 slot = usb_get_hostdata ( hub->usb );
3048
3049 /* Update device slot hub parameters. We don't inform the
3050 * hardware of this information until the hub's interrupt
3051 * endpoint is opened, since the only mechanism for so doing
3052 * provided by the xHCI specification is a Configure Endpoint
3053 * command, and we can't issue that command until we have a
3054 * non-EP0 endpoint to configure.
3055 */
3056 slot->ports = hub->ports;
3057
3058 return 0;
3059}
unsigned int ports
Number of ports.
Definition usb.h:861

References usb_hub::ports, slot, usb_hub::usb, and usb_get_hostdata().

◆ xhci_hub_close()

void xhci_hub_close ( struct usb_hub *hub __unused)
static

Close hub.

Parameters
hubUSB hub

Definition at line 3066 of file xhci.c.

3066 {
3067
3068 /* Nothing to do */
3069}

References __unused.

◆ xhci_root_open()

int xhci_root_open ( struct usb_hub * hub)
static

Open root hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 3084 of file xhci.c.

3084 {
3085 struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3086 struct usb_port *port;
3087 uint32_t portsc;
3088 unsigned int i;
3089
3090 /* Enable power to all ports */
3091 for ( i = 1 ; i <= xhci->ports ; i++ ) {
3092 portsc = readl ( xhci->op + XHCI_OP_PORTSC ( i ) );
3093 portsc &= XHCI_PORTSC_PRESERVE;
3094 portsc |= XHCI_PORTSC_PP;
3095 writel ( portsc, xhci->op + XHCI_OP_PORTSC ( i ) );
3096 }
3097
3098 /* xHCI spec requires us to potentially wait 20ms after
3099 * enabling power to a port.
3100 */
3102
3103 /* USB3 ports may power up as Disabled */
3104 for ( i = 1 ; i <= xhci->ports ; i++ ) {
3105 portsc = readl ( xhci->op + XHCI_OP_PORTSC ( i ) );
3106 port = usb_port ( hub, i );
3107 if ( ( port->protocol >= USB_PROTO_3_0 ) &&
3108 ( ( portsc & XHCI_PORTSC_PLS_MASK ) ==
3110 /* Force link state to RxDetect */
3111 portsc &= XHCI_PORTSC_PRESERVE;
3113 writel ( portsc, xhci->op + XHCI_OP_PORTSC ( i ) );
3114 }
3115 }
3116
3117 /* Some xHCI cards seem to require an additional delay after
3118 * setting the link state to RxDetect.
3119 */
3121
3122 return 0;
3123}
@ USB_PROTO_3_0
USB 3.0.
Definition usb.h:25
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition usb.h:958
#define XHCI_PORTSC_PLS_RXDETECT
RxDetect port link state.
Definition xhci.h:222
#define XHCI_PORT_POWER_DELAY_MS
Time to delay after enabling power to a port.
Definition xhci.h:231
#define XHCI_PORTSC_LWS
Port link state write strobe.
Definition xhci.h:243
#define XHCI_PORTSC_PLS_DISABLED
Disabled port link state.
Definition xhci.h:219
#define XHCI_LINK_STATE_DELAY_MS
Time to delay after writing the port link state.
Definition xhci.h:246
#define XHCI_PORTSC_PLS_MASK
Port link state mask.
Definition xhci.h:225

References usb_port::hub, mdelay(), xhci_device::op, port, xhci_device::ports, readl, usb_hub_get_drvdata(), usb_port(), USB_PROTO_3_0, writel, XHCI_LINK_STATE_DELAY_MS, XHCI_OP_PORTSC, XHCI_PORT_POWER_DELAY_MS, XHCI_PORTSC_LWS, XHCI_PORTSC_PLS_DISABLED, XHCI_PORTSC_PLS_MASK, XHCI_PORTSC_PLS_RXDETECT, XHCI_PORTSC_PP, and XHCI_PORTSC_PRESERVE.

◆ xhci_root_close()

void xhci_root_close ( struct usb_hub *hub __unused)
static

Close root hub.

Parameters
hubUSB hub

Definition at line 3130 of file xhci.c.

3130 {
3131
3132 /* Nothing to do */
3133}

References __unused.

◆ xhci_root_enable()

int xhci_root_enable ( struct usb_hub * hub,
struct usb_port * port )
static

Enable port.

Parameters
hubUSB hub
portUSB port
Return values
rcReturn status code

Definition at line 3142 of file xhci.c.

3142 {
3143 struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3144 uint32_t portsc;
3145 unsigned int i;
3146
3147 /* Reset port */
3148 portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3149 portsc &= XHCI_PORTSC_PRESERVE;
3150 portsc |= XHCI_PORTSC_PR;
3151 writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3152
3153 /* Wait for port to become enabled */
3154 for ( i = 0 ; i < XHCI_PORT_RESET_MAX_WAIT_MS ; i++ ) {
3155
3156 /* Check port status */
3157 portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3158 if ( portsc & XHCI_PORTSC_PED )
3159 return 0;
3160
3161 /* Delay */
3162 mdelay ( 1 );
3163 }
3164
3165 DBGC ( xhci, "XHCI %s-%d timed out waiting for port to enable\n",
3166 xhci->name, port->address );
3167 return -ETIMEDOUT;
3168}
#define XHCI_PORT_RESET_MAX_WAIT_MS
Maximum time to wait for a port reset to complete.
Definition xhci.h:1018

References DBGC, ETIMEDOUT, mdelay(), xhci_device::name, xhci_device::op, port, readl, usb_hub_get_drvdata(), writel, XHCI_OP_PORTSC, XHCI_PORT_RESET_MAX_WAIT_MS, XHCI_PORTSC_PED, XHCI_PORTSC_PR, and XHCI_PORTSC_PRESERVE.

◆ xhci_root_disable()

int xhci_root_disable ( struct usb_hub * hub,
struct usb_port * port )
static

Disable port.

Parameters
hubUSB hub
portUSB port
Return values
rcReturn status code

Definition at line 3177 of file xhci.c.

3177 {
3178 struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3179 uint32_t portsc;
3180
3181 /* Disable port */
3182 portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3183 portsc &= XHCI_PORTSC_PRESERVE;
3184 portsc |= XHCI_PORTSC_PED;
3185 writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3186
3187 /* Allow time for link state to stabilise */
3189
3190 /* Set link state to RxDetect for USB3 ports */
3191 if ( port->protocol >= USB_PROTO_3_0 ) {
3192 portsc &= XHCI_PORTSC_PRESERVE;
3194 writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3195 }
3196
3197 /* Allow time for link state to stabilise */
3199
3200 return 0;
3201}

References mdelay(), xhci_device::op, port, readl, usb_hub_get_drvdata(), USB_PROTO_3_0, writel, XHCI_LINK_STATE_DELAY_MS, XHCI_OP_PORTSC, XHCI_PORTSC_LWS, XHCI_PORTSC_PED, XHCI_PORTSC_PLS_RXDETECT, and XHCI_PORTSC_PRESERVE.

◆ xhci_root_speed()

int xhci_root_speed ( struct usb_hub * hub,
struct usb_port * port )
static

Update root hub port speed.

Parameters
hubUSB hub
portUSB port
Return values
rcReturn status code

Definition at line 3210 of file xhci.c.

3210 {
3211 struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3212 uint32_t portsc;
3213 unsigned int psiv;
3214 int ccs;
3215 int ped;
3216 int csc;
3217 int speed;
3218 int rc;
3219
3220 /* Read port status */
3221 portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3222 DBGC2 ( xhci, "XHCI %s-%d status is %08x\n",
3223 xhci->name, port->address, portsc );
3224 ccs = ( portsc & XHCI_PORTSC_CCS );
3225 ped = ( portsc & XHCI_PORTSC_PED );
3226 csc = ( portsc & XHCI_PORTSC_CSC );
3227 psiv = XHCI_PORTSC_PSIV ( portsc );
3228
3229 /* Record disconnections and clear changes */
3230 port->disconnected |= csc;
3232 writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3233
3234 /* Port speed is not valid unless port is connected */
3235 if ( ! ccs ) {
3236 port->speed = USB_SPEED_NONE;
3237 return 0;
3238 }
3239
3240 /* For USB2 ports, the PSIV field is not valid until the port
3241 * completes reset and becomes enabled.
3242 */
3243 if ( ( port->protocol < USB_PROTO_3_0 ) && ! ped ) {
3244 port->speed = USB_SPEED_FULL;
3245 return 0;
3246 }
3247
3248 /* Get port speed and map to generic USB speed */
3249 speed = xhci_port_speed ( xhci, port->address, psiv );
3250 if ( speed < 0 ) {
3251 rc = speed;
3252 return rc;
3253 }
3254
3255 port->speed = speed;
3256 return 0;
3257}
@ USB_SPEED_NONE
Not connected.
Definition usb.h:47
static int xhci_port_speed(struct xhci_device *xhci, unsigned int port, unsigned int psiv)
Find port speed.
Definition xhci.c:791

References DBGC2, xhci_device::name, xhci_device::op, port, rc, readl, usb_hub_get_drvdata(), USB_PROTO_3_0, USB_SPEED_FULL, USB_SPEED_NONE, writel, XHCI_OP_PORTSC, xhci_port_speed(), XHCI_PORTSC_CCS, XHCI_PORTSC_CHANGE, XHCI_PORTSC_CSC, XHCI_PORTSC_PED, XHCI_PORTSC_PRESERVE, and XHCI_PORTSC_PSIV.

◆ xhci_root_clear_tt()

int xhci_root_clear_tt ( struct usb_hub * hub,
struct usb_port * port,
struct usb_endpoint * ep )
static

Clear transaction translator buffer.

Parameters
hubUSB hub
portUSB port
epUSB endpoint
Return values
rcReturn status code

Definition at line 3267 of file xhci.c.

3268 {
3269 struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3270
3271 /* Should never be called; this is a root hub */
3272 DBGC ( xhci, "XHCI %s-%d nonsensical CLEAR_TT for %s %s\n", xhci->name,
3273 port->address, ep->usb->name, usb_endpoint_name ( ep ) );
3274
3275 return -ENOTSUP;
3276}
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging).
Definition usb.c:220

References DBGC, ENOTSUP, usb_device::name, xhci_device::name, port, usb_endpoint::usb, usb_endpoint_name(), and usb_hub_get_drvdata().

◆ xhci_register()

int xhci_register ( struct xhci_device * xhci)

Register xHCI controller.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 3325 of file xhci.c.

3325 {
3326 struct usb_port *port;
3327 unsigned int i;
3328 int rc;
3329
3330 /* Reset device */
3331 if ( ( rc = xhci_reset ( xhci ) ) != 0 )
3332 goto err_reset;
3333
3334 /* Allocate USB bus */
3335 xhci->bus = alloc_usb_bus ( xhci->dev, xhci->ports, XHCI_MTU,
3336 &xhci_operations );
3337 if ( ! xhci->bus ) {
3338 rc = -ENOMEM;
3339 goto err_alloc_bus;
3340 }
3341 usb_bus_set_hostdata ( xhci->bus, xhci );
3342 usb_hub_set_drvdata ( xhci->bus->hub, xhci );
3343
3344 /* Set port protocols */
3345 for ( i = 1 ; i <= xhci->ports ; i++ ) {
3346 port = usb_port ( xhci->bus->hub, i );
3347 port->protocol = xhci_port_protocol ( xhci, i );
3348 }
3349
3350 /* Register USB bus */
3351 if ( ( rc = register_usb_bus ( xhci->bus ) ) != 0 )
3352 goto err_register;
3353
3354 return 0;
3355
3356 unregister_usb_bus ( xhci->bus );
3357 err_register:
3358 free_usb_bus ( xhci->bus );
3359 err_alloc_bus:
3360 xhci_reset ( xhci );
3361 err_reset:
3362 return rc;
3363}
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition usb.h:947
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition usb.h:1061
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition usb.c:2170
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition usb.c:2130
struct usb_bus * alloc_usb_bus(struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
Allocate USB bus.
Definition usb.c:2094
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition usb.c:2194
static unsigned int xhci_port_protocol(struct xhci_device *xhci, unsigned int port)
Find port protocol.
Definition xhci.c:706
static struct usb_host_operations xhci_operations
USB host controller operations.
Definition xhci.c:3286

References alloc_usb_bus(), xhci_device::bus, xhci_device::dev, ENOMEM, free_usb_bus(), usb_bus::hub, port, xhci_device::ports, rc, register_usb_bus(), unregister_usb_bus(), usb_bus_set_hostdata(), usb_hub_set_drvdata(), usb_port(), XHCI_MTU, xhci_operations, xhci_port_protocol(), and xhci_reset().

Referenced by dwusb_probe(), and xhci_probe().

◆ xhci_unregister()

void xhci_unregister ( struct xhci_device * xhci)

Unregister xHCI controller.

Parameters
xhcixHCI device

Definition at line 3370 of file xhci.c.

3370 {
3371 struct usb_bus *bus = xhci->bus;
3372
3373 /* Unregister and free USB bus */
3375 free_usb_bus ( bus );
3376
3377 /* Reset device */
3378 xhci_reset ( xhci );
3379}
A USB bus.
Definition usb.h:976

References bus, xhci_device::bus, free_usb_bus(), unregister_usb_bus(), and xhci_reset().

Referenced by dwusb_probe(), dwusb_remove(), xhci_probe(), and xhci_remove().

◆ xhci_pch_fix()

void xhci_pch_fix ( struct xhci_device * xhci,
struct pci_device * pci )
static

Fix Intel PCH-specific quirks.

Parameters
xhcixHCI device
pciPCI device

Definition at line 3394 of file xhci.c.

3394 {
3395 struct xhci_pch *pch = &xhci->pch;
3397 uint32_t xusb2prm;
3399 uint32_t usb3prm;
3400
3401 /* Enable SuperSpeed capability. Do this before rerouting
3402 * USB2 ports, so that USB3 devices connect at SuperSpeed.
3403 */
3405 pci_read_config_dword ( pci, XHCI_PCH_USB3PRM, &usb3prm );
3406 if ( usb3prm & ~usb3pssen ) {
3407 DBGC ( xhci, "XHCI %s enabling SuperSpeed on ports %08x\n",
3408 xhci->name, ( usb3prm & ~usb3pssen ) );
3409 }
3410 pch->usb3pssen = usb3pssen;
3411 usb3pssen |= usb3prm;
3413
3414 /* Route USB2 ports from EHCI to xHCI */
3416 pci_read_config_dword ( pci, XHCI_PCH_XUSB2PRM, &xusb2prm );
3417 if ( xusb2prm & ~xusb2pr ) {
3418 DBGC ( xhci, "XHCI %s routing ports %08x from EHCI to xHCI\n",
3419 xhci->name, ( xusb2prm & ~xusb2pr ) );
3420 }
3421 pch->xusb2pr = xusb2pr;
3422 xusb2pr |= xusb2prm;
3424}
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
struct xhci_pch pch
Intel PCH quirk.
Definition xhci.h:1132
Intel PCH quirk.
Definition xhci.h:1021
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
Definition xhci.h:1025
uint32_t xusb2pr
USB2 port routing register original value.
Definition xhci.h:1023
#define XHCI_PCH_USB3PRM
Intel PCH USB3 port routing mask register.
Definition xhci.h:1041
#define XHCI_PCH_XUSB2PRM
Intel PCH USB2 port routing mask register.
Definition xhci.h:1035
#define XHCI_PCH_XUSB2PR
Intel PCH USB2 port routing register.
Definition xhci.h:1032
#define XHCI_PCH_USB3PSSEN
Intel PCH SuperSpeed enable register.
Definition xhci.h:1038

References DBGC, xhci_device::name, xhci_device::pch, pci_read_config_dword(), pci_write_config_dword(), xhci_pch::usb3pssen, XHCI_PCH_USB3PRM, XHCI_PCH_USB3PSSEN, XHCI_PCH_XUSB2PR, XHCI_PCH_XUSB2PRM, and xhci_pch::xusb2pr.

Referenced by xhci_probe().

◆ xhci_pch_undo()

void xhci_pch_undo ( struct xhci_device * xhci,
struct pci_device * pci )
static

Undo Intel PCH-specific quirk fixes.

Parameters
xhcixHCI device
pciPCI device

Definition at line 3432 of file xhci.c.

3432 {
3433 struct xhci_pch *pch = &xhci->pch;
3434
3435 /* Restore USB2 port routing to original state */
3437
3438 /* Restore SuperSpeed capability to original state */
3440}

References xhci_device::pch, pci_write_config_dword(), xhci_pch::usb3pssen, XHCI_PCH_USB3PSSEN, XHCI_PCH_XUSB2PR, and xhci_pch::xusb2pr.

Referenced by xhci_probe(), and xhci_remove().

◆ xhci_probe()

int xhci_probe ( struct pci_device * pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 3448 of file xhci.c.

3448 {
3449 struct xhci_device *xhci;
3450 unsigned long bar_start;
3451 size_t bar_size;
3452 int rc;
3453
3454 /* Allocate and initialise structure */
3455 xhci = zalloc ( sizeof ( *xhci ) );
3456 if ( ! xhci ) {
3457 rc = -ENOMEM;
3458 goto err_alloc;
3459 }
3460 xhci->dev = &pci->dev;
3461 xhci->dma = &pci->dma;
3462 xhci->quirks = pci->id->driver_data;
3463
3464 /* Fix up PCI device */
3465 adjust_pci_device ( pci );
3466
3467 /* Map registers */
3468 bar_start = pci_bar_start ( pci, XHCI_BAR );
3469 bar_size = pci_bar_size ( pci, XHCI_BAR );
3470 xhci->regs = pci_ioremap ( pci, bar_start, bar_size );
3471 if ( ! xhci->regs ) {
3472 rc = -ENODEV;
3473 goto err_ioremap;
3474 }
3475
3476 /* Initialise xHCI device */
3477 xhci_init ( xhci );
3478
3479 /* Initialise USB legacy support and claim ownership */
3480 xhci_legacy_init ( xhci );
3481 xhci_legacy_claim ( xhci );
3482
3483 /* Fix Intel PCH-specific quirks, if applicable */
3484 if ( xhci->quirks & XHCI_PCH )
3485 xhci_pch_fix ( xhci, pci );
3486
3487 /* Register xHCI device */
3488 if ( ( rc = xhci_register ( xhci ) ) != 0 )
3489 goto err_register;
3490
3491 pci_set_drvdata ( pci, xhci );
3492 return 0;
3493
3494 xhci_unregister ( xhci );
3495 err_register:
3496 if ( xhci->quirks & XHCI_PCH )
3497 xhci_pch_undo ( xhci, pci );
3498 xhci_legacy_release ( xhci );
3499 iounmap ( xhci->regs );
3500 err_ioremap:
3501 free ( xhci );
3502 err_alloc:
3503 return rc;
3504}
#define ENODEV
No such device.
Definition errno.h:553
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition pci.c:178
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:255
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition pci.c:111
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:370
unsigned long driver_data
Arbitrary driver data.
Definition pci.h:186
struct device dev
Generic device.
Definition pci.h:216
struct pci_device_id * id
Driver device ID.
Definition pci.h:251
struct dma_device dma
DMA device.
Definition pci.h:218
static void xhci_legacy_init(struct xhci_device *xhci)
Initialise USB legacy support.
Definition xhci.c:540
void xhci_unregister(struct xhci_device *xhci)
Unregister xHCI controller.
Definition xhci.c:3370
int xhci_register(struct xhci_device *xhci)
Register xHCI controller.
Definition xhci.c:3325
static void xhci_legacy_claim(struct xhci_device *xhci)
Claim ownership from BIOS.
Definition xhci.c:571
static void xhci_pch_undo(struct xhci_device *xhci, struct pci_device *pci)
Undo Intel PCH-specific quirk fixes.
Definition xhci.c:3432
static void xhci_legacy_release(struct xhci_device *xhci)
Release ownership back to BIOS.
Definition xhci.c:618
void xhci_init(struct xhci_device *xhci)
Initialise device.
Definition xhci.c:264
static void xhci_pch_fix(struct xhci_device *xhci, struct pci_device *pci)
Fix Intel PCH-specific quirks.
Definition xhci.c:3394
#define XHCI_PCH
Intel PCH quirk flag.
Definition xhci.h:1029
#define XHCI_BAR
xHCI PCI BAR
Definition xhci.h:31

References adjust_pci_device(), pci_device::dev, xhci_device::dev, pci_device::dma, xhci_device::dma, pci_device_id::driver_data, ENODEV, ENOMEM, free, pci_device::id, iounmap(), pci_bar_size(), pci_bar_start(), pci_ioremap(), pci_set_drvdata(), xhci_device::quirks, rc, xhci_device::regs, XHCI_BAR, xhci_init(), xhci_legacy_claim(), xhci_legacy_init(), xhci_legacy_release(), XHCI_PCH, xhci_pch_fix(), xhci_pch_undo(), xhci_register(), xhci_unregister(), and zalloc().

◆ xhci_remove()

void xhci_remove ( struct pci_device * pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 3511 of file xhci.c.

3511 {
3512 struct xhci_device *xhci = pci_get_drvdata ( pci );
3514
3515 /* Some systems are observed to disable bus mastering on
3516 * Thunderbolt controllers before we get a chance to shut
3517 * down. Detect this and avoid attempting any DMA operations,
3518 * which are guaranteed to fail and may end up spuriously
3519 * completing after the operating system kernel starts up.
3520 */
3522 if ( ! ( command & PCI_COMMAND_MASTER ) ) {
3523 DBGC ( xhci, "XHCI %s DMA was disabled\n", xhci->name );
3524 xhci_fail ( xhci );
3525 }
3526
3527 /* Unregister xHCI controller */
3528 xhci_unregister ( xhci );
3529
3530 /* Undo any PCH-specific fixes */
3531 if ( xhci->quirks & XHCI_PCH )
3532 xhci_pch_undo ( xhci, pci );
3533
3534 /* Release ownership back to BIOS */
3535 xhci_legacy_release ( xhci );
3536
3537 /* Unmap registers */
3538 iounmap ( xhci->regs );
3539
3540 /* Free device */
3541 free ( xhci );
3542}
unsigned short uint16_t
Definition stdint.h:11
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
#define PCI_COMMAND_MASTER
Bus master.
Definition pci.h:29
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:380
#define PCI_COMMAND
PCI command.
Definition pci.h:26
A command-line command.
Definition command.h:10

References DBGC, free, iounmap(), xhci_device::name, PCI_COMMAND, PCI_COMMAND_MASTER, pci_get_drvdata(), pci_read_config_word(), xhci_device::quirks, xhci_device::regs, xhci_fail(), xhci_legacy_release(), XHCI_PCH, xhci_pch_undo(), and xhci_unregister().

◆ xhci_shutdown()

void xhci_shutdown ( int booting)
static

Prepare for exit.

Parameters
bootingSystem is shutting down for OS boot

Definition at line 3566 of file xhci.c.

3566 {
3567 /* If we are shutting down to boot an OS, then prevent the
3568 * release of ownership back to BIOS.
3569 */
3571}

References xhci_legacy_prevent_release.

Referenced by __startup_fn().

◆ __startup_fn()

struct startup_fn xhci_startup __startup_fn ( STARTUP_LATE )

Startup/shutdown function.

References __startup_fn, STARTUP_LATE, and xhci_shutdown().

Variable Documentation

◆ __profiler

struct profiler xhci_transfer_profiler __profiler
static
Initial value:
=
{ .name = "xhci.message" }

Message transfer profiler.

Transfer event profiler.

Event ring profiler.

Stream transfer profiler.

Definition at line 48 of file xhci.c.

48 { .name = "xhci.message" };

◆ xhci_legacy_prevent_release

int xhci_legacy_prevent_release
static

Prevent the release of ownership back to BIOS.

Definition at line 533 of file xhci.c.

Referenced by xhci_legacy_release(), and xhci_shutdown().

◆ xhci_operations

struct usb_host_operations xhci_operations
static

USB host controller operations.

Definition at line 3286 of file xhci.c.

3286 {
3287 .endpoint = {
3288 .open = xhci_endpoint_open,
3289 .close = xhci_endpoint_close,
3290 .reset = xhci_endpoint_reset,
3291 .mtu = xhci_endpoint_mtu,
3292 .message = xhci_endpoint_message,
3293 .stream = xhci_endpoint_stream,
3294 },
3295 .device = {
3296 .open = xhci_device_open,
3297 .close = xhci_device_close,
3298 .address = xhci_device_address,
3299 },
3300 .bus = {
3301 .open = xhci_bus_open,
3302 .close = xhci_bus_close,
3303 .poll = xhci_bus_poll,
3304 },
3305 .hub = {
3306 .open = xhci_hub_open,
3307 .close = xhci_hub_close,
3308 },
3309 .root = {
3310 .open = xhci_root_open,
3311 .close = xhci_root_close,
3312 .enable = xhci_root_enable,
3313 .disable = xhci_root_disable,
3314 .speed = xhci_root_speed,
3315 .clear_tt = xhci_root_clear_tt,
3316 },
3317};
static void xhci_device_close(struct usb_device *usb)
Close device.
Definition xhci.c:2867
static int xhci_endpoint_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
Enqueue stream transfer.
Definition xhci.c:2701
static int xhci_endpoint_message(struct usb_endpoint *ep, struct io_buffer *iobuf)
Enqueue message transfer.
Definition xhci.c:2602
static int xhci_root_speed(struct usb_hub *hub, struct usb_port *port)
Update root hub port speed.
Definition xhci.c:3210
static int xhci_root_open(struct usb_hub *hub)
Open root hub.
Definition xhci.c:3084
static void xhci_root_close(struct usb_hub *hub __unused)
Close root hub.
Definition xhci.c:3130
static void xhci_hub_close(struct usb_hub *hub __unused)
Close hub.
Definition xhci.c:3066
static int xhci_hub_open(struct usb_hub *hub)
Open hub.
Definition xhci.c:3039
static int xhci_device_address(struct usb_device *usb)
Assign device address.
Definition xhci.c:2904
static int xhci_endpoint_open(struct usb_endpoint *ep)
Open endpoint.
Definition xhci.c:2448
static int xhci_endpoint_reset(struct usb_endpoint *ep)
Reset endpoint.
Definition xhci.c:2554
static void xhci_endpoint_close(struct usb_endpoint *ep)
Close endpoint.
Definition xhci.c:2524
static int xhci_bus_open(struct usb_bus *bus)
Open USB bus.
Definition xhci.c:2946
static int xhci_root_enable(struct usb_hub *hub, struct usb_port *port)
Enable port.
Definition xhci.c:3142
static void xhci_bus_close(struct usb_bus *bus)
Close USB bus.
Definition xhci.c:2997
static int xhci_endpoint_mtu(struct usb_endpoint *ep)
Update MTU.
Definition xhci.c:2582
static int xhci_root_clear_tt(struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
Clear transaction translator buffer.
Definition xhci.c:3267
static void xhci_bus_poll(struct usb_bus *bus)
Poll USB bus.
Definition xhci.c:3019
static int xhci_root_disable(struct usb_hub *hub, struct usb_port *port)
Disable port.
Definition xhci.c:3177
static int xhci_device_open(struct usb_device *usb)
Open device.
Definition xhci.c:2784

Referenced by xhci_register().

◆ xhci_ids

struct pci_device_id xhci_ids[]
static
Initial value:
= {
PCI_ROM ( 0x8086, 0x9d2f, "xhci-skylake", "xHCI (Skylake)", ( XHCI_PCH | XHCI_BAD_PSIV ) ),
PCI_ROM ( 0x8086, 0xffff, "xhci-pch", "xHCI (Intel PCH)", XHCI_PCH ),
PCI_ROM ( 0xffff, 0xffff, "xhci", "xHCI", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition pci.h:311

XHCI PCI device IDs.

Definition at line 3545 of file xhci.c.

3545 {
3546 PCI_ROM ( 0x8086, 0x9d2f, "xhci-skylake", "xHCI (Skylake)", ( XHCI_PCH | XHCI_BAD_PSIV ) ),
3547 PCI_ROM ( 0x8086, 0xffff, "xhci-pch", "xHCI (Intel PCH)", XHCI_PCH ),
3548 PCI_ROM ( 0xffff, 0xffff, "xhci", "xHCI", 0 ),
3549};

◆ __pci_driver

struct pci_driver xhci_driver __pci_driver
Initial value:
= {
.ids = xhci_ids,
.id_count = ( sizeof ( xhci_ids ) / sizeof ( xhci_ids[0] ) ),
.probe = xhci_probe,
.remove = xhci_remove,
}
#define PCI_CLASS_SERIAL
Definition Pci22.h:266
#define PCI_CLASS_SERIAL_USB
Definition Pci22.h:272
#define PCI_CLASS_SERIAL_USB_XHCI
xHCI USB controller
Definition pci.h:144
#define PCI_CLASS_ID(base, sub, progif)
Construct PCI class ID.
Definition pci.h:206
static void xhci_remove(struct pci_device *pci)
Remove PCI device.
Definition xhci.c:3511
static struct pci_device_id xhci_ids[]
XHCI PCI device IDs.
Definition xhci.c:3545
static int xhci_probe(struct pci_device *pci)
Probe PCI device.
Definition xhci.c:3448

XHCI PCI driver.

Definition at line 3552 of file xhci.c.

3552 {
3553 .ids = xhci_ids,
3554 .id_count = ( sizeof ( xhci_ids ) / sizeof ( xhci_ids[0] ) ),
3557 .probe = xhci_probe,
3558 .remove = xhci_remove,
3559};