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 )
148  align = EHCI_MIN_ALIGN;
149 
150  return align;
151 }
#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 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:1054
#define BUS_TYPE_PCI
PCI bus type.
Definition: device.h:43
struct device * dev
Underlying hardware device.
Definition: usb.h:953
#define PCI_FIRST_FUNC(busdevfn)
Definition: pci.h:262
#define PCI_CLASS(base, sub, progif)
Construct PCI class.
Definition: pci.h:143
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:1049
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:278
#define PCI_CLASS_SERIAL_USB_OHCI
OHCI USB controller.
Definition: pci.h:133
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:132
struct device_description desc
Device description.
Definition: device.h:79
A USB bus.
Definition: usb.h:949
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:143
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:278
A PCI device.
Definition: pci.h:187
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:134
#define PCI_LAST_FUNC(busdevfn)
Definition: pci.h:263
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:210
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:313

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_dma ( 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_dma ( 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_dma ( ring->desc, len );
611  err_alloc_desc:
612  err_unreachable_queue:
613  free_dma ( 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 __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
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
A transfer descriptor.
Definition: ehci.h:229
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: ehci.h:391
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
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_dma(), ehci_ring::head, ehci_ring::iobuf, len, link, malloc_dma(), 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_dma ( ring->desc, ( EHCI_RING_COUNT * sizeof ( ring->desc[0] ) ) );
635 
636  /* Free queue head */
637  free_dma ( ring->head, sizeof ( *ring->head ) );
638 
639  /* Free I/O buffers */
640  free ( ring->iobuf );
641 }
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
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: ehci.h:391
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ehci_transfer_descriptor * desc
Transfer descriptors.
Definition: ehci.h:384

References assert(), ehci_ring::desc, EHCI_RING_COUNT, ehci_ring_fill(), free, free_dma(), 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 653 of file ehci.c.

656  {
657  struct ehci_transfer_descriptor *desc;
659  void *data;
660  size_t len;
661  size_t offset;
662  size_t frag_len;
663  unsigned int toggle;
664  unsigned int index;
665  unsigned int i;
666 
667  /* Sanity check */
668  assert ( iobuf != NULL );
669  assert ( count > 0 );
670 
671  /* Fail if ring does not have sufficient space */
672  if ( ehci_ring_remaining ( ring ) < count )
673  return -ENOBUFS;
674 
675  /* Fail if any portion is unreachable */
676  for ( i = 0 ; i < count ; i++ ) {
677  if ( ! xfer[i].len )
678  continue;
679  phys = ( virt_to_phys ( xfer[i].data ) + xfer[i].len - 1 );
680  if ( ( phys > 0xffffffffUL ) && ( ! ehci->addr64 ) )
681  return -ENOTSUP;
682  }
683 
684  /* Enqueue each transfer, recording the I/O buffer with the last */
685  for ( ; count ; ring->prod++, xfer++ ) {
686 
687  /* Populate descriptor header */
688  index = ( ring->prod % EHCI_RING_COUNT );
689  desc = &ring->desc[index];
690  toggle = ( xfer->flags & EHCI_FL_TOGGLE );
691  assert ( xfer->len <= EHCI_LEN_MASK );
693  desc->len = cpu_to_le16 ( xfer->len | toggle );
694  desc->flags = ( xfer->flags | EHCI_FL_CERR_MAX );
695 
696  /* Populate buffer pointers */
697  data = xfer->data;
698  len = xfer->len;
699  for ( i = 0 ; len ; i++ ) {
700 
701  /* Calculate length of this fragment */
702  phys = virt_to_phys ( data );
703  offset = ( phys & ( EHCI_PAGE_ALIGN - 1 ) );
704  frag_len = ( EHCI_PAGE_ALIGN - offset );
705  if ( frag_len > len )
706  frag_len = len;
707 
708  /* Sanity checks */
709  assert ( ( i == 0 ) || ( offset == 0 ) );
710  assert ( i < ( sizeof ( desc->low ) /
711  sizeof ( desc->low[0] ) ) );
712 
713  /* Populate buffer pointer */
714  desc->low[i] = cpu_to_le32 ( phys );
715  if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
716  desc->high[i] =
717  cpu_to_le32 ( ((uint64_t) phys) >> 32 );
718  }
719 
720  /* Move to next fragment */
721  data += frag_len;
722  len -= frag_len;
723  }
724 
725  /* Ensure everything is valid before activating descriptor */
726  wmb();
727  desc->status = EHCI_STATUS_ACTIVE;
728 
729  /* Record I/O buffer against last ring index */
730  if ( --count == 0 )
731  ring->iobuf[index] = iobuf;
732  }
733 
734  return 0;
735 }
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 743 of file ehci.c.

743  {
744  struct ehci_transfer_descriptor *desc;
745  struct io_buffer *iobuf;
746  unsigned int index = ( ring->cons % EHCI_RING_COUNT );
747 
748  /* Sanity check */
749  assert ( ehci_ring_fill ( ring ) > 0 );
750 
751  /* Mark descriptor as inactive (and not halted) */
752  desc = &ring->desc[index];
753  desc->status = 0;
754 
755  /* Retrieve I/O buffer */
756  iobuf = ring->iobuf[index];
757  ring->iobuf[index] = NULL;
758 
759  /* Update consumer counter */
760  ring->cons++;
761 
762  return iobuf;
763 }
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:32

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 778 of file ehci.c.

778  {
779 
780  return ( virt_to_phys ( queue ) | EHCI_LINK_TYPE_QH );
781 }
#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 788 of file ehci.c.

788  {
789  struct ehci_endpoint *endpoint;
790  struct ehci_queue_head *queue;
791  uint32_t link;
792 
793  /* Build schedule in reverse order of execution. Provided
794  * that we only ever add or remove single endpoints, this can
795  * safely run concurrently with hardware execution of the
796  * schedule.
797  */
798  link = ehci_link_qh ( ehci->head );
799  list_for_each_entry_reverse ( endpoint, &ehci->async, schedule ) {
800  queue = endpoint->ring.head;
801  queue->link = cpu_to_le32 ( link );
802  wmb();
803  link = ehci_link_qh ( queue );
804  }
805  ehci->head->link = cpu_to_le32 ( link );
806  wmb();
807 }
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:778
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 814 of file ehci.c.

814  {
815  struct ehci_device *ehci = endpoint->ehci;
816 
817  /* Add to end of schedule */
818  list_add_tail ( &endpoint->schedule, &ehci->async );
819 
820  /* Rebuild schedule */
821  ehci_async_schedule ( ehci );
822 }
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:788
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 830 of file ehci.c.

830  {
831  struct ehci_device *ehci = endpoint->ehci;
832  uint32_t usbcmd;
833  uint32_t usbsts;
834  unsigned int i;
835 
836  /* Remove from schedule */
837  list_check_contains_entry ( endpoint, &ehci->async, schedule );
838  list_del ( &endpoint->schedule );
839 
840  /* Rebuild schedule */
841  ehci_async_schedule ( ehci );
842 
843  /* Request notification when asynchronous schedule advances */
844  usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
845  usbcmd |= EHCI_USBCMD_ASYNC_ADVANCE;
846  writel ( usbcmd, ehci->op + EHCI_OP_USBCMD );
847 
848  /* Wait for asynchronous schedule to advance */
849  for ( i = 0 ; i < EHCI_ASYNC_ADVANCE_MAX_WAIT_MS ; i++ ) {
850 
851  /* Check for asynchronous schedule advancing */
852  usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
853  if ( usbsts & EHCI_USBSTS_ASYNC_ADVANCE ) {
854  usbsts &= ~EHCI_USBSTS_CHANGE;
855  usbsts |= EHCI_USBSTS_ASYNC_ADVANCE;
856  writel ( usbsts, ehci->op + EHCI_OP_USBSTS );
857  return 0;
858  }
859 
860  /* Delay */
861  mdelay ( 1 );
862  }
863 
864  /* Bad things will probably happen now */
865  DBGC ( ehci, "EHCI %s timed out waiting for asynchronous schedule "
866  "to advance\n", ehci->name );
867  return -ETIMEDOUT;
868 }
#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:788
#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 875 of file ehci.c.

875  {
876  struct ehci_endpoint *endpoint;
877  struct ehci_queue_head *queue;
878  uint32_t link;
879  unsigned int frames;
880  unsigned int max_interval;
881  unsigned int i;
882 
883  /* Build schedule in reverse order of execution. Provided
884  * that we only ever add or remove single endpoints, this can
885  * safely run concurrently with hardware execution of the
886  * schedule.
887  */
888  DBGCP ( ehci, "EHCI %s periodic schedule: ", ehci->name );
890  list_for_each_entry_reverse ( endpoint, &ehci->periodic, schedule ) {
891  queue = endpoint->ring.head;
892  queue->link = cpu_to_le32 ( link );
893  wmb();
894  DBGCP ( ehci, "%s%d",
895  ( ( link == EHCI_LINK_TERMINATE ) ? "" : "<-" ),
896  endpoint->ep->interval );
897  link = ehci_link_qh ( queue );
898  }
899  DBGCP ( ehci, "\n" );
900 
901  /* Populate periodic frame list */
902  DBGCP ( ehci, "EHCI %s periodic frame list:", ehci->name );
903  frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
904  for ( i = 0 ; i < frames ; i++ ) {
905 
906  /* Calculate maximum interval (in microframes) which
907  * may appear as part of this frame list.
908  */
909  if ( i == 0 ) {
910  /* Start of list: include all endpoints */
911  max_interval = -1U;
912  } else {
913  /* Calculate highest power-of-two frame interval */
914  max_interval = ( 1 << ( ffs ( i ) - 1 ) );
915  /* Convert to microframes */
916  max_interval <<= 3;
917  /* Round up to nearest 2^n-1 */
918  max_interval = ( ( max_interval << 1 ) - 1 );
919  }
920 
921  /* Find first endpoint in schedule satisfying this
922  * maximum interval constraint.
923  */
925  list_for_each_entry ( endpoint, &ehci->periodic, schedule ) {
926  if ( endpoint->ep->interval <= max_interval ) {
927  queue = endpoint->ring.head;
928  link = ehci_link_qh ( queue );
929  DBGCP ( ehci, " %d:%d",
930  i, endpoint->ep->interval );
931  break;
932  }
933  }
934  ehci->frame[i].link = cpu_to_le32 ( link );
935  }
936  wmb();
937  DBGCP ( ehci, "\n" );
938 }
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:778
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 945 of file ehci.c.

945  {
946  struct ehci_device *ehci = endpoint->ehci;
947  struct ehci_endpoint *before;
948  unsigned int interval = endpoint->ep->interval;
949 
950  /* Find first endpoint with a smaller interval */
951  list_for_each_entry ( before, &ehci->periodic, schedule ) {
952  if ( before->ep->interval < interval )
953  break;
954  }
955  list_add_tail ( &endpoint->schedule, &before->schedule );
956 
957  /* Rebuild schedule */
959 }
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:875
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 967 of file ehci.c.

967  {
968  struct ehci_device *ehci = endpoint->ehci;
969 
970  /* Remove from schedule */
971  list_check_contains_entry ( endpoint, &ehci->periodic, schedule );
972  list_del ( &endpoint->schedule );
973 
974  /* Rebuild schedule */
975  ehci_periodic_schedule ( ehci );
976 
977  /* Delay for a whole USB frame (with a 100% safety margin) */
978  mdelay ( 2 );
979 
980  return 0;
981 }
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:875
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 988 of file ehci.c.

988  {
989  struct usb_endpoint *ep = endpoint->ep;
990  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
991 
993  ehci_periodic_add ( endpoint );
994  } else {
995  ehci_async_add ( endpoint );
996  }
997 }
#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:945
#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:814
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 1005 of file ehci.c.

1005  {
1006  struct usb_endpoint *ep = endpoint->ep;
1007  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1008 
1009  if ( attr == USB_ENDPOINT_ATTR_INTERRUPT ) {
1010  return ehci_periodic_del ( endpoint );
1011  } else {
1012  return ehci_async_del ( endpoint );
1013  }
1014 }
#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:967
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:830

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 1029 of file ehci.c.

1029  {
1030  struct usb_device *usb = ep->usb;
1031  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1032  uint32_t chr;
1033 
1034  /* Determine basic characteristics */
1035  chr = ( EHCI_CHR_ADDRESS ( usb->address ) |
1037  EHCI_CHR_MAX_LEN ( ep->mtu ) );
1038 
1039  /* Control endpoints require manual control of the data toggle */
1041  chr |= EHCI_CHR_TOGGLE;
1042 
1043  /* Determine endpoint speed */
1044  if ( usb->speed == USB_SPEED_HIGH ) {
1045  chr |= EHCI_CHR_EPS_HIGH;
1046  } else {
1047  if ( usb->speed == USB_SPEED_FULL ) {
1048  chr |= EHCI_CHR_EPS_FULL;
1049  } else {
1050  chr |= EHCI_CHR_EPS_LOW;
1051  }
1053  chr |= EHCI_CHR_CONTROL;
1054  }
1055 
1056  return chr;
1057 }
#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:716
unsigned int speed
Device speed.
Definition: usb.h:712
#define EHCI_CHR_ENDPOINT(address)
Endpoint number.
Definition: ehci.h:308
A USB device.
Definition: usb.h:706
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:728
#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 1065 of file ehci.c.

1065  {
1066  struct usb_device *usb = ep->usb;
1067  struct usb_port *tt = usb_transaction_translator ( usb );
1068  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1069  uint32_t cap;
1070  unsigned int i;
1071 
1072  /* Determine basic capabilities */
1073  cap = EHCI_CAP_MULT ( ep->burst + 1 );
1074 
1075  /* Determine interrupt schedule mask, if applicable */
1076  if ( ( attr == USB_ENDPOINT_ATTR_INTERRUPT ) &&
1077  ( ( ep->interval != 0 ) /* avoid infinite loop */ ) ) {
1078  for ( i = 0 ; i < 8 /* microframes per frame */ ;
1079  i += ep->interval ) {
1080  cap |= EHCI_CAP_INTR_SCHED ( i );
1081  }
1082  }
1083 
1084  /* Set transaction translator hub address and port, if applicable */
1085  if ( tt ) {
1086  assert ( tt->hub->usb );
1087  cap |= ( EHCI_CAP_TT_HUB ( tt->hub->usb->address ) |
1088  EHCI_CAP_TT_PORT ( tt->address ) );
1091  }
1092 
1093  return cap;
1094 }
#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:818
unsigned int address
Device address, if assigned.
Definition: usb.h:716
#define EHCI_CAP_SPLIT_SCHED_DEFAULT
Default split completion schedule mask.
Definition: ehci.h:354
A USB port.
Definition: usb.h:796
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:830
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:706
#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:2274
unsigned int address
Port address.
Definition: usb.h:800
struct usb_hub * hub
USB hub.
Definition: usb.h:798
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:728
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 1101 of file ehci.c.

1101  {
1102  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1103  struct ehci_queue_head *head;
1104 
1105  /* Update queue characteristics and capabilities */
1106  head = endpoint->ring.head;
1108  head->cap = cpu_to_le32 ( ehci_endpoint_capabilities ( ep ) );
1109 }
static uint32_t ehci_endpoint_capabilities(struct usb_endpoint *ep)
Determine endpoint capabilities.
Definition: ehci.c:1065
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:1029
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 1117 of file ehci.c.

1117  {
1118  struct usb_device *usb = ep->usb;
1119  struct ehci_device *ehci = usb_get_hostdata ( usb );
1120  struct ehci_endpoint *endpoint;
1121  int rc;
1122 
1123  /* Allocate and initialise structure */
1124  endpoint = zalloc ( sizeof ( *endpoint ) );
1125  if ( ! endpoint ) {
1126  rc = -ENOMEM;
1127  goto err_alloc;
1128  }
1129  endpoint->ehci = ehci;
1130  endpoint->ep = ep;
1131  usb_endpoint_set_hostdata ( ep, endpoint );
1132 
1133  /* Initialise descriptor ring */
1134  if ( ( rc = ehci_ring_alloc ( ehci, &endpoint->ring ) ) != 0 )
1135  goto err_ring_alloc;
1136 
1137  /* Update queue characteristics and capabilities */
1139 
1140  /* Add to list of endpoints */
1141  list_add_tail ( &endpoint->list, &ehci->endpoints );
1142 
1143  /* Add to schedule */
1144  ehci_schedule_add ( endpoint );
1145 
1146  return 0;
1147 
1148  ehci_ring_free ( &endpoint->ring );
1149  err_ring_alloc:
1150  free ( endpoint );
1151  err_alloc:
1152  return rc;
1153 }
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:1101
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:706
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:778
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:988
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:728
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 1160 of file ehci.c.

1160  {
1161  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1162  struct ehci_device *ehci = endpoint->ehci;
1163  struct usb_device *usb = ep->usb;
1164  struct io_buffer *iobuf;
1165  int rc;
1166 
1167  /* Remove from schedule */
1168  if ( ( rc = ehci_schedule_del ( endpoint ) ) != 0 ) {
1169  /* No way to prevent hardware from continuing to
1170  * access the memory, so leak it.
1171  */
1172  DBGC ( ehci, "EHCI %s %s could not unschedule: %s\n",
1173  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
1174  return;
1175  }
1176 
1177  /* Cancel any incomplete transfers */
1178  while ( ehci_ring_fill ( &endpoint->ring ) ) {
1179  iobuf = ehci_dequeue ( &endpoint->ring );
1180  if ( iobuf )
1181  usb_complete_err ( ep, iobuf, -ECANCELED );
1182  }
1183 
1184  /* Remove from list of endpoints */
1185  list_del ( &endpoint->list );
1186 
1187  /* Free descriptor ring */
1188  ehci_ring_free ( &endpoint->ring );
1189 
1190  /* Free endpoint */
1191  free ( endpoint );
1192 }
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:743
#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:708
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
A USB device.
Definition: usb.h:706
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:1005
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:728
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:569
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:32

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 1200 of file ehci.c.

1200  {
1201  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1202  struct ehci_ring *ring = &endpoint->ring;
1203  struct ehci_transfer_descriptor *cache = &ring->head->cache;
1204  uint32_t link;
1205 
1206  /* Sanity checks */
1207  assert ( ! ( cache->status & EHCI_STATUS_ACTIVE ) );
1208  assert ( cache->status & EHCI_STATUS_HALTED );
1209 
1210  /* Reset residual count */
1211  ring->residual = 0;
1212 
1213  /* Reset data toggle */
1214  cache->len = 0;
1215 
1216  /* Prepare to restart at next unconsumed descriptor */
1217  link = virt_to_phys ( &ring->desc[ ring->cons % EHCI_RING_COUNT ] );
1218  cache->next = cpu_to_le32 ( link );
1219 
1220  /* Restart ring */
1221  wmb();
1222  cache->status = 0;
1223 
1224  return 0;
1225 }
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 1233 of file ehci.c.

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

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 1248 of file ehci.c.

1249  {
1250  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1251  struct ehci_device *ehci = endpoint->ehci;
1252  struct usb_setup_packet *packet;
1253  unsigned int input;
1254  struct ehci_transfer xfers[3];
1255  struct ehci_transfer *xfer = xfers;
1256  size_t len;
1257  int rc;
1258 
1259  /* Construct setup stage */
1260  assert ( iob_len ( iobuf ) >= sizeof ( *packet ) );
1261  packet = iobuf->data;
1262  iob_pull ( iobuf, sizeof ( *packet ) );
1263  xfer->data = packet;
1264  xfer->len = sizeof ( *packet );
1265  xfer->flags = EHCI_FL_PID_SETUP;
1266  xfer++;
1267 
1268  /* Construct data stage, if applicable */
1269  len = iob_len ( iobuf );
1270  input = ( packet->request & cpu_to_le16 ( USB_DIR_IN ) );
1271  if ( len ) {
1272  xfer->data = iobuf->data;
1273  xfer->len = len;
1274  xfer->flags = ( EHCI_FL_TOGGLE |
1275  ( input ? EHCI_FL_PID_IN : EHCI_FL_PID_OUT ) );
1276  xfer++;
1277  }
1278 
1279  /* Construct status stage */
1280  xfer->data = NULL;
1281  xfer->len = 0;
1282  xfer->flags = ( EHCI_FL_TOGGLE | EHCI_FL_IOC |
1283  ( ( len && input ) ? EHCI_FL_PID_OUT : EHCI_FL_PID_IN));
1284  xfer++;
1285 
1286  /* Enqueue transfer */
1287  if ( ( rc = ehci_enqueue ( ehci, &endpoint->ring, iobuf, xfers,
1288  ( xfer - xfers ) ) ) != 0 )
1289  return rc;
1290 
1291  return 0;
1292 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
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
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:151
#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:44
#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:653
#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 1301 of file ehci.c.

1301  {
1302  unsigned int count;
1303 
1304  /* Split into 16kB transfers. A single transfer can handle up
1305  * to 20kB if it happens to be page-aligned, or up to 16kB
1306  * with arbitrary alignment. We simplify the code by assuming
1307  * that we can fit only 16kB into each transfer.
1308  */
1309  count = ( ( len + EHCI_MTU - 1 ) / EHCI_MTU );
1310 
1311  /* Append a zero-length transfer if applicable */
1312  if ( zlp || ( count == 0 ) )
1313  count++;
1314 
1315  return count;
1316 }
#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 1326 of file ehci.c.

1327  {
1328  struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1329  struct ehci_device *ehci = endpoint->ehci;
1330  void *data = iobuf->data;
1331  size_t len = iob_len ( iobuf );
1332  unsigned int count = ehci_endpoint_count ( len, zlp );
1333  unsigned int input = ( ep->address & USB_DIR_IN );
1334  unsigned int flags = ( input ? EHCI_FL_PID_IN : EHCI_FL_PID_OUT );
1335  struct ehci_transfer xfers[count];
1336  struct ehci_transfer *xfer = xfers;
1337  size_t xfer_len;
1338  unsigned int i;
1339  int rc;
1340 
1341  /* Create transfers */
1342  for ( i = 0 ; i < count ; i++ ) {
1343 
1344  /* Calculate transfer length */
1345  xfer_len = EHCI_MTU;
1346  if ( xfer_len > len )
1347  xfer_len = len;
1348 
1349  /* Create transfer */
1350  xfer->data = data;
1351  xfer->len = xfer_len;
1352  xfer->flags = flags;
1353 
1354  /* Move to next transfer */
1355  data += xfer_len;
1356  len -= xfer_len;
1357  xfer++;
1358  }
1359  xfer[-1].flags |= EHCI_FL_IOC;
1360 
1361  /* Enqueue transfer */
1362  if ( ( rc = ehci_enqueue ( ehci, &endpoint->ring, iobuf, xfers,
1363  count ) ) != 0 )
1364  return rc;
1365 
1366  return 0;
1367 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An EHCI endpoint.
Definition: ehci.h:528
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:1301
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:151
#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:44
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:653
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 1374 of file ehci.c.

1374  {
1375  struct ehci_device *ehci = endpoint->ehci;
1376  struct ehci_ring *ring = &endpoint->ring;
1377  struct ehci_transfer_descriptor *desc;
1378  struct usb_endpoint *ep = endpoint->ep;
1379  struct usb_device *usb = ep->usb;
1380  struct io_buffer *iobuf;
1381  unsigned int index;
1382  unsigned int status;
1383  int rc;
1384 
1385  /* Consume all completed descriptors */
1386  while ( ehci_ring_fill ( &endpoint->ring ) ) {
1387 
1388  /* Stop if we reach an uncompleted descriptor */
1389  rmb();
1390  index = ( ring->cons % EHCI_RING_COUNT );
1391  desc = &ring->desc[index];
1392  status = desc->status;
1393  if ( status & EHCI_STATUS_ACTIVE )
1394  break;
1395 
1396  /* Consume this descriptor */
1397  iobuf = ehci_dequeue ( ring );
1398 
1399  /* If we have encountered an error, then consume all
1400  * remaining descriptors in this transaction, report
1401  * the error to the USB core, and stop further
1402  * processing.
1403  */
1404  if ( status & EHCI_STATUS_HALTED ) {
1405  rc = -EIO_STATUS ( status );
1406  DBGC ( ehci, "EHCI %s %s completion %d failed (status "
1407  "%02x): %s\n", usb->name,
1408  usb_endpoint_name ( ep ), index, status,
1409  strerror ( rc ) );
1410  while ( ! iobuf )
1411  iobuf = ehci_dequeue ( ring );
1412  usb_complete_err ( endpoint->ep, iobuf, rc );
1413  return;
1414  }
1415 
1416  /* Accumulate residual data count */
1417  ring->residual += ( le16_to_cpu ( desc->len ) & EHCI_LEN_MASK );
1418 
1419  /* If this is not the end of a transaction (i.e. has
1420  * no I/O buffer), then continue to next descriptor.
1421  */
1422  if ( ! iobuf )
1423  continue;
1424 
1425  /* Update I/O buffer length */
1426  iob_unput ( iobuf, ring->residual );
1427  ring->residual = 0;
1428 
1429  /* Report completion to USB core */
1430  usb_complete ( endpoint->ep, iobuf );
1431  }
1432 }
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:743
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:708
struct ehci_ring ring
Transfer descriptor ring.
Definition: ehci.h:539
A USB device.
Definition: usb.h:706
#define iob_unput(iobuf, len)
Definition: iobuf.h:131
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:1064
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:728
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:569
An EHCI device.
Definition: ehci.h:483
A persistent I/O buffer.
Definition: iobuf.h:32

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 1447 of file ehci.c.

1447  {
1448  struct ehci_device *ehci = usb_bus_get_hostdata ( usb->port->hub->bus );
1449 
1450  usb_set_hostdata ( usb, ehci );
1451  return 0;
1452 }
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition: usb.h:767
struct usb_port * port
USB port.
Definition: usb.h:710
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1039
struct usb_hub * hub
USB hub.
Definition: usb.h:798
struct usb_bus * bus
USB bus.
Definition: usb.h:828
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 1459 of file ehci.c.

1459  {
1460  struct ehci_device *ehci = usb_get_hostdata ( usb );
1461  struct usb_bus *bus = ehci->bus;
1462 
1463  /* Free device address, if assigned */
1464  if ( usb->address )
1465  usb_free_address ( bus, usb->address );
1466 }
struct usb_bus * bus
USB bus.
Definition: ehci.h:524
unsigned int address
Device address, if assigned.
Definition: usb.h:716
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
Definition: usb.c:2198
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:778
A USB bus.
Definition: usb.h:949
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 1474 of file ehci.c.

1474  {
1475  struct ehci_device *ehci = usb_get_hostdata ( usb );
1476  struct usb_bus *bus = ehci->bus;
1477  struct usb_endpoint *ep0 = usb_endpoint ( usb, USB_EP0_ADDRESS );
1478  int address;
1479  int rc;
1480 
1481  /* Sanity checks */
1482  assert ( usb->address == 0 );
1483  assert ( ep0 != NULL );
1484 
1485  /* Allocate device address */
1487  if ( address < 0 ) {
1488  rc = address;
1489  DBGC ( ehci, "EHCI %s could not allocate address: %s\n",
1490  usb->name, strerror ( rc ) );
1491  goto err_alloc_address;
1492  }
1493 
1494  /* Set address */
1495  if ( ( rc = usb_set_address ( usb, address ) ) != 0 )
1496  goto err_set_address;
1497 
1498  /* Update device address */
1499  usb->address = address;
1500 
1501  /* Update control endpoint characteristics and capabilities */
1502  ehci_endpoint_update ( ep0 );
1503 
1504  return 0;
1505 
1506  err_set_address:
1508  err_alloc_address:
1509  return rc;
1510 }
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:1101
#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:716
static int usb_set_address(struct usb_device *usb, unsigned int address)
Set address.
Definition: usb.h:1136
A USB endpoint.
Definition: usb.h:389
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
char name[32]
Name.
Definition: usb.h:708
static struct usb_endpoint * usb_endpoint(struct usb_device *usb, unsigned int address)
Get USB endpoint.
Definition: usb.h:789
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:2198
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:778
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:2178
A USB bus.
Definition: usb.h:949
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 1525 of file ehci.c.

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

◆ ehci_hub_close()

static void ehci_hub_close ( struct usb_hub *hub  __unused)
static

Close hub.

Parameters
hubUSB hub

Definition at line 1536 of file ehci.c.

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

◆ 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 1554 of file ehci.c.

1554  {
1555  struct usb_bus *bus = hub->bus;
1556  struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
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  /* Record hub driver private data */
1575  usb_hub_set_drvdata ( hub, ehci );
1576 
1577  return 0;
1578 }
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
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1039
struct usb_hub * hub
Root hub.
Definition: usb.h:972
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:920
struct usb_bus * bus
USB bus.
Definition: usb.h:828
A USB bus.
Definition: usb.h:949
uint8_t bus
Bus.
Definition: edd.h:14
#define EHCI_CONFIGFLAG_CF
Configure flag.
Definition: ehci.h:174
An EHCI device.
Definition: ehci.h:483

References bus, usb_hub::bus, EHCI_CONFIGFLAG_CF, EHCI_OP_CONFIGFLAG, EHCI_OP_PORTSC, EHCI_PORT_POWER_DELAY_MS, EHCI_PORTSC_CHANGE, EHCI_PORTSC_PP, usb_bus::hub, mdelay(), ehci_device::op, ehci_device::ports, readl(), usb_bus_get_hostdata(), usb_hub_set_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 1585 of file ehci.c.

1585  {
1586  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1587 
1588  /* Route all ports back to companion controllers */
1589  writel ( 0, ehci->op + EHCI_OP_CONFIGFLAG );
1590 
1591  /* Clear hub driver private data */
1592  usb_hub_set_drvdata ( hub, NULL );
1593 }
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_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:920
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:931
An EHCI device.
Definition: ehci.h:483

References EHCI_OP_CONFIGFLAG, NULL, ehci_device::op, usb_hub_get_drvdata(), usb_hub_set_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 1602 of file ehci.c.

1602  {
1603  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1604  uint32_t portsc;
1605  unsigned int line;
1606  unsigned int i;
1607 
1608  /* Check for a low-speed device */
1609  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1610  line = EHCI_PORTSC_LINE_STATUS ( portsc );
1611  if ( line == EHCI_PORTSC_LINE_STATUS_LOW ) {
1612  DBGC ( ehci, "EHCI %s-%d detected low-speed device: "
1613  "disowning\n", ehci->name, port->address );
1614  goto disown;
1615  }
1616 
1617  /* Reset port */
1618  portsc &= ~( EHCI_PORTSC_PED | EHCI_PORTSC_CHANGE );
1619  portsc |= EHCI_PORTSC_PR;
1620  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1622  portsc &= ~EHCI_PORTSC_PR;
1623  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1624 
1625  /* Wait for reset to complete */
1626  for ( i = 0 ; i < EHCI_PORT_RESET_MAX_WAIT_MS ; i++ ) {
1627 
1628  /* Check port status */
1629  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1630  if ( ! ( portsc & EHCI_PORTSC_PR ) ) {
1631  if ( portsc & EHCI_PORTSC_PED )
1632  return 0;
1633  DBGC ( ehci, "EHCI %s-%d not enabled after reset: "
1634  "disowning\n", ehci->name, port->address );
1635  goto disown;
1636  }
1637 
1638  /* Delay */
1639  mdelay ( 1 );
1640  }
1641 
1642  DBGC ( ehci, "EHCI %s-%d timed out waiting for port to reset\n",
1643  ehci->name, port->address );
1644  return -ETIMEDOUT;
1645 
1646  disown:
1647  /* Disown port */
1648  portsc &= ~EHCI_PORTSC_CHANGE;
1649  portsc |= EHCI_PORTSC_OWNER;
1650  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1651 
1652  /* Delay to allow child companion controllers to settle */
1654 
1655  /* Poll child companion controllers */
1656  ehci_poll_companions ( ehci );
1657 
1658  return -ENODEV;
1659 }
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:1284
#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:931
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 1668 of file ehci.c.

1668  {
1669  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1670  uint32_t portsc;
1671 
1672  /* Disable port */
1673  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1674  portsc &= ~( EHCI_PORTSC_PED | EHCI_PORTSC_CHANGE );
1675  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1676 
1677  return 0;
1678 }
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:931
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 1687 of file ehci.c.

1687  {
1688  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1689  uint32_t portsc;
1690  unsigned int speed;
1691  unsigned int line;
1692  int ccs;
1693  int csc;
1694  int ped;
1695 
1696  /* Read port status */
1697  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1698  DBGC2 ( ehci, "EHCI %s-%d status is %08x\n",
1699  ehci->name, port->address, portsc );
1700  ccs = ( portsc & EHCI_PORTSC_CCS );
1701  csc = ( portsc & EHCI_PORTSC_CSC );
1702  ped = ( portsc & EHCI_PORTSC_PED );
1703  line = EHCI_PORTSC_LINE_STATUS ( portsc );
1704 
1705  /* Record disconnections and clear changes */
1706  port->disconnected |= csc;
1707  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1708 
1709  /* Determine port speed */
1710  if ( ! ccs ) {
1711  /* Port not connected */
1712  speed = USB_SPEED_NONE;
1713  } else if ( line == EHCI_PORTSC_LINE_STATUS_LOW ) {
1714  /* Detected as low-speed */
1715  speed = USB_SPEED_LOW;
1716  } else if ( ped ) {
1717  /* Port already enabled: must be high-speed */
1718  speed = USB_SPEED_HIGH;
1719  } else {
1720  /* Not low-speed and not yet enabled. Could be either
1721  * full-speed or high-speed; we can't yet tell.
1722  */
1723  speed = USB_SPEED_FULL;
1724  }
1725  port->speed = speed;
1726  return 0;
1727 }
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:931
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 1737 of file ehci.c.

1738  {
1739  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1740 
1741  /* Should never be called; this is a root hub */
1742  DBGC ( ehci, "EHCI %s-%d nonsensical CLEAR_TT for %s %s\n", ehci->name,
1743  port->address, ep->usb->name, usb_endpoint_name ( ep ) );
1744 
1745  return -ENOTSUP;
1746 }
#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:708
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:931
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 1754 of file ehci.c.

1754  {
1755  struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1756  uint32_t portsc;
1757  uint32_t change;
1758 
1759  /* Do nothing unless something has changed */
1760  portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1761  change = ( portsc & EHCI_PORTSC_CHANGE );
1762  if ( ! change )
1763  return;
1764 
1765  /* Record disconnections and clear changes */
1766  port->disconnected |= ( portsc & EHCI_PORTSC_CSC );
1767  writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1768 
1769  /* Report port status change */
1770  usb_port_changed ( port );
1771 }
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:1794
#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:931
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 1786 of file ehci.c.

1786  {
1787  struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1788  unsigned int frames;
1789  size_t len;
1790  int rc;
1791 
1792  /* Sanity checks */
1793  assert ( list_empty ( &ehci->async ) );
1794  assert ( list_empty ( &ehci->periodic ) );
1795 
1796  /* Allocate and initialise asynchronous queue head */
1797  ehci->head = malloc_dma ( sizeof ( *ehci->head ),
1798  ehci_align ( sizeof ( *ehci->head ) ) );
1799  if ( ! ehci->head ) {
1800  rc = -ENOMEM;
1801  goto err_alloc_head;
1802  }
1803  memset ( ehci->head, 0, sizeof ( *ehci->head ) );
1804  ehci->head->chr = cpu_to_le32 ( EHCI_CHR_HEAD );
1807  ehci_async_schedule ( ehci );
1808  writel ( virt_to_phys ( ehci->head ),
1809  ehci->op + EHCI_OP_ASYNCLISTADDR );
1810 
1811  /* Use async queue head to determine control data structure segment */
1812  ehci->ctrldssegment =
1813  ( ( ( uint64_t ) virt_to_phys ( ehci->head ) ) >> 32 );
1814  if ( ehci->addr64 ) {
1815  writel ( ehci->ctrldssegment, ehci->op + EHCI_OP_CTRLDSSEGMENT);
1816  } else if ( ehci->ctrldssegment ) {
1817  DBGC ( ehci, "EHCI %s CTRLDSSEGMENT not supported\n",
1818  ehci->name );
1819  rc = -ENOTSUP;
1820  goto err_ctrldssegment;
1821  }
1822 
1823  /* Allocate periodic frame list */
1824  frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
1825  len = ( frames * sizeof ( ehci->frame[0] ) );
1826  ehci->frame = malloc_dma ( len, EHCI_PAGE_ALIGN );
1827  if ( ! ehci->frame ) {
1828  rc = -ENOMEM;
1829  goto err_alloc_frame;
1830  }
1831  if ( ( rc = ehci_ctrl_reachable ( ehci, ehci->frame ) ) != 0 ) {
1832  DBGC ( ehci, "EHCI %s frame list unreachable\n", ehci->name );
1833  goto err_unreachable_frame;
1834  }
1835  ehci_periodic_schedule ( ehci );
1836  writel ( virt_to_phys ( ehci->frame ),
1837  ehci->op + EHCI_OP_PERIODICLISTBASE );
1838 
1839  /* Start controller */
1840  ehci_run ( ehci );
1841 
1842  return 0;
1843 
1844  ehci_stop ( ehci );
1845  err_unreachable_frame:
1846  free_dma ( ehci->frame, len );
1847  err_alloc_frame:
1848  err_ctrldssegment:
1849  free_dma ( ehci->head, sizeof ( *ehci->head ) );
1850  err_alloc_head:
1851  return rc;
1852 }
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 __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:788
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:1039
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 *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#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 free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
static void ehci_periodic_schedule(struct ehci_device *ehci)
(Re)build periodic schedule
Definition: ehci.c:875
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_dma(), ehci_device::head, len, list_empty, malloc_dma(), 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 1859 of file ehci.c.

1859  {
1860  struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1861  unsigned int frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
1862 
1863  /* Sanity checks */
1864  assert ( list_empty ( &ehci->async ) );
1865  assert ( list_empty ( &ehci->periodic ) );
1866 
1867  /* Stop controller */
1868  ehci_stop ( ehci );
1869 
1870  /* Free periodic frame list */
1871  free_dma ( ehci->frame, ( frames * sizeof ( ehci->frame[0] ) ) );
1872 
1873  /* Free asynchronous schedule */
1874  free_dma ( ehci->head, sizeof ( *ehci->head ) );
1875 }
#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:1039
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
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_dma(), 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 1882 of file ehci.c.

1882  {
1883  struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1884  struct usb_hub *hub = bus->hub;
1885  struct ehci_endpoint *endpoint;
1886  unsigned int i;
1887  uint32_t usbsts;
1888  uint32_t change;
1889 
1890  /* Do nothing unless something has changed */
1891  usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
1892  assert ( usbsts & EHCI_USBSTS_ASYNC );
1893  assert ( usbsts & EHCI_USBSTS_PERIODIC );
1894  assert ( ! ( usbsts & EHCI_USBSTS_HCH ) );
1895  change = ( usbsts & EHCI_USBSTS_CHANGE );
1896  if ( ! change )
1897  return;
1898 
1899  /* Acknowledge changes */
1900  writel ( usbsts, ehci->op + EHCI_OP_USBSTS );
1901 
1902  /* Process completions, if applicable */
1903  if ( change & ( EHCI_USBSTS_USBINT | EHCI_USBSTS_USBERRINT ) ) {
1904 
1905  /* Iterate over all endpoints looking for completed
1906  * descriptors. We trust that completion handlers are
1907  * minimal and will not do anything that could
1908  * plausibly affect the endpoint list itself.
1909  */
1910  list_for_each_entry ( endpoint, &ehci->endpoints, list )
1911  ehci_endpoint_poll ( endpoint );
1912  }
1913 
1914  /* Process port status changes, if applicable */
1915  if ( change & EHCI_USBSTS_PORT ) {
1916 
1917  /* Iterate over all ports looking for status changes */
1918  for ( i = 1 ; i <= ehci->ports ; i++ )
1919  ehci_root_poll ( hub, usb_port ( hub, i ) );
1920  }
1921 
1922  /* Report fatal errors */
1923  if ( change & EHCI_USBSTS_SYSERR )
1924  DBGC ( ehci, "EHCI %s host system error\n", ehci->name );
1925 }
#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:824
#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:1754
A USB port.
Definition: usb.h:796
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:1374
#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:1039
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 1974 of file ehci.c.

1974  {
1975  struct ehci_device *ehci;
1976  struct usb_port *port;
1977  unsigned long bar_start;
1978  size_t bar_size;
1979  unsigned int i;
1980  int rc;
1981 
1982  /* Allocate and initialise structure */
1983  ehci = zalloc ( sizeof ( *ehci ) );
1984  if ( ! ehci ) {
1985  rc = -ENOMEM;
1986  goto err_alloc;
1987  }
1988  ehci->name = pci->dev.name;
1989  INIT_LIST_HEAD ( &ehci->endpoints );
1990  INIT_LIST_HEAD ( &ehci->async );
1991  INIT_LIST_HEAD ( &ehci->periodic );
1992 
1993  /* Fix up PCI device */
1994  adjust_pci_device ( pci );
1995 
1996  /* Map registers */
1997  bar_start = pci_bar_start ( pci, EHCI_BAR );
1998  bar_size = pci_bar_size ( pci, EHCI_BAR );
1999  ehci->regs = ioremap ( bar_start, bar_size );
2000  if ( ! ehci->regs ) {
2001  rc = -ENODEV;
2002  goto err_ioremap;
2003  }
2004 
2005  /* Initialise EHCI device */
2006  ehci_init ( ehci, ehci->regs );
2007 
2008  /* Initialise USB legacy support and claim ownership */
2009  ehci_legacy_init ( ehci, pci );
2010  ehci_legacy_claim ( ehci, pci );
2011 
2012  /* Reset device */
2013  if ( ( rc = ehci_reset ( ehci ) ) != 0 )
2014  goto err_reset;
2015 
2016  /* Allocate USB bus */
2017  ehci->bus = alloc_usb_bus ( &pci->dev, ehci->ports, EHCI_MTU,
2018  &ehci_operations );
2019  if ( ! ehci->bus ) {
2020  rc = -ENOMEM;
2021  goto err_alloc_bus;
2022  }
2023  usb_bus_set_hostdata ( ehci->bus, ehci );
2024  usb_hub_set_drvdata ( ehci->bus->hub, ehci );
2025 
2026  /* Set port protocols */
2027  for ( i = 1 ; i <= ehci->ports ; i++ ) {
2028  port = usb_port ( ehci->bus->hub, i );
2029  port->protocol = USB_PROTO_2_0;
2030  }
2031 
2032  /* Register USB bus */
2033  if ( ( rc = register_usb_bus ( ehci->bus ) ) != 0 )
2034  goto err_register;
2035 
2036  pci_set_drvdata ( pci, ehci );
2037  return 0;
2038 
2039  unregister_usb_bus ( ehci->bus );
2040  err_register:
2041  free_usb_bus ( ehci->bus );
2042  err_alloc_bus:
2043  ehci_reset ( ehci );
2044  err_reset:
2045  ehci_legacy_release ( ehci, pci );
2046  iounmap ( ehci->regs );
2047  err_ioremap:
2048  free ( ehci );
2049  err_alloc:
2050  return rc;
2051 }
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:2031
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:189
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1028
#define EHCI_MTU
Maximum transfer size.
Definition: ehci.h:30
A USB port.
Definition: usb.h:796
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#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:2102
#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:1935
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:2067
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:972
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:920
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:943
struct list_head async
Asynchronous schedule.
Definition: ehci.h:516
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2126
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, ioremap(), iounmap(), device::name, ehci_device::name, pci_bar_size(), pci_bar_start(), 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 2058 of file ehci.c.

2058  {
2059  struct ehci_device *ehci = pci_get_drvdata ( pci );
2060  struct usb_bus *bus = ehci->bus;
2061 
2062  unregister_usb_bus ( bus );
2063  assert ( list_empty ( &ehci->async ) );
2064  assert ( list_empty ( &ehci->periodic ) );
2065  free_usb_bus ( bus );
2066  ehci_reset ( ehci );
2067  ehci_legacy_release ( ehci, pci );
2068  iounmap ( ehci->regs );
2069  free ( ehci );
2070 }
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:2102
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:348
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:949
uint8_t bus
Bus.
Definition: edd.h:14
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2126
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 2092 of file ehci.c.

2092  {
2093  /* If we are shutting down to boot an OS, then prevent the
2094  * release of ownership back to BIOS.
2095  */
2096  ehci_legacy_prevent_release = booting;
2097 }
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 1935 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:283

EHCI PCI device IDs.

Definition at line 2073 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:179
static struct pci_device_id ehci_ids[]
EHCI PCI device IDs.
Definition: ehci.c:2073
#define PCI_CLASS_SERIAL
Definition: Pci22.h:272
static int ehci_probe(struct pci_device *pci)
Probe PCI device.
Definition: ehci.c:1974
static void ehci_remove(struct pci_device *pci)
Remove PCI device.
Definition: ehci.c:2058
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:278
#define PCI_CLASS_SERIAL_USB_EHCI
ECHI USB controller.
Definition: pci.h:134

EHCI PCI driver.

Definition at line 2078 of file ehci.c.