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

Variables

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

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.

◆ EINFO_EIO_DATA

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

Definition at line 66 of file xhci.c.

◆ EIO_BABBLE

#define EIO_BABBLE   __einfo_error ( EINFO_EIO_BABBLE )

Definition at line 69 of file xhci.c.

◆ EINFO_EIO_BABBLE

#define EINFO_EIO_BABBLE
Value:
__einfo_uniqify ( EINFO_EIO, ( 3 - 0 ), \
"Babble detected" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 71 of file xhci.c.

◆ EIO_USB

#define EIO_USB   __einfo_error ( EINFO_EIO_USB )

Definition at line 74 of file xhci.c.

◆ EINFO_EIO_USB

#define EINFO_EIO_USB
Value:
__einfo_uniqify ( EINFO_EIO, ( 4 - 0 ), \
"USB transaction error" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 76 of file xhci.c.

◆ EIO_TRB

#define EIO_TRB   __einfo_error ( EINFO_EIO_TRB )

Definition at line 79 of file xhci.c.

◆ EINFO_EIO_TRB

#define EINFO_EIO_TRB
Value:
__einfo_uniqify ( EINFO_EIO, ( 5 - 0 ), \
"TRB error" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 81 of file xhci.c.

◆ EIO_STALL

#define EIO_STALL   __einfo_error ( EINFO_EIO_STALL )

Definition at line 84 of file xhci.c.

◆ EINFO_EIO_STALL

#define EINFO_EIO_STALL
Value:
__einfo_uniqify ( EINFO_EIO, ( 6 - 0 ), \
"Stall error" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 86 of file xhci.c.

◆ EIO_RESOURCE

#define EIO_RESOURCE   __einfo_error ( EINFO_EIO_RESOURCE )

Definition at line 89 of file xhci.c.

◆ EINFO_EIO_RESOURCE

#define EINFO_EIO_RESOURCE
Value:
__einfo_uniqify ( EINFO_EIO, ( 7 - 0 ), \
"Resource error" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 91 of file xhci.c.

◆ EIO_BANDWIDTH

#define EIO_BANDWIDTH   __einfo_error ( EINFO_EIO_BANDWIDTH )

Definition at line 94 of file xhci.c.

◆ EINFO_EIO_BANDWIDTH

#define EINFO_EIO_BANDWIDTH
Value:
__einfo_uniqify ( EINFO_EIO, ( 8 - 0 ), \
"Bandwidth error" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 96 of file xhci.c.

◆ EIO_NO_SLOTS

#define EIO_NO_SLOTS   __einfo_error ( EINFO_EIO_NO_SLOTS )

Definition at line 99 of file xhci.c.

◆ EINFO_EIO_NO_SLOTS

#define EINFO_EIO_NO_SLOTS
Value:
__einfo_uniqify ( EINFO_EIO, ( 9 - 0 ), \
"No slots available" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 101 of file xhci.c.

◆ EIO_STREAM_TYPE

#define EIO_STREAM_TYPE   __einfo_error ( EINFO_EIO_STREAM_TYPE )

Definition at line 104 of file xhci.c.

◆ EINFO_EIO_STREAM_TYPE

#define EINFO_EIO_STREAM_TYPE
Value:
__einfo_uniqify ( EINFO_EIO, ( 10 - 0 ), \
"Invalid stream type" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 106 of file xhci.c.

◆ EIO_SLOT

#define EIO_SLOT   __einfo_error ( EINFO_EIO_SLOT )

Definition at line 109 of file xhci.c.

◆ EINFO_EIO_SLOT

#define EINFO_EIO_SLOT
Value:
__einfo_uniqify ( EINFO_EIO, ( 11 - 0 ), \
"Slot not enabled" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 111 of file xhci.c.

◆ EIO_ENDPOINT

#define EIO_ENDPOINT   __einfo_error ( EINFO_EIO_ENDPOINT )

Definition at line 114 of file xhci.c.

◆ EINFO_EIO_ENDPOINT

#define EINFO_EIO_ENDPOINT
Value:
__einfo_uniqify ( EINFO_EIO, ( 12 - 0 ), \
"Endpoint not enabled" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 116 of file xhci.c.

◆ EIO_SHORT

#define EIO_SHORT   __einfo_error ( EINFO_EIO_SHORT )

Definition at line 119 of file xhci.c.

◆ EINFO_EIO_SHORT

#define EINFO_EIO_SHORT
Value:
__einfo_uniqify ( EINFO_EIO, ( 13 - 0 ), \
"Short packet" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 121 of file xhci.c.

◆ EIO_UNDERRUN

#define EIO_UNDERRUN   __einfo_error ( EINFO_EIO_UNDERRUN )

Definition at line 124 of file xhci.c.

◆ EINFO_EIO_UNDERRUN

#define EINFO_EIO_UNDERRUN
Value:
__einfo_uniqify ( EINFO_EIO, ( 14 - 0 ), \
"Ring underrun" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 126 of file xhci.c.

◆ EIO_OVERRUN

#define EIO_OVERRUN   __einfo_error ( EINFO_EIO_OVERRUN )

Definition at line 129 of file xhci.c.

◆ EINFO_EIO_OVERRUN

#define EINFO_EIO_OVERRUN
Value:
__einfo_uniqify ( EINFO_EIO, ( 15 - 0 ), \
"Ring overrun" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 131 of file xhci.c.

◆ EIO_VF_RING_FULL

#define EIO_VF_RING_FULL   __einfo_error ( EINFO_EIO_VF_RING_FULL )

Definition at line 134 of file xhci.c.

◆ EINFO_EIO_VF_RING_FULL

#define EINFO_EIO_VF_RING_FULL
Value:
__einfo_uniqify ( EINFO_EIO, ( 16 - 0 ), \
"Virtual function event ring full" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 136 of file xhci.c.

◆ EIO_PARAMETER

#define EIO_PARAMETER   __einfo_error ( EINFO_EIO_PARAMETER )

Definition at line 139 of file xhci.c.

◆ EINFO_EIO_PARAMETER

#define EINFO_EIO_PARAMETER
Value:
__einfo_uniqify ( EINFO_EIO, ( 17 - 0 ), \
"Parameter error" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 141 of file xhci.c.

◆ EIO_BANDWIDTH_OVERRUN

#define EIO_BANDWIDTH_OVERRUN   __einfo_error ( EINFO_EIO_BANDWIDTH_OVERRUN )

Definition at line 144 of file xhci.c.

◆ EINFO_EIO_BANDWIDTH_OVERRUN

#define EINFO_EIO_BANDWIDTH_OVERRUN
Value:
__einfo_uniqify ( EINFO_EIO, ( 18 - 0 ), \
"Bandwidth overrun" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 146 of file xhci.c.

◆ EIO_CONTEXT

#define EIO_CONTEXT   __einfo_error ( EINFO_EIO_CONTEXT )

Definition at line 149 of file xhci.c.

◆ EINFO_EIO_CONTEXT

#define EINFO_EIO_CONTEXT
Value:
__einfo_uniqify ( EINFO_EIO, ( 19 - 0 ), \
"Context state error" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 151 of file xhci.c.

◆ EIO_NO_PING

#define EIO_NO_PING   __einfo_error ( EINFO_EIO_NO_PING )

Definition at line 154 of file xhci.c.

◆ EINFO_EIO_NO_PING

#define EINFO_EIO_NO_PING
Value:
__einfo_uniqify ( EINFO_EIO, ( 20 - 0 ), \
"No ping response" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 156 of file xhci.c.

◆ EIO_RING_FULL

#define EIO_RING_FULL   __einfo_error ( EINFO_EIO_RING_FULL )

Definition at line 159 of file xhci.c.

◆ EINFO_EIO_RING_FULL

#define EINFO_EIO_RING_FULL
Value:
__einfo_uniqify ( EINFO_EIO, ( 21 - 0 ), \
"Event ring full" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 161 of file xhci.c.

◆ EIO_INCOMPATIBLE

#define EIO_INCOMPATIBLE   __einfo_error ( EINFO_EIO_INCOMPATIBLE )

Definition at line 164 of file xhci.c.

◆ EINFO_EIO_INCOMPATIBLE

#define EINFO_EIO_INCOMPATIBLE
Value:
__einfo_uniqify ( EINFO_EIO, ( 22 - 0 ), \
"Incompatible device" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 166 of file xhci.c.

◆ EIO_MISSED

#define EIO_MISSED   __einfo_error ( EINFO_EIO_MISSED )

Definition at line 169 of file xhci.c.

◆ EINFO_EIO_MISSED

#define EINFO_EIO_MISSED
Value:
__einfo_uniqify ( EINFO_EIO, ( 23 - 0 ), \
"Missed service error" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 171 of file xhci.c.

◆ EIO_CMD_STOPPED

#define EIO_CMD_STOPPED   __einfo_error ( EINFO_EIO_CMD_STOPPED )

Definition at line 174 of file xhci.c.

◆ EINFO_EIO_CMD_STOPPED

#define EINFO_EIO_CMD_STOPPED
Value:
__einfo_uniqify ( EINFO_EIO, ( 24 - 0 ), \
"Command ring stopped" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 176 of file xhci.c.

◆ EIO_CMD_ABORTED

#define EIO_CMD_ABORTED   __einfo_error ( EINFO_EIO_CMD_ABORTED )

Definition at line 179 of file xhci.c.

◆ EINFO_EIO_CMD_ABORTED

#define EINFO_EIO_CMD_ABORTED
Value:
__einfo_uniqify ( EINFO_EIO, ( 25 - 0 ), \
"Command aborted" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 181 of file xhci.c.

◆ EIO_STOP

#define EIO_STOP   __einfo_error ( EINFO_EIO_STOP )

Definition at line 184 of file xhci.c.

◆ EINFO_EIO_STOP

#define EINFO_EIO_STOP
Value:
__einfo_uniqify ( EINFO_EIO, ( 26 - 0 ), \
"Stopped" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 186 of file xhci.c.

◆ EIO_STOP_LEN

#define EIO_STOP_LEN   __einfo_error ( EINFO_EIO_STOP_LEN )

Definition at line 189 of file xhci.c.

◆ EINFO_EIO_STOP_LEN

#define EINFO_EIO_STOP_LEN
Value:
__einfo_uniqify ( EINFO_EIO, ( 27 - 0 ), \
"Stopped - length invalid" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 191 of file xhci.c.

◆ EIO_STOP_SHORT

#define EIO_STOP_SHORT   __einfo_error ( EINFO_EIO_STOP_SHORT )

Definition at line 194 of file xhci.c.

◆ EINFO_EIO_STOP_SHORT

#define EINFO_EIO_STOP_SHORT
Value:
__einfo_uniqify ( EINFO_EIO, ( 28 - 0 ), \
"Stopped - short packet" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 196 of file xhci.c.

◆ EIO_LATENCY

#define EIO_LATENCY   __einfo_error ( EINFO_EIO_LATENCY )

Definition at line 199 of file xhci.c.

◆ EINFO_EIO_LATENCY

#define EINFO_EIO_LATENCY
Value:
__einfo_uniqify ( EINFO_EIO, ( 29 - 0 ), \
"Maximum exit latency too large" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 201 of file xhci.c.

◆ EIO_ISOCH

#define EIO_ISOCH   __einfo_error ( EINFO_EIO_ISOCH )

Definition at line 204 of file xhci.c.

◆ EINFO_EIO_ISOCH

#define EINFO_EIO_ISOCH
Value:
__einfo_uniqify ( EINFO_EIO, ( 31 - 0 ), \
"Isochronous buffer overrun" )
#define EINFO_EIO
Definition: errno.h:435
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181

Definition at line 206 of file xhci.c.

◆ EPROTO_LOST

#define EPROTO_LOST   __einfo_error ( EINFO_EPROTO_LOST )

Definition at line 209 of file xhci.c.

◆ EINFO_EPROTO_LOST

#define EINFO_EPROTO_LOST
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 32 - 32 ), \
"Event lost" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181
#define EINFO_EPROTO
Definition: errno.h:626

Definition at line 211 of file xhci.c.

◆ EPROTO_UNDEFINED

#define EPROTO_UNDEFINED   __einfo_error ( EINFO_EPROTO_UNDEFINED )

Definition at line 214 of file xhci.c.

◆ EINFO_EPROTO_UNDEFINED

#define EINFO_EPROTO_UNDEFINED
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 33 - 32 ), \
"Undefined error" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181
#define EINFO_EPROTO
Definition: errno.h:626

Definition at line 216 of file xhci.c.

◆ EPROTO_STREAM_ID

#define EPROTO_STREAM_ID   __einfo_error ( EINFO_EPROTO_STREAM_ID )

Definition at line 219 of file xhci.c.

◆ EINFO_EPROTO_STREAM_ID

#define EINFO_EPROTO_STREAM_ID
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 34 - 32 ), \
"Invalid stream ID" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181
#define EINFO_EPROTO
Definition: errno.h:626

Definition at line 221 of file xhci.c.

◆ EPROTO_SECONDARY

#define EPROTO_SECONDARY   __einfo_error ( EINFO_EPROTO_SECONDARY )

Definition at line 224 of file xhci.c.

◆ EINFO_EPROTO_SECONDARY

#define EINFO_EPROTO_SECONDARY
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 35 - 32 ), \
"Secondary bandwidth error" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181
#define EINFO_EPROTO
Definition: errno.h:626

Definition at line 226 of file xhci.c.

◆ EPROTO_SPLIT

#define EPROTO_SPLIT   __einfo_error ( EINFO_EPROTO_SPLIT )

Definition at line 229 of file xhci.c.

◆ EINFO_EPROTO_SPLIT

#define EINFO_EPROTO_SPLIT
Value:
__einfo_uniqify ( EINFO_EPROTO, ( 36 - 32 ), \
"Split transaction error" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:181
#define EINFO_EPROTO
Definition: errno.h:626

Definition at line 231 of file xhci.c.

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

Definition at line 234 of file xhci.c.

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 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
unsigned int ports
Number of ports.
Definition: xhci.h:1093
void * run
Runtime registers.
Definition: xhci.h:1084
void * regs
Registers.
Definition: xhci.h:1069
#define XHCI_HCSPARAMS1_PORTS(params)
Number of ports.
Definition: xhci.h:49
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
struct device * dev
Underlying hardware device.
Definition: xhci.h:1071
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:79
#define XHCI_HCSPARAMS1_INTRS(params)
Number of interrupters.
Definition: xhci.h:46
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
Definition: dma.h:467
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1055
unsigned int slots
Number of device slots.
Definition: xhci.h:1089
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1112
#define XHCI_CAP_RTSOFF
Runtime register space offset.
Definition: xhci.h:74
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const char * name
Name.
Definition: xhci.h:1075
#define XHCI_HCCPARAMS1_XECP(params)
xHCI extended capabilities pointer
Definition: xhci.h:68
#define XHCI_HCCPARAMS1_ADDR64(params)
64-bit addressing capability
Definition: xhci.h:62
#define XHCI_CAP_CAPLENGTH
Capability register length.
Definition: xhci.h:34
unsigned int intrs
Number of interrupters.
Definition: xhci.h:1091
#define XHCI_HCSPARAMS1_SLOTS(params)
Number of device slots.
Definition: xhci.h:43
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1080
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1100
#define XHCI_OP_PAGESIZE
Page size register.
Definition: xhci.h:170
int addr64
64-bit addressing capability
Definition: xhci.h:1096
#define XHCI_PAGESIZE(pagesize)
Page size.
Definition: xhci.h:173
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1103
#define XHCI_CAP_DBOFF
Doorbell offset.
Definition: xhci.h:71
#define XHCI_HCCPARAMS1_CSZ_SHIFT(params)
Context size shift.
Definition: xhci.h:65
#define XHCI_CAP_HCSPARAMS1
Structural parameters 1.
Definition: xhci.h:40
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
#define XHCI_CAP_HCCPARAMS1
Capability parameters.
Definition: xhci.h:59
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1098
void * db
Doorbell registers.
Definition: xhci.h:1086
#define XHCI_HCSPARAMS2_SCRATCHPADS(params)
Number of page-sized scratchpad buffers.
Definition: xhci.h:55
#define XHCI_CAP_HCSPARAMS2
Structural parameters 2.
Definition: xhci.h:52
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 }
#define XHCI_XECP_NEXT(xecp)
Next xHCI extended capability pointer.
Definition: xhci.h:80
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define XHCI_XECP_ID(xecp)
xHCI extended capability ID
Definition: xhci.h:77
unsigned int uint32_t
Definition: stdint.h:12
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
void * cap
Capability registers.
Definition: xhci.h:1080
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1100
uint16_t offset
Offset to command line.
Definition: bzimage.h:8

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

static 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 }
static unsigned int unsigned int reg
Definition: myson.h:162
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
int addr64
64-bit addressing capability
Definition: xhci.h:1096
void writeq(uint64_t data, volatile uint64_t *io_addr)
Write 64-bit qword to memory-mapped device.

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

static 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:231
#define XHCI_MIN_ALIGN
Minimum alignment required for data structures.
Definition: xhci.h:25
#define fls(x)
Find last (i.e.
Definition: strings.h:167

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

static 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:28
#define XHCI_DCI(ctx)
Device context index.
Definition: xhci.h:957
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1098

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

static 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:960
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1098

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

static 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 XHCI_OP_USBSTS
USB status register.
Definition: xhci.h:164
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_PAGESIZE
Page size register.
Definition: xhci.h:170
#define XHCI_USBCMD_HCRST
Host controller reset.
Definition: xhci.h:161
#define XHCI_OP_CONFIG
Configure register.
Definition: xhci.h:194
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:158
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
#define XHCI_USBSTS_HCH
Host controller halted.
Definition: xhci.h:167
#define DBG_LOG
Definition: compiler.h:317
#define XHCI_OP_DNCTRL
Device notifcation control register.
Definition: xhci.h:176
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 }
#define XHCI_PORTSC_PSIV(portsc)
Port speed ID value.
Definition: xhci.h:234
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_OP_PORTHLPMC(port)
Port hardware link power management control register.
Definition: xhci.h:293
#define XHCI_OP_PORTLI(port)
Port link info register.
Definition: xhci.h:290
#define XHCI_PORTSC_PP
Port power.
Definition: xhci.h:228
#define XHCI_PORTSC_CCS
Current connect status.
Definition: xhci.h:207
u8 port
Port number.
Definition: CIB_PRM.h:31
const char * name
Name.
Definition: xhci.h:1075
#define XHCI_OP_PORTPMSC(port)
Port power management status and control register.
Definition: xhci.h:287
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
#define XHCI_PORTSC_PR
Port reset.
Definition: xhci.h:213
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:210
#define DBG_LOG
Definition: compiler.h:317
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define XHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
Definition: xhci.h:89
static unsigned int xhci_extended_capability(struct xhci_device *xhci, unsigned int id, unsigned int offset)
Find extended capability.
Definition: xhci.c:330
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: xhci.h:1075
#define XHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition: xhci.h:86
unsigned char uint8_t
Definition: stdint.h:10
void * cap
Capability registers.
Definition: xhci.h:1080
#define XHCI_XECP_ID_LEGACY
USB legacy support extended capability.
Definition: xhci.h:83
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: xhci.h:1106

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

static 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 }
#define XHCI_USBLEGSUP_MAX_WAIT_MS
Maximum time to wait for BIOS to release ownership.
Definition: xhci.h:984
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define XHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
Definition: xhci.h:89
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_USBLEGSUP_OS
USB legacy support OS owned semaphore.
Definition: xhci.h:92
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define XHCI_USBLEGSUP_CTLSTS
USB legacy support control/status.
Definition: xhci.h:98
const char * name
Name.
Definition: xhci.h:1075
#define XHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition: xhci.h:86
#define XHCI_USBLEGSUP_OS_OWNED
USB legacy support OS ownership flag.
Definition: xhci.h:95
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1080
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: xhci.h:1106

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

static 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 }
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_USBLEGSUP_OS
USB legacy support OS owned semaphore.
Definition: xhci.h:92
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1075
void * cap
Capability registers.
Definition: xhci.h:1080
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: xhci.h:1106
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()

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

static 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 );
687  count = XHCI_SUPPORTED_PORTS_COUNT ( 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 }
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
static unsigned int xhci_extended_capability(struct xhci_device *xhci, unsigned int id, unsigned int offset)
Find extended capability.
Definition: xhci.c:330
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define XHCI_XECP_ID_SUPPORTED
Supported protocol extended capability.
Definition: xhci.h:101
#define DBGC(...)
Definition: compiler.h:505
u8 port
Port number.
Definition: CIB_PRM.h:31
static unsigned int count
Number of entries.
Definition: dwmac.h:225
const char * name
Name.
Definition: xhci.h:1075
#define XHCI_SUPPORTED_PORTS_COUNT(ports)
Supported protocol port count.
Definition: xhci.h:119
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1080
#define XHCI_SUPPORTED_PORTS_OFFSET(ports)
Supported protocol port offset.
Definition: xhci.h:116
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
uint16_t supported
Bitmask of supported option values.
Definition: ena.h:12

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

static 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 {
710  uint32_t raw;
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;
720  uint32_t slot;
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';
736  slot = readl ( xhci->cap + supported + XHCI_SUPPORTED_SLOT );
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 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1042
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition: xhci.h:128
const char * name
Definition: ath9k_hw.c:1986
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition: xhci.h:125
uint32_t type
Operating system type.
Definition: ena.h:12
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:134
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
static const char * xhci_speed_name(uint32_t psi)
Transcribe port speed (for debugging)
Definition: xhci.c:649
u8 port
Port number.
Definition: CIB_PRM.h:31
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
Definition: xhci.h:122
#define cpu_to_le32(value)
Definition: byteswap.h:108
uint32_t revision
Entry point revision.
Definition: ib_mad.h:21
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:131
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1080
#define XHCI_SUPPORTED_REVISION
Supported protocol revision.
Definition: xhci.h:104
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 DBGC2(...)
Definition: compiler.h:522
__be32 raw[7]
Definition: CIB_PRM.h:28
uint16_t protocol
Protocol ID.
Definition: stp.h:19
#define DBG_EXTRA
Definition: compiler.h:319
#define XHCI_SUPPORTED_REVISION_VER(revision)
Supported protocol minor revision.
Definition: xhci.h:107
uint16_t supported
Bitmask of supported option values.
Definition: ena.h:12
unsigned int quirks
Quirks.
Definition: xhci.h:1077
#define XHCI_SUPPORTED_NAME
Supported protocol name.
Definition: xhci.h:110

References xhci_device::cap, cpu_to_le32, DBG_EXTRA, DBGC2, xhci_device::name, 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()

static 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;
770  uint32_t slot;
771 
772  /* Fail if there is no supported protocol */
773  if ( ! supported )
774  return -ENOTSUP;
775 
776  /* Get slot type */
777  slot = readl ( xhci->cap + supported + XHCI_SUPPORTED_SLOT );
779 
780  return type;
781 }
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition: xhci.h:128
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition: xhci.h:125
uint32_t type
Operating system type.
Definition: ena.h:12
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
u8 port
Port number.
Definition: CIB_PRM.h:31
uint8_t slot
Slot.
Definition: edd.h:17
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1080
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
uint16_t supported
Bitmask of supported option values.
Definition: ena.h:12

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

static 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 XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1042
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
Low speed (1.5Mbps)
Definition: usb.h:49
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:134
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
Full speed (12Mbps)
Definition: xhci.h:145
Super speed (5Gbps)
Definition: usb.h:55
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
u8 port
Port number.
Definition: CIB_PRM.h:31
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
Definition: usb.h:36
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
Definition: xhci.h:122
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:131
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1080
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
High speed (480Mbps)
Definition: usb.h:53
Super speed.
Definition: xhci.h:151
Low speed (1.5Mbps)
Definition: xhci.h:147
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)
Supported protocol PSI mantissa.
Definition: xhci.h:137
uint16_t supported
Bitmask of supported option values.
Definition: ena.h:12
High speed (480Mbps)
Definition: xhci.h:149
unsigned int quirks
Quirks.
Definition: xhci.h:1077
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
Definition: xhci.h:140
Full speed (12Mbps)
Definition: usb.h:51

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

static 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 XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1042
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
Low speed (1.5Mbps)
Definition: usb.h:49
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:134
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:515
Full speed (12Mbps)
Definition: xhci.h:145
Super speed (5Gbps)
Definition: usb.h:55
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
u8 port
Port number.
Definition: CIB_PRM.h:31
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
Definition: usb.h:36
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
Definition: xhci.h:122
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:131
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1080
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
High speed (480Mbps)
Definition: usb.h:53
Super speed.
Definition: xhci.h:151
Low speed (1.5Mbps)
Definition: xhci.h:147
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)
Supported protocol PSI mantissa.
Definition: xhci.h:137
uint16_t supported
Bitmask of supported option values.
Definition: ena.h:12
High speed (480Mbps)
Definition: xhci.h:149
unsigned int quirks
Quirks.
Definition: xhci.h:1077
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
Definition: xhci.h:140
Full speed (12Mbps)
Definition: usb.h:51

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

static 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:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1109
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:400
#define DBGC(...)
Definition: compiler.h:505
unsigned int slots
Number of device slots.
Definition: xhci.h:1089
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
#define ENOMEM
Not enough space.
Definition: errno.h:535
ring len
Length.
Definition: dwmac.h:231
#define XHCI_OP_DCBAAP
Device context base address array pointer.
Definition: xhci.h:191
const char * name
Name.
Definition: xhci.h:1075
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:366
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
unsigned long physaddr_t
Definition: stdint.h:20
#define DBGC2(...)
Definition: compiler.h:522
struct dma_mapping map
DMA mapping.
Definition: xhci.h:1049
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
void * op
Operational registers.
Definition: xhci.h:1082
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 }
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1109
unsigned int slots
Number of device slots.
Definition: xhci.h:1089
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
#define XHCI_OP_DCBAAP
Device context base address array pointer.
Definition: xhci.h:191
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:366
struct dma_mapping map
DMA mapping.
Definition: xhci.h:1049
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * buffer
Scratchpad buffer area.
Definition: xhci.h:1057
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1109
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:400
#define DBGC(...)
Definition: compiler.h:505
struct dma_mapping buffer_map
Buffer DMA mapping.
Definition: xhci.h:1059
#define cpu_to_le64(value)
Definition: byteswap.h:109
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1055
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1112
uint64_t * array
Scratchpad array.
Definition: xhci.h:1061
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
#define ENOMEM
Not enough space.
Definition: errno.h:535
struct dma_mapping array_map
Array DMA mapping.
Definition: xhci.h:1063
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
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.
const char * name
Name.
Definition: xhci.h:1075
uint32_t addr
Buffer address.
Definition: dwmac.h:20
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
void dma_ufree(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
Scratchpad buffer.
Definition: xhci.h:1053
unsigned long physaddr_t
Definition: stdint.h:20
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1103
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 }
void * buffer
Scratchpad buffer area.
Definition: xhci.h:1057
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1109
struct dma_mapping buffer_map
Buffer DMA mapping.
Definition: xhci.h:1059
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1055
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1112
uint64_t * array
Scratchpad array.
Definition: xhci.h:1061
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
struct dma_mapping array_map
Array DMA mapping.
Definition: xhci.h:1063
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
void dma_ufree(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
Scratchpad buffer.
Definition: xhci.h:1053
size_t pagesize
Page size.
Definition: xhci.h:1103
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

static 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 );
1094  config &= ~XHCI_CONFIG_MAX_SLOTS_EN_MASK;
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(slots)
Maximum device slots enabled.
Definition: xhci.h:197
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
unsigned int slots
Number of device slots.
Definition: xhci.h:1089
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_CONFIG
Configure register.
Definition: xhci.h:194
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:158
#define XHCI_CONFIG_MAX_SLOTS_EN_MASK
Maximum device slots enabled mask.
Definition: xhci.h:200
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 XHCI_OP_USBSTS
USB status register.
Definition: xhci.h:164
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
#define XHCI_STOP_MAX_WAIT_MS
Maximum time to wait for host controller to stop.
Definition: xhci.h:990
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:158
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
#define XHCI_USBSTS_HCH
Host controller halted.
Definition: xhci.h:167
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:670
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition: xhci.c:1110
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
Definition: xhci.h:996
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_USBCMD_HCRST
Host controller reset.
Definition: xhci.h:161
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:670
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1109
unsigned int slots
Number of device slots.
Definition: xhci.h:1089
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
int failed
Command mechanism has permanently failed.
Definition: xhci.h:1121
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1142
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
void * memset(void *dest, int character, size_t len) __nonnull

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

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 
)
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 }
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
Definition: xhci.h:332
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t dbval
Doorbell register value.
Definition: xhci.h:865
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:400
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
#define cpu_to_le64(value)
Definition: byteswap.h:109
void * db
Doorbell register.
Definition: xhci.h:863
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
#define ENOMEM
Not enough space.
Definition: errno.h:535
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:25
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
uint8_t slot
Slot.
Definition: edd.h:17
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
#define XHCI_DBVAL(target, stream)
Calculate doorbell register value.
Definition: xhci.h:889
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
struct xhci_trb_link * link
Link TRB (if applicable)
Definition: xhci.h:860
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
void * db
Doorbell registers.
Definition: xhci.h:1086
#define XHCI_TRB_LINK
A link transfer request block.
Definition: xhci.h:460
struct xhci_trb_link link
Link TRB.
Definition: xhci.h:697
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), count, cpu_to_le64, xhci_trb_ring::db, xhci_device::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()

static 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:844
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
static unsigned int count
Number of entries.
Definition: dwmac.h:225
unsigned int prod
Producer counter.
Definition: xhci.h:842
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 }
unsigned int cons
Consumer counter.
Definition: xhci.h:844
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
unsigned int prod
Producer counter.
Definition: xhci.h:842
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

static 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 }
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
Definition: xhci.h:332
wmb()
struct xhci_trb_common common
Common fields.
Definition: xhci.h:687
long index
Definition: bigint.h:65
uint8_t flags
Flags.
Definition: xhci.h:321
static unsigned int xhci_ring_remaining(struct xhci_trb_ring *ring)
Calculate space remaining in TRB ring.
Definition: xhci.h:913
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct xhci_trb_template template
Template.
Definition: xhci.h:685
#define cpu_to_le32(value)
Definition: byteswap.h:108
uint32_t status
Status.
Definition: xhci.h:309
A transfer request block.
Definition: xhci.h:683
unsigned int prod
Producer counter.
Definition: xhci.h:842
uint32_t control
Control.
Definition: xhci.h:311
#define ENOBUFS
No buffer space available.
Definition: errno.h:499
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:151
struct xhci_trb_link * link
Link TRB (if applicable)
Definition: xhci.h:860
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
#define XHCI_TRB_C
Transfer request block cycle bit flag.
Definition: xhci.h:329
uint64_t parameter
Parameter.
Definition: xhci.h:307

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

static 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 }
unsigned int cons
Consumer counter.
Definition: xhci.h:844
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition: xhci.h:898
long index
Definition: bigint.h:65
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint16_t cons
Consumer index.
Definition: ena.h:22
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

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

static 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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static unsigned int xhci_ring_remaining(struct xhci_trb_ring *ring)
Calculate space remaining in TRB ring.
Definition: xhci.h:913
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static unsigned int count
Number of entries.
Definition: dwmac.h:225
A transfer request block.
Definition: xhci.h:683
#define ENOBUFS
No buffer space available.
Definition: errno.h:499
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
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

Referenced by xhci_endpoint_message(), and xhci_endpoint_stream().

◆ xhci_dequeue_multi()

static 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
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

References NULL, and xhci_dequeue().

Referenced by xhci_endpoint_close(), and xhci_transfer().

◆ xhci_doorbell()

static 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 }
wmb()
uint32_t dbval
Doorbell register value.
Definition: xhci.h:865
void * db
Doorbell register.
Definition: xhci.h:863
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.

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

static 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 arbelprm_rc_send_wqe rc
Definition: arbel.h:14
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1115
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1290
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:179
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
const char * name
Name.
Definition: xhci.h:1075
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:366
unsigned long physaddr_t
Definition: stdint.h:20
#define DBGC2(...)
Definition: compiler.h:522
#define XHCI_CRCR_RCS
Command ring cycle state.
Definition: xhci.h:182
void * op
Operational registers.
Definition: xhci.h:1082
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
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
#define XHCI_CMD_TRBS_LOG2
Number of TRBs (excluding Link TRB) in the command ring.
Definition: xhci.h:966

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

static 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 }
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1115
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1290
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:179
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:366
#define XHCI_CRCR_CRR
Command ring running.
Definition: xhci.h:188
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 }
An event ring.
Definition: xhci.h:869
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * run
Runtime registers.
Definition: xhci.h:1084
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:400
#define cpu_to_le64(value)
Definition: byteswap.h:109
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
#define ENOMEM
Not enough space.
Definition: errno.h:535
ring len
Length.
Definition: dwmac.h:231
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#define cpu_to_le32(value)
Definition: byteswap.h:108
const char * name
Name.
Definition: xhci.h:1075
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:366
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
#define XHCI_RUN_ERSTBA(intr)
Event ring segment table base address register.
Definition: xhci.h:299
#define DBGC2(...)
Definition: compiler.h:522
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:972
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition: xhci.h:296
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1117
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:302
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 }
An event ring.
Definition: xhci.h:869
void * run
Runtime registers.
Definition: xhci.h:1084
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
ring len
Length.
Definition: dwmac.h:231
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:366
#define XHCI_RUN_ERSTBA(intr)
Event ring segment table base address register.
Definition: xhci.h:299
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:972
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition: xhci.h:296
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1117
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:302

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

static 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  int rc;
1602 
1603  /* Profile transfer events */
1604  profile_start ( &xhci_transfer_profiler );
1605 
1606  /* Identify slot */
1607  if ( ( trb->slot > xhci->slots ) ||
1608  ( ( slot = xhci->slot[trb->slot] ) == NULL ) ) {
1609  DBGC ( xhci, "XHCI %s transfer event invalid slot %d:\n",
1610  xhci->name, trb->slot );
1611  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1612  return;
1613  }
1614 
1615  /* Identify endpoint */
1616  if ( ( trb->endpoint >= XHCI_CTX_END ) ||
1617  ( ( endpoint = slot->endpoint[trb->endpoint] ) == NULL ) ) {
1618  DBGC ( xhci, "XHCI %s slot %d transfer event invalid epid "
1619  "%d:\n", xhci->name, slot->id, trb->endpoint );
1620  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1621  return;
1622  }
1623 
1624  /* Dequeue TRB(s) */
1625  iobuf = xhci_dequeue_multi ( &endpoint->ring );
1626  assert ( iobuf != NULL );
1627 
1628  /* Unmap I/O buffer */
1629  iob_unmap ( iobuf );
1630 
1631  /* Check for errors */
1632  if ( ! ( ( trb->code == XHCI_CMPLT_SUCCESS ) ||
1633  ( trb->code == XHCI_CMPLT_SHORT ) ) ) {
1634 
1635  /* Construct error */
1636  rc = -ECODE ( trb->code );
1637  DBGC ( xhci, "XHCI %s slot %d ctx %d failed (code %d): %s\n",
1638  xhci->name, slot->id, endpoint->ctx, trb->code,
1639  strerror ( rc ) );
1640  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1641 
1642  /* Sanity check */
1643  assert ( ( endpoint->context->state & XHCI_ENDPOINT_STATE_MASK )
1644  != XHCI_ENDPOINT_RUNNING );
1645 
1646  /* Report failure to USB core */
1647  usb_complete_err ( endpoint->ep, iobuf, rc );
1648  return;
1649  }
1650 
1651  /* Record actual transfer size */
1652  iob_unput ( iobuf, le16_to_cpu ( trb->residual ) );
1653 
1654  /* Sanity check (for successful completions only) */
1655  assert ( xhci_ring_consumed ( &endpoint->ring ) ==
1656  le64_to_cpu ( trb->transfer ) );
1657 
1658  /* Report completion to USB core */
1659  usb_complete ( endpoint->ep, iobuf );
1660  profile_stop ( &xhci_transfer_profiler );
1661 }
Short packet.
Definition: xhci.h:637
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
Definition: xhci.h:936
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
uint8_t state
Endpoint state.
Definition: xhci.h:771
#define DBGC(...)
Definition: compiler.h:505
uint8_t code
Completion code.
Definition: xhci.h:597
An xHCI endpoint.
Definition: xhci.h:1162
Success.
Definition: xhci.h:635
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:174
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:603
unsigned int slots
Number of device slots.
Definition: xhci.h:1089
#define ECODE(code)
Definition: xhci.c:234
uint8_t slot
Slot ID.
Definition: xhci.h:605
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int ctx
Context index.
Definition: xhci.h:1170
#define DBGC_HDA(...)
Definition: compiler.h:506
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:279
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:161
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1176
An xHCI device slot.
Definition: xhci.h:1134
#define iob_unput(iobuf, len)
Definition: iobuf.h:140
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
#define le16_to_cpu(value)
Definition: byteswap.h:113
Endpoint is running.
Definition: xhci.h:799
static struct io_buffer * xhci_dequeue_multi(struct xhci_trb_ring *ring)
Dequeue multiple transfer request blocks.
Definition: xhci.c:1420
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition: usb.h:1087
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
uint16_t residual
Residual transfer length.
Definition: xhci.h:593
uint64_t transfer
Transfer TRB pointer.
Definition: xhci.h:591
#define le64_to_cpu(value)
Definition: byteswap.h:115
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1124
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:587
#define XHCI_ENDPOINT_STATE_MASK
Endpoint state mask.
Definition: xhci.h:809
A persistent I/O buffer.
Definition: iobuf.h:38

References assert(), xhci_trb_transfer::code, xhci_endpoint::context, xhci_endpoint::ctx, DBGC, DBGC_HDA, ECODE, xhci_trb_transfer::endpoint, xhci_endpoint::ep, iob_unmap(), iob_unput, le16_to_cpu, le64_to_cpu, xhci_device::name, NULL, profile_start(), profile_stop(), rc, xhci_trb_transfer::residual, xhci_endpoint::ring, slot, xhci_trb_transfer::slot, xhci_device::slot, xhci_device::slots, xhci_endpoint_context::state, strerror(), xhci_trb_transfer::transfer, usb_complete(), usb_complete_err(), 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()

static 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 1669 of file xhci.c.

1670  {
1671  int rc;
1672 
1673  /* Ignore "command ring stopped" notifications */
1674  if ( trb->code == XHCI_CMPLT_CMD_STOPPED ) {
1675  DBGC2 ( xhci, "XHCI %s command ring stopped\n", xhci->name );
1676  return;
1677  }
1678 
1679  /* Ignore unexpected completions */
1680  if ( ! xhci->pending ) {
1681  rc = -ECODE ( trb->code );
1682  DBGC ( xhci, "XHCI %s unexpected completion (code %d): %s\n",
1683  xhci->name, trb->code, strerror ( rc ) );
1684  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1685  return;
1686  }
1687 
1688  /* Dequeue command TRB */
1689  xhci_dequeue ( &xhci->command );
1690 
1691  /* Sanity check */
1692  assert ( xhci_ring_consumed ( &xhci->command ) ==
1693  le64_to_cpu ( trb->command ) );
1694 
1695  /* Record completion */
1696  memcpy ( xhci->pending, trb, sizeof ( *xhci->pending ) );
1697  xhci->pending = NULL;
1698 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t command
Command TRB pointer.
Definition: xhci.h:614
static struct io_buffer * xhci_dequeue(struct xhci_trb_ring *ring)
Dequeue a transfer request block.
Definition: xhci.c:1359
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
Definition: xhci.h:936
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1115
union xhci_trb * pending
Current command (if any)
Definition: xhci.h:1119
#define DBGC(...)
Definition: compiler.h:505
#define ECODE(code)
Definition: xhci.c:234
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define DBGC_HDA(...)
Definition: compiler.h:506
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * name
Name.
Definition: xhci.h:1075
Command ring stopped.
Definition: xhci.h:639
#define DBGC2(...)
Definition: compiler.h:522
uint8_t code
Completion code.
Definition: xhci.h:618
#define le64_to_cpu(value)
Definition: byteswap.h:115
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References assert(), xhci_trb_complete::code, xhci_trb_complete::command, xhci_device::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()

static 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 1706 of file xhci.c.

1707  {
1708  struct usb_port *port = usb_port ( xhci->bus->hub, trb->port );
1709  uint32_t portsc;
1710 
1711  /* Sanity check */
1712  assert ( ( trb->port > 0 ) && ( trb->port <= xhci->ports ) );
1713 
1714  /* Record disconnections and clear changes */
1715  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1716  port->disconnected |= ( portsc & XHCI_PORTSC_CSC );
1717  portsc &= ( XHCI_PORTSC_PRESERVE | XHCI_PORTSC_CHANGE );
1718  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1719 
1720  /* Report port status change */
1721  usb_port_changed ( port );
1722 }
unsigned int ports
Number of ports.
Definition: xhci.h:1093
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
struct usb_bus * bus
USB bus.
Definition: xhci.h:1127
#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
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition: usb.c:1858
A USB port.
Definition: usb.h:813
u8 port
Port number.
Definition: CIB_PRM.h:31
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_PORTSC_CHANGE
Port status change mask.
Definition: xhci.h:270
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
unsigned int uint32_t
Definition: stdint.h:12
uint8_t port
Port ID.
Definition: xhci.h:647
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
struct usb_hub * hub
Root hub.
Definition: usb.h:995
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:960
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 1730 of file xhci.c.

1731  {
1732  int rc;
1733 
1734  /* Construct error */
1735  rc = -ECODE ( trb->code );
1736  DBGC ( xhci, "XHCI %s host controller event (code %d): %s\n",
1737  xhci->name, trb->code, strerror ( rc ) );
1738 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
uint8_t code
Completion code.
Definition: xhci.h:670
#define ECODE(code)
Definition: xhci.c:234
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * name
Name.
Definition: xhci.h:1075

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

Referenced by xhci_event_poll().

◆ xhci_event_poll()

static void xhci_event_poll ( struct xhci_device xhci)
static

Poll event ring.

Parameters
xhcixHCI device

Definition at line 1745 of file xhci.c.

1745  {
1746  struct xhci_event_ring *event = &xhci->event;
1747  union xhci_trb *trb;
1748  unsigned int shift = XHCI_EVENT_TRBS_LOG2;
1749  unsigned int count = ( 1 << shift );
1750  unsigned int mask = ( count - 1 );
1751  unsigned int consumed;
1752  unsigned int type;
1753 
1754  /* Do nothing if device has permanently failed */
1755  if ( xhci->failed )
1756  return;
1757 
1758  /* Poll for events */
1759  profile_start ( &xhci_event_profiler );
1760  for ( consumed = 0 ; ; consumed++ ) {
1761 
1762  /* Stop if we reach an empty TRB */
1763  rmb();
1764  trb = &event->trb[ event->cons & mask ];
1765  if ( ! ( ( trb->common.flags ^
1766  ( event->cons >> shift ) ) & XHCI_TRB_C ) )
1767  break;
1768 
1769  /* Consume this TRB */
1770  event->cons++;
1771 
1772  /* Handle TRB */
1773  type = ( trb->common.type & XHCI_TRB_TYPE_MASK );
1774  switch ( type ) {
1775 
1776  case XHCI_TRB_TRANSFER :
1777  xhci_transfer ( xhci, &trb->transfer );
1778  break;
1779 
1780  case XHCI_TRB_COMPLETE :
1781  xhci_complete ( xhci, &trb->complete );
1782  break;
1783 
1784  case XHCI_TRB_PORT_STATUS:
1785  xhci_port_status ( xhci, &trb->port );
1786  break;
1787 
1789  xhci_host_controller ( xhci, &trb->host );
1790  break;
1791 
1792  default:
1793  DBGC ( xhci, "XHCI %s unrecognised event %#x\n:",
1794  xhci->name, ( event->cons - 1 ) );
1795  DBGC_HDA ( xhci, virt_to_phys ( trb ),
1796  trb, sizeof ( *trb ) );
1797  break;
1798  }
1799  }
1800 
1801  /* Update dequeue pointer if applicable */
1802  if ( consumed ) {
1803  xhci_writeq ( xhci, dma ( &event->trb_map, trb ),
1804  xhci->run + XHCI_RUN_ERDP ( 0 ) );
1805  profile_stop ( &xhci_event_profiler );
1806  }
1807 }
An event ring.
Definition: xhci.h:869
struct xhci_trb_common common
Common fields.
Definition: xhci.h:687
void * run
Runtime registers.
Definition: xhci.h:1084
uint32_t type
Operating system type.
Definition: ena.h:12
struct xhci_trb_transfer transfer
Transfer event.
Definition: xhci.h:711
#define DBGC(...)
Definition: compiler.h:505
uint8_t type
Type.
Definition: xhci.h:323
uint8_t flags
Flags.
Definition: xhci.h:321
#define XHCI_TRB_PORT_STATUS
A port status change transfer request block.
Definition: xhci.h:661
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:174
static void xhci_transfer(struct xhci_device *xhci, struct xhci_trb_transfer *trb)
Handle transfer event.
Definition: xhci.c:1596
struct xhci_trb_host_controller host
Host controller event.
Definition: xhci.h:717
#define rmb()
Definition: io.h:545
#define XHCI_TRB_COMPLETE
A command completion event transfer request block.
Definition: xhci.h:630
#define DBGC_HDA(...)
Definition: compiler.h:506
#define XHCI_TRB_TRANSFER
A transfer event transfer request block.
Definition: xhci.h:609
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:161
#define XHCI_TRB_HOST_CONTROLLER
A port status change transfer request block.
Definition: xhci.h:680
int failed
Command mechanism has permanently failed.
Definition: xhci.h:1121
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1075
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:366
struct xhci_trb_complete complete
Command completion event.
Definition: xhci.h:713
#define XHCI_TRB_TYPE_MASK
Transfer request block type mask.
Definition: xhci.h:347
static void xhci_host_controller(struct xhci_device *xhci, struct xhci_trb_host_controller *trb)
Handle host controller event.
Definition: xhci.c:1730
static void xhci_complete(struct xhci_device *xhci, struct xhci_trb_complete *trb)
Handle command completion event.
Definition: xhci.c:1669
struct xhci_trb_port_status port
Port status changed event.
Definition: xhci.h:715
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:972
#define XHCI_TRB_C
Transfer request block cycle bit flag.
Definition: xhci.h:329
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1117
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:302
static void xhci_port_status(struct xhci_device *xhci, struct xhci_trb_port_status *trb)
Handle port status event.
Definition: xhci.c:1706

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

static void xhci_abort ( struct xhci_device xhci)
static

Abort command.

Parameters
xhcixHCI device

Definition at line 1814 of file xhci.c.

1814  {
1815  physaddr_t crp;
1816  uint32_t crcr;
1817 
1818  /* Abort the command */
1819  DBGC2 ( xhci, "XHCI %s aborting command\n", xhci->name );
1820  xhci_writeq ( xhci, XHCI_CRCR_CA, xhci->op + XHCI_OP_CRCR );
1821 
1822  /* Allow time for command to abort */
1824 
1825  /* Check for failure to abort */
1826  crcr = readl ( xhci->op + XHCI_OP_CRCR );
1827  if ( crcr & XHCI_CRCR_CRR ) {
1828 
1829  /* Device has failed to abort a command and is almost
1830  * certainly beyond repair. Reset device, abandoning
1831  * all state, and mark device as failed to avoid
1832  * delays on any future command attempts.
1833  */
1834  DBGC ( xhci, "XHCI %s failed to abort command\n", xhci->name );
1835  xhci_fail ( xhci );
1836  }
1837 
1838  /* Consume (and ignore) any final command status */
1839  xhci_event_poll ( xhci );
1840 
1841  /* Reset the command ring control register */
1842  xhci_ring_reset ( &xhci->command );
1843  crp = dma ( &xhci->command.map, xhci->command.trb );
1844  xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ), xhci->op + XHCI_OP_CRCR );
1845 }
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1115
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
#define XHCI_COMMAND_ABORT_DELAY_MS
Time to delay after aborting a command.
Definition: xhci.h:1010
static void xhci_ring_reset(struct xhci_trb_ring *ring)
Reset transfer request block ring.
Definition: xhci.c:1274
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:179
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
static int xhci_fail(struct xhci_device *xhci)
Mark xHCI device as permanently failed.
Definition: xhci.c:1180
const char * name
Name.
Definition: xhci.h:1075
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:366
unsigned int uint32_t
Definition: stdint.h:12
unsigned long physaddr_t
Definition: stdint.h:20
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
#define DBGC2(...)
Definition: compiler.h:522
static void xhci_event_poll(struct xhci_device *xhci)
Poll event ring.
Definition: xhci.c:1745
#define XHCI_CRCR_RCS
Command ring cycle state.
Definition: xhci.h:182
#define XHCI_CRCR_CA
Command abort.
Definition: xhci.h:185
#define XHCI_CRCR_CRR
Command ring running.
Definition: xhci.h:188
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
void * op
Operational registers.
Definition: xhci.h:1082

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

static 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 1857 of file xhci.c.

1857  {
1858  struct xhci_trb_complete *complete = &trb->complete;
1859  unsigned int i;
1860  int rc;
1861 
1862  /* Immediately fail all commands if command mechanism has failed */
1863  if ( xhci->failed ) {
1864  rc = -EPIPE;
1865  goto err_failed;
1866  }
1867 
1868  /* Sanity check */
1869  if ( xhci->pending ) {
1870  DBGC ( xhci, "XHCI %s command ring busy\n", xhci->name );
1871  rc = -EBUSY;
1872  goto err_pending;
1873  }
1874 
1875  /* Record the pending command */
1876  xhci->pending = trb;
1877 
1878  /* Enqueue the command */
1879  if ( ( rc = xhci_enqueue ( &xhci->command, NULL, trb ) ) != 0 )
1880  goto err_enqueue;
1881 
1882  /* Ring the command doorbell */
1883  xhci_doorbell ( &xhci->command );
1884 
1885  /* Wait for the command to complete */
1886  for ( i = 0 ; i < XHCI_COMMAND_MAX_WAIT_MS ; i++ ) {
1887 
1888  /* Poll event ring */
1889  xhci_event_poll ( xhci );
1890 
1891  /* Check for completion */
1892  if ( ! xhci->pending ) {
1893  if ( complete->code != XHCI_CMPLT_SUCCESS ) {
1894  rc = -ECODE ( complete->code );
1895  DBGC ( xhci, "XHCI %s command failed (code "
1896  "%d): %s\n", xhci->name, complete->code,
1897  strerror ( rc ) );
1898  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1899  return rc;
1900  }
1901  return 0;
1902  }
1903 
1904  /* Delay */
1905  mdelay ( 1 );
1906  }
1907 
1908  /* Timeout */
1909  DBGC ( xhci, "XHCI %s timed out waiting for completion\n", xhci->name );
1910  rc = -ETIMEDOUT;
1911 
1912  /* Abort command */
1913  xhci_abort ( xhci );
1914 
1915  err_enqueue:
1916  xhci->pending = NULL;
1917  err_pending:
1918  err_failed:
1919  return rc;
1920 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EBUSY
Device or resource busy.
Definition: errno.h:339
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1115
A command completion event transfer request block.
Definition: xhci.h:612
#define EPIPE
Broken pipe.
Definition: errno.h:620
union xhci_trb * pending
Current command (if any)
Definition: xhci.h:1119
#define DBGC(...)
Definition: compiler.h:505
Success.
Definition: xhci.h:635
#define ECODE(code)
Definition: xhci.c:234
#define XHCI_COMMAND_MAX_WAIT_MS
Maximum time to wait for a command to complete.
Definition: xhci.h:1004
#define DBGC_HDA(...)
Definition: compiler.h:506
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
int failed
Command mechanism has permanently failed.
Definition: xhci.h:1121
const char * name
Name.
Definition: xhci.h:1075
struct xhci_trb_complete complete
Command completion event.
Definition: xhci.h:713
static void xhci_abort(struct xhci_device *xhci)
Abort command.
Definition: xhci.c:1814
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
static void xhci_event_poll(struct xhci_device *xhci)
Poll event ring.
Definition: xhci.c:1745
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
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition: xhci.c:1437
uint8_t code
Completion code.
Definition: xhci.h:618
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:670

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

static 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 1928 of file xhci.c.

1928  {
1929  union xhci_trb trb;
1930  struct xhci_trb_common *nop = &trb.common;
1931  int rc;
1932 
1933  /* Construct command */
1934  memset ( nop, 0, sizeof ( *nop ) );
1935  nop->flags = XHCI_TRB_IOC;
1936  nop->type = XHCI_TRB_NOP_CMD;
1937 
1938  /* Issue command and wait for completion */
1939  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1940  DBGC ( xhci, "XHCI %s NOP failed: %s\n",
1941  xhci->name, strerror ( rc ) );
1942  return rc;
1943  }
1944 
1945  DBGC2 ( xhci, "XHCI %s NOP completed successfully\n", xhci->name );
1946  return 0;
1947 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A transfer request block.
Definition: xhci.h:315
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_TRB_NOP_CMD
A no-op command transfer request block.
Definition: xhci.h:586
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1075
uint8_t nop
Definition: tcp.h:14
#define DBGC2(...)
Definition: compiler.h:522
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1857
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
Definition: xhci.h:338
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 1956 of file xhci.c.

1957  {
1958  union xhci_trb trb;
1959  struct xhci_trb_enable_slot *enable = &trb.enable;
1960  struct xhci_trb_complete *enabled = &trb.complete;
1961  unsigned int slot;
1962  int rc;
1963 
1964  /* Construct command */
1965  memset ( enable, 0, sizeof ( *enable ) );
1966  enable->slot = type;
1967  enable->type = XHCI_TRB_ENABLE_SLOT;
1968 
1969  /* Issue command and wait for completion */
1970  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1971  DBGC ( xhci, "XHCI %s could not enable new slot: %s\n",
1972  xhci->name, strerror ( rc ) );
1973  return rc;
1974  }
1975 
1976  /* Extract slot number */
1977  slot = enabled->slot;
1978 
1979  DBGC2 ( xhci, "XHCI %s slot %d enabled\n", xhci->name, slot );
1980  return slot;
1981 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_ENABLE_SLOT
An enable slot transfer request block.
Definition: xhci.h:482
uint8_t slot
Slot type.
Definition: xhci.h:476
A command completion event transfer request block.
Definition: xhci.h:612
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC(...)
Definition: compiler.h:505
An enable slot transfer request block.
Definition: xhci.h:466
uint16_t enabled
Single-entry bitmask of the enabled option value.
Definition: ena.h:14
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
#define DBGC2(...)
Definition: compiler.h:522
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1857
uint8_t type
Type.
Definition: xhci.h:474
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 1990 of file xhci.c.

1991  {
1992  union xhci_trb trb;
1993  struct xhci_trb_disable_slot *disable = &trb.disable;
1994  int rc;
1995 
1996  /* Construct command */
1997  memset ( disable, 0, sizeof ( *disable ) );
1998  disable->type = XHCI_TRB_DISABLE_SLOT;
1999  disable->slot = slot;
2000 
2001  /* Issue command and wait for completion */
2002  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2003  DBGC ( xhci, "XHCI %s could not disable slot %d: %s\n",
2004  xhci->name, slot, strerror ( rc ) );
2005  return rc;
2006  }
2007 
2008  DBGC2 ( xhci, "XHCI %s slot %d disabled\n", xhci->name, slot );
2009  return 0;
2010 }
A disable slot transfer request block.
Definition: xhci.h:485
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_DISABLE_SLOT
A disable slot transfer request block.
Definition: xhci.h:501
#define DBGC(...)
Definition: compiler.h:505
uint8_t slot
Slot ID.
Definition: xhci.h:497
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
uint8_t type
Type.
Definition: xhci.h:493
#define DBGC2(...)
Definition: compiler.h:522
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1857
void * memset(void *dest, int character, size_t len) __nonnull

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

static int xhci_context ( struct xhci_device xhci,
struct xhci_slot slot,
struct xhci_endpoint endpoint,
unsigned int  type,
void(*)(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input populate 
)
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 2022 of file xhci.c.

2027  {
2028  union xhci_trb trb;
2029  struct xhci_trb_context *context = &trb.context;
2030  struct dma_mapping map;
2031  size_t len;
2032  void *input;
2033  int rc;
2034 
2035  /* Allocate an input context */
2036  memset ( &map, 0, sizeof ( map ) );
2038  input = dma_alloc ( xhci->dma, &map, len, xhci_align ( len ) );
2039  if ( ! input ) {
2040  rc = -ENOMEM;
2041  goto err_alloc;
2042  }
2043  memset ( input, 0, len );
2044 
2045  /* Populate input context */
2046  populate ( xhci, slot, endpoint, input );
2047 
2048  /* Construct command */
2049  memset ( context, 0, sizeof ( *context ) );
2050  context->type = type;
2051  context->input = cpu_to_le64 ( dma ( &map, input ) );
2052  context->slot = slot->id;
2053 
2054  /* Issue command and wait for completion */
2055  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 )
2056  goto err_command;
2057 
2058  err_command:
2059  dma_free ( &map, input, len );
2060  err_alloc:
2061  return rc;
2062 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:400
uint32_t type
Operating system type.
Definition: ena.h:12
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:109
uint64_t input
Input context.
Definition: xhci.h:506
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
#define ENOMEM
Not enough space.
Definition: errno.h:535
ring len
Length.
Definition: dwmac.h:231
A context transfer request block.
Definition: xhci.h:504
A transfer request block.
Definition: xhci.h:683
uint8_t slot
Slot.
Definition: edd.h:17
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
static __always_inline int struct dma_mapping * map
Definition: dma.h:184
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:431
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
A DMA mapping.
Definition: dma.h:33
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1857
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
uint8_t type
Type.
Definition: xhci.h:512
uint8_t slot
Slot ID.
Definition: xhci.h:516
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 2072 of file xhci.c.

2075  {
2076  struct xhci_trb_ring *ring = &endpoint->ring;
2077  struct xhci_control_context *control_ctx;
2078  struct xhci_slot_context *slot_ctx;
2079  struct xhci_endpoint_context *ep_ctx;
2080 
2081  /* Sanity checks */
2082  assert ( endpoint->ctx == XHCI_CTX_EP0 );
2083 
2084  /* Populate control context */
2085  control_ctx = input;
2086  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2087  ( 1 << XHCI_CTX_EP0 ) );
2088 
2089  /* Populate slot context */
2090  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2091  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( 1, 0, slot->psiv,
2092  slot->route ) );
2093  slot_ctx->port = slot->port;
2094  slot_ctx->tt_id = slot->tt_id;
2095  slot_ctx->tt_port = slot->tt_port;
2096 
2097  /* Populate control endpoint context */
2098  ep_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_EP0 ) );
2099  ep_ctx->type = XHCI_EP_TYPE_CONTROL;
2100  ep_ctx->burst = endpoint->ep->burst;
2101  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2102  ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
2103  XHCI_EP_DCS );
2104  ep_ctx->trb_len = cpu_to_le16 ( XHCI_EP0_TRB_LEN );
2105 }
An endpoint context.
Definition: xhci.h:769
uint8_t burst
Maximum burst size.
Definition: xhci.h:781
uint8_t type
Endpoint type.
Definition: xhci.h:779
An input control context.
Definition: xhci.h:721
uint16_t trb_len
Average TRB length.
Definition: xhci.h:787
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
Definition: xhci.h:815
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:109
uint32_t add
Add context flags.
Definition: xhci.h:725
uint64_t dequeue
Transfer ring dequeue pointer.
Definition: xhci.h:785
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:824
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int ctx
Context index.
Definition: xhci.h:1170
uint8_t port
Root hub port number.
Definition: xhci.h:745
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:765
uint16_t mtu
Maximum packet size.
Definition: xhci.h:783
unsigned int burst
Maximum burst size.
Definition: usb.h:414
uint32_t info
Device info.
Definition: xhci.h:741
#define cpu_to_le32(value)
Definition: byteswap.h:108
uint8_t slot
Slot.
Definition: edd.h:17
#define XHCI_EP0_TRB_LEN
Control endpoint average TRB length.
Definition: xhci.h:827
size_t mtu
Maximum transfer size.
Definition: usb.h:412
uint8_t tt_id
TT hub slot ID.
Definition: xhci.h:749
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
uint8_t tt_port
TT port number.
Definition: xhci.h:751
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:431
#define cpu_to_le16(value)
Definition: byteswap.h:107
A transfer request block command/transfer ring.
Definition: xhci.h:840
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:951
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

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

static 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 2114 of file xhci.c.

2115  {
2116  struct usb_device *usb = slot->usb;
2117  struct xhci_slot_context *slot_ctx;
2118  int rc;
2119 
2120  /* Assign device address */
2121  if ( ( rc = xhci_context ( xhci, slot, slot->endpoint[XHCI_CTX_EP0],
2123  xhci_address_device_input ) ) != 0 ) {
2124  DBGC ( xhci, "XHCI %s slot %d could not assign address: %s\n",
2125  xhci->name, slot->id, strerror ( rc ) );
2126  return rc;
2127  }
2128 
2129  /* Get assigned address */
2130  slot_ctx = ( slot->context +
2132  usb->address = slot_ctx->address;
2133  DBGC2 ( xhci, "XHCI %s slot %d assigned address %d to %s\n",
2134  xhci->name, slot->id, usb->address, usb->name );
2135 
2136  return 0;
2137 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
Definition: xhci.c:419
#define DBGC(...)
Definition: compiler.h:505
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:2022
unsigned int address
Device address, if assigned.
Definition: usb.h:733
uint8_t address
USB address.
Definition: xhci.h:755
#define XHCI_TRB_ADDRESS_DEVICE
An address device transfer request block.
Definition: xhci.h:520
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
#define DBGC2(...)
Definition: compiler.h:522
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:2072
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:951
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

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

static 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 2147 of file xhci.c.

2150  {
2151  struct xhci_trb_ring *ring = &endpoint->ring;
2152  struct xhci_control_context *control_ctx;
2153  struct xhci_slot_context *slot_ctx;
2154  struct xhci_endpoint_context *ep_ctx;
2155 
2156  /* Populate control context */
2157  control_ctx = input;
2158  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2159  ( 1 << endpoint->ctx ) );
2160 
2161  /* Populate slot context */
2162  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2163  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2164  ( slot->ports ? 1 : 0 ),
2165  slot->psiv, 0 ) );
2166  slot_ctx->ports = slot->ports;
2167 
2168  /* Populate endpoint context */
2169  ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2170  ep_ctx->interval = endpoint->interval;
2171  ep_ctx->type = endpoint->type;
2172  ep_ctx->burst = endpoint->ep->burst;
2173  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2174  ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
2175  XHCI_EP_DCS );
2176  ep_ctx->trb_len = cpu_to_le16 ( endpoint->ep->mtu ); /* best guess */
2177 }
An endpoint context.
Definition: xhci.h:769
uint8_t burst
Maximum burst size.
Definition: xhci.h:781
uint8_t type
Endpoint type.
Definition: xhci.h:779
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
An input control context.
Definition: xhci.h:721
uint16_t trb_len
Average TRB length.
Definition: xhci.h:787
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:109
uint32_t add
Add context flags.
Definition: xhci.h:725
uint64_t dequeue
Transfer ring dequeue pointer.
Definition: xhci.h:785
uint8_t ports
Number of downstream ports.
Definition: xhci.h:747
unsigned int type
Endpoint type.
Definition: xhci.h:1172
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:824
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
unsigned int ctx
Context index.
Definition: xhci.h:1170
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:765
uint16_t mtu
Maximum packet size.
Definition: xhci.h:783
unsigned int burst
Maximum burst size.
Definition: usb.h:414
uint32_t info
Device info.
Definition: xhci.h:741
#define cpu_to_le32(value)
Definition: byteswap.h:108
uint8_t slot
Slot.
Definition: edd.h:17
size_t mtu
Maximum transfer size.
Definition: usb.h:412
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
uint8_t interval
Polling interval.
Definition: xhci.h:775
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:431
#define cpu_to_le16(value)
Definition: byteswap.h:107
A transfer request block command/transfer ring.
Definition: xhci.h:840
unsigned int interval
Endpoint interval.
Definition: xhci.h:1174
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

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_context::interval, xhci_endpoint::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_context::type, xhci_endpoint::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()

static 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 2187 of file xhci.c.

2189  {
2190  int rc;
2191 
2192  /* Configure endpoint */
2193  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2195  xhci_configure_endpoint_input ) ) != 0 ) {
2196  DBGC ( xhci, "XHCI %s slot %d ctx %d could not configure: %s\n",
2197  xhci->name, slot->id, endpoint->ctx, strerror ( rc ) );
2198  return rc;
2199  }
2200 
2201  DBGC2 ( xhci, "XHCI %s slot %d ctx %d configured\n",
2202  xhci->name, slot->id, endpoint->ctx );
2203  return 0;
2204 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
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:2022
unsigned int ctx
Context index.
Definition: xhci.h:1170
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
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:2147
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
Definition: xhci.h:523
#define DBGC2(...)
Definition: compiler.h:522

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

static 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 2215 of file xhci.c.

2218  {
2219  struct xhci_control_context *control_ctx;
2220  struct xhci_slot_context *slot_ctx;
2221 
2222  /* Populate control context */
2223  control_ctx = input;
2224  control_ctx->add = cpu_to_le32 ( 1 << XHCI_CTX_SLOT );
2225  control_ctx->drop = cpu_to_le32 ( 1 << endpoint->ctx );
2226 
2227  /* Populate slot context */
2228  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2229  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2230  0, 0, 0 ) );
2231 }
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
An input control context.
Definition: xhci.h:721
Definition: bnxt_hsi.h:68
uint32_t add
Add context flags.
Definition: xhci.h:725
uint32_t drop
Drop context flags.
Definition: xhci.h:723
unsigned int ctx
Context index.
Definition: xhci.h:1170
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:765
uint32_t info
Device info.
Definition: xhci.h:741
#define cpu_to_le32(value)
Definition: byteswap.h:108
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:431
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

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

Referenced by xhci_deconfigure_endpoint().

◆ xhci_deconfigure_endpoint()

static 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 2241 of file xhci.c.

2243  {
2244  int rc;
2245 
2246  /* Deconfigure endpoint */
2247  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2249  xhci_deconfigure_endpoint_input ) ) != 0 ) {
2250  DBGC ( xhci, "XHCI %s slot %d ctx %d could not deconfigure: "
2251  "%s\n", xhci->name, slot->id, endpoint->ctx,
2252  strerror ( rc ) );
2253  return rc;
2254  }
2255 
2256  DBGC2 ( xhci, "XHCI %s slot %d ctx %d deconfigured\n",
2257  xhci->name, slot->id, endpoint->ctx );
2258  return 0;
2259 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
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:2022
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:2215
unsigned int ctx
Context index.
Definition: xhci.h:1170
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
Definition: xhci.h:523
#define DBGC2(...)
Definition: compiler.h:522

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

static 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 2269 of file xhci.c.

2272  {
2273  struct xhci_control_context *control_ctx;
2274  struct xhci_slot_context *slot_ctx;
2275  struct xhci_endpoint_context *ep_ctx;
2276 
2277  /* Populate control context */
2278  control_ctx = input;
2279  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2280  ( 1 << endpoint->ctx ) );
2281 
2282  /* Populate slot context */
2283  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2284  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2285  0, 0, 0 ) );
2286 
2287  /* Populate endpoint context */
2288  ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2289  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2290 }
An endpoint context.
Definition: xhci.h:769
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
An input control context.
Definition: xhci.h:721
Definition: bnxt_hsi.h:68
uint32_t add
Add context flags.
Definition: xhci.h:725
unsigned int ctx
Context index.
Definition: xhci.h:1170
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:765
uint16_t mtu
Maximum packet size.
Definition: xhci.h:783
uint32_t info
Device info.
Definition: xhci.h:741
#define cpu_to_le32(value)
Definition: byteswap.h:108
size_t mtu
Maximum transfer size.
Definition: usb.h:412
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:431
#define cpu_to_le16(value)
Definition: byteswap.h:107
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

References 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, XHCI_CTX_END, XHCI_CTX_SLOT, xhci_input_context_offset(), and XHCI_SLOT_INFO.

Referenced by xhci_evaluate_context().

◆ xhci_evaluate_context()

static 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 2300 of file xhci.c.

2302  {
2303  int rc;
2304 
2305  /* Configure endpoint */
2306  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2308  xhci_evaluate_context_input ) ) != 0 ) {
2309  DBGC ( xhci, "XHCI %s slot %d ctx %d could not (re-)evaluate: "
2310  "%s\n", xhci->name, slot->id, endpoint->ctx,
2311  strerror ( rc ) );
2312  return rc;
2313  }
2314 
2315  DBGC2 ( xhci, "XHCI %s slot %d ctx %d (re-)evaluated\n",
2316  xhci->name, slot->id, endpoint->ctx );
2317  return 0;
2318 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
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:2269
#define DBGC(...)
Definition: compiler.h:505
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:2022
unsigned int ctx
Context index.
Definition: xhci.h:1170
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
#define DBGC2(...)
Definition: compiler.h:522
#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()

static 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 2328 of file xhci.c.

2330  {
2331  union xhci_trb trb;
2332  struct xhci_trb_reset_endpoint *reset = &trb.reset;
2333  int rc;
2334 
2335  /* Construct command */
2336  memset ( reset, 0, sizeof ( *reset ) );
2337  reset->slot = slot->id;
2338  reset->endpoint = endpoint->ctx;
2339  reset->type = XHCI_TRB_RESET_ENDPOINT;
2340 
2341  /* Issue command and wait for completion */
2342  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2343  DBGC ( xhci, "XHCI %s slot %d ctx %d could not reset endpoint "
2344  "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2345  endpoint->context->state, strerror ( rc ) );
2346  return rc;
2347  }
2348 
2349  return 0;
2350 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_TRB_RESET_ENDPOINT
A reset endpoint transfer request block.
Definition: xhci.h:545
uint8_t type
Type.
Definition: xhci.h:537
uint8_t slot
Slot ID.
Definition: xhci.h:541
A reset endpoint transfer request block.
Definition: xhci.h:529
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:539
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1857
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 2360 of file xhci.c.

2362  {
2363  union xhci_trb trb;
2364  struct xhci_trb_stop_endpoint *stop = &trb.stop;
2365  int rc;
2366 
2367  /* Construct command */
2368  memset ( stop, 0, sizeof ( *stop ) );
2369  stop->slot = slot->id;
2370  stop->endpoint = endpoint->ctx;
2371  stop->type = XHCI_TRB_STOP_ENDPOINT;
2372 
2373  /* Issue command and wait for completion */
2374  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2375  DBGC ( xhci, "XHCI %s slot %d ctx %d could not stop endpoint "
2376  "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2377  endpoint->context->state, strerror ( rc ) );
2378  return rc;
2379  }
2380 
2381  return 0;
2382 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:558
uint8_t slot
Slot ID.
Definition: xhci.h:560
#define XHCI_TRB_STOP_ENDPOINT
A stop endpoint transfer request block.
Definition: xhci.h:564
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
uint8_t type
Type.
Definition: xhci.h:556
A stop endpoint transfer request block.
Definition: xhci.h:548
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1857
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 2393 of file xhci.c.

2395  {
2396  union xhci_trb trb;
2397  struct xhci_trb_set_tr_dequeue_pointer *dequeue = &trb.dequeue;
2398  struct xhci_trb_ring *ring = &endpoint->ring;
2399  unsigned int cons;
2400  unsigned int mask;
2401  unsigned int index;
2402  unsigned int dcs;
2403  physaddr_t addr;
2404  int rc;
2405 
2406  /* Construct command */
2407  memset ( dequeue, 0, sizeof ( *dequeue ) );
2408  cons = ring->cons;
2409  mask = ring->mask;
2410  dcs = ( ( ~( cons >> ring->shift ) ) & XHCI_EP_DCS );
2411  index = ( cons & mask );
2412  addr = dma ( &ring->map, &ring->trb[index] );
2413  dequeue->dequeue = cpu_to_le64 ( addr | dcs );
2414  dequeue->slot = slot->id;
2415  dequeue->endpoint = endpoint->ctx;
2417 
2418  /* Issue command and wait for completion */
2419  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2420  DBGC ( xhci, "XHCI %s slot %d ctx %d could not set TR dequeue "
2421  "pointer in state %d: %s\n", xhci->name, slot->id,
2422  endpoint->ctx, endpoint->context->state, strerror ( rc));
2423  return rc;
2424  }
2425 
2426  return 0;
2427 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_SET_TR_DEQUEUE_POINTER
A set transfer ring dequeue pointer transfer request block.
Definition: xhci.h:583
unsigned int cons
Consumer counter.
Definition: xhci.h:844
A set transfer ring dequeue pointer transfer request block.
Definition: xhci.h:567
uint8_t state
Endpoint state.
Definition: xhci.h:771
#define DBGC(...)
Definition: compiler.h:505
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
long index
Definition: bigint.h:65
#define cpu_to_le64(value)
Definition: byteswap.h:109
uint64_t dequeue
Dequeue pointer.
Definition: xhci.h:569
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:824
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
unsigned int ctx
Context index.
Definition: xhci.h:1170
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1176
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
uint16_t cons
Consumer index.
Definition: ena.h:22
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot ID.
Definition: xhci.h:579
uint32_t addr
Buffer address.
Definition: dwmac.h:20
uint8_t slot
Slot.
Definition: edd.h:17
unsigned long physaddr_t
Definition: stdint.h:20
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
A transfer request block command/transfer ring.
Definition: xhci.h:840
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1857
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:577
void * memset(void *dest, int character, size_t len) __nonnull

References addr, cons, xhci_trb_ring::cons, xhci_endpoint::context, cpu_to_le64, xhci_endpoint::ctx, DBGC, xhci_trb_set_tr_dequeue_pointer::dequeue, xhci_trb::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()

static int xhci_endpoint_open ( struct usb_endpoint ep)
static

Open endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2442 of file xhci.c.

2442  {
2443  struct usb_device *usb = ep->usb;
2444  struct xhci_slot *slot = usb_get_hostdata ( usb );
2445  struct xhci_device *xhci = slot->xhci;
2446  struct xhci_endpoint *endpoint;
2447  unsigned int ctx;
2448  unsigned int type;
2449  unsigned int interval;
2450  int rc;
2451 
2452  /* Calculate context index */
2453  ctx = XHCI_CTX ( ep->address );
2454  assert ( slot->endpoint[ctx] == NULL );
2455 
2456  /* Calculate endpoint type */
2460  if ( ep->address & USB_DIR_IN )
2461  type |= XHCI_EP_TYPE_IN;
2462 
2463  /* Calculate interval */
2464  if ( type & XHCI_EP_TYPE_PERIODIC ) {
2465  interval = ( fls ( ep->interval ) - 1 );
2466  } else {
2467  interval = ep->interval;
2468  }
2469 
2470  /* Allocate and initialise structure */
2471  endpoint = zalloc ( sizeof ( *endpoint ) );
2472  if ( ! endpoint ) {
2473  rc = -ENOMEM;
2474  goto err_alloc;
2475  }
2476  usb_endpoint_set_hostdata ( ep, endpoint );
2477  slot->endpoint[ctx] = endpoint;
2478  endpoint->xhci = xhci;
2479  endpoint->slot = slot;
2480  endpoint->ep = ep;
2481  endpoint->ctx = ctx;
2482  endpoint->type = type;
2483  endpoint->interval = interval;
2484  endpoint->context = ( ( ( void * ) slot->context ) +
2486 
2487  /* Allocate transfer ring */
2488  if ( ( rc = xhci_ring_alloc ( xhci, &endpoint->ring,
2490  slot->id, ctx, 0 ) ) != 0 )
2491  goto err_ring_alloc;
2492 
2493  /* Configure endpoint, if applicable */
2494  if ( ( ctx != XHCI_CTX_EP0 ) &&
2495  ( ( rc = xhci_configure_endpoint ( xhci, slot, endpoint ) ) != 0 ))
2496  goto err_configure_endpoint;
2497 
2498  DBGC2 ( xhci, "XHCI %s slot %d ctx %d ring [%08lx,%08lx)\n",
2499  xhci->name, slot->id, ctx, virt_to_phys ( endpoint->ring.trb ),
2500  ( virt_to_phys ( endpoint->ring.trb ) + endpoint->ring.len ) );
2501  return 0;
2502 
2503  xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2504  err_configure_endpoint:
2505  xhci_ring_free ( &endpoint->ring );
2506  err_ring_alloc:
2507  slot->endpoint[ctx] = NULL;
2508  free ( endpoint );
2509  err_alloc:
2510  return rc;
2511 }
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
Definition: usb.h:576
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
Definition: xhci.c:419
An xHCI device.
Definition: xhci.h:1067
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:281
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
uint32_t type
Operating system type.
Definition: ena.h:12
#define XHCI_EP_TYPE(type)
Endpoint type.
Definition: xhci.h:812
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
Definition: xhci.h:815
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1290
static int xhci_configure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Configure endpoint.
Definition: xhci.c:2187
#define XHCI_TRANSFER_TRBS_LOG2
Number of TRBs in a transfer ring.
Definition: xhci.h:978
An xHCI endpoint.
Definition: xhci.h:1162
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
unsigned int type
Endpoint type.
Definition: xhci.h:1172
#define XHCI_EP_TYPE_IN
Input endpoint type.
Definition: xhci.h:818
#define ENOMEM
Not enough space.
Definition: errno.h:535
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_EP_TYPE_PERIODIC
Periodic endpoint type.
Definition: xhci.h:821
unsigned int ctx
Context index.
Definition: xhci.h:1170
struct usb_device * usb
USB device.
Definition: xhci.h:1138
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:98
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1166
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1176
A USB device.
Definition: usb.h:723
static int xhci_deconfigure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Deconfigure endpoint.
Definition: xhci.c:2241
An xHCI device slot.
Definition: xhci.h:1134
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:795
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
#define XHCI_CTX(address)
Calculate context index from USB endpoint address.
Definition: xhci.h:946
#define DBGC2(...)
Definition: compiler.h:522
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
unsigned int interval
Interval (in microframes)
Definition: usb.h:416
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
Definition: usb.h:287
struct usb_device * usb
USB device.
Definition: usb.h:406
unsigned int interval
Endpoint interval.
Definition: xhci.h:1174
#define fls(x)
Find last (i.e.
Definition: strings.h:167
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1164
unsigned int attributes
Attributes.
Definition: usb.h:410
unsigned int address
Endpoint address.
Definition: usb.h:408
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:951
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

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

static void xhci_endpoint_close ( struct usb_endpoint ep)
static

Close endpoint.

Parameters
epUSB endpoint

Definition at line 2518 of file xhci.c.

2518  {
2519  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2520  struct xhci_slot *slot = endpoint->slot;
2521  struct xhci_device *xhci = slot->xhci;
2522  struct io_buffer *iobuf;
2523  unsigned int ctx = endpoint->ctx;
2524 
2525  /* Deconfigure endpoint, if applicable */
2526  if ( ctx != XHCI_CTX_EP0 )
2527  xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2528 
2529  /* Cancel any incomplete transfers */
2530  while ( xhci_ring_fill ( &endpoint->ring ) ) {
2531  iobuf = xhci_dequeue_multi ( &endpoint->ring );
2532  iob_unmap ( iobuf );
2533  usb_complete_err ( ep, iobuf, -ECANCELED );
2534  }
2535 
2536  /* Free endpoint */
2537  xhci_ring_free ( &endpoint->ring );
2538  slot->endpoint[ctx] = NULL;
2539  free ( endpoint );
2540 }
An xHCI device.
Definition: xhci.h:1067
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition: xhci.h:898
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition: xhci.h:1158
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1290
An xHCI endpoint.
Definition: xhci.h:1162
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
#define ECANCELED
Operation canceled.
Definition: errno.h:344
unsigned int ctx
Context index.
Definition: xhci.h:1170
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:279
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1166
static int xhci_deconfigure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Deconfigure endpoint.
Definition: xhci.c:2241
An xHCI device slot.
Definition: xhci.h:1134
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
uint8_t slot
Slot.
Definition: edd.h:17
static struct io_buffer * xhci_dequeue_multi(struct xhci_trb_ring *ring)
Dequeue multiple transfer request blocks.
Definition: xhci.c:1420
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:951
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:587
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:587
A persistent I/O buffer.
Definition: iobuf.h:38

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

static int xhci_endpoint_reset ( struct usb_endpoint ep)
static

Reset endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2548 of file xhci.c.

2548  {
2549  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2550  struct xhci_slot *slot = endpoint->slot;
2551  struct xhci_device *xhci = slot->xhci;
2552  int rc;
2553 
2554  /* Reset endpoint context */
2555  if ( ( rc = xhci_reset_endpoint ( xhci, slot, endpoint ) ) != 0 )
2556  return rc;
2557 
2558  /* Set transfer ring dequeue pointer */
2559  if ( ( rc = xhci_set_tr_dequeue_pointer ( xhci, slot, endpoint ) ) != 0)
2560  return rc;
2561 
2562  /* Ring doorbell to resume processing */
2563  xhci_doorbell ( &endpoint->ring );
2564 
2565  DBGC ( xhci, "XHCI %s slot %d ctx %d reset\n",
2566  xhci->name, slot->id, endpoint->ctx );
2567  return 0;
2568 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An xHCI device.
Definition: xhci.h:1067
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition: xhci.h:1158
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:2393
#define DBGC(...)
Definition: compiler.h:505
An xHCI endpoint.
Definition: xhci.h:1162
unsigned int ctx
Context index.
Definition: xhci.h:1170
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1166
An xHCI device slot.
Definition: xhci.h:1134
const char * name
Name.
Definition: xhci.h:1075
uint8_t slot
Slot.
Definition: edd.h:17
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition: xhci.c:1437
static int xhci_reset_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Reset endpoint.
Definition: xhci.c:2328
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:587

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

static int xhci_endpoint_mtu ( struct usb_endpoint ep)
static

Update MTU.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2576 of file xhci.c.

2576  {
2577  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2578  struct xhci_slot *slot = endpoint->slot;
2579  struct xhci_device *xhci = slot->xhci;
2580  int rc;
2581 
2582  /* Evalulate context */
2583  if ( ( rc = xhci_evaluate_context ( xhci, slot, endpoint ) ) != 0 )
2584  return rc;
2585 
2586  return 0;
2587 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An xHCI device.
Definition: xhci.h:1067
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition: xhci.h:1158
An xHCI endpoint.
Definition: xhci.h:1162
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1166
An xHCI device slot.
Definition: xhci.h:1134
uint8_t slot
Slot.
Definition: edd.h:17
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
static int xhci_evaluate_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Evaluate context.
Definition: xhci.c:2300
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:587

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

◆ xhci_endpoint_message()

static 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 2596 of file xhci.c.

2597  {
2598  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2599  struct xhci_device *xhci = endpoint->xhci;
2600  struct usb_setup_packet *packet;
2601  unsigned int input;
2602  size_t len;
2603  union xhci_trb trbs[ 1 /* setup */ + 1 /* possible data */ +
2604  1 /* status */ ];
2605  union xhci_trb *trb = trbs;
2606  struct xhci_trb_setup *setup;
2607  struct xhci_trb_data *data;
2608  struct xhci_trb_status *status;
2609  int rc;
2610 
2611  /* Profile message transfers */
2612  profile_start ( &xhci_message_profiler );
2613 
2614  /* Construct setup stage TRB */
2615  memset ( trbs, 0, sizeof ( trbs ) );
2616  assert ( iob_len ( iobuf ) >= sizeof ( *packet ) );
2617  packet = iobuf->data;
2618  iob_pull ( iobuf, sizeof ( *packet ) );
2619  setup = &(trb++)->setup;
2620  memcpy ( &setup->packet, packet, sizeof ( setup->packet ) );
2621  setup->len = cpu_to_le32 ( sizeof ( *packet ) );
2622  setup->flags = XHCI_TRB_IDT;
2623  setup->type = XHCI_TRB_SETUP;
2624  len = iob_len ( iobuf );
2625  input = ( packet->request & cpu_to_le16 ( USB_DIR_IN ) );
2626  if ( len )
2627  setup->direction = ( input ? XHCI_SETUP_IN : XHCI_SETUP_OUT );
2628 
2629  /* Map I/O buffer */
2630  if ( ( rc = iob_map ( iobuf, xhci->dma, len,
2631  ( input ? DMA_RX : DMA_TX ) ) ) != 0 )
2632  goto err_map;
2633 
2634  /* Construct data stage TRB, if applicable */
2635  if ( len ) {
2636  data = &(trb++)->data;
2637  data->data = cpu_to_le64 ( iob_dma ( iobuf ) );
2638  data->len = cpu_to_le32 ( len );
2639  data->type = XHCI_TRB_DATA;
2640  data->direction = ( input ? XHCI_DATA_IN : XHCI_DATA_OUT );
2641  }
2642 
2643  /* Construct status stage TRB */
2644  status = &(trb++)->status;
2645  status->flags = XHCI_TRB_IOC;
2646  status->type = XHCI_TRB_STATUS;
2647  status->direction =
2648  ( ( len && input ) ? XHCI_STATUS_OUT : XHCI_STATUS_IN );
2649 
2650  /* Enqueue TRBs */
2651  if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
2652  ( trb - trbs ) ) ) != 0 )
2653  goto err_enqueue;
2654 
2655  /* Ring the doorbell */
2656  xhci_doorbell ( &endpoint->ring );
2657 
2658  profile_stop ( &xhci_message_profiler );
2659  return 0;
2660 
2661  err_enqueue:
2662  iob_unmap ( iobuf );
2663  err_map:
2664  return rc;
2665 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:107
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_STATUS_IN
Input status direction.
Definition: xhci.h:440
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:135
A status stage transfer request block.
Definition: xhci.h:421
An xHCI device.
Definition: xhci.h:1067
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:138
Definition: bnxt_hsi.h:68
#define XHCI_SETUP_OUT
Setup stage output data direction.
Definition: xhci.h:393
#define cpu_to_le64(value)
Definition: byteswap.h:109
A data stage transfer request block.
Definition: xhci.h:396
#define XHCI_DATA_IN
Input data direction.
Definition: xhci.h:415
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:231
An xHCI endpoint.
Definition: xhci.h:1162
uint8_t direction
Transfer direction.
Definition: xhci.h:381
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:174
#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
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_TRB_DATA
A data stage transfer request block.
Definition: xhci.h:412
uint32_t len
Length.
Definition: xhci.h:375
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:279
ring len
Length.
Definition: dwmac.h:231
A setup stage transfer request block.
Definition: xhci.h:371
#define XHCI_TRB_SETUP
A setup stage transfer request block.
Definition: xhci.h:387
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
Definition: iobuf.h:268
uint8_t type
Type.
Definition: xhci.h:379
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:98
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:161
#define cpu_to_le32(value)
Definition: byteswap.h:108
uint8_t flags
Flags.
Definition: xhci.h:377
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
A transfer request block.
Definition: xhci.h:683
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
A USB setup data packet.
Definition: usb.h:83
#define XHCI_TRB_IDT
Transfer request block immediate data flag.
Definition: xhci.h:341
uint8_t status
Status.
Definition: ena.h:16
uint16_t request
Request.
Definition: usb.h:85
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
void * data
Start of data.
Definition: iobuf.h:53
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
#define cpu_to_le16(value)
Definition: byteswap.h:107
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition: xhci.c:1437
struct usb_setup_packet packet
Setup packet.
Definition: xhci.h:373
#define XHCI_SETUP_IN
Setup stage input data direction.
Definition: xhci.h:390
#define XHCI_STATUS_OUT
Output status direction.
Definition: xhci.h:443
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1164
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
Definition: xhci.h:338
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:587
void * memset(void *dest, int character, size_t len) __nonnull

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

static 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 2674 of file xhci.c.

2674  {
2675  unsigned int count;
2676 
2677  /* Split into 64kB TRBs */
2678  count = ( ( len + XHCI_MTU - 1 ) / XHCI_MTU );
2679 
2680  /* Append a zero-length TRB if applicable */
2681  if ( zlp || ( count == 0 ) )
2682  count++;
2683 
2684  return count;
2685 }
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:28
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225

References count, len, and XHCI_MTU.

Referenced by xhci_endpoint_stream().

◆ xhci_endpoint_stream()

static 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 2695 of file xhci.c.

2696  {
2697  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2698  struct xhci_device *xhci = endpoint->xhci;
2699  size_t len = iob_len ( iobuf );
2700  unsigned int count = xhci_endpoint_count ( len, zlp );
2701  union xhci_trb trbs[count];
2702  union xhci_trb *trb = trbs;
2703  struct xhci_trb_normal *normal;
2704  physaddr_t data;
2705  unsigned int i;
2706  size_t trb_len;
2707  int rc;
2708 
2709  /* Profile stream transfers */
2710  profile_start ( &xhci_stream_profiler );
2711 
2712  /* Map I/O buffer */
2713  if ( ( rc = iob_map ( iobuf, xhci->dma, len,
2714  ( ( ep->address & USB_DIR_IN ) ?
2715  DMA_RX : DMA_TX ) ) ) != 0 )
2716  goto err_map;
2717  data = iob_dma ( iobuf );
2718 
2719  /* Construct normal TRBs */
2720  memset ( &trbs, 0, sizeof ( trbs ) );
2721  for ( i = 0 ; i < count ; i ++ ) {
2722 
2723  /* Calculate TRB length */
2724  trb_len = XHCI_MTU;
2725  if ( trb_len > len )
2726  trb_len = len;
2727 
2728  /* Construct normal TRB */
2729  normal = &trb->normal;
2730  normal->data = cpu_to_le64 ( data );
2731  normal->len = cpu_to_le32 ( trb_len );
2732  normal->type = XHCI_TRB_NORMAL;
2733  normal->flags = XHCI_TRB_CH;
2734 
2735  /* Move to next TRB */
2736  data += trb_len;
2737  len -= trb_len;
2738  trb++;
2739  }
2740 
2741  /* Mark zero-length packet (if present) as a separate transfer */
2742  if ( zlp && ( count > 1 ) )
2743  trb[-2].normal.flags = 0;
2744 
2745  /* Generate completion for final TRB */
2746  trb[-1].normal.flags = XHCI_TRB_IOC;
2747 
2748  /* Enqueue TRBs */
2749  if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
2750  count ) ) != 0 )
2751  goto err_enqueue;
2752 
2753  /* Ring the doorbell */
2754  xhci_doorbell ( &endpoint->ring );
2755 
2756  profile_stop ( &xhci_stream_profiler );
2757  return 0;
2758 
2759  err_enqueue:
2760  iob_unmap ( iobuf );
2761  err_map:
2762  return rc;
2763 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:135
struct arbelprm_completion_queue_entry normal
Definition: arbel.h:11
An xHCI device.
Definition: xhci.h:1067
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:138
uint8_t flags
Flags.
Definition: xhci.h:356
#define cpu_to_le64(value)
Definition: byteswap.h:109
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:231
An xHCI endpoint.
Definition: xhci.h:1162
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:174
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:28
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:279
ring len
Length.
Definition: dwmac.h:231
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
Definition: iobuf.h:268
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:98
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:161
#define cpu_to_le32(value)
Definition: byteswap.h:108
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
A transfer request block.
Definition: xhci.h:683
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
A normal transfer request block.
Definition: xhci.h:350
struct xhci_trb_normal normal
Normal TRB.
Definition: xhci.h:689
unsigned long physaddr_t
Definition: stdint.h:20
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1168
#define XHCI_TRB_NORMAL
A normal transfer request block.
Definition: xhci.h:364
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1178
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define XHCI_TRB_CH
Transfer request block chain flag.
Definition: xhci.h:335
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition: xhci.c:1437
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1164
static unsigned int xhci_endpoint_count(size_t len, int zlp)
Calculate number of TRBs.
Definition: xhci.c:2674
unsigned int address
Endpoint address.
Definition: usb.h:408
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
Definition: xhci.h:338
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:587
void * memset(void *dest, int character, size_t len) __nonnull

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

static int xhci_device_open ( struct usb_device usb)
static

Open device.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 2778 of file xhci.c.

2778  {
2779  struct xhci_device *xhci = usb_bus_get_hostdata ( usb->port->hub->bus );
2780  struct usb_port *root_port = usb_root_hub_port ( usb );
2781  struct usb_port *tt = usb_transaction_translator ( usb );
2782  struct xhci_slot *slot;
2783  struct xhci_slot *tt_slot;
2784  size_t len;
2785  int type;
2786  int id;
2787  int rc;
2788 
2789  /* Determine applicable slot type */
2790  type = xhci_port_slot_type ( xhci, root_port->address );
2791  if ( type < 0 ) {
2792  rc = type;
2793  DBGC ( xhci, "XHCI %s-%d has no slot type\n",
2794  xhci->name, usb->port->address );
2795  goto err_type;
2796  }
2797 
2798  /* Allocate a device slot number */
2799  id = xhci_enable_slot ( xhci, type );
2800  if ( id < 0 ) {
2801  rc = id;
2802  goto err_enable_slot;
2803  }
2804  assert ( ( id > 0 ) && ( ( unsigned int ) id <= xhci->slots ) );
2805  assert ( xhci->slot[id] == NULL );
2806 
2807  /* Allocate and initialise structure */
2808  slot = zalloc ( sizeof ( *slot ) );
2809  if ( ! slot ) {
2810  rc = -ENOMEM;
2811  goto err_alloc;
2812  }
2813  usb_set_hostdata ( usb, slot );
2814  xhci->slot[id] = slot;
2815  slot->xhci = xhci;
2816  slot->usb = usb;
2817  slot->id = id;
2818  if ( tt ) {
2819  tt_slot = usb_get_hostdata ( tt->hub->usb );
2820  slot->tt_id = tt_slot->id;
2821  slot->tt_port = tt->address;
2822  }
2823 
2824  /* Allocate a device context */
2826  slot->context = dma_alloc ( xhci->dma, &slot->map, len,
2827  xhci_align ( len ) );
2828  if ( ! slot->context ) {
2829  rc = -ENOMEM;
2830  goto err_alloc_context;
2831  }
2832  memset ( slot->context, 0, len );
2833 
2834  /* Set device context base address */
2835  assert ( xhci->dcbaa.context[id] == 0 );
2836  xhci->dcbaa.context[id] = cpu_to_le64 ( dma ( &slot->map,
2837  slot->context ) );
2838 
2839  DBGC2 ( xhci, "XHCI %s slot %d device context [%08lx,%08lx) for %s\n",
2840  xhci->name, slot->id, virt_to_phys ( slot->context ),
2841  ( virt_to_phys ( slot->context ) + len ), usb->name );
2842  return 0;
2843 
2844  xhci->dcbaa.context[id] = 0;
2845  dma_free ( &slot->map, slot->context, len );
2846  err_alloc_context:
2847  xhci->slot[id] = NULL;
2848  free ( slot );
2849  err_alloc:
2850  xhci_disable_slot ( xhci, id );
2851  err_enable_slot:
2852  err_type:
2853  return rc;
2854 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1109
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1136
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
Definition: xhci.c:419
An xHCI device.
Definition: xhci.h:1067
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:400
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition: usb.h:784
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:835
#define cpu_to_le64(value)
Definition: byteswap.h:109
A USB port.
Definition: usb.h:813
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
#define ENOMEM
Not enough space.
Definition: errno.h:535
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:847
static int xhci_enable_slot(struct xhci_device *xhci, unsigned int type)
Enable slot.
Definition: xhci.c:1956
static int xhci_port_slot_type(struct xhci_device *xhci, unsigned int port)
Find port slot type.
Definition: xhci.c:767
struct usb_port * port
USB port.
Definition: usb.h:727
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct usb_device * usb
USB device.
Definition: xhci.h:1138
ring len
Length.
Definition: dwmac.h:231
char name[32]
Name.
Definition: usb.h:725
uint8_t id
Request identifier.
Definition: ena.h:12
An xHCI device slot.
Definition: xhci.h:1134
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
const char * name
Name.
Definition: xhci.h:1075
unsigned int id
Slot ID.
Definition: xhci.h:1140
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
uint8_t slot
Slot.
Definition: edd.h:17
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:795
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
struct usb_port * usb_root_hub_port(struct usb_device *usb)
Get USB root hub port.
Definition: usb.c:2356
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
Definition: usb.c:2372
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1062
static int xhci_disable_slot(struct xhci_device *xhci, unsigned int slot)
Disable slot.
Definition: xhci.c:1990
#define DBGC2(...)
Definition: compiler.h:522
unsigned int address
Port address.
Definition: usb.h:817
struct usb_hub * hub
USB hub.
Definition: usb.h:815
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
struct usb_bus * bus
USB bus.
Definition: usb.h:845
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1124
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
void * memset(void *dest, int character, size_t len) __nonnull

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_port::usb, usb_hub::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()

static void xhci_device_close ( struct usb_device usb)
static

Close device.

Parameters
usbUSB device

Definition at line 2861 of file xhci.c.

2861  {
2862  struct xhci_slot *slot = usb_get_hostdata ( usb );
2863  struct xhci_device *xhci = slot->xhci;
2864  size_t len = xhci_device_context_offset ( xhci, XHCI_CTX_END );
2865  unsigned int id = slot->id;
2866  int rc;
2867 
2868  /* Disable slot */
2869  if ( ( rc = xhci_disable_slot ( xhci, id ) ) != 0 ) {
2870  /* Slot is still enabled. Leak the slot context,
2871  * since the controller may still write to this
2872  * memory, and leave the DCBAA entry intact.
2873  *
2874  * If the controller later reports that this same slot
2875  * has been re-enabled, then some assertions will be
2876  * triggered.
2877  */
2878  DBGC ( xhci, "XHCI %s slot %d leaking context memory\n",
2879  xhci->name, slot->id );
2880  slot->context = NULL;
2881  }
2882 
2883  /* Free slot */
2884  if ( slot->context ) {
2885  dma_free ( &slot->map, slot->context, len );
2886  xhci->dcbaa.context[id] = 0;
2887  }
2888  xhci->slot[id] = NULL;
2889  free ( slot );
2890 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1109
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
Definition: xhci.c:419
An xHCI device.
Definition: xhci.h:1067
#define DBGC(...)
Definition: compiler.h:505
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
struct usb_device * usb
USB device.
Definition: xhci.h:1138
ring len
Length.
Definition: dwmac.h:231
uint8_t id
Request identifier.
Definition: ena.h:12
An xHCI device slot.
Definition: xhci.h:1134
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
const char * name
Name.
Definition: xhci.h:1075
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
uint8_t slot
Slot.
Definition: edd.h:17
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:795
static int xhci_disable_slot(struct xhci_device *xhci, unsigned int slot)
Disable slot.
Definition: xhci.c:1990
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1124
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

static int xhci_device_address ( struct usb_device usb)
static

Assign device address.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 2898 of file xhci.c.

2898  {
2899  struct xhci_slot *slot = usb_get_hostdata ( usb );
2900  struct xhci_device *xhci = slot->xhci;
2901  struct usb_port *root_port;
2902  int psiv;
2903  int rc;
2904 
2905  /* Calculate route string */
2906  slot->route = usb_route_string ( usb );
2907 
2908  /* Calculate root hub port number */
2909  root_port = usb_root_hub_port ( usb );
2910  slot->port = root_port->address;
2911 
2912  /* Calculate protocol speed ID */
2913  psiv = xhci_port_psiv ( xhci, slot->port, usb->speed );
2914  if ( psiv < 0 ) {
2915  rc = psiv;
2916  return rc;
2917  }
2918  slot->psiv = psiv;
2919 
2920  /* Address device */
2921  if ( ( rc = xhci_address_device ( xhci, slot ) ) != 0 )
2922  return rc;
2923 
2924  return 0;
2925 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xhci_address_device(struct xhci_device *xhci, struct xhci_slot *slot)
Address device.
Definition: xhci.c:2114
An xHCI device.
Definition: xhci.h:1067
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:835
unsigned int speed
Device speed.
Definition: usb.h:729
static int xhci_port_psiv(struct xhci_device *xhci, unsigned int port, unsigned int speed)
Find protocol speed ID value.
Definition: xhci.c:855
A USB port.
Definition: usb.h:813
struct usb_device * usb
USB device.
Definition: xhci.h:1138
An xHCI device slot.
Definition: xhci.h:1134
unsigned int usb_route_string(struct usb_device *usb)
Get USB route string.
Definition: usb.c:2336
uint8_t slot
Slot.
Definition: edd.h:17
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:795
struct usb_port * usb_root_hub_port(struct usb_device *usb)
Get USB root hub port.
Definition: usb.c:2356
unsigned int address
Port address.
Definition: usb.h:817

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

static int xhci_bus_open ( struct usb_bus bus)
static

Open USB bus.

Parameters
busUSB bus
Return values
rcReturn status code

Definition at line 2940 of file xhci.c.

2940  {
2941  struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
2942  int rc;
2943 
2944  /* Allocate device slot array */
2945  xhci->slot = zalloc ( ( xhci->slots + 1 ) * sizeof ( xhci->slot[0] ) );
2946  if ( ! xhci->slot ) {
2947  rc = -ENOMEM;
2948  goto err_slot_alloc;
2949  }
2950 
2951  /* Allocate device context base address array */
2952  if ( ( rc = xhci_dcbaa_alloc ( xhci ) ) != 0 )
2953  goto err_dcbaa_alloc;
2954 
2955  /* Allocate scratchpad buffers */
2956  if ( ( rc = xhci_scratchpad_alloc ( xhci ) ) != 0 )
2957  goto err_scratchpad_alloc;
2958 
2959  /* Allocate command ring */
2960  if ( ( rc = xhci_command_alloc ( xhci ) ) != 0 )
2961  goto err_command_alloc;
2962 
2963  /* Allocate event ring */
2964  if ( ( rc = xhci_event_alloc ( xhci ) ) != 0 )
2965  goto err_event_alloc;
2966 
2967  /* Start controller */
2968  xhci_run ( xhci );
2969 
2970  return 0;
2971 
2972  xhci_stop ( xhci );
2973  xhci_event_free ( xhci );
2974  err_event_alloc:
2975  xhci_command_free ( xhci );
2976  err_command_alloc:
2977  xhci_scratchpad_free ( xhci );
2978  err_scratchpad_alloc:
2979  xhci_dcbaa_free ( xhci );
2980  err_dcbaa_alloc:
2981  free ( xhci->slot );
2982  err_slot_alloc:
2983  return rc;
2984 }
static void xhci_command_free(struct xhci_device *xhci)
Free command ring.
Definition: xhci.c:1487
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition: xhci.c:1110
An xHCI device.
Definition: xhci.h:1067
static int xhci_command_alloc(struct xhci_device *xhci)
Allocate command ring.
Definition: xhci.c:1456
unsigned int slots
Number of device slots.
Definition: xhci.h:1089
#define ENOMEM
Not enough space.
Definition: errno.h:535
static void xhci_event_free(struct xhci_device *xhci)
Free event ring.
Definition: xhci.c:1570
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
static void xhci_dcbaa_free(struct xhci_device *xhci)
Free device context base address array.
Definition: xhci.c:959
static int xhci_scratchpad_alloc(struct xhci_device *xhci)
Allocate scratchpad buffers.
Definition: xhci.c:988
static void xhci_run(struct xhci_device *xhci)
Start xHCI device.
Definition: xhci.c:1088
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1062
static void xhci_scratchpad_free(struct xhci_device *xhci)
Free scratchpad buffers.
Definition: xhci.c:1054
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1124
static int xhci_event_alloc(struct xhci_device *xhci)
Allocate event ring.
Definition: xhci.c:1505
uint8_t bus
Bus.
Definition: edd.h:15
static int xhci_dcbaa_alloc(struct xhci_device *xhci)
Allocate device context base address array.
Definition: xhci.c:917

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

static void xhci_bus_close ( struct usb_bus bus)
static

Close USB bus.

Parameters
busUSB bus

Definition at line 2991 of file xhci.c.

2991  {
2992  struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
2993  unsigned int i;
2994 
2995  /* Sanity checks */
2996  assert ( xhci->slot != NULL );
2997  for ( i = 0 ; i <= xhci->slots ; i++ )
2998  assert ( xhci->slot[i] == NULL );
2999 
3000  xhci_stop ( xhci );
3001  xhci_event_free ( xhci );
3002  xhci_command_free ( xhci );
3003  xhci_scratchpad_free ( xhci );
3004  xhci_dcbaa_free ( xhci );
3005  free ( xhci->slot );
3006 }
static void xhci_command_free(struct xhci_device *xhci)
Free command ring.
Definition: xhci.c:1487
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition: xhci.c:1110
An xHCI device.
Definition: xhci.h:1067
unsigned int slots
Number of device slots.
Definition: xhci.h:1089
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void xhci_event_free(struct xhci_device *xhci)
Free event ring.
Definition: xhci.c:1570
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
static void xhci_dcbaa_free(struct xhci_device *xhci)
Free device context base address array.
Definition: xhci.c:959
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1062
static void xhci_scratchpad_free(struct xhci_device *xhci)
Free scratchpad buffers.
Definition: xhci.c:1054
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1124
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
uint8_t bus
Bus.
Definition: edd.h:15

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

static void xhci_bus_poll ( struct usb_bus bus)
static

Poll USB bus.

Parameters
busUSB bus

Definition at line 3013 of file xhci.c.

3013  {
3014  struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
3015 
3016  /* Poll event ring */
3017  xhci_event_poll ( xhci );
3018 }
An xHCI device.
Definition: xhci.h:1067
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1062
static void xhci_event_poll(struct xhci_device *xhci)
Poll event ring.
Definition: xhci.c:1745
uint8_t bus
Bus.
Definition: edd.h:15

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

◆ xhci_hub_open()

static int xhci_hub_open ( struct usb_hub hub)
static

Open hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 3033 of file xhci.c.

3033  {
3034  struct xhci_slot *slot;
3035 
3036  /* Do nothing if this is the root hub */
3037  if ( ! hub->usb )
3038  return 0;
3039 
3040  /* Get device slot */
3041  slot = usb_get_hostdata ( hub->usb );
3042 
3043  /* Update device slot hub parameters. We don't inform the
3044  * hardware of this information until the hub's interrupt
3045  * endpoint is opened, since the only mechanism for so doing
3046  * provided by the xHCI specification is a Configure Endpoint
3047  * command, and we can't issue that command until we have a
3048  * non-EP0 endpoint to configure.
3049  */
3050  slot->ports = hub->ports;
3051 
3052  return 0;
3053 }
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:847
unsigned int ports
Number of ports.
Definition: usb.h:851
An xHCI device slot.
Definition: xhci.h:1134
uint8_t slot
Slot.
Definition: edd.h:17
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:795

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

◆ xhci_hub_close()

static void xhci_hub_close ( struct usb_hub *hub  __unused)
static

Close hub.

Parameters
hubUSB hub

Definition at line 3060 of file xhci.c.

3060  {
3061 
3062  /* Nothing to do */
3063 }

◆ xhci_root_open()

static int xhci_root_open ( struct usb_hub hub)
static

Open root hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 3078 of file xhci.c.

3078  {
3079  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3080  struct usb_port *port;
3081  uint32_t portsc;
3082  unsigned int i;
3083 
3084  /* Enable power to all ports */
3085  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3086  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( i ) );
3087  portsc &= XHCI_PORTSC_PRESERVE;
3088  portsc |= XHCI_PORTSC_PP;
3089  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( i ) );
3090  }
3091 
3092  /* xHCI spec requires us to potentially wait 20ms after
3093  * enabling power to a port.
3094  */
3096 
3097  /* USB3 ports may power up as Disabled */
3098  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3099  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( i ) );
3100  port = usb_port ( hub, i );
3101  if ( ( port->protocol >= USB_PROTO_3_0 ) &&
3102  ( ( portsc & XHCI_PORTSC_PLS_MASK ) ==
3104  /* Force link state to RxDetect */
3105  portsc &= XHCI_PORTSC_PRESERVE;
3107  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( i ) );
3108  }
3109  }
3110 
3111  /* Some xHCI cards seem to require an additional delay after
3112  * setting the link state to RxDetect.
3113  */
3115 
3116  return 0;
3117 }
unsigned int ports
Number of ports.
Definition: xhci.h:1093
An xHCI device.
Definition: xhci.h:1067
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
Definition: xhci.h:284
#define XHCI_PORTSC_PP
Port power.
Definition: xhci.h:228
A USB port.
Definition: usb.h:813
u8 port
Port number.
Definition: CIB_PRM.h:31
USB 3.0.
Definition: usb.h:25
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define XHCI_PORTSC_LWS
Port link state write strobe.
Definition: xhci.h:243
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
#define XHCI_PORTSC_PLS_RXDETECT
RxDetect port link state.
Definition: xhci.h:222
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
#define XHCI_PORT_POWER_DELAY_MS
Time to delay after enabling power to a port.
Definition: xhci.h:231
struct usb_hub * hub
USB hub.
Definition: usb.h:815
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:960
#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
void * op
Operational registers.
Definition: xhci.h:1082
#define XHCI_PORTSC_PLS_MASK
Port link state mask.
Definition: xhci.h:225
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:948

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

static void xhci_root_close ( struct usb_hub *hub  __unused)
static

Close root hub.

Parameters
hubUSB hub

Definition at line 3124 of file xhci.c.

3124  {
3125 
3126  /* Nothing to do */
3127 }

◆ xhci_root_enable()

static 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 3136 of file xhci.c.

3136  {
3137  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3138  uint32_t portsc;
3139  unsigned int i;
3140 
3141  /* Reset port */
3142  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3143  portsc &= XHCI_PORTSC_PRESERVE;
3144  portsc |= XHCI_PORTSC_PR;
3145  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3146 
3147  /* Wait for port to become enabled */
3148  for ( i = 0 ; i < XHCI_PORT_RESET_MAX_WAIT_MS ; i++ ) {
3149 
3150  /* Check port status */
3151  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3152  if ( portsc & XHCI_PORTSC_PED )
3153  return 0;
3154 
3155  /* Delay */
3156  mdelay ( 1 );
3157  }
3158 
3159  DBGC ( xhci, "XHCI %s-%d timed out waiting for port to enable\n",
3160  xhci->name, port->address );
3161  return -ETIMEDOUT;
3162 }
An xHCI device.
Definition: xhci.h:1067
#define XHCI_PORT_RESET_MAX_WAIT_MS
Maximum time to wait for a port reset to complete.
Definition: xhci.h:1016
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
Definition: xhci.h:284
u8 port
Port number.
Definition: CIB_PRM.h:31
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
#define XHCI_PORTSC_PR
Port reset.
Definition: xhci.h:213
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:210
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:670
void * op
Operational registers.
Definition: xhci.h:1082
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:948

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

static 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 3171 of file xhci.c.

3171  {
3172  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3173  uint32_t portsc;
3174 
3175  /* Disable port */
3176  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3177  portsc &= XHCI_PORTSC_PRESERVE;
3178  portsc |= XHCI_PORTSC_PED;
3179  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3180 
3181  /* Allow time for link state to stabilise */
3183 
3184  /* Set link state to RxDetect for USB3 ports */
3185  if ( port->protocol >= USB_PROTO_3_0 ) {
3186  portsc &= XHCI_PORTSC_PRESERVE;
3187  portsc |= ( XHCI_PORTSC_PLS_RXDETECT | XHCI_PORTSC_LWS );
3188  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3189  }
3190 
3191  /* Allow time for link state to stabilise */
3193 
3194  return 0;
3195 }
An xHCI device.
Definition: xhci.h:1067
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
Definition: xhci.h:284
u8 port
Port number.
Definition: CIB_PRM.h:31
USB 3.0.
Definition: usb.h:25
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define XHCI_PORTSC_LWS
Port link state write strobe.
Definition: xhci.h:243
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
#define XHCI_PORTSC_PLS_RXDETECT
RxDetect port link state.
Definition: xhci.h:222
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:210
#define XHCI_LINK_STATE_DELAY_MS
Time to delay after writing the port link state.
Definition: xhci.h:246
void * op
Operational registers.
Definition: xhci.h:1082
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:948

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

static 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 3204 of file xhci.c.

3204  {
3205  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3206  uint32_t portsc;
3207  unsigned int psiv;
3208  int ccs;
3209  int ped;
3210  int csc;
3211  int speed;
3212  int rc;
3213 
3214  /* Read port status */
3215  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3216  DBGC2 ( xhci, "XHCI %s-%d status is %08x\n",
3217  xhci->name, port->address, portsc );
3218  ccs = ( portsc & XHCI_PORTSC_CCS );
3219  ped = ( portsc & XHCI_PORTSC_PED );
3220  csc = ( portsc & XHCI_PORTSC_CSC );
3221  psiv = XHCI_PORTSC_PSIV ( portsc );
3222 
3223  /* Record disconnections and clear changes */
3224  port->disconnected |= csc;
3225  portsc &= ( XHCI_PORTSC_PRESERVE | XHCI_PORTSC_CHANGE );
3226  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3227 
3228  /* Port speed is not valid unless port is connected */
3229  if ( ! ccs ) {
3230  port->speed = USB_SPEED_NONE;
3231  return 0;
3232  }
3233 
3234  /* For USB2 ports, the PSIV field is not valid until the port
3235  * completes reset and becomes enabled.
3236  */
3237  if ( ( port->protocol < USB_PROTO_3_0 ) && ! ped ) {
3238  port->speed = USB_SPEED_FULL;
3239  return 0;
3240  }
3241 
3242  /* Get port speed and map to generic USB speed */
3243  speed = xhci_port_speed ( xhci, port->address, psiv );
3244  if ( speed < 0 ) {
3245  rc = speed;
3246  return rc;
3247  }
3248 
3249  port->speed = speed;
3250  return 0;
3251 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_PORTSC_PSIV(portsc)
Port speed ID value.
Definition: xhci.h:234
An xHCI device.
Definition: xhci.h:1067
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#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_CCS
Current connect status.
Definition: xhci.h:207
u8 port
Port number.
Definition: CIB_PRM.h:31
USB 3.0.
Definition: usb.h:25
Not connected.
Definition: usb.h:47
#define XHCI_PORTSC_CHANGE
Port status change mask.
Definition: xhci.h:270
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
#define DBGC2(...)
Definition: compiler.h:522
static int xhci_port_speed(struct xhci_device *xhci, unsigned int port, unsigned int psiv)
Find port speed.
Definition: xhci.c:791
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:210
Full speed (12Mbps)
Definition: usb.h:51
void * op
Operational registers.
Definition: xhci.h:1082
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:948

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

static 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 3261 of file xhci.c.

3262  {
3263  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3264 
3265  /* Should never be called; this is a root hub */
3266  DBGC ( xhci, "XHCI %s-%d nonsensical CLEAR_TT for %s %s\n", xhci->name,
3267  port->address, ep->usb->name, usb_endpoint_name ( ep ) );
3268 
3269  return -ENOTSUP;
3270 }
An xHCI device.
Definition: xhci.h:1067
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
u8 port
Port number.
Definition: CIB_PRM.h:31
char name[32]
Name.
Definition: usb.h:725
const char * name
Name.
Definition: xhci.h:1075
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
struct usb_device * usb
USB device.
Definition: usb.h:406
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:948

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 3319 of file xhci.c.

3319  {
3320  struct usb_port *port;
3321  unsigned int i;
3322  int rc;
3323 
3324  /* Reset device */
3325  if ( ( rc = xhci_reset ( xhci ) ) != 0 )
3326  goto err_reset;
3327 
3328  /* Allocate USB bus */
3329  xhci->bus = alloc_usb_bus ( xhci->dev, xhci->ports, XHCI_MTU,
3330  &xhci_operations );
3331  if ( ! xhci->bus ) {
3332  rc = -ENOMEM;
3333  goto err_alloc_bus;
3334  }
3335  usb_bus_set_hostdata ( xhci->bus, xhci );
3336  usb_hub_set_drvdata ( xhci->bus->hub, xhci );
3337 
3338  /* Set port protocols */
3339  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3340  port = usb_port ( xhci->bus->hub, i );
3341  port->protocol = xhci_port_protocol ( xhci, i );
3342  }
3343 
3344  /* Register USB bus */
3345  if ( ( rc = register_usb_bus ( xhci->bus ) ) != 0 )
3346  goto err_register;
3347 
3348  return 0;
3349 
3350  unregister_usb_bus ( xhci->bus );
3351  err_register:
3352  free_usb_bus ( xhci->bus );
3353  err_alloc_bus:
3354  xhci_reset ( xhci );
3355  err_reset:
3356  return rc;
3357 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int ports
Number of ports.
Definition: xhci.h:1093
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:2095
struct device * dev
Underlying hardware device.
Definition: xhci.h:1071
struct usb_bus * bus
USB bus.
Definition: xhci.h:1127
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1051
A USB port.
Definition: usb.h:813
#define ENOMEM
Not enough space.
Definition: errno.h:535
u8 port
Port number.
Definition: CIB_PRM.h:31
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2171
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:28
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1142
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2131
static unsigned int xhci_port_protocol(struct xhci_device *xhci, unsigned int port)
Find port protocol.
Definition: xhci.c:706
struct usb_hub * hub
Root hub.
Definition: usb.h:995
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:937
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:960
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2195
static struct usb_host_operations xhci_operations
USB host controller operations.
Definition: xhci.c:3280

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 3364 of file xhci.c.

3364  {
3365  struct usb_bus *bus = xhci->bus;
3366 
3367  /* Unregister and free USB bus */
3368  unregister_usb_bus ( bus );
3369  free_usb_bus ( bus );
3370 
3371  /* Reset device */
3372  xhci_reset ( xhci );
3373 }
struct usb_bus * bus
USB bus.
Definition: xhci.h:1127
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2171
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1142
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2195

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

static 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 3388 of file xhci.c.

3388  {
3389  struct xhci_pch *pch = &xhci->pch;
3390  uint32_t xusb2pr;
3391  uint32_t xusb2prm;
3393  uint32_t usb3prm;
3394 
3395  /* Enable SuperSpeed capability. Do this before rerouting
3396  * USB2 ports, so that USB3 devices connect at SuperSpeed.
3397  */
3399  pci_read_config_dword ( pci, XHCI_PCH_USB3PRM, &usb3prm );
3400  if ( usb3prm & ~usb3pssen ) {
3401  DBGC ( xhci, "XHCI %s enabling SuperSpeed on ports %08x\n",
3402  xhci->name, ( usb3prm & ~usb3pssen ) );
3403  }
3404  pch->usb3pssen = usb3pssen;
3405  usb3pssen |= usb3prm;
3407 
3408  /* Route USB2 ports from EHCI to xHCI */
3410  pci_read_config_dword ( pci, XHCI_PCH_XUSB2PRM, &xusb2prm );
3411  if ( xusb2prm & ~xusb2pr ) {
3412  DBGC ( xhci, "XHCI %s routing ports %08x from EHCI to xHCI\n",
3413  xhci->name, ( xusb2prm & ~xusb2pr ) );
3414  }
3415  pch->xusb2pr = xusb2pr;
3416  xusb2pr |= xusb2prm;
3418 }
#define XHCI_PCH_XUSB2PR
Intel PCH USB2 port routing register.
Definition: xhci.h:1030
#define DBGC(...)
Definition: compiler.h:505
Intel PCH quirk.
Definition: xhci.h:1019
struct xhci_pch pch
Intel PCH quirk.
Definition: xhci.h:1130
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
uint32_t xusb2pr
USB2 port routing register original value.
Definition: xhci.h:1021
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
Definition: xhci.h:1023
const char * name
Name.
Definition: xhci.h:1075
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_PCH_USB3PSSEN
Intel PCH SuperSpeed enable register.
Definition: xhci.h:1036
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define XHCI_PCH_USB3PRM
Intel PCH USB3 port routing mask register.
Definition: xhci.h:1039
#define XHCI_PCH_XUSB2PRM
Intel PCH USB2 port routing mask register.
Definition: xhci.h:1033

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

static 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 3426 of file xhci.c.

3426  {
3427  struct xhci_pch *pch = &xhci->pch;
3428 
3429  /* Restore USB2 port routing to original state */
3431 
3432  /* Restore SuperSpeed capability to original state */
3434 }
#define XHCI_PCH_XUSB2PR
Intel PCH USB2 port routing register.
Definition: xhci.h:1030
Intel PCH quirk.
Definition: xhci.h:1019
struct xhci_pch pch
Intel PCH quirk.
Definition: xhci.h:1130
uint32_t xusb2pr
USB2 port routing register original value.
Definition: xhci.h:1021
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
Definition: xhci.h:1023
#define XHCI_PCH_USB3PSSEN
Intel PCH SuperSpeed enable register.
Definition: xhci.h:1036
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.

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

static int xhci_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 3442 of file xhci.c.

3442  {
3443  struct xhci_device *xhci;
3444  unsigned long bar_start;
3445  size_t bar_size;
3446  int rc;
3447 
3448  /* Allocate and initialise structure */
3449  xhci = zalloc ( sizeof ( *xhci ) );
3450  if ( ! xhci ) {
3451  rc = -ENOMEM;
3452  goto err_alloc;
3453  }
3454  xhci->dev = &pci->dev;
3455  xhci->dma = &pci->dma;
3456  xhci->quirks = pci->id->driver_data;
3457 
3458  /* Fix up PCI device */
3459  adjust_pci_device ( pci );
3460 
3461  /* Map registers */
3462  bar_start = pci_bar_start ( pci, XHCI_BAR );
3463  bar_size = pci_bar_size ( pci, XHCI_BAR );
3464  xhci->regs = pci_ioremap ( pci, bar_start, bar_size );
3465  if ( ! xhci->regs ) {
3466  rc = -ENODEV;
3467  goto err_ioremap;
3468  }
3469 
3470  /* Initialise xHCI device */
3471  xhci_init ( xhci );
3472 
3473  /* Initialise USB legacy support and claim ownership */
3474  xhci_legacy_init ( xhci );
3475  xhci_legacy_claim ( xhci );
3476 
3477  /* Fix Intel PCH-specific quirks, if applicable */
3478  if ( xhci->quirks & XHCI_PCH )
3479  xhci_pch_fix ( xhci, pci );
3480 
3481  /* Register xHCI device */
3482  if ( ( rc = xhci_register ( xhci ) ) != 0 )
3483  goto err_register;
3484 
3485  pci_set_drvdata ( pci, xhci );
3486  return 0;
3487 
3488  xhci_unregister ( xhci );
3489  err_register:
3490  if ( xhci->quirks & XHCI_PCH )
3491  xhci_pch_undo ( xhci, pci );
3492  xhci_legacy_release ( xhci );
3493  iounmap ( xhci->regs );
3494  err_ioremap:
3495  free ( xhci );
3496  err_alloc:
3497  return rc;
3498 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:215
int xhci_register(struct xhci_device *xhci)
Register xHCI controller.
Definition: xhci.c:3319
An xHCI device.
Definition: xhci.h:1067
void * regs
Registers.
Definition: xhci.h:1069
unsigned long driver_data
Arbitrary driver data.
Definition: pci.h:183
struct device * dev
Underlying hardware device.
Definition: xhci.h:1071
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition: pci.c:164
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:241
struct device dev
Generic device.
Definition: pci.h:213
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:366
#define ENOMEM
Not enough space.
Definition: errno.h:535
void xhci_init(struct xhci_device *xhci)
Initialise device.
Definition: xhci.c:264
#define XHCI_PCH
Intel PCH quirk flag.
Definition: xhci.h:1027
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:97
static void xhci_legacy_claim(struct xhci_device *xhci)
Claim ownership from BIOS.
Definition: xhci.c:571
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
#define ENODEV
No such device.
Definition: errno.h:510
#define XHCI_BAR
xHCI PCI BAR
Definition: xhci.h:31
static void xhci_pch_fix(struct xhci_device *xhci, struct pci_device *pci)
Fix Intel PCH-specific quirks.
Definition: xhci.c:3388
struct pci_device_id * id
Driver device ID.
Definition: pci.h:248
static void xhci_pch_undo(struct xhci_device *xhci, struct pci_device *pci)
Undo Intel PCH-specific quirk fixes.
Definition: xhci.c:3426
void iounmap(volatile const void *io_addr)
Unmap I/O address.
struct dma_device * dma
DMA device.
Definition: xhci.h:1073
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
static void xhci_legacy_init(struct xhci_device *xhci)
Initialise USB legacy support.
Definition: xhci.c:540
unsigned int quirks
Quirks.
Definition: xhci.h:1077
void xhci_unregister(struct xhci_device *xhci)
Unregister xHCI controller.
Definition: xhci.c:3364
static void xhci_legacy_release(struct xhci_device *xhci)
Release ownership back to BIOS.
Definition: xhci.c:618

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

static void xhci_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 3505 of file xhci.c.

3505  {
3506  struct xhci_device *xhci = pci_get_drvdata ( pci );
3507  uint16_t command;
3508 
3509  /* Some systems are observed to disable bus mastering on
3510  * Thunderbolt controllers before we get a chance to shut
3511  * down. Detect this and avoid attempting any DMA operations,
3512  * which are guaranteed to fail and may end up spuriously
3513  * completing after the operating system kernel starts up.
3514  */
3516  if ( ! ( command & PCI_COMMAND_MASTER ) ) {
3517  DBGC ( xhci, "XHCI %s DMA was disabled\n", xhci->name );
3518  xhci_fail ( xhci );
3519  }
3520 
3521  /* Unregister xHCI controller */
3522  xhci_unregister ( xhci );
3523 
3524  /* Undo any PCH-specific fixes */
3525  if ( xhci->quirks & XHCI_PCH )
3526  xhci_pch_undo ( xhci, pci );
3527 
3528  /* Release ownership back to BIOS */
3529  xhci_legacy_release ( xhci );
3530 
3531  /* Unmap registers */
3532  iounmap ( xhci->regs );
3533 
3534  /* Free device */
3535  free ( xhci );
3536 }
unsigned short uint16_t
Definition: stdint.h:11
An xHCI device.
Definition: xhci.h:1067
void * regs
Registers.
Definition: xhci.h:1069
A command-line command.
Definition: command.h:10
#define DBGC(...)
Definition: compiler.h:505
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
PCI command.
Definition: pci.h:26
#define PCI_COMMAND_MASTER
Bus master.
Definition: pci.h:29
#define XHCI_PCH
Intel PCH quirk flag.
Definition: xhci.h:1027
static int xhci_fail(struct xhci_device *xhci)
Mark xHCI device as permanently failed.
Definition: xhci.c:1180
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
const char * name
Name.
Definition: xhci.h:1075
static int command
Definition: epic100.c:68
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:376
static void xhci_pch_undo(struct xhci_device *xhci, struct pci_device *pci)
Undo Intel PCH-specific quirk fixes.
Definition: xhci.c:3426
void iounmap(volatile const void *io_addr)
Unmap I/O address.
unsigned int quirks
Quirks.
Definition: xhci.h:1077
void xhci_unregister(struct xhci_device *xhci)
Unregister xHCI controller.
Definition: xhci.c:3364
static void xhci_legacy_release(struct xhci_device *xhci)
Release ownership back to BIOS.
Definition: xhci.c:618

References command, 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()

static void xhci_shutdown ( int  booting)
static

Prepare for exit.

Parameters
bootingSystem is shutting down for OS boot

Definition at line 3560 of file xhci.c.

3560  {
3561  /* If we are shutting down to boot an OS, then prevent the
3562  * release of ownership back to BIOS.
3563  */
3564  xhci_legacy_prevent_release = booting;
3565 }
static int xhci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
Definition: xhci.c:533

References xhci_legacy_prevent_release.

◆ __startup_fn()

struct startup_fn xhci_startup __startup_fn ( STARTUP_LATE  )

Startup/shutdown function.

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.

◆ 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 3280 of file xhci.c.

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 XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1042
#define XHCI_PCH
Intel PCH quirk flag.
Definition: xhci.h:1027
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:308

XHCI PCI device IDs.

Definition at line 3539 of file xhci.c.

◆ __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_ID(base, sub, progif)
Construct PCI class ID.
Definition: pci.h:203
static struct pci_device_id xhci_ids[]
XHCI PCI device IDs.
Definition: xhci.c:3539
#define PCI_CLASS_SERIAL_USB_XHCI
xHCI USB controller
Definition: pci.h:141
#define PCI_CLASS_SERIAL
Definition: Pci22.h:267
static int xhci_probe(struct pci_device *pci)
Probe PCI device.
Definition: xhci.c:3442
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:273
static void xhci_remove(struct pci_device *pci)
Remove PCI device.
Definition: xhci.c:3505

XHCI PCI driver.

Definition at line 3546 of file xhci.c.