iPXE
Macros | Functions | Variables
ehci.c File Reference

USB Enhanced Host Controller Interface (EHCI) driver. More...

#include <stdlib.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 "ehci.h"

Go to the source code of this file.

Macros

#define EIO_STATUS(status)   EUNIQ ( EINFO_EIO, ( ( (status) >> 2 ) & 0xf ) )
 Construct error code from transfer descriptor status. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void ehci_init (struct ehci_device *ehci, void *regs)
 Initialise device. More...
 
static unsigned int ehci_extended_capability (struct ehci_device *ehci, struct pci_device *pci, unsigned int id, unsigned int offset)
 Find extended capability. More...
 
static size_t ehci_align (size_t len)
 Calculate buffer alignment. More...
 
static int ehci_ctrl_reachable (struct ehci_device *ehci, void *ptr)
 Check control data structure reachability. More...
 
static __unused void ehci_dump (struct ehci_device *ehci)
 Dump host controller registers. More...
 
static void ehci_legacy_init (struct ehci_device *ehci, struct pci_device *pci)
 Initialise USB legacy support. More...
 
static void ehci_legacy_claim (struct ehci_device *ehci, struct pci_device *pci)
 Claim ownership from BIOS. More...
 
static void ehci_legacy_release (struct ehci_device *ehci, struct pci_device *pci)
 Release ownership back to BIOS. More...
 
static void ehci_poll_companions (struct ehci_device *ehci)
 Poll child companion controllers. More...
 
unsigned int ehci_companion (struct pci_device *pci)
 Locate EHCI companion controller. More...
 
static void ehci_run (struct ehci_device *ehci)
 Start EHCI device. More...
 
static int ehci_stop (struct ehci_device *ehci)
 Stop EHCI device. More...
 
static int ehci_reset (struct ehci_device *ehci)
 Reset EHCI device. More...
 
static int ehci_ring_alloc (struct ehci_device *ehci, struct ehci_ring *ring)
 Allocate transfer descriptor ring. More...
 
static void ehci_ring_free (struct ehci_ring *ring)
 Free transfer descriptor ring. More...
 
static int ehci_enqueue (struct ehci_device *ehci, struct ehci_ring *ring, struct io_buffer *iobuf, const struct ehci_transfer *xfer, unsigned int count)
 Enqueue transfer descriptors. More...
 
static struct io_bufferehci_dequeue (struct ehci_ring *ring)
 Dequeue a transfer descriptor. More...
 
static uint32_t ehci_link_qh (struct ehci_queue_head *queue)
 Get link value for a queue head. More...
 
static void ehci_async_schedule (struct ehci_device *ehci)
 (Re)build asynchronous schedule More...
 
static void ehci_async_add (struct ehci_endpoint *endpoint)
 Add endpoint to asynchronous schedule. More...
 
static int ehci_async_del (struct ehci_endpoint *endpoint)
 Remove endpoint from asynchronous schedule. More...
 
static void ehci_periodic_schedule (struct ehci_device *ehci)
 (Re)build periodic schedule More...
 
static void ehci_periodic_add (struct ehci_endpoint *endpoint)
 Add endpoint to periodic schedule. More...
 
static int ehci_periodic_del (struct ehci_endpoint *endpoint)
 Remove endpoint from periodic schedule. More...
 
static void ehci_schedule_add (struct ehci_endpoint *endpoint)
 Add endpoint to appropriate schedule. More...
 
static int ehci_schedule_del (struct ehci_endpoint *endpoint)
 Remove endpoint from appropriate schedule. More...
 
static uint32_t ehci_endpoint_characteristics (struct usb_endpoint *ep)
 Determine endpoint characteristics. More...
 
static uint32_t ehci_endpoint_capabilities (struct usb_endpoint *ep)
 Determine endpoint capabilities. More...
 
static void ehci_endpoint_update (struct usb_endpoint *ep)
 Update endpoint characteristics and capabilities. More...
 
static int ehci_endpoint_open (struct usb_endpoint *ep)
 Open endpoint. More...
 
static void ehci_endpoint_close (struct usb_endpoint *ep)
 Close endpoint. More...
 
static int ehci_endpoint_reset (struct usb_endpoint *ep)
 Reset endpoint. More...
 
static int ehci_endpoint_mtu (struct usb_endpoint *ep)
 Update MTU. More...
 
static int ehci_endpoint_message (struct usb_endpoint *ep, struct io_buffer *iobuf)
 Enqueue message transfer. More...
 
static unsigned int ehci_endpoint_count (size_t len, int zlp)
 Calculate number of transfer descriptors. More...
 
static int ehci_endpoint_stream (struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
 Enqueue stream transfer. More...
 
static void ehci_endpoint_poll (struct ehci_endpoint *endpoint)
 Poll for completions. More...
 
static int ehci_device_open (struct usb_device *usb)
 Open device. More...
 
static void ehci_device_close (struct usb_device *usb)
 Close device. More...
 
static int ehci_device_address (struct usb_device *usb)
 Assign device address. More...
 
static int ehci_hub_open (struct usb_hub *hub __unused)
 Open hub. More...
 
static void ehci_hub_close (struct usb_hub *hub __unused)
 Close hub. More...
 
static int ehci_root_open (struct usb_hub *hub)
 Open root hub. More...
 
static void ehci_root_close (struct usb_hub *hub)
 Close root hub. More...
 
static int ehci_root_enable (struct usb_hub *hub, struct usb_port *port)
 Enable port. More...
 
static int ehci_root_disable (struct usb_hub *hub, struct usb_port *port)
 Disable port. More...
 
static int ehci_root_speed (struct usb_hub *hub, struct usb_port *port)
 Update root hub port speed. More...
 
static int ehci_root_clear_tt (struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
 Clear transaction translator buffer. More...
 
static void ehci_root_poll (struct usb_hub *hub, struct usb_port *port)
 Poll for port status changes. More...
 
static int ehci_bus_open (struct usb_bus *bus)
 Open USB bus. More...
 
static void ehci_bus_close (struct usb_bus *bus)
 Close USB bus. More...
 
static void ehci_bus_poll (struct usb_bus *bus)
 Poll USB bus. More...
 
static int ehci_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void ehci_remove (struct pci_device *pci)
 Remove PCI device. More...
 
static void ehci_shutdown (int booting)
 Prepare for exit. More...
 
struct startup_fn ehci_startup __startup_fn (STARTUP_LATE)
 Startup/shutdown function. More...
 

Variables

static int ehci_legacy_prevent_release
 Prevent the release of ownership back to BIOS. More...
 
static struct usb_host_operations ehci_operations
 USB host controller operations. More...
 
static struct pci_device_id ehci_ids []
 EHCI PCI device IDs. More...
 
struct pci_driver ehci_driver __pci_driver
 EHCI PCI driver. More...
 

Detailed Description

USB Enhanced Host Controller Interface (EHCI) driver.

Definition in file ehci.c.

Macro Definition Documentation

◆ EIO_STATUS

#define EIO_STATUS (   status)    EUNIQ ( EINFO_EIO, ( ( (status) >> 2 ) & 0xf ) )

Construct error code from transfer descriptor status.

Parameters
statusTransfer descriptor status
Return values
rcError code

Bits 2-5 of the status code provide some indication as to the root cause of the error. We incorporate these into the error code as reported to usb_complete_err().

Definition at line 54 of file ehci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ehci_init()

static void ehci_init ( struct ehci_device ehci,
void *  regs 
)
static

Initialise device.

Parameters
ehciEHCI device
regsMMIO registers

Definition at line 69 of file ehci.c.

69  {
70  uint32_t hcsparams;
71  uint32_t hccparams;
72  size_t caplength;
73 
74  /* Locate capability and operational registers */
75  ehci->cap = regs;
76  caplength = readb ( ehci->cap + EHCI_CAP_CAPLENGTH );
77  ehci->op = ( ehci->cap + caplength );
78  DBGC2 ( ehci, "EHCI %s cap %08lx op %08lx\n", ehci->name,
79  virt_to_phys ( ehci->cap ), virt_to_phys ( ehci->op ) );
80 
81  /* Read structural parameters */
82  hcsparams = readl ( ehci->cap + EHCI_CAP_HCSPARAMS );
83  ehci->ports = EHCI_HCSPARAMS_PORTS ( hcsparams );
84  DBGC ( ehci, "EHCI %s has %d ports\n", ehci->name, ehci->ports );
85 
86  /* Read capability parameters 1 */
87  hccparams = readl ( ehci->cap + EHCI_CAP_HCCPARAMS );
88  ehci->addr64 = EHCI_HCCPARAMS_ADDR64 ( hccparams );
89  ehci->flsize = ( EHCI_HCCPARAMS_FLSIZE ( hccparams ) ?
91  ehci->eecp = EHCI_HCCPARAMS_EECP ( hccparams );
92  DBGC2 ( ehci, "EHCI %s %d-bit flsize %d\n", ehci->name,
93  ( ehci->addr64 ? 64 : 32 ), ehci->flsize );
94 }
unsigned int ports
Number of ports.
Definition: ehci.h:495
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
void * op
Operational registers.
Definition: ehci.h:492
#define EHCI_HCCPARAMS_ADDR64(params)
64-bit addressing capability
Definition: ehci.h:54
#define EHCI_CAP_CAPLENGTH
Capability register length.
Definition: ehci.h:39
#define EHCI_HCSPARAMS_PORTS(params)
Number of ports.
Definition: ehci.h:48
#define EHCI_HCCPARAMS_EECP(params)
EHCI extended capabilities pointer.
Definition: ehci.h:60
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#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
int addr64
64-bit addressing capability
Definition: ehci.h:497
void * cap
Capability registers.
Definition: ehci.h:490
unsigned int flsize
Frame list size.
Definition: ehci.h:499
#define EHCI_FLSIZE_SMALL
Smallest allowed frame list size.
Definition: ehci.h:105
const char * name
Name.
Definition: ehci.h:487
#define EHCI_HCCPARAMS_FLSIZE(params)
Programmable frame list flag.
Definition: ehci.h:57
#define EHCI_CAP_HCSPARAMS
Structural parameters.
Definition: ehci.h:45
unsigned int uint32_t
Definition: stdint.h:12
struct i386_regs regs
Definition: registers.h:15
#define DBGC2(...)
Definition: compiler.h:522
#define EHCI_CAP_HCCPARAMS
Capability parameters.
Definition: ehci.h:51
unsigned int eecp
EHCI extended capabilities offset.
Definition: ehci.h:501
#define EHCI_FLSIZE_DEFAULT
Default frame list size.
Definition: ehci.h:102

References ehci_device::addr64, ehci_device::cap, DBGC, DBGC2, ehci_device::eecp, EHCI_CAP_CAPLENGTH, EHCI_CAP_HCCPARAMS, EHCI_CAP_HCSPARAMS, EHCI_FLSIZE_DEFAULT, EHCI_FLSIZE_SMALL, EHCI_HCCPARAMS_ADDR64, EHCI_HCCPARAMS_EECP, EHCI_HCCPARAMS_FLSIZE, EHCI_HCSPARAMS_PORTS, ehci_device::flsize, ehci_device::name, ehci_device::op, ehci_device::ports, readb(), readl(), regs, and virt_to_phys().

Referenced by ehci_probe().

◆ ehci_extended_capability()

static unsigned int ehci_extended_capability ( struct ehci_device ehci,
struct pci_device pci,
unsigned int  id,
unsigned int  offset 
)
static

Find extended capability.

Parameters
ehciEHCI device
pciPCI 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 105 of file ehci.c.

108  {
109  uint32_t eecp;
110 
111  /* Locate the extended capability */
112  while ( 1 ) {
113 
114  /* Locate first or next capability as applicable */
115  if ( offset ) {
116  pci_read_config_dword ( pci, offset, &eecp );
117  offset = EHCI_EECP_NEXT ( eecp );
118  } else {
119  offset = ehci->eecp;
120  }
121  if ( ! offset )
122  return 0;
123 
124  /* Check if this is the requested capability */
125  pci_read_config_dword ( pci, offset, &eecp );
126  if ( EHCI_EECP_ID ( eecp ) == id )
127  return offset;
128  }
129 }
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_EECP_NEXT(eecp)
Next EHCI extended capability pointer.
Definition: ehci.h:66
unsigned int eecp
EHCI extended capabilities offset.
Definition: ehci.h:501
#define EHCI_EECP_ID(eecp)
EHCI extended capability ID.
Definition: ehci.h:63

References ehci_device::eecp, EHCI_EECP_ID, EHCI_EECP_NEXT, offset, and pci_read_config_dword().

Referenced by ehci_legacy_init().

◆ ehci_align()

static size_t ehci_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 EHCI_MIN_ALIGN and which must not cross a page boundary.

Definition at line 140 of file ehci.c.

140  {
141  size_t align;
142 
143  /* Align to own length (rounded up to a power of two) */
144  align = ( 1 << fls ( len - 1 ) );
145 
146  /* Round up to EHCI_MIN_ALIGN if needed */
147  if ( align < EHCI_MIN_ALIGN )
149 
150  return align;
151 }
static __always_inline void struct dma_mapping size_t size_t align
Definition: dma.h:222
#define EHCI_MIN_ALIGN
Minimum alignment required for data structures.
Definition: ehci.h:23
uint32_t len
Length.
Definition: ena.h:14
#define fls(x)
Find last (i.e.
Definition: strings.h:166

References align, EHCI_MIN_ALIGN, fls, and len.

Referenced by ehci_bus_open(), and ehci_ring_alloc().

◆ ehci_ctrl_reachable()

static int ehci_ctrl_reachable ( struct ehci_device ehci,
void *  ptr 
)
static

Check control data structure reachability.

Parameters
ehciEHCI device
ptrData structure pointer
Return values
rcReturn status code

Definition at line 160 of file ehci.c.

160  {
161  physaddr_t phys = virt_to_phys ( ptr );
163 
164  /* Always reachable in a 32-bit build */
165  if ( sizeof ( physaddr_t ) <= sizeof ( uint32_t ) )
166  return 0;
167 
168  /* Reachable only if control segment matches in a 64-bit build */
169  segment = ( ( ( uint64_t ) phys ) >> 32 );
170  if ( segment == ehci->ctrldssegment )
171  return 0;
172 
173  return -ENOTSUP;
174 }
uint16_t segment
Code segment.
Definition: librm.h:252
uint32_t ctrldssegment
Control data structure segment.
Definition: ehci.h:507
unsigned long long uint64_t
Definition: stdint.h:13
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static signed char phys[4]
Definition: epic100.c:88
unsigned int uint32_t
Definition: stdint.h:12
unsigned long physaddr_t
Definition: stdint.h:20

References ehci_device::ctrldssegment, ENOTSUP, phys, segment, and virt_to_phys().

Referenced by ehci_bus_open(), and ehci_ring_alloc().

◆ ehci_dump()

static __unused void ehci_dump ( struct ehci_device ehci)
static

Dump host controller registers.

Parameters
ehciEHCI device

Definition at line 188 of file ehci.c.

188  {
189  uint8_t caplength;
190  uint16_t hciversion;
191  uint32_t hcsparams;
192  uint32_t hccparams;
193  uint32_t usbcmd;
194  uint32_t usbsts;
195  uint32_t usbintr;
196  uint32_t frindex;
197  uint32_t ctrldssegment;
198  uint32_t periodiclistbase;
199  uint32_t asynclistaddr;
200  uint32_t configflag;
201 
202  /* Do nothing unless debugging is enabled */
203  if ( ! DBG_LOG )
204  return;
205 
206  /* Dump capability registers */
207  caplength = readb ( ehci->cap + EHCI_CAP_CAPLENGTH );
208  hciversion = readw ( ehci->cap + EHCI_CAP_HCIVERSION );
209  hcsparams = readl ( ehci->cap + EHCI_CAP_HCSPARAMS );
210  hccparams = readl ( ehci->cap + EHCI_CAP_HCCPARAMS );
211  DBGC ( ehci, "EHCI %s caplen %02x hciversion %04x hcsparams %08x "
212  "hccparams %08x\n", ehci->name, caplength, hciversion,
213  hcsparams, hccparams );
214 
215  /* Dump operational registers */
216  usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
217  usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
218  usbintr = readl ( ehci->op + EHCI_OP_USBINTR );
219  frindex = readl ( ehci->op + EHCI_OP_FRINDEX );
220  ctrldssegment = readl ( ehci->op + EHCI_OP_CTRLDSSEGMENT );
221  periodiclistbase = readl ( ehci->op + EHCI_OP_PERIODICLISTBASE );
222  asynclistaddr = readl ( ehci->op + EHCI_OP_ASYNCLISTADDR );
223  configflag = readl ( ehci->op + EHCI_OP_CONFIGFLAG );
224  DBGC ( ehci, "EHCI %s usbcmd %08x usbsts %08x usbint %08x frindx "
225  "%08x\n", ehci->name, usbcmd, usbsts, usbintr, frindex );
226  DBGC ( ehci, "EHCI %s ctrlds %08x period %08x asyncl %08x cfgflg "
227  "%08x\n", ehci->name, ctrldssegment, periodiclistbase,
228  asynclistaddr, configflag );
229 }
unsigned short uint16_t
Definition: stdint.h:11
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
void * op
Operational registers.
Definition: ehci.h:492
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
#define EHCI_CAP_CAPLENGTH
Capability register length.
Definition: ehci.h:39
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define EHCI_OP_USBCMD
USB command register.
Definition: ehci.h:87
void * cap
Capability registers.
Definition: ehci.h:490
const char * name
Name.
Definition: ehci.h:487
#define EHCI_OP_USBINTR
USB interrupt enable register.
Definition: ehci.h:156
#define EHCI_OP_CONFIGFLAG
Configure flag register.
Definition: ehci.h:171
#define EHCI_OP_ASYNCLISTADDR
Current asynchronous list address register.
Definition: ehci.h:168
unsigned char uint8_t
Definition: stdint.h:10
#define EHCI_CAP_HCSPARAMS
Structural parameters.
Definition: ehci.h:45
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_OP_CTRLDSSEGMENT
Control data structure segment register.
Definition: ehci.h:162
#define EHCI_OP_USBSTS
USB status register.
Definition: ehci.h:120
#define EHCI_OP_PERIODICLISTBASE
Periodic frame list base address register.
Definition: ehci.h:165
#define EHCI_CAP_HCCPARAMS
Capability parameters.
Definition: ehci.h:51
#define EHCI_CAP_HCIVERSION
Host controller interface version number.
Definition: ehci.h:42
#define EHCI_OP_FRINDEX
Frame index register.
Definition: ehci.h:159
#define DBG_LOG
Definition: compiler.h:317

References ehci_device::cap, DBG_LOG, DBGC, EHCI_CAP_CAPLENGTH, EHCI_CAP_HCCPARAMS, EHCI_CAP_HCIVERSION, EHCI_CAP_HCSPARAMS, EHCI_OP_ASYNCLISTADDR, EHCI_OP_CONFIGFLAG, EHCI_OP_CTRLDSSEGMENT, EHCI_OP_FRINDEX, EHCI_OP_PERIODICLISTBASE, EHCI_OP_USBCMD, EHCI_OP_USBINTR, EHCI_OP_USBSTS, ehci_device::name, ehci_device::op, readb(), readl(), and readw().

◆ ehci_legacy_init()

static void ehci_legacy_init ( struct ehci_device ehci,
struct pci_device pci 
)
static

Initialise USB legacy support.

Parameters
ehciEHCI device
pciPCI device

Definition at line 247 of file ehci.c.

248  {
249  unsigned int legacy;
250  uint8_t bios;
251 
252  /* Locate USB legacy support capability (if present) */
253  legacy = ehci_extended_capability ( ehci, pci, EHCI_EECP_ID_LEGACY, 0 );
254  if ( ! legacy ) {
255  /* Not an error; capability may not be present */
256  DBGC ( ehci, "EHCI %s has no USB legacy support capability\n",
257  ehci->name );
258  return;
259  }
260 
261  /* Check if legacy USB support is enabled */
262  pci_read_config_byte ( pci, ( legacy + EHCI_USBLEGSUP_BIOS ), &bios );
263  if ( ! ( bios & EHCI_USBLEGSUP_BIOS_OWNED ) ) {
264  /* Not an error; already owned by OS */
265  DBGC ( ehci, "EHCI %s USB legacy support already disabled\n",
266  ehci->name );
267  return;
268  }
269 
270  /* Record presence of USB legacy support capability */
271  ehci->legacy = legacy;
272 }
#define EHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
Definition: ehci.h:75
#define EHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition: ehci.h:72
#define DBGC(...)
Definition: compiler.h:505
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: ehci.h:504
const char * name
Name.
Definition: ehci.h:487
static unsigned int ehci_extended_capability(struct ehci_device *ehci, struct pci_device *pci, unsigned int id, unsigned int offset)
Find extended capability.
Definition: ehci.c:105
unsigned char uint8_t
Definition: stdint.h:10
#define EHCI_EECP_ID_LEGACY
USB legacy support extended capability.
Definition: ehci.h:69
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.

References DBGC, EHCI_EECP_ID_LEGACY, ehci_extended_capability(), EHCI_USBLEGSUP_BIOS, EHCI_USBLEGSUP_BIOS_OWNED, ehci_device::legacy, ehci_device::name, and pci_read_config_byte().

Referenced by ehci_probe().

◆ ehci_legacy_claim()

static void ehci_legacy_claim ( struct ehci_device ehci,
struct pci_device pci 
)
static

Claim ownership from BIOS.

Parameters
ehciEHCI device
pciPCI device

Definition at line 280 of file ehci.c.

281  {
282  unsigned int legacy = ehci->legacy;
283  uint32_t ctlsts;
284  uint8_t bios;
285  unsigned int i;
286 
287  /* Do nothing unless legacy support capability is present */
288  if ( ! legacy )
289  return;
290 
291  /* Dump original SMI usage */
292  pci_read_config_dword ( pci, ( legacy + EHCI_USBLEGSUP_CTLSTS ),
293  &ctlsts );
294  if ( ctlsts ) {
295  DBGC ( ehci, "EHCI %s BIOS using SMIs: %08x\n",
296  ehci->name, ctlsts );
297  }
298 
299  /* Claim ownership */
300  pci_write_config_byte ( pci, ( legacy + EHCI_USBLEGSUP_OS ),
302 
303  /* Wait for BIOS to release ownership */
304  for ( i = 0 ; i < EHCI_USBLEGSUP_MAX_WAIT_MS ; i++ ) {
305 
306  /* Check if BIOS has released ownership */
307  pci_read_config_byte ( pci, ( legacy + EHCI_USBLEGSUP_BIOS ),
308  &bios );
309  if ( ! ( bios & EHCI_USBLEGSUP_BIOS_OWNED ) ) {
310  DBGC ( ehci, "EHCI %s claimed ownership from BIOS\n",
311  ehci->name );
312  pci_read_config_dword ( pci, ( legacy +
314  &ctlsts );
315  if ( ctlsts ) {
316  DBGC ( ehci, "EHCI %s warning: BIOS retained "
317  "SMIs: %08x\n", ehci->name, ctlsts );
318  }
319  return;
320  }
321 
322  /* Delay */
323  mdelay ( 1 );
324  }
325 
326  /* BIOS did not release ownership. Claim it forcibly by
327  * disabling all SMIs.
328  */
329  DBGC ( ehci, "EHCI %s could not claim ownership from BIOS: forcibly "
330  "disabling SMIs\n", ehci->name );
331  pci_write_config_dword ( pci, ( legacy + EHCI_USBLEGSUP_CTLSTS ), 0 );
332 }
#define EHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
Definition: ehci.h:75
#define EHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition: ehci.h:72
#define DBGC(...)
Definition: compiler.h:505
#define EHCI_USBLEGSUP_CTLSTS
USB legacy support control/status.
Definition: ehci.h:84
#define EHCI_USBLEGSUP_MAX_WAIT_MS
Maximum time to wait for BIOS to release ownership.
Definition: ehci.h:437
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: ehci.h:504
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
const char * name
Name.
Definition: ehci.h:487
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_USBLEGSUP_OS_OWNED
USB legacy support OS ownership flag.
Definition: ehci.h:81
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define EHCI_USBLEGSUP_OS
USB legacy support OS owned semaphore.
Definition: ehci.h:78
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.

References DBGC, EHCI_USBLEGSUP_BIOS, EHCI_USBLEGSUP_BIOS_OWNED, EHCI_USBLEGSUP_CTLSTS, EHCI_USBLEGSUP_MAX_WAIT_MS, EHCI_USBLEGSUP_OS, EHCI_USBLEGSUP_OS_OWNED, ehci_device::legacy, mdelay(), ehci_device::name, pci_read_config_byte(), pci_read_config_dword(), pci_write_config_byte(), and pci_write_config_dword().

Referenced by ehci_probe().

◆ ehci_legacy_release()

static void ehci_legacy_release ( struct ehci_device ehci,
struct pci_device pci 
)
static

Release ownership back to BIOS.

Parameters
ehciEHCI device
pciPCI device

Definition at line 340 of file ehci.c.

341  {
342  unsigned int legacy = ehci->legacy;
343  uint32_t ctlsts;
344 
345  /* Do nothing unless legacy support capability is present */
346  if ( ! legacy )
347  return;
348 
349  /* Do nothing if releasing ownership is prevented */
351  DBGC ( ehci, "EHCI %s not releasing ownership to BIOS\n",
352  ehci->name );
353  return;
354  }
355 
356  /* Release ownership */
357  pci_write_config_byte ( pci, ( legacy + EHCI_USBLEGSUP_OS ), 0 );
358  DBGC ( ehci, "EHCI %s released ownership to BIOS\n", ehci->name );
359 
360  /* Dump restored SMI usage */
361  pci_read_config_dword ( pci, ( legacy + EHCI_USBLEGSUP_CTLSTS ),
362  &ctlsts );
363  DBGC ( ehci, "EHCI %s BIOS reclaimed SMIs: %08x\n",
364  ehci->name, ctlsts );
365 }
#define DBGC(...)
Definition: compiler.h:505
static int ehci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
Definition: ehci.c:239
#define EHCI_USBLEGSUP_CTLSTS
USB legacy support control/status.
Definition: ehci.h:84
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition: ehci.h:504
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
const char * name
Name.
Definition: ehci.h:487
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_USBLEGSUP_OS
USB legacy support OS owned semaphore.
Definition: ehci.h:78

References DBGC, ehci_legacy_prevent_release, EHCI_USBLEGSUP_CTLSTS, EHCI_USBLEGSUP_OS, ehci_device::legacy, ehci_device::name, pci_read_config_dword(), and pci_write_config_byte().

Referenced by ehci_probe(), and ehci_remove().

◆ ehci_poll_companions()

static void ehci_poll_companions ( struct ehci_device ehci)
static

Poll child companion controllers.

Parameters
ehciEHCI device

Definition at line 379 of file ehci.c.

379  {
380  struct usb_bus *bus;
381  struct device_description *desc;
382 
383  /* Poll any USB buses belonging to child companion controllers */
384  for_each_usb_bus ( bus ) {
385 
386  /* Get underlying devices description */
387  desc = &bus->dev->desc;
388 
389  /* Skip buses that are not PCI devices */
390  if ( desc->bus_type != BUS_TYPE_PCI )
391  continue;
392 
393  /* Skip buses that are not part of the same PCI device */
394  if ( PCI_FIRST_FUNC ( desc->location ) !=
395  PCI_FIRST_FUNC ( ehci->bus->dev->desc.location ) )
396  continue;
397 
398  /* Skip buses that are not UHCI or OHCI PCI devices */
399  if ( ( desc->class != PCI_CLASS ( PCI_CLASS_SERIAL,
402  ( desc->class != PCI_CLASS ( PCI_CLASS_SERIAL,
405  continue;
406 
407  /* Poll child companion controller bus */
408  DBGC2 ( ehci, "EHCI %s polling companion %s\n",
409  ehci->name, bus->name );
410  usb_poll ( bus );
411  }
412 }
struct usb_bus * bus
USB bus.
Definition: ehci.h:524
unsigned long class
Device class.
Definition: device.h:35
A hardware device description.
Definition: device.h:19
#define PCI_CLASS_SERIAL
Definition: Pci22.h:272
#define for_each_usb_bus(bus)
Iterate over all USB buses.
Definition: usb.h:1056
#define BUS_TYPE_PCI
PCI bus type.
Definition: device.h:43
struct device * dev
Underlying hardware device.
Definition: usb.h:955
#define PCI_FIRST_FUNC(busdevfn)
Definition: pci.h:268
#define PCI_CLASS(base, sub, progif)
Construct PCI class.
Definition: pci.h:147
const char * name
Name.
Definition: ehci.h:487
unsigned int location
Location.
Definition: device.h:29
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1051
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:278
#define PCI_CLASS_SERIAL_USB_OHCI
OHCI USB controller.
Definition: pci.h:134
unsigned int bus_type
Bus type.
Definition: device.h:24
#define DBGC2(...)
Definition: compiler.h:522
#define PCI_CLASS_SERIAL_USB_UHCI
UHCI USB controller.
Definition: pci.h:133
struct device_description desc
Device description.
Definition: device.h:79
A USB bus.
Definition: usb.h:951
uint8_t bus
Bus.
Definition: edd.h:14

References bus, ehci_device::bus, device_description::bus_type, BUS_TYPE_PCI, device_description::class, DBGC2, device::desc, usb_bus::dev, for_each_usb_bus, device_description::location, ehci_device::name, PCI_CLASS, PCI_CLASS_SERIAL, PCI_CLASS_SERIAL_USB, PCI_CLASS_SERIAL_USB_OHCI, PCI_CLASS_SERIAL_USB_UHCI, PCI_FIRST_FUNC, and usb_poll().

Referenced by ehci_root_enable().

◆ ehci_companion()

unsigned int ehci_companion ( struct pci_device pci)

Locate EHCI companion controller.

Parameters
pciPCI device
Return values
busdevfnEHCI companion controller bus:dev.fn (if any)

Definition at line 420 of file ehci.c.

420  {
421  struct pci_device tmp;
422  unsigned int busdevfn;
423  int rc;
424 
425  /* Look for an EHCI function on the same PCI device */
426  busdevfn = pci->busdevfn;
427  while ( ++busdevfn <= PCI_LAST_FUNC ( pci->busdevfn ) ) {
428  pci_init ( &tmp, busdevfn );
429  if ( ( rc = pci_read_config ( &tmp ) ) != 0 )
430  continue;
431  if ( tmp.class == PCI_CLASS ( PCI_CLASS_SERIAL,
434  return busdevfn;
435  }
436 
437  return 0;
438 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define PCI_CLASS_SERIAL
Definition: Pci22.h:272
#define PCI_CLASS(base, sub, progif)
Construct PCI class.
Definition: pci.h:147
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:278
A PCI device.
Definition: pci.h:191
uint8_t * tmp
Definition: entropy.h:156
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition: pci.c:177
#define PCI_CLASS_SERIAL_USB_EHCI
ECHI USB controller.
Definition: pci.h:135
#define PCI_LAST_FUNC(busdevfn)
Definition: pci.h:269
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:216
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:319

References pci_device::busdevfn, PCI_CLASS, PCI_CLASS_SERIAL, PCI_CLASS_SERIAL_USB, PCI_CLASS_SERIAL_USB_EHCI, pci_init(), PCI_LAST_FUNC, pci_read_config(), rc, and tmp.

◆ ehci_run()

static void ehci_run ( struct ehci_device ehci)
static

Start EHCI device.

Parameters
ehciEHCI device

Definition at line 452 of file ehci.c.

452  {
453  uint32_t usbcmd;
454 
455  /* Set run/stop bit */
456  usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
457  usbcmd &= ~EHCI_USBCMD_FLSIZE_MASK;
458  usbcmd |= ( EHCI_USBCMD_RUN | EHCI_USBCMD_FLSIZE ( ehci->flsize ) |
460  writel ( usbcmd, ehci->op + EHCI_OP_USBCMD );
461 }
void * op
Operational registers.
Definition: ehci.h:492
#define EHCI_USBCMD_RUN
Run/stop.
Definition: ehci.h:90
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define EHCI_OP_USBCMD
USB command register.
Definition: ehci.h:87
#define EHCI_USBCMD_FLSIZE(flsize)
Frame list size.
Definition: ehci.h:96
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
unsigned int flsize
Frame list size.
Definition: ehci.h:499
#define EHCI_USBCMD_ASYNC
Asynchronous schedule enable.
Definition: ehci.h:114
#define EHCI_USBCMD_PERIODIC
Periodic schedule enable.
Definition: ehci.h:111
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_USBCMD_FLSIZE_MASK
Frame list size mask.
Definition: ehci.h:99

References EHCI_OP_USBCMD, EHCI_USBCMD_ASYNC, EHCI_USBCMD_FLSIZE, EHCI_USBCMD_FLSIZE_MASK, EHCI_USBCMD_PERIODIC, EHCI_USBCMD_RUN, ehci_device::flsize, ehci_device::op, readl(), and writel().

Referenced by ehci_bus_open().

◆ ehci_stop()

static int ehci_stop ( struct ehci_device ehci)
static

Stop EHCI device.

Parameters
ehciEHCI device
Return values
rcReturn status code

Definition at line 469 of file ehci.c.

469  {
470  uint32_t usbcmd;
471  uint32_t usbsts;
472  unsigned int i;
473 
474  /* Clear run/stop bit */
475  usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
476  usbcmd &= ~( EHCI_USBCMD_RUN | EHCI_USBCMD_PERIODIC |
478  writel ( usbcmd, ehci->op + EHCI_OP_USBCMD );
479 
480  /* Wait for device to stop */
481  for ( i = 0 ; i < EHCI_STOP_MAX_WAIT_MS ; i++ ) {
482 
483  /* Check if device is stopped */
484  usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
485  if ( usbsts & EHCI_USBSTS_HCH )
486  return 0;
487 
488  /* Delay */
489  mdelay ( 1 );
490  }
491 
492  DBGC ( ehci, "EHCI %s timed out waiting for stop\n", ehci->name );
493  return -ETIMEDOUT;
494 }
void * op
Operational registers.
Definition: ehci.h:492
#define EHCI_USBCMD_RUN
Run/stop.
Definition: ehci.h:90
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define EHCI_OP_USBCMD
USB command register.
Definition: ehci.h:87
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define EHCI_USBSTS_HCH
Host controller halted.
Definition: ehci.h:147
const char * name
Name.
Definition: ehci.h:487
#define EHCI_USBCMD_ASYNC
Asynchronous schedule enable.
Definition: ehci.h:114
#define EHCI_USBCMD_PERIODIC
Periodic schedule enable.
Definition: ehci.h:111
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_OP_USBSTS
USB status register.
Definition: ehci.h:120
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
#define EHCI_STOP_MAX_WAIT_MS
Maximum time to wait for host controller to stop.
Definition: ehci.h:449

References DBGC, EHCI_OP_USBCMD, EHCI_OP_USBSTS, EHCI_STOP_MAX_WAIT_MS, EHCI_USBCMD_ASYNC, EHCI_USBCMD_PERIODIC, EHCI_USBCMD_RUN, EHCI_USBSTS_HCH, ETIMEDOUT, mdelay(), ehci_device::name, ehci_device::op, readl(), and writel().

Referenced by ehci_bus_close(), ehci_bus_open(), and ehci_reset().

◆ ehci_reset()

static int ehci_reset ( struct ehci_device ehci)
static

Reset EHCI device.

Parameters
ehciEHCI device
Return values
rcReturn status code

Definition at line 502 of file ehci.c.

502  {
503  uint32_t usbcmd;
504  unsigned int i;
505  int rc;
506 
507  /* The EHCI specification states that resetting a running
508  * device may result in undefined behaviour, so try stopping
509  * it first.
510  */
511  if ( ( rc = ehci_stop ( ehci ) ) != 0 ) {
512  /* Ignore errors and attempt to reset the device anyway */
513  }
514 
515  /* Reset device */
517 
518  /* Wait for reset to complete */
519  for ( i = 0 ; i < EHCI_RESET_MAX_WAIT_MS ; i++ ) {
520 
521  /* Check if reset is complete */
522  usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
523  if ( ! ( usbcmd & EHCI_USBCMD_HCRST ) )
524  return 0;
525 
526  /* Delay */
527  mdelay ( 1 );
528  }
529 
530  DBGC ( ehci, "EHCI %s timed out waiting for reset\n", ehci->name );
531  return -ETIMEDOUT;
532 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EHCI_USBCMD_HCRST
Host controller reset.
Definition: ehci.h:93
static int ehci_stop(struct ehci_device *ehci)
Stop EHCI device.
Definition: ehci.c:469
void * op
Operational registers.
Definition: ehci.h:492
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define EHCI_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
Definition: ehci.h:455
#define EHCI_OP_USBCMD
USB command register.
Definition: ehci.h:87
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: ehci.h:487
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 ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, EHCI_OP_USBCMD, EHCI_RESET_MAX_WAIT_MS, ehci_stop(), EHCI_USBCMD_HCRST, ETIMEDOUT, mdelay(), ehci_device::name, ehci_device::op, rc, readl(), and writel().

Referenced by ehci_probe(), and ehci_remove().

◆ ehci_ring_alloc()

static int ehci_ring_alloc ( struct ehci_device ehci,
struct ehci_ring ring 
)
static

Allocate transfer descriptor ring.

Parameters
ehciEHCI device
ringTransfer descriptor ring
Return values
rcReturn status code

Definition at line 548 of file ehci.c.

549  {
550  struct ehci_transfer_descriptor *desc;
552  unsigned int i;
553  size_t len;
554  uint32_t link;
555  int rc;
556 
557  /* Initialise structure */
558  memset ( ring, 0, sizeof ( *ring ) );
559 
560  /* Allocate I/O buffers */
561  ring->iobuf = zalloc ( EHCI_RING_COUNT * sizeof ( ring->iobuf[0] ) );
562  if ( ! ring->iobuf ) {
563  rc = -ENOMEM;
564  goto err_alloc_iobuf;
565  }
566 
567  /* Allocate queue head */
568  ring->head = malloc_phys ( sizeof ( *ring->head ),
569  ehci_align ( sizeof ( *ring->head ) ) );
570  if ( ! ring->head ) {
571  rc = -ENOMEM;
572  goto err_alloc_queue;
573  }
574  if ( ( rc = ehci_ctrl_reachable ( ehci, ring->head ) ) != 0 ) {
575  DBGC ( ehci, "EHCI %s queue head unreachable\n", ehci->name );
576  goto err_unreachable_queue;
577  }
578  memset ( ring->head, 0, sizeof ( *ring->head ) );
579 
580  /* Allocate transfer descriptors */
581  len = ( EHCI_RING_COUNT * sizeof ( ring->desc[0] ) );
582  ring->desc = malloc_phys ( len, sizeof ( ring->desc[0] ) );
583  if ( ! ring->desc ) {
584  rc = -ENOMEM;
585  goto err_alloc_desc;
586  }
587  memset ( ring->desc, 0, len );
588 
589  /* Initialise transfer descriptors */
590  for ( i = 0 ; i < EHCI_RING_COUNT ; i++ ) {
591  desc = &ring->desc[i];
592  if ( ( rc = ehci_ctrl_reachable ( ehci, desc ) ) != 0 ) {
593  DBGC ( ehci, "EHCI %s descriptor unreachable\n",
594  ehci->name );
595  goto err_unreachable_desc;
596  }
597  next = &ring->desc[ ( i + 1 ) % EHCI_RING_COUNT ];
598  link = virt_to_phys ( next );
599  desc->next = cpu_to_le32 ( link );
600  desc->alt = cpu_to_le32 ( link );
601  }
602 
603  /* Initialise queue head */
604  link = virt_to_phys ( &ring->desc[0] );
605  ring->head->cache.next = cpu_to_le32 ( link );
606 
607  return 0;
608 
609  err_unreachable_desc:
610  free_phys ( ring->desc, len );
611  err_alloc_desc:
612  err_unreachable_queue:
613  free_phys ( ring->head, sizeof ( *ring->head ) );
614  err_alloc_queue:
615  free ( ring->iobuf );
616  err_alloc_iobuf:
617  return rc;
618 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static size_t ehci_align(size_t len)
Calculate buffer alignment.
Definition: ehci.c:140
uint32_t next
Next descriptor address.
Definition: myson.h:18
#define DBGC(...)
Definition: compiler.h:505
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.h:62
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint32_t next
Next transfer descriptor.
Definition: ehci.h:231
struct ehci_queue_head * head
Queue head.
Definition: ehci.h:382
struct io_buffer ** iobuf
I/O buffers.
Definition: ehci.h:379
#define ENOMEM
Not enough space.
Definition: errno.h:534
uint32_t alt
Alternate next transfer descriptor.
Definition: ehci.h:233
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
struct ehci_transfer_descriptor cache
Transfer descriptor cache.
Definition: ehci.h:301
const char * name
Name.
Definition: ehci.h:487
#define cpu_to_le32(value)
Definition: byteswap.h:107
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
unsigned int uint32_t
Definition: stdint.h:12
uint32_t len
Length.
Definition: ena.h:14
static int ehci_ctrl_reachable(struct ehci_device *ehci, void *ptr)
Check control data structure reachability.
Definition: ehci.c:160
A transfer descriptor.
Definition: ehci.h:229
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: ehci.h:391
struct ehci_transfer_descriptor * desc
Transfer descriptors.
Definition: ehci.h:384
void * memset(void *dest, int character, size_t len) __nonnull

References ehci_transfer_descriptor::alt, ehci_queue_head::cache, cpu_to_le32, DBGC, ehci_ring::desc, ehci_align(), ehci_ctrl_reachable(), EHCI_RING_COUNT, ENOMEM, free, free_phys(), ehci_ring::head, ehci_ring::iobuf, len, link, malloc_phys(), memset(), ehci_device::name, next, ehci_transfer_descriptor::next, rc, virt_to_phys(), and zalloc().

Referenced by ehci_endpoint_open().

◆ ehci_ring_free()

static void ehci_ring_free ( struct ehci_ring ring)
static

Free transfer descriptor ring.

Parameters
ringTransfer descriptor ring

Definition at line 625 of file ehci.c.

625  {
626  unsigned int i;
627 
628  /* Sanity checks */
629  assert ( ehci_ring_fill ( ring ) == 0 );
630  for ( i = 0 ; i < EHCI_RING_COUNT ; i++ )
631  assert ( ring->iobuf[i] == NULL );
632 
633  /* Free transfer descriptors */
634  free_phys ( ring->desc, ( EHCI_RING_COUNT *
635  sizeof ( ring->desc[0] ) ) );
636 
637  /* Free queue head */
638  free_phys ( ring->head, sizeof ( *ring->head ) );
639 
640  /* Free I/O buffers */
641  free ( ring->iobuf );
642 }
struct ehci_queue_head * head
Queue head.
Definition: ehci.h:382
struct io_buffer ** iobuf
I/O buffers.
Definition: ehci.h:379
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static unsigned int ehci_ring_fill(struct ehci_ring *ring)
Calculate space used in transfer descriptor ring.
Definition: ehci.h:400
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: ehci.h:391
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ehci_transfer_descriptor * desc
Transfer descriptors.
Definition: ehci.h:384

References assert(), ehci_ring::desc, EHCI_RING_COUNT, ehci_ring_fill(), free, free_phys(), ehci_ring::head, ehci_ring::iobuf, and NULL.

Referenced by ehci_endpoint_close(), and ehci_endpoint_open().

◆ ehci_enqueue()

static int ehci_enqueue ( struct ehci_device ehci,
struct ehci_ring ring,
struct io_buffer iobuf,
const struct ehci_transfer xfer,
unsigned int  count 
)
static

Enqueue transfer descriptors.

Parameters
ehciEHCI device
ringTransfer descriptor ring
iobufI/O buffer
xfersTransfers
countNumber of transfers
Return values
rcReturn status code

Definition at line 654 of file ehci.c.

657  {
658  struct ehci_transfer_descriptor *desc;
660  void *data;
661  size_t len;
662  size_t offset;
663  size_t frag_len;
664  unsigned int toggle;
665  unsigned int index;
666  unsigned int i;
667 
668  /* Sanity check */
669  assert ( iobuf != NULL );
670  assert ( count > 0 );
671 
672  /* Fail if ring does not have sufficient space */
673  if ( ehci_ring_remaining ( ring ) < count )
674  return -ENOBUFS;
675 
676  /* Fail if any portion is unreachable */
677  for ( i = 0 ; i < count ; i++ ) {
678  if ( ! xfer[i].len )
679  continue;
680  phys = ( virt_to_phys ( xfer[i].data ) + xfer[i].len - 1 );
681  if ( ( phys > 0xffffffffUL ) && ( ! ehci->addr64 ) )
682  return -ENOTSUP;
683  }
684 
685  /* Enqueue each transfer, recording the I/O buffer with the last */
686  for ( ; count ; ring->prod++, xfer++ ) {
687 
688  /* Populate descriptor header */
689  index = ( ring->prod % EHCI_RING_COUNT );
690  desc = &ring->desc[index];
691  toggle = ( xfer->flags & EHCI_FL_TOGGLE );
692  assert ( xfer->len <= EHCI_LEN_MASK );
694  desc->len = cpu_to_le16 ( xfer->len | toggle );
695  desc->flags = ( xfer->flags | EHCI_FL_CERR_MAX );
696 
697  /* Populate buffer pointers */
698  data = xfer->data;
699  len = xfer->len;
700  for ( i = 0 ; len ; i++ ) {
701 
702  /* Calculate length of this fragment */
703  phys = virt_to_phys ( data );
704  offset = ( phys & ( EHCI_PAGE_ALIGN - 1 ) );
705  frag_len = ( EHCI_PAGE_ALIGN - offset );
706  if ( frag_len > len )
707  frag_len = len;
708 
709  /* Sanity checks */
710  assert ( ( i == 0 ) || ( offset == 0 ) );
711  assert ( i < ( sizeof ( desc->low ) /
712  sizeof ( desc->low[0] ) ) );
713 
714  /* Populate buffer pointer */
715  desc->low[i] = cpu_to_le32 ( phys );
716  if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
717  desc->high[i] =
718  cpu_to_le32 ( ((uint64_t) phys) >> 32 );
719  }
720 
721  /* Move to next fragment */
722  data += frag_len;
723  len -= frag_len;
724  }
725 
726  /* Ensure everything is valid before activating descriptor */
727  wmb();
728  desc->status = EHCI_STATUS_ACTIVE;
729 
730  /* Record I/O buffer against last ring index */
731  if ( --count == 0 )
732  ring->iobuf[index] = iobuf;
733  }
734 
735  return 0;
736 }
wmb()
uint32_t high[5]
Extended buffer pointers (high 32 bits)
Definition: ehci.h:243
#define EHCI_STATUS_ACTIVE
Active.
Definition: ehci.h:261
#define EHCI_FL_CERR_MAX
Error counter maximum value.
Definition: ehci.h:279
uint16_t len
Transfer length.
Definition: ehci.h:239
unsigned long long uint64_t
Definition: stdint.h:13
uint32_t low[5]
Buffer pointers (low 32 bits)
Definition: ehci.h:241
#define EHCI_LEN_MASK
Length mask.
Definition: ehci.h:285
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
struct io_buffer ** iobuf
I/O buffers.
Definition: ehci.h:379
static signed char phys[4]
Definition: epic100.c:88
int addr64
64-bit addressing capability
Definition: ehci.h:497
unsigned int prod
Producer counter.
Definition: ehci.h:371
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define EHCI_PAGE_ALIGN
Page-alignment required for some data structures.
Definition: ehci.h:33
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint8_t flags
Flags.
Definition: ehci.h:237
size_t len
Length.
Definition: ehci.h:468
static unsigned int ehci_ring_remaining(struct ehci_ring *ring)
Calculate space remaining in transfer descriptor ring.
Definition: ehci.h:415
unsigned int flags
Flags.
Definition: ehci.h:476
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_FL_TOGGLE
Set initial data toggle.
Definition: ehci.h:480
unsigned long physaddr_t
Definition: stdint.h:20
uint8_t status
Status.
Definition: ehci.h:235
uint32_t len
Length.
Definition: ena.h:14
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define EHCI_LEN_TOGGLE
Data toggle.
Definition: ehci.h:288
uint16_t count
Number of entries.
Definition: ena.h:22
#define cpu_to_le16(value)
Definition: byteswap.h:106
A transfer descriptor.
Definition: ehci.h:229
void * data
Data buffer.
Definition: ehci.h:466
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: ehci.h:391
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ehci_transfer_descriptor * desc
Transfer descriptors.
Definition: ehci.h:384

References ehci_device::addr64, assert(), count, cpu_to_le16, cpu_to_le32, data, ehci_transfer::data, ehci_ring::desc, EHCI_FL_CERR_MAX, EHCI_FL_TOGGLE, EHCI_LEN_MASK, EHCI_LEN_TOGGLE, EHCI_PAGE_ALIGN, EHCI_RING_COUNT, ehci_ring_remaining(), EHCI_STATUS_ACTIVE, ENOBUFS, ENOTSUP, ehci_transfer_descriptor::flags, ehci_transfer::flags, ehci_transfer_descriptor::high, index, ehci_ring::iobuf, len, ehci_transfer_descriptor::len, ehci_transfer::len, ehci_transfer_descriptor::low, NULL, offset, phys, ehci_ring::prod, ehci_transfer_descriptor::status, virt_to_phys(), and wmb().

Referenced by ehci_endpoint_message(), and ehci_endpoint_stream().

◆ ehci_dequeue()

static struct io_buffer* ehci_dequeue ( struct ehci_ring ring)
static

Dequeue a transfer descriptor.

Parameters
ringTransfer descriptor ring
Return values
iobufI/O buffer (or NULL)

Definition at line 744 of file ehci.c.

744  {
745  struct ehci_transfer_descriptor *desc;
746  struct io_buffer *iobuf;
747  unsigned int index = ( ring->cons % EHCI_RING_COUNT );
748 
749  /* Sanity check */
750  assert ( ehci_ring_fill ( ring ) > 0 );
751 
752  /* Mark descriptor as inactive (and not halted) */
753  desc = &ring->desc[index];
754  desc->status = 0;
755 
756  /* Retrieve I/O buffer */
757  iobuf = ring->iobuf[index];
758  ring->iobuf[index] = NULL;
759 
760  /* Update consumer counter */
761  ring->cons++;
762 
763  return iobuf;
764 }
unsigned int cons
Consumer counter.
Definition: ehci.h:373
struct io_buffer ** iobuf
I/O buffers.
Definition: ehci.h:379
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint8_t status
Status.
Definition: ehci.h:235
A transfer descriptor.
Definition: ehci.h:229
static unsigned int ehci_ring_fill(struct ehci_ring *ring)
Calculate space used in transfer descriptor ring.
Definition: ehci.h:400
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: ehci.h:391
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ehci_transfer_descriptor * desc
Transfer descriptors.
Definition: ehci.h:384
A persistent I/O buffer.
Definition: iobuf.h:33

References assert(), ehci_ring::cons, ehci_ring::desc, EHCI_RING_COUNT, ehci_ring_fill(), index, ehci_ring::iobuf, NULL, and ehci_transfer_descriptor::status.

Referenced by ehci_endpoint_close(), and ehci_endpoint_poll().

◆ ehci_link_qh()

static uint32_t ehci_link_qh ( struct ehci_queue_head queue)
inlinestatic

Get link value for a queue head.

Parameters
queueQueue head
Return values
linkLink value

Definition at line 779 of file ehci.c.

779  {
780 
781  return ( virt_to_phys ( queue ) | EHCI_LINK_TYPE_QH );
782 }
#define EHCI_LINK_TYPE_QH
Queue head type.
Definition: ehci.h:220
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint16_t queue
Queue ID.
Definition: ena.h:22

References EHCI_LINK_TYPE_QH, queue, and virt_to_phys().

Referenced by ehci_async_schedule(), and ehci_periodic_schedule().

◆ ehci_async_schedule()

static void ehci_async_schedule ( struct ehci_device ehci)
static

(Re)build asynchronous schedule

Parameters
ehciEHCI device

Definition at line 789 of file ehci.c.

789  {
790  struct ehci_endpoint *endpoint;
791  struct ehci_queue_head *queue;
792  uint32_t link;
793 
794  /* Build schedule in reverse order of execution. Provided
795  * that we only ever add or remove single endpoints, this can
796  * safely run concurrently with hardware execution of the
797  * schedule.
798  */
799  link = ehci_link_qh ( ehci->head );
800  list_for_each_entry_reverse ( endpoint, &ehci->async, schedule ) {
801  queue = endpoint->ring.head;
802  queue->link = cpu_to_le32 ( link );
803  wmb();
804  link = ehci_link_qh ( queue );
805  }
806  ehci->head->link = cpu_to_le32 ( link );
807  wmb();
808 }
wmb()
An EHCI endpoint.
Definition: ehci.h:528
struct ehci_queue_head * head
Queue head.
Definition: ehci.h:382
struct ehci_queue_head * head
Asynchronous queue head.
Definition: ehci.h:509
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
Definition: list.h:433
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
#define cpu_to_le32(value)
Definition: byteswap.h:107
A queue head.
Definition: ehci.h:291
static uint32_t ehci_link_qh(struct ehci_queue_head *queue)
Get link value for a queue head.
Definition: ehci.c:779
unsigned int uint32_t
Definition: stdint.h:12
uint32_t link
Horizontal link pointer.
Definition: ehci.h:293
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
uint16_t queue
Queue ID.
Definition: ena.h:22

References ehci_device::async, cpu_to_le32, ehci_link_qh(), ehci_ring::head, ehci_device::head, link, ehci_queue_head::link, list_for_each_entry_reverse, queue, ehci_endpoint::ring, and wmb().

Referenced by ehci_async_add(), ehci_async_del(), and ehci_bus_open().

◆ ehci_async_add()

static void ehci_async_add ( struct ehci_endpoint endpoint)
static

Add endpoint to asynchronous schedule.

Parameters
endpointEndpoint

Definition at line 815 of file ehci.c.

815  {
816  struct ehci_device *ehci = endpoint->ehci;
817 
818  /* Add to end of schedule */
819  list_add_tail ( &endpoint->schedule, &ehci->async );
820 
821  /* Rebuild schedule */
822  ehci_async_schedule ( ehci );
823 }
struct list_head schedule
Endpoint schedule.
Definition: ehci.h:536
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
static void ehci_async_schedule(struct ehci_device *ehci)
(Re)build asynchronous schedule
Definition: ehci.c:789
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
An EHCI device.
Definition: ehci.h:483

References ehci_device::async, ehci_endpoint::ehci, ehci_async_schedule(), list_add_tail, and ehci_endpoint::schedule.

Referenced by ehci_schedule_add().

◆ ehci_async_del()

static int ehci_async_del ( struct ehci_endpoint endpoint)
static

Remove endpoint from asynchronous schedule.

Parameters
endpointEndpoint
Return values
rcReturn status code

Definition at line 831 of file ehci.c.

831  {
832  struct ehci_device *ehci = endpoint->ehci;
833  uint32_t usbcmd;
834  uint32_t usbsts;
835  unsigned int i;
836 
837  /* Remove from schedule */
838  list_check_contains_entry ( endpoint, &ehci->async, schedule );
839  list_del ( &endpoint->schedule );
840 
841  /* Rebuild schedule */
842  ehci_async_schedule ( ehci );
843 
844  /* Request notification when asynchronous schedule advances */
845  usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
846  usbcmd |= EHCI_USBCMD_ASYNC_ADVANCE;
847  writel ( usbcmd, ehci->op + EHCI_OP_USBCMD );
848 
849  /* Wait for asynchronous schedule to advance */
850  for ( i = 0 ; i < EHCI_ASYNC_ADVANCE_MAX_WAIT_MS ; i++ ) {
851 
852  /* Check for asynchronous schedule advancing */
853  usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
854  if ( usbsts & EHCI_USBSTS_ASYNC_ADVANCE ) {
855  usbsts &= ~EHCI_USBSTS_CHANGE;
856  usbsts |= EHCI_USBSTS_ASYNC_ADVANCE;
857  writel ( usbsts, ehci->op + EHCI_OP_USBSTS );
858  return 0;
859  }
860 
861  /* Delay */
862  mdelay ( 1 );
863  }
864 
865  /* Bad things will probably happen now */
866  DBGC ( ehci, "EHCI %s timed out waiting for asynchronous schedule "
867  "to advance\n", ehci->name );
868  return -ETIMEDOUT;
869 }
#define EHCI_USBCMD_ASYNC_ADVANCE
Asyncchronous schedule advance doorbell.
Definition: ehci.h:117
void * op
Operational registers.
Definition: ehci.h:492
#define EHCI_USBSTS_CHANGE
USB status change mask.
Definition: ehci.h:150
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define EHCI_USBSTS_ASYNC_ADVANCE
Asynchronous schedule advanced.
Definition: ehci.h:138
struct list_head schedule
Endpoint schedule.
Definition: ehci.h:536
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define EHCI_OP_USBCMD
USB command register.
Definition: ehci.h:87
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
#define EHCI_ASYNC_ADVANCE_MAX_WAIT_MS
Maximum time to wait for asynchronous schedule to advance.
Definition: ehci.h:443
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: ehci.h:487
unsigned int uint32_t
Definition: stdint.h:12
static void ehci_async_schedule(struct ehci_device *ehci)
(Re)build asynchronous schedule
Definition: ehci.c:789
#define EHCI_OP_USBSTS
USB status register.
Definition: ehci.h:120
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition: list.h:522
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
An EHCI device.
Definition: ehci.h:483

References ehci_device::async, DBGC, ehci_endpoint::ehci, EHCI_ASYNC_ADVANCE_MAX_WAIT_MS, ehci_async_schedule(), EHCI_OP_USBCMD, EHCI_OP_USBSTS, EHCI_USBCMD_ASYNC_ADVANCE, EHCI_USBSTS_ASYNC_ADVANCE, EHCI_USBSTS_CHANGE, ETIMEDOUT, list_check_contains_entry, list_del, mdelay(), ehci_device::name, ehci_device::op, readl(), ehci_endpoint::schedule, and writel().

Referenced by ehci_schedule_del().

◆ ehci_periodic_schedule()

static void ehci_periodic_schedule ( struct ehci_device ehci)
static

(Re)build periodic schedule

Parameters
ehciEHCI device

Definition at line 876 of file ehci.c.

876  {
877  struct ehci_endpoint *endpoint;
878  struct ehci_queue_head *queue;
879  uint32_t link;
880  unsigned int frames;
881  unsigned int max_interval;
882  unsigned int i;
883 
884  /* Build schedule in reverse order of execution. Provided
885  * that we only ever add or remove single endpoints, this can
886  * safely run concurrently with hardware execution of the
887  * schedule.
888  */
889  DBGCP ( ehci, "EHCI %s periodic schedule: ", ehci->name );
891  list_for_each_entry_reverse ( endpoint, &ehci->periodic, schedule ) {
892  queue = endpoint->ring.head;
893  queue->link = cpu_to_le32 ( link );
894  wmb();
895  DBGCP ( ehci, "%s%d",
896  ( ( link == EHCI_LINK_TERMINATE ) ? "" : "<-" ),
897  endpoint->ep->interval );
898  link = ehci_link_qh ( queue );
899  }
900  DBGCP ( ehci, "\n" );
901 
902  /* Populate periodic frame list */
903  DBGCP ( ehci, "EHCI %s periodic frame list:", ehci->name );
904  frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
905  for ( i = 0 ; i < frames ; i++ ) {
906 
907  /* Calculate maximum interval (in microframes) which
908  * may appear as part of this frame list.
909  */
910  if ( i == 0 ) {
911  /* Start of list: include all endpoints */
912  max_interval = -1U;
913  } else {
914  /* Calculate highest power-of-two frame interval */
915  max_interval = ( 1 << ( ffs ( i ) - 1 ) );
916  /* Convert to microframes */
917  max_interval <<= 3;
918  /* Round up to nearest 2^n-1 */
919  max_interval = ( ( max_interval << 1 ) - 1 );
920  }
921 
922  /* Find first endpoint in schedule satisfying this
923  * maximum interval constraint.
924  */
926  list_for_each_entry ( endpoint, &ehci->periodic, schedule ) {
927  if ( endpoint->ep->interval <= max_interval ) {
928  queue = endpoint->ring.head;
929  link = ehci_link_qh ( queue );
930  DBGCP ( ehci, " %d:%d",
931  i, endpoint->ep->interval );
932  break;
933  }
934  }
935  ehci->frame[i].link = cpu_to_le32 ( link );
936  }
937  wmb();
938  DBGCP ( ehci, "\n" );
939 }
wmb()
#define EHCI_PERIODIC_FRAMES(flsize)
Number of elements in frame list.
Definition: ehci.h:108
struct list_head periodic
Periodic schedule.
Definition: ehci.h:521
An EHCI endpoint.
Definition: ehci.h:528
uint32_t link
First queue head.
Definition: ehci.h:225
struct ehci_queue_head * head
Queue head.
Definition: ehci.h:382
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
Definition: list.h:433
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
unsigned int flsize
Frame list size.
Definition: ehci.h:499
const char * name
Name.
Definition: ehci.h:487
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
#define cpu_to_le32(value)
Definition: byteswap.h:107
A queue head.
Definition: ehci.h:291
static uint32_t ehci_link_qh(struct ehci_queue_head *queue)
Get link value for a queue head.
Definition: ehci.c:779
struct ehci_periodic_frame * frame
Periodic frame list.
Definition: ehci.h:511
unsigned int uint32_t
Definition: stdint.h:12
#define ffs(x)
Find first (i.e.
Definition: strings.h:140
#define EHCI_LINK_TERMINATE
List terminator.
Definition: ehci.h:214
unsigned int interval
Interval (in microframes)
Definition: usb.h:401
#define DBGCP(...)
Definition: compiler.h:539
uint16_t queue
Queue ID.
Definition: ena.h:22

References cpu_to_le32, DBGCP, ehci_link_qh(), EHCI_LINK_TERMINATE, EHCI_PERIODIC_FRAMES, ehci_endpoint::ep, ffs, ehci_device::flsize, ehci_device::frame, ehci_ring::head, usb_endpoint::interval, link, ehci_periodic_frame::link, list_for_each_entry, list_for_each_entry_reverse, ehci_device::name, ehci_device::periodic, queue, ehci_endpoint::ring, and wmb().

Referenced by ehci_bus_open(), ehci_periodic_add(), and ehci_periodic_del().

◆ ehci_periodic_add()

static void ehci_periodic_add ( struct ehci_endpoint endpoint)
static

Add endpoint to periodic schedule.

Parameters
endpointEndpoint

Definition at line 946 of file ehci.c.

946  {
947  struct ehci_device *ehci = endpoint->ehci;
948  struct ehci_endpoint *before;
949  unsigned int interval = endpoint->ep->interval;
950 
951  /* Find first endpoint with a smaller interval */
952  list_for_each_entry ( before, &ehci->periodic, schedule ) {
953  if ( before->ep->interval < interval )
954  break;
955  }
956  list_add_tail ( &endpoint->schedule, &before->schedule );
957 
958  /* Rebuild schedule */
960 }
struct list_head periodic
Periodic schedule.
Definition: ehci.h:521
An EHCI endpoint.
Definition: ehci.h:528
struct list_head schedule
Endpoint schedule.
Definition: ehci.h:536
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
unsigned int interval
Interval (in microframes)
Definition: usb.h:401
static void ehci_periodic_schedule(struct ehci_device *ehci)
(Re)build periodic schedule
Definition: ehci.c:876
An EHCI device.
Definition: ehci.h:483

References ehci_endpoint::ehci, ehci_periodic_schedule(), ehci_endpoint::ep, usb_endpoint::interval, list_add_tail, list_for_each_entry, ehci_device::periodic, and ehci_endpoint::schedule.

Referenced by ehci_schedule_add().

◆ ehci_periodic_del()

static int ehci_periodic_del ( struct ehci_endpoint endpoint)
static

Remove endpoint from periodic schedule.

Parameters
endpointEndpoint
Return values
rcReturn status code

Definition at line 968 of file ehci.c.

968  {
969  struct ehci_device *ehci = endpoint->ehci;
970 
971  /* Remove from schedule */
972  list_check_contains_entry ( endpoint, &ehci->periodic, schedule );
973  list_del ( &endpoint->schedule );
974 
975  /* Rebuild schedule */
976  ehci_periodic_schedule ( ehci );
977 
978  /* Delay for a whole USB frame (with a 100% safety margin) */
979  mdelay ( 2 );
980 
981  return 0;
982 }
struct list_head periodic
Periodic schedule.
Definition: ehci.h:521
struct list_head schedule
Endpoint schedule.
Definition: ehci.h:536
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition: list.h:522
static void ehci_periodic_schedule(struct ehci_device *ehci)
(Re)build periodic schedule
Definition: ehci.c:876
An EHCI device.
Definition: ehci.h:483

References ehci_endpoint::ehci, ehci_periodic_schedule(), list_check_contains_entry, list_del, mdelay(), ehci_device::periodic, and ehci_endpoint::schedule.

Referenced by ehci_schedule_del().

◆ ehci_schedule_add()

static void ehci_schedule_add ( struct ehci_endpoint endpoint)
static

Add endpoint to appropriate schedule.

Parameters
endpointEndpoint

Definition at line 989 of file ehci.c.

989  {
990  struct usb_endpoint *ep = endpoint->ep;
991  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
992 
994  ehci_periodic_add ( endpoint );
995  } else {
996  ehci_async_add ( endpoint );
997  }
998 }
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:266
uint8_t attr
Type and attributes.
Definition: librm.h:256
A USB endpoint.
Definition: usb.h:389
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
static void ehci_periodic_add(struct ehci_endpoint *endpoint)
Add endpoint to periodic schedule.
Definition: ehci.c:946
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:278
static void ehci_async_add(struct ehci_endpoint *endpoint)
Add endpoint to asynchronous schedule.
Definition: ehci.c:815
unsigned int attributes
Attributes.
Definition: usb.h:395

References attr, usb_endpoint::attributes, ehci_async_add(), ehci_periodic_add(), ehci_endpoint::ep, USB_ENDPOINT_ATTR_INTERRUPT, and USB_ENDPOINT_ATTR_TYPE_MASK.

Referenced by ehci_endpoint_open().

◆ ehci_schedule_del()

static int ehci_schedule_del ( struct ehci_endpoint endpoint)
static

Remove endpoint from appropriate schedule.

Parameters
endpointEndpoint
Return values
rcReturn status code

Definition at line 1006 of file ehci.c.

1006  {
1007  struct usb_endpoint *ep = endpoint->ep;
1008  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1009 
1010  if ( attr == USB_ENDPOINT_ATTR_INTERRUPT ) {
1011  return ehci_periodic_del ( endpoint );
1012  } else {
1013  return ehci_async_del ( endpoint );
1014  }
1015 }
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:266
uint8_t attr
Type and attributes.
Definition: librm.h:256
A USB endpoint.
Definition: usb.h:389
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:278
static int ehci_periodic_del(struct ehci_endpoint *endpoint)
Remove endpoint from periodic schedule.
Definition: ehci.c:968
unsigned int attributes
Attributes.
Definition: usb.h:395
static int ehci_async_del(struct ehci_endpoint *endpoint)
Remove endpoint from asynchronous schedule.
Definition: ehci.c:831

References attr, usb_endpoint::attributes, ehci_async_del(), ehci_periodic_del(), ehci_endpoint::ep, USB_ENDPOINT_ATTR_INTERRUPT, and USB_ENDPOINT_ATTR_TYPE_MASK.

Referenced by ehci_endpoint_close().

◆ ehci_endpoint_characteristics()

static uint32_t ehci_endpoint_characteristics ( struct usb_endpoint ep)
static

Determine endpoint characteristics.

Parameters
epUSB endpoint
Return values
chrEndpoint characteristics

Definition at line 1030 of file ehci.c.

1030  {
1031  struct usb_device *usb = ep->usb;
1032  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1033  uint32_t chr;
1034 
1035  /* Determine basic characteristics */
1036  chr = ( EHCI_CHR_ADDRESS ( usb->address ) |
1038  EHCI_CHR_MAX_LEN ( ep->mtu ) );
1039 
1040  /* Control endpoints require manual control of the data toggle */
1042  chr |= EHCI_CHR_TOGGLE;
1043 
1044  /* Determine endpoint speed */
1045  if ( usb->speed == USB_SPEED_HIGH ) {
1046  chr |= EHCI_CHR_EPS_HIGH;
1047  } else {
1048  if ( usb->speed == USB_SPEED_FULL ) {
1049  chr |= EHCI_CHR_EPS_FULL;
1050  } else {
1051  chr |= EHCI_CHR_EPS_LOW;
1052  }
1054  chr |= EHCI_CHR_CONTROL;
1055  }
1056 
1057  return chr;
1058 }
#define EHCI_CHR_CONTROL
Control endpoint flag.
Definition: ehci.h:332
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:266
#define EHCI_CHR_TOGGLE
Explicit data toggles.
Definition: ehci.h:323
uint8_t attr
Type and attributes.
Definition: librm.h:256
unsigned int address
Device address, if assigned.
Definition: usb.h:718
unsigned int speed
Device speed.
Definition: usb.h:714
#define EHCI_CHR_ENDPOINT(address)
Endpoint number.
Definition: ehci.h:308
A USB device.
Definition: usb.h:708
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_CHR_MAX_LEN(len)
Maximum packet length.
Definition: ehci.h:329
size_t mtu
Maximum transfer size.
Definition: usb.h:397
#define EHCI_CHR_ADDRESS(address)
Device address.
Definition: ehci.h:305
#define EHCI_CHR_EPS_FULL
Full-speed endpoint.
Definition: ehci.h:314
#define EHCI_CHR_EPS_HIGH
High-speed endpoint.
Definition: ehci.h:320
High speed (480Mbps)
Definition: usb.h:52
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:730
#define EHCI_CHR_EPS_LOW
Low-speed endpoint.
Definition: ehci.h:317
#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 attributes
Attributes.
Definition: usb.h:395
Full speed (12Mbps)
Definition: usb.h:50
unsigned int address
Endpoint address.
Definition: usb.h:393

References usb_endpoint::address, usb_device::address, attr, usb_endpoint::attributes, EHCI_CHR_ADDRESS, EHCI_CHR_CONTROL, EHCI_CHR_ENDPOINT, EHCI_CHR_EPS_FULL, EHCI_CHR_EPS_HIGH, EHCI_CHR_EPS_LOW, EHCI_CHR_MAX_LEN, EHCI_CHR_TOGGLE, usb_device::ep, usb_endpoint::mtu, usb_device::speed, usb_endpoint::usb, USB_ENDPOINT_ATTR_CONTROL, USB_ENDPOINT_ATTR_TYPE_MASK, USB_SPEED_FULL, and USB_SPEED_HIGH.

Referenced by ehci_endpoint_update().

◆ ehci_endpoint_capabilities()

static uint32_t ehci_endpoint_capabilities ( struct usb_endpoint ep)
static

Determine endpoint capabilities.

Parameters
epUSB endpoint
Return values
capEndpoint capabilities

Definition at line 1066 of file ehci.c.

1066  {
1067  struct usb_device *usb = ep->usb;
1068  struct usb_port *tt = usb_transaction_translator ( usb );
1069  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1070  uint32_t cap;
1071  unsigned int i;
1072 
1073  /* Determine basic capabilities */
1074  cap = EHCI_CAP_MULT ( ep->burst + 1 );
1075 
1076  /* Determine interrupt schedule mask, if applicable */
1077  if ( ( attr == USB_ENDPOINT_ATTR_INTERRUPT ) &&
1078  ( ( ep->interval != 0 ) /* avoid infinite loop */ ) ) {
1079  for ( i = 0 ; i < 8 /* microframes per frame */ ;
1080  i += ep->interval ) {
1081  cap |= EHCI_CAP_INTR_SCHED ( i );
1082  }
1083  }
1084 
1085  /* Set transaction translator hub address and port, if applicable */
1086  if ( tt ) {
1087  assert ( tt->hub->usb );
1088  cap |= ( EHCI_CAP_TT_HUB ( tt->hub->usb->address ) |
1089  EHCI_CAP_TT_PORT ( tt->address ) );
1092  }
1093 
1094  return cap;
1095 }
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:266
#define EHCI_CAP_TT_HUB(address)
Transaction translator hub address.
Definition: ehci.h:360
uint8_t attr
Type and attributes.
Definition: librm.h:256
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:820
unsigned int address
Device address, if assigned.
Definition: usb.h:718
#define EHCI_CAP_SPLIT_SCHED_DEFAULT
Default split completion schedule mask.
Definition: ehci.h:354
A USB port.
Definition: usb.h:798
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:832
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int burst
Maximum burst size.
Definition: usb.h:399
#define EHCI_CAP_MULT(mult)
High-bandwidth pipe multiplier.
Definition: ehci.h:366
A USB device.
Definition: usb.h:708
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:278
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_CAP_TT_PORT(port)
Transaction translator port number.
Definition: ehci.h:363
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
Definition: usb.c:2302
unsigned int address
Port address.
Definition: usb.h:802
struct usb_hub * hub
USB hub.
Definition: usb.h:800
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:730
unsigned int interval
Interval (in microframes)
Definition: usb.h:401
struct usb_device * usb
USB device.
Definition: usb.h:391
#define EHCI_CAP_INTR_SCHED(uframe)
Interrupt schedule mask.
Definition: ehci.h:335
unsigned int attributes
Attributes.
Definition: usb.h:395

References usb_device::address, usb_port::address, assert(), attr, usb_endpoint::attributes, usb_endpoint::burst, EHCI_CAP_INTR_SCHED, EHCI_CAP_MULT, EHCI_CAP_SPLIT_SCHED_DEFAULT, EHCI_CAP_TT_HUB, EHCI_CAP_TT_PORT, usb_device::ep, usb_port::hub, usb_endpoint::interval, usb_endpoint::usb, usb_port::usb, usb_hub::usb, USB_ENDPOINT_ATTR_INTERRUPT, USB_ENDPOINT_ATTR_TYPE_MASK, and usb_transaction_translator().

Referenced by ehci_endpoint_update().

◆ ehci_endpoint_update()

static void ehci_endpoint_update ( struct usb_endpoint ep)
static

Update endpoint characteristics and capabilities.

Parameters
epUSB endpoint

Definition at line 1102 of file ehci.c.

1102  {
1103  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1104  struct ehci_queue_head *head;
1105 
1106  /* Update queue characteristics and capabilities */
1107  head = endpoint->ring.head;
1109  head->cap = cpu_to_le32 ( ehci_endpoint_capabilities ( ep ) );
1110 }
static uint32_t ehci_endpoint_capabilities(struct usb_endpoint *ep)
Determine endpoint capabilities.
Definition: ehci.c:1066
An EHCI endpoint.
Definition: ehci.h:528
uint8_t head
Head number.
Definition: int13.h:34
struct ehci_queue_head * head
Queue head.
Definition: ehci.h:382
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
#define cpu_to_le32(value)
Definition: byteswap.h:107
A queue head.
Definition: ehci.h:291
static uint32_t ehci_endpoint_characteristics(struct usb_endpoint *ep)
Determine endpoint characteristics.
Definition: ehci.c:1030
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572

References cpu_to_le32, ehci_endpoint_capabilities(), ehci_endpoint_characteristics(), ehci_endpoint::ep, head, ehci_ring::head, ehci_endpoint::ring, and usb_endpoint_get_hostdata().

Referenced by ehci_device_address(), ehci_endpoint_mtu(), and ehci_endpoint_open().

◆ ehci_endpoint_open()

static int ehci_endpoint_open ( struct usb_endpoint ep)
static

Open endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 1118 of file ehci.c.

1118  {
1119  struct usb_device *usb = ep->usb;
1120  struct ehci_device *ehci = usb_get_hostdata ( usb );
1121  struct ehci_endpoint *endpoint;
1122  int rc;
1123 
1124  /* Allocate and initialise structure */
1125  endpoint = zalloc ( sizeof ( *endpoint ) );
1126  if ( ! endpoint ) {
1127  rc = -ENOMEM;
1128  goto err_alloc;
1129  }
1130  endpoint->ehci = ehci;
1131  endpoint->ep = ep;
1132  usb_endpoint_set_hostdata ( ep, endpoint );
1133 
1134  /* Initialise descriptor ring */
1135  if ( ( rc = ehci_ring_alloc ( ehci, &endpoint->ring ) ) != 0 )
1136  goto err_ring_alloc;
1137 
1138  /* Update queue characteristics and capabilities */
1140 
1141  /* Add to list of endpoints */
1142  list_add_tail ( &endpoint->list, &ehci->endpoints );
1143 
1144  /* Add to schedule */
1145  ehci_schedule_add ( endpoint );
1146 
1147  return 0;
1148 
1149  ehci_ring_free ( &endpoint->ring );
1150  err_ring_alloc:
1151  free ( endpoint );
1152  err_alloc:
1153  return rc;
1154 }
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 void ehci_endpoint_update(struct usb_endpoint *ep)
Update endpoint characteristics and capabilities.
Definition: ehci.c:1102
An EHCI endpoint.
Definition: ehci.h:528
static int ehci_ring_alloc(struct ehci_device *ehci, struct ehci_ring *ring)
Allocate transfer descriptor ring.
Definition: ehci.c:548
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
A USB device.
Definition: usb.h:708
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:780
struct list_head endpoints
List of all endpoints.
Definition: ehci.h:514
static void ehci_schedule_add(struct ehci_endpoint *endpoint)
Add endpoint to appropriate schedule.
Definition: ehci.c:989
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:730
static void ehci_ring_free(struct ehci_ring *ring)
Free transfer descriptor ring.
Definition: ehci.c:625
struct usb_device * usb
USB device.
Definition: usb.h:391
struct list_head list
List of all endpoints.
Definition: ehci.h:534
An EHCI device.
Definition: ehci.h:483

References ehci_endpoint::ehci, ehci_endpoint_update(), ehci_ring_alloc(), ehci_ring_free(), ehci_schedule_add(), ehci_device::endpoints, ENOMEM, ehci_endpoint::ep, usb_device::ep, free, ehci_endpoint::list, list_add_tail, rc, ehci_endpoint::ring, usb_endpoint::usb, usb_endpoint_set_hostdata(), usb_get_hostdata(), and zalloc().

◆ ehci_endpoint_close()

static void ehci_endpoint_close ( struct usb_endpoint ep)
static

Close endpoint.

Parameters
epUSB endpoint

Definition at line 1161 of file ehci.c.

1161  {
1162  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1163  struct ehci_device *ehci = endpoint->ehci;
1164  struct usb_device *usb = ep->usb;
1165  struct io_buffer *iobuf;
1166  int rc;
1167 
1168  /* Remove from schedule */
1169  if ( ( rc = ehci_schedule_del ( endpoint ) ) != 0 ) {
1170  /* No way to prevent hardware from continuing to
1171  * access the memory, so leak it.
1172  */
1173  DBGC ( ehci, "EHCI %s %s could not unschedule: %s\n",
1174  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
1175  return;
1176  }
1177 
1178  /* Cancel any incomplete transfers */
1179  while ( ehci_ring_fill ( &endpoint->ring ) ) {
1180  iobuf = ehci_dequeue ( &endpoint->ring );
1181  if ( iobuf )
1182  usb_complete_err ( ep, iobuf, -ECANCELED );
1183  }
1184 
1185  /* Remove from list of endpoints */
1186  list_del ( &endpoint->list );
1187 
1188  /* Free descriptor ring */
1189  ehci_ring_free ( &endpoint->ring );
1190 
1191  /* Free endpoint */
1192  free ( endpoint );
1193 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct io_buffer * ehci_dequeue(struct ehci_ring *ring)
Dequeue a transfer descriptor.
Definition: ehci.c:744
#define DBGC(...)
Definition: compiler.h:505
An EHCI endpoint.
Definition: ehci.h:528
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
char name[32]
Name.
Definition: usb.h:710
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
A USB device.
Definition: usb.h:708
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static int ehci_schedule_del(struct ehci_endpoint *endpoint)
Remove endpoint from appropriate schedule.
Definition: ehci.c:1006
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:730
static void ehci_ring_free(struct ehci_ring *ring)
Free transfer descriptor ring.
Definition: ehci.c:625
static unsigned int ehci_ring_fill(struct ehci_ring *ring)
Calculate space used in transfer descriptor ring.
Definition: ehci.h:400
struct usb_device * usb
USB device.
Definition: usb.h:391
struct list_head list
List of all endpoints.
Definition: ehci.h:534
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
An EHCI device.
Definition: ehci.h:483
A persistent I/O buffer.
Definition: iobuf.h:33

References DBGC, ECANCELED, ehci_endpoint::ehci, ehci_dequeue(), ehci_ring_fill(), ehci_ring_free(), ehci_schedule_del(), ehci_endpoint::ep, usb_device::ep, free, ehci_endpoint::list, list_del, usb_device::name, rc, ehci_endpoint::ring, strerror(), usb_endpoint::usb, usb_complete_err(), usb_endpoint_get_hostdata(), and usb_endpoint_name().

◆ ehci_endpoint_reset()

static int ehci_endpoint_reset ( struct usb_endpoint ep)
static

Reset endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 1201 of file ehci.c.

1201  {
1202  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1203  struct ehci_ring *ring = &endpoint->ring;
1204  struct ehci_transfer_descriptor *cache = &ring->head->cache;
1205  uint32_t link;
1206 
1207  /* Sanity checks */
1208  assert ( ! ( cache->status & EHCI_STATUS_ACTIVE ) );
1209  assert ( cache->status & EHCI_STATUS_HALTED );
1210 
1211  /* Reset residual count */
1212  ring->residual = 0;
1213 
1214  /* Reset data toggle */
1215  cache->len = 0;
1216 
1217  /* Prepare to restart at next unconsumed descriptor */
1218  link = virt_to_phys ( &ring->desc[ ring->cons % EHCI_RING_COUNT ] );
1219  cache->next = cpu_to_le32 ( link );
1220 
1221  /* Restart ring */
1222  wmb();
1223  cache->status = 0;
1224 
1225  return 0;
1226 }
unsigned int cons
Consumer counter.
Definition: ehci.h:373
wmb()
A transfer descriptor ring.
Definition: ehci.h:369
#define EHCI_STATUS_ACTIVE
Active.
Definition: ehci.h:261
size_t residual
Residual untransferred data.
Definition: ehci.h:376
uint16_t len
Transfer length.
Definition: ehci.h:239
An EHCI endpoint.
Definition: ehci.h:528
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint32_t next
Next transfer descriptor.
Definition: ehci.h:231
struct ehci_queue_head * head
Queue head.
Definition: ehci.h:382
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
struct ehci_transfer_descriptor cache
Transfer descriptor cache.
Definition: ehci.h:301
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
#define cpu_to_le32(value)
Definition: byteswap.h:107
unsigned int uint32_t
Definition: stdint.h:12
uint8_t status
Status.
Definition: ehci.h:235
A transfer descriptor.
Definition: ehci.h:229
#define EHCI_STATUS_HALTED
Halted.
Definition: ehci.h:258
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: ehci.h:391
struct ehci_transfer_descriptor * desc
Transfer descriptors.
Definition: ehci.h:384
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572

References assert(), ehci_queue_head::cache, ehci_ring::cons, cpu_to_le32, ehci_ring::desc, EHCI_RING_COUNT, EHCI_STATUS_ACTIVE, EHCI_STATUS_HALTED, ehci_endpoint::ep, ehci_ring::head, ehci_transfer_descriptor::len, link, ehci_transfer_descriptor::next, ehci_ring::residual, ehci_endpoint::ring, ehci_transfer_descriptor::status, usb_endpoint_get_hostdata(), virt_to_phys(), and wmb().

◆ ehci_endpoint_mtu()

static int ehci_endpoint_mtu ( struct usb_endpoint ep)
static

Update MTU.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 1234 of file ehci.c.

1234  {
1235 
1236  /* Update endpoint characteristics and capabilities */
1237  ehci_endpoint_update ( ep );
1238 
1239  return 0;
1240 }
static void ehci_endpoint_update(struct usb_endpoint *ep)
Update endpoint characteristics and capabilities.
Definition: ehci.c:1102

References ehci_endpoint_update().

◆ ehci_endpoint_message()

static int ehci_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 1249 of file ehci.c.

1250  {
1251  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1252  struct ehci_device *ehci = endpoint->ehci;
1253  struct usb_setup_packet *packet;
1254  unsigned int input;
1255  struct ehci_transfer xfers[3];
1256  struct ehci_transfer *xfer = xfers;
1257  size_t len;
1258  int rc;
1259 
1260  /* Construct setup stage */
1261  assert ( iob_len ( iobuf ) >= sizeof ( *packet ) );
1262  packet = iobuf->data;
1263  iob_pull ( iobuf, sizeof ( *packet ) );
1264  xfer->data = packet;
1265  xfer->len = sizeof ( *packet );
1266  xfer->flags = EHCI_FL_PID_SETUP;
1267  xfer++;
1268 
1269  /* Construct data stage, if applicable */
1270  len = iob_len ( iobuf );
1271  input = ( packet->request & cpu_to_le16 ( USB_DIR_IN ) );
1272  if ( len ) {
1273  xfer->data = iobuf->data;
1274  xfer->len = len;
1275  xfer->flags = ( EHCI_FL_TOGGLE |
1277  xfer++;
1278  }
1279 
1280  /* Construct status stage */
1281  xfer->data = NULL;
1282  xfer->len = 0;
1283  xfer->flags = ( EHCI_FL_TOGGLE | EHCI_FL_IOC |
1284  ( ( len && input ) ? EHCI_FL_PID_OUT : EHCI_FL_PID_IN));
1285  xfer++;
1286 
1287  /* Enqueue transfer */
1288  if ( ( rc = ehci_enqueue ( ehci, &endpoint->ring, iobuf, xfers,
1289  ( xfer - xfers ) ) ) != 0 )
1290  return rc;
1291 
1292  return 0;
1293 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EHCI_FL_PID_SETUP
SETUP token.
Definition: ehci.h:273
An EHCI endpoint.
Definition: ehci.h:528
Definition: bnxt_hsi.h:68
An EHCI transfer.
Definition: ehci.h:464
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
#define EHCI_FL_IOC
Interrupt on completion.
Definition: ehci.h:282
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:83
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
#define EHCI_FL_PID_IN
IN token.
Definition: ehci.h:270
size_t len
Length.
Definition: ehci.h:468
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
#define EHCI_FL_PID_OUT
OUT token.
Definition: ehci.h:267
unsigned int flags
Flags.
Definition: ehci.h:476
A USB setup data packet.
Definition: usb.h:68
#define EHCI_FL_TOGGLE
Set initial data toggle.
Definition: ehci.h:480
uint16_t request
Request.
Definition: usb.h:70
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:48
#define cpu_to_le16(value)
Definition: byteswap.h:106
void * data
Data buffer.
Definition: ehci.h:466
static int ehci_enqueue(struct ehci_device *ehci, struct ehci_ring *ring, struct io_buffer *iobuf, const struct ehci_transfer *xfer, unsigned int count)
Enqueue transfer descriptors.
Definition: ehci.c:654
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572
An EHCI device.
Definition: ehci.h:483

References assert(), cpu_to_le16, io_buffer::data, ehci_transfer::data, ehci_endpoint::ehci, ehci_enqueue(), EHCI_FL_IOC, EHCI_FL_PID_IN, EHCI_FL_PID_OUT, EHCI_FL_PID_SETUP, EHCI_FL_TOGGLE, ehci_endpoint::ep, ehci_transfer::flags, iob_len(), iob_pull, len, ehci_transfer::len, NULL, rc, usb_setup_packet::request, ehci_endpoint::ring, USB_DIR_IN, and usb_endpoint_get_hostdata().

◆ ehci_endpoint_count()

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

Calculate number of transfer descriptors.

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

Definition at line 1302 of file ehci.c.

1302  {
1303  unsigned int count;
1304 
1305  /* Split into 16kB transfers. A single transfer can handle up
1306  * to 20kB if it happens to be page-aligned, or up to 16kB
1307  * with arbitrary alignment. We simplify the code by assuming
1308  * that we can fit only 16kB into each transfer.
1309  */
1310  count = ( ( len + EHCI_MTU - 1 ) / EHCI_MTU );
1311 
1312  /* Append a zero-length transfer if applicable */
1313  if ( zlp || ( count == 0 ) )
1314  count++;
1315 
1316  return count;
1317 }
#define EHCI_MTU
Maximum transfer size.
Definition: ehci.h:30
uint32_t len
Length.
Definition: ena.h:14
uint16_t count
Number of entries.
Definition: ena.h:22

References count, EHCI_MTU, and len.

Referenced by ehci_endpoint_stream().

◆ ehci_endpoint_stream()

static int ehci_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 1327 of file ehci.c.

1328  {
1329  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1330  struct ehci_device *ehci = endpoint->ehci;
1331  void *data = iobuf->data;
1332  size_t len = iob_len ( iobuf );
1333  unsigned int count = ehci_endpoint_count ( len, zlp );
1334  unsigned int input = ( ep->address & USB_DIR_IN );
1335  unsigned int flags = ( input ? EHCI_FL_PID_IN : EHCI_FL_PID_OUT );
1336  struct ehci_transfer xfers[count];
1337  struct ehci_transfer *xfer = xfers;
1338  size_t xfer_len;
1339  unsigned int i;
1340  int rc;
1341 
1342  /* Create transfers */
1343  for ( i = 0 ; i < count ; i++ ) {
1344 
1345  /* Calculate transfer length */
1346  xfer_len = EHCI_MTU;
1347  if ( xfer_len > len )
1348  xfer_len = len;
1349 
1350  /* Create transfer */
1351  xfer->data = data;
1352  xfer->len = xfer_len;
1353  xfer->flags = flags;
1354 
1355  /* Move to next transfer */
1356  data += xfer_len;
1357  len -= xfer_len;
1358  xfer++;
1359  }
1360  xfer[-1].flags |= EHCI_FL_IOC;
1361 
1362  /* Enqueue transfer */
1363  if ( ( rc = ehci_enqueue ( ehci, &endpoint->ring, iobuf, xfers,
1364  count ) ) != 0 )
1365  return rc;
1366 
1367  return 0;
1368 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An EHCI endpoint.
Definition: ehci.h:528
Definition: bnxt_hsi.h:68
An EHCI transfer.
Definition: ehci.h:464
#define EHCI_MTU
Maximum transfer size.
Definition: ehci.h:30
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
#define EHCI_FL_IOC
Interrupt on completion.
Definition: ehci.h:282
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:83
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
#define EHCI_FL_PID_IN
IN token.
Definition: ehci.h:270
static unsigned int ehci_endpoint_count(size_t len, int zlp)
Calculate number of transfer descriptors.
Definition: ehci.c:1302
size_t len
Length.
Definition: ehci.h:468
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
#define EHCI_FL_PID_OUT
OUT token.
Definition: ehci.h:267
unsigned int flags
Flags.
Definition: ehci.h:476
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:48
uint16_t count
Number of entries.
Definition: ena.h:22
void * data
Data buffer.
Definition: ehci.h:466
static int ehci_enqueue(struct ehci_device *ehci, struct ehci_ring *ring, struct io_buffer *iobuf, const struct ehci_transfer *xfer, unsigned int count)
Enqueue transfer descriptors.
Definition: ehci.c:654
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
unsigned int address
Endpoint address.
Definition: usb.h:393
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572
An EHCI device.
Definition: ehci.h:483
uint8_t flags
Flags.
Definition: ena.h:18

References usb_endpoint::address, count, data, io_buffer::data, ehci_transfer::data, ehci_endpoint::ehci, ehci_endpoint_count(), ehci_enqueue(), EHCI_FL_IOC, EHCI_FL_PID_IN, EHCI_FL_PID_OUT, EHCI_MTU, ehci_endpoint::ep, flags, ehci_transfer::flags, iob_len(), len, ehci_transfer::len, rc, ehci_endpoint::ring, USB_DIR_IN, and usb_endpoint_get_hostdata().

◆ ehci_endpoint_poll()

static void ehci_endpoint_poll ( struct ehci_endpoint endpoint)
static

Poll for completions.

Parameters
endpointEndpoint

Definition at line 1375 of file ehci.c.

1375  {
1376  struct ehci_device *ehci = endpoint->ehci;
1377  struct ehci_ring *ring = &endpoint->ring;
1378  struct ehci_transfer_descriptor *desc;
1379  struct usb_endpoint *ep = endpoint->ep;
1380  struct usb_device *usb = ep->usb;
1381  struct io_buffer *iobuf;
1382  unsigned int index;
1383  unsigned int status;
1384  int rc;
1385 
1386  /* Consume all completed descriptors */
1387  while ( ehci_ring_fill ( &endpoint->ring ) ) {
1388 
1389  /* Stop if we reach an uncompleted descriptor */
1390  rmb();
1391  index = ( ring->cons % EHCI_RING_COUNT );
1392  desc = &ring->desc[index];
1393  status = desc->status;
1394  if ( status & EHCI_STATUS_ACTIVE )
1395  break;
1396 
1397  /* Consume this descriptor */
1398  iobuf = ehci_dequeue ( ring );
1399 
1400  /* If we have encountered an error, then consume all
1401  * remaining descriptors in this transaction, report
1402  * the error to the USB core, and stop further
1403  * processing.
1404  */
1405  if ( status & EHCI_STATUS_HALTED ) {
1406  rc = -EIO_STATUS ( status );
1407  DBGC ( ehci, "EHCI %s %s completion %d failed (status "
1408  "%02x): %s\n", usb->name,
1409  usb_endpoint_name ( ep ), index, status,
1410  strerror ( rc ) );
1411  while ( ! iobuf )
1412  iobuf = ehci_dequeue ( ring );
1413  usb_complete_err ( endpoint->ep, iobuf, rc );
1414  return;
1415  }
1416 
1417  /* Accumulate residual data count */
1418  ring->residual += ( le16_to_cpu ( desc->len ) & EHCI_LEN_MASK );
1419 
1420  /* If this is not the end of a transaction (i.e. has
1421  * no I/O buffer), then continue to next descriptor.
1422  */
1423  if ( ! iobuf )
1424  continue;
1425 
1426  /* Update I/O buffer length */
1427  iob_unput ( iobuf, ring->residual );
1428  ring->residual = 0;
1429 
1430  /* Report completion to USB core */
1431  usb_complete ( endpoint->ep, iobuf );
1432  }
1433 }
unsigned int cons
Consumer counter.
Definition: ehci.h:373
#define EIO_STATUS(status)
Construct error code from transfer descriptor status.
Definition: ehci.c:54
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct io_buffer * ehci_dequeue(struct ehci_ring *ring)
Dequeue a transfer descriptor.
Definition: ehci.c:744
A transfer descriptor ring.
Definition: ehci.h:369
#define EHCI_STATUS_ACTIVE
Active.
Definition: ehci.h:261
size_t residual
Residual untransferred data.
Definition: ehci.h:376
#define DBGC(...)
Definition: compiler.h:505
uint16_t len
Transfer length.
Definition: ehci.h:239
#define EHCI_LEN_MASK
Length mask.
Definition: ehci.h:285
uint8_t status
Status.
Definition: ena.h:16
#define rmb()
Definition: io.h:484
A USB endpoint.
Definition: usb.h:389
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
struct usb_endpoint * ep
USB endpoint.
Definition: ehci.h:532
char name[32]
Name.
Definition: usb.h:710
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
A USB device.
Definition: usb.h:708
#define iob_unput(iobuf, len)
Definition: iobuf.h:135
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define le16_to_cpu(value)
Definition: byteswap.h:112
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
uint8_t status
Status.
Definition: ehci.h:235
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition: usb.h:1066
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:730
A transfer descriptor.
Definition: ehci.h:229
static unsigned int ehci_ring_fill(struct ehci_ring *ring)
Calculate space used in transfer descriptor ring.
Definition: ehci.h:400
struct usb_device * usb
USB device.
Definition: usb.h:391
#define EHCI_STATUS_HALTED
Halted.
Definition: ehci.h:258
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: ehci.h:391
struct ehci_transfer_descriptor * desc
Transfer descriptors.
Definition: ehci.h:384
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:586
An EHCI device.
Definition: ehci.h:483
A persistent I/O buffer.
Definition: iobuf.h:33

References ehci_ring::cons, DBGC, ehci_ring::desc, ehci_endpoint::ehci, ehci_dequeue(), EHCI_LEN_MASK, EHCI_RING_COUNT, ehci_ring_fill(), EHCI_STATUS_ACTIVE, EHCI_STATUS_HALTED, EIO_STATUS, ehci_endpoint::ep, usb_device::ep, index, iob_unput, le16_to_cpu, ehci_transfer_descriptor::len, usb_device::name, rc, ehci_ring::residual, ehci_endpoint::ring, rmb, status, ehci_transfer_descriptor::status, strerror(), usb_endpoint::usb, usb_complete(), usb_complete_err(), and usb_endpoint_name().

Referenced by ehci_bus_poll().

◆ ehci_device_open()

static int ehci_device_open ( struct usb_device usb)
static

Open device.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 1448 of file ehci.c.

1448  {
1449  struct ehci_device *ehci = usb_bus_get_hostdata ( usb->port->hub->bus );
1450 
1451  usb_set_hostdata ( usb, ehci );
1452  return 0;
1453 }
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition: usb.h:769
struct usb_port * port
USB port.
Definition: usb.h:712
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1041
struct usb_hub * hub
USB hub.
Definition: usb.h:800
struct usb_bus * bus
USB bus.
Definition: usb.h:830
An EHCI device.
Definition: ehci.h:483

References usb_hub::bus, usb_port::hub, usb_device::port, usb_bus_get_hostdata(), and usb_set_hostdata().

◆ ehci_device_close()

static void ehci_device_close ( struct usb_device usb)
static

Close device.

Parameters
usbUSB device

Definition at line 1460 of file ehci.c.

1460  {
1461  struct ehci_device *ehci = usb_get_hostdata ( usb );
1462  struct usb_bus *bus = ehci->bus;
1463 
1464  /* Free device address, if assigned */
1465  if ( usb->address )
1466  usb_free_address ( bus, usb->address );
1467 }
struct usb_bus * bus
USB bus.
Definition: ehci.h:524
unsigned int address
Device address, if assigned.
Definition: usb.h:718
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
Definition: usb.c:2243
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:780
A USB bus.
Definition: usb.h:951
uint8_t bus
Bus.
Definition: edd.h:14
An EHCI device.
Definition: ehci.h:483

References usb_device::address, bus, ehci_device::bus, usb_free_address(), and usb_get_hostdata().

◆ ehci_device_address()

static int ehci_device_address ( struct usb_device usb)
static

Assign device address.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 1475 of file ehci.c.

1475  {
1476  struct ehci_device *ehci = usb_get_hostdata ( usb );
1477  struct usb_bus *bus = ehci->bus;
1478  struct usb_endpoint *ep0 = usb_endpoint ( usb, USB_EP0_ADDRESS );
1479  int address;
1480  int rc;
1481 
1482  /* Sanity checks */
1483  assert ( usb->address == 0 );
1484  assert ( ep0 != NULL );
1485 
1486  /* Allocate device address */
1488  if ( address < 0 ) {
1489  rc = address;
1490  DBGC ( ehci, "EHCI %s could not allocate address: %s\n",
1491  usb->name, strerror ( rc ) );
1492  goto err_alloc_address;
1493  }
1494 
1495  /* Set address */
1496  if ( ( rc = usb_set_address ( usb, address ) ) != 0 )
1497  goto err_set_address;
1498 
1499  /* Update device address */
1500  usb->address = address;
1501 
1502  /* Update control endpoint characteristics and capabilities */
1503  ehci_endpoint_update ( ep0 );
1504 
1505  return 0;
1506 
1507  err_set_address:
1509  err_alloc_address:
1510  return rc;
1511 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t address
Base address.
Definition: ena.h:24
static void ehci_endpoint_update(struct usb_endpoint *ep)
Update endpoint characteristics and capabilities.
Definition: ehci.c:1102
#define DBGC(...)
Definition: compiler.h:505
struct usb_bus * bus
USB bus.
Definition: ehci.h:524
unsigned int address
Device address, if assigned.
Definition: usb.h:718
static int usb_set_address(struct usb_device *usb, unsigned int address)
Set address.
Definition: usb.h:1138
A USB endpoint.
Definition: usb.h:389
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
char name[32]
Name.
Definition: usb.h:710
static struct usb_endpoint * usb_endpoint(struct usb_device *usb, unsigned int address)
Get USB endpoint.
Definition: usb.h:791
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
Definition: usb.c:2243
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:780
struct usb_device * usb
USB device.
Definition: usb.h:391
#define USB_EP0_ADDRESS
Control endpoint address.
Definition: usb.h:486
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
int usb_alloc_address(struct usb_bus *bus)
Allocate device address.
Definition: usb.c:2223
A USB bus.
Definition: usb.h:951
uint8_t bus
Bus.
Definition: edd.h:14
An EHCI device.
Definition: ehci.h:483

References address, usb_device::address, assert(), bus, ehci_device::bus, DBGC, ehci_endpoint_update(), usb_device::name, NULL, rc, strerror(), usb_endpoint::usb, usb_alloc_address(), usb_endpoint(), USB_EP0_ADDRESS, usb_free_address(), usb_get_hostdata(), and usb_set_address().

◆ ehci_hub_open()

static int ehci_hub_open ( struct usb_hub *hub  __unused)
static

Open hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 1526 of file ehci.c.

1526  {
1527 
1528  /* Nothing to do */
1529  return 0;
1530 }

◆ ehci_hub_close()

static void ehci_hub_close ( struct usb_hub *hub  __unused)
static

Close hub.

Parameters
hubUSB hub

Definition at line 1537 of file ehci.c.

1537  {
1538 
1539  /* Nothing to do */
1540 }

◆ ehci_root_open()

static int ehci_root_open ( struct usb_hub hub)
static

Open root hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 1555 of file ehci.c.

1555  {
1556  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1557  uint32_t portsc;
1558  unsigned int i;
1559 
1560  /* Route all ports to EHCI controller */
1562 
1563  /* Enable power to all ports */
1564  for ( i = 1 ; i <= ehci->ports ; i++ ) {
1565  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( i ) );
1566  portsc &= ~EHCI_PORTSC_CHANGE;
1567  portsc |= EHCI_PORTSC_PP;
1568  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( i ) );
1569  }
1570 
1571  /* Wait 20ms after potentially enabling power to a port */
1573 
1574  return 0;
1575 }
unsigned int ports
Number of ports.
Definition: ehci.h:495
void * op
Operational registers.
Definition: ehci.h:492
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define EHCI_PORTSC_CHANGE
Port status change mask.
Definition: ehci.h:210
#define EHCI_PORTSC_PP
Port power.
Definition: ehci.h:204
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define EHCI_PORT_POWER_DELAY_MS
Time to delay after enabling power to a port.
Definition: ehci.h:425
#define EHCI_OP_CONFIGFLAG
Configure flag register.
Definition: ehci.h:171
#define EHCI_OP_PORTSC(port)
Port status and control register.
Definition: ehci.h:177
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 EHCI_CONFIGFLAG_CF
Configure flag.
Definition: ehci.h:174
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:933
An EHCI device.
Definition: ehci.h:483

References EHCI_CONFIGFLAG_CF, EHCI_OP_CONFIGFLAG, EHCI_OP_PORTSC, EHCI_PORT_POWER_DELAY_MS, EHCI_PORTSC_CHANGE, EHCI_PORTSC_PP, mdelay(), ehci_device::op, ehci_device::ports, readl(), usb_hub_get_drvdata(), and writel().

◆ ehci_root_close()

static void ehci_root_close ( struct usb_hub hub)
static

Close root hub.

Parameters
hubUSB hub

Definition at line 1582 of file ehci.c.

1582  {
1583  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1584 
1585  /* Route all ports back to companion controllers */
1586  writel ( 0, ehci->op + EHCI_OP_CONFIGFLAG );
1587 }
void * op
Operational registers.
Definition: ehci.h:492
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define EHCI_OP_CONFIGFLAG
Configure flag register.
Definition: ehci.h:171
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:933
An EHCI device.
Definition: ehci.h:483

References EHCI_OP_CONFIGFLAG, ehci_device::op, usb_hub_get_drvdata(), and writel().

◆ ehci_root_enable()

static int ehci_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 1596 of file ehci.c.

1596  {
1597  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1598  uint32_t portsc;
1599  unsigned int line;
1600  unsigned int i;
1601 
1602  /* Check for a low-speed device */
1603  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1604  line = EHCI_PORTSC_LINE_STATUS ( portsc );
1605  if ( line == EHCI_PORTSC_LINE_STATUS_LOW ) {
1606  DBGC ( ehci, "EHCI %s-%d detected low-speed device: "
1607  "disowning\n", ehci->name, port->address );
1608  goto disown;
1609  }
1610 
1611  /* Reset port */
1612  portsc &= ~( EHCI_PORTSC_PED | EHCI_PORTSC_CHANGE );
1613  portsc |= EHCI_PORTSC_PR;
1614  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1616  portsc &= ~EHCI_PORTSC_PR;
1617  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1618 
1619  /* Wait for reset to complete */
1620  for ( i = 0 ; i < EHCI_PORT_RESET_MAX_WAIT_MS ; i++ ) {
1621 
1622  /* Check port status */
1623  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1624  if ( ! ( portsc & EHCI_PORTSC_PR ) ) {
1625  if ( portsc & EHCI_PORTSC_PED )
1626  return 0;
1627  DBGC ( ehci, "EHCI %s-%d not enabled after reset: "
1628  "disowning\n", ehci->name, port->address );
1629  goto disown;
1630  }
1631 
1632  /* Delay */
1633  mdelay ( 1 );
1634  }
1635 
1636  DBGC ( ehci, "EHCI %s-%d timed out waiting for port to reset\n",
1637  ehci->name, port->address );
1638  return -ETIMEDOUT;
1639 
1640  disown:
1641  /* Disown port */
1642  portsc &= ~EHCI_PORTSC_CHANGE;
1643  portsc |= EHCI_PORTSC_OWNER;
1644  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1645 
1646  /* Delay to allow child companion controllers to settle */
1648 
1649  /* Poll child companion controllers */
1650  ehci_poll_companions ( ehci );
1651 
1652  return -ENODEV;
1653 }
void * op
Operational registers.
Definition: ehci.h:492
#define EHCI_DISOWN_DELAY_MS
Time to delay after releasing ownership of a port.
Definition: ehci.h:431
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define USB_RESET_DELAY_MS
Minimum reset time.
Definition: usb.h:1302
#define EHCI_PORT_RESET_MAX_WAIT_MS
Maximum time to wait for a port reset to complete.
Definition: ehci.h:461
#define EHCI_PORTSC_CHANGE
Port status change mask.
Definition: ehci.h:210
#define EHCI_PORTSC_PED
Port enabled.
Definition: ehci.h:186
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: ehci.h:487
#define EHCI_PORTSC_LINE_STATUS_LOW
Line status: low-speed device.
Definition: ehci.h:201
#define EHCI_PORTSC_PR
Port reset.
Definition: ehci.h:195
#define EHCI_PORTSC_OWNER
Port owner.
Definition: ehci.h:207
#define EHCI_OP_PORTSC(port)
Port status and control register.
Definition: ehci.h:177
#define ENODEV
No such device.
Definition: errno.h:509
#define EHCI_PORTSC_LINE_STATUS(portsc)
Line status.
Definition: ehci.h:198
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 ETIMEDOUT
Connection timed out.
Definition: errno.h:669
static void ehci_poll_companions(struct ehci_device *ehci)
Poll child companion controllers.
Definition: ehci.c:379
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:933
An EHCI device.
Definition: ehci.h:483

References DBGC, EHCI_DISOWN_DELAY_MS, EHCI_OP_PORTSC, ehci_poll_companions(), EHCI_PORT_RESET_MAX_WAIT_MS, EHCI_PORTSC_CHANGE, EHCI_PORTSC_LINE_STATUS, EHCI_PORTSC_LINE_STATUS_LOW, EHCI_PORTSC_OWNER, EHCI_PORTSC_PED, EHCI_PORTSC_PR, ENODEV, ETIMEDOUT, mdelay(), ehci_device::name, ehci_device::op, port, readl(), usb_hub_get_drvdata(), USB_RESET_DELAY_MS, and writel().

◆ ehci_root_disable()

static int ehci_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 1662 of file ehci.c.

1662  {
1663  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1664  uint32_t portsc;
1665 
1666  /* Disable port */
1667  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1668  portsc &= ~( EHCI_PORTSC_PED | EHCI_PORTSC_CHANGE );
1669  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1670 
1671  return 0;
1672 }
void * op
Operational registers.
Definition: ehci.h:492
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define EHCI_PORTSC_CHANGE
Port status change mask.
Definition: ehci.h:210
#define EHCI_PORTSC_PED
Port enabled.
Definition: ehci.h:186
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.
#define EHCI_OP_PORTSC(port)
Port status and control register.
Definition: ehci.h:177
unsigned int uint32_t
Definition: stdint.h:12
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:933
An EHCI device.
Definition: ehci.h:483

References EHCI_OP_PORTSC, EHCI_PORTSC_CHANGE, EHCI_PORTSC_PED, ehci_device::op, port, readl(), usb_hub_get_drvdata(), and writel().

◆ ehci_root_speed()

static int ehci_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 1681 of file ehci.c.

1681  {
1682  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1683  uint32_t portsc;
1684  unsigned int speed;
1685  unsigned int line;
1686  int ccs;
1687  int csc;
1688  int ped;
1689 
1690  /* Read port status */
1691  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1692  DBGC2 ( ehci, "EHCI %s-%d status is %08x\n",
1693  ehci->name, port->address, portsc );
1694  ccs = ( portsc & EHCI_PORTSC_CCS );
1695  csc = ( portsc & EHCI_PORTSC_CSC );
1696  ped = ( portsc & EHCI_PORTSC_PED );
1697  line = EHCI_PORTSC_LINE_STATUS ( portsc );
1698 
1699  /* Record disconnections and clear changes */
1700  port->disconnected |= csc;
1701  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1702 
1703  /* Determine port speed */
1704  if ( ! ccs ) {
1705  /* Port not connected */
1706  speed = USB_SPEED_NONE;
1707  } else if ( line == EHCI_PORTSC_LINE_STATUS_LOW ) {
1708  /* Detected as low-speed */
1709  speed = USB_SPEED_LOW;
1710  } else if ( ped ) {
1711  /* Port already enabled: must be high-speed */
1712  speed = USB_SPEED_HIGH;
1713  } else {
1714  /* Not low-speed and not yet enabled. Could be either
1715  * full-speed or high-speed; we can't yet tell.
1716  */
1717  speed = USB_SPEED_FULL;
1718  }
1719  port->speed = speed;
1720  return 0;
1721 }
void * op
Operational registers.
Definition: ehci.h:492
Low speed (1.5Mbps)
Definition: usb.h:48
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define EHCI_PORTSC_PED
Port enabled.
Definition: ehci.h:186
u8 port
Port number.
Definition: CIB_PRM.h:31
#define EHCI_PORTSC_CCS
Current connect status.
Definition: ehci.h:180
Not connected.
Definition: usb.h:46
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
const char * name
Name.
Definition: ehci.h:487
#define EHCI_PORTSC_LINE_STATUS_LOW
Line status: low-speed device.
Definition: ehci.h:201
#define EHCI_OP_PORTSC(port)
Port status and control register.
Definition: ehci.h:177
#define EHCI_PORTSC_LINE_STATUS(portsc)
Line status.
Definition: ehci.h:198
#define EHCI_PORTSC_CSC
Connect status change.
Definition: ehci.h:183
unsigned int uint32_t
Definition: stdint.h:12
#define DBGC2(...)
Definition: compiler.h:522
High speed (480Mbps)
Definition: usb.h:52
Full speed (12Mbps)
Definition: usb.h:50
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:933
An EHCI device.
Definition: ehci.h:483

References DBGC2, EHCI_OP_PORTSC, EHCI_PORTSC_CCS, EHCI_PORTSC_CSC, EHCI_PORTSC_LINE_STATUS, EHCI_PORTSC_LINE_STATUS_LOW, EHCI_PORTSC_PED, ehci_device::name, ehci_device::op, port, readl(), usb_hub_get_drvdata(), USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_LOW, USB_SPEED_NONE, and writel().

◆ ehci_root_clear_tt()

static int ehci_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 1731 of file ehci.c.

1732  {
1733  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1734 
1735  /* Should never be called; this is a root hub */
1736  DBGC ( ehci, "EHCI %s-%d nonsensical CLEAR_TT for %s %s\n", ehci->name,
1737  port->address, ep->usb->name, usb_endpoint_name ( ep ) );
1738 
1739  return -ENOTSUP;
1740 }
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
u8 port
Port number.
Definition: CIB_PRM.h:31
const char * name
Name.
Definition: ehci.h:487
char name[32]
Name.
Definition: usb.h:710
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
An EHCI device.
Definition: ehci.h:483

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

◆ ehci_root_poll()

static void ehci_root_poll ( struct usb_hub hub,
struct usb_port port 
)
static

Poll for port status changes.

Parameters
hubUSB hub
portUSB port

Definition at line 1748 of file ehci.c.

1748  {
1749  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1750  uint32_t portsc;
1751  uint32_t change;
1752 
1753  /* Do nothing unless something has changed */
1754  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1755  change = ( portsc & EHCI_PORTSC_CHANGE );
1756  if ( ! change )
1757  return;
1758 
1759  /* Record disconnections and clear changes */
1760  port->disconnected |= ( portsc & EHCI_PORTSC_CSC );
1761  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1762 
1763  /* Report port status change */
1764  usb_port_changed ( port );
1765 }
void * op
Operational registers.
Definition: ehci.h:492
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition: usb.c:1839
#define EHCI_PORTSC_CHANGE
Port status change mask.
Definition: ehci.h:210
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.
#define EHCI_OP_PORTSC(port)
Port status and control register.
Definition: ehci.h:177
#define EHCI_PORTSC_CSC
Connect status change.
Definition: ehci.h:183
unsigned int uint32_t
Definition: stdint.h:12
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:933
An EHCI device.
Definition: ehci.h:483

References EHCI_OP_PORTSC, EHCI_PORTSC_CHANGE, EHCI_PORTSC_CSC, ehci_device::op, port, readl(), usb_hub_get_drvdata(), usb_port_changed(), and writel().

Referenced by ehci_bus_poll().

◆ ehci_bus_open()

static int ehci_bus_open ( struct usb_bus bus)
static

Open USB bus.

Parameters
busUSB bus
Return values
rcReturn status code

Definition at line 1780 of file ehci.c.

1780  {
1781  struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1782  unsigned int frames;
1783  size_t len;
1784  int rc;
1785 
1786  /* Sanity checks */
1787  assert ( list_empty ( &ehci->async ) );
1788  assert ( list_empty ( &ehci->periodic ) );
1789 
1790  /* Allocate and initialise asynchronous queue head */
1791  ehci->head = malloc_phys ( sizeof ( *ehci->head ),
1792  ehci_align ( sizeof ( *ehci->head ) ) );
1793  if ( ! ehci->head ) {
1794  rc = -ENOMEM;
1795  goto err_alloc_head;
1796  }
1797  memset ( ehci->head, 0, sizeof ( *ehci->head ) );
1798  ehci->head->chr = cpu_to_le32 ( EHCI_CHR_HEAD );
1801  ehci_async_schedule ( ehci );
1802  writel ( virt_to_phys ( ehci->head ),
1803  ehci->op + EHCI_OP_ASYNCLISTADDR );
1804 
1805  /* Use async queue head to determine control data structure segment */
1806  ehci->ctrldssegment =
1807  ( ( ( uint64_t ) virt_to_phys ( ehci->head ) ) >> 32 );
1808  if ( ehci->addr64 ) {
1809  writel ( ehci->ctrldssegment, ehci->op + EHCI_OP_CTRLDSSEGMENT);
1810  } else if ( ehci->ctrldssegment ) {
1811  DBGC ( ehci, "EHCI %s CTRLDSSEGMENT not supported\n",
1812  ehci->name );
1813  rc = -ENOTSUP;
1814  goto err_ctrldssegment;
1815  }
1816 
1817  /* Allocate periodic frame list */
1818  frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
1819  len = ( frames * sizeof ( ehci->frame[0] ) );
1820  ehci->frame = malloc_phys ( len, EHCI_PAGE_ALIGN );
1821  if ( ! ehci->frame ) {
1822  rc = -ENOMEM;
1823  goto err_alloc_frame;
1824  }
1825  if ( ( rc = ehci_ctrl_reachable ( ehci, ehci->frame ) ) != 0 ) {
1826  DBGC ( ehci, "EHCI %s frame list unreachable\n", ehci->name );
1827  goto err_unreachable_frame;
1828  }
1829  ehci_periodic_schedule ( ehci );
1830  writel ( virt_to_phys ( ehci->frame ),
1831  ehci->op + EHCI_OP_PERIODICLISTBASE );
1832 
1833  /* Start controller */
1834  ehci_run ( ehci );
1835 
1836  return 0;
1837 
1838  ehci_stop ( ehci );
1839  err_unreachable_frame:
1840  free_phys ( ehci->frame, len );
1841  err_alloc_frame:
1842  err_ctrldssegment:
1843  free_phys ( ehci->head, sizeof ( *ehci->head ) );
1844  err_alloc_head:
1845  return rc;
1846 }
static void ehci_run(struct ehci_device *ehci)
Start EHCI device.
Definition: ehci.c:452
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EHCI_PERIODIC_FRAMES(flsize)
Number of elements in frame list.
Definition: ehci.h:108
static int ehci_stop(struct ehci_device *ehci)
Stop EHCI device.
Definition: ehci.c:469
static size_t ehci_align(size_t len)
Calculate buffer alignment.
Definition: ehci.c:140
struct list_head periodic
Periodic schedule.
Definition: ehci.h:521
void * op
Operational registers.
Definition: ehci.h:492
uint32_t ctrldssegment
Control data structure segment.
Definition: ehci.h:507
#define DBGC(...)
Definition: compiler.h:505
unsigned long long uint64_t
Definition: stdint.h:13
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.h:62
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
uint32_t next
Next transfer descriptor.
Definition: ehci.h:231
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
struct ehci_queue_head * head
Asynchronous queue head.
Definition: ehci.h:509
#define ENOMEM
Not enough space.
Definition: errno.h:534
int addr64
64-bit addressing capability
Definition: ehci.h:497
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define EHCI_PAGE_ALIGN
Page-alignment required for some data structures.
Definition: ehci.h:33
unsigned int flsize
Frame list size.
Definition: ehci.h:499
struct ehci_transfer_descriptor cache
Transfer descriptor cache.
Definition: ehci.h:301
const char * name
Name.
Definition: ehci.h:487
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define EHCI_OP_ASYNCLISTADDR
Current asynchronous list address register.
Definition: ehci.h:168
struct ehci_periodic_frame * frame
Periodic frame list.
Definition: ehci.h:511
#define EHCI_LINK_TERMINATE
List terminator.
Definition: ehci.h:214
#define EHCI_OP_CTRLDSSEGMENT
Control data structure segment register.
Definition: ehci.h:162
static void ehci_async_schedule(struct ehci_device *ehci)
(Re)build asynchronous schedule
Definition: ehci.c:789
uint8_t status
Status.
Definition: ehci.h:235
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1041
uint32_t len
Length.
Definition: ena.h:14
#define EHCI_OP_PERIODICLISTBASE
Periodic frame list base address register.
Definition: ehci.h:165
static int ehci_ctrl_reachable(struct ehci_device *ehci, void *ptr)
Check control data structure reachability.
Definition: ehci.c:160
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
#define EHCI_STATUS_HALTED
Halted.
Definition: ehci.h:258
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
#define EHCI_CHR_HEAD
Head of reclamation list flag.
Definition: ehci.h:326
static void ehci_periodic_schedule(struct ehci_device *ehci)
(Re)build periodic schedule
Definition: ehci.c:876
uint8_t bus
Bus.
Definition: edd.h:14
uint32_t chr
Endpoint characteristics.
Definition: ehci.h:295
An EHCI device.
Definition: ehci.h:483
void * memset(void *dest, int character, size_t len) __nonnull

References ehci_device::addr64, assert(), ehci_device::async, bus, ehci_queue_head::cache, ehci_queue_head::chr, cpu_to_le32, ehci_device::ctrldssegment, DBGC, ehci_align(), ehci_async_schedule(), EHCI_CHR_HEAD, ehci_ctrl_reachable(), EHCI_LINK_TERMINATE, EHCI_OP_ASYNCLISTADDR, EHCI_OP_CTRLDSSEGMENT, EHCI_OP_PERIODICLISTBASE, EHCI_PAGE_ALIGN, EHCI_PERIODIC_FRAMES, ehci_periodic_schedule(), ehci_run(), EHCI_STATUS_HALTED, ehci_stop(), ENOMEM, ENOTSUP, ehci_device::flsize, ehci_device::frame, free_phys(), ehci_device::head, len, list_empty, malloc_phys(), memset(), ehci_device::name, ehci_transfer_descriptor::next, ehci_device::op, ehci_device::periodic, rc, ehci_transfer_descriptor::status, usb_bus_get_hostdata(), virt_to_phys(), and writel().

◆ ehci_bus_close()

static void ehci_bus_close ( struct usb_bus bus)
static

Close USB bus.

Parameters
busUSB bus

Definition at line 1853 of file ehci.c.

1853  {
1854  struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1855  unsigned int frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
1856 
1857  /* Sanity checks */
1858  assert ( list_empty ( &ehci->async ) );
1859  assert ( list_empty ( &ehci->periodic ) );
1860 
1861  /* Stop controller */
1862  ehci_stop ( ehci );
1863 
1864  /* Free periodic frame list */
1865  free_phys ( ehci->frame, ( frames * sizeof ( ehci->frame[0] ) ) );
1866 
1867  /* Free asynchronous schedule */
1868  free_phys ( ehci->head, sizeof ( *ehci->head ) );
1869 }
#define EHCI_PERIODIC_FRAMES(flsize)
Number of elements in frame list.
Definition: ehci.h:108
static int ehci_stop(struct ehci_device *ehci)
Stop EHCI device.
Definition: ehci.c:469
struct list_head periodic
Periodic schedule.
Definition: ehci.h:521
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
struct ehci_queue_head * head
Asynchronous queue head.
Definition: ehci.h:509
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int flsize
Frame list size.
Definition: ehci.h:499
struct ehci_periodic_frame * frame
Periodic frame list.
Definition: ehci.h:511
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1041
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
uint8_t bus
Bus.
Definition: edd.h:14
An EHCI device.
Definition: ehci.h:483

References assert(), ehci_device::async, bus, EHCI_PERIODIC_FRAMES, ehci_stop(), ehci_device::flsize, ehci_device::frame, free_phys(), ehci_device::head, list_empty, ehci_device::periodic, and usb_bus_get_hostdata().

◆ ehci_bus_poll()

static void ehci_bus_poll ( struct usb_bus bus)
static

Poll USB bus.

Parameters
busUSB bus

Definition at line 1876 of file ehci.c.

1876  {
1877  struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1878  struct usb_hub *hub = bus->hub;
1879  struct ehci_endpoint *endpoint;
1880  unsigned int i;
1881  uint32_t usbsts;
1882  uint32_t change;
1883 
1884  /* Do nothing unless something has changed */
1885  usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
1886  assert ( usbsts & EHCI_USBSTS_ASYNC );
1887  assert ( usbsts & EHCI_USBSTS_PERIODIC );
1888  assert ( ! ( usbsts & EHCI_USBSTS_HCH ) );
1889  change = ( usbsts & EHCI_USBSTS_CHANGE );
1890  if ( ! change )
1891  return;
1892 
1893  /* Acknowledge changes */
1894  writel ( usbsts, ehci->op + EHCI_OP_USBSTS );
1895 
1896  /* Process completions, if applicable */
1897  if ( change & ( EHCI_USBSTS_USBINT | EHCI_USBSTS_USBERRINT ) ) {
1898 
1899  /* Iterate over all endpoints looking for completed
1900  * descriptors. We trust that completion handlers are
1901  * minimal and will not do anything that could
1902  * plausibly affect the endpoint list itself.
1903  */
1904  list_for_each_entry ( endpoint, &ehci->endpoints, list )
1905  ehci_endpoint_poll ( endpoint );
1906  }
1907 
1908  /* Process port status changes, if applicable */
1909  if ( change & EHCI_USBSTS_PORT ) {
1910 
1911  /* Iterate over all ports looking for status changes */
1912  for ( i = 1 ; i <= ehci->ports ; i++ )
1913  ehci_root_poll ( hub, usb_port ( hub, i ) );
1914  }
1915 
1916  /* Report fatal errors */
1917  if ( change & EHCI_USBSTS_SYSERR )
1918  DBGC ( ehci, "EHCI %s host system error\n", ehci->name );
1919 }
#define EHCI_USBSTS_SYSERR
Host system error.
Definition: ehci.h:135
unsigned int ports
Number of ports.
Definition: ehci.h:495
void * op
Operational registers.
Definition: ehci.h:492
A USB hub.
Definition: usb.h:826
#define EHCI_USBSTS_ASYNC
Asynchronous schedule enabled.
Definition: ehci.h:144
#define EHCI_USBSTS_CHANGE
USB status change mask.
Definition: ehci.h:150
#define EHCI_USBSTS_PORT
Port change detect.
Definition: ehci.h:129
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
An EHCI endpoint.
Definition: ehci.h:528
static void ehci_root_poll(struct usb_hub *hub, struct usb_port *port)
Poll for port status changes.
Definition: ehci.c:1748
A USB port.
Definition: usb.h:798
struct ehci_device * ehci
EHCI device.
Definition: ehci.h:530
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define EHCI_USBSTS_USBERRINT
USB error interrupt.
Definition: ehci.h:126
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static void ehci_endpoint_poll(struct ehci_endpoint *endpoint)
Poll for completions.
Definition: ehci.c:1375
#define EHCI_USBSTS_HCH
Host controller halted.
Definition: ehci.h:147
const char * name
Name.
Definition: ehci.h:487
unsigned int uint32_t
Definition: stdint.h:12
#define EHCI_USBSTS_USBINT
USB interrupt.
Definition: ehci.h:123
#define EHCI_OP_USBSTS
USB status register.
Definition: ehci.h:120
#define EHCI_USBSTS_PERIODIC
Periodic schedule enabled.
Definition: ehci.h:141
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1041
struct list_head endpoints
List of all endpoints.
Definition: ehci.h:514
struct list_head list
List of all endpoints.
Definition: ehci.h:534
uint8_t bus
Bus.
Definition: edd.h:14
An EHCI device.
Definition: ehci.h:483

References assert(), bus, DBGC, ehci_endpoint::ehci, ehci_endpoint_poll(), EHCI_OP_USBSTS, ehci_root_poll(), EHCI_USBSTS_ASYNC, EHCI_USBSTS_CHANGE, EHCI_USBSTS_HCH, EHCI_USBSTS_PERIODIC, EHCI_USBSTS_PORT, EHCI_USBSTS_SYSERR, EHCI_USBSTS_USBERRINT, EHCI_USBSTS_USBINT, ehci_device::endpoints, ehci_endpoint::list, list_for_each_entry, ehci_device::name, ehci_device::op, ehci_device::ports, readl(), usb_bus_get_hostdata(), and writel().

◆ ehci_probe()

static int ehci_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 1968 of file ehci.c.

1968  {
1969  struct ehci_device *ehci;
1970  struct usb_port *port;
1971  unsigned long bar_start;
1972  size_t bar_size;
1973  unsigned int i;
1974  int rc;
1975 
1976  /* Allocate and initialise structure */
1977  ehci = zalloc ( sizeof ( *ehci ) );
1978  if ( ! ehci ) {
1979  rc = -ENOMEM;
1980  goto err_alloc;
1981  }
1982  ehci->name = pci->dev.name;
1983  INIT_LIST_HEAD ( &ehci->endpoints );
1984  INIT_LIST_HEAD ( &ehci->async );
1985  INIT_LIST_HEAD ( &ehci->periodic );
1986 
1987  /* Fix up PCI device */
1988  adjust_pci_device ( pci );
1989 
1990  /* Map registers */
1991  bar_start = pci_bar_start ( pci, EHCI_BAR );
1992  bar_size = pci_bar_size ( pci, EHCI_BAR );
1993  ehci->regs = pci_ioremap ( pci, bar_start, bar_size );
1994  if ( ! ehci->regs ) {
1995  rc = -ENODEV;
1996  goto err_ioremap;
1997  }
1998 
1999  /* Initialise EHCI device */
2000  ehci_init ( ehci, ehci->regs );
2001 
2002  /* Initialise USB legacy support and claim ownership */
2003  ehci_legacy_init ( ehci, pci );
2004  ehci_legacy_claim ( ehci, pci );
2005 
2006  /* Reset device */
2007  if ( ( rc = ehci_reset ( ehci ) ) != 0 )
2008  goto err_reset;
2009 
2010  /* Allocate USB bus */
2011  ehci->bus = alloc_usb_bus ( &pci->dev, ehci->ports, EHCI_MTU,
2012  &ehci_operations );
2013  if ( ! ehci->bus ) {
2014  rc = -ENOMEM;
2015  goto err_alloc_bus;
2016  }
2017  usb_bus_set_hostdata ( ehci->bus, ehci );
2018  usb_hub_set_drvdata ( ehci->bus->hub, ehci );
2019 
2020  /* Set port protocols */
2021  for ( i = 1 ; i <= ehci->ports ; i++ ) {
2022  port = usb_port ( ehci->bus->hub, i );
2023  port->protocol = USB_PROTO_2_0;
2024  }
2025 
2026  /* Register USB bus */
2027  if ( ( rc = register_usb_bus ( ehci->bus ) ) != 0 )
2028  goto err_register;
2029 
2030  pci_set_drvdata ( pci, ehci );
2031  return 0;
2032 
2033  unregister_usb_bus ( ehci->bus );
2034  err_register:
2035  free_usb_bus ( ehci->bus );
2036  err_alloc_bus:
2037  ehci_reset ( ehci );
2038  err_reset:
2039  ehci_legacy_release ( ehci, pci );
2040  iounmap ( ehci->regs );
2041  err_ioremap:
2042  free ( ehci );
2043  err_alloc:
2044  return rc;
2045 }
static void ehci_legacy_claim(struct ehci_device *ehci, struct pci_device *pci)
Claim ownership from BIOS.
Definition: ehci.c:280
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int ports
Number of ports.
Definition: ehci.h:495
struct list_head periodic
Periodic schedule.
Definition: ehci.h:521
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
USB 2.0.
Definition: usb.h:22
char name[40]
Name.
Definition: device.h:75
struct usb_bus * bus
USB bus.
Definition: ehci.h:524
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct device dev
Generic device.
Definition: pci.h:193
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1030
#define EHCI_MTU
Maximum transfer size.
Definition: ehci.h:30
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:344
#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 EHCI_BAR
EHCI PCI BAR.
Definition: ehci.h:36
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
const char * name
Name.
Definition: ehci.h:487
static struct usb_host_operations ehci_operations
USB host controller operations.
Definition: ehci.c:1929
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static int ehci_reset(struct ehci_device *ehci)
Reset EHCI device.
Definition: ehci.c:502
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Find the size of a PCI BAR.
Definition: pciextra.c:90
#define ENODEV
No such device.
Definition: errno.h:509
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct list_head endpoints
List of all endpoints.
Definition: ehci.h:514
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2112
static void ehci_legacy_init(struct ehci_device *ehci, struct pci_device *pci)
Initialise USB legacy support.
Definition: ehci.c:247
static void ehci_init(struct ehci_device *ehci, void *regs)
Initialise device.
Definition: ehci.c:69
static void ehci_legacy_release(struct ehci_device *ehci, struct pci_device *pci)
Release ownership back to BIOS.
Definition: ehci.c:340
void iounmap(volatile const void *io_addr)
Unmap I/O address.
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
void * regs
Registers.
Definition: ehci.h:485
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:945
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2171
An EHCI device.
Definition: ehci.h:483

References adjust_pci_device(), alloc_usb_bus(), ehci_device::async, ehci_device::bus, pci_device::dev, EHCI_BAR, ehci_init(), ehci_legacy_claim(), ehci_legacy_init(), ehci_legacy_release(), EHCI_MTU, ehci_operations, ehci_reset(), ehci_device::endpoints, ENODEV, ENOMEM, free, free_usb_bus(), usb_bus::hub, INIT_LIST_HEAD, iounmap(), device::name, ehci_device::name, pci_bar_size(), pci_bar_start(), pci_ioremap(), pci_set_drvdata(), ehci_device::periodic, port, ehci_device::ports, rc, register_usb_bus(), ehci_device::regs, unregister_usb_bus(), usb_bus_set_hostdata(), usb_hub_set_drvdata(), usb_port(), USB_PROTO_2_0, and zalloc().

◆ ehci_remove()

static void ehci_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 2052 of file ehci.c.

2052  {
2053  struct ehci_device *ehci = pci_get_drvdata ( pci );
2054  struct usb_bus *bus = ehci->bus;
2055 
2056  unregister_usb_bus ( bus );
2057  assert ( list_empty ( &ehci->async ) );
2058  assert ( list_empty ( &ehci->periodic ) );
2059  free_usb_bus ( bus );
2060  ehci_reset ( ehci );
2061  ehci_legacy_release ( ehci, pci );
2062  iounmap ( ehci->regs );
2063  free ( ehci );
2064 }
struct list_head periodic
Periodic schedule.
Definition: ehci.h:521
struct usb_bus * bus
USB bus.
Definition: ehci.h:524
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2147
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static int ehci_reset(struct ehci_device *ehci)
Reset EHCI device.
Definition: ehci.c:502
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:354
static void ehci_legacy_release(struct ehci_device *ehci, struct pci_device *pci)
Release ownership back to BIOS.
Definition: ehci.c:340
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * regs
Registers.
Definition: ehci.h:485
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
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
An EHCI device.
Definition: ehci.h:483

References assert(), ehci_device::async, bus, ehci_device::bus, ehci_legacy_release(), ehci_reset(), free, free_usb_bus(), iounmap(), list_empty, pci_get_drvdata(), ehci_device::periodic, ehci_device::regs, and unregister_usb_bus().

◆ ehci_shutdown()

static void ehci_shutdown ( int  booting)
static

Prepare for exit.

Parameters
bootingSystem is shutting down for OS boot

Definition at line 2086 of file ehci.c.

2086  {
2087  /* If we are shutting down to boot an OS, then prevent the
2088  * release of ownership back to BIOS.
2089  */
2090  ehci_legacy_prevent_release = booting;
2091 }
static int ehci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
Definition: ehci.c:239

References ehci_legacy_prevent_release.

◆ __startup_fn()

struct startup_fn ehci_startup __startup_fn ( STARTUP_LATE  )

Startup/shutdown function.

Variable Documentation

◆ ehci_legacy_prevent_release

int ehci_legacy_prevent_release
static

Prevent the release of ownership back to BIOS.

Definition at line 239 of file ehci.c.

Referenced by ehci_legacy_release(), and ehci_shutdown().

◆ ehci_operations

struct usb_host_operations ehci_operations
static

USB host controller operations.

Definition at line 1929 of file ehci.c.

Referenced by ehci_probe().

◆ ehci_ids

struct pci_device_id ehci_ids[]
static
Initial value:
= {
PCI_ROM ( 0xffff, 0xffff, "ehci", "EHCI", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:289

EHCI PCI device IDs.

Definition at line 2067 of file ehci.c.

◆ __pci_driver

struct pci_driver ehci_driver __pci_driver
Initial value:
= {
.ids = ehci_ids,
.id_count = ( sizeof ( ehci_ids ) / sizeof ( ehci_ids[0] ) ),
.probe = ehci_probe,
.remove = ehci_remove,
}
#define PCI_CLASS_ID(base, sub, progif)
Construct PCI class ID.
Definition: pci.h:183
static struct pci_device_id ehci_ids[]
EHCI PCI device IDs.
Definition: ehci.c:2067
#define PCI_CLASS_SERIAL
Definition: Pci22.h:272
static int ehci_probe(struct pci_device *pci)
Probe PCI device.
Definition: ehci.c:1968
static void ehci_remove(struct pci_device *pci)
Remove PCI device.
Definition: ehci.c:2052
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:278
#define PCI_CLASS_SERIAL_USB_EHCI
ECHI USB controller.
Definition: pci.h:135

EHCI PCI driver.

Definition at line 2072 of file ehci.c.