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/umalloc.h>
#include <ipxe/pci.h>
#include <ipxe/usb.h>
#include <ipxe/init.h>
#include <ipxe/profile.h>
#include "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)
 
static void xhci_init (struct xhci_device *xhci, void *regs)
 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_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)
 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...
 
static void xhci_pch_fix (struct xhci_device *xhci, struct pci_device *pci)
 Fix Intel PCH-specific quirks. More...
 
static void xhci_pch_undo (struct xhci_device *xhci, struct pci_device *pci)
 Undo Intel PCH-specific quirk fixes. More...
 
static int xhci_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void xhci_remove (struct pci_device *pci)
 Remove PCI device. More...
 
static void xhci_shutdown (int booting)
 Prepare for exit. More...
 
struct startup_fn xhci_startup __startup_fn (STARTUP_LATE)
 Startup/shutdown function. More...
 

Variables

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

Detailed Description

USB eXtensible Host Controller Interface (xHCI) driver.

Definition in file xhci.c.

Macro Definition Documentation

◆ EIO_DATA

#define EIO_DATA   __einfo_error ( EINFO_EIO_DATA )

Definition at line 64 of file xhci.c.

◆ EINFO_EIO_DATA

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

Definition at line 66 of file xhci.c.

◆ EIO_BABBLE

#define EIO_BABBLE   __einfo_error ( EINFO_EIO_BABBLE )

Definition at line 69 of file xhci.c.

◆ EINFO_EIO_BABBLE

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

Definition at line 71 of file xhci.c.

◆ EIO_USB

#define EIO_USB   __einfo_error ( EINFO_EIO_USB )

Definition at line 74 of file xhci.c.

◆ EINFO_EIO_USB

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

Definition at line 76 of file xhci.c.

◆ EIO_TRB

#define EIO_TRB   __einfo_error ( EINFO_EIO_TRB )

Definition at line 79 of file xhci.c.

◆ EINFO_EIO_TRB

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

Definition at line 81 of file xhci.c.

◆ EIO_STALL

#define EIO_STALL   __einfo_error ( EINFO_EIO_STALL )

Definition at line 84 of file xhci.c.

◆ EINFO_EIO_STALL

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

Definition at line 86 of file xhci.c.

◆ EIO_RESOURCE

#define EIO_RESOURCE   __einfo_error ( EINFO_EIO_RESOURCE )

Definition at line 89 of file xhci.c.

◆ EINFO_EIO_RESOURCE

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

Definition at line 91 of file xhci.c.

◆ EIO_BANDWIDTH

#define EIO_BANDWIDTH   __einfo_error ( EINFO_EIO_BANDWIDTH )

Definition at line 94 of file xhci.c.

◆ EINFO_EIO_BANDWIDTH

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

Definition at line 96 of file xhci.c.

◆ EIO_NO_SLOTS

#define EIO_NO_SLOTS   __einfo_error ( EINFO_EIO_NO_SLOTS )

Definition at line 99 of file xhci.c.

◆ EINFO_EIO_NO_SLOTS

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

Definition at line 101 of file xhci.c.

◆ EIO_STREAM_TYPE

#define EIO_STREAM_TYPE   __einfo_error ( EINFO_EIO_STREAM_TYPE )

Definition at line 104 of file xhci.c.

◆ EINFO_EIO_STREAM_TYPE

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

Definition at line 106 of file xhci.c.

◆ EIO_SLOT

#define EIO_SLOT   __einfo_error ( EINFO_EIO_SLOT )

Definition at line 109 of file xhci.c.

◆ EINFO_EIO_SLOT

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

Definition at line 111 of file xhci.c.

◆ EIO_ENDPOINT

#define EIO_ENDPOINT   __einfo_error ( EINFO_EIO_ENDPOINT )

Definition at line 114 of file xhci.c.

◆ EINFO_EIO_ENDPOINT

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

Definition at line 116 of file xhci.c.

◆ EIO_SHORT

#define EIO_SHORT   __einfo_error ( EINFO_EIO_SHORT )

Definition at line 119 of file xhci.c.

◆ EINFO_EIO_SHORT

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

Definition at line 121 of file xhci.c.

◆ EIO_UNDERRUN

#define EIO_UNDERRUN   __einfo_error ( EINFO_EIO_UNDERRUN )

Definition at line 124 of file xhci.c.

◆ EINFO_EIO_UNDERRUN

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

Definition at line 126 of file xhci.c.

◆ EIO_OVERRUN

#define EIO_OVERRUN   __einfo_error ( EINFO_EIO_OVERRUN )

Definition at line 129 of file xhci.c.

◆ EINFO_EIO_OVERRUN

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

Definition at line 131 of file xhci.c.

◆ EIO_VF_RING_FULL

#define EIO_VF_RING_FULL   __einfo_error ( EINFO_EIO_VF_RING_FULL )

Definition at line 134 of file xhci.c.

◆ EINFO_EIO_VF_RING_FULL

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

Definition at line 136 of file xhci.c.

◆ EIO_PARAMETER

#define EIO_PARAMETER   __einfo_error ( EINFO_EIO_PARAMETER )

Definition at line 139 of file xhci.c.

◆ EINFO_EIO_PARAMETER

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

Definition at line 141 of file xhci.c.

◆ EIO_BANDWIDTH_OVERRUN

#define EIO_BANDWIDTH_OVERRUN   __einfo_error ( EINFO_EIO_BANDWIDTH_OVERRUN )

Definition at line 144 of file xhci.c.

◆ EINFO_EIO_BANDWIDTH_OVERRUN

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

Definition at line 146 of file xhci.c.

◆ EIO_CONTEXT

#define EIO_CONTEXT   __einfo_error ( EINFO_EIO_CONTEXT )

Definition at line 149 of file xhci.c.

◆ EINFO_EIO_CONTEXT

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

Definition at line 151 of file xhci.c.

◆ EIO_NO_PING

#define EIO_NO_PING   __einfo_error ( EINFO_EIO_NO_PING )

Definition at line 154 of file xhci.c.

◆ EINFO_EIO_NO_PING

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

Definition at line 156 of file xhci.c.

◆ EIO_RING_FULL

#define EIO_RING_FULL   __einfo_error ( EINFO_EIO_RING_FULL )

Definition at line 159 of file xhci.c.

◆ EINFO_EIO_RING_FULL

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

Definition at line 161 of file xhci.c.

◆ EIO_INCOMPATIBLE

#define EIO_INCOMPATIBLE   __einfo_error ( EINFO_EIO_INCOMPATIBLE )

Definition at line 164 of file xhci.c.

◆ EINFO_EIO_INCOMPATIBLE

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

Definition at line 166 of file xhci.c.

◆ EIO_MISSED

#define EIO_MISSED   __einfo_error ( EINFO_EIO_MISSED )

Definition at line 169 of file xhci.c.

◆ EINFO_EIO_MISSED

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

Definition at line 171 of file xhci.c.

◆ EIO_CMD_STOPPED

#define EIO_CMD_STOPPED   __einfo_error ( EINFO_EIO_CMD_STOPPED )

Definition at line 174 of file xhci.c.

◆ EINFO_EIO_CMD_STOPPED

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

Definition at line 176 of file xhci.c.

◆ EIO_CMD_ABORTED

#define EIO_CMD_ABORTED   __einfo_error ( EINFO_EIO_CMD_ABORTED )

Definition at line 179 of file xhci.c.

◆ EINFO_EIO_CMD_ABORTED

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

Definition at line 181 of file xhci.c.

◆ EIO_STOP

#define EIO_STOP   __einfo_error ( EINFO_EIO_STOP )

Definition at line 184 of file xhci.c.

◆ EINFO_EIO_STOP

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

Definition at line 186 of file xhci.c.

◆ EIO_STOP_LEN

#define EIO_STOP_LEN   __einfo_error ( EINFO_EIO_STOP_LEN )

Definition at line 189 of file xhci.c.

◆ EINFO_EIO_STOP_LEN

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

Definition at line 191 of file xhci.c.

◆ EIO_STOP_SHORT

#define EIO_STOP_SHORT   __einfo_error ( EINFO_EIO_STOP_SHORT )

Definition at line 194 of file xhci.c.

◆ EINFO_EIO_STOP_SHORT

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

Definition at line 196 of file xhci.c.

◆ EIO_LATENCY

#define EIO_LATENCY   __einfo_error ( EINFO_EIO_LATENCY )

Definition at line 199 of file xhci.c.

◆ EINFO_EIO_LATENCY

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

Definition at line 201 of file xhci.c.

◆ EIO_ISOCH

#define EIO_ISOCH   __einfo_error ( EINFO_EIO_ISOCH )

Definition at line 204 of file xhci.c.

◆ EINFO_EIO_ISOCH

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

Definition at line 206 of file xhci.c.

◆ EPROTO_LOST

#define EPROTO_LOST   __einfo_error ( EINFO_EPROTO_LOST )

Definition at line 209 of file xhci.c.

◆ EINFO_EPROTO_LOST

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

Definition at line 211 of file xhci.c.

◆ EPROTO_UNDEFINED

#define EPROTO_UNDEFINED   __einfo_error ( EINFO_EPROTO_UNDEFINED )

Definition at line 214 of file xhci.c.

◆ EINFO_EPROTO_UNDEFINED

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

Definition at line 216 of file xhci.c.

◆ EPROTO_STREAM_ID

#define EPROTO_STREAM_ID   __einfo_error ( EINFO_EPROTO_STREAM_ID )

Definition at line 219 of file xhci.c.

◆ EINFO_EPROTO_STREAM_ID

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

Definition at line 221 of file xhci.c.

◆ EPROTO_SECONDARY

#define EPROTO_SECONDARY   __einfo_error ( EINFO_EPROTO_SECONDARY )

Definition at line 224 of file xhci.c.

◆ EINFO_EPROTO_SECONDARY

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

Definition at line 226 of file xhci.c.

◆ EPROTO_SPLIT

#define EPROTO_SPLIT   __einfo_error ( EINFO_EPROTO_SPLIT )

Definition at line 229 of file xhci.c.

◆ EINFO_EPROTO_SPLIT

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

Definition at line 231 of file xhci.c.

◆ ECODE

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

Definition at line 234 of file xhci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ xhci_init()

static void xhci_init ( struct xhci_device xhci,
void *  regs 
)
static

Initialise device.

Parameters
xhcixHCI device
regsMMIO registers

Definition at line 265 of file xhci.c.

265  {
266  uint32_t hcsparams1;
267  uint32_t hcsparams2;
268  uint32_t hccparams1;
269  uint32_t pagesize;
270  size_t caplength;
271  size_t rtsoff;
272  size_t dboff;
273 
274  /* Locate capability, operational, runtime, and doorbell registers */
275  xhci->cap = regs;
276  caplength = readb ( xhci->cap + XHCI_CAP_CAPLENGTH );
277  rtsoff = readl ( xhci->cap + XHCI_CAP_RTSOFF );
278  dboff = readl ( xhci->cap + XHCI_CAP_DBOFF );
279  xhci->op = ( xhci->cap + caplength );
280  xhci->run = ( xhci->cap + rtsoff );
281  xhci->db = ( xhci->cap + dboff );
282  DBGC2 ( xhci, "XHCI %s cap %08lx op %08lx run %08lx db %08lx\n",
283  xhci->name, virt_to_phys ( xhci->cap ),
284  virt_to_phys ( xhci->op ), virt_to_phys ( xhci->run ),
285  virt_to_phys ( xhci->db ) );
286 
287  /* Read structural parameters 1 */
288  hcsparams1 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS1 );
289  xhci->slots = XHCI_HCSPARAMS1_SLOTS ( hcsparams1 );
290  xhci->intrs = XHCI_HCSPARAMS1_INTRS ( hcsparams1 );
291  xhci->ports = XHCI_HCSPARAMS1_PORTS ( hcsparams1 );
292  DBGC ( xhci, "XHCI %s has %d slots %d intrs %d ports\n",
293  xhci->name, xhci->slots, xhci->intrs, xhci->ports );
294 
295  /* Read structural parameters 2 */
296  hcsparams2 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS2 );
297  xhci->scratchpads = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
298  DBGC2 ( xhci, "XHCI %s needs %d scratchpads\n",
299  xhci->name, xhci->scratchpads );
300 
301  /* Read capability parameters 1 */
302  hccparams1 = readl ( xhci->cap + XHCI_CAP_HCCPARAMS1 );
303  xhci->addr64 = XHCI_HCCPARAMS1_ADDR64 ( hccparams1 );
304  xhci->csz_shift = XHCI_HCCPARAMS1_CSZ_SHIFT ( hccparams1 );
305  xhci->xecp = XHCI_HCCPARAMS1_XECP ( hccparams1 );
306 
307  /* Read page size */
308  pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
309  xhci->pagesize = XHCI_PAGESIZE ( pagesize );
310  assert ( xhci->pagesize != 0 );
311  assert ( ( ( xhci->pagesize ) & ( xhci->pagesize - 1 ) ) == 0 );
312  DBGC2 ( xhci, "XHCI %s page size %zd bytes\n",
313  xhci->name, xhci->pagesize );
314 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
unsigned int ports
Number of ports.
Definition: xhci.h:1061
void * run
Runtime registers.
Definition: xhci.h:1052
#define XHCI_HCSPARAMS1_PORTS(params)
Number of ports.
Definition: xhci.h:49
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_HCSPARAMS1_INTRS(params)
Number of interrupters.
Definition: xhci.h:46
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
unsigned int slots
Number of device slots.
Definition: xhci.h:1057
#define XHCI_CAP_RTSOFF
Runtime register space offset.
Definition: xhci.h:74
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int scratchpads
Number of page-sized scratchpad buffers.
Definition: xhci.h:1064
const char * name
Name.
Definition: xhci.h:1043
#define XHCI_HCCPARAMS1_XECP(params)
xHCI extended capabilities pointer
Definition: xhci.h:68
#define XHCI_HCCPARAMS1_ADDR64(params)
64-bit addressing capability
Definition: xhci.h:62
#define XHCI_CAP_CAPLENGTH
Capability register length.
Definition: xhci.h:34
unsigned int intrs
Number of interrupters.
Definition: xhci.h:1059
#define XHCI_HCSPARAMS1_SLOTS(params)
Number of device slots.
Definition: xhci.h:43
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1048
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1071
#define XHCI_OP_PAGESIZE
Page size register.
Definition: xhci.h:170
struct i386_regs regs
Definition: registers.h:15
int addr64
64-bit addressing capability
Definition: xhci.h:1067
#define XHCI_PAGESIZE(pagesize)
Page size.
Definition: xhci.h:173
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1074
#define XHCI_CAP_DBOFF
Doorbell offset.
Definition: xhci.h:71
#define XHCI_HCCPARAMS1_CSZ_SHIFT(params)
Context size shift.
Definition: xhci.h:65
#define XHCI_CAP_HCSPARAMS1
Structural parameters 1.
Definition: xhci.h:40
#define XHCI_CAP_HCCPARAMS1
Capability parameters.
Definition: xhci.h:59
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1069
void * db
Doorbell registers.
Definition: xhci.h:1054
#define XHCI_HCSPARAMS2_SCRATCHPADS(params)
Number of page-sized scratchpad buffers.
Definition: xhci.h:55
#define XHCI_CAP_HCSPARAMS2
Structural parameters 2.
Definition: xhci.h:52
void * op
Operational registers.
Definition: xhci.h:1050

References xhci_device::addr64, assert(), xhci_device::cap, xhci_device::csz_shift, xhci_device::db, DBGC, DBGC2, xhci_device::intrs, xhci_device::name, xhci_device::op, xhci_device::pagesize, xhci_device::ports, readb(), readl(), regs, xhci_device::run, xhci_device::scratchpads, xhci_device::slots, virt_to_phys(), 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 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 324 of file xhci.c.

326  {
327  uint32_t xecp;
328  unsigned int next;
329 
330  /* Locate the extended capability */
331  while ( 1 ) {
332 
333  /* Locate first or next capability as applicable */
334  if ( offset ) {
335  xecp = readl ( xhci->cap + offset );
336  next = XHCI_XECP_NEXT ( xecp );
337  } else {
338  next = xhci->xecp;
339  }
340  if ( ! next )
341  return 0;
342  offset += next;
343 
344  /* Check if this is the requested capability */
345  xecp = readl ( xhci->cap + offset );
346  if ( XHCI_XECP_ID ( xecp ) == id )
347  return offset;
348  }
349 }
#define XHCI_XECP_NEXT(xecp)
Next xHCI extended capability pointer.
Definition: xhci.h:80
uint32_t next
Next descriptor address.
Definition: myson.h:18
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define XHCI_XECP_ID(xecp)
xHCI extended capability ID
Definition: xhci.h:77
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1048
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1071

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

360  {
361 
362  /* If this is a 32-bit build, then this can never fail
363  * (allowing the compiler to optimise out the error path).
364  */
365  if ( sizeof ( value ) <= sizeof ( uint32_t ) ) {
366  writel ( value, reg );
367  writel ( 0, ( reg + sizeof ( uint32_t ) ) );
368  return 0;
369  }
370 
371  /* If the device does not support 64-bit addresses and this
372  * address is outside the 32-bit address space, then fail.
373  */
374  if ( ( value & ~0xffffffffULL ) && ! xhci->addr64 ) {
375  DBGC ( xhci, "XHCI %s cannot access address %lx\n",
376  xhci->name, value );
377  return -ENOTSUP;
378  }
379 
380  /* If this is a 64-bit build, then writeq() is available */
381  writeq ( value, reg );
382  return 0;
383 }
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static unsigned int unsigned int reg
Definition: intel.h:245
const char * name
Name.
Definition: xhci.h:1043
unsigned int uint32_t
Definition: stdint.h:12
int addr64
64-bit addressing capability
Definition: xhci.h:1067
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 394 of file xhci.c.

394  {
395  size_t align;
396 
397  /* Align to own length (rounded up to a power of two) */
398  align = ( 1 << fls ( len - 1 ) );
399 
400  /* Round up to XHCI_MIN_ALIGN if needed */
401  if ( align < XHCI_MIN_ALIGN )
402  align = XHCI_MIN_ALIGN;
403 
404  return align;
405 }
uint32_t len
Length.
Definition: ena.h:14
#define XHCI_MIN_ALIGN
Minimum alignment required for data structures.
Definition: xhci.h:25
#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 413 of file xhci.c.

414  {
415 
416  return ( XHCI_DCI ( ctx ) << xhci->csz_shift );
417 }
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
#define XHCI_DCI(ctx)
Device context index.
Definition: xhci.h:951
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1069

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

426  {
427 
428  return ( XHCI_ICI ( ctx ) << xhci->csz_shift );
429 }
#define XHCI_ICI(ctx)
Input context index.
Definition: xhci.h:954
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
unsigned int csz_shift
Context size shift.
Definition: xhci.h:1069

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

443  {
444  uint32_t usbcmd;
445  uint32_t usbsts;
446  uint32_t pagesize;
447  uint32_t dnctrl;
448  uint32_t config;
449 
450  /* Do nothing unless debugging is enabled */
451  if ( ! DBG_LOG )
452  return;
453 
454  /* Dump USBCMD */
455  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
456  DBGC ( xhci, "XHCI %s USBCMD %08x%s%s\n", xhci->name, usbcmd,
457  ( ( usbcmd & XHCI_USBCMD_RUN ) ? " run" : "" ),
458  ( ( usbcmd & XHCI_USBCMD_HCRST ) ? " hcrst" : "" ) );
459 
460  /* Dump USBSTS */
461  usbsts = readl ( xhci->op + XHCI_OP_USBSTS );
462  DBGC ( xhci, "XHCI %s USBSTS %08x%s\n", xhci->name, usbsts,
463  ( ( usbsts & XHCI_USBSTS_HCH ) ? " hch" : "" ) );
464 
465  /* Dump PAGESIZE */
466  pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
467  DBGC ( xhci, "XHCI %s PAGESIZE %08x\n", xhci->name, pagesize );
468 
469  /* Dump DNCTRL */
470  dnctrl = readl ( xhci->op + XHCI_OP_DNCTRL );
471  DBGC ( xhci, "XHCI %s DNCTRL %08x\n", xhci->name, dnctrl );
472 
473  /* Dump CONFIG */
474  config = readl ( xhci->op + XHCI_OP_CONFIG );
475  DBGC ( xhci, "XHCI %s CONFIG %08x\n", xhci->name, config );
476 }
#define XHCI_OP_USBSTS
USB status register.
Definition: xhci.h:164
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: xhci.h:1043
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_PAGESIZE
Page size register.
Definition: xhci.h:170
#define XHCI_USBCMD_HCRST
Host controller reset.
Definition: xhci.h:161
#define XHCI_OP_CONFIG
Configure register.
Definition: xhci.h:194
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:158
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
#define XHCI_USBSTS_HCH
Host controller halted.
Definition: xhci.h:167
#define DBG_LOG
Definition: compiler.h:317
#define XHCI_OP_DNCTRL
Device notifcation control register.
Definition: xhci.h:176
void * op
Operational registers.
Definition: xhci.h:1050

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

485  {
486  uint32_t portsc;
487  uint32_t portpmsc;
488  uint32_t portli;
489  uint32_t porthlpmc;
490 
491  /* Do nothing unless debugging is enabled */
492  if ( ! DBG_LOG )
493  return;
494 
495  /* Dump PORTSC */
496  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port ) );
497  DBGC ( xhci, "XHCI %s-%d PORTSC %08x%s%s%s%s psiv=%d\n",
498  xhci->name, port, portsc,
499  ( ( portsc & XHCI_PORTSC_CCS ) ? " ccs" : "" ),
500  ( ( portsc & XHCI_PORTSC_PED ) ? " ped" : "" ),
501  ( ( portsc & XHCI_PORTSC_PR ) ? " pr" : "" ),
502  ( ( portsc & XHCI_PORTSC_PP ) ? " pp" : "" ),
503  XHCI_PORTSC_PSIV ( portsc ) );
504 
505  /* Dump PORTPMSC */
506  portpmsc = readl ( xhci->op + XHCI_OP_PORTPMSC ( port ) );
507  DBGC ( xhci, "XHCI %s-%d PORTPMSC %08x\n", xhci->name, port, portpmsc );
508 
509  /* Dump PORTLI */
510  portli = readl ( xhci->op + XHCI_OP_PORTLI ( port ) );
511  DBGC ( xhci, "XHCI %s-%d PORTLI %08x\n", xhci->name, port, portli );
512 
513  /* Dump PORTHLPMC */
514  porthlpmc = readl ( xhci->op + XHCI_OP_PORTHLPMC ( port ) );
515  DBGC ( xhci, "XHCI %s-%d PORTHLPMC %08x\n",
516  xhci->name, port, porthlpmc );
517 }
#define XHCI_PORTSC_PSIV(portsc)
Port speed ID value.
Definition: xhci.h:234
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_OP_PORTHLPMC(port)
Port hardware link power management control register.
Definition: xhci.h:293
#define XHCI_OP_PORTLI(port)
Port link info register.
Definition: xhci.h:290
#define XHCI_PORTSC_PP
Port power.
Definition: xhci.h:228
#define XHCI_PORTSC_CCS
Current connect status.
Definition: xhci.h:207
u8 port
Port number.
Definition: CIB_PRM.h:31
const char * name
Name.
Definition: xhci.h:1043
#define XHCI_OP_PORTPMSC(port)
Port power management status and control register.
Definition: xhci.h:287
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
#define XHCI_PORTSC_PR
Port reset.
Definition: xhci.h:213
#define XHCI_PORTSC_PED
Port enabled.
Definition: xhci.h:210
#define DBG_LOG
Definition: compiler.h:317
void * op
Operational registers.
Definition: xhci.h:1050

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

534  {
535  unsigned int legacy;
536  uint8_t bios;
537 
538  /* Locate USB legacy support capability (if present) */
539  legacy = xhci_extended_capability ( xhci, XHCI_XECP_ID_LEGACY, 0 );
540  if ( ! legacy ) {
541  /* Not an error; capability may not be present */
542  DBGC ( xhci, "XHCI %s has no USB legacy support capability\n",
543  xhci->name );
544  return;
545  }
546 
547  /* Check if legacy USB support is enabled */
548  bios = readb ( xhci->cap + legacy + XHCI_USBLEGSUP_BIOS );
549  if ( ! ( bios & XHCI_USBLEGSUP_BIOS_OWNED ) ) {
550  /* Not an error; already owned by OS */
551  DBGC ( xhci, "XHCI %s USB legacy support already disabled\n",
552  xhci->name );
553  return;
554  }
555 
556  /* Record presence of USB legacy support capability */
557  xhci->legacy = legacy;
558 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define XHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
Definition: xhci.h:89
static unsigned int xhci_extended_capability(struct xhci_device *xhci, unsigned int id, unsigned int offset)
Find extended capability.
Definition: xhci.c:324
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: xhci.h:1043
#define XHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition: xhci.h:86
unsigned char uint8_t
Definition: stdint.h:10
void * cap
Capability registers.
Definition: xhci.h:1048
#define XHCI_XECP_ID_LEGACY
USB legacy support extended capability.
Definition: xhci.h:83
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: xhci.h:1077

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

565  {
566  uint32_t ctlsts;
567  uint8_t bios;
568  unsigned int i;
569 
570  /* Do nothing unless legacy support capability is present */
571  if ( ! xhci->legacy )
572  return;
573 
574  /* Claim ownership */
576  xhci->cap + xhci->legacy + XHCI_USBLEGSUP_OS );
577 
578  /* Wait for BIOS to release ownership */
579  for ( i = 0 ; i < XHCI_USBLEGSUP_MAX_WAIT_MS ; i++ ) {
580 
581  /* Check if BIOS has released ownership */
582  bios = readb ( xhci->cap + xhci->legacy + XHCI_USBLEGSUP_BIOS );
583  if ( ! ( bios & XHCI_USBLEGSUP_BIOS_OWNED ) ) {
584  DBGC ( xhci, "XHCI %s claimed ownership from BIOS\n",
585  xhci->name );
586  ctlsts = readl ( xhci->cap + xhci->legacy +
588  if ( ctlsts ) {
589  DBGC ( xhci, "XHCI %s warning: BIOS retained "
590  "SMIs: %08x\n", xhci->name, ctlsts );
591  }
592  return;
593  }
594 
595  /* Delay */
596  mdelay ( 1 );
597  }
598 
599  /* BIOS did not release ownership. Claim it forcibly by
600  * disabling all SMIs.
601  */
602  DBGC ( xhci, "XHCI %s could not claim ownership from BIOS: forcibly "
603  "disabling SMIs\n", xhci->name );
604  writel ( 0, xhci->cap + xhci->legacy + XHCI_USBLEGSUP_CTLSTS );
605 }
#define XHCI_USBLEGSUP_MAX_WAIT_MS
Maximum time to wait for BIOS to release ownership.
Definition: xhci.h:978
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define XHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
Definition: xhci.h:89
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_USBLEGSUP_OS
USB legacy support OS owned semaphore.
Definition: xhci.h:92
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define XHCI_USBLEGSUP_CTLSTS
USB legacy support control/status.
Definition: xhci.h:98
const char * name
Name.
Definition: xhci.h:1043
#define XHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition: xhci.h:86
#define XHCI_USBLEGSUP_OS_OWNED
USB legacy support OS ownership flag.
Definition: xhci.h:95
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1048
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:1077

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

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

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

643  {
644  static const char *exponents[4] = { "", "k", "M", "G" };
645  static char buf[ 10 /* "xxxxxXbps" + NUL */ ];
646  unsigned int mantissa;
647  unsigned int exponent;
648 
649  /* Extract mantissa and exponent */
650  mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
651  exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
652 
653  /* Transcribe speed */
654  snprintf ( buf, sizeof ( buf ), "%d%sbps",
655  mantissa, exponents[exponent] );
656  return buf;
657 }
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:137
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
Definition: xhci.h:140

References snprintf(), XHCI_SUPPORTED_PSI_EXPONENT, and XHCI_SUPPORTED_PSI_MANTISSA.

Referenced by xhci_port_protocol().

◆ xhci_supported_protocol()

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

Find supported protocol extended capability for a port.

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

Definition at line 666 of file xhci.c.

667  {
668  unsigned int supported = 0;
669  unsigned int offset;
670  unsigned int count;
671  uint32_t ports;
672 
673  /* Iterate over all supported protocol structures */
674  while ( ( supported = xhci_extended_capability ( xhci,
676  supported ) ) ) {
677 
678  /* Determine port range */
679  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
681  count = XHCI_SUPPORTED_PORTS_COUNT ( ports );
682 
683  /* Check if port lies within this range */
684  if ( ( port - offset ) < count )
685  return supported;
686  }
687 
688  DBGC ( xhci, "XHCI %s-%d has no supported protocol\n",
689  xhci->name, port );
690  return 0;
691 }
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
static unsigned int xhci_extended_capability(struct xhci_device *xhci, unsigned int id, unsigned int offset)
Find extended capability.
Definition: xhci.c:324
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define XHCI_XECP_ID_SUPPORTED
Supported protocol extended capability.
Definition: xhci.h:101
#define DBGC(...)
Definition: compiler.h:505
u8 port
Port number.
Definition: CIB_PRM.h:31
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
const char * name
Name.
Definition: xhci.h:1043
#define XHCI_SUPPORTED_PORTS_COUNT(ports)
Supported protocol port count.
Definition: xhci.h:119
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1048
#define XHCI_SUPPORTED_PORTS_OFFSET(ports)
Supported protocol port offset.
Definition: xhci.h:116
uint16_t count
Number of entries.
Definition: ena.h:22

References xhci_device::cap, count, DBGC, xhci_device::name, offset, port, readl(), 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 700 of file xhci.c.

701  {
702  unsigned int supported = xhci_supported_protocol ( xhci, port );
703  union {
704  uint32_t raw;
705  char text[5];
706  } name;
707  unsigned int protocol;
708  unsigned int type;
709  unsigned int psic;
710  unsigned int psiv;
711  unsigned int i;
713  uint32_t ports;
714  uint32_t slot;
715  uint32_t psi;
716 
717  /* Fail if there is no supported protocol */
718  if ( ! supported )
719  return 0;
720 
721  /* Determine protocol version */
722  revision = readl ( xhci->cap + supported + XHCI_SUPPORTED_REVISION );
724 
725  /* Describe port protocol */
726  if ( DBG_EXTRA ) {
727  name.raw = cpu_to_le32 ( readl ( xhci->cap + supported +
729  name.text[4] = '\0';
730  slot = readl ( xhci->cap + supported + XHCI_SUPPORTED_SLOT );
732  DBGC2 ( xhci, "XHCI %s-%d %sv%04x type %d",
733  xhci->name, port, name.text, protocol, type );
734  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
735  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
736  if ( psic ) {
737  DBGC2 ( xhci, " speeds" );
738  for ( i = 0 ; i < psic ; i++ ) {
739  psi = readl ( xhci->cap + supported +
740  XHCI_SUPPORTED_PSI ( i ) );
741  psiv = XHCI_SUPPORTED_PSI_VALUE ( psi );
742  DBGC2 ( xhci, " %d:%s", psiv,
743  xhci_speed_name ( psi ) );
744  }
745  }
746  if ( xhci->quirks & XHCI_BAD_PSIV )
747  DBGC2 ( xhci, " (ignored)" );
748  DBGC2 ( xhci, "\n" );
749  }
750 
751  return protocol;
752 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1036
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition: xhci.h:128
const char * name
Definition: ath9k_hw.c:1984
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition: xhci.h:125
uint8_t type
Type.
Definition: ena.h:16
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:134
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
static const char * xhci_speed_name(uint32_t psi)
Transcribe port speed (for debugging)
Definition: xhci.c:643
u8 port
Port number.
Definition: CIB_PRM.h:31
#define XHCI_SUPPORTED_PORTS_PSIC(ports)
Supported protocol PSI count.
Definition: xhci.h:122
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint32_t revision
Definition: ib_mad.h:20
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:131
const char * name
Name.
Definition: xhci.h:1043
uint8_t slot
Slot.
Definition: edd.h:16
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1048
#define XHCI_SUPPORTED_REVISION
Supported protocol revision.
Definition: xhci.h:104
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:666
#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:107
unsigned int quirks
Quirks.
Definition: xhci.h:1045
#define XHCI_SUPPORTED_NAME
Supported protocol name.
Definition: xhci.h:110

References xhci_device::cap, cpu_to_le32, DBG_EXTRA, DBGC2, xhci_device::name, name, port, protocol, xhci_device::quirks, raw, readl(), revision, slot, 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_probe().

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

761  {
762  unsigned int supported = xhci_supported_protocol ( xhci, port );
763  unsigned int type;
764  uint32_t slot;
765 
766  /* Fail if there is no supported protocol */
767  if ( ! supported )
768  return -ENOTSUP;
769 
770  /* Get slot type */
771  slot = readl ( xhci->cap + supported + XHCI_SUPPORTED_SLOT );
773 
774  return type;
775 }
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition: xhci.h:128
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition: xhci.h:125
uint8_t type
Type.
Definition: ena.h:16
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:1048
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:666

References xhci_device::cap, ENOTSUP, port, readl(), slot, 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 785 of file xhci.c.

786  {
787  unsigned int supported = xhci_supported_protocol ( xhci, port );
788  unsigned int psic;
789  unsigned int mantissa;
790  unsigned int exponent;
791  unsigned int speed;
792  unsigned int i;
793  uint32_t ports;
794  uint32_t psi;
795 
796  /* Fail if there is no supported protocol */
797  if ( ! supported )
798  return -ENOTSUP;
799 
800  /* Get protocol speed ID count */
801  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
802  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
803 
804  /* Use protocol speed ID table unless device is known to be faulty */
805  if ( ! ( xhci->quirks & XHCI_BAD_PSIV ) ) {
806 
807  /* Iterate over PSI dwords looking for a match */
808  for ( i = 0 ; i < psic ; i++ ) {
809  psi = readl ( xhci->cap + supported +
810  XHCI_SUPPORTED_PSI ( i ) );
811  if ( psiv == XHCI_SUPPORTED_PSI_VALUE ( psi ) ) {
812  mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
813  exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
814  speed = USB_SPEED ( mantissa, exponent );
815  return speed;
816  }
817  }
818 
819  /* Record device as faulty if no match is found */
820  if ( psic != 0 ) {
821  DBGC ( xhci, "XHCI %s-%d spurious PSI value %d: "
822  "assuming PSI table is invalid\n",
823  xhci->name, port, psiv );
824  xhci->quirks |= XHCI_BAD_PSIV;
825  }
826  }
827 
828  /* Use the default mappings */
829  switch ( psiv ) {
830  case XHCI_SPEED_LOW : return USB_SPEED_LOW;
831  case XHCI_SPEED_FULL : return USB_SPEED_FULL;
832  case XHCI_SPEED_HIGH : return USB_SPEED_HIGH;
833  case XHCI_SPEED_SUPER : return USB_SPEED_SUPER;
834  default:
835  DBGC ( xhci, "XHCI %s-%d unrecognised PSI value %d\n",
836  xhci->name, port, psiv );
837  return -ENOTSUP;
838  }
839 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1036
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
Low speed (1.5Mbps)
Definition: usb.h:48
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:134
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
Full speed (12Mbps)
Definition: xhci.h:145
Super speed (5Gbps)
Definition: usb.h: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:122
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:131
const char * name
Name.
Definition: xhci.h:1043
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1048
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:666
High speed (480Mbps)
Definition: usb.h:52
Super speed.
Definition: xhci.h:151
Low speed (1.5Mbps)
Definition: xhci.h:147
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)
Supported protocol PSI mantissa.
Definition: xhci.h:137
High speed (480Mbps)
Definition: xhci.h:149
unsigned int quirks
Quirks.
Definition: xhci.h:1045
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
Definition: xhci.h:140
Full speed (12Mbps)
Definition: usb.h:50

References xhci_device::cap, DBGC, ENOTSUP, xhci_device::name, port, xhci_device::quirks, readl(), 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 849 of file xhci.c.

850  {
851  unsigned int supported = xhci_supported_protocol ( xhci, port );
852  unsigned int psic;
853  unsigned int mantissa;
854  unsigned int exponent;
855  unsigned int psiv;
856  unsigned int i;
857  uint32_t ports;
858  uint32_t psi;
859 
860  /* Fail if there is no supported protocol */
861  if ( ! supported )
862  return -ENOTSUP;
863 
864  /* Get protocol speed ID count */
865  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
866  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
867 
868  /* Use the default mappings if applicable */
869  if ( ( psic == 0 ) || ( xhci->quirks & XHCI_BAD_PSIV ) ) {
870  switch ( speed ) {
871  case USB_SPEED_LOW : return XHCI_SPEED_LOW;
872  case USB_SPEED_FULL : return XHCI_SPEED_FULL;
873  case USB_SPEED_HIGH : return XHCI_SPEED_HIGH;
874  case USB_SPEED_SUPER : return XHCI_SPEED_SUPER;
875  default:
876  DBGC ( xhci, "XHCI %s-%d non-standard speed %d\n",
877  xhci->name, port, speed );
878  return -ENOTSUP;
879  }
880  }
881 
882  /* Iterate over PSI dwords looking for a match */
883  for ( i = 0 ; i < psic ; i++ ) {
884  psi = readl ( xhci->cap + supported + XHCI_SUPPORTED_PSI ( i ));
885  mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
886  exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
887  if ( speed == USB_SPEED ( mantissa, exponent ) ) {
888  psiv = XHCI_SUPPORTED_PSI_VALUE ( psi );
889  return psiv;
890  }
891  }
892 
893  DBGC ( xhci, "XHCI %s-%d unrepresentable speed %#x\n",
894  xhci->name, port, speed );
895  return -ENOENT;
896 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1036
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
Low speed (1.5Mbps)
Definition: usb.h:48
#define XHCI_SUPPORTED_PSI_VALUE(psi)
Supported protocol PSI value.
Definition: xhci.h:134
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
Full speed (12Mbps)
Definition: xhci.h:145
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:122
#define XHCI_SUPPORTED_PSI(index)
Supported protocol PSI.
Definition: xhci.h:131
const char * name
Name.
Definition: xhci.h:1043
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1048
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:666
High speed (480Mbps)
Definition: usb.h:52
Super speed.
Definition: xhci.h:151
Low speed (1.5Mbps)
Definition: xhci.h:147
#define XHCI_SUPPORTED_PSI_MANTISSA(psi)
Supported protocol PSI mantissa.
Definition: xhci.h:137
High speed (480Mbps)
Definition: xhci.h:149
unsigned int quirks
Quirks.
Definition: xhci.h:1045
#define XHCI_SUPPORTED_PSI_EXPONENT(psi)
Supported protocol PSI exponent.
Definition: xhci.h:140
Full speed (12Mbps)
Definition: usb.h:50

References xhci_device::cap, DBGC, ENOENT, ENOTSUP, xhci_device::name, port, xhci_device::quirks, readl(), 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 911 of file xhci.c.

911  {
912  size_t len;
913  physaddr_t dcbaap;
914  int rc;
915 
916  /* Allocate and initialise structure. Must be at least
917  * 64-byte aligned and must not cross a page boundary, so
918  * align on its own size (rounded up to a power of two and
919  * with a minimum of 64 bytes).
920  */
921  len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa[0] ) );
922  xhci->dcbaa = malloc_dma ( len, xhci_align ( len ) );
923  if ( ! xhci->dcbaa ) {
924  DBGC ( xhci, "XHCI %s could not allocate DCBAA\n", xhci->name );
925  rc = -ENOMEM;
926  goto err_alloc;
927  }
928  memset ( xhci->dcbaa, 0, len );
929 
930  /* Program DCBAA pointer */
931  dcbaap = virt_to_phys ( xhci->dcbaa );
932  if ( ( rc = xhci_writeq ( xhci, dcbaap,
933  xhci->op + XHCI_OP_DCBAAP ) ) != 0 )
934  goto err_writeq;
935 
936  DBGC2 ( xhci, "XHCI %s DCBAA at [%08lx,%08lx)\n",
937  xhci->name, dcbaap, ( dcbaap + len ) );
938  return 0;
939 
940  err_writeq:
941  free_dma ( xhci->dcbaa, len );
942  err_alloc:
943  return rc;
944 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:394
#define DBGC(...)
Definition: compiler.h:505
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
unsigned int slots
Number of device slots.
Definition: xhci.h:1057
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define XHCI_OP_DCBAAP
Device context base address array pointer.
Definition: xhci.h:191
const char * name
Name.
Definition: xhci.h:1043
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:360
unsigned long physaddr_t
Definition: stdint.h:20
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
void * op
Operational registers.
Definition: xhci.h:1050
uint64_t * dcbaa
Device context base address array.
Definition: xhci.h:1080
void * memset(void *dest, int character, size_t len) __nonnull

References DBGC, DBGC2, xhci_device::dcbaa, ENOMEM, free_dma(), len, malloc_dma(), memset(), xhci_device::name, xhci_device::op, rc, xhci_device::slots, virt_to_phys(), 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 951 of file xhci.c.

951  {
952  size_t len;
953  unsigned int i;
954 
955  /* Sanity check */
956  for ( i = 0 ; i <= xhci->slots ; i++ )
957  assert ( xhci->dcbaa[i] == 0 );
958 
959  /* Clear DCBAA pointer */
960  xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_DCBAAP );
961 
962  /* Free DCBAA */
963  len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa[0] ) );
964  free_dma ( xhci->dcbaa, len );
965 }
unsigned int slots
Number of device slots.
Definition: xhci.h:1057
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_OP_DCBAAP
Device context base address array pointer.
Definition: xhci.h:191
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:360
uint32_t len
Length.
Definition: ena.h:14
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
void * op
Operational registers.
Definition: xhci.h:1050
uint64_t * dcbaa
Device context base address array.
Definition: xhci.h:1080

References assert(), xhci_device::dcbaa, free_dma(), len, 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 980 of file xhci.c.

980  {
981  size_t array_len;
982  size_t len;
984  unsigned int i;
985  int rc;
986 
987  /* Do nothing if no scratchpad buffers are used */
988  if ( ! xhci->scratchpads )
989  return 0;
990 
991  /* Allocate scratchpads */
992  len = ( xhci->scratchpads * xhci->pagesize );
993  xhci->scratchpad = umalloc ( len );
994  if ( ! xhci->scratchpad ) {
995  DBGC ( xhci, "XHCI %s could not allocate scratchpad buffers\n",
996  xhci->name );
997  rc = -ENOMEM;
998  goto err_alloc;
999  }
1000  memset_user ( xhci->scratchpad, 0, 0, len );
1001 
1002  /* Allocate scratchpad array */
1003  array_len = ( xhci->scratchpads * sizeof ( xhci->scratchpad_array[0] ));
1004  xhci->scratchpad_array =
1005  malloc_dma ( array_len, xhci_align ( array_len ) );
1006  if ( ! xhci->scratchpad_array ) {
1007  DBGC ( xhci, "XHCI %s could not allocate scratchpad buffer "
1008  "array\n", xhci->name );
1009  rc = -ENOMEM;
1010  goto err_alloc_array;
1011  }
1012 
1013  /* Populate scratchpad array */
1014  for ( i = 0 ; i < xhci->scratchpads ; i++ ) {
1015  phys = user_to_phys ( xhci->scratchpad, ( i * xhci->pagesize ));
1016  xhci->scratchpad_array[i] = phys;
1017  }
1018 
1019  /* Set scratchpad array pointer */
1020  assert ( xhci->dcbaa != NULL );
1021  xhci->dcbaa[0] = cpu_to_le64 ( virt_to_phys ( xhci->scratchpad_array ));
1022 
1023  DBGC2 ( xhci, "XHCI %s scratchpad [%08lx,%08lx) array [%08lx,%08lx)\n",
1024  xhci->name, user_to_phys ( xhci->scratchpad, 0 ),
1025  user_to_phys ( xhci->scratchpad, len ),
1026  virt_to_phys ( xhci->scratchpad_array ),
1027  ( virt_to_phys ( xhci->scratchpad_array ) + array_len ) );
1028  return 0;
1029 
1030  free_dma ( xhci->scratchpad_array, array_len );
1031  err_alloc_array:
1032  ufree ( xhci->scratchpad );
1033  err_alloc:
1034  return rc;
1035 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:394
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
#define DBGC(...)
Definition: compiler.h:505
#define cpu_to_le64(value)
Definition: byteswap.h:108
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
void memset_user(userptr_t userptr, off_t offset, int c, size_t len)
Fill user buffer with a constant byte.
#define ENOMEM
Not enough space.
Definition: errno.h:534
static signed char phys[4]
Definition: epic100.c:88
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
userptr_t scratchpad
Scratchpad buffer area.
Definition: xhci.h:1083
unsigned int scratchpads
Number of page-sized scratchpad buffers.
Definition: xhci.h:1064
const char * name
Name.
Definition: xhci.h:1043
unsigned long physaddr_t
Definition: stdint.h:20
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
uint32_t len
Length.
Definition: ena.h:14
static __always_inline userptr_t umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:54
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1074
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
uint64_t * scratchpad_array
Scratchpad buffer array.
Definition: xhci.h:1085
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
uint64_t * dcbaa
Device context base address array.
Definition: xhci.h:1080

References assert(), cpu_to_le64, DBGC, DBGC2, xhci_device::dcbaa, ENOMEM, free_dma(), len, malloc_dma(), memset_user(), xhci_device::name, NULL, xhci_device::pagesize, phys, rc, xhci_device::scratchpad, xhci_device::scratchpad_array, xhci_device::scratchpads, ufree(), umalloc(), user_to_phys(), virt_to_phys(), 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 1042 of file xhci.c.

1042  {
1043  size_t array_len;
1044 
1045  /* Do nothing if no scratchpad buffers are used */
1046  if ( ! xhci->scratchpads )
1047  return;
1048 
1049  /* Clear scratchpad array pointer */
1050  assert ( xhci->dcbaa != NULL );
1051  xhci->dcbaa[0] = 0;
1052 
1053  /* Free scratchpad array */
1054  array_len = ( xhci->scratchpads * sizeof ( xhci->scratchpad_array[0] ));
1055  free_dma ( xhci->scratchpad_array, array_len );
1056 
1057  /* Free scratchpads */
1058  ufree ( xhci->scratchpad );
1059 }
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
userptr_t scratchpad
Scratchpad buffer area.
Definition: xhci.h:1083
unsigned int scratchpads
Number of page-sized scratchpad buffers.
Definition: xhci.h:1064
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
uint64_t * scratchpad_array
Scratchpad buffer array.
Definition: xhci.h:1085
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
uint64_t * dcbaa
Device context base address array.
Definition: xhci.h:1080

References assert(), xhci_device::dcbaa, free_dma(), NULL, xhci_device::scratchpad, xhci_device::scratchpad_array, xhci_device::scratchpads, and ufree().

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

1073  {
1074  uint32_t config;
1075  uint32_t usbcmd;
1076 
1077  /* Configure number of device slots */
1078  config = readl ( xhci->op + XHCI_OP_CONFIG );
1079  config &= ~XHCI_CONFIG_MAX_SLOTS_EN_MASK;
1080  config |= XHCI_CONFIG_MAX_SLOTS_EN ( xhci->slots );
1081  writel ( config, xhci->op + XHCI_OP_CONFIG );
1082 
1083  /* Set run/stop bit */
1084  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1085  usbcmd |= XHCI_USBCMD_RUN;
1086  writel ( usbcmd, xhci->op + XHCI_OP_USBCMD );
1087 }
#define XHCI_CONFIG_MAX_SLOTS_EN(slots)
Maximum device slots enabled.
Definition: xhci.h:197
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
unsigned int slots
Number of device slots.
Definition: xhci.h:1057
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_OP_CONFIG
Configure register.
Definition: xhci.h:194
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:158
#define XHCI_CONFIG_MAX_SLOTS_EN_MASK
Maximum device slots enabled mask.
Definition: xhci.h:200
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
void * op
Operational registers.
Definition: xhci.h:1050

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

1095  {
1096  uint32_t usbcmd;
1097  uint32_t usbsts;
1098  unsigned int i;
1099 
1100  /* Clear run/stop bit */
1101  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1102  usbcmd &= ~XHCI_USBCMD_RUN;
1103  writel ( usbcmd, xhci->op + XHCI_OP_USBCMD );
1104 
1105  /* Wait for device to stop */
1106  for ( i = 0 ; i < XHCI_STOP_MAX_WAIT_MS ; i++ ) {
1107 
1108  /* Check if device is stopped */
1109  usbsts = readl ( xhci->op + XHCI_OP_USBSTS );
1110  if ( usbsts & XHCI_USBSTS_HCH )
1111  return 0;
1112 
1113  /* Delay */
1114  mdelay ( 1 );
1115  }
1116 
1117  DBGC ( xhci, "XHCI %s timed out waiting for stop\n", xhci->name );
1118  return -ETIMEDOUT;
1119 }
#define XHCI_OP_USBSTS
USB status register.
Definition: xhci.h:164
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1043
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:984
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:158
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
#define XHCI_USBSTS_HCH
Host controller halted.
Definition: xhci.h:167
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * op
Operational registers.
Definition: xhci.h:1050

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

1127  {
1128  uint32_t usbcmd;
1129  unsigned int i;
1130  int rc;
1131 
1132  /* The xHCI specification states that resetting a running
1133  * device may result in undefined behaviour, so try stopping
1134  * it first.
1135  */
1136  if ( ( rc = xhci_stop ( xhci ) ) != 0 ) {
1137  /* Ignore errors and attempt to reset the device anyway */
1138  }
1139 
1140  /* Reset device */
1142 
1143  /* Wait for reset to complete */
1144  for ( i = 0 ; i < XHCI_RESET_MAX_WAIT_MS ; i++ ) {
1145 
1146  /* Check if reset is complete */
1147  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1148  if ( ! ( usbcmd & XHCI_USBCMD_HCRST ) )
1149  return 0;
1150 
1151  /* Delay */
1152  mdelay ( 1 );
1153  }
1154 
1155  DBGC ( xhci, "XHCI %s timed out waiting for reset\n", xhci->name );
1156  return -ETIMEDOUT;
1157 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition: xhci.c:1095
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:990
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:1043
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_USBCMD_HCRST
Host controller reset.
Definition: xhci.h:161
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * op
Operational registers.
Definition: xhci.h:1050

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_probe(), 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 1177 of file xhci.c.

1180  {
1181  struct xhci_trb_link *link;
1182  unsigned int count;
1183  int rc;
1184 
1185  /* Sanity check */
1186  assert ( shift > 0 );
1187 
1188  /* Initialise structure */
1189  memset ( ring, 0, sizeof ( *ring ) );
1190  ring->shift = shift;
1191  count = ( 1U << shift );
1192  ring->mask = ( count - 1 );
1193  ring->len = ( ( count + 1 /* Link TRB */ ) * sizeof ( ring->trb[0] ) );
1194  ring->db = ( xhci->db + ( slot * sizeof ( ring->dbval ) ) );
1195  ring->dbval = XHCI_DBVAL ( target, stream );
1196 
1197  /* Allocate I/O buffers */
1198  ring->iobuf = zalloc ( count * sizeof ( ring->iobuf[0] ) );
1199  if ( ! ring->iobuf ) {
1200  rc = -ENOMEM;
1201  goto err_alloc_iobuf;
1202  }
1203 
1204  /* Allocate TRBs */
1205  ring->trb = malloc_dma ( ring->len, xhci_align ( ring->len ) );
1206  if ( ! ring->trb ) {
1207  rc = -ENOMEM;
1208  goto err_alloc_trb;
1209  }
1210  memset ( ring->trb, 0, ring->len );
1211 
1212  /* Initialise Link TRB */
1213  link = &ring->trb[count].link;
1214  link->next = cpu_to_le64 ( virt_to_phys ( ring->trb ) );
1215  link->flags = XHCI_TRB_TC;
1216  link->type = XHCI_TRB_LINK;
1217  ring->link = link;
1218 
1219  return 0;
1220 
1221  free_dma ( ring->trb, ring->len );
1222  err_alloc_trb:
1223  free ( ring->iobuf );
1224  err_alloc_iobuf:
1225  return rc;
1226 }
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
Definition: xhci.h:332
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t dbval
Doorbell register value.
Definition: xhci.h:863
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:394
#define cpu_to_le64(value)
Definition: byteswap.h:108
void * db
Doorbell register.
Definition: xhci.h:861
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define ENOMEM
Not enough space.
Definition: errno.h:534
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
uint8_t slot
Slot.
Definition: edd.h:16
#define XHCI_DBVAL(target, stream)
Calculate doorbell register value.
Definition: xhci.h:883
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
uint16_t count
Number of entries.
Definition: ena.h:22
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
struct xhci_trb_link * link
Link TRB (if applicable)
Definition: xhci.h:858
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
void * db
Doorbell registers.
Definition: xhci.h:1054
#define XHCI_TRB_LINK
A link transfer request block.
Definition: xhci.h:460
struct xhci_trb_link link
Link TRB.
Definition: xhci.h:697
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
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, ENOMEM, free, free_dma(), xhci_trb_ring::iobuf, xhci_trb_ring::len, link, xhci_trb::link, xhci_trb_ring::link, malloc_dma(), xhci_trb_ring::mask, memset(), rc, xhci_trb_ring::shift, slot, xhci_trb_ring::trb, virt_to_phys(), 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 1233 of file xhci.c.

1233  {
1234  unsigned int count = ( 1U << ring->shift );
1235 
1236  /* Reset producer and consumer counters */
1237  ring->prod = 0;
1238  ring->cons = 0;
1239 
1240  /* Reset TRBs (except Link TRB) */
1241  memset ( ring->trb, 0, ( count * sizeof ( ring->trb[0] ) ) );
1242 }
unsigned int cons
Consumer counter.
Definition: xhci.h:844
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
unsigned int prod
Producer counter.
Definition: xhci.h:842
uint16_t count
Number of entries.
Definition: ena.h:22
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
void * memset(void *dest, int character, size_t len) __nonnull

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

Referenced by xhci_abort().

◆ xhci_ring_free()

static void xhci_ring_free ( struct xhci_trb_ring ring)
static

Free transfer request block ring.

Parameters
ringTRB ring

Definition at line 1249 of file xhci.c.

1249  {
1250  unsigned int count = ( 1U << ring->shift );
1251  unsigned int i;
1252 
1253  /* Sanity checks */
1254  assert ( ring->cons == ring->prod );
1255  for ( i = 0 ; i < count ; i++ )
1256  assert ( ring->iobuf[i] == NULL );
1257 
1258  /* Free TRBs */
1259  free_dma ( ring->trb, ring->len );
1260 
1261  /* Free I/O buffers */
1262  free ( ring->iobuf );
1263 }
unsigned int cons
Consumer counter.
Definition: xhci.h:844
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
unsigned int prod
Producer counter.
Definition: xhci.h:842
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
uint16_t count
Number of entries.
Definition: ena.h:22
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), xhci_trb_ring::cons, count, free, free_dma(), xhci_trb_ring::iobuf, xhci_trb_ring::len, 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 1275 of file xhci.c.

1276  {
1277  union xhci_trb *dest;
1278  unsigned int prod;
1279  unsigned int mask;
1280  unsigned int index;
1281  unsigned int cycle;
1282 
1283  /* Sanity check */
1284  assert ( ! ( trb->common.flags & XHCI_TRB_C ) );
1285 
1286  /* Fail if ring is full */
1287  if ( ! xhci_ring_remaining ( ring ) )
1288  return -ENOBUFS;
1289 
1290  /* Update producer counter (and link TRB, if applicable) */
1291  prod = ring->prod++;
1292  mask = ring->mask;
1293  cycle = ( ( ~( prod >> ring->shift ) ) & XHCI_TRB_C );
1294  index = ( prod & mask );
1295  if ( index == 0 )
1296  ring->link->flags = ( XHCI_TRB_TC | ( cycle ^ XHCI_TRB_C ) );
1297 
1298  /* Record I/O buffer */
1299  ring->iobuf[index] = iobuf;
1300 
1301  /* Enqueue TRB */
1302  dest = &ring->trb[index];
1303  dest->template.parameter = trb->template.parameter;
1304  dest->template.status = trb->template.status;
1305  wmb();
1306  dest->template.control = ( trb->template.control |
1307  cpu_to_le32 ( cycle ) );
1308 
1309  return 0;
1310 }
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
Definition: xhci.h:332
wmb()
struct xhci_trb_common common
Common fields.
Definition: xhci.h:687
uint8_t flags
Flags.
Definition: xhci.h:321
static unsigned int xhci_ring_remaining(struct xhci_trb_ring *ring)
Calculate space remaining in TRB ring.
Definition: xhci.h:907
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct xhci_trb_template template
Template.
Definition: xhci.h:685
static void * dest
Definition: strings.h:176
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint32_t status
Status.
Definition: xhci.h:309
A transfer request block.
Definition: xhci.h:683
unsigned int prod
Producer counter.
Definition: xhci.h:842
uint32_t control
Control.
Definition: xhci.h:311
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
struct xhci_trb_link * link
Link TRB (if applicable)
Definition: xhci.h:858
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define XHCI_TRB_C
Transfer request block cycle bit flag.
Definition: xhci.h:329
uint64_t parameter
Parameter.
Definition: xhci.h:307

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

Referenced by xhci_command(), and xhci_enqueue_multi().

◆ xhci_dequeue()

static struct io_buffer* xhci_dequeue ( struct xhci_trb_ring ring)
static

Dequeue a transfer request block.

Parameters
ringTRB ring
Return values
iobufI/O buffer

Definition at line 1318 of file xhci.c.

1318  {
1319  struct io_buffer *iobuf;
1320  unsigned int cons;
1321  unsigned int mask;
1322  unsigned int index;
1323 
1324  /* Sanity check */
1325  assert ( xhci_ring_fill ( ring ) != 0 );
1326 
1327  /* Update consumer counter */
1328  cons = ring->cons++;
1329  mask = ring->mask;
1330  index = ( cons & mask );
1331 
1332  /* Retrieve I/O buffer */
1333  iobuf = ring->iobuf[index];
1334  ring->iobuf[index] = NULL;
1335 
1336  return iobuf;
1337 }
unsigned int cons
Consumer counter.
Definition: xhci.h:844
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition: xhci.h:892
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint16_t cons
Consumer index.
Definition: ena.h:22
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

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

1353  {
1354  const union xhci_trb *trb = trbs;
1355  int rc;
1356 
1357  /* Sanity check */
1358  assert ( iobuf != NULL );
1359 
1360  /* Fail if ring does not have sufficient space */
1361  if ( xhci_ring_remaining ( ring ) < count )
1362  return -ENOBUFS;
1363 
1364  /* Enqueue each TRB, recording the I/O buffer with the final TRB */
1365  while ( count-- ) {
1366  rc = xhci_enqueue ( ring, ( count ? NULL : iobuf ), trb++ );
1367  assert ( rc == 0 ); /* Should never be able to fail */
1368  }
1369 
1370  return 0;
1371 }
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:907
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
A transfer request block.
Definition: xhci.h:683
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
uint16_t count
Number of entries.
Definition: ena.h:22
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:1275
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

1379  {
1380  struct io_buffer *iobuf;
1381 
1382  /* Dequeue TRBs until we reach the final TRB for an I/O buffer */
1383  do {
1384  iobuf = xhci_dequeue ( ring );
1385  } while ( iobuf == NULL );
1386 
1387  return iobuf;
1388 }
static struct io_buffer * xhci_dequeue(struct xhci_trb_ring *ring)
Dequeue a transfer request block.
Definition: xhci.c:1318
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

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

1396  {
1397 
1398  wmb();
1399  writel ( ring->dbval, ring->db );
1400 }
wmb()
uint32_t dbval
Doorbell register value.
Definition: xhci.h:863
void * db
Doorbell register.
Definition: xhci.h:861
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 1415 of file xhci.c.

1415  {
1416  physaddr_t crp;
1417  int rc;
1418 
1419  /* Allocate TRB ring */
1420  if ( ( rc = xhci_ring_alloc ( xhci, &xhci->command, XHCI_CMD_TRBS_LOG2,
1421  0, 0, 0 ) ) != 0 )
1422  goto err_ring_alloc;
1423 
1424  /* Program command ring control register */
1425  crp = virt_to_phys ( xhci->command.trb );
1426  if ( ( rc = xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ),
1427  xhci->op + XHCI_OP_CRCR ) ) != 0 )
1428  goto err_writeq;
1429 
1430  DBGC2 ( xhci, "XHCI %s CRCR at [%08lx,%08lx)\n",
1431  xhci->name, crp, ( crp + xhci->command.len ) );
1432  return 0;
1433 
1434  err_writeq:
1435  xhci_ring_free ( &xhci->command );
1436  err_ring_alloc:
1437  return rc;
1438 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1088
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1249
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:179
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
const char * name
Name.
Definition: xhci.h:1043
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:360
unsigned long physaddr_t
Definition: stdint.h:20
#define DBGC2(...)
Definition: compiler.h:522
#define XHCI_CRCR_RCS
Command ring cycle state.
Definition: xhci.h:182
void * op
Operational registers.
Definition: xhci.h:1050
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:1177
#define XHCI_CMD_TRBS_LOG2
Number of TRBs (excluding Link TRB) in the command ring.
Definition: xhci.h:960

References xhci_device::command, DBGC2, xhci_trb_ring::len, xhci_device::name, xhci_device::op, rc, xhci_trb_ring::trb, virt_to_phys(), 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 1445 of file xhci.c.

1445  {
1446 
1447  /* Sanity check */
1448  assert ( ( readl ( xhci->op + XHCI_OP_CRCR ) & XHCI_CRCR_CRR ) == 0 );
1449 
1450  /* Clear command ring control register */
1451  xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_CRCR );
1452 
1453  /* Free TRB ring */
1454  xhci_ring_free ( &xhci->command );
1455 }
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1088
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:1249
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:179
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:360
#define XHCI_CRCR_CRR
Command ring running.
Definition: xhci.h:188
void * op
Operational registers.
Definition: xhci.h:1050

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

1463  {
1464  struct xhci_event_ring *event = &xhci->event;
1465  unsigned int count;
1466  size_t len;
1467  int rc;
1468 
1469  /* Allocate event ring */
1470  count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
1471  len = ( count * sizeof ( event->trb[0] ) );
1472  event->trb = malloc_dma ( len, xhci_align ( len ) );
1473  if ( ! event->trb ) {
1474  rc = -ENOMEM;
1475  goto err_alloc_trb;
1476  }
1477  memset ( event->trb, 0, len );
1478 
1479  /* Allocate event ring segment table */
1480  event->segment = malloc_dma ( sizeof ( event->segment[0] ),
1481  xhci_align ( sizeof (event->segment[0])));
1482  if ( ! event->segment ) {
1483  rc = -ENOMEM;
1484  goto err_alloc_segment;
1485  }
1486  memset ( event->segment, 0, sizeof ( event->segment[0] ) );
1487  event->segment[0].base = cpu_to_le64 ( virt_to_phys ( event->trb ) );
1488  event->segment[0].count = cpu_to_le32 ( count );
1489 
1490  /* Program event ring registers */
1491  writel ( 1, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
1492  if ( ( rc = xhci_writeq ( xhci, virt_to_phys ( event->trb ),
1493  xhci->run + XHCI_RUN_ERDP ( 0 ) ) ) != 0 )
1494  goto err_writeq_erdp;
1495  if ( ( rc = xhci_writeq ( xhci, virt_to_phys ( event->segment ),
1496  xhci->run + XHCI_RUN_ERSTBA ( 0 ) ) ) != 0 )
1497  goto err_writeq_erstba;
1498 
1499  DBGC2 ( xhci, "XHCI %s event ring [%08lx,%08lx) table [%08lx,%08lx)\n",
1500  xhci->name, virt_to_phys ( event->trb ),
1501  ( virt_to_phys ( event->trb ) + len ),
1502  virt_to_phys ( event->segment ),
1503  ( virt_to_phys ( event->segment ) +
1504  sizeof (event->segment[0] ) ) );
1505  return 0;
1506 
1507  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
1508  err_writeq_erstba:
1509  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
1510  err_writeq_erdp:
1511  free_dma ( event->trb, len );
1512  err_alloc_segment:
1513  free_dma ( event->segment, sizeof ( event->segment[0] ) );
1514  err_alloc_trb:
1515  return rc;
1516 }
An event ring.
Definition: xhci.h:867
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * run
Runtime registers.
Definition: xhci.h:1052
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:394
#define cpu_to_le64(value)
Definition: byteswap.h:108
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define ENOMEM
Not enough space.
Definition: errno.h:534
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define cpu_to_le32(value)
Definition: byteswap.h:107
const char * name
Name.
Definition: xhci.h:1043
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:360
#define XHCI_RUN_ERSTBA(intr)
Event ring segment table base address register.
Definition: xhci.h:299
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
uint16_t count
Number of entries.
Definition: ena.h:22
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:966
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition: xhci.h:296
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1090
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:302
void * memset(void *dest, int character, size_t len) __nonnull

References count, cpu_to_le32, cpu_to_le64, DBGC2, ENOMEM, xhci_device::event, free_dma(), len, malloc_dma(), memset(), xhci_device::name, rc, xhci_device::run, virt_to_phys(), 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 1523 of file xhci.c.

1523  {
1524  struct xhci_event_ring *event = &xhci->event;
1525  unsigned int count;
1526  size_t len;
1527 
1528  /* Clear event ring registers */
1529  writel ( 0, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
1530  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
1531  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
1532 
1533  /* Free event ring segment table */
1534  free_dma ( event->segment, sizeof ( event->segment[0] ) );
1535 
1536  /* Free event ring */
1537  count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
1538  len = ( count * sizeof ( event->trb[0] ) );
1539  free_dma ( event->trb, len );
1540 }
An event ring.
Definition: xhci.h:867
void * run
Runtime registers.
Definition: xhci.h:1052
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:360
#define XHCI_RUN_ERSTBA(intr)
Event ring segment table base address register.
Definition: xhci.h:299
uint32_t len
Length.
Definition: ena.h:14
uint16_t count
Number of entries.
Definition: ena.h:22
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:966
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition: xhci.h:296
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1090
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:302

References count, xhci_device::event, free_dma(), 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 1548 of file xhci.c.

1549  {
1550  struct xhci_slot *slot;
1551  struct xhci_endpoint *endpoint;
1552  struct io_buffer *iobuf;
1553  int rc;
1554 
1555  /* Profile transfer events */
1556  profile_start ( &xhci_transfer_profiler );
1557 
1558  /* Identify slot */
1559  if ( ( trb->slot > xhci->slots ) ||
1560  ( ( slot = xhci->slot[trb->slot] ) == NULL ) ) {
1561  DBGC ( xhci, "XHCI %s transfer event invalid slot %d:\n",
1562  xhci->name, trb->slot );
1563  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1564  return;
1565  }
1566 
1567  /* Identify endpoint */
1568  if ( ( trb->endpoint >= XHCI_CTX_END ) ||
1569  ( ( endpoint = slot->endpoint[trb->endpoint] ) == NULL ) ) {
1570  DBGC ( xhci, "XHCI %s slot %d transfer event invalid epid "
1571  "%d:\n", xhci->name, slot->id, trb->endpoint );
1572  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1573  return;
1574  }
1575 
1576  /* Dequeue TRB(s) */
1577  iobuf = xhci_dequeue_multi ( &endpoint->ring );
1578  assert ( iobuf != NULL );
1579 
1580  /* Check for errors */
1581  if ( ! ( ( trb->code == XHCI_CMPLT_SUCCESS ) ||
1582  ( trb->code == XHCI_CMPLT_SHORT ) ) ) {
1583 
1584  /* Construct error */
1585  rc = -ECODE ( trb->code );
1586  DBGC ( xhci, "XHCI %s slot %d ctx %d failed (code %d): %s\n",
1587  xhci->name, slot->id, endpoint->ctx, trb->code,
1588  strerror ( rc ) );
1589  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1590 
1591  /* Sanity check */
1592  assert ( ( endpoint->context->state & XHCI_ENDPOINT_STATE_MASK )
1593  != XHCI_ENDPOINT_RUNNING );
1594 
1595  /* Report failure to USB core */
1596  usb_complete_err ( endpoint->ep, iobuf, rc );
1597  return;
1598  }
1599 
1600  /* Record actual transfer size */
1601  iob_unput ( iobuf, le16_to_cpu ( trb->residual ) );
1602 
1603  /* Sanity check (for successful completions only) */
1604  assert ( xhci_ring_consumed ( &endpoint->ring ) ==
1605  le64_to_cpu ( trb->transfer ) );
1606 
1607  /* Report completion to USB core */
1608  usb_complete ( endpoint->ep, iobuf );
1609  profile_stop ( &xhci_transfer_profiler );
1610 }
Short packet.
Definition: xhci.h:637
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
Definition: xhci.h:930
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:948
uint8_t state
Endpoint state.
Definition: xhci.h:771
#define DBGC(...)
Definition: compiler.h:505
uint8_t code
Completion code.
Definition: xhci.h:597
An xHCI endpoint.
Definition: xhci.h:1131
Success.
Definition: xhci.h:635
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:603
unsigned int slots
Number of device slots.
Definition: xhci.h:1057
#define ECODE(code)
Definition: xhci.c:234
uint8_t slot
Slot ID.
Definition: xhci.h:605
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int ctx
Context index.
Definition: xhci.h:1139
#define DBGC_HDA(...)
Definition: compiler.h:506
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1145
An xHCI device slot.
Definition: xhci.h:1105
#define iob_unput(iobuf, len)
Definition: iobuf.h:131
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1043
uint8_t slot
Slot.
Definition: edd.h:16
#define le16_to_cpu(value)
Definition: byteswap.h:112
Endpoint is running.
Definition: xhci.h:799
static struct io_buffer * xhci_dequeue_multi(struct xhci_trb_ring *ring)
Dequeue multiple transfer request blocks.
Definition: xhci.c:1379
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1137
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition: usb.h:1064
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1147
uint16_t residual
Residual transfer length.
Definition: xhci.h:593
uint64_t transfer
Transfer TRB pointer.
Definition: xhci.h:591
#define le64_to_cpu(value)
Definition: byteswap.h:114
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1095
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:569
#define XHCI_ENDPOINT_STATE_MASK
Endpoint state mask.
Definition: xhci.h:809
A persistent I/O buffer.
Definition: iobuf.h:32

References assert(), xhci_trb_transfer::code, xhci_endpoint::context, xhci_endpoint::ctx, DBGC, DBGC_HDA, ECODE, xhci_trb_transfer::endpoint, xhci_endpoint::ep, 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 1618 of file xhci.c.

1619  {
1620  int rc;
1621 
1622  /* Ignore "command ring stopped" notifications */
1623  if ( trb->code == XHCI_CMPLT_CMD_STOPPED ) {
1624  DBGC2 ( xhci, "XHCI %s command ring stopped\n", xhci->name );
1625  return;
1626  }
1627 
1628  /* Ignore unexpected completions */
1629  if ( ! xhci->pending ) {
1630  rc = -ECODE ( trb->code );
1631  DBGC ( xhci, "XHCI %s unexpected completion (code %d): %s\n",
1632  xhci->name, trb->code, strerror ( rc ) );
1633  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1634  return;
1635  }
1636 
1637  /* Dequeue command TRB */
1638  xhci_dequeue ( &xhci->command );
1639 
1640  /* Sanity check */
1641  assert ( xhci_ring_consumed ( &xhci->command ) ==
1642  le64_to_cpu ( trb->command ) );
1643 
1644  /* Record completion */
1645  memcpy ( xhci->pending, trb, sizeof ( *xhci->pending ) );
1646  xhci->pending = NULL;
1647 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t command
Command TRB pointer.
Definition: xhci.h:614
static struct io_buffer * xhci_dequeue(struct xhci_trb_ring *ring)
Dequeue a transfer request block.
Definition: xhci.c:1318
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
Definition: xhci.h:930
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1088
union xhci_trb * pending
Current command (if any)
Definition: xhci.h:1092
#define DBGC(...)
Definition: compiler.h:505
#define ECODE(code)
Definition: xhci.c:234
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define DBGC_HDA(...)
Definition: compiler.h:506
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1043
Command ring stopped.
Definition: xhci.h:639
#define DBGC2(...)
Definition: compiler.h:522
uint8_t code
Completion code.
Definition: xhci.h:618
#define le64_to_cpu(value)
Definition: byteswap.h:114
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

1656  {
1657  struct usb_port *port = usb_port ( xhci->bus->hub, trb->port );
1658  uint32_t portsc;
1659 
1660  /* Sanity check */
1661  assert ( ( trb->port > 0 ) && ( trb->port <= xhci->ports ) );
1662 
1663  /* Record disconnections and clear changes */
1664  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1665  port->disconnected |= ( portsc & XHCI_PORTSC_CSC );
1666  portsc &= ( XHCI_PORTSC_PRESERVE | XHCI_PORTSC_CHANGE );
1667  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1668 
1669  /* Report port status change */
1670  usb_port_changed ( port );
1671 }
unsigned int ports
Number of ports.
Definition: xhci.h:1061
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:1098
#define XHCI_PORTSC_CSC
Connect status change.
Definition: xhci.h:249
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
Definition: xhci.h:284
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition: usb.c:1794
A USB port.
Definition: usb.h:796
u8 port
Port number.
Definition: CIB_PRM.h:31
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_PORTSC_CHANGE
Port status change mask.
Definition: xhci.h:270
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
unsigned int uint32_t
Definition: stdint.h:12
uint8_t port
Port ID.
Definition: xhci.h:647
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
struct usb_hub * hub
Root hub.
Definition: usb.h:972
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:943
void * op
Operational registers.
Definition: xhci.h:1050

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

1680  {
1681  int rc;
1682 
1683  /* Construct error */
1684  rc = -ECODE ( trb->code );
1685  DBGC ( xhci, "XHCI %s host controller event (code %d): %s\n",
1686  xhci->name, trb->code, strerror ( rc ) );
1687 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
uint8_t code
Completion code.
Definition: xhci.h:670
#define ECODE(code)
Definition: xhci.c:234
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1043

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

1694  {
1695  struct xhci_event_ring *event = &xhci->event;
1696  union xhci_trb *trb;
1697  unsigned int shift = XHCI_EVENT_TRBS_LOG2;
1698  unsigned int count = ( 1 << shift );
1699  unsigned int mask = ( count - 1 );
1700  unsigned int consumed;
1701  unsigned int type;
1702 
1703  /* Poll for events */
1704  profile_start ( &xhci_event_profiler );
1705  for ( consumed = 0 ; ; consumed++ ) {
1706 
1707  /* Stop if we reach an empty TRB */
1708  rmb();
1709  trb = &event->trb[ event->cons & mask ];
1710  if ( ! ( ( trb->common.flags ^
1711  ( event->cons >> shift ) ) & XHCI_TRB_C ) )
1712  break;
1713 
1714  /* Consume this TRB */
1715  event->cons++;
1716 
1717  /* Handle TRB */
1718  type = ( trb->common.type & XHCI_TRB_TYPE_MASK );
1719  switch ( type ) {
1720 
1721  case XHCI_TRB_TRANSFER :
1722  xhci_transfer ( xhci, &trb->transfer );
1723  break;
1724 
1725  case XHCI_TRB_COMPLETE :
1726  xhci_complete ( xhci, &trb->complete );
1727  break;
1728 
1729  case XHCI_TRB_PORT_STATUS:
1730  xhci_port_status ( xhci, &trb->port );
1731  break;
1732 
1734  xhci_host_controller ( xhci, &trb->host );
1735  break;
1736 
1737  default:
1738  DBGC ( xhci, "XHCI %s unrecognised event %#x\n:",
1739  xhci->name, ( event->cons - 1 ) );
1740  DBGC_HDA ( xhci, virt_to_phys ( trb ),
1741  trb, sizeof ( *trb ) );
1742  break;
1743  }
1744  }
1745 
1746  /* Update dequeue pointer if applicable */
1747  if ( consumed ) {
1748  xhci_writeq ( xhci, virt_to_phys ( trb ),
1749  xhci->run + XHCI_RUN_ERDP ( 0 ) );
1750  profile_stop ( &xhci_event_profiler );
1751  }
1752 }
An event ring.
Definition: xhci.h:867
struct xhci_trb_common common
Common fields.
Definition: xhci.h:687
void * run
Runtime registers.
Definition: xhci.h:1052
uint8_t type
Type.
Definition: ena.h:16
struct xhci_trb_transfer transfer
Transfer event.
Definition: xhci.h:711
#define DBGC(...)
Definition: compiler.h:505
uint8_t type
Type.
Definition: xhci.h:323
uint8_t flags
Flags.
Definition: xhci.h:321
#define XHCI_TRB_PORT_STATUS
A port status change transfer request block.
Definition: xhci.h:661
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
static void xhci_transfer(struct xhci_device *xhci, struct xhci_trb_transfer *trb)
Handle transfer event.
Definition: xhci.c:1548
struct xhci_trb_host_controller host
Host controller event.
Definition: xhci.h:717
#define rmb()
Definition: io.h:484
#define XHCI_TRB_COMPLETE
A command completion event transfer request block.
Definition: xhci.h:630
#define DBGC_HDA(...)
Definition: compiler.h:506
#define XHCI_TRB_TRANSFER
A transfer event transfer request block.
Definition: xhci.h:609
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
#define XHCI_TRB_HOST_CONTROLLER
A port status change transfer request block.
Definition: xhci.h:680
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1043
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:360
struct xhci_trb_complete complete
Command completion event.
Definition: xhci.h:713
#define XHCI_TRB_TYPE_MASK
Transfer request block type mask.
Definition: xhci.h:347
static void xhci_host_controller(struct xhci_device *xhci, struct xhci_trb_host_controller *trb)
Handle host controller event.
Definition: xhci.c:1679
uint16_t count
Number of entries.
Definition: ena.h:22
static void xhci_complete(struct xhci_device *xhci, struct xhci_trb_complete *trb)
Handle command completion event.
Definition: xhci.c:1618
struct xhci_trb_port_status port
Port status changed event.
Definition: xhci.h:715
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:966
#define XHCI_TRB_C
Transfer request block cycle bit flag.
Definition: xhci.h:329
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1090
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:302
static void xhci_port_status(struct xhci_device *xhci, struct xhci_trb_port_status *trb)
Handle port status event.
Definition: xhci.c:1655

References xhci_trb::common, xhci_trb::complete, count, DBGC, DBGC_HDA, xhci_device::event, 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, virt_to_phys(), 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 1759 of file xhci.c.

1759  {
1760  physaddr_t crp;
1761 
1762  /* Abort the command */
1763  DBGC2 ( xhci, "XHCI %s aborting command\n", xhci->name );
1764  xhci_writeq ( xhci, XHCI_CRCR_CA, xhci->op + XHCI_OP_CRCR );
1765 
1766  /* Allow time for command to abort */
1768 
1769  /* Sanity check */
1770  assert ( ( readl ( xhci->op + XHCI_OP_CRCR ) & XHCI_CRCR_CRR ) == 0 );
1771 
1772  /* Consume (and ignore) any final command status */
1773  xhci_event_poll ( xhci );
1774 
1775  /* Reset the command ring control register */
1776  xhci_ring_reset ( &xhci->command );
1777  crp = virt_to_phys ( xhci->command.trb );
1778  xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ), xhci->op + XHCI_OP_CRCR );
1779 }
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1088
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define XHCI_COMMAND_ABORT_DELAY_MS
Time to delay after aborting a command.
Definition: xhci.h:1004
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
static void xhci_ring_reset(struct xhci_trb_ring *ring)
Reset transfer request block ring.
Definition: xhci.c:1233
#define XHCI_OP_CRCR
Command ring control register.
Definition: xhci.h:179
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const char * name
Name.
Definition: xhci.h:1043
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:360
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:1694
#define XHCI_CRCR_RCS
Command ring cycle state.
Definition: xhci.h:182
#define XHCI_CRCR_CA
Command abort.
Definition: xhci.h:185
#define XHCI_CRCR_CRR
Command ring running.
Definition: xhci.h:188
void * op
Operational registers.
Definition: xhci.h:1050

References assert(), xhci_device::command, DBGC2, mdelay(), xhci_device::name, xhci_device::op, readl(), xhci_trb_ring::trb, virt_to_phys(), XHCI_COMMAND_ABORT_DELAY_MS, XHCI_CRCR_CA, XHCI_CRCR_CRR, XHCI_CRCR_RCS, xhci_event_poll(), 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 1791 of file xhci.c.

1791  {
1792  struct xhci_trb_complete *complete = &trb->complete;
1793  unsigned int i;
1794  int rc;
1795 
1796  /* Record the pending command */
1797  xhci->pending = trb;
1798 
1799  /* Enqueue the command */
1800  if ( ( rc = xhci_enqueue ( &xhci->command, NULL, trb ) ) != 0 )
1801  goto err_enqueue;
1802 
1803  /* Ring the command doorbell */
1804  xhci_doorbell ( &xhci->command );
1805 
1806  /* Wait for the command to complete */
1807  for ( i = 0 ; i < XHCI_COMMAND_MAX_WAIT_MS ; i++ ) {
1808 
1809  /* Poll event ring */
1810  xhci_event_poll ( xhci );
1811 
1812  /* Check for completion */
1813  if ( ! xhci->pending ) {
1814  if ( complete->code != XHCI_CMPLT_SUCCESS ) {
1815  rc = -ECODE ( complete->code );
1816  DBGC ( xhci, "XHCI %s command failed (code "
1817  "%d): %s\n", xhci->name, complete->code,
1818  strerror ( rc ) );
1819  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1820  return rc;
1821  }
1822  return 0;
1823  }
1824 
1825  /* Delay */
1826  mdelay ( 1 );
1827  }
1828 
1829  /* Timeout */
1830  DBGC ( xhci, "XHCI %s timed out waiting for completion\n", xhci->name );
1831  rc = -ETIMEDOUT;
1832 
1833  /* Abort command */
1834  xhci_abort ( xhci );
1835 
1836  err_enqueue:
1837  xhci->pending = NULL;
1838  return rc;
1839 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1088
A command completion event transfer request block.
Definition: xhci.h:612
union xhci_trb * pending
Current command (if any)
Definition: xhci.h:1092
#define DBGC(...)
Definition: compiler.h:505
Success.
Definition: xhci.h:635
#define ECODE(code)
Definition: xhci.c:234
#define XHCI_COMMAND_MAX_WAIT_MS
Maximum time to wait for a command to complete.
Definition: xhci.h:998
#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:1043
struct xhci_trb_complete complete
Command completion event.
Definition: xhci.h:713
static void xhci_abort(struct xhci_device *xhci)
Abort command.
Definition: xhci.c:1759
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:1694
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:1275
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition: xhci.c:1396
uint8_t code
Completion code.
Definition: xhci.h:618
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References xhci_trb_complete::code, xhci_device::command, xhci_trb::complete, DBGC, DBGC_HDA, ECODE, ETIMEDOUT, 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 1847 of file xhci.c.

1847  {
1848  union xhci_trb trb;
1849  struct xhci_trb_common *nop = &trb.common;
1850  int rc;
1851 
1852  /* Construct command */
1853  memset ( nop, 0, sizeof ( *nop ) );
1854  nop->flags = XHCI_TRB_IOC;
1855  nop->type = XHCI_TRB_NOP_CMD;
1856 
1857  /* Issue command and wait for completion */
1858  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 )
1859  return rc;
1860 
1861  return 0;
1862 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A transfer request block.
Definition: xhci.h:315
#define XHCI_TRB_NOP_CMD
A no-op command transfer request block.
Definition: xhci.h:586
A transfer request block.
Definition: xhci.h:683
uint8_t nop
Definition: tcp.h:13
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1791
#define XHCI_TRB_IOC
Transfer request block interrupt on completion flag.
Definition: xhci.h:338
void * memset(void *dest, int character, size_t len) __nonnull

References xhci_trb::common, memset(), nop, rc, 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 1871 of file xhci.c.

1872  {
1873  union xhci_trb trb;
1874  struct xhci_trb_enable_slot *enable = &trb.enable;
1875  struct xhci_trb_complete *enabled = &trb.complete;
1876  unsigned int slot;
1877  int rc;
1878 
1879  /* Construct command */
1880  memset ( enable, 0, sizeof ( *enable ) );
1881  enable->slot = type;
1882  enable->type = XHCI_TRB_ENABLE_SLOT;
1883 
1884  /* Issue command and wait for completion */
1885  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1886  DBGC ( xhci, "XHCI %s could not enable new slot: %s\n",
1887  xhci->name, strerror ( rc ) );
1888  return rc;
1889  }
1890 
1891  /* Extract slot number */
1892  slot = enabled->slot;
1893 
1894  DBGC2 ( xhci, "XHCI %s slot %d enabled\n", xhci->name, slot );
1895  return slot;
1896 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_ENABLE_SLOT
An enable slot transfer request block.
Definition: xhci.h:482
uint8_t slot
Slot type.
Definition: xhci.h:476
A command completion event transfer request block.
Definition: xhci.h:612
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
An enable slot transfer request block.
Definition: xhci.h:466
uint8_t slot
Slot ID.
Definition: xhci.h:626
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1043
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:1791
uint8_t type
Type.
Definition: xhci.h:474
void * memset(void *dest, int character, size_t len) __nonnull

References xhci_trb::complete, DBGC, DBGC2, xhci_trb::enable, memset(), xhci_device::name, rc, slot, xhci_trb_enable_slot::slot, xhci_trb_complete::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 1905 of file xhci.c.

1906  {
1907  union xhci_trb trb;
1908  struct xhci_trb_disable_slot *disable = &trb.disable;
1909  int rc;
1910 
1911  /* Construct command */
1912  memset ( disable, 0, sizeof ( *disable ) );
1913  disable->type = XHCI_TRB_DISABLE_SLOT;
1914  disable->slot = slot;
1915 
1916  /* Issue command and wait for completion */
1917  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1918  DBGC ( xhci, "XHCI %s could not disable slot %d: %s\n",
1919  xhci->name, slot, strerror ( rc ) );
1920  return rc;
1921  }
1922 
1923  DBGC2 ( xhci, "XHCI %s slot %d disabled\n", xhci->name, slot );
1924  return 0;
1925 }
A disable slot transfer request block.
Definition: xhci.h:485
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_DISABLE_SLOT
A disable slot transfer request block.
Definition: xhci.h:501
#define DBGC(...)
Definition: compiler.h:505
uint8_t slot
Slot ID.
Definition: xhci.h:497
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1043
uint8_t slot
Slot.
Definition: edd.h:16
uint8_t type
Type.
Definition: xhci.h:493
#define DBGC2(...)
Definition: compiler.h:522
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1791
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 1937 of file xhci.c.

1942  {
1943  union xhci_trb trb;
1944  struct xhci_trb_context *context = &trb.context;
1945  size_t len;
1946  void *input;
1947  int rc;
1948 
1949  /* Allocate an input context */
1951  input = malloc_dma ( len, xhci_align ( len ) );
1952  if ( ! input ) {
1953  rc = -ENOMEM;
1954  goto err_alloc;
1955  }
1956  memset ( input, 0, len );
1957 
1958  /* Populate input context */
1959  populate ( xhci, slot, endpoint, input );
1960 
1961  /* Construct command */
1962  memset ( context, 0, sizeof ( *context ) );
1963  context->type = type;
1964  context->input = cpu_to_le64 ( virt_to_phys ( input ) );
1965  context->slot = slot->id;
1966 
1967  /* Issue command and wait for completion */
1968  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 )
1969  goto err_command;
1970 
1971  err_command:
1972  free_dma ( input, len );
1973  err_alloc:
1974  return rc;
1975 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:948
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:394
uint8_t type
Type.
Definition: ena.h:16
#define cpu_to_le64(value)
Definition: byteswap.h:108
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint64_t input
Input context.
Definition: xhci.h:506
#define ENOMEM
Not enough space.
Definition: errno.h:534
A context transfer request block.
Definition: xhci.h:504
A transfer request block.
Definition: xhci.h:683
uint8_t slot
Slot.
Definition: edd.h:16
uint32_t len
Length.
Definition: ena.h:14
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:425
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1791
uint8_t type
Type.
Definition: xhci.h:512
uint8_t slot
Slot ID.
Definition: xhci.h:516
void * memset(void *dest, int character, size_t len) __nonnull

References xhci_trb::context, cpu_to_le64, ENOMEM, free_dma(), xhci_trb_context::input, len, malloc_dma(), memset(), rc, slot, xhci_trb_context::slot, type, xhci_trb_context::type, virt_to_phys(), 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 1985 of file xhci.c.

1988  {
1989  struct xhci_control_context *control_ctx;
1990  struct xhci_slot_context *slot_ctx;
1991  struct xhci_endpoint_context *ep_ctx;
1992 
1993  /* Sanity checks */
1994  assert ( endpoint->ctx == XHCI_CTX_EP0 );
1995 
1996  /* Populate control context */
1997  control_ctx = input;
1998  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
1999  ( 1 << XHCI_CTX_EP0 ) );
2000 
2001  /* Populate slot context */
2002  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2003  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( 1, 0, slot->psiv,
2004  slot->route ) );
2005  slot_ctx->port = slot->port;
2006  slot_ctx->tt_id = slot->tt_id;
2007  slot_ctx->tt_port = slot->tt_port;
2008 
2009  /* Populate control endpoint context */
2010  ep_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_EP0 ) );
2011  ep_ctx->type = XHCI_EP_TYPE_CONTROL;
2012  ep_ctx->burst = endpoint->ep->burst;
2013  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2014  ep_ctx->dequeue = cpu_to_le64 ( virt_to_phys ( endpoint->ring.trb ) |
2015  XHCI_EP_DCS );
2016  ep_ctx->trb_len = cpu_to_le16 ( XHCI_EP0_TRB_LEN );
2017 }
An endpoint context.
Definition: xhci.h:769
uint8_t burst
Maximum burst size.
Definition: xhci.h:781
uint8_t type
Endpoint type.
Definition: xhci.h:779
An input control context.
Definition: xhci.h:721
uint16_t trb_len
Average TRB length.
Definition: xhci.h:787
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
Definition: xhci.h:815
#define cpu_to_le64(value)
Definition: byteswap.h:108
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint32_t add
Add context flags.
Definition: xhci.h:725
uint64_t dequeue
Transfer ring dequeue pointer.
Definition: xhci.h:785
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:824
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int ctx
Context index.
Definition: xhci.h:1139
uint8_t port
Root hub port number.
Definition: xhci.h:745
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:765
uint16_t mtu
Maximum packet size.
Definition: xhci.h:783
unsigned int burst
Maximum burst size.
Definition: usb.h:399
uint32_t info
Device info.
Definition: xhci.h:741
#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:827
size_t mtu
Maximum transfer size.
Definition: usb.h:397
uint8_t tt_id
TT hub slot ID.
Definition: xhci.h:749
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1137
uint8_t tt_port
TT port number.
Definition: xhci.h:751
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1147
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:425
#define cpu_to_le16(value)
Definition: byteswap.h:106
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:945
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:937

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, xhci_endpoint::ep, xhci_slot_context::info, 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, virt_to_phys(), 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 2026 of file xhci.c.

2027  {
2028  struct usb_device *usb = slot->usb;
2029  struct xhci_slot_context *slot_ctx;
2030  int rc;
2031 
2032  /* Assign device address */
2033  if ( ( rc = xhci_context ( xhci, slot, slot->endpoint[XHCI_CTX_EP0],
2035  xhci_address_device_input ) ) != 0 )
2036  return rc;
2037 
2038  /* Get assigned address */
2039  slot_ctx = ( slot->context +
2041  usb->address = slot_ctx->address;
2042  DBGC2 ( xhci, "XHCI %s assigned address %d to %s\n",
2043  xhci->name, usb->address, usb->name );
2044 
2045  return 0;
2046 }
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:413
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:1937
unsigned int address
Device address, if assigned.
Definition: usb.h:716
uint8_t address
USB address.
Definition: xhci.h:755
#define XHCI_TRB_ADDRESS_DEVICE
An address device transfer request block.
Definition: xhci.h:520
char name[32]
Name.
Definition: usb.h:708
A USB device.
Definition: usb.h:706
const char * name
Name.
Definition: xhci.h:1043
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:1985
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:945
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:937

References usb_device::address, xhci_slot_context::address, DBGC2, usb_device::name, xhci_device::name, rc, slot, 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 2056 of file xhci.c.

2059  {
2060  struct xhci_control_context *control_ctx;
2061  struct xhci_slot_context *slot_ctx;
2062  struct xhci_endpoint_context *ep_ctx;
2063 
2064  /* Populate control context */
2065  control_ctx = input;
2066  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2067  ( 1 << endpoint->ctx ) );
2068 
2069  /* Populate slot context */
2070  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2071  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2072  ( slot->ports ? 1 : 0 ),
2073  slot->psiv, 0 ) );
2074  slot_ctx->ports = slot->ports;
2075 
2076  /* Populate endpoint context */
2077  ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2078  ep_ctx->interval = endpoint->interval;
2079  ep_ctx->type = endpoint->type;
2080  ep_ctx->burst = endpoint->ep->burst;
2081  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2082  ep_ctx->dequeue = cpu_to_le64 ( virt_to_phys ( endpoint->ring.trb ) |
2083  XHCI_EP_DCS );
2084  ep_ctx->trb_len = cpu_to_le16 ( endpoint->ep->mtu ); /* best guess */
2085 }
An endpoint context.
Definition: xhci.h:769
uint8_t burst
Maximum burst size.
Definition: xhci.h:781
uint8_t type
Endpoint type.
Definition: xhci.h:779
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:948
An input control context.
Definition: xhci.h:721
uint16_t trb_len
Average TRB length.
Definition: xhci.h:787
#define cpu_to_le64(value)
Definition: byteswap.h:108
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint32_t add
Add context flags.
Definition: xhci.h:725
uint64_t dequeue
Transfer ring dequeue pointer.
Definition: xhci.h:785
uint8_t ports
Number of downstream ports.
Definition: xhci.h:747
unsigned int type
Endpoint type.
Definition: xhci.h:1141
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:824
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
unsigned int ctx
Context index.
Definition: xhci.h:1139
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:765
uint16_t mtu
Maximum packet size.
Definition: xhci.h:783
unsigned int burst
Maximum burst size.
Definition: usb.h:399
uint32_t info
Device info.
Definition: xhci.h:741
#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:397
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1137
uint8_t interval
Polling interval.
Definition: xhci.h:775
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1147
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:425
#define cpu_to_le16(value)
Definition: byteswap.h:106
unsigned int interval
Endpoint interval.
Definition: xhci.h:1143
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:937

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, xhci_endpoint::ep, xhci_slot_context::info, xhci_endpoint_context::interval, xhci_endpoint::interval, 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, virt_to_phys(), 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 2095 of file xhci.c.

2097  {
2098  int rc;
2099 
2100  /* Configure endpoint */
2101  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2104  return rc;
2105 
2106  DBGC2 ( xhci, "XHCI %s slot %d ctx %d configured\n",
2107  xhci->name, slot->id, endpoint->ctx );
2108  return 0;
2109 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
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:1937
unsigned int ctx
Context index.
Definition: xhci.h:1139
const char * name
Name.
Definition: xhci.h:1043
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:2056
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
Definition: xhci.h:523
#define DBGC2(...)
Definition: compiler.h:522

References xhci_endpoint::ctx, DBGC2, xhci_device::name, rc, slot, 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 2120 of file xhci.c.

2123  {
2124  struct xhci_control_context *control_ctx;
2125  struct xhci_slot_context *slot_ctx;
2126 
2127  /* Populate control context */
2128  control_ctx = input;
2129  control_ctx->add = cpu_to_le32 ( 1 << XHCI_CTX_SLOT );
2130  control_ctx->drop = cpu_to_le32 ( 1 << endpoint->ctx );
2131 
2132  /* Populate slot context */
2133  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2134  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2135  0, 0, 0 ) );
2136 }
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:948
An input control context.
Definition: xhci.h:721
uint32_t add
Add context flags.
Definition: xhci.h:725
uint32_t drop
Drop context flags.
Definition: xhci.h:723
unsigned int ctx
Context index.
Definition: xhci.h:1139
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:765
uint32_t info
Device info.
Definition: xhci.h:741
#define cpu_to_le32(value)
Definition: byteswap.h:107
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:425
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:937

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

2148  {
2149  int rc;
2150 
2151  /* Deconfigure endpoint */
2152  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2155  return rc;
2156 
2157  DBGC2 ( xhci, "XHCI %s slot %d ctx %d deconfigured\n",
2158  xhci->name, slot->id, endpoint->ctx );
2159  return 0;
2160 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
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:1937
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:2120
unsigned int ctx
Context index.
Definition: xhci.h:1139
const char * name
Name.
Definition: xhci.h:1043
uint8_t slot
Slot.
Definition: edd.h:16
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
Definition: xhci.h:523
#define DBGC2(...)
Definition: compiler.h:522

References xhci_endpoint::ctx, DBGC2, xhci_device::name, rc, slot, 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 2170 of file xhci.c.

2173  {
2174  struct xhci_control_context *control_ctx;
2175  struct xhci_slot_context *slot_ctx;
2176  struct xhci_endpoint_context *ep_ctx;
2177 
2178  /* Populate control context */
2179  control_ctx = input;
2180  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2181  ( 1 << endpoint->ctx ) );
2182 
2183  /* Populate slot context */
2184  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2185  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2186  0, 0, 0 ) );
2187 
2188  /* Populate endpoint context */
2189  ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2190  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2191 }
An endpoint context.
Definition: xhci.h:769
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:948
An input control context.
Definition: xhci.h:721
uint32_t add
Add context flags.
Definition: xhci.h:725
unsigned int ctx
Context index.
Definition: xhci.h:1139
#define XHCI_SLOT_INFO(entries, hub, speed, route)
Construct slot context device info.
Definition: xhci.h:765
uint16_t mtu
Maximum packet size.
Definition: xhci.h:783
uint32_t info
Device info.
Definition: xhci.h:741
#define cpu_to_le32(value)
Definition: byteswap.h:107
size_t mtu
Maximum transfer size.
Definition: usb.h:397
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1137
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:425
#define cpu_to_le16(value)
Definition: byteswap.h:106
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:937

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

2203  {
2204  int rc;
2205 
2206  /* Configure endpoint */
2207  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2209  xhci_evaluate_context_input ) ) != 0 )
2210  return rc;
2211 
2212  DBGC2 ( xhci, "XHCI %s slot %d ctx %d (re-)evaluated\n",
2213  xhci->name, slot->id, endpoint->ctx );
2214  return 0;
2215 }
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:2170
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:1937
unsigned int ctx
Context index.
Definition: xhci.h:1139
const char * name
Name.
Definition: xhci.h:1043
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:526

References xhci_endpoint::ctx, DBGC2, xhci_device::name, rc, slot, 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 2225 of file xhci.c.

2227  {
2228  union xhci_trb trb;
2229  struct xhci_trb_reset_endpoint *reset = &trb.reset;
2230  int rc;
2231 
2232  /* Construct command */
2233  memset ( reset, 0, sizeof ( *reset ) );
2234  reset->slot = slot->id;
2235  reset->endpoint = endpoint->ctx;
2236  reset->type = XHCI_TRB_RESET_ENDPOINT;
2237 
2238  /* Issue command and wait for completion */
2239  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2240  DBGC ( xhci, "XHCI %s slot %d ctx %d could not reset endpoint "
2241  "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2242  endpoint->context->state, strerror ( rc ) );
2243  return rc;
2244  }
2245 
2246  return 0;
2247 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_TRB_RESET_ENDPOINT
A reset endpoint transfer request block.
Definition: xhci.h:545
uint8_t type
Type.
Definition: xhci.h:537
uint8_t slot
Slot ID.
Definition: xhci.h:541
A reset endpoint transfer request block.
Definition: xhci.h:529
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1043
uint8_t slot
Slot.
Definition: edd.h:16
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:539
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1791
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 2257 of file xhci.c.

2259  {
2260  union xhci_trb trb;
2261  struct xhci_trb_stop_endpoint *stop = &trb.stop;
2262  int rc;
2263 
2264  /* Construct command */
2265  memset ( stop, 0, sizeof ( *stop ) );
2266  stop->slot = slot->id;
2267  stop->endpoint = endpoint->ctx;
2268  stop->type = XHCI_TRB_STOP_ENDPOINT;
2269 
2270  /* Issue command and wait for completion */
2271  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2272  DBGC ( xhci, "XHCI %s slot %d ctx %d could not stop endpoint "
2273  "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2274  endpoint->context->state, strerror ( rc ) );
2275  return rc;
2276  }
2277 
2278  return 0;
2279 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:558
uint8_t slot
Slot ID.
Definition: xhci.h:560
#define XHCI_TRB_STOP_ENDPOINT
A stop endpoint transfer request block.
Definition: xhci.h:564
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1043
uint8_t slot
Slot.
Definition: edd.h:16
uint8_t type
Type.
Definition: xhci.h:556
A stop endpoint transfer request block.
Definition: xhci.h:548
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1791
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 2290 of file xhci.c.

2292  {
2293  union xhci_trb trb;
2294  struct xhci_trb_set_tr_dequeue_pointer *dequeue = &trb.dequeue;
2295  struct xhci_trb_ring *ring = &endpoint->ring;
2296  unsigned int cons;
2297  unsigned int mask;
2298  unsigned int index;
2299  unsigned int dcs;
2300  int rc;
2301 
2302  /* Construct command */
2303  memset ( dequeue, 0, sizeof ( *dequeue ) );
2304  cons = ring->cons;
2305  mask = ring->mask;
2306  dcs = ( ( ~( cons >> ring->shift ) ) & XHCI_EP_DCS );
2307  index = ( cons & mask );
2308  dequeue->dequeue =
2309  cpu_to_le64 ( virt_to_phys ( &ring->trb[index] ) | dcs );
2310  dequeue->slot = slot->id;
2311  dequeue->endpoint = endpoint->ctx;
2313 
2314  /* Issue command and wait for completion */
2315  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2316  DBGC ( xhci, "XHCI %s slot %d ctx %d could not set TR dequeue "
2317  "pointer in state %d: %s\n", xhci->name, slot->id,
2318  endpoint->ctx, endpoint->context->state, strerror ( rc));
2319  return rc;
2320  }
2321 
2322  return 0;
2323 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_SET_TR_DEQUEUE_POINTER
A set transfer ring dequeue pointer transfer request block.
Definition: xhci.h:583
unsigned int cons
Consumer counter.
Definition: xhci.h:844
A set transfer ring dequeue pointer transfer request block.
Definition: xhci.h:567
uint8_t state
Endpoint state.
Definition: xhci.h:771
#define DBGC(...)
Definition: compiler.h:505
#define cpu_to_le64(value)
Definition: byteswap.h:108
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint64_t dequeue
Dequeue pointer.
Definition: xhci.h:569
#define XHCI_EP_DCS
Endpoint dequeue cycle state.
Definition: xhci.h:824
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
unsigned int ctx
Context index.
Definition: xhci.h:1139
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1145
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:683
const char * name
Name.
Definition: xhci.h:1043
uint8_t slot
Slot ID.
Definition: xhci.h:579
uint8_t slot
Slot.
Definition: edd.h:16
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1147
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
A transfer request block command/transfer ring.
Definition: xhci.h:840
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1791
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:577
void * memset(void *dest, int character, size_t len) __nonnull

References 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, xhci_trb_set_tr_dequeue_pointer::endpoint, index, 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, virt_to_phys(), 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 2338 of file xhci.c.

2338  {
2339  struct usb_device *usb = ep->usb;
2340  struct xhci_slot *slot = usb_get_hostdata ( usb );
2341  struct xhci_device *xhci = slot->xhci;
2342  struct xhci_endpoint *endpoint;
2343  unsigned int ctx;
2344  unsigned int type;
2345  unsigned int interval;
2346  int rc;
2347 
2348  /* Calculate context index */
2349  ctx = XHCI_CTX ( ep->address );
2350  assert ( slot->endpoint[ctx] == NULL );
2351 
2352  /* Calculate endpoint type */
2356  if ( ep->address & USB_DIR_IN )
2357  type |= XHCI_EP_TYPE_IN;
2358 
2359  /* Calculate interval */
2360  if ( type & XHCI_EP_TYPE_PERIODIC ) {
2361  interval = ( fls ( ep->interval ) - 1 );
2362  } else {
2363  interval = ep->interval;
2364  }
2365 
2366  /* Allocate and initialise structure */
2367  endpoint = zalloc ( sizeof ( *endpoint ) );
2368  if ( ! endpoint ) {
2369  rc = -ENOMEM;
2370  goto err_alloc;
2371  }
2372  usb_endpoint_set_hostdata ( ep, endpoint );
2373  slot->endpoint[ctx] = endpoint;
2374  endpoint->xhci = xhci;
2375  endpoint->slot = slot;
2376  endpoint->ep = ep;
2377  endpoint->ctx = ctx;
2378  endpoint->type = type;
2379  endpoint->interval = interval;
2380  endpoint->context = ( ( ( void * ) slot->context ) +
2382 
2383  /* Allocate transfer ring */
2384  if ( ( rc = xhci_ring_alloc ( xhci, &endpoint->ring,
2386  slot->id, ctx, 0 ) ) != 0 )
2387  goto err_ring_alloc;
2388 
2389  /* Configure endpoint, if applicable */
2390  if ( ( ctx != XHCI_CTX_EP0 ) &&
2391  ( ( rc = xhci_configure_endpoint ( xhci, slot, endpoint ) ) != 0 ))
2392  goto err_configure_endpoint;
2393 
2394  DBGC2 ( xhci, "XHCI %s slot %d ctx %d ring [%08lx,%08lx)\n",
2395  xhci->name, slot->id, ctx, virt_to_phys ( endpoint->ring.trb ),
2396  ( virt_to_phys ( endpoint->ring.trb ) + endpoint->ring.len ) );
2397  return 0;
2398 
2399  xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2400  err_configure_endpoint:
2401  xhci_ring_free ( &endpoint->ring );
2402  err_ring_alloc:
2403  slot->endpoint[ctx] = NULL;
2404  free ( endpoint );
2405  err_alloc:
2406  return rc;
2407 }
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
Definition: usb.h:561
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:413
An xHCI device.
Definition: xhci.h:1039
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:266
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
uint8_t type
Type.
Definition: ena.h:16
#define XHCI_EP_TYPE(type)
Endpoint type.
Definition: xhci.h:812
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
Definition: xhci.h:815
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1249
static int xhci_configure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Configure endpoint.
Definition: xhci.c:2095
#define XHCI_TRANSFER_TRBS_LOG2
Number of TRBs in a transfer ring.
Definition: xhci.h:972
An xHCI endpoint.
Definition: xhci.h:1131
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
unsigned int type
Endpoint type.
Definition: xhci.h:1141
#define XHCI_EP_TYPE_IN
Input endpoint type.
Definition: xhci.h:818
#define ENOMEM
Not enough space.
Definition: errno.h:534
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_EP_TYPE_PERIODIC
Periodic endpoint type.
Definition: xhci.h:821
unsigned int ctx
Context index.
Definition: xhci.h:1139
struct usb_device * usb
USB device.
Definition: xhci.h:1109
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:83