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)
 
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 63 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 65 of file xhci.c.

◆ EIO_BABBLE

#define EIO_BABBLE   __einfo_error ( EINFO_EIO_BABBLE )

Definition at line 68 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 70 of file xhci.c.

◆ EIO_USB

#define EIO_USB   __einfo_error ( EINFO_EIO_USB )

Definition at line 73 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 75 of file xhci.c.

◆ EIO_TRB

#define EIO_TRB   __einfo_error ( EINFO_EIO_TRB )

Definition at line 78 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 80 of file xhci.c.

◆ EIO_STALL

#define EIO_STALL   __einfo_error ( EINFO_EIO_STALL )

Definition at line 83 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 85 of file xhci.c.

◆ EIO_RESOURCE

#define EIO_RESOURCE   __einfo_error ( EINFO_EIO_RESOURCE )

Definition at line 88 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 90 of file xhci.c.

◆ EIO_BANDWIDTH

#define EIO_BANDWIDTH   __einfo_error ( EINFO_EIO_BANDWIDTH )

Definition at line 93 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 95 of file xhci.c.

◆ EIO_NO_SLOTS

#define EIO_NO_SLOTS   __einfo_error ( EINFO_EIO_NO_SLOTS )

Definition at line 98 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 100 of file xhci.c.

◆ EIO_STREAM_TYPE

#define EIO_STREAM_TYPE   __einfo_error ( EINFO_EIO_STREAM_TYPE )

Definition at line 103 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 105 of file xhci.c.

◆ EIO_SLOT

#define EIO_SLOT   __einfo_error ( EINFO_EIO_SLOT )

Definition at line 108 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 110 of file xhci.c.

◆ EIO_ENDPOINT

#define EIO_ENDPOINT   __einfo_error ( EINFO_EIO_ENDPOINT )

Definition at line 113 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 115 of file xhci.c.

◆ EIO_SHORT

#define EIO_SHORT   __einfo_error ( EINFO_EIO_SHORT )

Definition at line 118 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 120 of file xhci.c.

◆ EIO_UNDERRUN

#define EIO_UNDERRUN   __einfo_error ( EINFO_EIO_UNDERRUN )

Definition at line 123 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 125 of file xhci.c.

◆ EIO_OVERRUN

#define EIO_OVERRUN   __einfo_error ( EINFO_EIO_OVERRUN )

Definition at line 128 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 130 of file xhci.c.

◆ EIO_VF_RING_FULL

#define EIO_VF_RING_FULL   __einfo_error ( EINFO_EIO_VF_RING_FULL )

Definition at line 133 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 135 of file xhci.c.

◆ EIO_PARAMETER

#define EIO_PARAMETER   __einfo_error ( EINFO_EIO_PARAMETER )

Definition at line 138 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 140 of file xhci.c.

◆ EIO_BANDWIDTH_OVERRUN

#define EIO_BANDWIDTH_OVERRUN   __einfo_error ( EINFO_EIO_BANDWIDTH_OVERRUN )

Definition at line 143 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 145 of file xhci.c.

◆ EIO_CONTEXT

#define EIO_CONTEXT   __einfo_error ( EINFO_EIO_CONTEXT )

Definition at line 148 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 150 of file xhci.c.

◆ EIO_NO_PING

#define EIO_NO_PING   __einfo_error ( EINFO_EIO_NO_PING )

Definition at line 153 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 155 of file xhci.c.

◆ EIO_RING_FULL

#define EIO_RING_FULL   __einfo_error ( EINFO_EIO_RING_FULL )

Definition at line 158 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 160 of file xhci.c.

◆ EIO_INCOMPATIBLE

#define EIO_INCOMPATIBLE   __einfo_error ( EINFO_EIO_INCOMPATIBLE )

Definition at line 163 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 165 of file xhci.c.

◆ EIO_MISSED

#define EIO_MISSED   __einfo_error ( EINFO_EIO_MISSED )

Definition at line 168 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 170 of file xhci.c.

◆ EIO_CMD_STOPPED

#define EIO_CMD_STOPPED   __einfo_error ( EINFO_EIO_CMD_STOPPED )

Definition at line 173 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 175 of file xhci.c.

◆ EIO_CMD_ABORTED

#define EIO_CMD_ABORTED   __einfo_error ( EINFO_EIO_CMD_ABORTED )

Definition at line 178 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 180 of file xhci.c.

◆ EIO_STOP

#define EIO_STOP   __einfo_error ( EINFO_EIO_STOP )

Definition at line 183 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 185 of file xhci.c.

◆ EIO_STOP_LEN

#define EIO_STOP_LEN   __einfo_error ( EINFO_EIO_STOP_LEN )

Definition at line 188 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 190 of file xhci.c.

◆ EIO_STOP_SHORT

#define EIO_STOP_SHORT   __einfo_error ( EINFO_EIO_STOP_SHORT )

Definition at line 193 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 195 of file xhci.c.

◆ EIO_LATENCY

#define EIO_LATENCY   __einfo_error ( EINFO_EIO_LATENCY )

Definition at line 198 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 200 of file xhci.c.

◆ EIO_ISOCH

#define EIO_ISOCH   __einfo_error ( EINFO_EIO_ISOCH )

Definition at line 203 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:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 205 of file xhci.c.

◆ EPROTO_LOST

#define EPROTO_LOST   __einfo_error ( EINFO_EPROTO_LOST )

Definition at line 208 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:180
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 210 of file xhci.c.

◆ EPROTO_UNDEFINED

#define EPROTO_UNDEFINED   __einfo_error ( EINFO_EPROTO_UNDEFINED )

Definition at line 213 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:180
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 215 of file xhci.c.

◆ EPROTO_STREAM_ID

#define EPROTO_STREAM_ID   __einfo_error ( EINFO_EPROTO_STREAM_ID )

Definition at line 218 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:180
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 220 of file xhci.c.

◆ EPROTO_SECONDARY

#define EPROTO_SECONDARY   __einfo_error ( EINFO_EPROTO_SECONDARY )

Definition at line 223 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:180
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 225 of file xhci.c.

◆ EPROTO_SPLIT

#define EPROTO_SPLIT   __einfo_error ( EINFO_EPROTO_SPLIT )

Definition at line 228 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:180
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 230 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:188
#define EIO_STOP
Definition: xhci.c:183
#define EIO_LATENCY
Definition: xhci.c:198
#define EIO_BANDWIDTH_OVERRUN
Definition: xhci.c:143
#define EIO_USB
Definition: xhci.c:73
#define EIO_BANDWIDTH
Definition: xhci.c:93
#define EPROTO_LOST
Definition: xhci.c:208
static unsigned int code
Response code.
Definition: hyperv.h:26
#define EIO_RESOURCE
Definition: xhci.c:88
#define EIO_DATA
Definition: xhci.c:63
#define EIO_SHORT
Definition: xhci.c:118
#define EIO_INCOMPATIBLE
Definition: xhci.c:163
#define EIO_STOP_SHORT
Definition: xhci.c:193
#define EPROTO_STREAM_ID
Definition: xhci.c:218
#define EINFO_EIO
Definition: errno.h:434
#define EIO_CMD_ABORTED
Definition: xhci.c:178
#define EFAULT
Bad address.
Definition: errno.h:393
#define EIO_CMD_STOPPED
Definition: xhci.c:173
#define EIO_PARAMETER
Definition: xhci.c:138
#define EIO_TRB
Definition: xhci.c:78
#define EIO_CONTEXT
Definition: xhci.c:148
#define EIO_STALL
Definition: xhci.c:83
#define EIO_NO_SLOTS
Definition: xhci.c:98
#define EIO_SLOT
Definition: xhci.c:108
#define EIO_BABBLE
Definition: xhci.c:68
#define EIO_ISOCH
Definition: xhci.c:203
#define EIO_ENDPOINT
Definition: xhci.c:113
#define EPROTO_UNDEFINED
Definition: xhci.c:213
#define EIO_RING_FULL
Definition: xhci.c:158
#define EIO_VF_RING_FULL
Definition: xhci.c:133
#define EIO_OVERRUN
Definition: xhci.c:128
#define EIO_MISSED
Definition: xhci.c:168
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225
#define EIO_UNDERRUN
Definition: xhci.c:123
#define EIO_STREAM_TYPE
Definition: xhci.c:103
#define EIO_NO_PING
Definition: xhci.c:153
#define EPROTO_SPLIT
Definition: xhci.c:228
#define EPROTO_SECONDARY
Definition: xhci.c:223
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 233 of file xhci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ xhci_init()

void xhci_init ( struct xhci_device xhci)

Initialise device.

Parameters
xhcixHCI device

Definition at line 263 of file xhci.c.

263  {
264  uint32_t hcsparams1;
265  uint32_t hcsparams2;
266  uint32_t hccparams1;
267  uint32_t pagesize;
268  size_t caplength;
269  size_t rtsoff;
270  size_t dboff;
271 
272  /* Set device name */
273  xhci->name = xhci->dev->name;
274 
275  /* Locate capability, operational, runtime, and doorbell registers */
276  xhci->cap = xhci->regs;
277  caplength = readb ( xhci->cap + XHCI_CAP_CAPLENGTH );
278  rtsoff = readl ( xhci->cap + XHCI_CAP_RTSOFF );
279  dboff = readl ( xhci->cap + XHCI_CAP_DBOFF );
280  xhci->op = ( xhci->cap + caplength );
281  xhci->run = ( xhci->cap + rtsoff );
282  xhci->db = ( xhci->cap + dboff );
283  DBGC2 ( xhci, "XHCI %s cap %08lx op %08lx run %08lx db %08lx\n",
284  xhci->name, virt_to_phys ( xhci->cap ),
285  virt_to_phys ( xhci->op ), virt_to_phys ( xhci->run ),
286  virt_to_phys ( xhci->db ) );
287 
288  /* Read structural parameters 1 */
289  hcsparams1 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS1 );
290  xhci->slots = XHCI_HCSPARAMS1_SLOTS ( hcsparams1 );
291  xhci->intrs = XHCI_HCSPARAMS1_INTRS ( hcsparams1 );
292  xhci->ports = XHCI_HCSPARAMS1_PORTS ( hcsparams1 );
293  DBGC ( xhci, "XHCI %s has %d slots %d intrs %d ports\n",
294  xhci->name, xhci->slots, xhci->intrs, xhci->ports );
295 
296  /* Read structural parameters 2 */
297  hcsparams2 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS2 );
298  xhci->scratch.count = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
299  DBGC2 ( xhci, "XHCI %s needs %d scratchpads\n",
300  xhci->name, xhci->scratch.count );
301 
302  /* Read capability parameters 1 */
303  hccparams1 = readl ( xhci->cap + XHCI_CAP_HCCPARAMS1 );
304  xhci->addr64 = XHCI_HCCPARAMS1_ADDR64 ( hccparams1 );
305  xhci->csz_shift = XHCI_HCCPARAMS1_CSZ_SHIFT ( hccparams1 );
306  xhci->xecp = XHCI_HCCPARAMS1_XECP ( hccparams1 );
307 
308  /* Read page size */
309  pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
310  xhci->pagesize = XHCI_PAGESIZE ( pagesize );
311  assert ( xhci->pagesize != 0 );
312  assert ( ( ( xhci->pagesize ) & ( xhci->pagesize - 1 ) ) == 0 );
313  DBGC2 ( xhci, "XHCI %s page size %zd bytes\n",
314  xhci->name, xhci->pagesize );
315 
316  /* Configure DMA device */
317  if ( xhci->dma && xhci->addr64 )
318  dma_set_mask_64bit ( xhci->dma );
319 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
unsigned int ports
Number of ports.
Definition: xhci.h:1092
void * run
Runtime registers.
Definition: xhci.h:1083
void * regs
Registers.
Definition: xhci.h:1068
#define XHCI_HCSPARAMS1_PORTS(params)
Number of ports.
Definition: xhci.h:48
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:1070
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:78
#define XHCI_HCSPARAMS1_INTRS(params)
Number of interrupters.
Definition: xhci.h:45
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
Definition: dma.h:466
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1054
unsigned int slots
Number of device slots.
Definition: xhci.h:1088
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1111
#define XHCI_CAP_RTSOFF
Runtime register space offset.
Definition: xhci.h:73
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const char * name
Name.
Definition: xhci.h:1074
#define XHCI_HCCPARAMS1_XECP(params)
xHCI extended capabilities pointer
Definition: xhci.h:67
#define XHCI_HCCPARAMS1_ADDR64(params)
64-bit addressing capability
Definition: xhci.h:61
#define XHCI_CAP_CAPLENGTH
Capability register length.
Definition: xhci.h:33
unsigned int intrs
Number of interrupters.
Definition: xhci.h:1090
#define XHCI_HCSPARAMS1_SLOTS(params)
Number of device slots.
Definition: xhci.h:42
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1079
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1099
#define XHCI_OP_PAGESIZE
Page size register.
Definition: xhci.h:169
int addr64
64-bit addressing capability
Definition: xhci.h:1095
#define XHCI_PAGESIZE(pagesize)
Page size.
Definition: xhci.h:172
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1102
#define XHCI_CAP_DBOFF
Doorbell offset.
Definition: xhci.h:70
#define XHCI_HCCPARAMS1_CSZ_SHIFT(params)
Context size shift.
Definition: xhci.h:64
#define XHCI_CAP_HCSPARAMS1
Structural parameters 1.
Definition: xhci.h:39
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
#define XHCI_CAP_HCCPARAMS1
Capability parameters.
Definition: xhci.h:58
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1097
void * db
Doorbell registers.
Definition: xhci.h:1085
#define XHCI_HCSPARAMS2_SCRATCHPADS(params)
Number of page-sized scratchpad buffers.
Definition: xhci.h:54
#define XHCI_CAP_HCSPARAMS2
Structural parameters 2.
Definition: xhci.h:51
void * op
Operational registers.
Definition: xhci.h:1081

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

331  {
332  uint32_t xecp;
333  unsigned int next;
334 
335  /* Locate the extended capability */
336  while ( 1 ) {
337 
338  /* Locate first or next capability as applicable */
339  if ( offset ) {
340  xecp = readl ( xhci->cap + offset );
341  next = XHCI_XECP_NEXT ( xecp );
342  } else {
343  next = xhci->xecp;
344  }
345  if ( ! next )
346  return 0;
347  offset += next;
348 
349  /* Check if this is the requested capability */
350  xecp = readl ( xhci->cap + offset );
351  if ( XHCI_XECP_ID ( xecp ) == id )
352  return offset;
353  }
354 }
#define XHCI_XECP_NEXT(xecp)
Next xHCI extended capability pointer.
Definition: xhci.h:79
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:76
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:1079
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1099
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 365 of file xhci.c.

365  {
366 
367  /* If this is a 32-bit build, then this can never fail
368  * (allowing the compiler to optimise out the error path).
369  */
370  if ( sizeof ( value ) <= sizeof ( uint32_t ) ) {
371  writel ( value, reg );
372  writel ( 0, ( reg + sizeof ( uint32_t ) ) );
373  return 0;
374  }
375 
376  /* If the device does not support 64-bit addresses and this
377  * address is outside the 32-bit address space, then fail.
378  */
379  if ( ( value & ~0xffffffffULL ) && ! xhci->addr64 ) {
380  DBGC ( xhci, "XHCI %s cannot access address %lx\n",
381  xhci->name, value );
382  return -ENOTSUP;
383  }
384 
385  /* If this is a 64-bit build, then writeq() is available */
386  writeq ( value, reg );
387  return 0;
388 }
static unsigned int unsigned int reg
Definition: myson.h:162
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
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:1074
unsigned int uint32_t
Definition: stdint.h:12
int addr64
64-bit addressing capability
Definition: xhci.h:1095
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 399 of file xhci.c.

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

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

419  {
420 
421  return ( XHCI_DCI ( ctx ) << xhci->csz_shift );
422 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
#define XHCI_DCI(ctx)
Device context index.
Definition: xhci.h:956
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1097

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

431  {
432 
433  return ( XHCI_ICI ( ctx ) << xhci->csz_shift );
434 }
#define XHCI_ICI(ctx)
Input context index.
Definition: xhci.h:959
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1097

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

448  {
449  uint32_t usbcmd;
450  uint32_t usbsts;
451  uint32_t pagesize;
452  uint32_t dnctrl;
453  uint32_t config;
454 
455  /* Do nothing unless debugging is enabled */
456  if ( ! DBG_LOG )
457  return;
458 
459  /* Dump USBCMD */
460  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
461  DBGC ( xhci, "XHCI %s USBCMD %08x%s%s\n", xhci->name, usbcmd,
462  ( ( usbcmd & XHCI_USBCMD_RUN ) ? " run" : "" ),
463  ( ( usbcmd & XHCI_USBCMD_HCRST ) ? " hcrst" : "" ) );
464 
465  /* Dump USBSTS */
466  usbsts = readl ( xhci->op + XHCI_OP_USBSTS );
467  DBGC ( xhci, "XHCI %s USBSTS %08x%s\n", xhci->name, usbsts,
468  ( ( usbsts & XHCI_USBSTS_HCH ) ? " hch" : "" ) );
469 
470  /* Dump PAGESIZE */
471  pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
472  DBGC ( xhci, "XHCI %s PAGESIZE %08x\n", xhci->name, pagesize );
473 
474  /* Dump DNCTRL */
475  dnctrl = readl ( xhci->op + XHCI_OP_DNCTRL );
476  DBGC ( xhci, "XHCI %s DNCTRL %08x\n", xhci->name, dnctrl );
477 
478  /* Dump CONFIG */
479  config = readl ( xhci->op + XHCI_OP_CONFIG );
480  DBGC ( xhci, "XHCI %s CONFIG %08x\n", xhci->name, config );
481 }
#define XHCI_OP_USBSTS
USB status register.
Definition: xhci.h:163
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:1074
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_PAGESIZE
Page size register.
Definition: xhci.h:169
#define XHCI_USBCMD_HCRST
Host controller reset.
Definition: xhci.h:160
#define XHCI_OP_CONFIG
Configure register.
Definition: xhci.h:193
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:157
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:154
#define XHCI_USBSTS_HCH
Host controller halted.
Definition: xhci.h:166
#define DBG_LOG
Definition: compiler.h:317
#define XHCI_OP_DNCTRL
Device notifcation control register.
Definition: xhci.h:175
void * op
Operational registers.
Definition: xhci.h:1081

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

490  {
491  uint32_t portsc;
492  uint32_t portpmsc;
493  uint32_t portli;
494  uint32_t porthlpmc;
495 
496  /* Do nothing unless debugging is enabled */
497  if ( ! DBG_LOG )
498  return;
499 
500  /* Dump PORTSC */
501  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port ) );
502  DBGC ( xhci, "XHCI %s-%d PORTSC %08x%s%s%s%s psiv=%d\n",
503  xhci->name, port, portsc,
504  ( ( portsc & XHCI_PORTSC_CCS ) ? " ccs" : "" ),
505  ( ( portsc & XHCI_PORTSC_PED ) ? " ped" : "" ),
506  ( ( portsc & XHCI_PORTSC_PR ) ? " pr" : "" ),
507  ( ( portsc & XHCI_PORTSC_PP ) ? " pp" : "" ),
508  XHCI_PORTSC_PSIV ( portsc ) );
509 
510  /* Dump PORTPMSC */
511  portpmsc = readl ( xhci->op + XHCI_OP_PORTPMSC ( port ) );
512  DBGC ( xhci, "XHCI %s-%d PORTPMSC %08x\n", xhci->name, port, portpmsc );
513 
514  /* Dump PORTLI */
515  portli = readl ( xhci->op + XHCI_OP_PORTLI ( port ) );
516  DBGC ( xhci, "XHCI %s-%d PORTLI %08x\n", xhci->name, port, portli );
517 
518  /* Dump PORTHLPMC */
519  porthlpmc = readl ( xhci->op + XHCI_OP_PORTHLPMC ( port ) );
520  DBGC ( xhci, "XHCI %s-%d PORTHLPMC %08x\n",
521  xhci->name, port, porthlpmc );
522 }
#define XHCI_PORTSC_PSIV(portsc)
Port speed ID value.
Definition: xhci.h:233
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:292
#define XHCI_OP_PORTLI(port)
Port link info register.
Definition: xhci.h:289
#define XHCI_PORTSC_PP
Port power.
Definition: xhci.h:227
#define XHCI_PORTSC_CCS
Current connect status.
Definition: xhci.h:206
u8 port
Port number.
Definition: CIB_PRM.h:31
const char * name
Name.
Definition: xhci.h:1074
#define XHCI_OP_PORTPMSC(port)
Port power management status and control register.
Definition: xhci.h:286
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:203
#define XHCI_PORTSC_PR
Port reset.
Definition: xhci.h:212
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:209
#define DBG_LOG
Definition: compiler.h:317
void * op
Operational registers.
Definition: xhci.h:1081

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

539  {
540  unsigned int legacy;
541  uint8_t bios;
542 
543  /* Locate USB legacy support capability (if present) */
544  legacy = xhci_extended_capability ( xhci, XHCI_XECP_ID_LEGACY, 0 );
545  if ( ! legacy ) {
546  /* Not an error; capability may not be present */
547  DBGC ( xhci, "XHCI %s has no USB legacy support capability\n",
548  xhci->name );
549  return;
550  }
551 
552  /* Check if legacy USB support is enabled */
553  bios = readb ( xhci->cap + legacy + XHCI_USBLEGSUP_BIOS );
554  if ( ! ( bios & XHCI_USBLEGSUP_BIOS_OWNED ) ) {
555  /* Not an error; already owned by OS */
556  DBGC ( xhci, "XHCI %s USB legacy support already disabled\n",
557  xhci->name );
558  return;
559  }
560 
561  /* Record presence of USB legacy support capability */
562  xhci->legacy = legacy;
563 }
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:88
static unsigned int xhci_extended_capability(struct xhci_device *xhci, unsigned int id, unsigned int offset)
Find extended capability.
Definition: xhci.c:329
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: xhci.h:1074
#define XHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition: xhci.h:85
unsigned char uint8_t
Definition: stdint.h:10
void * cap
Capability registers.
Definition: xhci.h:1079
#define XHCI_XECP_ID_LEGACY
USB legacy support extended capability.
Definition: xhci.h:82
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: xhci.h:1105

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

570  {
571  uint32_t ctlsts;
572  uint8_t bios;
573  unsigned int i;
574 
575  /* Do nothing unless legacy support capability is present */
576  if ( ! xhci->legacy )
577  return;
578 
579  /* Claim ownership */
581  xhci->cap + xhci->legacy + XHCI_USBLEGSUP_OS );
582 
583  /* Wait for BIOS to release ownership */
584  for ( i = 0 ; i < XHCI_USBLEGSUP_MAX_WAIT_MS ; i++ ) {
585 
586  /* Check if BIOS has released ownership */
587  bios = readb ( xhci->cap + xhci->legacy + XHCI_USBLEGSUP_BIOS );
588  if ( ! ( bios & XHCI_USBLEGSUP_BIOS_OWNED ) ) {
589  DBGC ( xhci, "XHCI %s claimed ownership from BIOS\n",
590  xhci->name );
591  ctlsts = readl ( xhci->cap + xhci->legacy +
593  if ( ctlsts ) {
594  DBGC ( xhci, "XHCI %s warning: BIOS retained "
595  "SMIs: %08x\n", xhci->name, ctlsts );
596  }
597  return;
598  }
599 
600  /* Delay */
601  mdelay ( 1 );
602  }
603 
604  /* BIOS did not release ownership. Claim it forcibly by
605  * disabling all SMIs.
606  */
607  DBGC ( xhci, "XHCI %s could not claim ownership from BIOS: forcibly "
608  "disabling SMIs\n", xhci->name );
609  writel ( 0, xhci->cap + xhci->legacy + XHCI_USBLEGSUP_CTLSTS );
610 }
#define XHCI_USBLEGSUP_MAX_WAIT_MS
Maximum time to wait for BIOS to release ownership.
Definition: xhci.h:983
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:88
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:91
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:97
const char * name
Name.
Definition: xhci.h:1074
#define XHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition: xhci.h:85
#define XHCI_USBLEGSUP_OS_OWNED
USB legacy support OS ownership flag.
Definition: xhci.h:94
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1079
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: xhci.h:1105

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

617  {
618 
619  /* Do nothing unless legacy support capability is present */
620  if ( ! xhci->legacy )
621  return;
622 
623  /* Do nothing if releasing ownership is prevented */
625  DBGC ( xhci, "XHCI %s not releasing ownership to BIOS\n",
626  xhci->name );
627  return;
628  }
629 
630  /* Release ownership */
631  writeb ( 0, xhci->cap + xhci->legacy + XHCI_USBLEGSUP_OS );
632  DBGC ( xhci, "XHCI %s released ownership to BIOS\n", xhci->name );
633 }
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_USBLEGSUP_OS
USB legacy support OS owned semaphore.
Definition: xhci.h:91
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1074
void * cap
Capability registers.
Definition: xhci.h:1079
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: xhci.h:1105
static int xhci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
Definition: xhci.c:532

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

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

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

672  {
673  unsigned int supported = 0;
674  unsigned int offset;
675  unsigned int count;
676  uint32_t ports;
677 
678  /* Iterate over all supported protocol structures */
679  while ( ( supported = xhci_extended_capability ( xhci,
681  supported ) ) ) {
682 
683  /* Determine port range */
684  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
686  count = XHCI_SUPPORTED_PORTS_COUNT ( ports );
687 
688  /* Check if port lies within this range */
689  if ( ( port - offset ) < count )
690  return supported;
691  }
692 
693  DBGC ( xhci, "XHCI %s-%d has no supported protocol\n",
694  xhci->name, port );
695  return 0;
696 }
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:112
static unsigned int xhci_extended_capability(struct xhci_device *xhci, unsigned int id, unsigned int offset)
Find extended capability.
Definition: xhci.c:329
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:100
#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:1074
#define XHCI_SUPPORTED_PORTS_COUNT(ports)
Supported protocol port count.
Definition: xhci.h:118
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1079
#define XHCI_SUPPORTED_PORTS_OFFSET(ports)
Supported protocol port offset.
Definition: xhci.h:115
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 705 of file xhci.c.

706  {
707  unsigned int supported = xhci_supported_protocol ( xhci, port );
708  union {
709  uint32_t raw;
710  char text[5];
711  } name;
712  unsigned int protocol;
713  unsigned int type;
714  unsigned int psic;
715  unsigned int psiv;
716  unsigned int i;
718  uint32_t ports;
719  uint32_t slot;
720  uint32_t psi;
721 
722  /* Fail if there is no supported protocol */
723  if ( ! supported )
724  return 0;
725 
726  /* Determine protocol version */
729 
730  /* Describe port protocol */
731  if ( DBG_EXTRA ) {
732  name.raw = cpu_to_le32 ( readl ( xhci->cap + supported +
734  name.text[4] = '\0';
735  slot = readl ( xhci->cap + supported + XHCI_SUPPORTED_SLOT );
737  DBGC2 ( xhci, "XHCI %s-%d %sv%04x type %d",
738  xhci->name, port, name.text, protocol, type );
739  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
740  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
741  if ( psic ) {
742  DBGC2 ( xhci, " speeds" );
743  for ( i = 0 ; i < psic ; i++ ) {
744  psi = readl ( xhci->cap + supported +
745  XHCI_SUPPORTED_PSI ( i ) );
746  psiv = XHCI_SUPPORTED_PSI_VALUE ( psi );
747  DBGC2 ( xhci, " %d:%s", psiv,
748  xhci_speed_name ( psi ) );
749  }
750  }
751  if ( xhci->quirks & XHCI_BAD_PSIV )
752  DBGC2 ( xhci, " (ignored)" );
753  DBGC2 ( xhci, "\n" );
754  }
755 
756  return protocol;
757 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1041
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:112
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition: xhci.h:127
const char * name
Definition: ath9k_hw.c:1984
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition: xhci.h:124
uint32_t type
Operating system type.
Definition: ena.h:12
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:133
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:648
u8 port
Port number.
Definition: CIB_PRM.h:31
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
Definition: xhci.h:121
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint32_t revision
Entry point revision.
Definition: ib_mad.h:20
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:130
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1079
#define XHCI_SUPPORTED_REVISION
Supported protocol revision.
Definition: xhci.h:103
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:671
#define DBGC2(...)
Definition: compiler.h:522
__be32 raw[7]
Definition: CIB_PRM.h:28
uint16_t protocol
Protocol ID.
Definition: stp.h:18
#define DBG_EXTRA
Definition: compiler.h:319
#define XHCI_SUPPORTED_REVISION_VER(revision)
Supported protocol minor revision.
Definition: xhci.h:106
uint16_t supported
Bitmask of supported option values.
Definition: ena.h:12
unsigned int quirks
Quirks.
Definition: xhci.h:1076
#define XHCI_SUPPORTED_NAME
Supported protocol name.
Definition: xhci.h:109

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

766  {
767  unsigned int supported = xhci_supported_protocol ( xhci, port );
768  unsigned int type;
769  uint32_t slot;
770 
771  /* Fail if there is no supported protocol */
772  if ( ! supported )
773  return -ENOTSUP;
774 
775  /* Get slot type */
776  slot = readl ( xhci->cap + supported + XHCI_SUPPORTED_SLOT );
778 
779  return type;
780 }
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition: xhci.h:127
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition: xhci.h:124
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:589
u8 port
Port number.
Definition: CIB_PRM.h:31
uint8_t slot
Slot.
Definition: edd.h:16
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1079
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:671
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 790 of file xhci.c.

791  {
792  unsigned int supported = xhci_supported_protocol ( xhci, port );
793  unsigned int psic;
794  unsigned int mantissa;
795  unsigned int exponent;
796  unsigned int speed;
797  unsigned int i;
798  uint32_t ports;
799  uint32_t psi;
800 
801  /* Fail if there is no supported protocol */
802  if ( ! supported )
803  return -ENOTSUP;
804 
805  /* Get protocol speed ID count */
806  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
807  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
808 
809  /* Use protocol speed ID table unless device is known to be faulty */
810  if ( ! ( xhci->quirks & XHCI_BAD_PSIV ) ) {
811 
812  /* Iterate over PSI dwords looking for a match */
813  for ( i = 0 ; i < psic ; i++ ) {
814  psi = readl ( xhci->cap + supported +
815  XHCI_SUPPORTED_PSI ( i ) );
816  if ( psiv == XHCI_SUPPORTED_PSI_VALUE ( psi ) ) {
817  mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
818  exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
819  speed = USB_SPEED ( mantissa, exponent );
820  return speed;
821  }
822  }
823 
824  /* Record device as faulty if no match is found */
825  if ( psic != 0 ) {
826  DBGC ( xhci, "XHCI %s-%d spurious PSI value %d: "
827  "assuming PSI table is invalid\n",
828  xhci->name, port, psiv );
829  xhci->quirks |= XHCI_BAD_PSIV;
830  }
831  }
832 
833  /* Use the default mappings */
834  switch ( psiv ) {
835  case XHCI_SPEED_LOW : return USB_SPEED_LOW;
836  case XHCI_SPEED_FULL : return USB_SPEED_FULL;
837  case XHCI_SPEED_HIGH : return USB_SPEED_HIGH;
838  case XHCI_SPEED_SUPER : return USB_SPEED_SUPER;
839  default:
840  DBGC ( xhci, "XHCI %s-%d unrecognised PSI value %d\n",
841  xhci->name, port, psiv );
842  return -ENOTSUP;
843  }
844 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1041
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:112
Low speed (1.5Mbps)
Definition: usb.h:48
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:133
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:144
Super speed (5Gbps)
Definition: usb.h:54
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
u8 port
Port number.
Definition: CIB_PRM.h:31
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
Definition: usb.h:35
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
Definition: xhci.h:121
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:130
const char * name
Name.
Definition: xhci.h:1074
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1079
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:671
High speed (480Mbps)
Definition: usb.h:52
Super speed.
Definition: xhci.h:150
Low speed (1.5Mbps)
Definition: xhci.h:146
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)
Supported protocol PSI mantissa.
Definition: xhci.h:136
uint16_t supported
Bitmask of supported option values.
Definition: ena.h:12
High speed (480Mbps)
Definition: xhci.h:148
unsigned int quirks
Quirks.
Definition: xhci.h:1076
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
Definition: xhci.h:139
Full speed (12Mbps)
Definition: usb.h:50

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

855  {
856  unsigned int supported = xhci_supported_protocol ( xhci, port );
857  unsigned int psic;
858  unsigned int mantissa;
859  unsigned int exponent;
860  unsigned int psiv;
861  unsigned int i;
862  uint32_t ports;
863  uint32_t psi;
864 
865  /* Fail if there is no supported protocol */
866  if ( ! supported )
867  return -ENOTSUP;
868 
869  /* Get protocol speed ID count */
870  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
871  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
872 
873  /* Use the default mappings if applicable */
874  if ( ( psic == 0 ) || ( xhci->quirks & XHCI_BAD_PSIV ) ) {
875  switch ( speed ) {
876  case USB_SPEED_LOW : return XHCI_SPEED_LOW;
877  case USB_SPEED_FULL : return XHCI_SPEED_FULL;
878  case USB_SPEED_HIGH : return XHCI_SPEED_HIGH;
879  case USB_SPEED_SUPER : return XHCI_SPEED_SUPER;
880  default:
881  DBGC ( xhci, "XHCI %s-%d non-standard speed %d\n",
882  xhci->name, port, speed );
883  return -ENOTSUP;
884  }
885  }
886 
887  /* Iterate over PSI dwords looking for a match */
888  for ( i = 0 ; i < psic ; i++ ) {
889  psi = readl ( xhci->cap + supported + XHCI_SUPPORTED_PSI ( i ));
890  mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
891  exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
892  if ( speed == USB_SPEED ( mantissa, exponent ) ) {
893  psiv = XHCI_SUPPORTED_PSI_VALUE ( psi );
894  return psiv;
895  }
896  }
897 
898  DBGC ( xhci, "XHCI %s-%d unrepresentable speed %#x\n",
899  xhci->name, port, speed );
900  return -ENOENT;
901 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1041
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:112
Low speed (1.5Mbps)
Definition: usb.h:48
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:133
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:514
Full speed (12Mbps)
Definition: xhci.h:144
Super speed (5Gbps)
Definition: usb.h:54
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
u8 port
Port number.
Definition: CIB_PRM.h:31
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
Definition: usb.h:35
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
Definition: xhci.h:121
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:130
const char * name
Name.
Definition: xhci.h:1074
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1079
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:671
High speed (480Mbps)
Definition: usb.h:52
Super speed.
Definition: xhci.h:150
Low speed (1.5Mbps)
Definition: xhci.h:146
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)
Supported protocol PSI mantissa.
Definition: xhci.h:136
uint16_t supported
Bitmask of supported option values.
Definition: ena.h:12
High speed (480Mbps)
Definition: xhci.h:148
unsigned int quirks
Quirks.
Definition: xhci.h:1076
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
Definition: xhci.h:139
Full speed (12Mbps)
Definition: usb.h:50

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

916  {
917  size_t len;
918  physaddr_t dcbaap;
919  int rc;
920 
921  /* Allocate and initialise structure. Must be at least
922  * 64-byte aligned and must not cross a page boundary, so
923  * align on its own size (rounded up to a power of two and
924  * with a minimum of 64 bytes).
925  */
926  len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
927  xhci->dcbaa.context = dma_alloc ( xhci->dma, &xhci->dcbaa.map, len,
928  xhci_align ( len ) );
929  if ( ! xhci->dcbaa.context ) {
930  DBGC ( xhci, "XHCI %s could not allocate DCBAA\n", xhci->name );
931  rc = -ENOMEM;
932  goto err_alloc;
933  }
934  memset ( xhci->dcbaa.context, 0, len );
935 
936  /* Program DCBAA pointer */
937  dcbaap = dma ( &xhci->dcbaa.map, xhci->dcbaa.context );
938  if ( ( rc = xhci_writeq ( xhci, dcbaap,
939  xhci->op + XHCI_OP_DCBAAP ) ) != 0 )
940  goto err_writeq;
941 
942  DBGC2 ( xhci, "XHCI %s DCBAA at [%08lx,%08lx)\n", xhci->name,
943  virt_to_phys ( xhci->dcbaa.context ),
944  ( virt_to_phys ( xhci->dcbaa.context ) + len ) );
945  return 0;
946 
947  err_writeq:
948  dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
949  err_alloc:
950  return rc;
951 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1108
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:399
#define DBGC(...)
Definition: compiler.h:505
unsigned int slots
Number of device slots.
Definition: xhci.h:1088
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:534
ring len
Length.
Definition: dwmac.h:231
#define XHCI_OP_DCBAAP
Device context base address array pointer.
Definition: xhci.h:190
const char * name
Name.
Definition: xhci.h:1074
uint64_t * context
Context base addresses.
Definition: xhci.h:1046
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:365
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:1048
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
void * op
Operational registers.
Definition: xhci.h:1081
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 958 of file xhci.c.

958  {
959  size_t len;
960  unsigned int i;
961 
962  /* Sanity check */
963  for ( i = 0 ; i <= xhci->slots ; i++ )
964  assert ( xhci->dcbaa.context[i] == 0 );
965 
966  /* Clear DCBAA pointer */
967  xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_DCBAAP );
968 
969  /* Free DCBAA */
970  len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
971  dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
972 }
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1108
unsigned int slots
Number of device slots.
Definition: xhci.h:1088
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:190
uint64_t * context
Context base addresses.
Definition: xhci.h:1046
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:365
struct dma_mapping map
DMA mapping.
Definition: xhci.h:1048
void * op
Operational registers.
Definition: xhci.h:1081

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

987  {
988  struct xhci_scratchpad *scratch = &xhci->scratch;
989  size_t buffer_len;
990  size_t array_len;
992  unsigned int i;
993  int rc;
994 
995  /* Do nothing if no scratchpad buffers are used */
996  if ( ! scratch->count )
997  return 0;
998 
999  /* Allocate scratchpad buffers */
1000  buffer_len = ( scratch->count * xhci->pagesize );
1001  scratch->buffer = dma_umalloc ( xhci->dma, &scratch->buffer_map,
1002  buffer_len, xhci->pagesize );
1003  if ( ! scratch->buffer ) {
1004  DBGC ( xhci, "XHCI %s could not allocate scratchpad buffers\n",
1005  xhci->name );
1006  rc = -ENOMEM;
1007  goto err_alloc;
1008  }
1009  memset ( scratch->buffer, 0, buffer_len );
1010 
1011  /* Allocate scratchpad array */
1012  array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
1013  scratch->array = dma_alloc ( xhci->dma, &scratch->array_map,
1014  array_len, xhci_align ( array_len ) );
1015  if ( ! scratch->array ) {
1016  DBGC ( xhci, "XHCI %s could not allocate scratchpad buffer "
1017  "array\n", xhci->name );
1018  rc = -ENOMEM;
1019  goto err_alloc_array;
1020  }
1021 
1022  /* Populate scratchpad array */
1023  addr = dma ( &scratch->buffer_map, scratch->buffer );
1024  for ( i = 0 ; i < scratch->count ; i++ ) {
1025  scratch->array[i] = cpu_to_le64 ( addr );
1026  addr += xhci->pagesize;
1027  }
1028 
1029  /* Set scratchpad array pointer */
1030  assert ( xhci->dcbaa.context != NULL );
1031  xhci->dcbaa.context[0] = cpu_to_le64 ( dma ( &scratch->array_map,
1032  scratch->array ) );
1033 
1034  DBGC2 ( xhci, "XHCI %s scratchpad [%08lx,%08lx) array [%08lx,%08lx)\n",
1035  xhci->name, virt_to_phys ( scratch->buffer ),
1036  ( virt_to_phys ( scratch->buffer ) + buffer_len ),
1037  virt_to_phys ( scratch->array ),
1038  ( virt_to_phys ( scratch->array ) + array_len ) );
1039  return 0;
1040 
1041  dma_free ( &scratch->array_map, scratch->array, array_len );
1042  err_alloc_array:
1043  dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
1044  err_alloc:
1045  return rc;
1046 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * buffer
Scratchpad buffer area.
Definition: xhci.h:1056
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1108
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:399
#define DBGC(...)
Definition: compiler.h:505
struct dma_mapping buffer_map
Buffer DMA mapping.
Definition: xhci.h:1058
#define cpu_to_le64(value)
Definition: byteswap.h:108
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1054
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1111
uint64_t * array
Scratchpad array.
Definition: xhci.h:1060
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:534
struct dma_mapping array_map
Array DMA mapping.
Definition: xhci.h:1062
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:1074
uint32_t addr
Buffer address.
Definition: dwmac.h:20
uint64_t * context
Context base addresses.
Definition: xhci.h:1046
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:1052
unsigned long physaddr_t
Definition: stdint.h:20
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1102
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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 1053 of file xhci.c.

1053  {
1054  struct xhci_scratchpad *scratch = &xhci->scratch;
1055  size_t array_len;
1056  size_t buffer_len;
1057 
1058  /* Do nothing if no scratchpad buffers are used */
1059  if ( ! scratch->count )
1060  return;
1061 
1062  /* Clear scratchpad array pointer */
1063  assert ( xhci->dcbaa.context != NULL );
1064  xhci->dcbaa.context[0] = 0;
1065 
1066  /* Free scratchpad array */
1067  array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
1068  dma_free ( &scratch->array_map, scratch->array, array_len );
1069 
1070  /* Free scratchpad buffers */
1071  buffer_len = ( scratch->count * xhci->pagesize );
1072  dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
1073 }
void * buffer
Scratchpad buffer area.
Definition: xhci.h:1056
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1108
struct dma_mapping buffer_map
Buffer DMA mapping.
Definition: xhci.h:1058
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1054
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1111
uint64_t * array
Scratchpad array.
Definition: xhci.h:1060
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:1062
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint64_t * context
Context base addresses.
Definition: xhci.h:1046
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:1052
size_t pagesize
Page size.
Definition: xhci.h:1102
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

1087  {
1088  uint32_t config;
1089  uint32_t usbcmd;
1090 
1091  /* Configure number of device slots */
1092  config = readl ( xhci->op + XHCI_OP_CONFIG );
1093  config &= ~XHCI_CONFIG_MAX_SLOTS_EN_MASK;
1094  config |= XHCI_CONFIG_MAX_SLOTS_EN ( xhci->slots );
1095  writel ( config, xhci->op + XHCI_OP_CONFIG );
1096 
1097  /* Set run/stop bit */
1098  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1099  usbcmd |= XHCI_USBCMD_RUN;
1100  writel ( usbcmd, xhci->op + XHCI_OP_USBCMD );
1101 }
#define XHCI_CONFIG_MAX_SLOTS_EN(slots)
Maximum device slots enabled.
Definition: xhci.h:196
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:1088
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:193
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:157
#define XHCI_CONFIG_MAX_SLOTS_EN_MASK
Maximum device slots enabled mask.
Definition: xhci.h:199
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:154
void * op
Operational registers.
Definition: xhci.h:1081

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

1109  {
1110  uint32_t usbcmd;
1111  uint32_t usbsts;
1112  unsigned int i;
1113 
1114  /* Clear run/stop bit */
1115  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1116  usbcmd &= ~XHCI_USBCMD_RUN;
1117  writel ( usbcmd, xhci->op + XHCI_OP_USBCMD );
1118 
1119  /* Wait for device to stop */
1120  for ( i = 0 ; i < XHCI_STOP_MAX_WAIT_MS ; i++ ) {
1121 
1122  /* Check if device is stopped */
1123  usbsts = readl ( xhci->op + XHCI_OP_USBSTS );
1124  if ( usbsts & XHCI_USBSTS_HCH )
1125  return 0;
1126 
1127  /* Delay */
1128  mdelay ( 1 );
1129  }
1130 
1131  DBGC ( xhci, "XHCI %s timed out waiting for stop\n", xhci->name );
1132  return -ETIMEDOUT;
1133 }
#define XHCI_OP_USBSTS
USB status register.
Definition: xhci.h:163
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:1074
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define XHCI_STOP_MAX_WAIT_MS
Maximum time to wait for host controller to stop.
Definition: xhci.h:989
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:157
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:154
#define XHCI_USBSTS_HCH
Host controller halted.
Definition: xhci.h:166
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * op
Operational registers.
Definition: xhci.h:1081

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

1141  {
1142  uint32_t usbcmd;
1143  unsigned int i;
1144  int rc;
1145 
1146  /* The xHCI specification states that resetting a running
1147  * device may result in undefined behaviour, so try stopping
1148  * it first.
1149  */
1150  if ( ( rc = xhci_stop ( xhci ) ) != 0 ) {
1151  /* Ignore errors and attempt to reset the device anyway */
1152  }
1153 
1154  /* Reset device */
1156 
1157  /* Wait for reset to complete */
1158  for ( i = 0 ; i < XHCI_RESET_MAX_WAIT_MS ; i++ ) {
1159 
1160  /* Check if reset is complete */
1161  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1162  if ( ! ( usbcmd & XHCI_USBCMD_HCRST ) )
1163  return 0;
1164 
1165  /* Delay */
1166  mdelay ( 1 );
1167  }
1168 
1169  DBGC ( xhci, "XHCI %s timed out waiting for reset\n", xhci->name );
1170  return -ETIMEDOUT;
1171 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition: xhci.c:1109
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:995
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:1074
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_USBCMD_HCRST
Host controller reset.
Definition: xhci.h:160
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:154
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * op
Operational registers.
Definition: xhci.h:1081

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

1179  {
1180  size_t len;
1181  int rc;
1182 
1183  /* Mark command mechanism as permanently failed */
1184  xhci->failed = 1;
1185 
1186  /* Reset device */
1187  if ( ( rc = xhci_reset ( xhci ) ) != 0 )
1188  return rc;
1189 
1190  /* Discard DCBAA entries since DCBAAP has been cleared */
1191  assert ( xhci->dcbaa.context != NULL );
1192  len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
1193  memset ( xhci->dcbaa.context, 0, len );
1194 
1195  return 0;
1196 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1108
unsigned int slots
Number of device slots.
Definition: xhci.h:1088
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:1120
uint64_t * context
Context base addresses.
Definition: xhci.h:1046
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1141
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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 1216 of file xhci.c.

1219  {
1220  struct xhci_trb_link *link;
1221  unsigned int count;
1222  int rc;
1223 
1224  /* Sanity check */
1225  assert ( shift > 0 );
1226 
1227  /* Initialise structure */
1228  memset ( ring, 0, sizeof ( *ring ) );
1229  ring->shift = shift;
1230  count = ( 1U << shift );
1231  ring->mask = ( count - 1 );
1232  ring->len = ( ( count + 1 /* Link TRB */ ) * sizeof ( ring->trb[0] ) );
1233  ring->db = ( xhci->db + ( slot * sizeof ( ring->dbval ) ) );
1234  ring->dbval = XHCI_DBVAL ( target, stream );
1235 
1236  /* Allocate I/O buffers */
1237  ring->iobuf = zalloc ( count * sizeof ( ring->iobuf[0] ) );
1238  if ( ! ring->iobuf ) {
1239  rc = -ENOMEM;
1240  goto err_alloc_iobuf;
1241  }
1242 
1243  /* Allocate TRBs */
1244  ring->trb = dma_alloc ( xhci->dma, &ring->map, ring->len,
1245  xhci_align ( ring->len ) );
1246  if ( ! ring->trb ) {
1247  rc = -ENOMEM;
1248  goto err_alloc_trb;
1249  }
1250  memset ( ring->trb, 0, ring->len );
1251 
1252  /* Initialise Link TRB */
1253  link = &ring->trb[count].link;
1254  link->next = cpu_to_le64 ( dma ( &ring->map, ring->trb ) );
1255  link->flags = XHCI_TRB_TC;
1256  link->type = XHCI_TRB_LINK;
1257  ring->link = link;
1258 
1259  return 0;
1260 
1261  dma_free ( &ring->map, ring->trb, ring->len );
1262  err_alloc_trb:
1263  free ( ring->iobuf );
1264  err_alloc_iobuf:
1265  return rc;
1266 }
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
Definition: xhci.h:331
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t dbval
Doorbell register value.
Definition: xhci.h:864
size_t len
Length of transfer request blocks.
Definition: xhci.h:855
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:399
struct dma_mapping map
DMA mapping.
Definition: xhci.h:857
#define cpu_to_le64(value)
Definition: byteswap.h:108
void * db
Doorbell register.
Definition: xhci.h:862
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:534
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
uint8_t slot
Slot.
Definition: edd.h:16
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:888
unsigned int mask
Ring counter mask.
Definition: xhci.h:847
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:850
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
struct xhci_trb_link * link
Link TRB (if applicable)
Definition: xhci.h:859
unsigned int shift
Ring size (log2)
Definition: xhci.h:845
void * db
Doorbell registers.
Definition: xhci.h:1085
#define XHCI_TRB_LINK
A link transfer request block.
Definition: xhci.h:459
struct xhci_trb_link link
Link TRB.
Definition: xhci.h:696
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 1273 of file xhci.c.

1273  {
1274  unsigned int count = ( 1U << ring->shift );
1275 
1276  /* Reset producer and consumer counters */
1277  ring->prod = 0;
1278  ring->cons = 0;
1279 
1280  /* Reset TRBs (except Link TRB) */
1281  memset ( ring->trb, 0, ( count * sizeof ( ring->trb[0] ) ) );
1282 }
unsigned int cons
Consumer counter.
Definition: xhci.h:843
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
static unsigned int count
Number of entries.
Definition: dwmac.h:225
unsigned int prod
Producer counter.
Definition: xhci.h:841
unsigned int shift
Ring size (log2)
Definition: xhci.h:845
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 1289 of file xhci.c.

1289  {
1290  unsigned int count = ( 1U << ring->shift );
1291  unsigned int i;
1292 
1293  /* Sanity checks */
1294  assert ( ring->cons == ring->prod );
1295  for ( i = 0 ; i < count ; i++ )
1296  assert ( ring->iobuf[i] == NULL );
1297 
1298  /* Free TRBs */
1299  dma_free ( &ring->map, ring->trb, ring->len );
1300 
1301  /* Free I/O buffers */
1302  free ( ring->iobuf );
1303 }
unsigned int cons
Consumer counter.
Definition: xhci.h:843
size_t len
Length of transfer request blocks.
Definition: xhci.h:855
struct dma_mapping map
DMA mapping.
Definition: xhci.h:857
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:853
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:54
unsigned int prod
Producer counter.
Definition: xhci.h:841
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:850
unsigned int shift
Ring size (log2)
Definition: xhci.h:845
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

1316  {
1317  union xhci_trb *dest;
1318  unsigned int prod;
1319  unsigned int mask;
1320  unsigned int index;
1321  unsigned int cycle;
1322 
1323  /* Sanity check */
1324  assert ( ! ( trb->common.flags & XHCI_TRB_C ) );
1325 
1326  /* Fail if ring is full */
1327  if ( ! xhci_ring_remaining ( ring ) )
1328  return -ENOBUFS;
1329 
1330  /* Update producer counter (and link TRB, if applicable) */
1331  prod = ring->prod++;
1332  mask = ring->mask;
1333  cycle = ( ( ~( prod >> ring->shift ) ) & XHCI_TRB_C );
1334  index = ( prod & mask );
1335  if ( index == 0 )
1336  ring->link->flags = ( XHCI_TRB_TC | ( cycle ^ XHCI_TRB_C ) );
1337 
1338  /* Record I/O buffer */
1339  ring->iobuf[index] = iobuf;
1340 
1341  /* Enqueue TRB */
1342  dest = &ring->trb[index];
1343  dest->template.parameter = trb->template.parameter;
1344  dest->template.status = trb->template.status;
1345  wmb();
1346  dest->template.control = ( trb->template.control |
1347  cpu_to_le32 ( cycle ) );
1348 
1349  return 0;
1350 }
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
Definition: xhci.h:331
wmb()
struct xhci_trb_common common
Common fields.
Definition: xhci.h:686
long index
Definition: bigint.h:62
uint8_t flags
Flags.
Definition: xhci.h:320
static unsigned int xhci_ring_remaining(struct xhci_trb_ring *ring)
Calculate space remaining in TRB ring.
Definition: xhci.h:912
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct xhci_trb_template template
Template.
Definition: xhci.h:684
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint32_t status
Status.
Definition: xhci.h:308
A transfer request block.
Definition: xhci.h:682
unsigned int prod
Producer counter.
Definition: xhci.h:841
uint32_t control
Control.
Definition: xhci.h:310
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
unsigned int mask
Ring counter mask.
Definition: xhci.h:847
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:850
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:150
struct xhci_trb_link * link
Link TRB (if applicable)
Definition: xhci.h:859
unsigned int shift
Ring size (log2)
Definition: xhci.h:845
#define XHCI_TRB_C
Transfer request block cycle bit flag.
Definition: xhci.h:328
uint64_t parameter
Parameter.
Definition: xhci.h:306

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

1358  {
1359  struct io_buffer *iobuf;
1360  unsigned int cons;
1361  unsigned int mask;
1362  unsigned int index;
1363 
1364  /* Sanity check */
1365  assert ( xhci_ring_fill ( ring ) != 0 );
1366 
1367  /* Update consumer counter */
1368  cons = ring->cons++;
1369  mask = ring->mask;
1370  index = ( cons & mask );
1371 
1372  /* Retrieve I/O buffer */
1373  iobuf = ring->iobuf[index];
1374  ring->iobuf[index] = NULL;
1375 
1376  return iobuf;
1377 }
unsigned int cons
Consumer counter.
Definition: xhci.h:843
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition: xhci.h:897
long index
Definition: bigint.h:62
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:847
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:850
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:37

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

1393  {
1394  const union xhci_trb *trb = trbs;
1395  int rc;
1396 
1397  /* Sanity check */
1398  assert ( iobuf != NULL );
1399 
1400  /* Fail if ring does not have sufficient space */
1401  if ( xhci_ring_remaining ( ring ) < count )
1402  return -ENOBUFS;
1403 
1404  /* Enqueue each TRB, recording the I/O buffer with the final TRB */
1405  while ( count-- ) {
1406  rc = xhci_enqueue ( ring, ( count ? NULL : iobuf ), trb++ );
1407  assert ( rc == 0 ); /* Should never be able to fail */
1408  }
1409 
1410  return 0;
1411 }
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:912
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:682
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
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:1315
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

1419  {
1420  struct io_buffer *iobuf;
1421 
1422  /* Dequeue TRBs until we reach the final TRB for an I/O buffer */
1423  do {
1424  iobuf = xhci_dequeue ( ring );
1425  } while ( iobuf == NULL );
1426 
1427  return iobuf;
1428 }
static struct io_buffer * xhci_dequeue(struct xhci_trb_ring *ring)
Dequeue a transfer request block.
Definition: xhci.c:1358
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:37

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

1436  {
1437 
1438  wmb();
1439  writel ( ring->dbval, ring->db );
1440 }
wmb()
uint32_t dbval
Doorbell register value.
Definition: xhci.h:864
void * db
Doorbell register.
Definition: xhci.h:862
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 1455 of file xhci.c.

1455  {
1456  physaddr_t crp;
1457  int rc;
1458 
1459  /* Allocate TRB ring */
1460  if ( ( rc = xhci_ring_alloc ( xhci, &xhci->command, XHCI_CMD_TRBS_LOG2,
1461  0, 0, 0 ) ) != 0 )
1462  goto err_ring_alloc;
1463 
1464  /* Program command ring control register */
1465  crp = dma ( &xhci->command.map, xhci->command.trb );
1466  if ( ( rc = xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ),
1467  xhci->op + XHCI_OP_CRCR ) ) != 0 )
1468  goto err_writeq;
1469 
1470  DBGC2 ( xhci, "XHCI %s CRCR at [%08lx,%08lx)\n", xhci->name,
1471  virt_to_phys ( xhci->command.trb ),
1472  ( virt_to_phys ( xhci->command.trb ) + xhci->command.len ) );
1473  return 0;
1474 
1475  err_writeq:
1476  xhci_ring_free ( &xhci->command );
1477  err_ring_alloc:
1478  return rc;
1479 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
size_t len
Length of transfer request blocks.
Definition: xhci.h:855
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1114
struct dma_mapping map
DMA mapping.
Definition: xhci.h:857
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1289
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:178
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
const char * name
Name.
Definition: xhci.h:1074
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:365
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:181
void * op
Operational registers.
Definition: xhci.h:1081
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:1216
#define XHCI_CMD_TRBS_LOG2
Number of TRBs (excluding Link TRB) in the command ring.
Definition: xhci.h:965

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

1486  {
1487 
1488  /* Sanity check */
1489  assert ( ( readl ( xhci->op + XHCI_OP_CRCR ) & XHCI_CRCR_CRR ) == 0 );
1490 
1491  /* Clear command ring control register */
1492  xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_CRCR );
1493 
1494  /* Free TRB ring */
1495  xhci_ring_free ( &xhci->command );
1496 }
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1114
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:1289
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:178
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:365
#define XHCI_CRCR_CRR
Command ring running.
Definition: xhci.h:187
void * op
Operational registers.
Definition: xhci.h:1081

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

1504  {
1505  struct xhci_event_ring *event = &xhci->event;
1506  unsigned int count;
1507  size_t len;
1508  int rc;
1509 
1510  /* Allocate event ring */
1511  count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
1512  len = ( count * sizeof ( event->trb[0] ) );
1513  event->trb = dma_alloc ( xhci->dma, &event->trb_map, len,
1514  xhci_align ( len ) );
1515  if ( ! event->trb ) {
1516  rc = -ENOMEM;
1517  goto err_alloc_trb;
1518  }
1519  memset ( event->trb, 0, len );
1520 
1521  /* Allocate event ring segment table */
1522  event->segment = dma_alloc ( xhci->dma, &event->segment_map,
1523  sizeof ( event->segment[0] ),
1524  xhci_align ( sizeof (event->segment[0])));
1525  if ( ! event->segment ) {
1526  rc = -ENOMEM;
1527  goto err_alloc_segment;
1528  }
1529  memset ( event->segment, 0, sizeof ( event->segment[0] ) );
1530  event->segment[0].base = cpu_to_le64 ( dma ( &event->trb_map,
1531  event->trb ) );
1532  event->segment[0].count = cpu_to_le32 ( count );
1533 
1534  /* Program event ring registers */
1535  writel ( 1, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
1536  if ( ( rc = xhci_writeq ( xhci, dma ( &event->trb_map, event->trb ),
1537  xhci->run + XHCI_RUN_ERDP ( 0 ) ) ) != 0 )
1538  goto err_writeq_erdp;
1539  if ( ( rc = xhci_writeq ( xhci,
1540  dma ( &event->segment_map, event->segment ),
1541  xhci->run + XHCI_RUN_ERSTBA ( 0 ) ) ) != 0 )
1542  goto err_writeq_erstba;
1543 
1544  DBGC2 ( xhci, "XHCI %s event ring [%08lx,%08lx) table [%08lx,%08lx)\n",
1545  xhci->name, virt_to_phys ( event->trb ),
1546  ( virt_to_phys ( event->trb ) + len ),
1547  virt_to_phys ( event->segment ),
1548  ( virt_to_phys ( event->segment ) +
1549  sizeof ( event->segment[0] ) ) );
1550  return 0;
1551 
1552  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
1553  err_writeq_erstba:
1554  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
1555  err_writeq_erdp:
1556  dma_free ( &event->segment_map, event->segment,
1557  sizeof ( event->segment[0] ) );
1558  err_alloc_segment:
1559  dma_free ( &event->trb_map, event->trb, len );
1560  err_alloc_trb:
1561  return rc;
1562 }
An event ring.
Definition: xhci.h:868
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * run
Runtime registers.
Definition: xhci.h:1083
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:399
#define cpu_to_le64(value)
Definition: byteswap.h:108
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:534
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:107
const char * name
Name.
Definition: xhci.h:1074
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:365
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:298
#define DBGC2(...)
Definition: compiler.h:522
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:971
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition: xhci.h:295
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1116
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:301
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 1569 of file xhci.c.

1569  {
1570  struct xhci_event_ring *event = &xhci->event;
1571  unsigned int count;
1572  size_t len;
1573 
1574  /* Clear event ring registers */
1575  writel ( 0, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
1576  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
1577  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
1578 
1579  /* Free event ring segment table */
1580  dma_free ( &event->segment_map, event->segment,
1581  sizeof ( event->segment[0] ) );
1582 
1583  /* Free event ring */
1584  count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
1585  len = ( count * sizeof ( event->trb[0] ) );
1586  dma_free ( &event->trb_map, event->trb, len );
1587 }
An event ring.
Definition: xhci.h:868
void * run
Runtime registers.
Definition: xhci.h:1083
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:365
#define XHCI_RUN_ERSTBA(intr)
Event ring segment table base address register.
Definition: xhci.h:298
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:971
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition: xhci.h:295
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1116
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:301

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

1596  {
1597  struct xhci_slot *slot;
1598  struct xhci_endpoint *endpoint;
1599  struct io_buffer *iobuf;
1600  int rc;
1601 
1602  /* Profile transfer events */
1603  profile_start ( &xhci_transfer_profiler );
1604 
1605  /* Identify slot */
1606  if ( ( trb->slot > xhci->slots ) ||
1607  ( ( slot = xhci->slot[trb->slot] ) == NULL ) ) {
1608  DBGC ( xhci, "XHCI %s transfer event invalid slot %d:\n",
1609  xhci->name, trb->slot );
1610  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1611  return;
1612  }
1613 
1614  /* Identify endpoint */
1615  if ( ( trb->endpoint >= XHCI_CTX_END ) ||
1616  ( ( endpoint = slot->endpoint[trb->endpoint] ) == NULL ) ) {
1617  DBGC ( xhci, "XHCI %s slot %d transfer event invalid epid "
1618  "%d:\n", xhci->name, slot->id, trb->endpoint );
1619  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1620  return;
1621  }
1622 
1623  /* Dequeue TRB(s) */
1624  iobuf = xhci_dequeue_multi ( &endpoint->ring );
1625  assert ( iobuf != NULL );
1626 
1627  /* Unmap I/O buffer */
1628  iob_unmap ( iobuf );
1629 
1630  /* Check for errors */
1631  if ( ! ( ( trb->code == XHCI_CMPLT_SUCCESS ) ||
1632  ( trb->code == XHCI_CMPLT_SHORT ) ) ) {
1633 
1634  /* Construct error */
1635  rc = -ECODE ( trb->code );
1636  DBGC ( xhci, "XHCI %s slot %d ctx %d failed (code %d): %s\n",
1637  xhci->name, slot->id, endpoint->ctx, trb->code,
1638  strerror ( rc ) );
1639  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1640 
1641  /* Sanity check */
1642  assert ( ( endpoint->context->state & XHCI_ENDPOINT_STATE_MASK )
1643  != XHCI_ENDPOINT_RUNNING );
1644 
1645  /* Report failure to USB core */
1646  usb_complete_err ( endpoint->ep, iobuf, rc );
1647  return;
1648  }
1649 
1650  /* Record actual transfer size */
1651  iob_unput ( iobuf, le16_to_cpu ( trb->residual ) );
1652 
1653  /* Sanity check (for successful completions only) */
1654  assert ( xhci_ring_consumed ( &endpoint->ring ) ==
1655  le64_to_cpu ( trb->transfer ) );
1656 
1657  /* Report completion to USB core */
1658  usb_complete ( endpoint->ep, iobuf );
1659  profile_stop ( &xhci_transfer_profiler );
1660 }
Short packet.
Definition: xhci.h:636
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:935
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:953
uint8_t state
Endpoint state.
Definition: xhci.h:770
#define DBGC(...)
Definition: compiler.h:505
uint8_t code
Completion code.
Definition: xhci.h:596
An xHCI endpoint.
Definition: xhci.h:1161
Success.
Definition: xhci.h:634
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:602
unsigned int slots
Number of device slots.
Definition: xhci.h:1088
#define ECODE(code)
Definition: xhci.c:233
uint8_t slot
Slot ID.
Definition: xhci.h:604
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int ctx
Context index.
Definition: xhci.h:1169
#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:278
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1175
An xHCI device slot.
Definition: xhci.h:1133
#define iob_unput(iobuf, len)
Definition: iobuf.h:139
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
#define le16_to_cpu(value)
Definition: byteswap.h:112
Endpoint is running.
Definition: xhci.h:798
static struct io_buffer * xhci_dequeue_multi(struct xhci_trb_ring *ring)
Dequeue multiple transfer request blocks.
Definition: xhci.c:1419
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition: usb.h:1086
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1177
uint16_t residual
Residual transfer length.
Definition: xhci.h:592
uint64_t transfer
Transfer TRB pointer.
Definition: xhci.h:590
#define le64_to_cpu(value)
Definition: byteswap.h:114
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1123
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:586
#define XHCI_ENDPOINT_STATE_MASK
Endpoint state mask.
Definition: xhci.h:808
A persistent I/O buffer.
Definition: iobuf.h:37

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

1669  {
1670  int rc;
1671 
1672  /* Ignore "command ring stopped" notifications */
1673  if ( trb->code == XHCI_CMPLT_CMD_STOPPED ) {
1674  DBGC2 ( xhci, "XHCI %s command ring stopped\n", xhci->name );
1675  return;
1676  }
1677 
1678  /* Ignore unexpected completions */
1679  if ( ! xhci->pending ) {
1680  rc = -ECODE ( trb->code );
1681  DBGC ( xhci, "XHCI %s unexpected completion (code %d): %s\n",
1682  xhci->name, trb->code, strerror ( rc ) );
1683  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1684  return;
1685  }
1686 
1687  /* Dequeue command TRB */
1688  xhci_dequeue ( &xhci->command );
1689 
1690  /* Sanity check */
1691  assert ( xhci_ring_consumed ( &xhci->command ) ==
1692  le64_to_cpu ( trb->command ) );
1693 
1694  /* Record completion */
1695  memcpy ( xhci->pending, trb, sizeof ( *xhci->pending ) );
1696  xhci->pending = NULL;
1697 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t command
Command TRB pointer.
Definition: xhci.h:613
static struct io_buffer * xhci_dequeue(struct xhci_trb_ring *ring)
Dequeue a transfer request block.
Definition: xhci.c:1358
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
Definition: xhci.h:935
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1114
union xhci_trb * pending
Current command (if any)
Definition: xhci.h:1118
#define DBGC(...)
Definition: compiler.h:505
#define ECODE(code)
Definition: xhci.c:233
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:78
const char * name
Name.
Definition: xhci.h:1074
Command ring stopped.
Definition: xhci.h:638
#define DBGC2(...)
Definition: compiler.h:522
uint8_t code
Completion code.
Definition: xhci.h:617
#define le64_to_cpu(value)
Definition: byteswap.h:114
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

1706  {
1707  struct usb_port *port = usb_port ( xhci->bus->hub, trb->port );
1708  uint32_t portsc;
1709 
1710  /* Sanity check */
1711  assert ( ( trb->port > 0 ) && ( trb->port <= xhci->ports ) );
1712 
1713  /* Record disconnections and clear changes */
1714  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1715  port->disconnected |= ( portsc & XHCI_PORTSC_CSC );
1716  portsc &= ( XHCI_PORTSC_PRESERVE | XHCI_PORTSC_CHANGE );
1717  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1718 
1719  /* Report port status change */
1720  usb_port_changed ( port );
1721 }
unsigned int ports
Number of ports.
Definition: xhci.h:1092
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:1126
#define XHCI_PORTSC_CSC
Connect status change.
Definition: xhci.h:248
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
Definition: xhci.h:283
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition: usb.c:1857
A USB port.
Definition: usb.h:812
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:269
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:646
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:203
struct usb_hub * hub
Root hub.
Definition: usb.h:994
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:959
void * op
Operational registers.
Definition: xhci.h:1081

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

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

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

1744  {
1745  struct xhci_event_ring *event = &xhci->event;
1746  union xhci_trb *trb;
1747  unsigned int shift = XHCI_EVENT_TRBS_LOG2;
1748  unsigned int count = ( 1 << shift );
1749  unsigned int mask = ( count - 1 );
1750  unsigned int consumed;
1751  unsigned int type;
1752 
1753  /* Do nothing if device has permanently failed */
1754  if ( xhci->failed )
1755  return;
1756 
1757  /* Poll for events */
1758  profile_start ( &xhci_event_profiler );
1759  for ( consumed = 0 ; ; consumed++ ) {
1760 
1761  /* Stop if we reach an empty TRB */
1762  rmb();
1763  trb = &event->trb[ event->cons & mask ];
1764  if ( ! ( ( trb->common.flags ^
1765  ( event->cons >> shift ) ) & XHCI_TRB_C ) )
1766  break;
1767 
1768  /* Consume this TRB */
1769  event->cons++;
1770 
1771  /* Handle TRB */
1772  type = ( trb->common.type & XHCI_TRB_TYPE_MASK );
1773  switch ( type ) {
1774 
1775  case XHCI_TRB_TRANSFER :
1776  xhci_transfer ( xhci, &trb->transfer );
1777  break;
1778 
1779  case XHCI_TRB_COMPLETE :
1780  xhci_complete ( xhci, &trb->complete );
1781  break;
1782 
1783  case XHCI_TRB_PORT_STATUS:
1784  xhci_port_status ( xhci, &trb->port );
1785  break;
1786 
1788  xhci_host_controller ( xhci, &trb->host );
1789  break;
1790 
1791  default:
1792  DBGC ( xhci, "XHCI %s unrecognised event %#x\n:",
1793  xhci->name, ( event->cons - 1 ) );
1794  DBGC_HDA ( xhci, virt_to_phys ( trb ),
1795  trb, sizeof ( *trb ) );
1796  break;
1797  }
1798  }
1799 
1800  /* Update dequeue pointer if applicable */
1801  if ( consumed ) {
1802  xhci_writeq ( xhci, dma ( &event->trb_map, trb ),
1803  xhci->run + XHCI_RUN_ERDP ( 0 ) );
1804  profile_stop ( &xhci_event_profiler );
1805  }
1806 }
An event ring.
Definition: xhci.h:868
struct xhci_trb_common common
Common fields.
Definition: xhci.h:686
void * run
Runtime registers.
Definition: xhci.h:1083
uint32_t type
Operating system type.
Definition: ena.h:12
struct xhci_trb_transfer transfer
Transfer event.
Definition: xhci.h:710
#define DBGC(...)
Definition: compiler.h:505
uint8_t type
Type.
Definition: xhci.h:322
uint8_t flags
Flags.
Definition: xhci.h:320
#define XHCI_TRB_PORT_STATUS
A port status change transfer request block.
Definition: xhci.h:660
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
static void xhci_transfer(struct xhci_device *xhci, struct xhci_trb_transfer *trb)
Handle transfer event.
Definition: xhci.c:1595
struct xhci_trb_host_controller host
Host controller event.
Definition: xhci.h:716
#define rmb()
Definition: io.h:544
#define XHCI_TRB_COMPLETE
A command completion event transfer request block.
Definition: xhci.h:629
#define DBGC_HDA(...)
Definition: compiler.h:506
#define XHCI_TRB_TRANSFER
A transfer event transfer request block.
Definition: xhci.h:608
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
#define XHCI_TRB_HOST_CONTROLLER
A port status change transfer request block.
Definition: xhci.h:679
int failed
Command mechanism has permanently failed.
Definition: xhci.h:1120
A transfer request block.
Definition: xhci.h:682
const char * name
Name.
Definition: xhci.h:1074
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:365
struct xhci_trb_complete complete
Command completion event.
Definition: xhci.h:712
#define XHCI_TRB_TYPE_MASK
Transfer request block type mask.
Definition: xhci.h:346
static void xhci_host_controller(struct xhci_device *xhci, struct xhci_trb_host_controller *trb)
Handle host controller event.
Definition: xhci.c:1729
static void xhci_complete(struct xhci_device *xhci, struct xhci_trb_complete *trb)
Handle command completion event.
Definition: xhci.c:1668
struct xhci_trb_port_status port
Port status changed event.
Definition: xhci.h:714
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:971
#define XHCI_TRB_C
Transfer request block cycle bit flag.
Definition: xhci.h:328
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1116
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:301
static void xhci_port_status(struct xhci_device *xhci, struct xhci_trb_port_status *trb)
Handle port status event.
Definition: xhci.c:1705

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

1813  {
1814  physaddr_t crp;
1815  uint32_t crcr;
1816 
1817  /* Abort the command */
1818  DBGC2 ( xhci, "XHCI %s aborting command\n", xhci->name );
1819  xhci_writeq ( xhci, XHCI_CRCR_CA, xhci->op + XHCI_OP_CRCR );
1820 
1821  /* Allow time for command to abort */
1823 
1824  /* Check for failure to abort */
1825  crcr = readl ( xhci->op + XHCI_OP_CRCR );
1826  if ( crcr & XHCI_CRCR_CRR ) {
1827 
1828  /* Device has failed to abort a command and is almost
1829  * certainly beyond repair. Reset device, abandoning
1830  * all state, and mark device as failed to avoid
1831  * delays on any future command attempts.
1832  */
1833  DBGC ( xhci, "XHCI %s failed to abort command\n", xhci->name );
1834  xhci_fail ( xhci );
1835  }
1836 
1837  /* Consume (and ignore) any final command status */
1838  xhci_event_poll ( xhci );
1839 
1840  /* Reset the command ring control register */
1841  xhci_ring_reset ( &xhci->command );
1842  crp = dma ( &xhci->command.map, xhci->command.trb );
1843  xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ), xhci->op + XHCI_OP_CRCR );
1844 }
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1114
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:857
#define XHCI_COMMAND_ABORT_DELAY_MS
Time to delay after aborting a command.
Definition: xhci.h:1009
static void xhci_ring_reset(struct xhci_trb_ring *ring)
Reset transfer request block ring.
Definition: xhci.c:1273
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:178
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
static int xhci_fail(struct xhci_device *xhci)
Mark xHCI device as permanently failed.
Definition: xhci.c:1179
const char * name
Name.
Definition: xhci.h:1074
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:365
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:78
#define DBGC2(...)
Definition: compiler.h:522
static void xhci_event_poll(struct xhci_device *xhci)
Poll event ring.
Definition: xhci.c:1744
#define XHCI_CRCR_RCS
Command ring cycle state.
Definition: xhci.h:181
#define XHCI_CRCR_CA
Command abort.
Definition: xhci.h:184
#define XHCI_CRCR_CRR
Command ring running.
Definition: xhci.h:187
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
void * op
Operational registers.
Definition: xhci.h:1081

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

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

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

1927  {
1928  union xhci_trb trb;
1929  struct xhci_trb_common *nop = &trb.common;
1930  int rc;
1931 
1932  /* Construct command */
1933  memset ( nop, 0, sizeof ( *nop ) );
1934  nop->flags = XHCI_TRB_IOC;
1935  nop->type = XHCI_TRB_NOP_CMD;
1936 
1937  /* Issue command and wait for completion */
1938  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1939  DBGC ( xhci, "XHCI %s NOP failed: %s\n",
1940  xhci->name, strerror ( rc ) );
1941  return rc;
1942  }
1943 
1944  DBGC2 ( xhci, "XHCI %s NOP completed successfully\n", xhci->name );
1945  return 0;
1946 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A transfer request block.
Definition: xhci.h:314
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_TRB_NOP_CMD
A no-op command transfer request block.
Definition: xhci.h:585
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:682
const char * name
Name.
Definition: xhci.h:1074
uint8_t nop
Definition: tcp.h:13
#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:1856
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
Definition: xhci.h:337
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 1955 of file xhci.c.

1956  {
1957  union xhci_trb trb;
1958  struct xhci_trb_enable_slot *enable = &trb.enable;
1959  struct xhci_trb_complete *enabled = &trb.complete;
1960  unsigned int slot;
1961  int rc;
1962 
1963  /* Construct command */
1964  memset ( enable, 0, sizeof ( *enable ) );
1965  enable->slot = type;
1966  enable->type = XHCI_TRB_ENABLE_SLOT;
1967 
1968  /* Issue command and wait for completion */
1969  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1970  DBGC ( xhci, "XHCI %s could not enable new slot: %s\n",
1971  xhci->name, strerror ( rc ) );
1972  return rc;
1973  }
1974 
1975  /* Extract slot number */
1976  slot = enabled->slot;
1977 
1978  DBGC2 ( xhci, "XHCI %s slot %d enabled\n", xhci->name, slot );
1979  return slot;
1980 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_ENABLE_SLOT
An enable slot transfer request block.
Definition: xhci.h:481
uint8_t slot
Slot type.
Definition: xhci.h:475
A command completion event transfer request block.
Definition: xhci.h:611
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:465
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:78
A transfer request block.
Definition: xhci.h:682
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
#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:1856
uint8_t type
Type.
Definition: xhci.h:473
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 1989 of file xhci.c.

1990  {
1991  union xhci_trb trb;
1992  struct xhci_trb_disable_slot *disable = &trb.disable;
1993  int rc;
1994 
1995  /* Construct command */
1996  memset ( disable, 0, sizeof ( *disable ) );
1997  disable->type = XHCI_TRB_DISABLE_SLOT;
1998  disable->slot = slot;
1999 
2000  /* Issue command and wait for completion */
2001  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2002  DBGC ( xhci, "XHCI %s could not disable slot %d: %s\n",
2003  xhci->name, slot, strerror ( rc ) );
2004  return rc;
2005  }
2006 
2007  DBGC2 ( xhci, "XHCI %s slot %d disabled\n", xhci->name, slot );
2008  return 0;
2009 }
A disable slot transfer request block.
Definition: xhci.h:484
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_DISABLE_SLOT
A disable slot transfer request block.
Definition: xhci.h:500
#define DBGC(...)
Definition: compiler.h:505
uint8_t slot
Slot ID.
Definition: xhci.h:496
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:682
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
uint8_t type
Type.
Definition: xhci.h:492
#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:1856
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 2021 of file xhci.c.

2026  {
2027  union xhci_trb trb;
2028  struct xhci_trb_context *context = &trb.context;
2029  struct dma_mapping map;
2030  size_t len;
2031  void *input;
2032  int rc;
2033 
2034  /* Allocate an input context */
2035  memset ( &map, 0, sizeof ( map ) );
2037  input = dma_alloc ( xhci->dma, &map, len, xhci_align ( len ) );
2038  if ( ! input ) {
2039  rc = -ENOMEM;
2040  goto err_alloc;
2041  }
2042  memset ( input, 0, len );
2043 
2044  /* Populate input context */
2045  populate ( xhci, slot, endpoint, input );
2046 
2047  /* Construct command */
2048  memset ( context, 0, sizeof ( *context ) );
2049  context->type = type;
2050  context->input = cpu_to_le64 ( dma ( &map, input ) );
2051  context->slot = slot->id;
2052 
2053  /* Issue command and wait for completion */
2054  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 )
2055  goto err_command;
2056 
2057  err_command:
2058  dma_free ( &map, input, len );
2059  err_alloc:
2060  return rc;
2061 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:953
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:399
uint32_t type
Operating system type.
Definition: ena.h:12
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:108
uint64_t input
Input context.
Definition: xhci.h:505
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:534
ring len
Length.
Definition: dwmac.h:231
A context transfer request block.
Definition: xhci.h:503
A transfer request block.
Definition: xhci.h:682
uint8_t slot
Slot.
Definition: edd.h:16
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:183
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:430
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
A DMA mapping.
Definition: dma.h:32
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1856
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
uint8_t type
Type.
Definition: xhci.h:511
uint8_t slot
Slot ID.
Definition: xhci.h:515
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 2071 of file xhci.c.

2074  {
2075  struct xhci_trb_ring *ring = &endpoint->ring;
2076  struct xhci_control_context *control_ctx;
2077  struct xhci_slot_context *slot_ctx;
2078  struct xhci_endpoint_context *ep_ctx;
2079 
2080  /* Sanity checks */
2081  assert ( endpoint->ctx == XHCI_CTX_EP0 );
2082 
2083  /* Populate control context */
2084  control_ctx = input;
2085  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2086  ( 1 << XHCI_CTX_EP0 ) );
2087 
2088  /* Populate slot context */
2089  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2090  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( 1, 0, slot->psiv,
2091  slot->route ) );
2092  slot_ctx->port = slot->port;
2093  slot_ctx->tt_id = slot->tt_id;
2094  slot_ctx->tt_port = slot->tt_port;
2095 
2096  /* Populate control endpoint context */
2097  ep_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_EP0 ) );
2098  ep_ctx->type = XHCI_EP_TYPE_CONTROL;
2099  ep_ctx->burst = endpoint->ep->burst;
2100  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2101  ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
2102  XHCI_EP_DCS );
2103  ep_ctx->trb_len = cpu_to_le16 ( XHCI_EP0_TRB_LEN );
2104 }
An endpoint context.
Definition: xhci.h:768
uint8_t burst
Maximum burst size.
Definition: xhci.h:780
uint8_t type
Endpoint type.
Definition: xhci.h:778
An input control context.
Definition: xhci.h:720
uint16_t trb_len
Average TRB length.
Definition: xhci.h:786
struct dma_mapping map
DMA mapping.
Definition: xhci.h:857
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
Definition: xhci.h:814
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:108
uint32_t add
Add context flags.
Definition: xhci.h:724
uint64_t dequeue
Transfer ring dequeue pointer.
Definition: xhci.h:784
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:823
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int ctx
Context index.
Definition: xhci.h:1169
uint8_t port
Root hub port number.
Definition: xhci.h:744
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:764
uint16_t mtu
Maximum packet size.
Definition: xhci.h:782
unsigned int burst
Maximum burst size.
Definition: usb.h:413
uint32_t info
Device info.
Definition: xhci.h:740
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint8_t slot
Slot.
Definition: edd.h:16
#define XHCI_EP0_TRB_LEN
Control endpoint average TRB length.
Definition: xhci.h:826
size_t mtu
Maximum transfer size.
Definition: usb.h:411
uint8_t tt_id
TT hub slot ID.
Definition: xhci.h:748
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
uint8_t tt_port
TT port number.
Definition: xhci.h:750
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1177
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:430
#define cpu_to_le16(value)
Definition: byteswap.h:106
A transfer request block command/transfer ring.
Definition: xhci.h:839
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:950
A slot context.
Definition: xhci.h:738
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:942

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

2114  {
2115  struct usb_device *usb = slot->usb;
2116  struct xhci_slot_context *slot_ctx;
2117  int rc;
2118 
2119  /* Assign device address */
2120  if ( ( rc = xhci_context ( xhci, slot, slot->endpoint[XHCI_CTX_EP0],
2122  xhci_address_device_input ) ) != 0 ) {
2123  DBGC ( xhci, "XHCI %s slot %d could not assign address: %s\n",
2124  xhci->name, slot->id, strerror ( rc ) );
2125  return rc;
2126  }
2127 
2128  /* Get assigned address */
2129  slot_ctx = ( slot->context +
2131  usb->address = slot_ctx->address;
2132  DBGC2 ( xhci, "XHCI %s slot %d assigned address %d to %s\n",
2133  xhci->name, slot->id, usb->address, usb->name );
2134 
2135  return 0;
2136 }
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:418
#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:2021
unsigned int address
Device address, if assigned.
Definition: usb.h:732
uint8_t address
USB address.
Definition: xhci.h:754
#define XHCI_TRB_ADDRESS_DEVICE
An address device transfer request block.
Definition: xhci.h:519
char name[32]
Name.
Definition: usb.h:724
A USB device.
Definition: usb.h:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
#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:2071
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:950
A slot context.
Definition: xhci.h:738
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:942

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

2149  {
2150  struct xhci_trb_ring *ring = &endpoint->ring;
2151  struct xhci_control_context *control_ctx;
2152  struct xhci_slot_context *slot_ctx;
2153  struct xhci_endpoint_context *ep_ctx;
2154 
2155  /* Populate control context */
2156  control_ctx = input;
2157  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2158  ( 1 << endpoint->ctx ) );
2159 
2160  /* Populate slot context */
2161  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2162  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2163  ( slot->ports ? 1 : 0 ),
2164  slot->psiv, 0 ) );
2165  slot_ctx->ports = slot->ports;
2166 
2167  /* Populate endpoint context */
2168  ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2169  ep_ctx->interval = endpoint->interval;
2170  ep_ctx->type = endpoint->type;
2171  ep_ctx->burst = endpoint->ep->burst;
2172  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2173  ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
2174  XHCI_EP_DCS );
2175  ep_ctx->trb_len = cpu_to_le16 ( endpoint->ep->mtu ); /* best guess */
2176 }
An endpoint context.
Definition: xhci.h:768
uint8_t burst
Maximum burst size.
Definition: xhci.h:780
uint8_t type
Endpoint type.
Definition: xhci.h:778
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:953
An input control context.
Definition: xhci.h:720
uint16_t trb_len
Average TRB length.
Definition: xhci.h:786
struct dma_mapping map
DMA mapping.
Definition: xhci.h:857
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:108
uint32_t add
Add context flags.
Definition: xhci.h:724
uint64_t dequeue
Transfer ring dequeue pointer.
Definition: xhci.h:784
uint8_t ports
Number of downstream ports.
Definition: xhci.h:746
unsigned int type
Endpoint type.
Definition: xhci.h:1171
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:823
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
unsigned int ctx
Context index.
Definition: xhci.h:1169
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:764
uint16_t mtu
Maximum packet size.
Definition: xhci.h:782
unsigned int burst
Maximum burst size.
Definition: usb.h:413
uint32_t info
Device info.
Definition: xhci.h:740
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint8_t slot
Slot.
Definition: edd.h:16
size_t mtu
Maximum transfer size.
Definition: usb.h:411
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
uint8_t interval
Polling interval.
Definition: xhci.h:774
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1177
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:430
#define cpu_to_le16(value)
Definition: byteswap.h:106
A transfer request block command/transfer ring.
Definition: xhci.h:839
unsigned int interval
Endpoint interval.
Definition: xhci.h:1173
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
A slot context.
Definition: xhci.h:738
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:942

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

2188  {
2189  int rc;
2190 
2191  /* Configure endpoint */
2192  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2194  xhci_configure_endpoint_input ) ) != 0 ) {
2195  DBGC ( xhci, "XHCI %s slot %d ctx %d could not configure: %s\n",
2196  xhci->name, slot->id, endpoint->ctx, strerror ( rc ) );
2197  return rc;
2198  }
2199 
2200  DBGC2 ( xhci, "XHCI %s slot %d ctx %d configured\n",
2201  xhci->name, slot->id, endpoint->ctx );
2202  return 0;
2203 }
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:2021
unsigned int ctx
Context index.
Definition: xhci.h:1169
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
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:2146
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
Definition: xhci.h:522
#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 2214 of file xhci.c.

2217  {
2218  struct xhci_control_context *control_ctx;
2219  struct xhci_slot_context *slot_ctx;
2220 
2221  /* Populate control context */
2222  control_ctx = input;
2223  control_ctx->add = cpu_to_le32 ( 1 << XHCI_CTX_SLOT );
2224  control_ctx->drop = cpu_to_le32 ( 1 << endpoint->ctx );
2225 
2226  /* Populate slot context */
2227  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2228  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2229  0, 0, 0 ) );
2230 }
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:953
An input control context.
Definition: xhci.h:720
Definition: bnxt_hsi.h:68
uint32_t add
Add context flags.
Definition: xhci.h:724
uint32_t drop
Drop context flags.
Definition: xhci.h:722
unsigned int ctx
Context index.
Definition: xhci.h:1169
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:764
uint32_t info
Device info.
Definition: xhci.h:740
#define cpu_to_le32(value)
Definition: byteswap.h:107
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:430
A slot context.
Definition: xhci.h:738
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:942

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

2242  {
2243  int rc;
2244 
2245  /* Deconfigure endpoint */
2246  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2248  xhci_deconfigure_endpoint_input ) ) != 0 ) {
2249  DBGC ( xhci, "XHCI %s slot %d ctx %d could not deconfigure: "
2250  "%s\n", xhci->name, slot->id, endpoint->ctx,
2251  strerror ( rc ) );
2252  return rc;
2253  }
2254 
2255  DBGC2 ( xhci, "XHCI %s slot %d ctx %d deconfigured\n",
2256  xhci->name, slot->id, endpoint->ctx );
2257  return 0;
2258 }
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:2021
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:2214
unsigned int ctx
Context index.
Definition: xhci.h:1169
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
Definition: xhci.h:522
#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 2268 of file xhci.c.

2271  {
2272  struct xhci_control_context *control_ctx;
2273  struct xhci_slot_context *slot_ctx;
2274  struct xhci_endpoint_context *ep_ctx;
2275 
2276  /* Populate control context */
2277  control_ctx = input;
2278  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2279  ( 1 << endpoint->ctx ) );
2280 
2281  /* Populate slot context */
2282  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2283  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2284  0, 0, 0 ) );
2285 
2286  /* Populate endpoint context */
2287  ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2288  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2289 }
An endpoint context.
Definition: xhci.h:768
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:953
An input control context.
Definition: xhci.h:720
Definition: bnxt_hsi.h:68
uint32_t add
Add context flags.
Definition: xhci.h:724
unsigned int ctx
Context index.
Definition: xhci.h:1169
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:764
uint16_t mtu
Maximum packet size.
Definition: xhci.h:782
uint32_t info
Device info.
Definition: xhci.h:740
#define cpu_to_le32(value)
Definition: byteswap.h:107
size_t mtu
Maximum transfer size.
Definition: usb.h:411
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:430
#define cpu_to_le16(value)
Definition: byteswap.h:106
A slot context.
Definition: xhci.h:738
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:942

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

2301  {
2302  int rc;
2303 
2304  /* Configure endpoint */
2305  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2307  xhci_evaluate_context_input ) ) != 0 ) {
2308  DBGC ( xhci, "XHCI %s slot %d ctx %d could not (re-)evaluate: "
2309  "%s\n", xhci->name, slot->id, endpoint->ctx,
2310  strerror ( rc ) );
2311  return rc;
2312  }
2313 
2314  DBGC2 ( xhci, "XHCI %s slot %d ctx %d (re-)evaluated\n",
2315  xhci->name, slot->id, endpoint->ctx );
2316  return 0;
2317 }
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:2268
#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:2021
unsigned int ctx
Context index.
Definition: xhci.h:1169
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
#define DBGC2(...)
Definition: compiler.h:522
#define XHCI_TRB_EVALUATE_CONTEXT
An evaluate context transfer request block.
Definition: xhci.h:525

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

2329  {
2330  union xhci_trb trb;
2331  struct xhci_trb_reset_endpoint *reset = &trb.reset;
2332  int rc;
2333 
2334  /* Construct command */
2335  memset ( reset, 0, sizeof ( *reset ) );
2336  reset->slot = slot->id;
2337  reset->endpoint = endpoint->ctx;
2338  reset->type = XHCI_TRB_RESET_ENDPOINT;
2339 
2340  /* Issue command and wait for completion */
2341  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2342  DBGC ( xhci, "XHCI %s slot %d ctx %d could not reset endpoint "
2343  "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2344  endpoint->context->state, strerror ( rc ) );
2345  return rc;
2346  }
2347 
2348  return 0;
2349 }
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:544
uint8_t type
Type.
Definition: xhci.h:536
uint8_t slot
Slot ID.
Definition: xhci.h:540
A reset endpoint transfer request block.
Definition: xhci.h:528
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:682
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:538
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1856
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 2359 of file xhci.c.

2361  {
2362  union xhci_trb trb;
2363  struct xhci_trb_stop_endpoint *stop = &trb.stop;
2364  int rc;
2365 
2366  /* Construct command */
2367  memset ( stop, 0, sizeof ( *stop ) );
2368  stop->slot = slot->id;
2369  stop->endpoint = endpoint->ctx;
2370  stop->type = XHCI_TRB_STOP_ENDPOINT;
2371 
2372  /* Issue command and wait for completion */
2373  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2374  DBGC ( xhci, "XHCI %s slot %d ctx %d could not stop endpoint "
2375  "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2376  endpoint->context->state, strerror ( rc ) );
2377  return rc;
2378  }
2379 
2380  return 0;
2381 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:557
uint8_t slot
Slot ID.
Definition: xhci.h:559
#define XHCI_TRB_STOP_ENDPOINT
A stop endpoint transfer request block.
Definition: xhci.h:563
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:682
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
uint8_t type
Type.
Definition: xhci.h:555
A stop endpoint transfer request block.
Definition: xhci.h:547
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1856
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 2392 of file xhci.c.

2394  {
2395  union xhci_trb trb;
2396  struct xhci_trb_set_tr_dequeue_pointer *dequeue = &trb.dequeue;
2397  struct xhci_trb_ring *ring = &endpoint->ring;
2398  unsigned int cons;
2399  unsigned int mask;
2400  unsigned int index;
2401  unsigned int dcs;
2402  physaddr_t addr;
2403  int rc;
2404 
2405  /* Construct command */
2406  memset ( dequeue, 0, sizeof ( *dequeue ) );
2407  cons = ring->cons;
2408  mask = ring->mask;
2409  dcs = ( ( ~( cons >> ring->shift ) ) & XHCI_EP_DCS );
2410  index = ( cons & mask );
2411  addr = dma ( &ring->map, &ring->trb[index] );
2412  dequeue->dequeue = cpu_to_le64 ( addr | dcs );
2413  dequeue->slot = slot->id;
2414  dequeue->endpoint = endpoint->ctx;
2416 
2417  /* Issue command and wait for completion */
2418  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2419  DBGC ( xhci, "XHCI %s slot %d ctx %d could not set TR dequeue "
2420  "pointer in state %d: %s\n", xhci->name, slot->id,
2421  endpoint->ctx, endpoint->context->state, strerror ( rc));
2422  return rc;
2423  }
2424 
2425  return 0;
2426 }
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:582
unsigned int cons
Consumer counter.
Definition: xhci.h:843
A set transfer ring dequeue pointer transfer request block.
Definition: xhci.h:566
uint8_t state
Endpoint state.
Definition: xhci.h:770
#define DBGC(...)
Definition: compiler.h:505
struct dma_mapping map
DMA mapping.
Definition: xhci.h:857
long index
Definition: bigint.h:62
#define cpu_to_le64(value)
Definition: byteswap.h:108
uint64_t dequeue
Dequeue pointer.
Definition: xhci.h:568
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:823
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
unsigned int ctx
Context index.
Definition: xhci.h:1169
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1175
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint16_t cons
Consumer index.
Definition: ena.h:22
A transfer request block.
Definition: xhci.h:682
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot ID.
Definition: xhci.h:578
uint32_t addr
Buffer address.
Definition: dwmac.h:20
uint8_t slot
Slot.
Definition: edd.h:16
unsigned long physaddr_t
Definition: stdint.h:20
unsigned int mask
Ring counter mask.
Definition: xhci.h:847
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1177
unsigned int shift
Ring size (log2)
Definition: xhci.h:845
A transfer request block command/transfer ring.
Definition: xhci.h:839
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1856
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:576
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 2441 of file xhci.c.

2441  {
2442  struct usb_device *usb = ep->usb;
2443  struct xhci_slot *slot = usb_get_hostdata ( usb );
2444  struct xhci_device *xhci = slot->xhci;
2445  struct xhci_endpoint *endpoint;
2446  unsigned int ctx;
2447  unsigned int type;
2448  unsigned int interval;
2449  int rc;
2450 
2451  /* Calculate context index */
2452  ctx = XHCI_CTX ( ep->address );
2453  assert ( slot->endpoint[ctx] == NULL );
2454 
2455  /* Calculate endpoint type */
2459  if ( ep->address & USB_DIR_IN )
2460  type |= XHCI_EP_TYPE_IN;
2461 
2462  /* Calculate interval */
2463  if ( type & XHCI_EP_TYPE_PERIODIC ) {
2464  interval = ( fls ( ep->interval ) - 1 );
2465  } else {
2466  interval = ep->interval;
2467  }
2468 
2469  /* Allocate and initialise structure */
2470  endpoint = zalloc ( sizeof ( *endpoint ) );
2471  if ( ! endpoint ) {
2472  rc = -ENOMEM;
2473  goto err_alloc;
2474  }
2475  usb_endpoint_set_hostdata ( ep, endpoint );
2476  slot->endpoint[ctx] = endpoint;
2477  endpoint->xhci = xhci;
2478  endpoint->slot = slot;
2479  endpoint->ep = ep;
2480  endpoint->ctx = ctx;
2481  endpoint->type = type;
2482  endpoint->interval = interval;
2483  endpoint->context = ( ( ( void * ) slot->context ) +
2485 
2486  /* Allocate transfer ring */
2487  if ( ( rc = xhci_ring_alloc ( xhci, &endpoint->ring,
2489  slot->id, ctx, 0 ) ) != 0 )
2490  goto err_ring_alloc;
2491 
2492  /* Configure endpoint, if applicable */
2493  if ( ( ctx != XHCI_CTX_EP0 ) &&
2494  ( ( rc = xhci_configure_endpoint ( xhci, slot, endpoint ) ) != 0 ))
2495  goto err_configure_endpoint;
2496 
2497  DBGC2 ( xhci, "XHCI %s slot %d ctx %d ring [%08lx,%08lx)\n",
2498  xhci->name, slot->id, ctx, virt_to_phys ( endpoint->ring.trb ),
2499  ( virt_to_phys ( endpoint->ring.trb ) + endpoint->ring.len ) );
2500  return 0;
2501 
2502  xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2503  err_configure_endpoint:
2504  xhci_ring_free ( &endpoint->ring );
2505  err_ring_alloc:
2506  slot->endpoint[ctx] = NULL;
2507  free ( endpoint );
2508  err_alloc:
2509  return rc;
2510 }
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
Definition: usb.h:575
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:418
An xHCI device.
Definition: xhci.h:1066
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:280
size_t len
Length of transfer request blocks.
Definition: xhci.h:855
uint32_t type
Operating system type.
Definition: ena.h:12
#define XHCI_EP_TYPE(type)
Endpoint type.
Definition: xhci.h:811
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
Definition: xhci.h:814
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1289
static int xhci_configure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Configure endpoint.
Definition: xhci.c:2186
#define XHCI_TRANSFER_TRBS_LOG2
Number of TRBs in a transfer ring.
Definition: xhci.h:977
An xHCI endpoint.
Definition: xhci.h:1161
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
unsigned int type
Endpoint type.
Definition: xhci.h:1171
#define XHCI_EP_TYPE_IN
Input endpoint type.
Definition: xhci.h:817
#define ENOMEM
Not enough space.
Definition: errno.h:534
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:853
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_EP_TYPE_PERIODIC
Periodic endpoint type.
Definition: xhci.h:820
unsigned int ctx
Context index.
Definition: xhci.h:1169
struct usb_device * usb
USB device.
Definition: xhci.h:1137
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:97
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1165
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1175
A USB device.
Definition: usb.h:722
static int xhci_deconfigure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Deconfigure endpoint.
Definition: xhci.c:2240
An xHCI device slot.
Definition: xhci.h:1133
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
const char * name
Name.
Definition: xhci.h:1074
uint8_t slot
Slot.
Definition: edd.h:16
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:794
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
#define XHCI_CTX(address)
Calculate context index from USB endpoint address.
Definition: xhci.h:945
#define DBGC2(...)
Definition: compiler.h:522
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1177
unsigned int interval
Interval (in microframes)
Definition: usb.h:415
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
Definition: usb.h:286
struct usb_device * usb
USB device.
Definition: usb.h:405
unsigned int interval
Endpoint interval.
Definition: xhci.h:1173
#define fls(x)
Find last (i.e.
Definition: strings.h:166
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1163
unsigned int attributes
Attributes.
Definition: usb.h:409
unsigned int address
Endpoint address.
Definition: usb.h:407
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:950
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:1216

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

2517  {
2518  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2519  struct xhci_slot *slot = endpoint->slot;
2520  struct xhci_device *xhci = slot->xhci;
2521  struct io_buffer *iobuf;
2522  unsigned int ctx = endpoint->ctx;
2523 
2524  /* Deconfigure endpoint, if applicable */
2525  if ( ctx != XHCI_CTX_EP0 )
2526  xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2527 
2528  /* Cancel any incomplete transfers */
2529  while ( xhci_ring_fill ( &endpoint->ring ) ) {
2530  iobuf = xhci_dequeue_multi ( &endpoint->ring );
2531  iob_unmap ( iobuf );
2532  usb_complete_err ( ep, iobuf, -ECANCELED );
2533  }
2534 
2535  /* Free endpoint */
2536  xhci_ring_free ( &endpoint->ring );
2537  slot->endpoint[ctx] = NULL;
2538  free ( endpoint );
2539 }
An xHCI device.
Definition: xhci.h:1066
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition: xhci.h:897
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition: xhci.h:1157
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1289
An xHCI endpoint.
Definition: xhci.h:1161
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
#define ECANCELED
Operation canceled.
Definition: errno.h:343
unsigned int ctx
Context index.
Definition: xhci.h:1169
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:278
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1165
static int xhci_deconfigure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Deconfigure endpoint.
Definition: xhci.c:2240
An xHCI device slot.
Definition: xhci.h:1133
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
uint8_t slot
Slot.
Definition: edd.h:16
static struct io_buffer * xhci_dequeue_multi(struct xhci_trb_ring *ring)
Dequeue multiple transfer request blocks.
Definition: xhci.c:1419
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1177
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:950
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:586
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:586
A persistent I/O buffer.
Definition: iobuf.h:37

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

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

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

2575  {
2576  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2577  struct xhci_slot *slot = endpoint->slot;
2578  struct xhci_device *xhci = slot->xhci;
2579  int rc;
2580 
2581  /* Evalulate context */
2582  if ( ( rc = xhci_evaluate_context ( xhci, slot, endpoint ) ) != 0 )
2583  return rc;
2584 
2585  return 0;
2586 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An xHCI device.
Definition: xhci.h:1066
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition: xhci.h:1157
An xHCI endpoint.
Definition: xhci.h:1161
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1165
An xHCI device slot.
Definition: xhci.h:1133
uint8_t slot
Slot.
Definition: edd.h:16
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
static int xhci_evaluate_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Evaluate context.
Definition: xhci.c:2299
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:586

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

2596  {
2597  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2598  struct xhci_device *xhci = endpoint->xhci;
2599  struct usb_setup_packet *packet;
2600  unsigned int input;
2601  size_t len;
2602  union xhci_trb trbs[ 1 /* setup */ + 1 /* possible data */ +
2603  1 /* status */ ];
2604  union xhci_trb *trb = trbs;
2605  struct xhci_trb_setup *setup;
2606  struct xhci_trb_data *data;
2607  struct xhci_trb_status *status;
2608  int rc;
2609 
2610  /* Profile message transfers */
2611  profile_start ( &xhci_message_profiler );
2612 
2613  /* Construct setup stage TRB */
2614  memset ( trbs, 0, sizeof ( trbs ) );
2615  assert ( iob_len ( iobuf ) >= sizeof ( *packet ) );
2616  packet = iobuf->data;
2617  iob_pull ( iobuf, sizeof ( *packet ) );
2618  setup = &(trb++)->setup;
2619  memcpy ( &setup->packet, packet, sizeof ( setup->packet ) );
2620  setup->len = cpu_to_le32 ( sizeof ( *packet ) );
2621  setup->flags = XHCI_TRB_IDT;
2622  setup->type = XHCI_TRB_SETUP;
2623  len = iob_len ( iobuf );
2624  input = ( packet->request & cpu_to_le16 ( USB_DIR_IN ) );
2625  if ( len )
2626  setup->direction = ( input ? XHCI_SETUP_IN : XHCI_SETUP_OUT );
2627 
2628  /* Map I/O buffer */
2629  if ( ( rc = iob_map ( iobuf, xhci->dma, len,
2630  ( input ? DMA_RX : DMA_TX ) ) ) != 0 )
2631  goto err_map;
2632 
2633  /* Construct data stage TRB, if applicable */
2634  if ( len ) {
2635  data = &(trb++)->data;
2636  data->data = cpu_to_le64 ( iob_dma ( iobuf ) );
2637  data->len = cpu_to_le32 ( len );
2638  data->type = XHCI_TRB_DATA;
2639  data->direction = ( input ? XHCI_DATA_IN : XHCI_DATA_OUT );
2640  }
2641 
2642  /* Construct status stage TRB */
2643  status = &(trb++)->status;
2644  status->flags = XHCI_TRB_IOC;
2645  status->type = XHCI_TRB_STATUS;
2646  status->direction =
2647  ( ( len && input ) ? XHCI_STATUS_OUT : XHCI_STATUS_IN );
2648 
2649  /* Enqueue TRBs */
2650  if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
2651  ( trb - trbs ) ) ) != 0 )
2652  goto err_enqueue;
2653 
2654  /* Ring the doorbell */
2655  xhci_doorbell ( &endpoint->ring );
2656 
2657  profile_stop ( &xhci_message_profiler );
2658  return 0;
2659 
2660  err_enqueue:
2661  iob_unmap ( iobuf );
2662  err_map:
2663  return rc;
2664 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:106
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_STATUS_IN
Input status direction.
Definition: xhci.h:439
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:134
A status stage transfer request block.
Definition: xhci.h:420
An xHCI device.
Definition: xhci.h:1066
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:137
Definition: bnxt_hsi.h:68
#define XHCI_SETUP_OUT
Setup stage output data direction.
Definition: xhci.h:392
#define cpu_to_le64(value)
Definition: byteswap.h:108
A data stage transfer request block.
Definition: xhci.h:395
#define XHCI_DATA_IN
Input data direction.
Definition: xhci.h:414
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:230
An xHCI endpoint.
Definition: xhci.h:1161
uint8_t direction
Transfer direction.
Definition: xhci.h:380
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
#define XHCI_TRB_STATUS
A status stage transfer request block.
Definition: xhci.h:436
#define XHCI_DATA_OUT
Output data direction.
Definition: xhci.h:417
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:411
uint32_t len
Length.
Definition: xhci.h:374
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:278
ring len
Length.
Definition: dwmac.h:231
A setup stage transfer request block.
Definition: xhci.h:370
#define XHCI_TRB_SETUP
A setup stage transfer request block.
Definition: xhci.h:386
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
Definition: iobuf.h:267
uint8_t type
Type.
Definition: xhci.h:378
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:97
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint8_t flags
Flags.
Definition: xhci.h:376
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:1390
A transfer request block.
Definition: xhci.h:682
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
A USB setup data packet.
Definition: usb.h:82
#define XHCI_TRB_IDT
Transfer request block immediate data flag.
Definition: xhci.h:340
uint8_t status
Status.
Definition: ena.h:16
uint16_t request
Request.
Definition: usb.h:84
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
void * data
Start of data.
Definition: iobuf.h:52
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1177
#define cpu_to_le16(value)
Definition: byteswap.h:106
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition: xhci.c:1436
struct usb_setup_packet packet
Setup packet.
Definition: xhci.h:372
#define XHCI_SETUP_IN
Setup stage input data direction.
Definition: xhci.h:389
#define XHCI_STATUS_OUT
Output status direction.
Definition: xhci.h:442
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1163
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
Definition: xhci.h:337
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:586
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 2673 of file xhci.c.

2673  {
2674  unsigned int count;
2675 
2676  /* Split into 64kB TRBs */
2677  count = ( ( len + XHCI_MTU - 1 ) / XHCI_MTU );
2678 
2679  /* Append a zero-length TRB if applicable */
2680  if ( zlp || ( count == 0 ) )
2681  count++;
2682 
2683  return count;
2684 }
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:27
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 2694 of file xhci.c.

2695  {
2696  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2697  struct xhci_device *xhci = endpoint->xhci;
2698  size_t len = iob_len ( iobuf );
2699  unsigned int count = xhci_endpoint_count ( len, zlp );
2700  union xhci_trb trbs[count];
2701  union xhci_trb *trb = trbs;
2702  struct xhci_trb_normal *normal;
2703  physaddr_t data;
2704  unsigned int i;
2705  size_t trb_len;
2706  int rc;
2707 
2708  /* Profile stream transfers */
2709  profile_start ( &xhci_stream_profiler );
2710 
2711  /* Map I/O buffer */
2712  if ( ( rc = iob_map ( iobuf, xhci->dma, len,
2713  ( ( ep->address & USB_DIR_IN ) ?
2714  DMA_RX : DMA_TX ) ) ) != 0 )
2715  goto err_map;
2716  data = iob_dma ( iobuf );
2717 
2718  /* Construct normal TRBs */
2719  memset ( &trbs, 0, sizeof ( trbs ) );
2720  for ( i = 0 ; i < count ; i ++ ) {
2721 
2722  /* Calculate TRB length */
2723  trb_len = XHCI_MTU;
2724  if ( trb_len > len )
2725  trb_len = len;
2726 
2727  /* Construct normal TRB */
2728  normal = &trb->normal;
2729  normal->data = cpu_to_le64 ( data );
2730  normal->len = cpu_to_le32 ( trb_len );
2731  normal->type = XHCI_TRB_NORMAL;
2732  normal->flags = XHCI_TRB_CH;
2733 
2734  /* Move to next TRB */
2735  data += trb_len;
2736  len -= trb_len;
2737  trb++;
2738  }
2739 
2740  /* Mark zero-length packet (if present) as a separate transfer */
2741  if ( zlp && ( count > 1 ) )
2742  trb[-2].normal.flags = 0;
2743 
2744  /* Generate completion for final TRB */
2745  trb[-1].normal.flags = XHCI_TRB_IOC;
2746 
2747  /* Enqueue TRBs */
2748  if ( ( rc = xhci_enqueue_multi ( &endpoint->ring, iobuf, trbs,
2749  count ) ) != 0 )
2750  goto err_enqueue;
2751 
2752  /* Ring the doorbell */
2753  xhci_doorbell ( &endpoint->ring );
2754 
2755  profile_stop ( &xhci_stream_profiler );
2756  return 0;
2757 
2758  err_enqueue:
2759  iob_unmap ( iobuf );
2760  err_map:
2761  return rc;
2762 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DMA_TX
Device will read data from host memory.
Definition: dma.h:134
struct arbelprm_completion_queue_entry normal
Definition: arbel.h:11
An xHCI device.
Definition: xhci.h:1066
#define DMA_RX
Device will write data to host memory.
Definition: dma.h:137
uint8_t flags
Flags.
Definition: xhci.h:355
#define cpu_to_le64(value)
Definition: byteswap.h:108
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:230
An xHCI endpoint.
Definition: xhci.h:1161
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:27
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:278
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:267
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:97
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
#define cpu_to_le32(value)
Definition: byteswap.h:107
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:1390
A transfer request block.
Definition: xhci.h:682
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
A normal transfer request block.
Definition: xhci.h:349
struct xhci_trb_normal normal
Normal TRB.
Definition: xhci.h:688
unsigned long physaddr_t
Definition: stdint.h:20
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1167
#define XHCI_TRB_NORMAL
A normal transfer request block.
Definition: xhci.h:363
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1177
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define XHCI_TRB_CH
Transfer request block chain flag.
Definition: xhci.h:334
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition: xhci.c:1436
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1163
static unsigned int xhci_endpoint_count(size_t len, int zlp)
Calculate number of TRBs.
Definition: xhci.c:2673
unsigned int address
Endpoint address.
Definition: usb.h:407
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
Definition: xhci.h:337
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:586
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 2777 of file xhci.c.

2777  {
2778  struct xhci_device *xhci = usb_bus_get_hostdata ( usb->port->hub->bus );
2779  struct usb_port *root_port = usb_root_hub_port ( usb );
2780  struct usb_port *tt = usb_transaction_translator ( usb );
2781  struct xhci_slot *slot;
2782  struct xhci_slot *tt_slot;
2783  size_t len;
2784  int type;
2785  int id;
2786  int rc;
2787 
2788  /* Determine applicable slot type */
2789  type = xhci_port_slot_type ( xhci, root_port->address );
2790  if ( type < 0 ) {
2791  rc = type;
2792  DBGC ( xhci, "XHCI %s-%d has no slot type\n",
2793  xhci->name, usb->port->address );
2794  goto err_type;
2795  }
2796 
2797  /* Allocate a device slot number */
2798  id = xhci_enable_slot ( xhci, type );
2799  if ( id < 0 ) {
2800  rc = id;
2801  goto err_enable_slot;
2802  }
2803  assert ( ( id > 0 ) && ( ( unsigned int ) id <= xhci->slots ) );
2804  assert ( xhci->slot[id] == NULL );
2805 
2806  /* Allocate and initialise structure */
2807  slot = zalloc ( sizeof ( *slot ) );
2808  if ( ! slot ) {
2809  rc = -ENOMEM;
2810  goto err_alloc;
2811  }
2812  usb_set_hostdata ( usb, slot );
2813  xhci->slot[id] = slot;
2814  slot->xhci = xhci;
2815  slot->usb = usb;
2816  slot->id = id;
2817  if ( tt ) {
2818  tt_slot = usb_get_hostdata ( tt->hub->usb );
2819  slot->tt_id = tt_slot->id;
2820  slot->tt_port = tt->address;
2821  }
2822 
2823  /* Allocate a device context */
2825  slot->context = dma_alloc ( xhci->dma, &slot->map, len,
2826  xhci_align ( len ) );
2827  if ( ! slot->context ) {
2828  rc = -ENOMEM;
2829  goto err_alloc_context;
2830  }
2831  memset ( slot->context, 0, len );
2832 
2833  /* Set device context base address */
2834  assert ( xhci->dcbaa.context[id] == 0 );
2835  xhci->dcbaa.context[id] = cpu_to_le64 ( dma ( &slot->map,
2836  slot->context ) );
2837 
2838  DBGC2 ( xhci, "XHCI %s slot %d device context [%08lx,%08lx) for %s\n",
2839  xhci->name, slot->id, virt_to_phys ( slot->context ),
2840  ( virt_to_phys ( slot->context ) + len ), usb->name );
2841  return 0;
2842 
2843  xhci->dcbaa.context[id] = 0;
2844  dma_free ( &slot->map, slot->context, len );
2845  err_alloc_context:
2846  xhci->slot[id] = NULL;
2847  free ( slot );
2848  err_alloc:
2849  xhci_disable_slot ( xhci, id );
2850  err_enable_slot:
2851  err_type:
2852  return rc;
2853 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1108
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:953
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1135
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
Definition: xhci.c:418
An xHCI device.
Definition: xhci.h:1066
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:399
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition: usb.h:783
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:834
#define cpu_to_le64(value)
Definition: byteswap.h:108
A USB port.
Definition: usb.h:812
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:534
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:846
static int xhci_enable_slot(struct xhci_device *xhci, unsigned int type)
Enable slot.
Definition: xhci.c:1955
static int xhci_port_slot_type(struct xhci_device *xhci, unsigned int port)
Find port slot type.
Definition: xhci.c:766
struct usb_port * port
USB port.
Definition: usb.h:726
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct usb_device * usb
USB device.
Definition: xhci.h:1137
ring len
Length.
Definition: dwmac.h:231
char name[32]
Name.
Definition: usb.h:724
uint8_t id
Request identifier.
Definition: ena.h:12
An xHCI device slot.
Definition: xhci.h:1133
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
const char * name
Name.
Definition: xhci.h:1074
unsigned int id
Slot ID.
Definition: xhci.h:1139
uint64_t * context
Context base addresses.
Definition: xhci.h:1046
uint8_t slot
Slot.
Definition: edd.h:16
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:794
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:2355
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
Definition: usb.c:2371
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1061
static int xhci_disable_slot(struct xhci_device *xhci, unsigned int slot)
Disable slot.
Definition: xhci.c:1989
#define DBGC2(...)
Definition: compiler.h:522
unsigned int address
Port address.
Definition: usb.h:816
struct usb_hub * hub
USB hub.
Definition: usb.h:814
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
struct usb_bus * bus
USB bus.
Definition: usb.h:844
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1123
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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 2860 of file xhci.c.

2860  {
2861  struct xhci_slot *slot = usb_get_hostdata ( usb );
2862  struct xhci_device *xhci = slot->xhci;
2863  size_t len = xhci_device_context_offset ( xhci, XHCI_CTX_END );
2864  unsigned int id = slot->id;
2865  int rc;
2866 
2867  /* Disable slot */
2868  if ( ( rc = xhci_disable_slot ( xhci, id ) ) != 0 ) {
2869  /* Slot is still enabled. Leak the slot context,
2870  * since the controller may still write to this
2871  * memory, and leave the DCBAA entry intact.
2872  *
2873  * If the controller later reports that this same slot
2874  * has been re-enabled, then some assertions will be
2875  * triggered.
2876  */
2877  DBGC ( xhci, "XHCI %s slot %d leaking context memory\n",
2878  xhci->name, slot->id );
2879  slot->context = NULL;
2880  }
2881 
2882  /* Free slot */
2883  if ( slot->context ) {
2884  dma_free ( &slot->map, slot->context, len );
2885  xhci->dcbaa.context[id] = 0;
2886  }
2887  xhci->slot[id] = NULL;
2888  free ( slot );
2889 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1108
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:953
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
Definition: xhci.c:418
An xHCI device.
Definition: xhci.h:1066
#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:1137
ring len
Length.
Definition: dwmac.h:231
uint8_t id
Request identifier.
Definition: ena.h:12
An xHCI device slot.
Definition: xhci.h:1133
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
const char * name
Name.
Definition: xhci.h:1074
uint64_t * context
Context base addresses.
Definition: xhci.h:1046
uint8_t slot
Slot.
Definition: edd.h:16
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:794
static int xhci_disable_slot(struct xhci_device *xhci, unsigned int slot)
Disable slot.
Definition: xhci.c:1989
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1123
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

2897  {
2898  struct xhci_slot *slot = usb_get_hostdata ( usb );
2899  struct xhci_device *xhci = slot->xhci;
2900  struct usb_port *root_port;
2901  int psiv;
2902  int rc;
2903 
2904  /* Calculate route string */
2905  slot->route = usb_route_string ( usb );
2906 
2907  /* Calculate root hub port number */
2908  root_port = usb_root_hub_port ( usb );
2909  slot->port = root_port->address;
2910 
2911  /* Calculate protocol speed ID */
2912  psiv = xhci_port_psiv ( xhci, slot->port, usb->speed );
2913  if ( psiv < 0 ) {
2914  rc = psiv;
2915  return rc;
2916  }
2917  slot->psiv = psiv;
2918 
2919  /* Address device */
2920  if ( ( rc = xhci_address_device ( xhci, slot ) ) != 0 )
2921  return rc;
2922 
2923  return 0;
2924 }
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:2113
An xHCI device.
Definition: xhci.h:1066
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:834
unsigned int speed
Device speed.
Definition: usb.h:728
static int xhci_port_psiv(struct xhci_device *xhci, unsigned int port, unsigned int speed)
Find protocol speed ID value.
Definition: xhci.c:854
A USB port.
Definition: usb.h:812
struct usb_device * usb
USB device.
Definition: xhci.h:1137
An xHCI device slot.
Definition: xhci.h:1133
unsigned int usb_route_string(struct usb_device *usb)
Get USB route string.
Definition: usb.c:2335
uint8_t slot
Slot.
Definition: edd.h:16
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:794
struct usb_port * usb_root_hub_port(struct usb_device *usb)
Get USB root hub port.
Definition: usb.c:2355
unsigned int address
Port address.
Definition: usb.h:816

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

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

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

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

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

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

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

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

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

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

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

3077  {
3078  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3079  struct usb_port *port;
3080  uint32_t portsc;
3081  unsigned int i;
3082 
3083  /* Enable power to all ports */
3084  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3085  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( i ) );
3086  portsc &= XHCI_PORTSC_PRESERVE;
3087  portsc |= XHCI_PORTSC_PP;
3088  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( i ) );
3089  }
3090 
3091  /* xHCI spec requires us to potentially wait 20ms after
3092  * enabling power to a port.
3093  */
3095 
3096  /* USB3 ports may power up as Disabled */
3097  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3098  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( i ) );
3099  port = usb_port ( hub, i );
3100  if ( ( port->protocol >= USB_PROTO_3_0 ) &&
3101  ( ( portsc & XHCI_PORTSC_PLS_MASK ) ==
3103  /* Force link state to RxDetect */
3104  portsc &= XHCI_PORTSC_PRESERVE;
3106  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( i ) );
3107  }
3108  }
3109 
3110  /* Some xHCI cards seem to require an additional delay after
3111  * setting the link state to RxDetect.
3112  */
3114 
3115  return 0;
3116 }
unsigned int ports
Number of ports.
Definition: xhci.h:1092
An xHCI device.
Definition: xhci.h:1066
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:283
#define XHCI_PORTSC_PP
Port power.
Definition: xhci.h:227
A USB port.
Definition: usb.h:812
u8 port
Port number.
Definition: CIB_PRM.h:31
USB 3.0.
Definition: usb.h:24
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:242
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define XHCI_PORTSC_PLS_RXDETECT
RxDetect port link state.
Definition: xhci.h:221
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:203
#define XHCI_PORT_POWER_DELAY_MS
Time to delay after enabling power to a port.
Definition: xhci.h:230
struct usb_hub * hub
USB hub.
Definition: usb.h:814
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:959
#define XHCI_PORTSC_PLS_DISABLED
Disabled port link state.
Definition: xhci.h:218
#define XHCI_LINK_STATE_DELAY_MS
Time to delay after writing the port link state.
Definition: xhci.h:245
void * op
Operational registers.
Definition: xhci.h:1081
#define XHCI_PORTSC_PLS_MASK
Port link state mask.
Definition: xhci.h:224
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:947

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

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

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

3135  {
3136  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3137  uint32_t portsc;
3138  unsigned int i;
3139 
3140  /* Reset port */
3141  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3142  portsc &= XHCI_PORTSC_PRESERVE;
3143  portsc |= XHCI_PORTSC_PR;
3144  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3145 
3146  /* Wait for port to become enabled */
3147  for ( i = 0 ; i < XHCI_PORT_RESET_MAX_WAIT_MS ; i++ ) {
3148 
3149  /* Check port status */
3150  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3151  if ( portsc & XHCI_PORTSC_PED )
3152  return 0;
3153 
3154  /* Delay */
3155  mdelay ( 1 );
3156  }
3157 
3158  DBGC ( xhci, "XHCI %s-%d timed out waiting for port to enable\n",
3159  xhci->name, port->address );
3160  return -ETIMEDOUT;
3161 }
An xHCI device.
Definition: xhci.h:1066
#define XHCI_PORT_RESET_MAX_WAIT_MS
Maximum time to wait for a port reset to complete.
Definition: xhci.h:1015
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:283
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:1074
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:203
#define XHCI_PORTSC_PR
Port reset.
Definition: xhci.h:212
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:209
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * op
Operational registers.
Definition: xhci.h:1081
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:947

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

3170  {
3171  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3172  uint32_t portsc;
3173 
3174  /* Disable port */
3175  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3176  portsc &= XHCI_PORTSC_PRESERVE;
3177  portsc |= XHCI_PORTSC_PED;
3178  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3179 
3180  /* Allow time for link state to stabilise */
3182 
3183  /* Set link state to RxDetect for USB3 ports */
3184  if ( port->protocol >= USB_PROTO_3_0 ) {
3185  portsc &= XHCI_PORTSC_PRESERVE;
3186  portsc |= ( XHCI_PORTSC_PLS_RXDETECT | XHCI_PORTSC_LWS );
3187  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3188  }
3189 
3190  /* Allow time for link state to stabilise */
3192 
3193  return 0;
3194 }
An xHCI device.
Definition: xhci.h:1066
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:283
u8 port
Port number.
Definition: CIB_PRM.h:31
USB 3.0.
Definition: usb.h:24
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:242
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define XHCI_PORTSC_PLS_RXDETECT
RxDetect port link state.
Definition: xhci.h:221
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:203
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:209
#define XHCI_LINK_STATE_DELAY_MS
Time to delay after writing the port link state.
Definition: xhci.h:245
void * op
Operational registers.
Definition: xhci.h:1081
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:947

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

3203  {
3204  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3205  uint32_t portsc;
3206  unsigned int psiv;
3207  int ccs;
3208  int ped;
3209  int csc;
3210  int speed;
3211  int rc;
3212 
3213  /* Read port status */
3214  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port->address ) );
3215  DBGC2 ( xhci, "XHCI %s-%d status is %08x\n",
3216  xhci->name, port->address, portsc );
3217  ccs = ( portsc & XHCI_PORTSC_CCS );
3218  ped = ( portsc & XHCI_PORTSC_PED );
3219  csc = ( portsc & XHCI_PORTSC_CSC );
3220  psiv = XHCI_PORTSC_PSIV ( portsc );
3221 
3222  /* Record disconnections and clear changes */
3223  port->disconnected |= csc;
3224  portsc &= ( XHCI_PORTSC_PRESERVE | XHCI_PORTSC_CHANGE );
3225  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( port->address ) );
3226 
3227  /* Port speed is not valid unless port is connected */
3228  if ( ! ccs ) {
3229  port->speed = USB_SPEED_NONE;
3230  return 0;
3231  }
3232 
3233  /* For USB2 ports, the PSIV field is not valid until the port
3234  * completes reset and becomes enabled.
3235  */
3236  if ( ( port->protocol < USB_PROTO_3_0 ) && ! ped ) {
3237  port->speed = USB_SPEED_FULL;
3238  return 0;
3239  }
3240 
3241  /* Get port speed and map to generic USB speed */
3242  speed = xhci_port_speed ( xhci, port->address, psiv );
3243  if ( speed < 0 ) {
3244  rc = speed;
3245  return rc;
3246  }
3247 
3248  port->speed = speed;
3249  return 0;
3250 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_PORTSC_PSIV(portsc)
Port speed ID value.
Definition: xhci.h:233
An xHCI device.
Definition: xhci.h:1066
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:248
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
Definition: xhci.h:283
#define XHCI_PORTSC_CCS
Current connect status.
Definition: xhci.h:206
u8 port
Port number.
Definition: CIB_PRM.h:31
USB 3.0.
Definition: usb.h:24
Not connected.
Definition: usb.h:46
#define XHCI_PORTSC_CHANGE
Port status change mask.
Definition: xhci.h:269
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:1074
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:203
#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:790
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:209
Full speed (12Mbps)
Definition: usb.h:50
void * op
Operational registers.
Definition: xhci.h:1081
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:947

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

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

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

3318  {
3319  struct usb_port *port;
3320  unsigned int i;
3321  int rc;
3322 
3323  /* Reset device */
3324  if ( ( rc = xhci_reset ( xhci ) ) != 0 )
3325  goto err_reset;
3326 
3327  /* Allocate USB bus */
3328  xhci->bus = alloc_usb_bus ( xhci->dev, xhci->ports, XHCI_MTU,
3329  &xhci_operations );
3330  if ( ! xhci->bus ) {
3331  rc = -ENOMEM;
3332  goto err_alloc_bus;
3333  }
3334  usb_bus_set_hostdata ( xhci->bus, xhci );
3335  usb_hub_set_drvdata ( xhci->bus->hub, xhci );
3336 
3337  /* Set port protocols */
3338  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3339  port = usb_port ( xhci->bus->hub, i );
3340  port->protocol = xhci_port_protocol ( xhci, i );
3341  }
3342 
3343  /* Register USB bus */
3344  if ( ( rc = register_usb_bus ( xhci->bus ) ) != 0 )
3345  goto err_register;
3346 
3347  return 0;
3348 
3349  unregister_usb_bus ( xhci->bus );
3350  err_register:
3351  free_usb_bus ( xhci->bus );
3352  err_alloc_bus:
3353  xhci_reset ( xhci );
3354  err_reset:
3355  return rc;
3356 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int ports
Number of ports.
Definition: xhci.h:1092
struct usb_bus * alloc_usb_bus(struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
Allocate USB bus.
Definition: usb.c:2094
struct device * dev
Underlying hardware device.
Definition: xhci.h:1070
struct usb_bus * bus
USB bus.
Definition: xhci.h:1126
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1050
A USB port.
Definition: usb.h:812
#define ENOMEM
Not enough space.
Definition: errno.h:534
u8 port
Port number.
Definition: CIB_PRM.h:31
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2170
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:27
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1141
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2130
static unsigned int xhci_port_protocol(struct xhci_device *xhci, unsigned int port)
Find port protocol.
Definition: xhci.c:705
struct usb_hub * hub
Root hub.
Definition: usb.h:994
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:936
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:959
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2194
static struct usb_host_operations xhci_operations
USB host controller operations.
Definition: xhci.c:3279

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

3363  {
3364  struct usb_bus *bus = xhci->bus;
3365 
3366  /* Unregister and free USB bus */
3367  unregister_usb_bus ( bus );
3368  free_usb_bus ( bus );
3369 
3370  /* Reset device */
3371  xhci_reset ( xhci );
3372 }
struct usb_bus * bus
USB bus.
Definition: xhci.h:1126
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2170
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1141
A USB bus.
Definition: usb.h:965
uint8_t bus
Bus.
Definition: edd.h:14
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2194

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

3387  {
3388  struct xhci_pch *pch = &xhci->pch;
3389  uint32_t xusb2pr;
3390  uint32_t xusb2prm;
3392  uint32_t usb3prm;
3393 
3394  /* Enable SuperSpeed capability. Do this before rerouting
3395  * USB2 ports, so that USB3 devices connect at SuperSpeed.
3396  */
3398  pci_read_config_dword ( pci, XHCI_PCH_USB3PRM, &usb3prm );
3399  if ( usb3prm & ~usb3pssen ) {
3400  DBGC ( xhci, "XHCI %s enabling SuperSpeed on ports %08x\n",
3401  xhci->name, ( usb3prm & ~usb3pssen ) );
3402  }
3403  pch->usb3pssen = usb3pssen;
3404  usb3pssen |= usb3prm;
3406 
3407  /* Route USB2 ports from EHCI to xHCI */
3409  pci_read_config_dword ( pci, XHCI_PCH_XUSB2PRM, &xusb2prm );
3410  if ( xusb2prm & ~xusb2pr ) {
3411  DBGC ( xhci, "XHCI %s routing ports %08x from EHCI to xHCI\n",
3412  xhci->name, ( xusb2prm & ~xusb2pr ) );
3413  }
3414  pch->xusb2pr = xusb2pr;
3415  xusb2pr |= xusb2prm;
3417 }
#define XHCI_PCH_XUSB2PR
Intel PCH USB2 port routing register.
Definition: xhci.h:1029
#define DBGC(...)
Definition: compiler.h:505
Intel PCH quirk.
Definition: xhci.h:1018
struct xhci_pch pch
Intel PCH quirk.
Definition: xhci.h:1129
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:1020
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
Definition: xhci.h:1022
const char * name
Name.
Definition: xhci.h:1074
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_PCH_USB3PSSEN
Intel PCH SuperSpeed enable register.
Definition: xhci.h:1035
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:1038
#define XHCI_PCH_XUSB2PRM
Intel PCH USB2 port routing mask register.
Definition: xhci.h:1032

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

3425  {
3426  struct xhci_pch *pch = &xhci->pch;
3427 
3428  /* Restore USB2 port routing to original state */
3430 
3431  /* Restore SuperSpeed capability to original state */
3433 }
#define XHCI_PCH_XUSB2PR
Intel PCH USB2 port routing register.
Definition: xhci.h:1029
Intel PCH quirk.
Definition: xhci.h:1018
struct xhci_pch pch
Intel PCH quirk.
Definition: xhci.h:1129
uint32_t xusb2pr
USB2 port routing register original value.
Definition: xhci.h:1020
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
Definition: xhci.h:1022
#define XHCI_PCH_USB3PSSEN
Intel PCH SuperSpeed enable register.
Definition: xhci.h:1035
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 3441 of file xhci.c.

3441  {
3442  struct xhci_device *xhci;
3443  unsigned long bar_start;
3444  size_t bar_size;
3445  int rc;
3446 
3447  /* Allocate and initialise structure */
3448  xhci = zalloc ( sizeof ( *xhci ) );
3449  if ( ! xhci ) {
3450  rc = -ENOMEM;
3451  goto err_alloc;
3452  }
3453  xhci->dev = &pci->dev;
3454  xhci->dma = &pci->dma;
3455  xhci->quirks = pci->id->driver_data;
3456 
3457  /* Fix up PCI device */
3458  adjust_pci_device ( pci );
3459 
3460  /* Map registers */
3461  bar_start = pci_bar_start ( pci, XHCI_BAR );
3462  bar_size = pci_bar_size ( pci, XHCI_BAR );
3463  xhci->regs = pci_ioremap ( pci, bar_start, bar_size );
3464  if ( ! xhci->regs ) {
3465  rc = -ENODEV;
3466  goto err_ioremap;
3467  }
3468 
3469  /* Initialise xHCI device */
3470  xhci_init ( xhci );
3471 
3472  /* Initialise USB legacy support and claim ownership */
3473  xhci_legacy_init ( xhci );
3474  xhci_legacy_claim ( xhci );
3475 
3476  /* Fix Intel PCH-specific quirks, if applicable */
3477  if ( xhci->quirks & XHCI_PCH )
3478  xhci_pch_fix ( xhci, pci );
3479 
3480  /* Register xHCI device */
3481  if ( ( rc = xhci_register ( xhci ) ) != 0 )
3482  goto err_register;
3483 
3484  pci_set_drvdata ( pci, xhci );
3485  return 0;
3486 
3487  xhci_unregister ( xhci );
3488  err_register:
3489  if ( xhci->quirks & XHCI_PCH )
3490  xhci_pch_undo ( xhci, pci );
3491  xhci_legacy_release ( xhci );
3492  iounmap ( xhci->regs );
3493  err_ioremap:
3494  free ( xhci );
3495  err_alloc:
3496  return rc;
3497 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:214
int xhci_register(struct xhci_device *xhci)
Register xHCI controller.
Definition: xhci.c:3318
An xHCI device.
Definition: xhci.h:1066
void * regs
Registers.
Definition: xhci.h:1068
unsigned long driver_data
Arbitrary driver data.
Definition: pci.h:182
struct device * dev
Underlying hardware device.
Definition: xhci.h:1070
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition: pci.c:163
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:240
struct device dev
Generic device.
Definition: pci.h:212
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:365
#define ENOMEM
Not enough space.
Definition: errno.h:534
void xhci_init(struct xhci_device *xhci)
Initialise device.
Definition: xhci.c:263
#define XHCI_PCH
Intel PCH quirk flag.
Definition: xhci.h:1026
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
static void xhci_legacy_claim(struct xhci_device *xhci)
Claim ownership from BIOS.
Definition: xhci.c:570
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
#define ENODEV
No such device.
Definition: errno.h:509
#define XHCI_BAR
xHCI PCI BAR
Definition: xhci.h:30
static void xhci_pch_fix(struct xhci_device *xhci, struct pci_device *pci)
Fix Intel PCH-specific quirks.
Definition: xhci.c:3387
struct pci_device_id * id
Driver device ID.
Definition: pci.h:247
static void xhci_pch_undo(struct xhci_device *xhci, struct pci_device *pci)
Undo Intel PCH-specific quirk fixes.
Definition: xhci.c:3425
void iounmap(volatile const void *io_addr)
Unmap I/O address.
struct dma_device * dma
DMA device.
Definition: xhci.h:1072
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:539
unsigned int quirks
Quirks.
Definition: xhci.h:1076
void xhci_unregister(struct xhci_device *xhci)
Unregister xHCI controller.
Definition: xhci.c:3363
static void xhci_legacy_release(struct xhci_device *xhci)
Release ownership back to BIOS.
Definition: xhci.c:617

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

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

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

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

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 47 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 532 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 3279 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:1041
#define XHCI_PCH
Intel PCH quirk flag.
Definition: xhci.h:1026
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:307

XHCI PCI device IDs.

Definition at line 3538 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:202
static struct pci_device_id xhci_ids[]
XHCI PCI device IDs.
Definition: xhci.c:3538
#define PCI_CLASS_SERIAL_USB_XHCI
xHCI USB controller
Definition: pci.h:140
#define PCI_CLASS_SERIAL
Definition: Pci22.h:266
static int xhci_probe(struct pci_device *pci)
Probe PCI device.
Definition: xhci.c:3441
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:272
static void xhci_remove(struct pci_device *pci)
Remove PCI device.
Definition: xhci.c:3504

XHCI PCI driver.

Definition at line 3545 of file xhci.c.