iPXE
Macros | Functions | Variables
xhci.c File Reference

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

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/usb.h>
#include <ipxe/init.h>
#include <ipxe/profile.h>
#include "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_fail (struct xhci_device *xhci)
 Mark xHCI device as permanently failed. More...
 
static int xhci_ring_alloc (struct xhci_device *xhci, struct xhci_trb_ring *ring, unsigned int shift, unsigned int slot, unsigned int target, unsigned int stream)
 Allocate transfer request block ring. More...
 
static void xhci_ring_reset (struct xhci_trb_ring *ring)
 Reset transfer request block ring. More...
 
static void xhci_ring_free (struct xhci_trb_ring *ring)
 Free transfer request block ring. More...
 
static int xhci_enqueue (struct xhci_trb_ring *ring, struct io_buffer *iobuf, const union xhci_trb *trb)
 Enqueue a transfer request block. More...
 
static struct io_bufferxhci_dequeue (struct xhci_trb_ring *ring)
 Dequeue a transfer request block. More...
 
static int xhci_enqueue_multi (struct xhci_trb_ring *ring, struct io_buffer *iobuf, const union xhci_trb *trbs, unsigned int count)
 Enqueue multiple transfer request blocks. More...
 
static struct io_bufferxhci_dequeue_multi (struct xhci_trb_ring *ring)
 Dequeue multiple transfer request blocks. More...
 
static void xhci_doorbell (struct xhci_trb_ring *ring)
 Ring doorbell register. More...
 
static int xhci_command_alloc (struct xhci_device *xhci)
 Allocate command ring. More...
 
static void xhci_command_free (struct xhci_device *xhci)
 Free command ring. More...
 
static int xhci_event_alloc (struct xhci_device *xhci)
 Allocate event ring. More...
 
static void xhci_event_free (struct xhci_device *xhci)
 Free event ring. More...
 
static void xhci_transfer (struct xhci_device *xhci, struct xhci_trb_transfer *trb)
 Handle transfer event. More...
 
static void xhci_complete (struct xhci_device *xhci, struct xhci_trb_complete *trb)
 Handle command completion event. More...
 
static void xhci_port_status (struct xhci_device *xhci, struct xhci_trb_port_status *trb)
 Handle port status event. More...
 
static void xhci_host_controller (struct xhci_device *xhci, struct xhci_trb_host_controller *trb)
 Handle host controller event. More...
 
static void xhci_event_poll (struct xhci_device *xhci)
 Poll event ring. More...
 
static void xhci_abort (struct xhci_device *xhci)
 Abort command. More...
 
static int xhci_command (struct xhci_device *xhci, union xhci_trb *trb)
 Issue command and wait for completion. More...
 
static int xhci_nop (struct xhci_device *xhci)
 Issue NOP and wait for completion. More...
 
static int xhci_enable_slot (struct xhci_device *xhci, unsigned int type)
 Enable slot. More...
 
static int xhci_disable_slot (struct xhci_device *xhci, unsigned int slot)
 Disable slot. More...
 
static int xhci_context (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, unsigned int type, void(*populate)(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input))
 Issue context-based command and wait for completion. More...
 
static void xhci_address_device_input (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input)
 Populate address device input context. More...
 
static int xhci_address_device (struct xhci_device *xhci, struct xhci_slot *slot)
 Address device. More...
 
static void xhci_configure_endpoint_input (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input)
 Populate configure endpoint input context. More...
 
static int xhci_configure_endpoint (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Configure endpoint. More...
 
static void xhci_deconfigure_endpoint_input (struct xhci_device *xhci __unused, struct xhci_slot *slot __unused, struct xhci_endpoint *endpoint, void *input)
 Populate deconfigure endpoint input context. More...
 
static int xhci_deconfigure_endpoint (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Deconfigure endpoint. More...
 
static void xhci_evaluate_context_input (struct xhci_device *xhci, struct xhci_slot *slot __unused, struct xhci_endpoint *endpoint, void *input)
 Populate evaluate context input context. More...
 
static int xhci_evaluate_context (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Evaluate context. More...
 
static int xhci_reset_endpoint (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Reset endpoint. More...
 
static int xhci_stop_endpoint (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Stop endpoint. More...
 
static int xhci_set_tr_dequeue_pointer (struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
 Set transfer ring dequeue pointer. More...
 
static int xhci_endpoint_open (struct usb_endpoint *ep)
 Open endpoint. More...
 
static void xhci_endpoint_close (struct usb_endpoint *ep)
 Close endpoint. More...
 
static int xhci_endpoint_reset (struct usb_endpoint *ep)
 Reset endpoint. More...
 
static int xhci_endpoint_mtu (struct usb_endpoint *ep)
 Update MTU. More...
 
static int xhci_endpoint_message (struct usb_endpoint *ep, struct io_buffer *iobuf)
 Enqueue message transfer. More...
 
static unsigned int xhci_endpoint_count (size_t len, int zlp)
 Calculate number of TRBs. More...
 
static int xhci_endpoint_stream (struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
 Enqueue stream transfer. More...
 
static int xhci_device_open (struct usb_device *usb)
 Open device. More...
 
static void xhci_device_close (struct usb_device *usb)
 Close device. More...
 
static int xhci_device_address (struct usb_device *usb)
 Assign device address. More...
 
static int xhci_bus_open (struct usb_bus *bus)
 Open USB bus. More...
 
static void xhci_bus_close (struct usb_bus *bus)
 Close USB bus. More...
 
static void xhci_bus_poll (struct usb_bus *bus)
 Poll USB bus. More...
 
static int xhci_hub_open (struct usb_hub *hub)
 Open hub. More...
 
static void xhci_hub_close (struct usb_hub *hub __unused)
 Close hub. More...
 
static int xhci_root_open (struct usb_hub *hub)
 Open root hub. More...
 
static void xhci_root_close (struct usb_hub *hub __unused)
 Close root hub. More...
 
static int xhci_root_enable (struct usb_hub *hub, struct usb_port *port)
 Enable port. More...
 
static int xhci_root_disable (struct usb_hub *hub, struct usb_port *port)
 Disable port. More...
 
static int xhci_root_speed (struct usb_hub *hub, struct usb_port *port)
 Update root hub port speed. More...
 
static int xhci_root_clear_tt (struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
 Clear transaction translator buffer. More...
 
static void xhci_pch_fix (struct xhci_device *xhci, struct pci_device *pci)
 Fix Intel PCH-specific quirks. More...
 
static void xhci_pch_undo (struct xhci_device *xhci, struct pci_device *pci)
 Undo Intel PCH-specific quirk fixes. More...
 
static int xhci_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void xhci_remove (struct pci_device *pci)
 Remove PCI device. More...
 
static void xhci_shutdown (int booting)
 Prepare for exit. More...
 
struct startup_fn xhci_startup __startup_fn (STARTUP_LATE)
 Startup/shutdown function. More...
 

Variables

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

Detailed Description

USB eXtensible Host Controller Interface (xHCI) driver.

Definition in file xhci.c.

Macro Definition Documentation

◆ EIO_DATA

#define EIO_DATA   __einfo_error ( EINFO_EIO_DATA )

Definition at line 63 of file xhci.c.

◆ EINFO_EIO_DATA

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

Definition at line 65 of file xhci.c.

◆ EIO_BABBLE

#define EIO_BABBLE   __einfo_error ( EINFO_EIO_BABBLE )

Definition at line 68 of file xhci.c.

◆ EINFO_EIO_BABBLE

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

Definition at line 70 of file xhci.c.

◆ EIO_USB

#define EIO_USB   __einfo_error ( EINFO_EIO_USB )

Definition at line 73 of file xhci.c.

◆ EINFO_EIO_USB

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

Definition at line 75 of file xhci.c.

◆ EIO_TRB

#define EIO_TRB   __einfo_error ( EINFO_EIO_TRB )

Definition at line 78 of file xhci.c.

◆ EINFO_EIO_TRB

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

Definition at line 80 of file xhci.c.

◆ EIO_STALL

#define EIO_STALL   __einfo_error ( EINFO_EIO_STALL )

Definition at line 83 of file xhci.c.

◆ EINFO_EIO_STALL

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

Definition at line 85 of file xhci.c.

◆ EIO_RESOURCE

#define EIO_RESOURCE   __einfo_error ( EINFO_EIO_RESOURCE )

Definition at line 88 of file xhci.c.

◆ EINFO_EIO_RESOURCE

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

Definition at line 90 of file xhci.c.

◆ EIO_BANDWIDTH

#define EIO_BANDWIDTH   __einfo_error ( EINFO_EIO_BANDWIDTH )

Definition at line 93 of file xhci.c.

◆ EINFO_EIO_BANDWIDTH

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

Definition at line 95 of file xhci.c.

◆ EIO_NO_SLOTS

#define EIO_NO_SLOTS   __einfo_error ( EINFO_EIO_NO_SLOTS )

Definition at line 98 of file xhci.c.

◆ EINFO_EIO_NO_SLOTS

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

Definition at line 100 of file xhci.c.

◆ EIO_STREAM_TYPE

#define EIO_STREAM_TYPE   __einfo_error ( EINFO_EIO_STREAM_TYPE )

Definition at line 103 of file xhci.c.

◆ EINFO_EIO_STREAM_TYPE

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

Definition at line 105 of file xhci.c.

◆ EIO_SLOT

#define EIO_SLOT   __einfo_error ( EINFO_EIO_SLOT )

Definition at line 108 of file xhci.c.

◆ EINFO_EIO_SLOT

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

Definition at line 110 of file xhci.c.

◆ EIO_ENDPOINT

#define EIO_ENDPOINT   __einfo_error ( EINFO_EIO_ENDPOINT )

Definition at line 113 of file xhci.c.

◆ EINFO_EIO_ENDPOINT

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

Definition at line 115 of file xhci.c.

◆ EIO_SHORT

#define EIO_SHORT   __einfo_error ( EINFO_EIO_SHORT )

Definition at line 118 of file xhci.c.

◆ EINFO_EIO_SHORT

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

Definition at line 120 of file xhci.c.

◆ EIO_UNDERRUN

#define EIO_UNDERRUN   __einfo_error ( EINFO_EIO_UNDERRUN )

Definition at line 123 of file xhci.c.

◆ EINFO_EIO_UNDERRUN

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

Definition at line 125 of file xhci.c.

◆ EIO_OVERRUN

#define EIO_OVERRUN   __einfo_error ( EINFO_EIO_OVERRUN )

Definition at line 128 of file xhci.c.

◆ EINFO_EIO_OVERRUN

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

Definition at line 130 of file xhci.c.

◆ EIO_VF_RING_FULL

#define EIO_VF_RING_FULL   __einfo_error ( EINFO_EIO_VF_RING_FULL )

Definition at line 133 of file xhci.c.

◆ EINFO_EIO_VF_RING_FULL

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

Definition at line 135 of file xhci.c.

◆ EIO_PARAMETER

#define EIO_PARAMETER   __einfo_error ( EINFO_EIO_PARAMETER )

Definition at line 138 of file xhci.c.

◆ EINFO_EIO_PARAMETER

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

Definition at line 140 of file xhci.c.

◆ EIO_BANDWIDTH_OVERRUN

#define EIO_BANDWIDTH_OVERRUN   __einfo_error ( EINFO_EIO_BANDWIDTH_OVERRUN )

Definition at line 143 of file xhci.c.

◆ EINFO_EIO_BANDWIDTH_OVERRUN

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

Definition at line 145 of file xhci.c.

◆ EIO_CONTEXT

#define EIO_CONTEXT   __einfo_error ( EINFO_EIO_CONTEXT )

Definition at line 148 of file xhci.c.

◆ EINFO_EIO_CONTEXT

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

Definition at line 150 of file xhci.c.

◆ EIO_NO_PING

#define EIO_NO_PING   __einfo_error ( EINFO_EIO_NO_PING )

Definition at line 153 of file xhci.c.

◆ EINFO_EIO_NO_PING

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

Definition at line 155 of file xhci.c.

◆ EIO_RING_FULL

#define EIO_RING_FULL   __einfo_error ( EINFO_EIO_RING_FULL )

Definition at line 158 of file xhci.c.

◆ EINFO_EIO_RING_FULL

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

Definition at line 160 of file xhci.c.

◆ EIO_INCOMPATIBLE

#define EIO_INCOMPATIBLE   __einfo_error ( EINFO_EIO_INCOMPATIBLE )

Definition at line 163 of file xhci.c.

◆ EINFO_EIO_INCOMPATIBLE

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

Definition at line 165 of file xhci.c.

◆ EIO_MISSED

#define EIO_MISSED   __einfo_error ( EINFO_EIO_MISSED )

Definition at line 168 of file xhci.c.

◆ EINFO_EIO_MISSED

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

Definition at line 170 of file xhci.c.

◆ EIO_CMD_STOPPED

#define EIO_CMD_STOPPED   __einfo_error ( EINFO_EIO_CMD_STOPPED )

Definition at line 173 of file xhci.c.

◆ EINFO_EIO_CMD_STOPPED

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

Definition at line 175 of file xhci.c.

◆ EIO_CMD_ABORTED

#define EIO_CMD_ABORTED   __einfo_error ( EINFO_EIO_CMD_ABORTED )

Definition at line 178 of file xhci.c.

◆ EINFO_EIO_CMD_ABORTED

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

Definition at line 180 of file xhci.c.

◆ EIO_STOP

#define EIO_STOP   __einfo_error ( EINFO_EIO_STOP )

Definition at line 183 of file xhci.c.

◆ EINFO_EIO_STOP

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

Definition at line 185 of file xhci.c.

◆ EIO_STOP_LEN

#define EIO_STOP_LEN   __einfo_error ( EINFO_EIO_STOP_LEN )

Definition at line 188 of file xhci.c.

◆ EINFO_EIO_STOP_LEN

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

Definition at line 190 of file xhci.c.

◆ EIO_STOP_SHORT

#define EIO_STOP_SHORT   __einfo_error ( EINFO_EIO_STOP_SHORT )

Definition at line 193 of file xhci.c.

◆ EINFO_EIO_STOP_SHORT

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

Definition at line 195 of file xhci.c.

◆ EIO_LATENCY

#define EIO_LATENCY   __einfo_error ( EINFO_EIO_LATENCY )

Definition at line 198 of file xhci.c.

◆ EINFO_EIO_LATENCY

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

Definition at line 200 of file xhci.c.

◆ EIO_ISOCH

#define EIO_ISOCH   __einfo_error ( EINFO_EIO_ISOCH )

Definition at line 203 of file xhci.c.

◆ EINFO_EIO_ISOCH

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

Definition at line 205 of file xhci.c.

◆ EPROTO_LOST

#define EPROTO_LOST   __einfo_error ( EINFO_EPROTO_LOST )

Definition at line 208 of file xhci.c.

◆ EINFO_EPROTO_LOST

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

Definition at line 210 of file xhci.c.

◆ EPROTO_UNDEFINED

#define EPROTO_UNDEFINED   __einfo_error ( EINFO_EPROTO_UNDEFINED )

Definition at line 213 of file xhci.c.

◆ EINFO_EPROTO_UNDEFINED

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

Definition at line 215 of file xhci.c.

◆ EPROTO_STREAM_ID

#define EPROTO_STREAM_ID   __einfo_error ( EINFO_EPROTO_STREAM_ID )

Definition at line 218 of file xhci.c.

◆ EINFO_EPROTO_STREAM_ID

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

Definition at line 220 of file xhci.c.

◆ EPROTO_SECONDARY

#define EPROTO_SECONDARY   __einfo_error ( EINFO_EPROTO_SECONDARY )

Definition at line 223 of file xhci.c.

◆ EINFO_EPROTO_SECONDARY

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

Definition at line 225 of file xhci.c.

◆ EPROTO_SPLIT

#define EPROTO_SPLIT   __einfo_error ( EINFO_EPROTO_SPLIT )

Definition at line 228 of file xhci.c.

◆ EINFO_EPROTO_SPLIT

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

Definition at line 230 of file xhci.c.

◆ ECODE

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

Definition at line 233 of file xhci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ xhci_init()

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

Initialise device.

Parameters
xhcixHCI device
regsMMIO registers

Definition at line 264 of file xhci.c.

264  {
265  uint32_t hcsparams1;
266  uint32_t hcsparams2;
267  uint32_t hccparams1;
268  uint32_t pagesize;
269  size_t caplength;
270  size_t rtsoff;
271  size_t dboff;
272 
273  /* Locate capability, operational, runtime, and doorbell registers */
274  xhci->cap = regs;
275  caplength = readb ( xhci->cap + XHCI_CAP_CAPLENGTH );
276  rtsoff = readl ( xhci->cap + XHCI_CAP_RTSOFF );
277  dboff = readl ( xhci->cap + XHCI_CAP_DBOFF );
278  xhci->op = ( xhci->cap + caplength );
279  xhci->run = ( xhci->cap + rtsoff );
280  xhci->db = ( xhci->cap + dboff );
281  DBGC2 ( xhci, "XHCI %s cap %08lx op %08lx run %08lx db %08lx\n",
282  xhci->name, virt_to_phys ( xhci->cap ),
283  virt_to_phys ( xhci->op ), virt_to_phys ( xhci->run ),
284  virt_to_phys ( xhci->db ) );
285 
286  /* Read structural parameters 1 */
287  hcsparams1 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS1 );
288  xhci->slots = XHCI_HCSPARAMS1_SLOTS ( hcsparams1 );
289  xhci->intrs = XHCI_HCSPARAMS1_INTRS ( hcsparams1 );
290  xhci->ports = XHCI_HCSPARAMS1_PORTS ( hcsparams1 );
291  DBGC ( xhci, "XHCI %s has %d slots %d intrs %d ports\n",
292  xhci->name, xhci->slots, xhci->intrs, xhci->ports );
293 
294  /* Read structural parameters 2 */
295  hcsparams2 = readl ( xhci->cap + XHCI_CAP_HCSPARAMS2 );
296  xhci->scratch.count = XHCI_HCSPARAMS2_SCRATCHPADS ( hcsparams2 );
297  DBGC2 ( xhci, "XHCI %s needs %d scratchpads\n",
298  xhci->name, xhci->scratch.count );
299 
300  /* Read capability parameters 1 */
301  hccparams1 = readl ( xhci->cap + XHCI_CAP_HCCPARAMS1 );
302  xhci->addr64 = XHCI_HCCPARAMS1_ADDR64 ( hccparams1 );
303  xhci->csz_shift = XHCI_HCCPARAMS1_CSZ_SHIFT ( hccparams1 );
304  xhci->xecp = XHCI_HCCPARAMS1_XECP ( hccparams1 );
305 
306  /* Read page size */
307  pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
308  xhci->pagesize = XHCI_PAGESIZE ( pagesize );
309  assert ( xhci->pagesize != 0 );
310  assert ( ( ( xhci->pagesize ) & ( xhci->pagesize - 1 ) ) == 0 );
311  DBGC2 ( xhci, "XHCI %s page size %zd bytes\n",
312  xhci->name, xhci->pagesize );
313 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
unsigned int ports
Number of ports.
Definition: xhci.h:1091
void * run
Runtime registers.
Definition: xhci.h:1082
#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
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1055
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:1087
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1110
#define XHCI_CAP_RTSOFF
Runtime register space offset.
Definition: xhci.h:74
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const char * name
Name.
Definition: xhci.h:1073
#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:1089
#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:1078
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1098
#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:1094
#define XHCI_PAGESIZE(pagesize)
Page size.
Definition: xhci.h:173
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1101
#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:1096
void * db
Doorbell registers.
Definition: xhci.h:1084
#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:1080

References xhci_device::addr64, assert(), xhci_device::cap, xhci_scratchpad::count, 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::scratch, 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 323 of file xhci.c.

325  {
326  uint32_t xecp;
327  unsigned int next;
328 
329  /* Locate the extended capability */
330  while ( 1 ) {
331 
332  /* Locate first or next capability as applicable */
333  if ( offset ) {
334  xecp = readl ( xhci->cap + offset );
335  next = XHCI_XECP_NEXT ( xecp );
336  } else {
337  next = xhci->xecp;
338  }
339  if ( ! next )
340  return 0;
341  offset += next;
342 
343  /* Check if this is the requested capability */
344  xecp = readl ( xhci->cap + offset );
345  if ( XHCI_XECP_ID ( xecp ) == id )
346  return offset;
347  }
348 }
#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:1078
unsigned int xecp
xHCI extended capabilities offset
Definition: xhci.h:1098

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

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

393  {
394  size_t align;
395 
396  /* Align to own length (rounded up to a power of two) */
397  align = ( 1 << fls ( len - 1 ) );
398 
399  /* Round up to XHCI_MIN_ALIGN if needed */
400  if ( align < XHCI_MIN_ALIGN )
402 
403  return align;
404 }
static __always_inline void struct dma_mapping size_t size_t align
Definition: dma.h:222
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 align, 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 412 of file xhci.c.

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

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

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

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

442  {
443  uint32_t usbcmd;
444  uint32_t usbsts;
445  uint32_t pagesize;
446  uint32_t dnctrl;
447  uint32_t config;
448 
449  /* Do nothing unless debugging is enabled */
450  if ( ! DBG_LOG )
451  return;
452 
453  /* Dump USBCMD */
454  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
455  DBGC ( xhci, "XHCI %s USBCMD %08x%s%s\n", xhci->name, usbcmd,
456  ( ( usbcmd & XHCI_USBCMD_RUN ) ? " run" : "" ),
457  ( ( usbcmd & XHCI_USBCMD_HCRST ) ? " hcrst" : "" ) );
458 
459  /* Dump USBSTS */
460  usbsts = readl ( xhci->op + XHCI_OP_USBSTS );
461  DBGC ( xhci, "XHCI %s USBSTS %08x%s\n", xhci->name, usbsts,
462  ( ( usbsts & XHCI_USBSTS_HCH ) ? " hch" : "" ) );
463 
464  /* Dump PAGESIZE */
465  pagesize = readl ( xhci->op + XHCI_OP_PAGESIZE );
466  DBGC ( xhci, "XHCI %s PAGESIZE %08x\n", xhci->name, pagesize );
467 
468  /* Dump DNCTRL */
469  dnctrl = readl ( xhci->op + XHCI_OP_DNCTRL );
470  DBGC ( xhci, "XHCI %s DNCTRL %08x\n", xhci->name, dnctrl );
471 
472  /* Dump CONFIG */
473  config = readl ( xhci->op + XHCI_OP_CONFIG );
474  DBGC ( xhci, "XHCI %s CONFIG %08x\n", xhci->name, config );
475 }
#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:1073
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:1080

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

484  {
485  uint32_t portsc;
486  uint32_t portpmsc;
487  uint32_t portli;
488  uint32_t porthlpmc;
489 
490  /* Do nothing unless debugging is enabled */
491  if ( ! DBG_LOG )
492  return;
493 
494  /* Dump PORTSC */
495  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( port ) );
496  DBGC ( xhci, "XHCI %s-%d PORTSC %08x%s%s%s%s psiv=%d\n",
497  xhci->name, port, portsc,
498  ( ( portsc & XHCI_PORTSC_CCS ) ? " ccs" : "" ),
499  ( ( portsc & XHCI_PORTSC_PED ) ? " ped" : "" ),
500  ( ( portsc & XHCI_PORTSC_PR ) ? " pr" : "" ),
501  ( ( portsc & XHCI_PORTSC_PP ) ? " pp" : "" ),
502  XHCI_PORTSC_PSIV ( portsc ) );
503 
504  /* Dump PORTPMSC */
505  portpmsc = readl ( xhci->op + XHCI_OP_PORTPMSC ( port ) );
506  DBGC ( xhci, "XHCI %s-%d PORTPMSC %08x\n", xhci->name, port, portpmsc );
507 
508  /* Dump PORTLI */
509  portli = readl ( xhci->op + XHCI_OP_PORTLI ( port ) );
510  DBGC ( xhci, "XHCI %s-%d PORTLI %08x\n", xhci->name, port, portli );
511 
512  /* Dump PORTHLPMC */
513  porthlpmc = readl ( xhci->op + XHCI_OP_PORTHLPMC ( port ) );
514  DBGC ( xhci, "XHCI %s-%d PORTHLPMC %08x\n",
515  xhci->name, port, porthlpmc );
516 }
#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:1073
#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:1080

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

533  {
534  unsigned int legacy;
535  uint8_t bios;
536 
537  /* Locate USB legacy support capability (if present) */
538  legacy = xhci_extended_capability ( xhci, XHCI_XECP_ID_LEGACY, 0 );
539  if ( ! legacy ) {
540  /* Not an error; capability may not be present */
541  DBGC ( xhci, "XHCI %s has no USB legacy support capability\n",
542  xhci->name );
543  return;
544  }
545 
546  /* Check if legacy USB support is enabled */
547  bios = readb ( xhci->cap + legacy + XHCI_USBLEGSUP_BIOS );
548  if ( ! ( bios & XHCI_USBLEGSUP_BIOS_OWNED ) ) {
549  /* Not an error; already owned by OS */
550  DBGC ( xhci, "XHCI %s USB legacy support already disabled\n",
551  xhci->name );
552  return;
553  }
554 
555  /* Record presence of USB legacy support capability */
556  xhci->legacy = legacy;
557 }
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:323
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: xhci.h:1073
#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:1078
#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:1104

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

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

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

611  {
612 
613  /* Do nothing unless legacy support capability is present */
614  if ( ! xhci->legacy )
615  return;
616 
617  /* Do nothing if releasing ownership is prevented */
619  DBGC ( xhci, "XHCI %s not releasing ownership to BIOS\n",
620  xhci->name );
621  return;
622  }
623 
624  /* Release ownership */
625  writeb ( 0, xhci->cap + xhci->legacy + XHCI_USBLEGSUP_OS );
626  DBGC ( xhci, "XHCI %s released ownership to BIOS\n", xhci->name );
627 }
#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:1073
void * cap
Capability registers.
Definition: xhci.h:1078
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: xhci.h:1104
static int xhci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
Definition: xhci.c:526

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

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

666  {
667  unsigned int supported = 0;
668  unsigned int offset;
669  unsigned int count;
670  uint32_t ports;
671 
672  /* Iterate over all supported protocol structures */
673  while ( ( supported = xhci_extended_capability ( xhci,
675  supported ) ) ) {
676 
677  /* Determine port range */
678  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
680  count = XHCI_SUPPORTED_PORTS_COUNT ( ports );
681 
682  /* Check if port lies within this range */
683  if ( ( port - offset ) < count )
684  return supported;
685  }
686 
687  DBGC ( xhci, "XHCI %s-%d has no supported protocol\n",
688  xhci->name, port );
689  return 0;
690 }
#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:323
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:1073
#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:1078
#define XHCI_SUPPORTED_PORTS_OFFSET(ports)
Supported protocol port offset.
Definition: xhci.h:116
uint16_t count
Number of entries.
Definition: ena.h:22
uint32_t supported
Bitmask of supported AENQ groups (device -> host)
Definition: ena.h:12

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

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

◆ xhci_port_protocol()

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

Find port protocol.

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

Definition at line 699 of file xhci.c.

700  {
701  unsigned int supported = xhci_supported_protocol ( xhci, port );
702  union {
703  uint32_t raw;
704  char text[5];
705  } name;
706  unsigned int protocol;
707  unsigned int type;
708  unsigned int psic;
709  unsigned int psiv;
710  unsigned int i;
712  uint32_t ports;
713  uint32_t slot;
714  uint32_t psi;
715 
716  /* Fail if there is no supported protocol */
717  if ( ! supported )
718  return 0;
719 
720  /* Determine protocol version */
723 
724  /* Describe port protocol */
725  if ( DBG_EXTRA ) {
726  name.raw = cpu_to_le32 ( readl ( xhci->cap + supported +
728  name.text[4] = '\0';
729  slot = readl ( xhci->cap + supported + XHCI_SUPPORTED_SLOT );
731  DBGC2 ( xhci, "XHCI %s-%d %sv%04x type %d",
732  xhci->name, port, name.text, protocol, type );
733  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
734  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
735  if ( psic ) {
736  DBGC2 ( xhci, " speeds" );
737  for ( i = 0 ; i < psic ; i++ ) {
738  psi = readl ( xhci->cap + supported +
739  XHCI_SUPPORTED_PSI ( i ) );
740  psiv = XHCI_SUPPORTED_PSI_VALUE ( psi );
741  DBGC2 ( xhci, " %d:%s", psiv,
742  xhci_speed_name ( psi ) );
743  }
744  }
745  if ( xhci->quirks & XHCI_BAD_PSIV )
746  DBGC2 ( xhci, " (ignored)" );
747  DBGC2 ( xhci, "\n" );
748  }
749 
750  return protocol;
751 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1042
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition: xhci.h:128
const char * name
Definition: ath9k_hw.c:1984
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition: xhci.h:125
#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:642
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
Entry point 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:1073
uint8_t slot
Slot.
Definition: edd.h:16
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1078
#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:665
uint32_t type
Operating system type.
Definition: ena.h:12
#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
uint32_t supported
Bitmask of supported AENQ groups (device -> host)
Definition: ena.h:12
unsigned int quirks
Quirks.
Definition: xhci.h:1075
#define XHCI_SUPPORTED_NAME
Supported protocol name.
Definition: xhci.h:110

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

Referenced by xhci_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 760 of file xhci.c.

760  {
761  unsigned int supported = xhci_supported_protocol ( xhci, port );
762  unsigned int type;
763  uint32_t slot;
764 
765  /* Fail if there is no supported protocol */
766  if ( ! supported )
767  return -ENOTSUP;
768 
769  /* Get slot type */
770  slot = readl ( xhci->cap + supported + XHCI_SUPPORTED_SLOT );
772 
773  return type;
774 }
#define XHCI_SUPPORTED_SLOT_TYPE(slot)
Supported protocol slot type.
Definition: xhci.h:128
#define XHCI_SUPPORTED_SLOT
Supported protocol slot.
Definition: xhci.h:125
uint32_t 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:1078
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:665
uint32_t type
Operating system type.
Definition: ena.h:12
uint32_t supported
Bitmask of supported AENQ groups (device -> host)
Definition: ena.h:12

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

Referenced by xhci_device_open().

◆ xhci_port_speed()

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

Find port speed.

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

Definition at line 784 of file xhci.c.

785  {
786  unsigned int supported = xhci_supported_protocol ( xhci, port );
787  unsigned int psic;
788  unsigned int mantissa;
789  unsigned int exponent;
790  unsigned int speed;
791  unsigned int i;
792  uint32_t ports;
793  uint32_t psi;
794 
795  /* Fail if there is no supported protocol */
796  if ( ! supported )
797  return -ENOTSUP;
798 
799  /* Get protocol speed ID count */
800  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
801  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
802 
803  /* Use protocol speed ID table unless device is known to be faulty */
804  if ( ! ( xhci->quirks & XHCI_BAD_PSIV ) ) {
805 
806  /* Iterate over PSI dwords looking for a match */
807  for ( i = 0 ; i < psic ; i++ ) {
808  psi = readl ( xhci->cap + supported +
809  XHCI_SUPPORTED_PSI ( i ) );
810  if ( psiv == XHCI_SUPPORTED_PSI_VALUE ( psi ) ) {
811  mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
812  exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
813  speed = USB_SPEED ( mantissa, exponent );
814  return speed;
815  }
816  }
817 
818  /* Record device as faulty if no match is found */
819  if ( psic != 0 ) {
820  DBGC ( xhci, "XHCI %s-%d spurious PSI value %d: "
821  "assuming PSI table is invalid\n",
822  xhci->name, port, psiv );
823  xhci->quirks |= XHCI_BAD_PSIV;
824  }
825  }
826 
827  /* Use the default mappings */
828  switch ( psiv ) {
829  case XHCI_SPEED_LOW : return USB_SPEED_LOW;
830  case XHCI_SPEED_FULL : return USB_SPEED_FULL;
831  case XHCI_SPEED_HIGH : return USB_SPEED_HIGH;
832  case XHCI_SPEED_SUPER : return USB_SPEED_SUPER;
833  default:
834  DBGC ( xhci, "XHCI %s-%d unrecognised PSI value %d\n",
835  xhci->name, port, psiv );
836  return -ENOTSUP;
837  }
838 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1042
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
Low speed (1.5Mbps)
Definition: usb.h: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:1073
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1078
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:665
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
uint32_t supported
Bitmask of supported AENQ groups (device -> host)
Definition: ena.h:12
High speed (480Mbps)
Definition: xhci.h:149
unsigned int quirks
Quirks.
Definition: xhci.h:1075
#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(), supported, USB_SPEED, USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_LOW, USB_SPEED_SUPER, XHCI_BAD_PSIV, XHCI_SPEED_FULL, XHCI_SPEED_HIGH, XHCI_SPEED_LOW, XHCI_SPEED_SUPER, XHCI_SUPPORTED_PORTS, XHCI_SUPPORTED_PORTS_PSIC, xhci_supported_protocol(), XHCI_SUPPORTED_PSI, XHCI_SUPPORTED_PSI_EXPONENT, XHCI_SUPPORTED_PSI_MANTISSA, and XHCI_SUPPORTED_PSI_VALUE.

Referenced by xhci_root_speed().

◆ xhci_port_psiv()

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

Find protocol speed ID value.

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

Definition at line 848 of file xhci.c.

849  {
850  unsigned int supported = xhci_supported_protocol ( xhci, port );
851  unsigned int psic;
852  unsigned int mantissa;
853  unsigned int exponent;
854  unsigned int psiv;
855  unsigned int i;
856  uint32_t ports;
857  uint32_t psi;
858 
859  /* Fail if there is no supported protocol */
860  if ( ! supported )
861  return -ENOTSUP;
862 
863  /* Get protocol speed ID count */
864  ports = readl ( xhci->cap + supported + XHCI_SUPPORTED_PORTS );
865  psic = XHCI_SUPPORTED_PORTS_PSIC ( ports );
866 
867  /* Use the default mappings if applicable */
868  if ( ( psic == 0 ) || ( xhci->quirks & XHCI_BAD_PSIV ) ) {
869  switch ( speed ) {
870  case USB_SPEED_LOW : return XHCI_SPEED_LOW;
871  case USB_SPEED_FULL : return XHCI_SPEED_FULL;
872  case USB_SPEED_HIGH : return XHCI_SPEED_HIGH;
873  case USB_SPEED_SUPER : return XHCI_SPEED_SUPER;
874  default:
875  DBGC ( xhci, "XHCI %s-%d non-standard speed %d\n",
876  xhci->name, port, speed );
877  return -ENOTSUP;
878  }
879  }
880 
881  /* Iterate over PSI dwords looking for a match */
882  for ( i = 0 ; i < psic ; i++ ) {
883  psi = readl ( xhci->cap + supported + XHCI_SUPPORTED_PSI ( i ));
884  mantissa = XHCI_SUPPORTED_PSI_MANTISSA ( psi );
885  exponent = XHCI_SUPPORTED_PSI_EXPONENT ( psi );
886  if ( speed == USB_SPEED ( mantissa, exponent ) ) {
887  psiv = XHCI_SUPPORTED_PSI_VALUE ( psi );
888  return psiv;
889  }
890  }
891 
892  DBGC ( xhci, "XHCI %s-%d unrepresentable speed %#x\n",
893  xhci->name, port, speed );
894  return -ENOENT;
895 }
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1042
#define XHCI_SUPPORTED_PORTS
Supported protocol ports.
Definition: xhci.h:113
Low speed (1.5Mbps)
Definition: usb.h: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:1073
unsigned int uint32_t
Definition: stdint.h:12
void * cap
Capability registers.
Definition: xhci.h:1078
static unsigned int xhci_supported_protocol(struct xhci_device *xhci, unsigned int port)
Find supported protocol extended capability for a port.
Definition: xhci.c:665
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
uint32_t supported
Bitmask of supported AENQ groups (device -> host)
Definition: ena.h:12
High speed (480Mbps)
Definition: xhci.h:149
unsigned int quirks
Quirks.
Definition: xhci.h:1075
#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(), supported, USB_SPEED, USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_LOW, USB_SPEED_SUPER, XHCI_BAD_PSIV, XHCI_SPEED_FULL, XHCI_SPEED_HIGH, XHCI_SPEED_LOW, XHCI_SPEED_SUPER, XHCI_SUPPORTED_PORTS, XHCI_SUPPORTED_PORTS_PSIC, xhci_supported_protocol(), XHCI_SUPPORTED_PSI, XHCI_SUPPORTED_PSI_EXPONENT, XHCI_SUPPORTED_PSI_MANTISSA, and XHCI_SUPPORTED_PSI_VALUE.

Referenced by xhci_device_address().

◆ xhci_dcbaa_alloc()

static int xhci_dcbaa_alloc ( struct xhci_device xhci)
static

Allocate device context base address array.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 910 of file xhci.c.

910  {
911  size_t len;
912  physaddr_t dcbaap;
913  int rc;
914 
915  /* Allocate and initialise structure. Must be at least
916  * 64-byte aligned and must not cross a page boundary, so
917  * align on its own size (rounded up to a power of two and
918  * with a minimum of 64 bytes).
919  */
920  len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
921  xhci->dcbaa.context = dma_alloc ( xhci->dma, &xhci->dcbaa.map, len,
922  xhci_align ( len ) );
923  if ( ! xhci->dcbaa.context ) {
924  DBGC ( xhci, "XHCI %s could not allocate DCBAA\n", xhci->name );
925  rc = -ENOMEM;
926  goto err_alloc;
927  }
928  memset ( xhci->dcbaa.context, 0, len );
929 
930  /* Program DCBAA pointer */
931  dcbaap = dma ( &xhci->dcbaa.map, xhci->dcbaa.context );
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", xhci->name,
937  virt_to_phys ( xhci->dcbaa.context ),
938  ( virt_to_phys ( xhci->dcbaa.context ) + len ) );
939  return 0;
940 
941  err_writeq:
942  dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
943  err_alloc:
944  return rc;
945 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1107
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:393
#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:1087
#define ENOMEM
Not enough space.
Definition: errno.h:534
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
#define XHCI_OP_DCBAAP
Device context base address array pointer.
Definition: xhci.h:191
const char * name
Name.
Definition: xhci.h:1073
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:359
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
unsigned long physaddr_t
Definition: stdint.h:20
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct dma_mapping map
DMA mapping.
Definition: xhci.h:1049
struct dma_device * dma
DMA device.
Definition: xhci.h:1071
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
void * op
Operational registers.
Definition: xhci.h:1080
void * memset(void *dest, int character, size_t len) __nonnull

References xhci_dcbaa::context, DBGC, DBGC2, xhci_device::dcbaa, dma(), xhci_device::dma, dma_alloc(), dma_free(), ENOMEM, len, xhci_dcbaa::map, memset(), xhci_device::name, xhci_device::op, rc, xhci_device::slots, 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 952 of file xhci.c.

952  {
953  size_t len;
954  unsigned int i;
955 
956  /* Sanity check */
957  for ( i = 0 ; i <= xhci->slots ; i++ )
958  assert ( xhci->dcbaa.context[i] == 0 );
959 
960  /* Clear DCBAA pointer */
961  xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_DCBAAP );
962 
963  /* Free DCBAA */
964  len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
965  dma_free ( &xhci->dcbaa.map, xhci->dcbaa.context, len );
966 }
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1107
unsigned int slots
Number of device slots.
Definition: xhci.h:1087
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define XHCI_OP_DCBAAP
Device context base address array pointer.
Definition: xhci.h:191
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:359
uint32_t len
Length.
Definition: ena.h:14
struct dma_mapping map
DMA mapping.
Definition: xhci.h:1049
void * op
Operational registers.
Definition: xhci.h:1080

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

Referenced by xhci_bus_close(), and xhci_bus_open().

◆ xhci_scratchpad_alloc()

static int xhci_scratchpad_alloc ( struct xhci_device xhci)
static

Allocate scratchpad buffers.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 981 of file xhci.c.

981  {
982  struct xhci_scratchpad *scratch = &xhci->scratch;
983  size_t buffer_len;
984  size_t array_len;
986  unsigned int i;
987  int rc;
988 
989  /* Do nothing if no scratchpad buffers are used */
990  if ( ! scratch->count )
991  return 0;
992 
993  /* Allocate scratchpad buffers */
994  buffer_len = ( scratch->count * xhci->pagesize );
995  scratch->buffer = dma_umalloc ( xhci->dma, &scratch->buffer_map,
996  buffer_len, xhci->pagesize );
997  if ( ! scratch->buffer ) {
998  DBGC ( xhci, "XHCI %s could not allocate scratchpad buffers\n",
999  xhci->name );
1000  rc = -ENOMEM;
1001  goto err_alloc;
1002  }
1003  memset_user ( scratch->buffer, 0, 0, buffer_len );
1004 
1005  /* Allocate scratchpad array */
1006  array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
1007  scratch->array = dma_alloc ( xhci->dma, &scratch->array_map,
1008  array_len, xhci_align ( array_len ) );
1009  if ( ! scratch->array ) {
1010  DBGC ( xhci, "XHCI %s could not allocate scratchpad buffer "
1011  "array\n", xhci->name );
1012  rc = -ENOMEM;
1013  goto err_alloc_array;
1014  }
1015 
1016  /* Populate scratchpad array */
1017  addr = dma_phys ( &scratch->buffer_map,
1018  user_to_phys ( scratch->buffer, 0 ) );
1019  for ( i = 0 ; i < scratch->count ; i++ ) {
1020  scratch->array[i] = cpu_to_le64 ( addr );
1021  addr += xhci->pagesize;
1022  }
1023 
1024  /* Set scratchpad array pointer */
1025  assert ( xhci->dcbaa.context != NULL );
1026  xhci->dcbaa.context[0] = cpu_to_le64 ( dma ( &scratch->array_map,
1027  scratch->array ) );
1028 
1029  DBGC2 ( xhci, "XHCI %s scratchpad [%08lx,%08lx) array [%08lx,%08lx)\n",
1030  xhci->name, user_to_phys ( scratch->buffer, 0 ),
1031  user_to_phys ( scratch->buffer, buffer_len ),
1032  virt_to_phys ( scratch->array ),
1033  ( virt_to_phys ( scratch->array ) + array_len ) );
1034  return 0;
1035 
1036  dma_free ( &scratch->array_map, scratch->array, array_len );
1037  err_alloc_array:
1038  dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
1039  err_alloc:
1040  return rc;
1041 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1107
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:393
physaddr_t dma_phys(struct dma_mapping *map, physaddr_t addr)
Get DMA address from physical address.
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
#define DBGC(...)
Definition: compiler.h:505
struct dma_mapping buffer_map
Buffer DMA mapping.
Definition: xhci.h:1059
#define cpu_to_le64(value)
Definition: byteswap.h:108
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1055
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1110
uint64_t * array
Scratchpad array.
Definition: xhci.h:1061
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
struct dma_mapping array_map
Array DMA mapping.
Definition: xhci.h:1063
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const char * name
Name.
Definition: xhci.h:1073
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
u32 addr
Definition: sky2.h:8
Scratchpad buffer.
Definition: xhci.h:1053
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
userptr_t buffer
Scratchpad buffer area.
Definition: xhci.h:1057
unsigned long physaddr_t
Definition: stdint.h:20
void dma_ufree(struct dma_mapping *map, userptr_t addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
#define DBGC2(...)
Definition: compiler.h:522
size_t pagesize
Page size.
Definition: xhci.h:1101
struct dma_device * dma
DMA device.
Definition: xhci.h:1071
userptr_t dma_umalloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer from external (user) memory.
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References addr, xhci_scratchpad::array, xhci_scratchpad::array_map, assert(), xhci_scratchpad::buffer, xhci_scratchpad::buffer_map, xhci_dcbaa::context, xhci_scratchpad::count, cpu_to_le64, DBGC, DBGC2, xhci_device::dcbaa, dma(), xhci_device::dma, dma_alloc(), dma_free(), dma_phys(), dma_ufree(), dma_umalloc(), ENOMEM, memset_user(), xhci_device::name, NULL, xhci_device::pagesize, rc, xhci_device::scratch, 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 1048 of file xhci.c.

1048  {
1049  struct xhci_scratchpad *scratch = &xhci->scratch;
1050  size_t array_len;
1051  size_t buffer_len;
1052 
1053  /* Do nothing if no scratchpad buffers are used */
1054  if ( ! scratch->count )
1055  return;
1056 
1057  /* Clear scratchpad array pointer */
1058  assert ( xhci->dcbaa.context != NULL );
1059  xhci->dcbaa.context[0] = 0;
1060 
1061  /* Free scratchpad array */
1062  array_len = ( scratch->count * sizeof ( scratch->array[0] ) );
1063  dma_free ( &scratch->array_map, scratch->array, array_len );
1064 
1065  /* Free scratchpad buffers */
1066  buffer_len = ( scratch->count * xhci->pagesize );
1067  dma_ufree ( &scratch->buffer_map, scratch->buffer, buffer_len );
1068 }
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1107
struct dma_mapping buffer_map
Buffer DMA mapping.
Definition: xhci.h:1059
unsigned int count
Number of page-sized scratchpad buffers.
Definition: xhci.h:1055
struct xhci_scratchpad scratch
Scratchpad buffer.
Definition: xhci.h:1110
uint64_t * array
Scratchpad array.
Definition: xhci.h:1061
struct dma_mapping array_map
Array DMA mapping.
Definition: xhci.h:1063
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
Scratchpad buffer.
Definition: xhci.h:1053
userptr_t buffer
Scratchpad buffer area.
Definition: xhci.h:1057
void dma_ufree(struct dma_mapping *map, userptr_t addr, size_t len)
Unmap and free DMA-coherent buffer from external (user) memory.
size_t pagesize
Page size.
Definition: xhci.h:1101
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by xhci_bus_close(), and xhci_bus_open().

◆ xhci_run()

static void xhci_run ( struct xhci_device xhci)
static

Start xHCI device.

Parameters
xhcixHCI device

Definition at line 1082 of file xhci.c.

1082  {
1083  uint32_t config;
1084  uint32_t usbcmd;
1085 
1086  /* Configure number of device slots */
1087  config = readl ( xhci->op + XHCI_OP_CONFIG );
1088  config &= ~XHCI_CONFIG_MAX_SLOTS_EN_MASK;
1089  config |= XHCI_CONFIG_MAX_SLOTS_EN ( xhci->slots );
1090  writel ( config, xhci->op + XHCI_OP_CONFIG );
1091 
1092  /* Set run/stop bit */
1093  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1094  usbcmd |= XHCI_USBCMD_RUN;
1095  writel ( usbcmd, xhci->op + XHCI_OP_USBCMD );
1096 }
#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:1087
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:1080

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

1104  {
1105  uint32_t usbcmd;
1106  uint32_t usbsts;
1107  unsigned int i;
1108 
1109  /* Clear run/stop bit */
1110  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1111  usbcmd &= ~XHCI_USBCMD_RUN;
1112  writel ( usbcmd, xhci->op + XHCI_OP_USBCMD );
1113 
1114  /* Wait for device to stop */
1115  for ( i = 0 ; i < XHCI_STOP_MAX_WAIT_MS ; i++ ) {
1116 
1117  /* Check if device is stopped */
1118  usbsts = readl ( xhci->op + XHCI_OP_USBSTS );
1119  if ( usbsts & XHCI_USBSTS_HCH )
1120  return 0;
1121 
1122  /* Delay */
1123  mdelay ( 1 );
1124  }
1125 
1126  DBGC ( xhci, "XHCI %s timed out waiting for stop\n", xhci->name );
1127  return -ETIMEDOUT;
1128 }
#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:1073
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:990
#define XHCI_USBCMD_RUN
Run/stop.
Definition: xhci.h:158
#define XHCI_OP_USBCMD
USB command register.
Definition: xhci.h:155
#define XHCI_USBSTS_HCH
Host controller halted.
Definition: xhci.h:167
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * op
Operational registers.
Definition: xhci.h:1080

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

1136  {
1137  uint32_t usbcmd;
1138  unsigned int i;
1139  int rc;
1140 
1141  /* The xHCI specification states that resetting a running
1142  * device may result in undefined behaviour, so try stopping
1143  * it first.
1144  */
1145  if ( ( rc = xhci_stop ( xhci ) ) != 0 ) {
1146  /* Ignore errors and attempt to reset the device anyway */
1147  }
1148 
1149  /* Reset device */
1151 
1152  /* Wait for reset to complete */
1153  for ( i = 0 ; i < XHCI_RESET_MAX_WAIT_MS ; i++ ) {
1154 
1155  /* Check if reset is complete */
1156  usbcmd = readl ( xhci->op + XHCI_OP_USBCMD );
1157  if ( ! ( usbcmd & XHCI_USBCMD_HCRST ) )
1158  return 0;
1159 
1160  /* Delay */
1161  mdelay ( 1 );
1162  }
1163 
1164  DBGC ( xhci, "XHCI %s timed out waiting for reset\n", xhci->name );
1165  return -ETIMEDOUT;
1166 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition: xhci.c:1104
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define XHCI_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
Definition: xhci.h:996
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: xhci.h:1073
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:1080

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

Referenced by xhci_fail(), xhci_probe(), and xhci_remove().

◆ xhci_fail()

static int xhci_fail ( struct xhci_device xhci)
static

Mark xHCI device as permanently failed.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1174 of file xhci.c.

1174  {
1175  size_t len;
1176  int rc;
1177 
1178  /* Mark command mechanism as permanently failed */
1179  xhci->failed = 1;
1180 
1181  /* Reset device */
1182  if ( ( rc = xhci_reset ( xhci ) ) != 0 )
1183  return rc;
1184 
1185  /* Discard DCBAA entries since DCBAAP has been cleared */
1186  assert ( xhci->dcbaa.context != NULL );
1187  len = ( ( xhci->slots + 1 ) * sizeof ( xhci->dcbaa.context[0] ) );
1188  memset ( xhci->dcbaa.context, 0, len );
1189 
1190  return 0;
1191 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1107
unsigned int slots
Number of device slots.
Definition: xhci.h:1087
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int failed
Command mechanism has permanently failed.
Definition: xhci.h:1119
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1136
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void * memset(void *dest, int character, size_t len) __nonnull

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

Referenced by xhci_abort(), and xhci_remove().

◆ xhci_ring_alloc()

static int xhci_ring_alloc ( struct xhci_device xhci,
struct xhci_trb_ring ring,
unsigned int  shift,
unsigned int  slot,
unsigned int  target,
unsigned int  stream 
)
static

Allocate transfer request block ring.

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

Definition at line 1211 of file xhci.c.

1214  {
1215  struct xhci_trb_link *link;
1216  unsigned int count;
1217  int rc;
1218 
1219  /* Sanity check */
1220  assert ( shift > 0 );
1221 
1222  /* Initialise structure */
1223  memset ( ring, 0, sizeof ( *ring ) );
1224  ring->shift = shift;
1225  count = ( 1U << shift );
1226  ring->mask = ( count - 1 );
1227  ring->len = ( ( count + 1 /* Link TRB */ ) * sizeof ( ring->trb[0] ) );
1228  ring->db = ( xhci->db + ( slot * sizeof ( ring->dbval ) ) );
1229  ring->dbval = XHCI_DBVAL ( target, stream );
1230 
1231  /* Allocate I/O buffers */
1232  ring->iobuf = zalloc ( count * sizeof ( ring->iobuf[0] ) );
1233  if ( ! ring->iobuf ) {
1234  rc = -ENOMEM;
1235  goto err_alloc_iobuf;
1236  }
1237 
1238  /* Allocate TRBs */
1239  ring->trb = dma_alloc ( xhci->dma, &ring->map, ring->len,
1240  xhci_align ( ring->len ) );
1241  if ( ! ring->trb ) {
1242  rc = -ENOMEM;
1243  goto err_alloc_trb;
1244  }
1245  memset ( ring->trb, 0, ring->len );
1246 
1247  /* Initialise Link TRB */
1248  link = &ring->trb[count].link;
1249  link->next = cpu_to_le64 ( dma ( &ring->map, ring->trb ) );
1250  link->flags = XHCI_TRB_TC;
1251  link->type = XHCI_TRB_LINK;
1252  ring->link = link;
1253 
1254  return 0;
1255 
1256  dma_free ( &ring->map, ring->trb, ring->len );
1257  err_alloc_trb:
1258  free ( ring->iobuf );
1259  err_alloc_iobuf:
1260  return rc;
1261 }
#define XHCI_TRB_TC
Transfer request block toggle cycle bit flag.
Definition: xhci.h:332
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t dbval
Doorbell register value.
Definition: xhci.h:865
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:393
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
#define cpu_to_le64(value)
Definition: byteswap.h:108
void * db
Doorbell register.
Definition: xhci.h:863
#define ENOMEM
Not enough space.
Definition: errno.h:534
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
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
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
#define XHCI_DBVAL(target, stream)
Calculate doorbell register value.
Definition: xhci.h:889
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct io_buffer ** iobuf
I/O buffers.
Definition: xhci.h:851
uint16_t count
Number of entries.
Definition: ena.h:22
struct dma_device * dma
DMA device.
Definition: xhci.h:1071
struct xhci_trb_link * link
Link TRB (if applicable)
Definition: xhci.h:860
unsigned int shift
Ring size (log2)
Definition: xhci.h:846
void * db
Doorbell registers.
Definition: xhci.h:1084
#define XHCI_TRB_LINK
A link transfer request block.
Definition: xhci.h:460
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
struct xhci_trb_link link
Link TRB.
Definition: xhci.h:697
void * memset(void *dest, int character, size_t len) __nonnull

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

Referenced by xhci_command_alloc(), and xhci_endpoint_open().

◆ xhci_ring_reset()

static void xhci_ring_reset ( struct xhci_trb_ring ring)
static

Reset transfer request block ring.

Parameters
ringTRB ring

Definition at line 1268 of file xhci.c.

1268  {
1269  unsigned int count = ( 1U << ring->shift );
1270 
1271  /* Reset producer and consumer counters */
1272  ring->prod = 0;
1273  ring->cons = 0;
1274 
1275  /* Reset TRBs (except Link TRB) */
1276  memset ( ring->trb, 0, ( count * sizeof ( ring->trb[0] ) ) );
1277 }
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 1284 of file xhci.c.

1284  {
1285  unsigned int count = ( 1U << ring->shift );
1286  unsigned int i;
1287 
1288  /* Sanity checks */
1289  assert ( ring->cons == ring->prod );
1290  for ( i = 0 ; i < count ; i++ )
1291  assert ( ring->iobuf[i] == NULL );
1292 
1293  /* Free TRBs */
1294  dma_free ( &ring->map, ring->trb, ring->len );
1295 
1296  /* Free I/O buffers */
1297  free ( ring->iobuf );
1298 }
unsigned int cons
Consumer counter.
Definition: xhci.h:844
size_t len
Length of transfer request blocks.
Definition: xhci.h:856
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
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
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

◆ xhci_enqueue()

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

Enqueue a transfer request block.

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

This operation does not implicitly ring the doorbell register.

Definition at line 1310 of file xhci.c.

1311  {
1312  union xhci_trb *dest;
1313  unsigned int prod;
1314  unsigned int mask;
1315  unsigned int index;
1316  unsigned int cycle;
1317 
1318  /* Sanity check */
1319  assert ( ! ( trb->common.flags & XHCI_TRB_C ) );
1320 
1321  /* Fail if ring is full */
1322  if ( ! xhci_ring_remaining ( ring ) )
1323  return -ENOBUFS;
1324 
1325  /* Update producer counter (and link TRB, if applicable) */
1326  prod = ring->prod++;
1327  mask = ring->mask;
1328  cycle = ( ( ~( prod >> ring->shift ) ) & XHCI_TRB_C );
1329  index = ( prod & mask );
1330  if ( index == 0 )
1331  ring->link->flags = ( XHCI_TRB_TC | ( cycle ^ XHCI_TRB_C ) );
1332 
1333  /* Record I/O buffer */
1334  ring->iobuf[index] = iobuf;
1335 
1336  /* Enqueue TRB */
1337  dest = &ring->trb[index];
1338  dest->template.parameter = trb->template.parameter;
1339  dest->template.status = trb->template.status;
1340  wmb();
1341  dest->template.control = ( trb->template.control |
1342  cpu_to_le32 ( cycle ) );
1343 
1344  return 0;
1345 }
#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:913
union xhci_trb * trb
Transfer request blocks.
Definition: xhci.h:854
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct xhci_trb_template template
Template.
Definition: xhci.h:685
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:860
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 1353 of file xhci.c.

1353  {
1354  struct io_buffer *iobuf;
1355  unsigned int cons;
1356  unsigned int mask;
1357  unsigned int index;
1358 
1359  /* Sanity check */
1360  assert ( xhci_ring_fill ( ring ) != 0 );
1361 
1362  /* Update consumer counter */
1363  cons = ring->cons++;
1364  mask = ring->mask;
1365  index = ( cons & mask );
1366 
1367  /* Retrieve I/O buffer */
1368  iobuf = ring->iobuf[index];
1369  ring->iobuf[index] = NULL;
1370 
1371  return iobuf;
1372 }
unsigned int cons
Consumer counter.
Definition: xhci.h:844
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition: xhci.h:898
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:321
A persistent I/O buffer.
Definition: iobuf.h:33

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

1388  {
1389  const union xhci_trb *trb = trbs;
1390  int rc;
1391 
1392  /* Sanity check */
1393  assert ( iobuf != NULL );
1394 
1395  /* Fail if ring does not have sufficient space */
1396  if ( xhci_ring_remaining ( ring ) < count )
1397  return -ENOBUFS;
1398 
1399  /* Enqueue each TRB, recording the I/O buffer with the final TRB */
1400  while ( count-- ) {
1401  rc = xhci_enqueue ( ring, ( count ? NULL : iobuf ), trb++ );
1402  assert ( rc == 0 ); /* Should never be able to fail */
1403  }
1404 
1405  return 0;
1406 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static unsigned int xhci_ring_remaining(struct xhci_trb_ring *ring)
Calculate space remaining in TRB ring.
Definition: xhci.h:913
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
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:1310
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by xhci_endpoint_message(), and xhci_endpoint_stream().

◆ xhci_dequeue_multi()

static struct io_buffer* xhci_dequeue_multi ( struct xhci_trb_ring ring)
static

Dequeue multiple transfer request blocks.

Parameters
ringTRB ring
Return values
iobufI/O buffer

Definition at line 1414 of file xhci.c.

1414  {
1415  struct io_buffer *iobuf;
1416 
1417  /* Dequeue TRBs until we reach the final TRB for an I/O buffer */
1418  do {
1419  iobuf = xhci_dequeue ( ring );
1420  } while ( iobuf == NULL );
1421 
1422  return iobuf;
1423 }
static struct io_buffer * xhci_dequeue(struct xhci_trb_ring *ring)
Dequeue a transfer request block.
Definition: xhci.c:1353
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:33

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

1431  {
1432 
1433  wmb();
1434  writel ( ring->dbval, ring->db );
1435 }
wmb()
uint32_t dbval
Doorbell register value.
Definition: xhci.h:865
void * db
Doorbell register.
Definition: xhci.h:863
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.

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

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

◆ xhci_command_alloc()

static int xhci_command_alloc ( struct xhci_device xhci)
static

Allocate command ring.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1450 of file xhci.c.

1450  {
1451  physaddr_t crp;
1452  int rc;
1453 
1454  /* Allocate TRB ring */
1455  if ( ( rc = xhci_ring_alloc ( xhci, &xhci->command, XHCI_CMD_TRBS_LOG2,
1456  0, 0, 0 ) ) != 0 )
1457  goto err_ring_alloc;
1458 
1459  /* Program command ring control register */
1460  crp = dma ( &xhci->command.map, xhci->command.trb );
1461  if ( ( rc = xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ),
1462  xhci->op + XHCI_OP_CRCR ) ) != 0 )
1463  goto err_writeq;
1464 
1465  DBGC2 ( xhci, "XHCI %s CRCR at [%08lx,%08lx)\n", xhci->name,
1466  virt_to_phys ( xhci->command.trb ),
1467  ( virt_to_phys ( xhci->command.trb ) + xhci->command.len ) );
1468  return 0;
1469 
1470  err_writeq:
1471  xhci_ring_free ( &xhci->command );
1472  err_ring_alloc:
1473  return rc;
1474 }
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:1113
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1284
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:1073
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:359
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
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
void * op
Operational registers.
Definition: xhci.h:1080
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:1211
#define XHCI_CMD_TRBS_LOG2
Number of TRBs (excluding Link TRB) in the command ring.
Definition: xhci.h:966

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

1481  {
1482 
1483  /* Sanity check */
1484  assert ( ( readl ( xhci->op + XHCI_OP_CRCR ) & XHCI_CRCR_CRR ) == 0 );
1485 
1486  /* Clear command ring control register */
1487  xhci_writeq ( xhci, 0, xhci->op + XHCI_OP_CRCR );
1488 
1489  /* Free TRB ring */
1490  xhci_ring_free ( &xhci->command );
1491 }
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1113
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:1284
#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:359
#define XHCI_CRCR_CRR
Command ring running.
Definition: xhci.h:188
void * op
Operational registers.
Definition: xhci.h:1080

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

1499  {
1500  struct xhci_event_ring *event = &xhci->event;
1501  unsigned int count;
1502  size_t len;
1503  int rc;
1504 
1505  /* Allocate event ring */
1506  count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
1507  len = ( count * sizeof ( event->trb[0] ) );
1508  event->trb = dma_alloc ( xhci->dma, &event->trb_map, len,
1509  xhci_align ( len ) );
1510  if ( ! event->trb ) {
1511  rc = -ENOMEM;
1512  goto err_alloc_trb;
1513  }
1514  memset ( event->trb, 0, len );
1515 
1516  /* Allocate event ring segment table */
1517  event->segment = dma_alloc ( xhci->dma, &event->segment_map,
1518  sizeof ( event->segment[0] ),
1519  xhci_align ( sizeof (event->segment[0])));
1520  if ( ! event->segment ) {
1521  rc = -ENOMEM;
1522  goto err_alloc_segment;
1523  }
1524  memset ( event->segment, 0, sizeof ( event->segment[0] ) );
1525  event->segment[0].base = cpu_to_le64 ( dma ( &event->trb_map,
1526  event->trb ) );
1527  event->segment[0].count = cpu_to_le32 ( count );
1528 
1529  /* Program event ring registers */
1530  writel ( 1, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
1531  if ( ( rc = xhci_writeq ( xhci, dma ( &event->trb_map, event->trb ),
1532  xhci->run + XHCI_RUN_ERDP ( 0 ) ) ) != 0 )
1533  goto err_writeq_erdp;
1534  if ( ( rc = xhci_writeq ( xhci,
1535  dma ( &event->segment_map, event->segment ),
1536  xhci->run + XHCI_RUN_ERSTBA ( 0 ) ) ) != 0 )
1537  goto err_writeq_erstba;
1538 
1539  DBGC2 ( xhci, "XHCI %s event ring [%08lx,%08lx) table [%08lx,%08lx)\n",
1540  xhci->name, virt_to_phys ( event->trb ),
1541  ( virt_to_phys ( event->trb ) + len ),
1542  virt_to_phys ( event->segment ),
1543  ( virt_to_phys ( event->segment ) +
1544  sizeof ( event->segment[0] ) ) );
1545  return 0;
1546 
1547  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
1548  err_writeq_erstba:
1549  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
1550  err_writeq_erdp:
1551  dma_free ( &event->segment_map, event->segment,
1552  sizeof ( event->segment[0] ) );
1553  err_alloc_segment:
1554  dma_free ( &event->trb_map, event->trb, len );
1555  err_alloc_trb:
1556  return rc;
1557 }
An event ring.
Definition: xhci.h:869
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * run
Runtime registers.
Definition: xhci.h:1082
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:393
#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 dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
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:1073
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:359
#define XHCI_RUN_ERSTBA(intr)
Event ring segment table base address register.
Definition: xhci.h:299
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
uint16_t count
Number of entries.
Definition: ena.h:22
struct dma_device * dma
DMA device.
Definition: xhci.h:1071
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:972
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition: xhci.h:296
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1115
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:302
void * memset(void *dest, int character, size_t len) __nonnull

References count, cpu_to_le32, cpu_to_le64, DBGC2, dma(), xhci_device::dma, dma_alloc(), dma_free(), ENOMEM, xhci_device::event, len, memset(), xhci_device::name, rc, xhci_device::run, 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 1564 of file xhci.c.

1564  {
1565  struct xhci_event_ring *event = &xhci->event;
1566  unsigned int count;
1567  size_t len;
1568 
1569  /* Clear event ring registers */
1570  writel ( 0, xhci->run + XHCI_RUN_ERSTSZ ( 0 ) );
1571  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERSTBA ( 0 ) );
1572  xhci_writeq ( xhci, 0, xhci->run + XHCI_RUN_ERDP ( 0 ) );
1573 
1574  /* Free event ring segment table */
1575  dma_free ( &event->segment_map, event->segment,
1576  sizeof ( event->segment[0] ) );
1577 
1578  /* Free event ring */
1579  count = ( 1 << XHCI_EVENT_TRBS_LOG2 );
1580  len = ( count * sizeof ( event->trb[0] ) );
1581  dma_free ( &event->trb_map, event->trb, len );
1582 }
An event ring.
Definition: xhci.h:869
void * run
Runtime registers.
Definition: xhci.h:1082
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
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:359
#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:972
#define XHCI_RUN_ERSTSZ(intr)
Event ring segment table size register.
Definition: xhci.h:296
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1115
#define XHCI_RUN_ERDP(intr)
Event ring dequeue pointer register.
Definition: xhci.h:302

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

Referenced by xhci_bus_close(), and xhci_bus_open().

◆ xhci_transfer()

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

Handle transfer event.

Parameters
xhcixHCI device
trbTransfer event TRB

Definition at line 1590 of file xhci.c.

1591  {
1592  struct xhci_slot *slot;
1593  struct xhci_endpoint *endpoint;
1594  struct io_buffer *iobuf;
1595  int rc;
1596 
1597  /* Profile transfer events */
1598  profile_start ( &xhci_transfer_profiler );
1599 
1600  /* Identify slot */
1601  if ( ( trb->slot > xhci->slots ) ||
1602  ( ( slot = xhci->slot[trb->slot] ) == NULL ) ) {
1603  DBGC ( xhci, "XHCI %s transfer event invalid slot %d:\n",
1604  xhci->name, trb->slot );
1605  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1606  return;
1607  }
1608 
1609  /* Identify endpoint */
1610  if ( ( trb->endpoint >= XHCI_CTX_END ) ||
1611  ( ( endpoint = slot->endpoint[trb->endpoint] ) == NULL ) ) {
1612  DBGC ( xhci, "XHCI %s slot %d transfer event invalid epid "
1613  "%d:\n", xhci->name, slot->id, trb->endpoint );
1614  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1615  return;
1616  }
1617 
1618  /* Dequeue TRB(s) */
1619  iobuf = xhci_dequeue_multi ( &endpoint->ring );
1620  assert ( iobuf != NULL );
1621 
1622  /* Unmap I/O buffer */
1623  iob_unmap ( iobuf );
1624 
1625  /* Check for errors */
1626  if ( ! ( ( trb->code == XHCI_CMPLT_SUCCESS ) ||
1627  ( trb->code == XHCI_CMPLT_SHORT ) ) ) {
1628 
1629  /* Construct error */
1630  rc = -ECODE ( trb->code );
1631  DBGC ( xhci, "XHCI %s slot %d ctx %d failed (code %d): %s\n",
1632  xhci->name, slot->id, endpoint->ctx, trb->code,
1633  strerror ( rc ) );
1634  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1635 
1636  /* Sanity check */
1637  assert ( ( endpoint->context->state & XHCI_ENDPOINT_STATE_MASK )
1638  != XHCI_ENDPOINT_RUNNING );
1639 
1640  /* Report failure to USB core */
1641  usb_complete_err ( endpoint->ep, iobuf, rc );
1642  return;
1643  }
1644 
1645  /* Record actual transfer size */
1646  iob_unput ( iobuf, le16_to_cpu ( trb->residual ) );
1647 
1648  /* Sanity check (for successful completions only) */
1649  assert ( xhci_ring_consumed ( &endpoint->ring ) ==
1650  le64_to_cpu ( trb->transfer ) );
1651 
1652  /* Report completion to USB core */
1653  usb_complete ( endpoint->ep, iobuf );
1654  profile_stop ( &xhci_transfer_profiler );
1655 }
Short packet.
Definition: xhci.h:637
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
Definition: xhci.h:936
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
uint8_t state
Endpoint state.
Definition: xhci.h:771
#define DBGC(...)
Definition: compiler.h:505
uint8_t code
Completion code.
Definition: xhci.h:597
An xHCI endpoint.
Definition: xhci.h:1160
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:1087
#define ECODE(code)
Definition: xhci.c:233
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:1168
#define DBGC_HDA(...)
Definition: compiler.h:506
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:275
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1174
An xHCI device slot.
Definition: xhci.h:1132
#define iob_unput(iobuf, len)
Definition: iobuf.h:135
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1073
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:1414
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1166
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition: usb.h:1066
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1176
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:1122
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:586
#define XHCI_ENDPOINT_STATE_MASK
Endpoint state mask.
Definition: xhci.h:809
A persistent I/O buffer.
Definition: iobuf.h:33

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

Referenced by xhci_event_poll().

◆ xhci_complete()

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

Handle command completion event.

Parameters
xhcixHCI device
trbCommand completion event

Definition at line 1663 of file xhci.c.

1664  {
1665  int rc;
1666 
1667  /* Ignore "command ring stopped" notifications */
1668  if ( trb->code == XHCI_CMPLT_CMD_STOPPED ) {
1669  DBGC2 ( xhci, "XHCI %s command ring stopped\n", xhci->name );
1670  return;
1671  }
1672 
1673  /* Ignore unexpected completions */
1674  if ( ! xhci->pending ) {
1675  rc = -ECODE ( trb->code );
1676  DBGC ( xhci, "XHCI %s unexpected completion (code %d): %s\n",
1677  xhci->name, trb->code, strerror ( rc ) );
1678  DBGC_HDA ( xhci, 0, trb, sizeof ( *trb ) );
1679  return;
1680  }
1681 
1682  /* Dequeue command TRB */
1683  xhci_dequeue ( &xhci->command );
1684 
1685  /* Sanity check */
1686  assert ( xhci_ring_consumed ( &xhci->command ) ==
1687  le64_to_cpu ( trb->command ) );
1688 
1689  /* Record completion */
1690  memcpy ( xhci->pending, trb, sizeof ( *xhci->pending ) );
1691  xhci->pending = NULL;
1692 }
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:1353
static physaddr_t xhci_ring_consumed(struct xhci_trb_ring *ring)
Calculate physical address of most recently consumed TRB.
Definition: xhci.h:936
struct xhci_trb_ring command
Command ring.
Definition: xhci.h:1113
union xhci_trb * pending
Current command (if any)
Definition: xhci.h:1117
#define DBGC(...)
Definition: compiler.h:505
#define ECODE(code)
Definition: xhci.c:233
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define DBGC_HDA(...)
Definition: compiler.h:506
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1073
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:321

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

Referenced by xhci_event_poll().

◆ xhci_port_status()

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

Handle port status event.

Parameters
xhcixHCI device
trbPort status event

Definition at line 1700 of file xhci.c.

1701  {
1702  struct usb_port *port = usb_port ( xhci->bus->hub, trb->port );
1703  uint32_t portsc;
1704 
1705  /* Sanity check */
1706  assert ( ( trb->port > 0 ) && ( trb->port <= xhci->ports ) );
1707 
1708  /* Record disconnections and clear changes */
1709  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1710  port->disconnected |= ( portsc & XHCI_PORTSC_CSC );
1711  portsc &= ( XHCI_PORTSC_PRESERVE | XHCI_PORTSC_CHANGE );
1712  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( trb->port ) );
1713 
1714  /* Report port status change */
1715  usb_port_changed ( port );
1716 }
unsigned int ports
Number of ports.
Definition: xhci.h:1091
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:1125
#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:1839
A USB port.
Definition: usb.h:798
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:974
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:945
void * op
Operational registers.
Definition: xhci.h:1080

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

1725  {
1726  int rc;
1727 
1728  /* Construct error */
1729  rc = -ECODE ( trb->code );
1730  DBGC ( xhci, "XHCI %s host controller event (code %d): %s\n",
1731  xhci->name, trb->code, strerror ( rc ) );
1732 }
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:233
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1073

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

1739  {
1740  struct xhci_event_ring *event = &xhci->event;
1741  union xhci_trb *trb;
1742  unsigned int shift = XHCI_EVENT_TRBS_LOG2;
1743  unsigned int count = ( 1 << shift );
1744  unsigned int mask = ( count - 1 );
1745  unsigned int consumed;
1746  unsigned int type;
1747 
1748  /* Do nothing if device has permanently failed */
1749  if ( xhci->failed )
1750  return;
1751 
1752  /* Poll for events */
1753  profile_start ( &xhci_event_profiler );
1754  for ( consumed = 0 ; ; consumed++ ) {
1755 
1756  /* Stop if we reach an empty TRB */
1757  rmb();
1758  trb = &event->trb[ event->cons & mask ];
1759  if ( ! ( ( trb->common.flags ^
1760  ( event->cons >> shift ) ) & XHCI_TRB_C ) )
1761  break;
1762 
1763  /* Consume this TRB */
1764  event->cons++;
1765 
1766  /* Handle TRB */
1767  type = ( trb->common.type & XHCI_TRB_TYPE_MASK );
1768  switch ( type ) {
1769 
1770  case XHCI_TRB_TRANSFER :
1771  xhci_transfer ( xhci, &trb->transfer );
1772  break;
1773 
1774  case XHCI_TRB_COMPLETE :
1775  xhci_complete ( xhci, &trb->complete );
1776  break;
1777 
1778  case XHCI_TRB_PORT_STATUS:
1779  xhci_port_status ( xhci, &trb->port );
1780  break;
1781 
1783  xhci_host_controller ( xhci, &trb->host );
1784  break;
1785 
1786  default:
1787  DBGC ( xhci, "XHCI %s unrecognised event %#x\n:",
1788  xhci->name, ( event->cons - 1 ) );
1789  DBGC_HDA ( xhci, virt_to_phys ( trb ),
1790  trb, sizeof ( *trb ) );
1791  break;
1792  }
1793  }
1794 
1795  /* Update dequeue pointer if applicable */
1796  if ( consumed ) {
1797  xhci_writeq ( xhci, dma ( &event->trb_map, trb ),
1798  xhci->run + XHCI_RUN_ERDP ( 0 ) );
1799  profile_stop ( &xhci_event_profiler );
1800  }
1801 }
An event ring.
Definition: xhci.h:869
struct xhci_trb_common common
Common fields.
Definition: xhci.h:687
void * run
Runtime registers.
Definition: xhci.h:1082
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:1590
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
int failed
Command mechanism has permanently failed.
Definition: xhci.h:1119
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1073
static int xhci_writeq(struct xhci_device *xhci, physaddr_t value, void *reg)
Write potentially 64-bit register.
Definition: xhci.c:359
struct xhci_trb_complete complete
Command completion event.
Definition: xhci.h:713
uint32_t type
Operating system type.
Definition: ena.h:12
#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:1724
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:1663
struct xhci_trb_port_status port
Port status changed event.
Definition: xhci.h:715
#define XHCI_EVENT_TRBS_LOG2
Number of TRBs in the event ring.
Definition: xhci.h:972
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
#define XHCI_TRB_C
Transfer request block cycle bit flag.
Definition: xhci.h:329
struct xhci_event_ring event
Event ring.
Definition: xhci.h:1115
#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:1700

References xhci_trb::common, xhci_trb::complete, count, DBGC, DBGC_HDA, dma(), xhci_device::event, xhci_device::failed, xhci_trb_common::flags, xhci_trb::host, xhci_device::name, xhci_trb::port, profile_start(), profile_stop(), rmb, xhci_device::run, xhci_trb::transfer, type, xhci_trb_common::type, 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 1808 of file xhci.c.

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

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

Referenced by xhci_command().

◆ xhci_command()

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

Issue command and wait for completion.

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

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

Definition at line 1851 of file xhci.c.

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

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

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

◆ xhci_nop()

static int xhci_nop ( struct xhci_device xhci)
inlinestatic

Issue NOP and wait for completion.

Parameters
xhcixHCI device
Return values
rcReturn status code

Definition at line 1922 of file xhci.c.

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

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

◆ xhci_enable_slot()

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

Enable slot.

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

Definition at line 1950 of file xhci.c.

1951  {
1952  union xhci_trb trb;
1953  struct xhci_trb_enable_slot *enable = &trb.enable;
1954  struct xhci_trb_complete *enabled = &trb.complete;
1955  unsigned int slot;
1956  int rc;
1957 
1958  /* Construct command */
1959  memset ( enable, 0, sizeof ( *enable ) );
1960  enable->slot = type;
1961  enable->type = XHCI_TRB_ENABLE_SLOT;
1962 
1963  /* Issue command and wait for completion */
1964  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1965  DBGC ( xhci, "XHCI %s could not enable new slot: %s\n",
1966  xhci->name, strerror ( rc ) );
1967  return rc;
1968  }
1969 
1970  /* Extract slot number */
1971  slot = enabled->slot;
1972 
1973  DBGC2 ( xhci, "XHCI %s slot %d enabled\n", xhci->name, slot );
1974  return slot;
1975 }
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
#define DBGC(...)
Definition: compiler.h:505
An enable slot transfer request block.
Definition: xhci.h:466
uint32_t enabled
Bitmask of enabled AENQ groups (host -> device)
Definition: ena.h:14
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A transfer request block.
Definition: xhci.h:683
const char * name
Name.
Definition: xhci.h:1073
uint8_t slot
Slot.
Definition: edd.h:16
uint32_t type
Operating system type.
Definition: ena.h:12
#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:1851
uint8_t type
Type.
Definition: xhci.h:474
void * memset(void *dest, int character, size_t len) __nonnull

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

Referenced by xhci_device_open().

◆ xhci_disable_slot()

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

Disable slot.

Parameters
xhcixHCI device
slotDevice slot
Return values
rcReturn status code

Definition at line 1984 of file xhci.c.

1985  {
1986  union xhci_trb trb;
1987  struct xhci_trb_disable_slot *disable = &trb.disable;
1988  int rc;
1989 
1990  /* Construct command */
1991  memset ( disable, 0, sizeof ( *disable ) );
1992  disable->type = XHCI_TRB_DISABLE_SLOT;
1993  disable->slot = slot;
1994 
1995  /* Issue command and wait for completion */
1996  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
1997  DBGC ( xhci, "XHCI %s could not disable slot %d: %s\n",
1998  xhci->name, slot, strerror ( rc ) );
1999  return rc;
2000  }
2001 
2002  DBGC2 ( xhci, "XHCI %s slot %d disabled\n", xhci->name, slot );
2003  return 0;
2004 }
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:1073
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:1851
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 2016 of file xhci.c.

2021  {
2022  union xhci_trb trb;
2023  struct xhci_trb_context *context = &trb.context;
2024  struct dma_mapping map;
2025  size_t len;
2026  void *input;
2027  int rc;
2028 
2029  /* Allocate an input context */
2030  memset ( &map, 0, sizeof ( map ) );
2032  input = dma_alloc ( xhci->dma, &map, len, xhci_align ( len ) );
2033  if ( ! input ) {
2034  rc = -ENOMEM;
2035  goto err_alloc;
2036  }
2037  memset ( input, 0, len );
2038 
2039  /* Populate input context */
2040  populate ( xhci, slot, endpoint, input );
2041 
2042  /* Construct command */
2043  memset ( context, 0, sizeof ( *context ) );
2044  context->type = type;
2045  context->input = cpu_to_le64 ( dma ( &map, input ) );
2046  context->slot = slot->id;
2047 
2048  /* Issue command and wait for completion */
2049  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 )
2050  goto err_command;
2051 
2052  err_command:
2053  dma_free ( &map, input, len );
2054  err_alloc:
2055  return rc;
2056 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:393
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:108
uint64_t input
Input context.
Definition: xhci.h:506
#define ENOMEM
Not enough space.
Definition: errno.h:534
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
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
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
uint32_t len
Length.
Definition: ena.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:424
struct dma_device * dma
DMA device.
Definition: xhci.h:1071
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
A DMA mapping.
Definition: dma.h:32
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1851
uint8_t type
Type.
Definition: xhci.h:512
uint8_t slot
Slot ID.
Definition: xhci.h:516
void * memset(void *dest, int character, size_t len) __nonnull

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

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

◆ xhci_address_device_input()

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

Populate address device input context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
inputInput context

Definition at line 2066 of file xhci.c.

2069  {
2070  struct xhci_trb_ring *ring = &endpoint->ring;
2071  struct xhci_control_context *control_ctx;
2072  struct xhci_slot_context *slot_ctx;
2073  struct xhci_endpoint_context *ep_ctx;
2074 
2075  /* Sanity checks */
2076  assert ( endpoint->ctx == XHCI_CTX_EP0 );
2077 
2078  /* Populate control context */
2079  control_ctx = input;
2080  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2081  ( 1 << XHCI_CTX_EP0 ) );
2082 
2083  /* Populate slot context */
2084  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2085  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( 1, 0, slot->psiv,
2086  slot->route ) );
2087  slot_ctx->port = slot->port;
2088  slot_ctx->tt_id = slot->tt_id;
2089  slot_ctx->tt_port = slot->tt_port;
2090 
2091  /* Populate control endpoint context */
2092  ep_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_EP0 ) );
2093  ep_ctx->type = XHCI_EP_TYPE_CONTROL;
2094  ep_ctx->burst = endpoint->ep->burst;
2095  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2096  ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
2097  XHCI_EP_DCS );
2098  ep_ctx->trb_len = cpu_to_le16 ( XHCI_EP0_TRB_LEN );
2099 }
An endpoint context.
Definition: xhci.h:769
uint8_t burst
Maximum burst size.
Definition: xhci.h:781
uint8_t type
Endpoint type.
Definition: xhci.h:779
An input control context.
Definition: xhci.h:721
uint16_t trb_len
Average TRB length.
Definition: xhci.h:787
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
#define XHCI_EP_TYPE_CONTROL
Control endpoint type.
Definition: xhci.h:815
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:108
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:1168
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:1166
uint8_t tt_port
TT port number.
Definition: xhci.h:751
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1176
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:424
#define cpu_to_le16(value)
Definition: byteswap.h:106
A transfer request block command/transfer ring.
Definition: xhci.h:840
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:951
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

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

Referenced by xhci_address_device().

◆ xhci_address_device()

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

Address device.

Parameters
xhcixHCI device
slotDevice slot
Return values
rcReturn status code

Definition at line 2108 of file xhci.c.

2109  {
2110  struct usb_device *usb = slot->usb;
2111  struct xhci_slot_context *slot_ctx;
2112  int rc;
2113 
2114  /* Assign device address */
2115  if ( ( rc = xhci_context ( xhci, slot, slot->endpoint[XHCI_CTX_EP0],
2117  xhci_address_device_input ) ) != 0 ) {
2118  DBGC ( xhci, "XHCI %s slot %d could not assign address: %s\n",
2119  xhci->name, slot->id, strerror ( rc ) );
2120  return rc;
2121  }
2122 
2123  /* Get assigned address */
2124  slot_ctx = ( slot->context +
2126  usb->address = slot_ctx->address;
2127  DBGC2 ( xhci, "XHCI %s slot %d assigned address %d to %s\n",
2128  xhci->name, slot->id, usb->address, usb->name );
2129 
2130  return 0;
2131 }
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:412
#define DBGC(...)
Definition: compiler.h:505
static int xhci_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, unsigned int type, void(*populate)(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input))
Issue context-based command and wait for completion.
Definition: xhci.c:2016
unsigned int address
Device address, if assigned.
Definition: usb.h:718
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:710
A USB device.
Definition: usb.h:708
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1073
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:2066
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:951
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

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

Referenced by xhci_device_address().

◆ xhci_configure_endpoint_input()

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

Populate configure endpoint input context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
inputInput context

Definition at line 2141 of file xhci.c.

2144  {
2145  struct xhci_trb_ring *ring = &endpoint->ring;
2146  struct xhci_control_context *control_ctx;
2147  struct xhci_slot_context *slot_ctx;
2148  struct xhci_endpoint_context *ep_ctx;
2149 
2150  /* Populate control context */
2151  control_ctx = input;
2152  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2153  ( 1 << endpoint->ctx ) );
2154 
2155  /* Populate slot context */
2156  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2157  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2158  ( slot->ports ? 1 : 0 ),
2159  slot->psiv, 0 ) );
2160  slot_ctx->ports = slot->ports;
2161 
2162  /* Populate endpoint context */
2163  ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2164  ep_ctx->interval = endpoint->interval;
2165  ep_ctx->type = endpoint->type;
2166  ep_ctx->burst = endpoint->ep->burst;
2167  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2168  ep_ctx->dequeue = cpu_to_le64 ( dma ( &ring->map, ring->trb ) |
2169  XHCI_EP_DCS );
2170  ep_ctx->trb_len = cpu_to_le16 ( endpoint->ep->mtu ); /* best guess */
2171 }
An endpoint context.
Definition: xhci.h:769
uint8_t burst
Maximum burst size.
Definition: xhci.h:781
uint8_t type
Endpoint type.
Definition: xhci.h:779
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
An input control context.
Definition: xhci.h:721
uint16_t trb_len
Average TRB length.
Definition: xhci.h:787
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
Definition: bnxt_hsi.h:68
#define cpu_to_le64(value)
Definition: byteswap.h:108
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:1170
#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:1168
#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:1166
uint8_t interval
Polling interval.
Definition: xhci.h:775
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1176
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:424
#define cpu_to_le16(value)
Definition: byteswap.h:106
A transfer request block command/transfer ring.
Definition: xhci.h:840
unsigned int interval
Endpoint interval.
Definition: xhci.h:1172
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

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

Referenced by xhci_configure_endpoint().

◆ xhci_configure_endpoint()

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

Configure endpoint.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2181 of file xhci.c.

2183  {
2184  int rc;
2185 
2186  /* Configure endpoint */
2187  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2189  xhci_configure_endpoint_input ) ) != 0 ) {
2190  DBGC ( xhci, "XHCI %s slot %d ctx %d could not configure: %s\n",
2191  xhci->name, slot->id, endpoint->ctx, strerror ( rc ) );
2192  return rc;
2193  }
2194 
2195  DBGC2 ( xhci, "XHCI %s slot %d ctx %d configured\n",
2196  xhci->name, slot->id, endpoint->ctx );
2197  return 0;
2198 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static int xhci_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, unsigned int type, void(*populate)(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input))
Issue context-based command and wait for completion.
Definition: xhci.c:2016
unsigned int ctx
Context index.
Definition: xhci.h:1168
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1073
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:2141
#define XHCI_TRB_CONFIGURE_ENDPOINT
A configure endpoint transfer request block.
Definition: xhci.h:523
#define DBGC2(...)
Definition: compiler.h:522

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

Referenced by xhci_endpoint_open().

◆ xhci_deconfigure_endpoint_input()

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

Populate deconfigure endpoint input context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
inputInput context

Definition at line 2209 of file xhci.c.

2212  {
2213  struct xhci_control_context *control_ctx;
2214  struct xhci_slot_context *slot_ctx;
2215 
2216  /* Populate control context */
2217  control_ctx = input;
2218  control_ctx->add = cpu_to_le32 ( 1 << XHCI_CTX_SLOT );
2219  control_ctx->drop = cpu_to_le32 ( 1 << endpoint->ctx );
2220 
2221  /* Populate slot context */
2222  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2223  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2224  0, 0, 0 ) );
2225 }
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
An input control context.
Definition: xhci.h:721
Definition: bnxt_hsi.h:68
uint32_t add
Add context flags.
Definition: xhci.h:725
uint32_t drop
Drop context flags.
Definition: xhci.h:723
unsigned int ctx
Context index.
Definition: xhci.h:1168
#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:424
A slot context.
Definition: xhci.h:739
#define XHCI_CTX_SLOT
Slot context index.
Definition: xhci.h:943

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

Referenced by xhci_deconfigure_endpoint().

◆ xhci_deconfigure_endpoint()

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

Deconfigure endpoint.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2235 of file xhci.c.

2237  {
2238  int rc;
2239 
2240  /* Deconfigure endpoint */
2241  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2243  xhci_deconfigure_endpoint_input ) ) != 0 ) {
2244  DBGC ( xhci, "XHCI %s slot %d ctx %d could not deconfigure: "
2245  "%s\n", xhci->name, slot->id, endpoint->ctx,
2246  strerror ( rc ) );
2247  return rc;
2248  }
2249 
2250  DBGC2 ( xhci, "XHCI %s slot %d ctx %d deconfigured\n",
2251  xhci->name, slot->id, endpoint->ctx );
2252  return 0;
2253 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static int xhci_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, unsigned int type, void(*populate)(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input))
Issue context-based command and wait for completion.
Definition: xhci.c:2016
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:2209
unsigned int ctx
Context index.
Definition: xhci.h:1168
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1073
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, DBGC, DBGC2, xhci_device::name, rc, slot, strerror(), xhci_context(), xhci_deconfigure_endpoint_input(), and XHCI_TRB_CONFIGURE_ENDPOINT.

Referenced by xhci_endpoint_close(), and xhci_endpoint_open().

◆ xhci_evaluate_context_input()

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

Populate evaluate context input context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
inputInput context

Definition at line 2263 of file xhci.c.

2266  {
2267  struct xhci_control_context *control_ctx;
2268  struct xhci_slot_context *slot_ctx;
2269  struct xhci_endpoint_context *ep_ctx;
2270 
2271  /* Populate control context */
2272  control_ctx = input;
2273  control_ctx->add = cpu_to_le32 ( ( 1 << XHCI_CTX_SLOT ) |
2274  ( 1 << endpoint->ctx ) );
2275 
2276  /* Populate slot context */
2277  slot_ctx = ( input + xhci_input_context_offset ( xhci, XHCI_CTX_SLOT ));
2278  slot_ctx->info = cpu_to_le32 ( XHCI_SLOT_INFO ( ( XHCI_CTX_END - 1 ),
2279  0, 0, 0 ) );
2280 
2281  /* Populate endpoint context */
2282  ep_ctx = ( input + xhci_input_context_offset ( xhci, endpoint->ctx ) );
2283  ep_ctx->mtu = cpu_to_le16 ( endpoint->ep->mtu );
2284 }
An endpoint context.
Definition: xhci.h:769
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
An input control context.
Definition: xhci.h:721
Definition: bnxt_hsi.h:68
uint32_t add
Add context flags.
Definition: xhci.h:725
unsigned int ctx
Context index.
Definition: xhci.h:1168
#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:1166
static size_t xhci_input_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate input context offset.
Definition: xhci.c:424
#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:943

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

Referenced by xhci_evaluate_context().

◆ xhci_evaluate_context()

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

Evaluate context.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2294 of file xhci.c.

2296  {
2297  int rc;
2298 
2299  /* Configure endpoint */
2300  if ( ( rc = xhci_context ( xhci, slot, endpoint,
2302  xhci_evaluate_context_input ) ) != 0 ) {
2303  DBGC ( xhci, "XHCI %s slot %d ctx %d could not (re-)evaluate: "
2304  "%s\n", xhci->name, slot->id, endpoint->ctx,
2305  strerror ( rc ) );
2306  return rc;
2307  }
2308 
2309  DBGC2 ( xhci, "XHCI %s slot %d ctx %d (re-)evaluated\n",
2310  xhci->name, slot->id, endpoint->ctx );
2311  return 0;
2312 }
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:2263
#define DBGC(...)
Definition: compiler.h:505
static int xhci_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, unsigned int type, void(*populate)(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint, void *input))
Issue context-based command and wait for completion.
Definition: xhci.c:2016
unsigned int ctx
Context index.
Definition: xhci.h:1168
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * name
Name.
Definition: xhci.h:1073
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, DBGC, DBGC2, xhci_device::name, rc, slot, strerror(), xhci_context(), xhci_evaluate_context_input(), and XHCI_TRB_EVALUATE_CONTEXT.

Referenced by xhci_endpoint_mtu().

◆ xhci_reset_endpoint()

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

Reset endpoint.

Parameters
xhcixHCI device
slotDevice slot
endpointEndpoint
Return values
rcReturn status code

Definition at line 2322 of file xhci.c.

2324  {
2325  union xhci_trb trb;
2326  struct xhci_trb_reset_endpoint *reset = &trb.reset;
2327  int rc;
2328 
2329  /* Construct command */
2330  memset ( reset, 0, sizeof ( *reset ) );
2331  reset->slot = slot->id;
2332  reset->endpoint = endpoint->ctx;
2333  reset->type = XHCI_TRB_RESET_ENDPOINT;
2334 
2335  /* Issue command and wait for completion */
2336  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2337  DBGC ( xhci, "XHCI %s slot %d ctx %d could not reset endpoint "
2338  "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2339  endpoint->context->state, strerror ( rc ) );
2340  return rc;
2341  }
2342 
2343  return 0;
2344 }
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:1073
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:1851
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 2354 of file xhci.c.

2356  {
2357  union xhci_trb trb;
2358  struct xhci_trb_stop_endpoint *stop = &trb.stop;
2359  int rc;
2360 
2361  /* Construct command */
2362  memset ( stop, 0, sizeof ( *stop ) );
2363  stop->slot = slot->id;
2364  stop->endpoint = endpoint->ctx;
2365  stop->type = XHCI_TRB_STOP_ENDPOINT;
2366 
2367  /* Issue command and wait for completion */
2368  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2369  DBGC ( xhci, "XHCI %s slot %d ctx %d could not stop endpoint "
2370  "in state %d: %s\n", xhci->name, slot->id, endpoint->ctx,
2371  endpoint->context->state, strerror ( rc ) );
2372  return rc;
2373  }
2374 
2375  return 0;
2376 }
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:1073
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:1851
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 2387 of file xhci.c.

2389  {
2390  union xhci_trb trb;
2391  struct xhci_trb_set_tr_dequeue_pointer *dequeue = &trb.dequeue;
2392  struct xhci_trb_ring *ring = &endpoint->ring;
2393  unsigned int cons;
2394  unsigned int mask;
2395  unsigned int index;
2396  unsigned int dcs;
2397  physaddr_t addr;
2398  int rc;
2399 
2400  /* Construct command */
2401  memset ( dequeue, 0, sizeof ( *dequeue ) );
2402  cons = ring->cons;
2403  mask = ring->mask;
2404  dcs = ( ( ~( cons >> ring->shift ) ) & XHCI_EP_DCS );
2405  index = ( cons & mask );
2406  addr = dma ( &ring->map, &ring->trb[index] );
2407  dequeue->dequeue = cpu_to_le64 ( addr | dcs );
2408  dequeue->slot = slot->id;
2409  dequeue->endpoint = endpoint->ctx;
2411 
2412  /* Issue command and wait for completion */
2413  if ( ( rc = xhci_command ( xhci, &trb ) ) != 0 ) {
2414  DBGC ( xhci, "XHCI %s slot %d ctx %d could not set TR dequeue "
2415  "pointer in state %d: %s\n", xhci->name, slot->id,
2416  endpoint->ctx, endpoint->context->state, strerror ( rc));
2417  return rc;
2418  }
2419 
2420  return 0;
2421 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define XHCI_TRB_SET_TR_DEQUEUE_POINTER
A set transfer ring dequeue pointer transfer request block.
Definition: xhci.h:583
unsigned int cons
Consumer counter.
Definition: xhci.h:844
A set transfer ring dequeue pointer transfer request block.
Definition: xhci.h:567
uint8_t state
Endpoint state.
Definition: xhci.h:771
#define DBGC(...)
Definition: compiler.h:505
struct dma_mapping map
DMA mapping.
Definition: xhci.h:858
#define cpu_to_le64(value)
Definition: byteswap.h:108
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:1168
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1174
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:1073
uint8_t slot
Slot ID.
Definition: xhci.h:579
u32 addr
Definition: sky2.h:8
uint8_t slot
Slot.
Definition: edd.h:16
unsigned long physaddr_t
Definition: stdint.h:20
unsigned int mask
Ring counter mask.
Definition: xhci.h:848
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1176
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 __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
static int xhci_command(struct xhci_device *xhci, union xhci_trb *trb)
Issue command and wait for completion.
Definition: xhci.c:1851
uint8_t endpoint
Endpoint ID.
Definition: xhci.h:577
void * memset(void *dest, int character, size_t len) __nonnull

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

Referenced by xhci_endpoint_reset().

◆ xhci_endpoint_open()

static int xhci_endpoint_open ( struct usb_endpoint ep)
static

Open endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2436 of file xhci.c.

2436  {
2437  struct usb_device *usb = ep->usb;
2438  struct xhci_slot *slot = usb_get_hostdata ( usb );
2439  struct xhci_device *xhci = slot->xhci;
2440  struct xhci_endpoint *endpoint;
2441  unsigned int ctx;
2442  unsigned int type;
2443  unsigned int interval;
2444  int rc;
2445 
2446  /* Calculate context index */
2447  ctx = XHCI_CTX ( ep->address );
2448  assert ( slot->endpoint[ctx] == NULL );
2449 
2450  /* Calculate endpoint type */
2454  if ( ep->address & USB_DIR_IN )
2455  type |= XHCI_EP_TYPE_IN;
2456 
2457  /* Calculate interval */
2458  if ( type & XHCI_EP_TYPE_PERIODIC ) {
2459  interval = ( fls ( ep->interval ) - 1 );
2460  } else {
2461  interval = ep->interval;
2462  }
2463 
2464  /* Allocate and initialise structure */
2465  endpoint = zalloc ( sizeof ( *endpoint ) );
2466  if ( ! endpoint ) {
2467  rc = -ENOMEM;
2468  goto err_alloc;
2469  }
2470  usb_endpoint_set_hostdata ( ep, endpoint );
2471  slot->endpoint[ctx] = endpoint;
2472  endpoint->xhci = xhci;
2473  endpoint->slot = slot;
2474  endpoint->ep = ep;
2475  endpoint->ctx = ctx;
2476  endpoint->type = type;
2477  endpoint->interval = interval;
2478  endpoint->context = ( ( ( void * ) slot->context ) +
2480 
2481  /* Allocate transfer ring */
2482  if ( ( rc = xhci_ring_alloc ( xhci, &endpoint->ring,
2484  slot->id, ctx, 0 ) ) != 0 )
2485  goto err_ring_alloc;
2486 
2487  /* Configure endpoint, if applicable */
2488  if ( ( ctx != XHCI_CTX_EP0 ) &&
2489  ( ( rc = xhci_configure_endpoint ( xhci, slot, endpoint ) ) != 0 ))
2490  goto err_configure_endpoint;
2491 
2492  DBGC2 ( xhci, "XHCI %s slot %d ctx %d ring [%08lx,%08lx)\n",
2493  xhci->name, slot->id, ctx, virt_to_phys ( endpoint->ring.trb ),
2494  ( virt_to_phys ( endpoint->ring.trb ) + endpoint->ring.len ) );
2495  return 0;
2496 
2497  xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2498  err_configure_endpoint:
2499  xhci_ring_free ( &endpoint->ring );
2500  err_ring_alloc:
2501  slot->endpoint[ctx] = NULL;
2502  free ( endpoint );
2503  err_alloc:
2504  return rc;
2505 }
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:412
An xHCI device.
Definition: xhci.h:1067
#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
#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:1284
static int xhci_configure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Configure endpoint.
Definition: xhci.c:2181
#define XHCI_TRANSFER_TRBS_LOG2
Number of TRBs in a transfer ring.
Definition: xhci.h:978
An xHCI endpoint.
Definition: xhci.h:1160
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:1170
#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:1168
struct usb_device * usb
USB device.
Definition: xhci.h:1136
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:83
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1164
struct xhci_endpoint_context * context
Endpoint context.
Definition: xhci.h:1174
A USB device.
Definition: usb.h:708
static int xhci_deconfigure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Deconfigure endpoint.
Definition: xhci.c:2235
An xHCI device slot.
Definition: xhci.h:1132
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
const char * name
Name.
Definition: xhci.h:1073
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
uint8_t slot
Slot.
Definition: edd.h:16
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:780
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1166
#define XHCI_CTX(address)
Calculate context index from USB endpoint address.
Definition: xhci.h:946
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC2(...)
Definition: compiler.h:522
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:730
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1176
unsigned int interval
Interval (in microframes)
Definition: usb.h:401
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
Definition: usb.h:272
struct usb_device * usb
USB device.
Definition: usb.h:391
unsigned int interval
Endpoint interval.
Definition: xhci.h:1172
#define fls(x)
Find last (i.e.
Definition: strings.h:166
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1162
unsigned int attributes
Attributes.
Definition: usb.h:395
unsigned int address
Endpoint address.
Definition: usb.h:393
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:951
static int xhci_ring_alloc(struct xhci_device *xhci, struct xhci_trb_ring *ring, unsigned int shift, unsigned int slot, unsigned int target, unsigned int stream)
Allocate transfer request block ring.
Definition: xhci.c:1211

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

◆ xhci_endpoint_close()

static void xhci_endpoint_close ( struct usb_endpoint ep)
static

Close endpoint.

Parameters
epUSB endpoint

Definition at line 2512 of file xhci.c.

2512  {
2513  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2514  struct xhci_slot *slot = endpoint->slot;
2515  struct xhci_device *xhci = slot->xhci;
2516  struct io_buffer *iobuf;
2517  unsigned int ctx = endpoint->ctx;
2518 
2519  /* Deconfigure endpoint, if applicable */
2520  if ( ctx != XHCI_CTX_EP0 )
2521  xhci_deconfigure_endpoint ( xhci, slot, endpoint );
2522 
2523  /* Cancel any incomplete transfers */
2524  while ( xhci_ring_fill ( &endpoint->ring ) ) {
2525  iobuf = xhci_dequeue_multi ( &endpoint->ring );
2526  iob_unmap ( iobuf );
2527  usb_complete_err ( ep, iobuf, -ECANCELED );
2528  }
2529 
2530  /* Free endpoint */
2531  xhci_ring_free ( &endpoint->ring );
2532  slot->endpoint[ctx] = NULL;
2533  free ( endpoint );
2534 }
An xHCI device.
Definition: xhci.h:1067
static unsigned int xhci_ring_fill(struct xhci_trb_ring *ring)
Calculate space used in TRB ring.
Definition: xhci.h:898
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition: xhci.h:1156
static void xhci_ring_free(struct xhci_trb_ring *ring)
Free transfer request block ring.
Definition: xhci.c:1284
An xHCI endpoint.
Definition: xhci.h:1160
#define ECANCELED
Operation canceled.
Definition: errno.h:343
unsigned int ctx
Context index.
Definition: xhci.h:1168
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:275
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1164
static int xhci_deconfigure_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Deconfigure endpoint.
Definition: xhci.c:2235
An xHCI device slot.
Definition: xhci.h:1132
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
uint8_t slot
Slot.
Definition: edd.h:16
static struct io_buffer * xhci_dequeue_multi(struct xhci_trb_ring *ring)
Dequeue multiple transfer request blocks.
Definition: xhci.c:1414
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1166
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1176
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define XHCI_CTX_EP0
Endpoint zero context index.
Definition: xhci.h:951
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:586
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572
A persistent I/O buffer.
Definition: iobuf.h:33

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

◆ xhci_endpoint_reset()

static int xhci_endpoint_reset ( struct usb_endpoint ep)
static

Reset endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2542 of file xhci.c.

2542  {
2543  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2544  struct xhci_slot *slot = endpoint->slot;
2545  struct xhci_device *xhci = slot->xhci;
2546  int rc;
2547 
2548  /* Reset endpoint context */
2549  if ( ( rc = xhci_reset_endpoint ( xhci, slot, endpoint ) ) != 0 )
2550  return rc;
2551 
2552  /* Set transfer ring dequeue pointer */
2553  if ( ( rc = xhci_set_tr_dequeue_pointer ( xhci, slot, endpoint ) ) != 0)
2554  return rc;
2555 
2556  /* Ring doorbell to resume processing */
2557  xhci_doorbell ( &endpoint->ring );
2558 
2559  DBGC ( xhci, "XHCI %s slot %d ctx %d reset\n",
2560  xhci->name, slot->id, endpoint->ctx );
2561  return 0;
2562 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An xHCI device.
Definition: xhci.h:1067
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition: xhci.h:1156
static int xhci_set_tr_dequeue_pointer(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Set transfer ring dequeue pointer.
Definition: xhci.c:2387
#define DBGC(...)
Definition: compiler.h:505
An xHCI endpoint.
Definition: xhci.h:1160
unsigned int ctx
Context index.
Definition: xhci.h:1168
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1164
An xHCI device slot.
Definition: xhci.h:1132
const char * name
Name.
Definition: xhci.h:1073
uint8_t slot
Slot.
Definition: edd.h:16
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1166
struct xhci_trb_ring ring
Transfer ring.
Definition: xhci.h:1176
static void xhci_doorbell(struct xhci_trb_ring *ring)
Ring doorbell register.
Definition: xhci.c:1431
static int xhci_reset_endpoint(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Reset endpoint.
Definition: xhci.c:2322
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572

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

◆ xhci_endpoint_mtu()

static int xhci_endpoint_mtu ( struct usb_endpoint ep)
static

Update MTU.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 2570 of file xhci.c.

2570  {
2571  struct xhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
2572  struct xhci_slot *slot = endpoint->slot;
2573  struct xhci_device *xhci = slot->xhci;
2574  int rc;
2575 
2576  /* Evalulate context */
2577  if ( ( rc = xhci_evaluate_context ( xhci, slot, endpoint ) ) != 0 )
2578  return rc;
2579 
2580  return 0;
2581 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An xHCI device.
Definition: xhci.h:1067
struct xhci_endpoint * endpoint[XHCI_CTX_END]
Endpoints, indexed by context ID.
Definition: xhci.h:1156
An xHCI endpoint.
Definition: xhci.h:1160
struct xhci_slot * slot
xHCI slot
Definition: xhci.h:1164
An xHCI device slot.
Definition: xhci.h:1132
uint8_t slot
Slot.
Definition: edd.h:16
struct usb_endpoint * ep
USB endpoint.
Definition: xhci.h:1166
static int xhci_evaluate_context(struct xhci_device *xhci, struct xhci_slot *slot, struct xhci_endpoint *endpoint)
Evaluate context.
Definition: xhci.c:2294
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572

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

◆ xhci_endpoint_message()

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

Enqueue message transfer.

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

Definition at line 2590 of file xhci.c.

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

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

◆ xhci_endpoint_count()

static unsigned int xhci_endpoint_count ( size_t  len,
int  zlp 
)
static

Calculate number of TRBs.

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

Definition at line 2668 of file xhci.c.

2668  {
2669  unsigned int count;
2670 
2671  /* Split into 64kB TRBs */
2672  count = ( ( len + XHCI_MTU - 1 ) / XHCI_MTU );
2673 
2674  /* Append a zero-length TRB if applicable */
2675  if ( zlp || ( count == 0 ) )
2676  count++;
2677 
2678  return count;
2679 }
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:28
uint32_t len
Length.
Definition: ena.h:14
uint16_t count
Number of entries.
Definition: ena.h:22

References count, len, and XHCI_MTU.

Referenced by xhci_endpoint_stream().

◆ xhci_endpoint_stream()

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

Enqueue stream transfer.

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

Definition at line 2689 of file xhci.c.

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

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

◆ xhci_device_open()

static int xhci_device_open ( struct usb_device usb)
static

Open device.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 2772 of file xhci.c.

2772  {
2773  struct xhci_device *xhci = usb_bus_get_hostdata ( usb->port->hub->bus );
2774  struct usb_port *tt = usb_transaction_translator ( usb );
2775  struct xhci_slot *slot;
2776  struct xhci_slot *tt_slot;
2777  size_t len;
2778  int type;
2779  int id;
2780  int rc;
2781 
2782  /* Determine applicable slot type */
2784  if ( type < 0 ) {
2785  rc = type;
2786  DBGC ( xhci, "XHCI %s-%d has no slot type\n",
2787  xhci->name, usb->port->address );
2788  goto err_type;
2789  }
2790 
2791  /* Allocate a device slot number */
2792  id = xhci_enable_slot ( xhci, type );
2793  if ( id < 0 ) {
2794  rc = id;
2795  goto err_enable_slot;
2796  }
2797  assert ( ( id > 0 ) && ( ( unsigned int ) id <= xhci->slots ) );
2798  assert ( xhci->slot[id] == NULL );
2799 
2800  /* Allocate and initialise structure */
2801  slot = zalloc ( sizeof ( *slot ) );
2802  if ( ! slot ) {
2803  rc = -ENOMEM;
2804  goto err_alloc;
2805  }
2806  usb_set_hostdata ( usb, slot );
2807  xhci->slot[id] = slot;
2808  slot->xhci = xhci;
2809  slot->usb = usb;
2810  slot->id = id;
2811  if ( tt ) {
2812  tt_slot = usb_get_hostdata ( tt->hub->usb );
2813  slot->tt_id = tt_slot->id;
2814  slot->tt_port = tt->address;
2815  }
2816 
2817  /* Allocate a device context */
2819  slot->context = dma_alloc ( xhci->dma, &slot->map, len,
2820  xhci_align ( len ) );
2821  if ( ! slot->context ) {
2822  rc = -ENOMEM;
2823  goto err_alloc_context;
2824  }
2825  memset ( slot->context, 0, len );
2826 
2827  /* Set device context base address */
2828  assert ( xhci->dcbaa.context[id] == 0 );
2829  xhci->dcbaa.context[id] = cpu_to_le64 ( dma ( &slot->map,
2830  slot->context ) );
2831 
2832  DBGC2 ( xhci, "XHCI %s slot %d device context [%08lx,%08lx) for %s\n",
2833  xhci->name, slot->id, virt_to_phys ( slot->context ),
2834  ( virt_to_phys ( slot->context ) + len ), usb->name );
2835  return 0;
2836 
2837  xhci->dcbaa.context[id] = 0;
2838  dma_free ( &slot->map, slot->context, len );
2839  err_alloc_context:
2840  xhci->slot[id] = NULL;
2841  free ( slot );
2842  err_alloc:
2843  xhci_disable_slot ( xhci, id );
2844  err_enable_slot:
2845  err_type:
2846  return rc;
2847 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct xhci_dcbaa dcbaa
Device context base address array.
Definition: xhci.h:1107
#define XHCI_CTX_END
End of contexts.
Definition: xhci.h:954
struct xhci_device * xhci
xHCI device
Definition: xhci.h:1134
static size_t xhci_device_context_offset(struct xhci_device *xhci, unsigned int ctx)
Calculate device context offset.
Definition: xhci.c:412
An xHCI device.
Definition: xhci.h:1067
static size_t xhci_align(size_t len)
Calculate buffer alignment.
Definition: xhci.c:393
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition: usb.h:769
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:820
#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
A USB port.
Definition: usb.h:798
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:832
static int xhci_enable_slot(struct xhci_device *xhci, unsigned int type)
Enable slot.
Definition: xhci.c:1950
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
static int xhci_port_slot_type(struct xhci_device *xhci, unsigned int port)
Find port slot type.
Definition: xhci.c:760
struct usb_port * port
USB port.
Definition: usb.h:712
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct usb_device * usb
USB device.
Definition: xhci.h:1136
char name[32]
Name.
Definition: usb.h:710
An xHCI device slot.
Definition: xhci.h:1132
uint8_t id
Request identifier.
Definition: ena.h:12
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
const char * name
Name.
Definition: xhci.h:1073
unsigned int id
Slot ID.
Definition: xhci.h:1138
uint64_t * context
Context base addresses.
Definition: xhci.h:1047
uint8_t slot
Slot.
Definition: edd.h:16
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:780
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
Definition: usb.c:2302
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1041
static int xhci_disable_slot(struct xhci_device *xhci, unsigned int slot)
Disable slot.
Definition: xhci.c:1984
uint32_t len
Length.
Definition: ena.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC2(...)
Definition: compiler.h:522
unsigned int address
Port address.
Definition: usb.h:802
struct usb_hub * hub
USB hub.
Definition: usb.h:800
struct dma_device * dma
DMA device.
Definition: xhci.h:1071
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
struct usb_bus * bus
USB bus.
Definition: usb.h:830
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1122
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void * memset(void *dest, int character, size_t len) __nonnull

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

◆ xhci_device_close()

static void xhci_device_close ( struct usb_device usb)
static

Close device.

Parameters
usbUSB device

Definition at line 2854 of file xhci.c.

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

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

◆ xhci_device_address()

static int xhci_device_address ( struct usb_device usb)
static

Assign device address.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 2891 of file xhci.c.

2891  {
2892  struct xhci_slot *slot = usb_get_hostdata ( usb );
2893  struct xhci_device *xhci = slot->xhci;
2894  struct usb_port *root_port;
2895  int psiv;
2896  int rc;
2897 
2898  /* Calculate route string */
2899  slot->route = usb_route_string ( usb );
2900 
2901  /* Calculate root hub port number */
2902  root_port = usb_root_hub_port ( usb );
2903  slot->port = root_port->address;
2904 
2905  /* Calculate protocol speed ID */
2906  psiv = xhci_port_psiv ( xhci, slot->port, usb->speed );
2907  if ( psiv < 0 ) {
2908  rc = psiv;
2909  return rc;
2910  }
2911  slot->psiv = psiv;
2912 
2913  /* Address device */
2914  if ( ( rc = xhci_address_device ( xhci, slot ) ) != 0 )
2915  return rc;
2916 
2917  return 0;
2918 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xhci_address_device(struct xhci_device *xhci, struct xhci_slot *slot)
Address device.
Definition: xhci.c:2108
An xHCI device.
Definition: xhci.h:1067
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:820
unsigned int speed
Device speed.
Definition: usb.h:714
static int xhci_port_psiv(struct xhci_device *xhci, unsigned int port, unsigned int speed)
Find protocol speed ID value.
Definition: xhci.c:848
A USB port.
Definition: usb.h:798
struct usb_device * usb
USB device.
Definition: xhci.h:1136
An xHCI device slot.
Definition: xhci.h:1132
unsigned int usb_route_string(struct usb_device *usb)
Get USB route string.
Definition: usb.c:2266
uint8_t slot
Slot.
Definition: edd.h:16
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:780
struct usb_port * usb_root_hub_port(struct usb_device *usb)
Get USB root hub port.
Definition: usb.c:2286
unsigned int address
Port address.
Definition: usb.h:802

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

◆ xhci_bus_open()

static int xhci_bus_open ( struct usb_bus bus)
static

Open USB bus.

Parameters
busUSB bus
Return values
rcReturn status code

Definition at line 2933 of file xhci.c.

2933  {
2934  struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
2935  int rc;
2936 
2937  /* Allocate device slot array */
2938  xhci->slot = zalloc ( ( xhci->slots + 1 ) * sizeof ( xhci->slot[0] ) );
2939  if ( ! xhci->slot ) {
2940  rc = -ENOMEM;
2941  goto err_slot_alloc;
2942  }
2943 
2944  /* Allocate device context base address array */
2945  if ( ( rc = xhci_dcbaa_alloc ( xhci ) ) != 0 )
2946  goto err_dcbaa_alloc;
2947 
2948  /* Allocate scratchpad buffers */
2949  if ( ( rc = xhci_scratchpad_alloc ( xhci ) ) != 0 )
2950  goto err_scratchpad_alloc;
2951 
2952  /* Allocate command ring */
2953  if ( ( rc = xhci_command_alloc ( xhci ) ) != 0 )
2954  goto err_command_alloc;
2955 
2956  /* Allocate event ring */
2957  if ( ( rc = xhci_event_alloc ( xhci ) ) != 0 )
2958  goto err_event_alloc;
2959 
2960  /* Start controller */
2961  xhci_run ( xhci );
2962 
2963  return 0;
2964 
2965  xhci_stop ( xhci );
2966  xhci_event_free ( xhci );
2967  err_event_alloc:
2968  xhci_command_free ( xhci );
2969  err_command_alloc:
2970  xhci_scratchpad_free ( xhci );
2971  err_scratchpad_alloc:
2972  xhci_dcbaa_free ( xhci );
2973  err_dcbaa_alloc:
2974  free ( xhci->slot );
2975  err_slot_alloc:
2976  return rc;
2977 }
static void xhci_command_free(struct xhci_device *xhci)
Free command ring.
Definition: xhci.c:1481
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition: xhci.c:1104
An xHCI device.
Definition: xhci.h:1067
static int xhci_command_alloc(struct xhci_device *xhci)
Allocate command ring.
Definition: xhci.c:1450
unsigned int slots
Number of device slots.
Definition: xhci.h:1087
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void xhci_event_free(struct xhci_device *xhci)
Free event ring.
Definition: xhci.c:1564
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static void xhci_dcbaa_free(struct xhci_device *xhci)
Free device context base address array.
Definition: xhci.c:952
static int xhci_scratchpad_alloc(struct xhci_device *xhci)
Allocate scratchpad buffers.
Definition: xhci.c:981
static void xhci_run(struct xhci_device *xhci)
Start xHCI device.
Definition: xhci.c:1082
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1041
static void xhci_scratchpad_free(struct xhci_device *xhci)
Free scratchpad buffers.
Definition: xhci.c:1048
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1122
static int xhci_event_alloc(struct xhci_device *xhci)
Allocate event ring.
Definition: xhci.c:1499
uint8_t bus
Bus.
Definition: edd.h:14
static int xhci_dcbaa_alloc(struct xhci_device *xhci)
Allocate device context base address array.
Definition: xhci.c:910

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

◆ xhci_bus_close()

static void xhci_bus_close ( struct usb_bus bus)
static

Close USB bus.

Parameters
busUSB bus

Definition at line 2984 of file xhci.c.

2984  {
2985  struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
2986  unsigned int i;
2987 
2988  /* Sanity checks */
2989  assert ( xhci->slot != NULL );
2990  for ( i = 0 ; i <= xhci->slots ; i++ )
2991  assert ( xhci->slot[i] == NULL );
2992 
2993  xhci_stop ( xhci );
2994  xhci_event_free ( xhci );
2995  xhci_command_free ( xhci );
2996  xhci_scratchpad_free ( xhci );
2997  xhci_dcbaa_free ( xhci );
2998  free ( xhci->slot );
2999 }
static void xhci_command_free(struct xhci_device *xhci)
Free command ring.
Definition: xhci.c:1481
static int xhci_stop(struct xhci_device *xhci)
Stop xHCI device.
Definition: xhci.c:1104
An xHCI device.
Definition: xhci.h:1067
unsigned int slots
Number of device slots.
Definition: xhci.h:1087
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void xhci_event_free(struct xhci_device *xhci)
Free event ring.
Definition: xhci.c:1564
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static void xhci_dcbaa_free(struct xhci_device *xhci)
Free device context base address array.
Definition: xhci.c:952
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1041
static void xhci_scratchpad_free(struct xhci_device *xhci)
Free scratchpad buffers.
Definition: xhci.c:1048
struct xhci_slot ** slot
Device slots, indexed by slot ID.
Definition: xhci.h:1122
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t bus
Bus.
Definition: edd.h:14

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

◆ xhci_bus_poll()

static void xhci_bus_poll ( struct usb_bus bus)
static

Poll USB bus.

Parameters
busUSB bus

Definition at line 3006 of file xhci.c.

3006  {
3007  struct xhci_device *xhci = usb_bus_get_hostdata ( bus );
3008 
3009  /* Poll event ring */
3010  xhci_event_poll ( xhci );
3011 }
An xHCI device.
Definition: xhci.h:1067
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1041
static void xhci_event_poll(struct xhci_device *xhci)
Poll event ring.
Definition: xhci.c:1739
uint8_t bus
Bus.
Definition: edd.h:14

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

◆ xhci_hub_open()

static int xhci_hub_open ( struct usb_hub hub)
static

Open hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 3026 of file xhci.c.

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

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

◆ xhci_hub_close()

static void xhci_hub_close ( struct usb_hub *hub  __unused)
static

Close hub.

Parameters
hubUSB hub

Definition at line 3053 of file xhci.c.

3053  {
3054 
3055  /* Nothing to do */
3056 }

◆ xhci_root_open()

static int xhci_root_open ( struct usb_hub hub)
static

Open root hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 3071 of file xhci.c.

3071  {
3072  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3073  struct usb_port *port;
3074  uint32_t portsc;
3075  unsigned int i;
3076 
3077  /* Enable power to all ports */
3078  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3079  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( i ) );
3080  portsc &= XHCI_PORTSC_PRESERVE;
3081  portsc |= XHCI_PORTSC_PP;
3082  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( i ) );
3083  }
3084 
3085  /* xHCI spec requires us to potentially wait 20ms after
3086  * enabling power to a port.
3087  */
3089 
3090  /* USB3 ports may power up as Disabled */
3091  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3092  portsc = readl ( xhci->op + XHCI_OP_PORTSC ( i ) );
3093  port = usb_port ( hub, i );
3094  if ( ( port->protocol >= USB_PROTO_3_0 ) &&
3095  ( ( portsc & XHCI_PORTSC_PLS_MASK ) ==
3097  /* Force link state to RxDetect */
3098  portsc &= XHCI_PORTSC_PRESERVE;
3100  writel ( portsc, xhci->op + XHCI_OP_PORTSC ( i ) );
3101  }
3102  }
3103 
3104  /* Some xHCI cards seem to require an additional delay after
3105  * setting the link state to RxDetect.
3106  */
3108 
3109  return 0;
3110 }
unsigned int ports
Number of ports.
Definition: xhci.h:1091
An xHCI device.
Definition: xhci.h:1067
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define XHCI_PORTSC_PRESERVE
Port status and control bits which should be preserved.
Definition: xhci.h:284
#define XHCI_PORTSC_PP
Port power.
Definition: xhci.h:228
A USB port.
Definition: usb.h:798
u8 port
Port number.
Definition: CIB_PRM.h:31
USB 3.0.
Definition: usb.h:24
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define XHCI_PORTSC_LWS
Port link state write strobe.
Definition: xhci.h:243
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define XHCI_PORTSC_PLS_RXDETECT
RxDetect port link state.
Definition: xhci.h:222
#define XHCI_OP_PORTSC(port)
Port status and control register.
Definition: xhci.h:204
#define XHCI_PORT_POWER_DELAY_MS
Time to delay after enabling power to a port.
Definition: xhci.h:231
struct usb_hub * hub
USB hub.
Definition: usb.h:800
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:945
#define XHCI_PORTSC_PLS_DISABLED
Disabled port link state.
Definition: xhci.h:219
#define XHCI_LINK_STATE_DELAY_MS
Time to delay after writing the port link state.
Definition: xhci.h:246
void * op
Operational registers.
Definition: xhci.h:1080
#define XHCI_PORTSC_PLS_MASK
Port link state mask.
Definition: xhci.h:225
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:933

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

◆ xhci_root_close()

static void xhci_root_close ( struct usb_hub *hub  __unused)
static

Close root hub.

Parameters
hubUSB hub

Definition at line 3117 of file xhci.c.

3117  {
3118 
3119  /* Nothing to do */
3120 }

◆ xhci_root_enable()

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

Enable port.

Parameters
hubUSB hub
portUSB port
Return values
rcReturn status code

Definition at line 3129 of file xhci.c.

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

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

◆ xhci_root_disable()

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

Disable port.

Parameters
hubUSB hub
portUSB port
Return values
rcReturn status code

Definition at line 3164 of file xhci.c.

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

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

◆ xhci_root_speed()

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

Update root hub port speed.

Parameters
hubUSB hub
portUSB port
Return values
rcReturn status code

Definition at line 3197 of file xhci.c.

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

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

◆ xhci_root_clear_tt()

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

Clear transaction translator buffer.

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

Definition at line 3254 of file xhci.c.

3255  {
3256  struct xhci_device *xhci = usb_hub_get_drvdata ( hub );
3257 
3258  /* Should never be called; this is a root hub */
3259  DBGC ( xhci, "XHCI %s-%d nonsensical CLEAR_TT for %s %s\n", xhci->name,
3260  port->address, ep->usb->name, usb_endpoint_name ( ep ) );
3261 
3262  return -ENOTSUP;
3263 }
An xHCI device.
Definition: xhci.h:1067
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
u8 port
Port number.
Definition: CIB_PRM.h:31
char name[32]
Name.
Definition: usb.h:710
const char * name
Name.
Definition: xhci.h:1073
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
struct usb_device * usb
USB device.
Definition: usb.h:391
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:933

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

◆ xhci_pch_fix()

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

Fix Intel PCH-specific quirks.

Parameters
xhcixHCI device
pciPCI device

Definition at line 3312 of file xhci.c.

3312  {
3313  struct xhci_pch *pch = &xhci->pch;
3314  uint32_t xusb2pr;
3315  uint32_t xusb2prm;
3317  uint32_t usb3prm;
3318 
3319  /* Enable SuperSpeed capability. Do this before rerouting
3320  * USB2 ports, so that USB3 devices connect at SuperSpeed.
3321  */
3323  pci_read_config_dword ( pci, XHCI_PCH_USB3PRM, &usb3prm );
3324  if ( usb3prm & ~usb3pssen ) {
3325  DBGC ( xhci, "XHCI %s enabling SuperSpeed on ports %08x\n",
3326  xhci->name, ( usb3prm & ~usb3pssen ) );
3327  }
3328  pch->usb3pssen = usb3pssen;
3329  usb3pssen |= usb3prm;
3331 
3332  /* Route USB2 ports from EHCI to xHCI */
3334  pci_read_config_dword ( pci, XHCI_PCH_XUSB2PRM, &xusb2prm );
3335  if ( xusb2prm & ~xusb2pr ) {
3336  DBGC ( xhci, "XHCI %s routing ports %08x from EHCI to xHCI\n",
3337  xhci->name, ( xusb2prm & ~xusb2pr ) );
3338  }
3339  pch->xusb2pr = xusb2pr;
3340  xusb2pr |= xusb2prm;
3342 }
#define XHCI_PCH_XUSB2PR
Intel PCH USB2 port routing register.
Definition: xhci.h:1030
#define DBGC(...)
Definition: compiler.h:505
Intel PCH quirk.
Definition: xhci.h:1019
struct xhci_pch pch
Intel PCH quirk.
Definition: xhci.h:1128
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
uint32_t xusb2pr
USB2 port routing register original value.
Definition: xhci.h:1021
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
Definition: xhci.h:1023
const char * name
Name.
Definition: xhci.h:1073
unsigned int uint32_t
Definition: stdint.h:12
#define XHCI_PCH_USB3PSSEN
Intel PCH SuperSpeed enable register.
Definition: xhci.h:1036
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define XHCI_PCH_USB3PRM
Intel PCH USB3 port routing mask register.
Definition: xhci.h:1039
#define XHCI_PCH_XUSB2PRM
Intel PCH USB2 port routing mask register.
Definition: xhci.h:1033

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

Referenced by xhci_probe().

◆ xhci_pch_undo()

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

Undo Intel PCH-specific quirk fixes.

Parameters
xhcixHCI device
pciPCI device

Definition at line 3350 of file xhci.c.

3350  {
3351  struct xhci_pch *pch = &xhci->pch;
3352 
3353  /* Restore USB2 port routing to original state */
3355 
3356  /* Restore SuperSpeed capability to original state */
3358 }
#define XHCI_PCH_XUSB2PR
Intel PCH USB2 port routing register.
Definition: xhci.h:1030
Intel PCH quirk.
Definition: xhci.h:1019
struct xhci_pch pch
Intel PCH quirk.
Definition: xhci.h:1128
uint32_t xusb2pr
USB2 port routing register original value.
Definition: xhci.h:1021
uint32_t usb3pssen
USB3 port SuperSpeed enable register original value.
Definition: xhci.h:1023
#define XHCI_PCH_USB3PSSEN
Intel PCH SuperSpeed enable register.
Definition: xhci.h:1036
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.

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

Referenced by xhci_probe(), and xhci_remove().

◆ xhci_probe()

static int xhci_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 3366 of file xhci.c.

3366  {
3367  struct xhci_device *xhci;
3368  struct usb_port *port;
3369  unsigned long bar_start;
3370  size_t bar_size;
3371  unsigned int i;
3372  int rc;
3373 
3374  /* Allocate and initialise structure */
3375  xhci = zalloc ( sizeof ( *xhci ) );
3376  if ( ! xhci ) {
3377  rc = -ENOMEM;
3378  goto err_alloc;
3379  }
3380  xhci->name = pci->dev.name;
3381  xhci->quirks = pci->id->driver_data;
3382 
3383  /* Fix up PCI device */
3384  adjust_pci_device ( pci );
3385 
3386  /* Map registers */
3387  bar_start = pci_bar_start ( pci, XHCI_BAR );
3388  bar_size = pci_bar_size ( pci, XHCI_BAR );
3389  xhci->regs = pci_ioremap ( pci, bar_start, bar_size );
3390  if ( ! xhci->regs ) {
3391  rc = -ENODEV;
3392  goto err_ioremap;
3393  }
3394 
3395  /* Initialise xHCI device */
3396  xhci_init ( xhci, xhci->regs );
3397 
3398  /* Configure DMA device */
3399  xhci->dma = &pci->dma;
3400  if ( xhci->addr64 )
3401  dma_set_mask_64bit ( xhci->dma );
3402 
3403  /* Initialise USB legacy support and claim ownership */
3404  xhci_legacy_init ( xhci );
3405  xhci_legacy_claim ( xhci );
3406 
3407  /* Fix Intel PCH-specific quirks, if applicable */
3408  if ( xhci->quirks & XHCI_PCH )
3409  xhci_pch_fix ( xhci, pci );
3410 
3411  /* Reset device */
3412  if ( ( rc = xhci_reset ( xhci ) ) != 0 )
3413  goto err_reset;
3414 
3415  /* Allocate USB bus */
3416  xhci->bus = alloc_usb_bus ( &pci->dev, xhci->ports, XHCI_MTU,
3417  &xhci_operations );
3418  if ( ! xhci->bus ) {
3419  rc = -ENOMEM;
3420  goto err_alloc_bus;
3421  }
3422  usb_bus_set_hostdata ( xhci->bus, xhci );
3423  usb_hub_set_drvdata ( xhci->bus->hub, xhci );
3424 
3425  /* Set port protocols */
3426  for ( i = 1 ; i <= xhci->ports ; i++ ) {
3427  port = usb_port ( xhci->bus->hub, i );
3428  port->protocol = xhci_port_protocol ( xhci, i );
3429  }
3430 
3431  /* Register USB bus */
3432  if ( ( rc = register_usb_bus ( xhci->bus ) ) != 0 )
3433  goto err_register;
3434 
3435  pci_set_drvdata ( pci, xhci );
3436  return 0;
3437 
3438  unregister_usb_bus ( xhci->bus );
3439  err_register:
3440  free_usb_bus ( xhci->bus );
3441  err_alloc_bus:
3442  xhci_reset ( xhci );
3443  err_reset:
3444  if ( xhci->quirks & XHCI_PCH )
3445  xhci_pch_undo ( xhci, pci );
3446  xhci_legacy_release ( xhci );
3447  iounmap ( xhci->regs );
3448  err_ioremap:
3449  free ( xhci );
3450  err_alloc:
3451  return rc;
3452 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_device dma
DMA device.
Definition: pci.h:210
unsigned int ports
Number of ports.
Definition: xhci.h:1091
An xHCI device.
Definition: xhci.h:1067
struct usb_bus * alloc_usb_bus(struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
Allocate USB bus.
Definition: usb.c:2076
void * regs
Registers.
Definition: xhci.h:1069
unsigned long driver_data
Arbitrary driver data.
Definition: pci.h:178
char name[40]
Name.
Definition: device.h:75
static __always_inline void dma_set_mask_64bit(struct dma_device *dma)
Set 64-bit addressable space mask.
Definition: dma.h:474
struct usb_bus * bus
USB bus.
Definition: xhci.h:1125
static void xhci_init(struct xhci_device *xhci, void *regs)
Initialise device.
Definition: xhci.c:264
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:154
struct device dev
Generic device.
Definition: pci.h:208
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1030
A USB port.
Definition: usb.h:798
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:359
#define ENOMEM
Not enough space.
Definition: errno.h:534
u8 port
Port number.
Definition: CIB_PRM.h:31
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2147
#define XHCI_MTU
Maximum transfer size.
Definition: xhci.h:28
#define XHCI_PCH
Intel PCH quirk flag.
Definition: xhci.h:1027
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
static void xhci_legacy_claim(struct xhci_device *xhci)
Claim ownership from BIOS.
Definition: xhci.c:564
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Find the size of a PCI BAR.
Definition: pciextra.c:92
const char * name
Name.
Definition: xhci.h:1073
#define ENODEV
No such device.
Definition: errno.h:509
#define XHCI_BAR
xHCI PCI BAR
Definition: xhci.h:31
int addr64
64-bit addressing capability
Definition: xhci.h:1094
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1136
static void xhci_pch_fix(struct xhci_device *xhci, struct pci_device *pci)
Fix Intel PCH-specific quirks.
Definition: xhci.c:3312
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2112
struct pci_device_id * id
Driver device ID.
Definition: pci.h:243
static void xhci_pch_undo(struct xhci_device *xhci, struct pci_device *pci)
Undo Intel PCH-specific quirk fixes.
Definition: xhci.c:3350
void iounmap(volatile const void *io_addr)
Unmap I/O address.
struct dma_device * dma
DMA device.
Definition: xhci.h:1071
static unsigned int xhci_port_protocol(struct xhci_device *xhci, unsigned int port)
Find port protocol.
Definition: xhci.c:699
struct usb_hub * hub
Root hub.
Definition: usb.h:974
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:922
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:945
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
static void xhci_legacy_init(struct xhci_device *xhci)
Initialise USB legacy support.
Definition: xhci.c:533
unsigned int quirks
Quirks.
Definition: xhci.h:1075
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2171
static struct usb_host_operations xhci_operations
USB host controller operations.
Definition: xhci.c:3273
static void xhci_legacy_release(struct xhci_device *xhci)
Release ownership back to BIOS.
Definition: xhci.c:611

References xhci_device::addr64, adjust_pci_device(), alloc_usb_bus(), xhci_device::bus, pci_device::dev, pci_device::dma, xhci_device::dma, dma_set_mask_64bit(), pci_device_id::driver_data, ENODEV, ENOMEM, free, free_usb_bus(), usb_bus::hub, pci_device::id, iounmap(), device::name, xhci_device::name, pci_bar_size(), pci_bar_start(), pci_ioremap(), pci_set_drvdata(), port, xhci_device::ports, xhci_device::quirks, rc, register_usb_bus(), xhci_device::regs, unregister_usb_bus(), usb_bus_set_hostdata(), usb_hub_set_drvdata(), usb_port(), XHCI_BAR, xhci_init(), xhci_legacy_claim(), xhci_legacy_init(), xhci_legacy_release(), XHCI_MTU, xhci_operations, XHCI_PCH, xhci_pch_fix(), xhci_pch_undo(), xhci_port_protocol(), xhci_reset(), and zalloc().

◆ xhci_remove()

static void xhci_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 3459 of file xhci.c.

3459  {
3460  struct xhci_device *xhci = pci_get_drvdata ( pci );
3461  struct usb_bus *bus = xhci->bus;
3462  uint16_t command;
3463 
3464  /* Some systems are observed to disable bus mastering on
3465  * Thunderbolt controllers before we get a chance to shut
3466  * down. Detect this and avoid attempting any DMA operations,
3467  * which are guaranteed to fail and may end up spuriously
3468  * completing after the operating system kernel starts up.
3469  */
3471  if ( ! ( command & PCI_COMMAND_MASTER ) ) {
3472  DBGC ( xhci, "XHCI %s DMA was disabled\n", xhci->name );
3473  xhci_fail ( xhci );
3474  }
3475 
3476  /* Unregister and free USB bus */
3477  unregister_usb_bus ( bus );
3478  free_usb_bus ( bus );
3479 
3480  /* Reset device and undo any PCH-specific fixes */
3481  xhci_reset ( xhci );
3482  if ( xhci->quirks & XHCI_PCH )
3483  xhci_pch_undo ( xhci, pci );
3484 
3485  /* Release ownership back to BIOS */
3486  xhci_legacy_release ( xhci );
3487 
3488  /* Unmap registers */
3489  iounmap ( xhci->regs );
3490 
3491  /* Free device */
3492  free ( xhci );
3493 }
unsigned short uint16_t
Definition: stdint.h:11
An xHCI device.
Definition: xhci.h:1067
void * regs
Registers.
Definition: xhci.h:1069
A command-line command.
Definition: command.h:9
#define DBGC(...)
Definition: compiler.h:505
struct usb_bus * bus
USB bus.
Definition: xhci.h:1125
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
#define PCI_COMMAND
PCI command.
Definition: pci.h:25
#define PCI_COMMAND_MASTER
Bus master.
Definition: pci.h:28
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2147
#define XHCI_PCH
Intel PCH quirk flag.
Definition: xhci.h:1027
static int xhci_fail(struct xhci_device *xhci)
Mark xHCI device as permanently failed.
Definition: xhci.c:1174
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
const char * name
Name.
Definition: xhci.h:1073
static int command
Definition: epic100.c:68
static int xhci_reset(struct xhci_device *xhci)
Reset xHCI device.
Definition: xhci.c:1136
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:369
static void xhci_pch_undo(struct xhci_device *xhci, struct pci_device *pci)
Undo Intel PCH-specific quirk fixes.
Definition: xhci.c:3350
void iounmap(volatile const void *io_addr)
Unmap I/O address.
unsigned int quirks
Quirks.
Definition: xhci.h:1075
A USB bus.
Definition: usb.h:951
uint8_t bus
Bus.
Definition: edd.h:14
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2171
static void xhci_legacy_release(struct xhci_device *xhci)
Release ownership back to BIOS.
Definition: xhci.c:611

References bus, xhci_device::bus, command, DBGC, free, free_usb_bus(), iounmap(), xhci_device::name, PCI_COMMAND, PCI_COMMAND_MASTER, pci_get_drvdata(), pci_read_config_word(), xhci_device::quirks, xhci_device::regs, unregister_usb_bus(), xhci_fail(), xhci_legacy_release(), XHCI_PCH, xhci_pch_undo(), and xhci_reset().

◆ xhci_shutdown()

static void xhci_shutdown ( int  booting)
static

Prepare for exit.

Parameters
bootingSystem is shutting down for OS boot

Definition at line 3517 of file xhci.c.

3517  {
3518  /* If we are shutting down to boot an OS, then prevent the
3519  * release of ownership back to BIOS.
3520  */
3521  xhci_legacy_prevent_release = booting;
3522 }
static int xhci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
Definition: xhci.c:526

References xhci_legacy_prevent_release.

◆ __startup_fn()

struct startup_fn xhci_startup __startup_fn ( STARTUP_LATE  )

Startup/shutdown function.

Variable Documentation

◆ __profiler

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

Message transfer profiler.

Transfer event profiler.

Event ring profiler.

Stream transfer profiler.

Definition at line 47 of file xhci.c.

◆ xhci_legacy_prevent_release

int xhci_legacy_prevent_release
static

Prevent the release of ownership back to BIOS.

Definition at line 526 of file xhci.c.

Referenced by xhci_legacy_release(), and xhci_shutdown().

◆ xhci_operations

struct usb_host_operations xhci_operations
static

USB host controller operations.

Definition at line 3273 of file xhci.c.

Referenced by xhci_probe().

◆ xhci_ids

struct pci_device_id xhci_ids[]
static
Initial value:
= {
PCI_ROM ( 0x8086, 0x9d2f, "xhci-skylake", "xHCI (Skylake)", ( XHCI_PCH | XHCI_BAD_PSIV ) ),
PCI_ROM ( 0x8086, 0xffff, "xhci-pch", "xHCI (Intel PCH)", XHCI_PCH ),
PCI_ROM ( 0xffff, 0xffff, "xhci", "xHCI", 0 ),
}
#define XHCI_BAD_PSIV
Invalid protocol speed ID values quirk.
Definition: xhci.h:1042
#define XHCI_PCH
Intel PCH quirk flag.
Definition: xhci.h:1027
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:303

XHCI PCI device IDs.

Definition at line 3496 of file xhci.c.

◆ __pci_driver

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

XHCI PCI driver.

Definition at line 3503 of file xhci.c.