iPXE
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)
 Construct error code from transfer descriptor status.

Functions

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

Variables

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

Detailed Description

USB Enhanced Host Controller Interface (EHCI) driver.

Definition in file ehci.c.

Macro Definition Documentation

◆ EIO_STATUS

#define EIO_STATUS ( status)
Value:
EUNIQ ( EINFO_EIO, ( ( (status) >> 2 ) & 0xf ) )
uint8_t status
Status.
Definition ena.h:5
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition errno.h:226
#define EINFO_EIO
Definition errno.h:435

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

Referenced by ehci_endpoint_poll().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ehci_init()

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

Initialise device.

Parameters
ehciEHCI device
regsMMIO registers

Definition at line 70 of file ehci.c.

70 {
71 uint32_t hcsparams;
72 uint32_t hccparams;
73 size_t caplength;
74
75 /* Locate capability and operational registers */
76 ehci->cap = regs;
77 caplength = readb ( ehci->cap + EHCI_CAP_CAPLENGTH );
78 ehci->op = ( ehci->cap + caplength );
79 DBGC2 ( ehci, "EHCI %s cap %08lx op %08lx\n", ehci->name,
80 virt_to_phys ( ehci->cap ), virt_to_phys ( ehci->op ) );
81
82 /* Read structural parameters */
83 hcsparams = readl ( ehci->cap + EHCI_CAP_HCSPARAMS );
84 ehci->ports = EHCI_HCSPARAMS_PORTS ( hcsparams );
85 DBGC ( ehci, "EHCI %s has %d ports\n", ehci->name, ehci->ports );
86
87 /* Read capability parameters 1 */
88 hccparams = readl ( ehci->cap + EHCI_CAP_HCCPARAMS );
89 ehci->addr64 = EHCI_HCCPARAMS_ADDR64 ( hccparams );
90 ehci->flsize = ( EHCI_HCCPARAMS_FLSIZE ( hccparams ) ?
92 ehci->eecp = EHCI_HCCPARAMS_EECP ( hccparams );
93 DBGC2 ( ehci, "EHCI %s %d-bit flsize %d\n", ehci->name,
94 ( ehci->addr64 ? 64 : 32 ), ehci->flsize );
95}
unsigned int uint32_t
Definition stdint.h:12
#define EHCI_CAP_HCSPARAMS
Structural parameters.
Definition ehci.h:46
#define EHCI_CAP_CAPLENGTH
Capability register length.
Definition ehci.h:40
#define EHCI_HCCPARAMS_FLSIZE(params)
Programmable frame list flag.
Definition ehci.h:58
#define EHCI_HCCPARAMS_EECP(params)
EHCI extended capabilities pointer.
Definition ehci.h:61
#define EHCI_FLSIZE_SMALL
Smallest allowed frame list size.
Definition ehci.h:106
#define EHCI_HCSPARAMS_PORTS(params)
Number of ports.
Definition ehci.h:49
#define EHCI_CAP_HCCPARAMS
Capability parameters.
Definition ehci.h:52
#define EHCI_FLSIZE_DEFAULT
Default frame list size.
Definition ehci.h:103
#define EHCI_HCCPARAMS_ADDR64(params)
64-bit addressing capability
Definition ehci.h:55
#define DBGC2(...)
Definition compiler.h:522
#define DBGC(...)
Definition compiler.h:505
struct i386_regs regs
Definition registers.h:1
const char * name
Name.
Definition ehci.h:488
unsigned int eecp
EHCI extended capabilities offset.
Definition ehci.h:502
void * cap
Capability registers.
Definition ehci.h:491
int addr64
64-bit addressing capability
Definition ehci.h:498
unsigned int flsize
Frame list size.
Definition ehci.h:500
void * op
Operational registers.
Definition ehci.h:493
unsigned int ports
Number of ports.
Definition ehci.h:496
#define readl
Definition w89c840.c:157
#define readb
Definition w89c840.c:155

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, and regs.

Referenced by ehci_probe().

◆ ehci_extended_capability()

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

109 {
110 uint32_t eecp;
111
112 /* Locate the extended capability */
113 while ( 1 ) {
114
115 /* Locate first or next capability as applicable */
116 if ( offset ) {
117 pci_read_config_dword ( pci, offset, &eecp );
118 offset = EHCI_EECP_NEXT ( eecp );
119 } else {
120 offset = ehci->eecp;
121 }
122 if ( ! offset )
123 return 0;
124
125 /* Check if this is the requested capability */
126 pci_read_config_dword ( pci, offset, &eecp );
127 if ( EHCI_EECP_ID ( eecp ) == id )
128 return offset;
129 }
130}
uint16_t offset
Offset to command line.
Definition bzimage.h:3
#define EHCI_EECP_ID(eecp)
EHCI extended capability ID.
Definition ehci.h:64
#define EHCI_EECP_NEXT(eecp)
Next EHCI extended capability pointer.
Definition ehci.h:67
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.

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

Referenced by ehci_legacy_init().

◆ ehci_align()

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

141 {
142 size_t align;
143
144 /* Align to own length (rounded up to a power of two) */
145 align = ( 1 << fls ( len - 1 ) );
146
147 /* Round up to EHCI_MIN_ALIGN if needed */
148 if ( align < EHCI_MIN_ALIGN )
149 align = EHCI_MIN_ALIGN;
150
151 return align;
152}
ring len
Length.
Definition dwmac.h:226
#define EHCI_MIN_ALIGN
Minimum alignment required for data structures.
Definition ehci.h:24
#define fls(x)
Find last (i.e.
Definition strings.h:167

References EHCI_MIN_ALIGN, fls, and len.

Referenced by ehci_bus_open(), and ehci_ring_alloc().

◆ ehci_ctrl_reachable()

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

161 {
162 physaddr_t phys = virt_to_phys ( ptr );
164
165 /* Always reachable in a 32-bit build */
166 if ( sizeof ( physaddr_t ) <= sizeof ( uint32_t ) )
167 return 0;
168
169 /* Reachable only if control segment matches in a 64-bit build */
170 segment = ( ( ( uint64_t ) phys ) >> 32 );
171 if ( segment == ehci->ctrldssegment )
172 return 0;
173
174 return -ENOTSUP;
175}
unsigned long physaddr_t
Definition stdint.h:20
unsigned long long uint64_t
Definition stdint.h:13
static signed char phys[4]
Definition epic100.c:88
#define ENOTSUP
Operation not supported.
Definition errno.h:590
uint16_t segment
Code segment.
Definition librm.h:3
uint32_t ctrldssegment
Control data structure segment.
Definition ehci.h:508

References ehci_device::ctrldssegment, ENOTSUP, phys, and segment.

Referenced by ehci_bus_open(), and ehci_ring_alloc().

◆ ehci_dump()

__unused void ehci_dump ( struct ehci_device * ehci)
static

Dump host controller registers.

Parameters
ehciEHCI device

Definition at line 189 of file ehci.c.

189 {
190 uint8_t caplength;
191 uint16_t hciversion;
192 uint32_t hcsparams;
193 uint32_t hccparams;
194 uint32_t usbcmd;
195 uint32_t usbsts;
196 uint32_t usbintr;
197 uint32_t frindex;
198 uint32_t ctrldssegment;
199 uint32_t periodiclistbase;
200 uint32_t asynclistaddr;
201 uint32_t configflag;
202
203 /* Do nothing unless debugging is enabled */
204 if ( ! DBG_LOG )
205 return;
206
207 /* Dump capability registers */
208 caplength = readb ( ehci->cap + EHCI_CAP_CAPLENGTH );
209 hciversion = readw ( ehci->cap + EHCI_CAP_HCIVERSION );
210 hcsparams = readl ( ehci->cap + EHCI_CAP_HCSPARAMS );
211 hccparams = readl ( ehci->cap + EHCI_CAP_HCCPARAMS );
212 DBGC ( ehci, "EHCI %s caplen %02x hciversion %04x hcsparams %08x "
213 "hccparams %08x\n", ehci->name, caplength, hciversion,
214 hcsparams, hccparams );
215
216 /* Dump operational registers */
217 usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
218 usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
219 usbintr = readl ( ehci->op + EHCI_OP_USBINTR );
220 frindex = readl ( ehci->op + EHCI_OP_FRINDEX );
221 ctrldssegment = readl ( ehci->op + EHCI_OP_CTRLDSSEGMENT );
222 periodiclistbase = readl ( ehci->op + EHCI_OP_PERIODICLISTBASE );
223 asynclistaddr = readl ( ehci->op + EHCI_OP_ASYNCLISTADDR );
224 configflag = readl ( ehci->op + EHCI_OP_CONFIGFLAG );
225 DBGC ( ehci, "EHCI %s usbcmd %08x usbsts %08x usbint %08x frindx "
226 "%08x\n", ehci->name, usbcmd, usbsts, usbintr, frindex );
227 DBGC ( ehci, "EHCI %s ctrlds %08x period %08x asyncl %08x cfgflg "
228 "%08x\n", ehci->name, ctrldssegment, periodiclistbase,
229 asynclistaddr, configflag );
230}
unsigned short uint16_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:10
#define EHCI_OP_CTRLDSSEGMENT
Control data structure segment register.
Definition ehci.h:163
#define EHCI_OP_PERIODICLISTBASE
Periodic frame list base address register.
Definition ehci.h:166
#define EHCI_OP_USBINTR
USB interrupt enable register.
Definition ehci.h:157
#define EHCI_OP_USBCMD
USB command register.
Definition ehci.h:88
#define EHCI_OP_FRINDEX
Frame index register.
Definition ehci.h:160
#define EHCI_OP_USBSTS
USB status register.
Definition ehci.h:121
#define EHCI_CAP_HCIVERSION
Host controller interface version number.
Definition ehci.h:43
#define EHCI_OP_ASYNCLISTADDR
Current asynchronous list address register.
Definition ehci.h:169
#define EHCI_OP_CONFIGFLAG
Configure flag register.
Definition ehci.h:172
#define DBG_LOG
Definition compiler.h:317
#define readw
Definition w89c840.c:156

References __unused, 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()

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

249 {
250 unsigned int legacy;
251 uint8_t bios;
252
253 /* Locate USB legacy support capability (if present) */
254 legacy = ehci_extended_capability ( ehci, pci, EHCI_EECP_ID_LEGACY, 0 );
255 if ( ! legacy ) {
256 /* Not an error; capability may not be present */
257 DBGC ( ehci, "EHCI %s has no USB legacy support capability\n",
258 ehci->name );
259 return;
260 }
261
262 /* Check if legacy USB support is enabled */
263 pci_read_config_byte ( pci, ( legacy + EHCI_USBLEGSUP_BIOS ), &bios );
264 if ( ! ( bios & EHCI_USBLEGSUP_BIOS_OWNED ) ) {
265 /* Not an error; already owned by OS */
266 DBGC ( ehci, "EHCI %s USB legacy support already disabled\n",
267 ehci->name );
268 return;
269 }
270
271 /* Record presence of USB legacy support capability */
272 ehci->legacy = legacy;
273}
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:106
#define EHCI_USBLEGSUP_BIOS_OWNED
USB legacy support BIOS ownership flag.
Definition ehci.h:76
#define EHCI_USBLEGSUP_BIOS
USB legacy support BIOS owned semaphore.
Definition ehci.h:73
#define EHCI_EECP_ID_LEGACY
USB legacy support extended capability.
Definition ehci.h:70
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.
unsigned int legacy
USB legacy support capability (if present and enabled)
Definition ehci.h:505

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()

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

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

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()

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

342 {
343 unsigned int legacy = ehci->legacy;
344 uint32_t ctlsts;
345
346 /* Do nothing unless legacy support capability is present */
347 if ( ! legacy )
348 return;
349
350 /* Do nothing if releasing ownership is prevented */
352 DBGC ( ehci, "EHCI %s not releasing ownership to BIOS\n",
353 ehci->name );
354 return;
355 }
356
357 /* Release ownership */
358 pci_write_config_byte ( pci, ( legacy + EHCI_USBLEGSUP_OS ), 0 );
359 DBGC ( ehci, "EHCI %s released ownership to BIOS\n", ehci->name );
360
361 /* Dump restored SMI usage */
363 &ctlsts );
364 DBGC ( ehci, "EHCI %s BIOS reclaimed SMIs: %08x\n",
365 ehci->name, ctlsts );
366}
static int ehci_legacy_prevent_release
Prevent the release of ownership back to BIOS.
Definition ehci.c:240

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()

void ehci_poll_companions ( struct ehci_device * ehci)
static

Poll child companion controllers.

Parameters
ehciEHCI device

Definition at line 380 of file ehci.c.

380 {
381 struct usb_bus *bus;
382 struct device_description *desc;
383
384 /* Poll any USB buses belonging to child companion controllers */
386
387 /* Get underlying devices description */
388 desc = &bus->dev->desc;
389
390 /* Skip buses that are not PCI devices */
391 if ( desc->bus_type != BUS_TYPE_PCI )
392 continue;
393
394 /* Skip buses that are not part of the same PCI device */
395 if ( PCI_FIRST_FUNC ( desc->location ) !=
396 PCI_FIRST_FUNC ( ehci->bus->dev->desc.location ) )
397 continue;
398
399 /* Skip buses that are not UHCI or OHCI PCI devices */
400 if ( ( desc->class != PCI_CLASS ( PCI_CLASS_SERIAL,
403 ( desc->class != PCI_CLASS ( PCI_CLASS_SERIAL,
406 continue;
407
408 /* Poll child companion controller bus */
409 DBGC2 ( ehci, "EHCI %s polling companion %s\n",
410 ehci->name, bus->name );
411 usb_poll ( bus );
412 }
413}
#define PCI_CLASS_SERIAL
Definition Pci22.h:267
#define PCI_CLASS_SERIAL_USB
Definition Pci22.h:273
#define BUS_TYPE_PCI
PCI bus type.
Definition device.h:44
uint8_t bus
Bus.
Definition edd.h:1
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
#define for_each_usb_bus(bus)
Iterate over all USB buses.
Definition usb.h:1077
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition usb.h:1072
#define PCI_CLASS(base, sub, progif)
Construct PCI class.
Definition pci.h:167
#define PCI_FIRST_FUNC(busdevfn)
Definition pci.h:287
#define PCI_CLASS_SERIAL_USB_UHCI
UHCI USB controller.
Definition pci.h:138
#define PCI_CLASS_SERIAL_USB_OHCI
OHCI USB controller.
Definition pci.h:139
A hardware device description.
Definition device.h:20
unsigned int location
Location.
Definition device.h:30
struct device_description desc
Device description.
Definition device.h:83
struct usb_bus * bus
USB bus.
Definition ehci.h:525
A USB bus.
Definition usb.h:966
struct device * dev
Underlying hardware device.
Definition usb.h:970

References bus, ehci_device::bus, BUS_TYPE_PCI, DBGC2, desc, 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 421 of file ehci.c.

421 {
422 struct pci_device tmp;
423 unsigned int busdevfn;
424 int rc;
425
426 /* Look for an EHCI function on the same PCI device */
427 busdevfn = pci->busdevfn;
428 while ( ++busdevfn <= PCI_LAST_FUNC ( pci->busdevfn ) ) {
429 pci_init ( &tmp, busdevfn );
430 if ( ( rc = pci_read_config ( &tmp ) ) != 0 )
431 continue;
432 if ( tmp.class == PCI_CLASS ( PCI_CLASS_SERIAL,
435 return busdevfn;
436 }
437
438 return 0;
439}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
unsigned long tmp
Definition linux_pci.h:65
int pci_read_config(struct pci_device *pci)
Read PCI device configuration.
Definition pci.c:269
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition pci.h:341
#define PCI_LAST_FUNC(busdevfn)
Definition pci.h:288
#define PCI_CLASS_SERIAL_USB_EHCI
ECHI USB controller.
Definition pci.h:140
A PCI device.
Definition pci.h:211
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition pci.h:238

References busdevfn, 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()

void ehci_run ( struct ehci_device * ehci)
static

Start EHCI device.

Parameters
ehciEHCI device

Definition at line 453 of file ehci.c.

453 {
454 uint32_t usbcmd;
455
456 /* Set run/stop bit */
457 usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
458 usbcmd &= ~EHCI_USBCMD_FLSIZE_MASK;
459 usbcmd |= ( EHCI_USBCMD_RUN | EHCI_USBCMD_FLSIZE ( ehci->flsize ) |
461 writel ( usbcmd, ehci->op + EHCI_OP_USBCMD );
462}
#define EHCI_USBCMD_PERIODIC
Periodic schedule enable.
Definition ehci.h:112
#define EHCI_USBCMD_RUN
Run/stop.
Definition ehci.h:91
#define EHCI_USBCMD_FLSIZE_MASK
Frame list size mask.
Definition ehci.h:100
#define EHCI_USBCMD_ASYNC
Asynchronous schedule enable.
Definition ehci.h:115
#define EHCI_USBCMD_FLSIZE(flsize)
Frame list size.
Definition ehci.h:97
#define writel
Definition w89c840.c:160

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()

int ehci_stop ( struct ehci_device * ehci)
static

Stop EHCI device.

Parameters
ehciEHCI device
Return values
rcReturn status code

Definition at line 470 of file ehci.c.

470 {
471 uint32_t usbcmd;
472 uint32_t usbsts;
473 unsigned int i;
474
475 /* Clear run/stop bit */
476 usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
479 writel ( usbcmd, ehci->op + EHCI_OP_USBCMD );
480
481 /* Wait for device to stop */
482 for ( i = 0 ; i < EHCI_STOP_MAX_WAIT_MS ; i++ ) {
483
484 /* Check if device is stopped */
485 usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
486 if ( usbsts & EHCI_USBSTS_HCH )
487 return 0;
488
489 /* Delay */
490 mdelay ( 1 );
491 }
492
493 DBGC ( ehci, "EHCI %s timed out waiting for stop\n", ehci->name );
494 return -ETIMEDOUT;
495}
#define EHCI_STOP_MAX_WAIT_MS
Maximum time to wait for host controller to stop.
Definition ehci.h:450
#define EHCI_USBSTS_HCH
Host controller halted.
Definition ehci.h:148
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670

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()

int ehci_reset ( struct ehci_device * ehci)
static

Reset EHCI device.

Parameters
ehciEHCI device
Return values
rcReturn status code

Definition at line 503 of file ehci.c.

503 {
504 uint32_t usbcmd;
505 unsigned int i;
506 int rc;
507
508 /* The EHCI specification states that resetting a running
509 * device may result in undefined behaviour, so try stopping
510 * it first.
511 */
512 if ( ( rc = ehci_stop ( ehci ) ) != 0 ) {
513 /* Ignore errors and attempt to reset the device anyway */
514 }
515
516 /* Reset device */
518
519 /* Wait for reset to complete */
520 for ( i = 0 ; i < EHCI_RESET_MAX_WAIT_MS ; i++ ) {
521
522 /* Check if reset is complete */
523 usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
524 if ( ! ( usbcmd & EHCI_USBCMD_HCRST ) )
525 return 0;
526
527 /* Delay */
528 mdelay ( 1 );
529 }
530
531 DBGC ( ehci, "EHCI %s timed out waiting for reset\n", ehci->name );
532 return -ETIMEDOUT;
533}
static int ehci_stop(struct ehci_device *ehci)
Stop EHCI device.
Definition ehci.c:470
#define EHCI_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
Definition ehci.h:456
#define EHCI_USBCMD_HCRST
Host controller reset.
Definition ehci.h:94

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()

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

550 {
553 unsigned int i;
554 size_t len;
556 int rc;
557
558 /* Initialise structure */
559 memset ( ring, 0, sizeof ( *ring ) );
560
561 /* Allocate I/O buffers */
562 ring->iobuf = zalloc ( EHCI_RING_COUNT * sizeof ( ring->iobuf[0] ) );
563 if ( ! ring->iobuf ) {
564 rc = -ENOMEM;
565 goto err_alloc_iobuf;
566 }
567
568 /* Allocate queue head */
569 ring->head = malloc_phys ( sizeof ( *ring->head ),
570 ehci_align ( sizeof ( *ring->head ) ) );
571 if ( ! ring->head ) {
572 rc = -ENOMEM;
573 goto err_alloc_queue;
574 }
575 if ( ( rc = ehci_ctrl_reachable ( ehci, ring->head ) ) != 0 ) {
576 DBGC ( ehci, "EHCI %s queue head unreachable\n", ehci->name );
577 goto err_unreachable_queue;
578 }
579 memset ( ring->head, 0, sizeof ( *ring->head ) );
580
581 /* Allocate transfer descriptors */
582 len = ( EHCI_RING_COUNT * sizeof ( ring->desc[0] ) );
583 ring->desc = malloc_phys ( len, sizeof ( ring->desc[0] ) );
584 if ( ! ring->desc ) {
585 rc = -ENOMEM;
586 goto err_alloc_desc;
587 }
588 memset ( ring->desc, 0, len );
589
590 /* Initialise transfer descriptors */
591 for ( i = 0 ; i < EHCI_RING_COUNT ; i++ ) {
592 desc = &ring->desc[i];
593 if ( ( rc = ehci_ctrl_reachable ( ehci, desc ) ) != 0 ) {
594 DBGC ( ehci, "EHCI %s descriptor unreachable\n",
595 ehci->name );
596 goto err_unreachable_desc;
597 }
598 next = &ring->desc[ ( i + 1 ) % EHCI_RING_COUNT ];
599 link = virt_to_phys ( next );
600 desc->next = cpu_to_le32 ( link );
601 desc->alt = cpu_to_le32 ( link );
602 }
603
604 /* Initialise queue head */
605 link = virt_to_phys ( &ring->desc[0] );
606 ring->head->cache.next = cpu_to_le32 ( link );
607
608 return 0;
609
610 err_unreachable_desc:
611 free_phys ( ring->desc, len );
612 err_alloc_desc:
613 err_unreachable_queue:
614 free_phys ( ring->head, sizeof ( *ring->head ) );
615 err_alloc_queue:
616 free ( ring->iobuf );
617 err_alloc_iobuf:
618 return rc;
619}
u32 link
Link to next descriptor.
Definition ar9003_mac.h:1
uint32_t next
Next descriptor address.
Definition dwmac.h:11
static int ehci_ctrl_reachable(struct ehci_device *ehci, void *ptr)
Check control data structure reachability.
Definition ehci.c:161
static size_t ehci_align(size_t len)
Calculate buffer alignment.
Definition ehci.c:141
#define EHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition ehci.h:392
#define ENOMEM
Not enough space.
Definition errno.h:535
#define cpu_to_le32(value)
Definition byteswap.h:108
void * memset(void *dest, int character, size_t len) __nonnull
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition malloc.c:707
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition malloc.c:723
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
struct ehci_transfer_descriptor cache
Transfer descriptor cache.
Definition ehci.h:302
struct ehci_transfer_descriptor * desc
Transfer descriptors.
Definition ehci.h:385
struct ehci_queue_head * head
Queue head.
Definition ehci.h:383
struct io_buffer ** iobuf
I/O buffers.
Definition ehci.h:380
A transfer descriptor.
Definition ehci.h:230
uint32_t next
Next transfer descriptor.
Definition ehci.h:232

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

Referenced by ehci_endpoint_open().

◆ ehci_ring_free()

void ehci_ring_free ( struct ehci_ring * ring)
static

Free transfer descriptor ring.

Parameters
ringTransfer descriptor ring

Definition at line 626 of file ehci.c.

626 {
627 unsigned int i;
628
629 /* Sanity checks */
630 assert ( ehci_ring_fill ( ring ) == 0 );
631 for ( i = 0 ; i < EHCI_RING_COUNT ; i++ )
632 assert ( ring->iobuf[i] == NULL );
633
634 /* Free transfer descriptors */
635 free_phys ( ring->desc, ( EHCI_RING_COUNT *
636 sizeof ( ring->desc[0] ) ) );
637
638 /* Free queue head */
639 free_phys ( ring->head, sizeof ( *ring->head ) );
640
641 /* Free I/O buffers */
642 free ( ring->iobuf );
643}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
static unsigned int ehci_ring_fill(struct ehci_ring *ring)
Calculate space used in transfer descriptor ring.
Definition ehci.h:401

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

Referenced by ehci_endpoint_close(), and ehci_endpoint_open().

◆ ehci_enqueue()

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

658 {
661 void *data;
662 size_t len;
663 size_t offset;
664 size_t frag_len;
665 unsigned int toggle;
666 unsigned int index;
667 unsigned int i;
668
669 /* Sanity check */
670 assert ( iobuf != NULL );
671 assert ( count > 0 );
672
673 /* Fail if ring does not have sufficient space */
674 if ( ehci_ring_remaining ( ring ) < count )
675 return -ENOBUFS;
676
677 /* Fail if any portion is unreachable */
678 for ( i = 0 ; i < count ; i++ ) {
679 if ( ! xfer[i].len )
680 continue;
681 phys = ( virt_to_phys ( xfer[i].data ) + xfer[i].len - 1 );
682 if ( ( phys > 0xffffffffUL ) && ( ! ehci->addr64 ) )
683 return -ENOTSUP;
684 }
685
686 /* Enqueue each transfer, recording the I/O buffer with the last */
687 for ( ; count ; ring->prod++, xfer++ ) {
688
689 /* Populate descriptor header */
690 index = ( ring->prod % EHCI_RING_COUNT );
691 desc = &ring->desc[index];
692 toggle = ( xfer->flags & EHCI_FL_TOGGLE );
693 assert ( xfer->len <= EHCI_LEN_MASK );
695 desc->len = cpu_to_le16 ( xfer->len | toggle );
696 desc->flags = ( xfer->flags | EHCI_FL_CERR_MAX );
697
698 /* Populate buffer pointers */
699 data = xfer->data;
700 len = xfer->len;
701 for ( i = 0 ; len ; i++ ) {
702
703 /* Calculate length of this fragment */
704 phys = virt_to_phys ( data );
705 offset = ( phys & ( EHCI_PAGE_ALIGN - 1 ) );
706 frag_len = ( EHCI_PAGE_ALIGN - offset );
707 if ( frag_len > len )
708 frag_len = len;
709
710 /* Sanity checks */
711 assert ( ( i == 0 ) || ( offset == 0 ) );
712 assert ( i < ( sizeof ( desc->low ) /
713 sizeof ( desc->low[0] ) ) );
714
715 /* Populate buffer pointer */
716 desc->low[i] = cpu_to_le32 ( phys );
717 if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
718 desc->high[i] =
719 cpu_to_le32 ( ((uint64_t) phys) >> 32 );
720 }
721
722 /* Move to next fragment */
723 data += frag_len;
724 len -= frag_len;
725 }
726
727 /* Ensure everything is valid before activating descriptor */
728 wmb();
729 desc->status = EHCI_STATUS_ACTIVE;
730
731 /* Record I/O buffer against last ring index */
732 if ( --count == 0 )
733 ring->iobuf[index] = iobuf;
734 }
735
736 return 0;
737}
long index
Definition bigint.h:65
#define EHCI_FL_CERR_MAX
Error counter maximum value.
Definition ehci.h:280
#define EHCI_STATUS_ACTIVE
Active.
Definition ehci.h:262
#define EHCI_PAGE_ALIGN
Page-alignment required for some data structures.
Definition ehci.h:34
static unsigned int ehci_ring_remaining(struct ehci_ring *ring)
Calculate space remaining in transfer descriptor ring.
Definition ehci.h:416
#define EHCI_LEN_TOGGLE
Data toggle.
Definition ehci.h:289
#define EHCI_LEN_MASK
Length mask.
Definition ehci.h:286
#define EHCI_FL_TOGGLE
Set initial data toggle.
Definition ehci.h:481
uint8_t data[48]
Additional event data.
Definition ena.h:11
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define ENOBUFS
No buffer space available.
Definition errno.h:499
#define cpu_to_le16(value)
Definition byteswap.h:107
#define wmb()
Definition io.h:546
unsigned int prod
Producer counter.
Definition ehci.h:372
unsigned int flags
Flags.
Definition ehci.h:477
void * data
Data buffer.
Definition ehci.h:467
size_t len
Length.
Definition ehci.h:469

References ehci_device::addr64, assert, count, cpu_to_le16, cpu_to_le32, data, ehci_transfer::data, desc, 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::flags, index, ehci_ring::iobuf, ehci_transfer::len, len, NULL, offset, phys, ehci_ring::prod, and wmb.

Referenced by ehci_endpoint_message(), and ehci_endpoint_stream().

◆ ehci_dequeue()

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

745 {
747 struct io_buffer *iobuf;
748 unsigned int index = ( ring->cons % EHCI_RING_COUNT );
749
750 /* Sanity check */
751 assert ( ehci_ring_fill ( ring ) > 0 );
752
753 /* Mark descriptor as inactive (and not halted) */
754 desc = &ring->desc[index];
755 desc->status = 0;
756
757 /* Retrieve I/O buffer */
758 iobuf = ring->iobuf[index];
759 ring->iobuf[index] = NULL;
760
761 /* Update consumer counter */
762 ring->cons++;
763
764 return iobuf;
765}
unsigned int cons
Consumer counter.
Definition ehci.h:374
A persistent I/O buffer.
Definition iobuf.h:38

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

Referenced by ehci_endpoint_close(), and ehci_endpoint_poll().

◆ ehci_link_qh()

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

780 {
781
782 return ( virt_to_phys ( queue ) | EHCI_LINK_TYPE_QH );
783}
#define EHCI_LINK_TYPE_QH
Queue head type.
Definition ehci.h:221
uint16_t queue
Queue ID.
Definition ena.h:11

References EHCI_LINK_TYPE_QH, and queue.

Referenced by ehci_async_schedule(), and ehci_periodic_schedule().

◆ ehci_async_schedule()

void ehci_async_schedule ( struct ehci_device * ehci)
static

(Re)build asynchronous schedule

Parameters
ehciEHCI device

Definition at line 790 of file ehci.c.

790 {
791 struct ehci_endpoint *endpoint;
792 struct ehci_queue_head *queue;
794
795 /* Build schedule in reverse order of execution. Provided
796 * that we only ever add or remove single endpoints, this can
797 * safely run concurrently with hardware execution of the
798 * schedule.
799 */
800 link = ehci_link_qh ( ehci->head );
801 list_for_each_entry_reverse ( endpoint, &ehci->async, schedule ) {
802 queue = endpoint->ring.head;
803 queue->link = cpu_to_le32 ( link );
804 wmb();
805 link = ehci_link_qh ( queue );
806 }
807 ehci->head->link = cpu_to_le32 ( link );
808 wmb();
809}
static uint32_t ehci_link_qh(struct ehci_queue_head *queue)
Get link value for a queue head.
Definition ehci.c:780
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
Definition list.h:445
struct list_head async
Asynchronous schedule.
Definition ehci.h:517
struct ehci_queue_head * head
Asynchronous queue head.
Definition ehci.h:510
An EHCI endpoint.
Definition ehci.h:529
struct ehci_ring ring
Transfer descriptor ring.
Definition ehci.h:540
A queue head.
Definition ehci.h:292
uint32_t link
Horizontal link pointer.
Definition ehci.h:294

References ehci_device::async, cpu_to_le32, ehci_link_qh(), ehci_device::head, ehci_ring::head, ehci_queue_head::link, 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()

void ehci_async_add ( struct ehci_endpoint * endpoint)
static

Add endpoint to asynchronous schedule.

Parameters
endpointEndpoint

Definition at line 816 of file ehci.c.

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

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()

int ehci_async_del ( struct ehci_endpoint * endpoint)
static

Remove endpoint from asynchronous schedule.

Parameters
endpointEndpoint
Return values
rcReturn status code

Definition at line 832 of file ehci.c.

832 {
833 struct ehci_device *ehci = endpoint->ehci;
834 uint32_t usbcmd;
835 uint32_t usbsts;
836 unsigned int i;
837
838 /* Remove from schedule */
839 list_check_contains_entry ( endpoint, &ehci->async, schedule );
840 list_del ( &endpoint->schedule );
841
842 /* Rebuild schedule */
843 ehci_async_schedule ( ehci );
844
845 /* Request notification when asynchronous schedule advances */
846 usbcmd = readl ( ehci->op + EHCI_OP_USBCMD );
848 writel ( usbcmd, ehci->op + EHCI_OP_USBCMD );
849
850 /* Wait for asynchronous schedule to advance */
851 for ( i = 0 ; i < EHCI_ASYNC_ADVANCE_MAX_WAIT_MS ; i++ ) {
852
853 /* Check for asynchronous schedule advancing */
854 usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
855 if ( usbsts & EHCI_USBSTS_ASYNC_ADVANCE ) {
856 usbsts &= ~EHCI_USBSTS_CHANGE;
858 writel ( usbsts, ehci->op + EHCI_OP_USBSTS );
859 return 0;
860 }
861
862 /* Delay */
863 mdelay ( 1 );
864 }
865
866 /* Bad things will probably happen now */
867 DBGC ( ehci, "EHCI %s timed out waiting for asynchronous schedule "
868 "to advance\n", ehci->name );
869 return -ETIMEDOUT;
870}
#define EHCI_ASYNC_ADVANCE_MAX_WAIT_MS
Maximum time to wait for asynchronous schedule to advance.
Definition ehci.h:444
#define EHCI_USBSTS_CHANGE
USB status change mask.
Definition ehci.h:151
#define EHCI_USBCMD_ASYNC_ADVANCE
Asyncchronous schedule advance doorbell.
Definition ehci.h:118
#define EHCI_USBSTS_ASYNC_ADVANCE
Asynchronous schedule advanced.
Definition ehci.h:139
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition list.h:550

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()

void ehci_periodic_schedule ( struct ehci_device * ehci)
static

(Re)build periodic schedule

Parameters
ehciEHCI device

Definition at line 877 of file ehci.c.

877 {
878 struct ehci_endpoint *endpoint;
879 struct ehci_queue_head *queue;
881 unsigned int frames;
882 unsigned int max_interval;
883 unsigned int i;
884
885 /* Build schedule in reverse order of execution. Provided
886 * that we only ever add or remove single endpoints, this can
887 * safely run concurrently with hardware execution of the
888 * schedule.
889 */
890 DBGCP ( ehci, "EHCI %s periodic schedule: ", ehci->name );
892 list_for_each_entry_reverse ( endpoint, &ehci->periodic, schedule ) {
893 queue = endpoint->ring.head;
894 queue->link = cpu_to_le32 ( link );
895 wmb();
896 DBGCP ( ehci, "%s%d",
897 ( ( link == EHCI_LINK_TERMINATE ) ? "" : "<-" ),
898 endpoint->ep->interval );
899 link = ehci_link_qh ( queue );
900 }
901 DBGCP ( ehci, "\n" );
902
903 /* Populate periodic frame list */
904 DBGCP ( ehci, "EHCI %s periodic frame list:", ehci->name );
905 frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
906 for ( i = 0 ; i < frames ; i++ ) {
907
908 /* Calculate maximum interval (in microframes) which
909 * may appear as part of this frame list.
910 */
911 if ( i == 0 ) {
912 /* Start of list: include all endpoints */
913 max_interval = -1U;
914 } else {
915 /* Calculate highest power-of-two frame interval */
916 max_interval = ( 1 << ( ffs ( i ) - 1 ) );
917 /* Convert to microframes */
918 max_interval <<= 3;
919 /* Round up to nearest 2^n-1 */
920 max_interval = ( ( max_interval << 1 ) - 1 );
921 }
922
923 /* Find first endpoint in schedule satisfying this
924 * maximum interval constraint.
925 */
927 list_for_each_entry ( endpoint, &ehci->periodic, schedule ) {
928 if ( endpoint->ep->interval <= max_interval ) {
929 queue = endpoint->ring.head;
930 link = ehci_link_qh ( queue );
931 DBGCP ( ehci, " %d:%d",
932 i, endpoint->ep->interval );
933 break;
934 }
935 }
936 ehci->frame[i].link = cpu_to_le32 ( link );
937 }
938 wmb();
939 DBGCP ( ehci, "\n" );
940}
#define EHCI_LINK_TERMINATE
List terminator.
Definition ehci.h:215
#define EHCI_PERIODIC_FRAMES(flsize)
Number of elements in frame list.
Definition ehci.h:109
#define DBGCP(...)
Definition compiler.h:539
#define ffs(x)
Find first (i.e.
Definition strings.h:141
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
struct list_head periodic
Periodic schedule.
Definition ehci.h:522
struct ehci_periodic_frame * frame
Periodic frame list.
Definition ehci.h:512
struct usb_endpoint * ep
USB endpoint.
Definition ehci.h:533
uint32_t link
First queue head.
Definition ehci.h:226
unsigned int interval
Interval (in microframes)
Definition usb.h:416

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, ehci_periodic_frame::link, 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()

void ehci_periodic_add ( struct ehci_endpoint * endpoint)
static

Add endpoint to periodic schedule.

Parameters
endpointEndpoint

Definition at line 947 of file ehci.c.

947 {
948 struct ehci_device *ehci = endpoint->ehci;
949 struct ehci_endpoint *before;
950 unsigned int interval = endpoint->ep->interval;
951
952 /* Find first endpoint with a smaller interval */
954 if ( before->ep->interval < interval )
955 break;
956 }
957 list_add_tail ( &endpoint->schedule, &before->schedule );
958
959 /* Rebuild schedule */
961}
static void ehci_periodic_schedule(struct ehci_device *ehci)
(Re)build periodic schedule
Definition ehci.c:877
int32_t before
Initial microcode version.
Definition ucode.h:5

References before, 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()

int ehci_periodic_del ( struct ehci_endpoint * endpoint)
static

Remove endpoint from periodic schedule.

Parameters
endpointEndpoint
Return values
rcReturn status code

Definition at line 969 of file ehci.c.

969 {
970 struct ehci_device *ehci = endpoint->ehci;
971
972 /* Remove from schedule */
973 list_check_contains_entry ( endpoint, &ehci->periodic, schedule );
974 list_del ( &endpoint->schedule );
975
976 /* Rebuild schedule */
977 ehci_periodic_schedule ( ehci );
978
979 /* Delay for a whole USB frame (with a 100% safety margin) */
980 mdelay ( 2 );
981
982 return 0;
983}

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()

void ehci_schedule_add ( struct ehci_endpoint * endpoint)
static

Add endpoint to appropriate schedule.

Parameters
endpointEndpoint

Definition at line 990 of file ehci.c.

990 {
991 struct usb_endpoint *ep = endpoint->ep;
992 unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
993
995 ehci_periodic_add ( endpoint );
996 } else {
997 ehci_async_add ( endpoint );
998 }
999}
static void ehci_async_add(struct ehci_endpoint *endpoint)
Add endpoint to asynchronous schedule.
Definition ehci.c:816
static void ehci_periodic_add(struct ehci_endpoint *endpoint)
Add endpoint to periodic schedule.
Definition ehci.c:947
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition usb.h:293
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition usb.h:281
uint8_t attr
Type and attributes.
Definition librm.h:7
A USB endpoint.
Definition usb.h:404
unsigned int attributes
Attributes.
Definition usb.h:410

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()

int ehci_schedule_del ( struct ehci_endpoint * endpoint)
static

Remove endpoint from appropriate schedule.

Parameters
endpointEndpoint
Return values
rcReturn status code

Definition at line 1007 of file ehci.c.

1007 {
1008 struct usb_endpoint *ep = endpoint->ep;
1009 unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1010
1012 return ehci_periodic_del ( endpoint );
1013 } else {
1014 return ehci_async_del ( endpoint );
1015 }
1016}
static int ehci_periodic_del(struct ehci_endpoint *endpoint)
Remove endpoint from periodic schedule.
Definition ehci.c:969
static int ehci_async_del(struct ehci_endpoint *endpoint)
Remove endpoint from asynchronous schedule.
Definition ehci.c:832

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()

uint32_t ehci_endpoint_characteristics ( struct usb_endpoint * ep)
static

Determine endpoint characteristics.

Parameters
epUSB endpoint
Return values
chrEndpoint characteristics

Definition at line 1031 of file ehci.c.

1031 {
1032 struct usb_device *usb = ep->usb;
1033 unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1034 uint32_t chr;
1035
1036 /* Determine basic characteristics */
1037 chr = ( EHCI_CHR_ADDRESS ( usb->address ) |
1039 EHCI_CHR_MAX_LEN ( ep->mtu ) );
1040
1041 /* Control endpoints require manual control of the data toggle */
1043 chr |= EHCI_CHR_TOGGLE;
1044
1045 /* Determine endpoint speed */
1046 if ( usb->speed == USB_SPEED_HIGH ) {
1047 chr |= EHCI_CHR_EPS_HIGH;
1048 } else {
1049 if ( usb->speed == USB_SPEED_FULL ) {
1050 chr |= EHCI_CHR_EPS_FULL;
1051 } else {
1052 chr |= EHCI_CHR_EPS_LOW;
1053 }
1055 chr |= EHCI_CHR_CONTROL;
1056 }
1057
1058 return chr;
1059}
#define EHCI_CHR_EPS_LOW
Low-speed endpoint.
Definition ehci.h:318
#define EHCI_CHR_EPS_HIGH
High-speed endpoint.
Definition ehci.h:321
#define EHCI_CHR_CONTROL
Control endpoint flag.
Definition ehci.h:333
#define EHCI_CHR_MAX_LEN(len)
Maximum packet length.
Definition ehci.h:330
#define EHCI_CHR_TOGGLE
Explicit data toggles.
Definition ehci.h:324
#define EHCI_CHR_ADDRESS(address)
Device address.
Definition ehci.h:306
#define EHCI_CHR_ENDPOINT(address)
Endpoint number.
Definition ehci.h:309
#define EHCI_CHR_EPS_FULL
Full-speed endpoint.
Definition ehci.h:315
@ USB_SPEED_FULL
Full speed (12Mbps)
Definition usb.h:51
@ USB_SPEED_HIGH
High speed (480Mbps)
Definition usb.h:53
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
Definition usb.h:287
A USB device.
Definition usb.h:723
unsigned int address
Device address, if assigned.
Definition usb.h:733
struct usb_endpoint * ep[32]
Endpoint list.
Definition usb.h:745
unsigned int speed
Device speed.
Definition usb.h:729
size_t mtu
Maximum transfer size.
Definition usb.h:412
struct usb_device * usb
USB device.
Definition usb.h:406
unsigned int address
Endpoint address.
Definition usb.h:408

References usb_device::address, usb_endpoint::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()

uint32_t ehci_endpoint_capabilities ( struct usb_endpoint * ep)
static

Determine endpoint capabilities.

Parameters
epUSB endpoint
Return values
capEndpoint capabilities

Definition at line 1067 of file ehci.c.

1067 {
1068 struct usb_device *usb = ep->usb;
1069 struct usb_port *tt = usb_transaction_translator ( usb );
1070 unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
1071 uint32_t cap;
1072 unsigned int i;
1073
1074 /* Determine basic capabilities */
1075 cap = EHCI_CAP_MULT ( ep->burst + 1 );
1076
1077 /* Determine interrupt schedule mask, if applicable */
1078 if ( ( attr == USB_ENDPOINT_ATTR_INTERRUPT ) &&
1079 ( ( ep->interval != 0 ) /* avoid infinite loop */ ) ) {
1080 for ( i = 0 ; i < 8 /* microframes per frame */ ;
1081 i += ep->interval ) {
1082 cap |= EHCI_CAP_INTR_SCHED ( i );
1083 }
1084 }
1085
1086 /* Set transaction translator hub address and port, if applicable */
1087 if ( tt ) {
1088 assert ( tt->hub->usb );
1089 cap |= ( EHCI_CAP_TT_HUB ( tt->hub->usb->address ) |
1090 EHCI_CAP_TT_PORT ( tt->address ) );
1093 }
1094
1095 return cap;
1096}
#define EHCI_CAP_TT_HUB(address)
Transaction translator hub address.
Definition ehci.h:361
#define EHCI_CAP_TT_PORT(port)
Transaction translator port number.
Definition ehci.h:364
#define EHCI_CAP_MULT(mult)
High-bandwidth pipe multiplier.
Definition ehci.h:367
#define EHCI_CAP_INTR_SCHED(uframe)
Interrupt schedule mask.
Definition ehci.h:336
#define EHCI_CAP_SPLIT_SCHED_DEFAULT
Default split completion schedule mask.
Definition ehci.h:355
unsigned int burst
Maximum burst size.
Definition usb.h:414
struct usb_device * usb
Underlying USB device, if any.
Definition usb.h:847
A USB port.
Definition usb.h:813
struct usb_hub * hub
USB hub.
Definition usb.h:815
struct usb_device * usb
Currently attached device (if in use)
Definition usb.h:835
unsigned int address
Port address.
Definition usb.h:817
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
Definition usb.c:2372

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_hub::usb, usb_port::usb, USB_ENDPOINT_ATTR_INTERRUPT, USB_ENDPOINT_ATTR_TYPE_MASK, and usb_transaction_translator().

Referenced by ehci_endpoint_update().

◆ ehci_endpoint_update()

void ehci_endpoint_update ( struct usb_endpoint * ep)
static

Update endpoint characteristics and capabilities.

Parameters
epUSB endpoint

Definition at line 1103 of file ehci.c.

1103 {
1104 struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1105 struct ehci_queue_head *head;
1106
1107 /* Update queue characteristics and capabilities */
1108 head = endpoint->ring.head;
1111}
static uint32_t ehci_endpoint_capabilities(struct usb_endpoint *ep)
Determine endpoint capabilities.
Definition ehci.c:1067
static uint32_t ehci_endpoint_characteristics(struct usb_endpoint *ep)
Determine endpoint characteristics.
Definition ehci.c:1031
uint8_t head
Head number.
Definition int13.h:23
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition usb.h:587

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

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

◆ ehci_endpoint_open()

int ehci_endpoint_open ( struct usb_endpoint * ep)
static

Open endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 1119 of file ehci.c.

1119 {
1120 struct usb_device *usb = ep->usb;
1121 struct ehci_device *ehci = usb_get_hostdata ( usb );
1122 struct ehci_endpoint *endpoint;
1123 int rc;
1124
1125 /* Allocate and initialise structure */
1126 endpoint = zalloc ( sizeof ( *endpoint ) );
1127 if ( ! endpoint ) {
1128 rc = -ENOMEM;
1129 goto err_alloc;
1130 }
1131 endpoint->ehci = ehci;
1132 endpoint->ep = ep;
1133 usb_endpoint_set_hostdata ( ep, endpoint );
1134
1135 /* Initialise descriptor ring */
1136 if ( ( rc = ehci_ring_alloc ( ehci, &endpoint->ring ) ) != 0 )
1137 goto err_ring_alloc;
1138
1139 /* Update queue characteristics and capabilities */
1141
1142 /* Add to list of endpoints */
1143 list_add_tail ( &endpoint->list, &ehci->endpoints );
1144
1145 /* Add to schedule */
1146 ehci_schedule_add ( endpoint );
1147
1148 return 0;
1149
1150 ehci_ring_free ( &endpoint->ring );
1151 err_ring_alloc:
1152 free ( endpoint );
1153 err_alloc:
1154 return rc;
1155}
static int ehci_ring_alloc(struct ehci_device *ehci, struct ehci_ring *ring)
Allocate transfer descriptor ring.
Definition ehci.c:549
static void ehci_schedule_add(struct ehci_endpoint *endpoint)
Add endpoint to appropriate schedule.
Definition ehci.c:990
static void ehci_ring_free(struct ehci_ring *ring)
Free transfer descriptor ring.
Definition ehci.c:626
static void ehci_endpoint_update(struct usb_endpoint *ep)
Update endpoint characteristics and capabilities.
Definition ehci.c:1103
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition usb.h:795
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
Definition usb.h:576
struct list_head endpoints
List of all endpoints.
Definition ehci.h:515
struct list_head list
List of all endpoints.
Definition ehci.h:535

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()

void ehci_endpoint_close ( struct usb_endpoint * ep)
static

Close endpoint.

Parameters
epUSB endpoint

Definition at line 1162 of file ehci.c.

1162 {
1163 struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1164 struct ehci_device *ehci = endpoint->ehci;
1165 struct usb_device *usb = ep->usb;
1166 struct io_buffer *iobuf;
1167 int rc;
1168
1169 /* Remove from schedule */
1170 if ( ( rc = ehci_schedule_del ( endpoint ) ) != 0 ) {
1171 /* No way to prevent hardware from continuing to
1172 * access the memory, so leak it.
1173 */
1174 DBGC ( ehci, "EHCI %s %s could not unschedule: %s\n",
1175 usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
1176 return;
1177 }
1178
1179 /* Cancel any incomplete transfers */
1180 while ( ehci_ring_fill ( &endpoint->ring ) ) {
1181 iobuf = ehci_dequeue ( &endpoint->ring );
1182 if ( iobuf )
1183 usb_complete_err ( ep, iobuf, -ECANCELED );
1184 }
1185
1186 /* Remove from list of endpoints */
1187 list_del ( &endpoint->list );
1188
1189 /* Free descriptor ring */
1190 ehci_ring_free ( &endpoint->ring );
1191
1192 /* Free endpoint */
1193 free ( endpoint );
1194}
static struct io_buffer * ehci_dequeue(struct ehci_ring *ring)
Dequeue a transfer descriptor.
Definition ehci.c:745
static int ehci_schedule_del(struct ehci_endpoint *endpoint)
Remove endpoint from appropriate schedule.
Definition ehci.c:1007
#define ECANCELED
Operation canceled.
Definition errno.h:344
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
char name[32]
Name.
Definition usb.h:725
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition usb.c:221
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition usb.c:587

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()

int ehci_endpoint_reset ( struct usb_endpoint * ep)
static

Reset endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 1202 of file ehci.c.

1202 {
1203 struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1204 struct ehci_ring *ring = &endpoint->ring;
1205 struct ehci_transfer_descriptor *cache = &ring->head->cache;
1206 uint32_t link;
1207
1208 /* Sanity checks */
1209 assert ( ! ( cache->status & EHCI_STATUS_ACTIVE ) );
1210 assert ( cache->status & EHCI_STATUS_HALTED );
1211
1212 /* Reset residual count */
1213 ring->residual = 0;
1214
1215 /* Reset data toggle */
1216 cache->len = 0;
1217
1218 /* Prepare to restart at next unconsumed descriptor */
1219 link = virt_to_phys ( &ring->desc[ ring->cons % EHCI_RING_COUNT ] );
1220 cache->next = cpu_to_le32 ( link );
1221
1222 /* Restart ring */
1223 wmb();
1224 cache->status = 0;
1225
1226 return 0;
1227}
#define EHCI_STATUS_HALTED
Halted.
Definition ehci.h:259
A transfer descriptor ring.
Definition ehci.h:370
size_t residual
Residual untransferred data.
Definition ehci.h:377
uint8_t status
Status.
Definition ehci.h:236
uint16_t len
Transfer length.
Definition ehci.h:240

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(), and wmb.

◆ ehci_endpoint_mtu()

int ehci_endpoint_mtu ( struct usb_endpoint * ep)
static

Update MTU.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 1235 of file ehci.c.

1235 {
1236
1237 /* Update endpoint characteristics and capabilities */
1238 ehci_endpoint_update ( ep );
1239
1240 return 0;
1241}

References ehci_endpoint_update().

◆ ehci_endpoint_message()

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

1251 {
1252 struct ehci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
1253 struct ehci_device *ehci = endpoint->ehci;
1254 struct usb_setup_packet *packet;
1255 unsigned int input;
1256 struct ehci_transfer xfers[3];
1257 struct ehci_transfer *xfer = xfers;
1258 size_t len;
1259 int rc;
1260
1261 /* Construct setup stage */
1262 assert ( iob_len ( iobuf ) >= sizeof ( *packet ) );
1263 packet = iobuf->data;
1264 iob_pull ( iobuf, sizeof ( *packet ) );
1265 xfer->data = packet;
1266 xfer->len = sizeof ( *packet );
1267 xfer->flags = EHCI_FL_PID_SETUP;
1268 xfer++;
1269
1270 /* Construct data stage, if applicable */
1271 len = iob_len ( iobuf );
1272 input = ( packet->request & cpu_to_le16 ( USB_DIR_IN ) );
1273 if ( len ) {
1274 xfer->data = iobuf->data;
1275 xfer->len = len;
1276 xfer->flags = ( EHCI_FL_TOGGLE |
1278 xfer++;
1279 }
1280
1281 /* Construct status stage */
1282 xfer->data = NULL;
1283 xfer->len = 0;
1284 xfer->flags = ( EHCI_FL_TOGGLE | EHCI_FL_IOC |
1285 ( ( len && input ) ? EHCI_FL_PID_OUT : EHCI_FL_PID_IN));
1286 xfer++;
1287
1288 /* Enqueue transfer */
1289 if ( ( rc = ehci_enqueue ( ehci, &endpoint->ring, iobuf, xfers,
1290 ( xfer - xfers ) ) ) != 0 )
1291 return rc;
1292
1293 return 0;
1294}
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:655
#define EHCI_FL_PID_OUT
OUT token.
Definition ehci.h:268
#define EHCI_FL_PID_SETUP
SETUP token.
Definition ehci.h:274
#define EHCI_FL_PID_IN
IN token.
Definition ehci.h:271
#define EHCI_FL_IOC
Interrupt on completion.
Definition ehci.h:283
#define USB_DIR_IN
Data transfer is from device to host.
Definition usb.h:98
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
#define iob_pull(iobuf, len)
Definition iobuf.h:107
An EHCI transfer.
Definition ehci.h:465
void * data
Start of data.
Definition iobuf.h:53
A USB setup data packet.
Definition usb.h:83
uint16_t request
Request.
Definition usb.h:85

References assert, cpu_to_le16, ehci_transfer::data, io_buffer::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, ehci_transfer::len, len, NULL, rc, usb_setup_packet::request, ehci_endpoint::ring, USB_DIR_IN, and usb_endpoint_get_hostdata().

◆ ehci_endpoint_count()

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

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

References count, EHCI_MTU, and len.

Referenced by ehci_endpoint_stream().

◆ ehci_endpoint_stream()

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

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

References usb_endpoint::address, count, data, ehci_transfer::data, io_buffer::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, ehci_transfer::flags, flags, iob_len(), ehci_transfer::len, len, rc, ehci_endpoint::ring, USB_DIR_IN, and usb_endpoint_get_hostdata().

◆ ehci_endpoint_poll()

void ehci_endpoint_poll ( struct ehci_endpoint * endpoint)
static

Poll for completions.

Parameters
endpointEndpoint

Definition at line 1376 of file ehci.c.

1376 {
1377 struct ehci_device *ehci = endpoint->ehci;
1378 struct ehci_ring *ring = &endpoint->ring;
1380 struct usb_endpoint *ep = endpoint->ep;
1381 struct usb_device *usb = ep->usb;
1382 struct io_buffer *iobuf;
1383 unsigned int index;
1384 unsigned int status;
1385 int rc;
1386
1387 /* Consume all completed descriptors */
1388 while ( ehci_ring_fill ( &endpoint->ring ) ) {
1389
1390 /* Stop if we reach an uncompleted descriptor */
1391 rmb();
1392 index = ( ring->cons % EHCI_RING_COUNT );
1393 desc = &ring->desc[index];
1394 status = desc->status;
1395 if ( status & EHCI_STATUS_ACTIVE )
1396 break;
1397
1398 /* Consume this descriptor */
1399 iobuf = ehci_dequeue ( ring );
1400
1401 /* If we have encountered an error, then consume all
1402 * remaining descriptors in this transaction, report
1403 * the error to the USB core, and stop further
1404 * processing.
1405 */
1406 if ( status & EHCI_STATUS_HALTED ) {
1407 rc = -EIO_STATUS ( status );
1408 DBGC ( ehci, "EHCI %s %s completion %d failed (status "
1409 "%02x): %s\n", usb->name,
1411 strerror ( rc ) );
1412 while ( ! iobuf )
1413 iobuf = ehci_dequeue ( ring );
1414 usb_complete_err ( endpoint->ep, iobuf, rc );
1415 return;
1416 }
1417
1418 /* Accumulate residual data count */
1419 ring->residual += ( le16_to_cpu ( desc->len ) & EHCI_LEN_MASK );
1420
1421 /* If this is not the end of a transaction (i.e. has
1422 * no I/O buffer), then continue to next descriptor.
1423 */
1424 if ( ! iobuf )
1425 continue;
1426
1427 /* Update I/O buffer length */
1428 iob_unput ( iobuf, ring->residual );
1429 ring->residual = 0;
1430
1431 /* Report completion to USB core */
1432 usb_complete ( endpoint->ep, iobuf );
1433 }
1434}
#define EIO_STATUS(status)
Construct error code from transfer descriptor status.
Definition ehci.c:55
#define le16_to_cpu(value)
Definition byteswap.h:113
#define rmb()
Definition io.h:545
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition usb.h:1087
#define iob_unput(iobuf, len)
Definition iobuf.h:140

References ehci_ring::cons, DBGC, desc, 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, usb_device::name, rc, ehci_ring::residual, ehci_endpoint::ring, rmb, status, strerror(), usb_endpoint::usb, usb_complete(), usb_complete_err(), and usb_endpoint_name().

Referenced by ehci_bus_poll().

◆ ehci_device_open()

int ehci_device_open ( struct usb_device * usb)
static

Open device.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 1449 of file ehci.c.

1449 {
1450 struct ehci_device *ehci = usb_bus_get_hostdata ( usb->port->hub->bus );
1451
1452 usb_set_hostdata ( usb, ehci );
1453 return 0;
1454}
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition usb.h:1062
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition usb.h:784
struct usb_port * port
USB port.
Definition usb.h:727
struct usb_bus * bus
USB bus.
Definition usb.h:845

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

◆ ehci_device_close()

void ehci_device_close ( struct usb_device * usb)
static

Close device.

Parameters
usbUSB device

Definition at line 1461 of file ehci.c.

1461 {
1462 struct ehci_device *ehci = usb_get_hostdata ( usb );
1463 struct usb_bus *bus = ehci->bus;
1464
1465 /* Free device address, if assigned */
1466 if ( usb->address )
1467 usb_free_address ( bus, usb->address );
1468}
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
Definition usb.c:2284

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

◆ ehci_device_address()

int ehci_device_address ( struct usb_device * usb)
static

Assign device address.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 1476 of file ehci.c.

1476 {
1477 struct ehci_device *ehci = usb_get_hostdata ( usb );
1478 struct usb_bus *bus = ehci->bus;
1479 struct usb_endpoint *ep0 = usb_endpoint ( usb, USB_EP0_ADDRESS );
1480 int address;
1481 int rc;
1482
1483 /* Sanity checks */
1484 assert ( usb->address == 0 );
1485 assert ( ep0 != NULL );
1486
1487 /* Allocate device address */
1489 if ( address < 0 ) {
1490 rc = address;
1491 DBGC ( ehci, "EHCI %s could not allocate address: %s\n",
1492 usb->name, strerror ( rc ) );
1493 goto err_alloc_address;
1494 }
1495
1496 /* Set address */
1497 if ( ( rc = usb_set_address ( usb, address ) ) != 0 )
1498 goto err_set_address;
1499
1500 /* Update device address */
1501 usb->address = address;
1502
1503 /* Update control endpoint characteristics and capabilities */
1504 ehci_endpoint_update ( ep0 );
1505
1506 return 0;
1507
1508 err_set_address:
1510 err_alloc_address:
1511 return rc;
1512}
uint64_t address
Base address.
Definition ena.h:13
static int usb_set_address(struct usb_device *usb, unsigned int address)
Set address.
Definition usb.h:1159
static struct usb_endpoint * usb_endpoint(struct usb_device *usb, unsigned int address)
Get USB endpoint.
Definition usb.h:806
#define USB_EP0_ADDRESS
Control endpoint address.
Definition usb.h:501
int usb_alloc_address(struct usb_bus *bus)
Allocate device address.
Definition usb.c:2264

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()

int ehci_hub_open ( struct usb_hub *hub __unused)
static

Open hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 1527 of file ehci.c.

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

References __unused.

◆ ehci_hub_close()

void ehci_hub_close ( struct usb_hub *hub __unused)
static

Close hub.

Parameters
hubUSB hub

Definition at line 1538 of file ehci.c.

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

References __unused.

◆ ehci_root_open()

int ehci_root_open ( struct usb_hub * hub)
static

Open root hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 1556 of file ehci.c.

1556 {
1557 struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1558 uint32_t portsc;
1559 unsigned int i;
1560
1561 /* Route all ports to EHCI controller */
1563
1564 /* Enable power to all ports */
1565 for ( i = 1 ; i <= ehci->ports ; i++ ) {
1566 portsc = readl ( ehci->op + EHCI_OP_PORTSC ( i ) );
1567 portsc &= ~EHCI_PORTSC_CHANGE;
1568 portsc |= EHCI_PORTSC_PP;
1569 writel ( portsc, ehci->op + EHCI_OP_PORTSC ( i ) );
1570 }
1571
1572 /* Wait 20ms after potentially enabling power to a port */
1574
1575 return 0;
1576}
#define EHCI_PORTSC_CHANGE
Port status change mask.
Definition ehci.h:211
#define EHCI_CONFIGFLAG_CF
Configure flag.
Definition ehci.h:175
#define EHCI_OP_PORTSC(port)
Port status and control register.
Definition ehci.h:178
#define EHCI_PORTSC_PP
Port power.
Definition ehci.h:205
#define EHCI_PORT_POWER_DELAY_MS
Time to delay after enabling power to a port.
Definition ehci.h:426
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition usb.h:948

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

◆ ehci_root_close()

void ehci_root_close ( struct usb_hub * hub)
static

Close root hub.

Parameters
hubUSB hub

Definition at line 1583 of file ehci.c.

1583 {
1584 struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1585
1586 /* Route all ports back to companion controllers */
1587 writel ( 0, ehci->op + EHCI_OP_CONFIGFLAG );
1588}

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

◆ ehci_root_enable()

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

1597 {
1598 struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1599 uint32_t portsc;
1600 unsigned int line;
1601 unsigned int i;
1602
1603 /* Check for a low-speed device */
1604 portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1605 line = EHCI_PORTSC_LINE_STATUS ( portsc );
1606 if ( line == EHCI_PORTSC_LINE_STATUS_LOW ) {
1607 DBGC ( ehci, "EHCI %s-%d detected low-speed device: "
1608 "disowning\n", ehci->name, port->address );
1609 goto disown;
1610 }
1611
1612 /* Reset port */
1613 portsc &= ~( EHCI_PORTSC_PED | EHCI_PORTSC_CHANGE );
1614 portsc |= EHCI_PORTSC_PR;
1615 writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1617 portsc &= ~EHCI_PORTSC_PR;
1618 writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1619
1620 /* Wait for reset to complete */
1621 for ( i = 0 ; i < EHCI_PORT_RESET_MAX_WAIT_MS ; i++ ) {
1622
1623 /* Check port status */
1624 portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1625 if ( ! ( portsc & EHCI_PORTSC_PR ) ) {
1626 if ( portsc & EHCI_PORTSC_PED )
1627 return 0;
1628 DBGC ( ehci, "EHCI %s-%d not enabled after reset: "
1629 "disowning\n", ehci->name, port->address );
1630 goto disown;
1631 }
1632
1633 /* Delay */
1634 mdelay ( 1 );
1635 }
1636
1637 DBGC ( ehci, "EHCI %s-%d timed out waiting for port to reset\n",
1638 ehci->name, port->address );
1639 return -ETIMEDOUT;
1640
1641 disown:
1642 /* Disown port */
1643 portsc &= ~EHCI_PORTSC_CHANGE;
1644 portsc |= EHCI_PORTSC_OWNER;
1645 writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1646
1647 /* Delay to allow child companion controllers to settle */
1649
1650 /* Poll child companion controllers */
1651 ehci_poll_companions ( ehci );
1652
1653 return -ENODEV;
1654}
u8 port
Port number.
Definition CIB_PRM.h:3
static void ehci_poll_companions(struct ehci_device *ehci)
Poll child companion controllers.
Definition ehci.c:380
#define EHCI_PORT_RESET_MAX_WAIT_MS
Maximum time to wait for a port reset to complete.
Definition ehci.h:462
#define EHCI_PORTSC_LINE_STATUS(portsc)
Line status.
Definition ehci.h:199
#define EHCI_PORTSC_LINE_STATUS_LOW
Line status: low-speed device.
Definition ehci.h:202
#define EHCI_PORTSC_OWNER
Port owner.
Definition ehci.h:208
#define EHCI_PORTSC_PR
Port reset.
Definition ehci.h:196
#define EHCI_PORTSC_PED
Port enabled.
Definition ehci.h:187
#define EHCI_DISOWN_DELAY_MS
Time to delay after releasing ownership of a port.
Definition ehci.h:432
#define ENODEV
No such device.
Definition errno.h:510
#define USB_RESET_DELAY_MS
Minimum reset time.
Definition usb.h:1328

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()

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

1663 {
1664 struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1665 uint32_t portsc;
1666
1667 /* Disable port */
1668 portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1669 portsc &= ~( EHCI_PORTSC_PED | EHCI_PORTSC_CHANGE );
1670 writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1671
1672 return 0;
1673}

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

◆ ehci_root_speed()

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

1682 {
1683 struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1684 uint32_t portsc;
1685 unsigned int speed;
1686 unsigned int line;
1687 int ccs;
1688 int csc;
1689 int ped;
1690
1691 /* Read port status */
1692 portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1693 DBGC2 ( ehci, "EHCI %s-%d status is %08x\n",
1694 ehci->name, port->address, portsc );
1695 ccs = ( portsc & EHCI_PORTSC_CCS );
1696 csc = ( portsc & EHCI_PORTSC_CSC );
1697 ped = ( portsc & EHCI_PORTSC_PED );
1698 line = EHCI_PORTSC_LINE_STATUS ( portsc );
1699
1700 /* Record disconnections and clear changes */
1701 port->disconnected |= csc;
1702 writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1703
1704 /* Determine port speed */
1705 if ( ! ccs ) {
1706 /* Port not connected */
1707 speed = USB_SPEED_NONE;
1708 } else if ( line == EHCI_PORTSC_LINE_STATUS_LOW ) {
1709 /* Detected as low-speed */
1710 speed = USB_SPEED_LOW;
1711 } else if ( ped ) {
1712 /* Port already enabled: must be high-speed */
1713 speed = USB_SPEED_HIGH;
1714 } else {
1715 /* Not low-speed and not yet enabled. Could be either
1716 * full-speed or high-speed; we can't yet tell.
1717 */
1718 speed = USB_SPEED_FULL;
1719 }
1720 port->speed = speed;
1721 return 0;
1722}
#define EHCI_PORTSC_CCS
Current connect status.
Definition ehci.h:181
#define EHCI_PORTSC_CSC
Connect status change.
Definition ehci.h:184
@ USB_SPEED_LOW
Low speed (1.5Mbps)
Definition usb.h:49
@ USB_SPEED_NONE
Not connected.
Definition usb.h:47

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()

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

1733 {
1734 struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1735
1736 /* Should never be called; this is a root hub */
1737 DBGC ( ehci, "EHCI %s-%d nonsensical CLEAR_TT for %s %s\n", ehci->name,
1738 port->address, ep->usb->name, usb_endpoint_name ( ep ) );
1739
1740 return -ENOTSUP;
1741}

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

◆ ehci_root_poll()

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

1749 {
1750 struct ehci_device *ehci = usb_hub_get_drvdata ( hub );
1751 uint32_t portsc;
1752 uint32_t change;
1753
1754 /* Do nothing unless something has changed */
1755 portsc = readl ( ehci->op + EHCI_OP_PORTSC ( port->address ) );
1756 change = ( portsc & EHCI_PORTSC_CHANGE );
1757 if ( ! change )
1758 return;
1759
1760 /* Record disconnections and clear changes */
1761 port->disconnected |= ( portsc & EHCI_PORTSC_CSC );
1762 writel ( portsc, ehci->op + EHCI_OP_PORTSC ( port->address ) );
1763
1764 /* Report port status change */
1766}
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition usb.c:1858

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()

int ehci_bus_open ( struct usb_bus * bus)
static

Open USB bus.

Parameters
busUSB bus
Return values
rcReturn status code

Definition at line 1781 of file ehci.c.

1781 {
1782 struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1783 unsigned int frames;
1784 size_t len;
1785 int rc;
1786
1787 /* Sanity checks */
1788 assert ( list_empty ( &ehci->async ) );
1789 assert ( list_empty ( &ehci->periodic ) );
1790
1791 /* Allocate and initialise asynchronous queue head */
1792 ehci->head = malloc_phys ( sizeof ( *ehci->head ),
1793 ehci_align ( sizeof ( *ehci->head ) ) );
1794 if ( ! ehci->head ) {
1795 rc = -ENOMEM;
1796 goto err_alloc_head;
1797 }
1798 memset ( ehci->head, 0, sizeof ( *ehci->head ) );
1799 ehci->head->chr = cpu_to_le32 ( EHCI_CHR_HEAD );
1802 ehci_async_schedule ( ehci );
1803 writel ( virt_to_phys ( ehci->head ),
1804 ehci->op + EHCI_OP_ASYNCLISTADDR );
1805
1806 /* Use async queue head to determine control data structure segment */
1807 ehci->ctrldssegment =
1808 ( ( ( uint64_t ) virt_to_phys ( ehci->head ) ) >> 32 );
1809 if ( ehci->addr64 ) {
1810 writel ( ehci->ctrldssegment, ehci->op + EHCI_OP_CTRLDSSEGMENT);
1811 } else if ( ehci->ctrldssegment ) {
1812 DBGC ( ehci, "EHCI %s CTRLDSSEGMENT not supported\n",
1813 ehci->name );
1814 rc = -ENOTSUP;
1815 goto err_ctrldssegment;
1816 }
1817
1818 /* Allocate periodic frame list */
1819 frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
1820 len = ( frames * sizeof ( ehci->frame[0] ) );
1821 ehci->frame = malloc_phys ( len, EHCI_PAGE_ALIGN );
1822 if ( ! ehci->frame ) {
1823 rc = -ENOMEM;
1824 goto err_alloc_frame;
1825 }
1826 if ( ( rc = ehci_ctrl_reachable ( ehci, ehci->frame ) ) != 0 ) {
1827 DBGC ( ehci, "EHCI %s frame list unreachable\n", ehci->name );
1828 goto err_unreachable_frame;
1829 }
1830 ehci_periodic_schedule ( ehci );
1831 writel ( virt_to_phys ( ehci->frame ),
1832 ehci->op + EHCI_OP_PERIODICLISTBASE );
1833
1834 /* Start controller */
1835 ehci_run ( ehci );
1836
1837 return 0;
1838
1839 ehci_stop ( ehci );
1840 err_unreachable_frame:
1841 free_phys ( ehci->frame, len );
1842 err_alloc_frame:
1843 err_ctrldssegment:
1844 free_phys ( ehci->head, sizeof ( *ehci->head ) );
1845 err_alloc_head:
1846 return rc;
1847}
static void ehci_run(struct ehci_device *ehci)
Start EHCI device.
Definition ehci.c:453
#define EHCI_CHR_HEAD
Head of reclamation list flag.
Definition ehci.h:327
#define list_empty(list)
Test whether a list is empty.
Definition list.h:137
uint32_t chr
Endpoint characteristics.
Definition ehci.h:296

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

◆ ehci_bus_close()

void ehci_bus_close ( struct usb_bus * bus)
static

Close USB bus.

Parameters
busUSB bus

Definition at line 1854 of file ehci.c.

1854 {
1855 struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1856 unsigned int frames = EHCI_PERIODIC_FRAMES ( ehci->flsize );
1857
1858 /* Sanity checks */
1859 assert ( list_empty ( &ehci->async ) );
1860 assert ( list_empty ( &ehci->periodic ) );
1861
1862 /* Stop controller */
1863 ehci_stop ( ehci );
1864
1865 /* Free periodic frame list */
1866 free_phys ( ehci->frame, ( frames * sizeof ( ehci->frame[0] ) ) );
1867
1868 /* Free asynchronous schedule */
1869 free_phys ( ehci->head, sizeof ( *ehci->head ) );
1870}

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

◆ ehci_bus_poll()

void ehci_bus_poll ( struct usb_bus * bus)
static

Poll USB bus.

Parameters
busUSB bus

Definition at line 1877 of file ehci.c.

1877 {
1878 struct ehci_device *ehci = usb_bus_get_hostdata ( bus );
1879 struct usb_hub *hub = bus->hub;
1880 struct ehci_endpoint *endpoint;
1881 unsigned int i;
1882 uint32_t usbsts;
1883 uint32_t change;
1884
1885 /* Do nothing unless something has changed */
1886 usbsts = readl ( ehci->op + EHCI_OP_USBSTS );
1887 assert ( usbsts & EHCI_USBSTS_ASYNC );
1888 assert ( usbsts & EHCI_USBSTS_PERIODIC );
1889 assert ( ! ( usbsts & EHCI_USBSTS_HCH ) );
1890 change = ( usbsts & EHCI_USBSTS_CHANGE );
1891 if ( ! change )
1892 return;
1893
1894 /* Acknowledge changes */
1895 writel ( usbsts, ehci->op + EHCI_OP_USBSTS );
1896
1897 /* Process completions, if applicable */
1898 if ( change & ( EHCI_USBSTS_USBINT | EHCI_USBSTS_USBERRINT ) ) {
1899
1900 /* Iterate over all endpoints looking for completed
1901 * descriptors. We trust that completion handlers are
1902 * minimal and will not do anything that could
1903 * plausibly affect the endpoint list itself.
1904 */
1905 list_for_each_entry ( endpoint, &ehci->endpoints, list )
1906 ehci_endpoint_poll ( endpoint );
1907 }
1908
1909 /* Process port status changes, if applicable */
1910 if ( change & EHCI_USBSTS_PORT ) {
1911
1912 /* Iterate over all ports looking for status changes */
1913 for ( i = 1 ; i <= ehci->ports ; i++ )
1914 ehci_root_poll ( hub, usb_port ( hub, i ) );
1915 }
1916
1917 /* Report fatal errors */
1918 if ( change & EHCI_USBSTS_SYSERR )
1919 DBGC ( ehci, "EHCI %s host system error\n", ehci->name );
1920}
static void ehci_root_poll(struct usb_hub *hub, struct usb_port *port)
Poll for port status changes.
Definition ehci.c:1749
static void ehci_endpoint_poll(struct ehci_endpoint *endpoint)
Poll for completions.
Definition ehci.c:1376
#define EHCI_USBSTS_PERIODIC
Periodic schedule enabled.
Definition ehci.h:142
#define EHCI_USBSTS_SYSERR
Host system error.
Definition ehci.h:136
#define EHCI_USBSTS_USBINT
USB interrupt.
Definition ehci.h:124
#define EHCI_USBSTS_ASYNC
Asynchronous schedule enabled.
Definition ehci.h:145
#define EHCI_USBSTS_USBERRINT
USB error interrupt.
Definition ehci.h:127
#define EHCI_USBSTS_PORT
Port change detect.
Definition ehci.h:130
A USB hub.
Definition usb.h:841

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()

int ehci_probe ( struct pci_device * pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 1969 of file ehci.c.

1969 {
1970 struct ehci_device *ehci;
1971 struct usb_port *port;
1972 unsigned long bar_start;
1973 size_t bar_size;
1974 unsigned int i;
1975 int rc;
1976
1977 /* Allocate and initialise structure */
1978 ehci = zalloc ( sizeof ( *ehci ) );
1979 if ( ! ehci ) {
1980 rc = -ENOMEM;
1981 goto err_alloc;
1982 }
1983 ehci->name = pci->dev.name;
1984 INIT_LIST_HEAD ( &ehci->endpoints );
1985 INIT_LIST_HEAD ( &ehci->async );
1986 INIT_LIST_HEAD ( &ehci->periodic );
1987
1988 /* Fix up PCI device */
1989 adjust_pci_device ( pci );
1990
1991 /* Map registers */
1992 bar_start = pci_bar_start ( pci, EHCI_BAR );
1993 bar_size = pci_bar_size ( pci, EHCI_BAR );
1994 ehci->regs = pci_ioremap ( pci, bar_start, bar_size );
1995 if ( ! ehci->regs ) {
1996 rc = -ENODEV;
1997 goto err_ioremap;
1998 }
1999
2000 /* Initialise EHCI device */
2001 ehci_init ( ehci, ehci->regs );
2002
2003 /* Initialise USB legacy support and claim ownership */
2004 ehci_legacy_init ( ehci, pci );
2005 ehci_legacy_claim ( ehci, pci );
2006
2007 /* Reset device */
2008 if ( ( rc = ehci_reset ( ehci ) ) != 0 )
2009 goto err_reset;
2010
2011 /* Allocate USB bus */
2012 ehci->bus = alloc_usb_bus ( &pci->dev, ehci->ports, EHCI_MTU,
2013 &ehci_operations );
2014 if ( ! ehci->bus ) {
2015 rc = -ENOMEM;
2016 goto err_alloc_bus;
2017 }
2018 usb_bus_set_hostdata ( ehci->bus, ehci );
2019 usb_hub_set_drvdata ( ehci->bus->hub, ehci );
2020
2021 /* Set port protocols */
2022 for ( i = 1 ; i <= ehci->ports ; i++ ) {
2023 port = usb_port ( ehci->bus->hub, i );
2024 port->protocol = USB_PROTO_2_0;
2025 }
2026
2027 /* Register USB bus */
2028 if ( ( rc = register_usb_bus ( ehci->bus ) ) != 0 )
2029 goto err_register;
2030
2031 pci_set_drvdata ( pci, ehci );
2032 return 0;
2033
2034 unregister_usb_bus ( ehci->bus );
2035 err_register:
2036 free_usb_bus ( ehci->bus );
2037 err_alloc_bus:
2038 ehci_reset ( ehci );
2039 err_reset:
2040 ehci_legacy_release ( ehci, pci );
2041 iounmap ( ehci->regs );
2042 err_ioremap:
2043 free ( ehci );
2044 err_alloc:
2045 return rc;
2046}
static void ehci_init(struct ehci_device *ehci, void *regs)
Initialise device.
Definition ehci.c:70
static void ehci_legacy_claim(struct ehci_device *ehci, struct pci_device *pci)
Claim ownership from BIOS.
Definition ehci.c:281
static struct usb_host_operations ehci_operations
USB host controller operations.
Definition ehci.c:1930
static void ehci_legacy_release(struct ehci_device *ehci, struct pci_device *pci)
Release ownership back to BIOS.
Definition ehci.c:341
static int ehci_reset(struct ehci_device *ehci)
Reset EHCI device.
Definition ehci.c:503
static void ehci_legacy_init(struct ehci_device *ehci, struct pci_device *pci)
Initialise USB legacy support.
Definition ehci.c:248
#define EHCI_BAR
EHCI PCI BAR.
Definition ehci.h:37
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
@ USB_PROTO_2_0
USB 2.0.
Definition usb.h:23
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition usb.h:960
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition usb.h:937
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition usb.h:1051
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition pci.c:164
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition pci.c:97
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:366
char name[40]
Name.
Definition device.h:79
void * regs
Registers.
Definition ehci.h:486
struct device dev
Generic device.
Definition pci.h:213
struct usb_hub * hub
Root hub.
Definition usb.h:995
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition usb.c:2171
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition usb.c:2131
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:2095
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition usb.c:2195

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

◆ ehci_remove()

void ehci_remove ( struct pci_device * pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 2053 of file ehci.c.

2053 {
2054 struct ehci_device *ehci = pci_get_drvdata ( pci );
2055 struct usb_bus *bus = ehci->bus;
2056
2058 assert ( list_empty ( &ehci->async ) );
2059 assert ( list_empty ( &ehci->periodic ) );
2060 free_usb_bus ( bus );
2061 ehci_reset ( ehci );
2062 ehci_legacy_release ( ehci, pci );
2063 iounmap ( ehci->regs );
2064 free ( ehci );
2065}
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:376

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()

void ehci_shutdown ( int booting)
static

Prepare for exit.

Parameters
bootingSystem is shutting down for OS boot

Definition at line 2087 of file ehci.c.

2087 {
2088 /* If we are shutting down to boot an OS, then prevent the
2089 * release of ownership back to BIOS.
2090 */
2092}

References ehci_legacy_prevent_release.

Referenced by __startup_fn().

◆ __startup_fn()

struct startup_fn ehci_startup __startup_fn ( STARTUP_LATE )

Startup/shutdown function.

References __startup_fn, ehci_shutdown(), and STARTUP_LATE.

Variable Documentation

◆ ehci_legacy_prevent_release

int ehci_legacy_prevent_release
static

Prevent the release of ownership back to BIOS.

Definition at line 240 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 1930 of file ehci.c.

1930 {
1931 .endpoint = {
1932 .open = ehci_endpoint_open,
1933 .close = ehci_endpoint_close,
1934 .reset = ehci_endpoint_reset,
1935 .mtu = ehci_endpoint_mtu,
1936 .message = ehci_endpoint_message,
1937 .stream = ehci_endpoint_stream,
1938 },
1939 .device = {
1940 .open = ehci_device_open,
1941 .close = ehci_device_close,
1942 .address = ehci_device_address,
1943 },
1944 .bus = {
1945 .open = ehci_bus_open,
1946 .close = ehci_bus_close,
1947 .poll = ehci_bus_poll,
1948 },
1949 .hub = {
1950 .open = ehci_hub_open,
1951 .close = ehci_hub_close,
1952 },
1953 .root = {
1954 .open = ehci_root_open,
1955 .close = ehci_root_close,
1956 .enable = ehci_root_enable,
1957 .disable = ehci_root_disable,
1958 .speed = ehci_root_speed,
1959 .clear_tt = ehci_root_clear_tt,
1960 },
1961};
static int ehci_bus_open(struct usb_bus *bus)
Open USB bus.
Definition ehci.c:1781
static void ehci_device_close(struct usb_device *usb)
Close device.
Definition ehci.c:1461
static int ehci_root_enable(struct usb_hub *hub, struct usb_port *port)
Enable port.
Definition ehci.c:1597
static int ehci_endpoint_open(struct usb_endpoint *ep)
Open endpoint.
Definition ehci.c:1119
static int ehci_device_open(struct usb_device *usb)
Open device.
Definition ehci.c:1449
static void ehci_hub_close(struct usb_hub *hub __unused)
Close hub.
Definition ehci.c:1538
static int ehci_endpoint_message(struct usb_endpoint *ep, struct io_buffer *iobuf)
Enqueue message transfer.
Definition ehci.c:1250
static int ehci_endpoint_reset(struct usb_endpoint *ep)
Reset endpoint.
Definition ehci.c:1202
static int ehci_endpoint_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
Enqueue stream transfer.
Definition ehci.c:1328
static void ehci_root_close(struct usb_hub *hub)
Close root hub.
Definition ehci.c:1583
static int ehci_root_open(struct usb_hub *hub)
Open root hub.
Definition ehci.c:1556
static int ehci_endpoint_mtu(struct usb_endpoint *ep)
Update MTU.
Definition ehci.c:1235
static void ehci_bus_poll(struct usb_bus *bus)
Poll USB bus.
Definition ehci.c:1877
static void ehci_bus_close(struct usb_bus *bus)
Close USB bus.
Definition ehci.c:1854
static int ehci_device_address(struct usb_device *usb)
Assign device address.
Definition ehci.c:1476
static int ehci_root_speed(struct usb_hub *hub, struct usb_port *port)
Update root hub port speed.
Definition ehci.c:1682
static int ehci_root_clear_tt(struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
Clear transaction translator buffer.
Definition ehci.c:1732
static int ehci_hub_open(struct usb_hub *hub __unused)
Open hub.
Definition ehci.c:1527
static int ehci_root_disable(struct usb_hub *hub, struct usb_port *port)
Disable port.
Definition ehci.c:1663
static void ehci_endpoint_close(struct usb_endpoint *ep)
Close endpoint.
Definition ehci.c:1162

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:308

EHCI PCI device IDs.

Definition at line 2068 of file ehci.c.

2068 {
2069 PCI_ROM ( 0xffff, 0xffff, "ehci", "EHCI", 0 ),
2070};

◆ __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,
}
static void ehci_remove(struct pci_device *pci)
Remove PCI device.
Definition ehci.c:2053
static int ehci_probe(struct pci_device *pci)
Probe PCI device.
Definition ehci.c:1969
static struct pci_device_id ehci_ids[]
EHCI PCI device IDs.
Definition ehci.c:2068
#define PCI_CLASS_ID(base, sub, progif)
Construct PCI class ID.
Definition pci.h:203

EHCI PCI driver.

Definition at line 2073 of file ehci.c.

2073 {
2074 .ids = ehci_ids,
2075 .id_count = ( sizeof ( ehci_ids ) / sizeof ( ehci_ids[0] ) ),
2078 .probe = ehci_probe,
2079 .remove = ehci_remove,
2080};