iPXE
Functions | Variables
uhci.c File Reference

USB Universal Host Controller Interface (UHCI) driver. More...

#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/usb.h>
#include "ehci.h"
#include "uhci.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int uhci_reachable (void *addr, size_t len)
 Check that address is reachable. More...
 
static void uhci_run (struct uhci_device *uhci)
 Start UHCI device. More...
 
static int uhci_stop (struct uhci_device *uhci)
 Stop UHCI device. More...
 
static int uhci_reset (struct uhci_device *uhci)
 Reset UHCI device. More...
 
static int uhci_ring_alloc (struct uhci_ring *ring)
 Allocate transfer ring. More...
 
static void uhci_ring_free (struct uhci_ring *ring)
 Free transfer ring. More...
 
static int uhci_enqueue (struct uhci_ring *ring, struct io_buffer *iobuf, unsigned int count)
 Enqueue new transfer. More...
 
static void uhci_describe (struct uhci_ring *ring, void *data, size_t len, uint8_t pid)
 Describe transfer. More...
 
static struct io_bufferuhci_dequeue (struct uhci_ring *ring)
 Dequeue transfer. More...
 
static void uhci_restart (struct uhci_ring *ring, uint32_t toggle)
 Restart ring. More...
 
static uint32_t uhci_link_qh (struct uhci_queue_head *queue)
 Get link value for a queue head. More...
 
static void uhci_async_schedule (struct uhci_device *uhci)
 (Re)build asynchronous schedule More...
 
static void uhci_async_add (struct uhci_endpoint *endpoint)
 Add endpoint to asynchronous schedule. More...
 
static void uhci_async_del (struct uhci_endpoint *endpoint)
 Remove endpoint from asynchronous schedule. More...
 
static void uhci_periodic_schedule (struct uhci_device *uhci)
 (Re)build periodic schedule More...
 
static void uhci_periodic_add (struct uhci_endpoint *endpoint)
 Add endpoint to periodic schedule. More...
 
static void uhci_periodic_del (struct uhci_endpoint *endpoint)
 Remove endpoint from periodic schedule. More...
 
static void uhci_schedule_add (struct uhci_endpoint *endpoint)
 Add endpoint to appropriate schedule. More...
 
static void uhci_schedule_del (struct uhci_endpoint *endpoint)
 Remove endpoint from appropriate schedule. More...
 
static int uhci_endpoint_open (struct usb_endpoint *ep)
 Open endpoint. More...
 
static void uhci_endpoint_close (struct usb_endpoint *ep)
 Close endpoint. More...
 
static int uhci_endpoint_reset (struct usb_endpoint *ep)
 Reset endpoint. More...
 
static int uhci_endpoint_mtu (struct usb_endpoint *ep)
 Update MTU. More...
 
static int uhci_endpoint_message (struct usb_endpoint *ep, struct io_buffer *iobuf)
 Enqueue message transfer. More...
 
static int uhci_endpoint_stream (struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
 Enqueue stream transfer. More...
 
static int uhci_is_message (struct uhci_transfer *xfer)
 Check if transfer is a message transfer. More...
 
static void uhci_endpoint_poll (struct uhci_endpoint *endpoint)
 Poll for completions. More...
 
static int uhci_device_open (struct usb_device *usb)
 Open device. More...
 
static void uhci_device_close (struct usb_device *usb)
 Close device. More...
 
static int uhci_device_address (struct usb_device *usb)
 Assign device address. More...
 
static int uhci_hub_open (struct usb_hub *hub __unused)
 Open hub. More...
 
static void uhci_hub_close (struct usb_hub *hub __unused)
 Close hub. More...
 
static int uhci_root_open (struct usb_hub *hub __unused)
 Open root hub. More...
 
static void uhci_root_close (struct usb_hub *hub __unused)
 Close root hub. More...
 
static int uhci_root_enable (struct usb_hub *hub, struct usb_port *port)
 Enable port. More...
 
static int uhci_root_disable (struct usb_hub *hub, struct usb_port *port)
 Disable port. More...
 
static int uhci_root_speed (struct usb_hub *hub, struct usb_port *port)
 Update root hub port speed. More...
 
static int uhci_root_clear_tt (struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
 Clear transaction translator buffer. More...
 
static void uhci_root_poll (struct usb_hub *hub, struct usb_port *port)
 Poll for port status changes. More...
 
static int uhci_bus_open (struct usb_bus *bus)
 Open USB bus. More...
 
static void uhci_bus_close (struct usb_bus *bus)
 Close USB bus. More...
 
static void uhci_bus_poll (struct usb_bus *bus)
 Poll USB bus. More...
 
__weak unsigned int ehci_companion (struct pci_device *pci __unused)
 Locate EHCI companion controller (when no EHCI support is present) More...
 
static int uhci_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void uhci_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

static struct usb_host_operations uhci_operations
 USB host controller operations. More...
 
static struct pci_device_id uhci_ids []
 UHCI PCI device IDs. More...
 
struct pci_driver uhci_driver __pci_driver
 UHCI PCI driver. More...
 

Detailed Description

USB Universal Host Controller Interface (UHCI) driver.

Definition in file uhci.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ uhci_reachable()

static int uhci_reachable ( void *  addr,
size_t  len 
)
inlinestatic

Check that address is reachable.

Parameters
addrAddress
lenLength
Return values
rcReturn status code

Definition at line 57 of file uhci.c.

57  {
59 
60  /* Always reachable in a 32-bit build */
61  if ( sizeof ( physaddr_t ) <= sizeof ( uint32_t ) )
62  return 0;
63 
64  /* Reachable if below 4GB */
65  if ( ( ( phys + len - 1 ) & ~0xffffffffULL ) == 0 )
66  return 0;
67 
68  return -ENOTSUP;
69 }
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static signed char phys[4]
Definition: epic100.c:88
u32 addr
Definition: sky2.h:8
unsigned int uint32_t
Definition: stdint.h:12
unsigned long physaddr_t
Definition: stdint.h:20
uint32_t len
Length.
Definition: ena.h:14

References addr, ENOTSUP, len, phys, and virt_to_phys().

Referenced by uhci_bus_open(), uhci_enqueue(), and uhci_ring_alloc().

◆ uhci_run()

static void uhci_run ( struct uhci_device uhci)
static

Start UHCI device.

Parameters
uhciUHCI device

Definition at line 83 of file uhci.c.

83  {
84  uint16_t usbcmd;
85 
86  /* Set run/stop bit */
87  usbcmd = inw ( uhci->regs + UHCI_USBCMD );
88  usbcmd |= ( UHCI_USBCMD_RUN | UHCI_USBCMD_MAX64 );
89  outw ( usbcmd, uhci->regs + UHCI_USBCMD );
90 }
unsigned short uint16_t
Definition: stdint.h:11
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
#define outw(data, io_addr)
Definition: io.h:319
#define UHCI_USBCMD_RUN
Run/stop.
Definition: uhci.h:42
unsigned long regs
Registers.
Definition: uhci.h:309
#define UHCI_USBCMD
USB command register.
Definition: uhci.h:33
#define UHCI_USBCMD_MAX64
Max packet is 64 bytes.
Definition: uhci.h:36

References inw(), outw, uhci_device::regs, UHCI_USBCMD, UHCI_USBCMD_MAX64, and UHCI_USBCMD_RUN.

Referenced by uhci_bus_open().

◆ uhci_stop()

static int uhci_stop ( struct uhci_device uhci)
static

Stop UHCI device.

Parameters
uhciUHCI device
Return values
rcReturn status code

Definition at line 98 of file uhci.c.

98  {
99  uint16_t usbcmd;
100  uint16_t usbsts;
101  unsigned int i;
102 
103  /* Clear run/stop bit */
104  usbcmd = inw ( uhci->regs + UHCI_USBCMD );
105  usbcmd &= ~UHCI_USBCMD_RUN;
106  outw ( usbcmd, uhci->regs + UHCI_USBCMD );
107 
108  /* Wait for device to stop */
109  for ( i = 0 ; i < UHCI_STOP_MAX_WAIT_MS ; i++ ) {
110 
111  /* Check if device is stopped */
112  usbsts = inw ( uhci->regs + UHCI_USBSTS );
113  if ( usbsts & UHCI_USBSTS_HCHALTED )
114  return 0;
115 
116  /* Delay */
117  mdelay ( 1 );
118  }
119 
120  DBGC ( uhci, "UHCI %s timed out waiting for stop\n", uhci->name );
121  return -ETIMEDOUT;
122 }
unsigned short uint16_t
Definition: stdint.h:11
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
#define outw(data, io_addr)
Definition: io.h:319
#define DBGC(...)
Definition: compiler.h:505
#define UHCI_USBCMD_RUN
Run/stop.
Definition: uhci.h:42
#define UHCI_USBSTS
USB status register.
Definition: uhci.h:45
const char * name
Name.
Definition: uhci.h:311
#define UHCI_USBSTS_HCHALTED
Host controller halted.
Definition: uhci.h:48
unsigned long regs
Registers.
Definition: uhci.h:309
#define UHCI_USBCMD
USB command register.
Definition: uhci.h:33
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define UHCI_STOP_MAX_WAIT_MS
Maximum time to wait for host controller to stop.
Definition: uhci.h:292
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, ETIMEDOUT, inw(), mdelay(), uhci_device::name, outw, uhci_device::regs, UHCI_STOP_MAX_WAIT_MS, UHCI_USBCMD, UHCI_USBCMD_RUN, UHCI_USBSTS, and UHCI_USBSTS_HCHALTED.

Referenced by uhci_bus_close(), uhci_bus_open(), and uhci_reset().

◆ uhci_reset()

static int uhci_reset ( struct uhci_device uhci)
static

Reset UHCI device.

Parameters
uhciUHCI device
Return values
rcReturn status code

Definition at line 130 of file uhci.c.

130  {
131  uint16_t usbcmd;
132  unsigned int i;
133  int rc;
134 
135  /* The UHCI specification states that resetting a running
136  * device may result in undefined behaviour, so try stopping
137  * it first.
138  */
139  if ( ( rc = uhci_stop ( uhci ) ) != 0 ) {
140  /* Ignore errors and attempt to reset the device anyway */
141  }
142 
143  /* Reset device */
145 
146  /* Wait for reset to complete */
147  for ( i = 0 ; i < UHCI_RESET_MAX_WAIT_MS ; i++ ) {
148 
149  /* Check if reset is complete */
150  usbcmd = inw ( uhci->regs + UHCI_USBCMD );
151  if ( ! ( usbcmd & UHCI_USBCMD_HCRESET ) )
152  return 0;
153 
154  /* Delay */
155  mdelay ( 1 );
156  }
157 
158  DBGC ( uhci, "UHCI %s timed out waiting for reset\n", uhci->name );
159  return -ETIMEDOUT;
160 }
#define UHCI_USBCMD_HCRESET
Host controller reset.
Definition: uhci.h:39
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
#define outw(data, io_addr)
Definition: io.h:319
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: uhci.h:311
unsigned long regs
Registers.
Definition: uhci.h:309
#define UHCI_USBCMD
USB command register.
Definition: uhci.h:33
#define UHCI_RESET_MAX_WAIT_MS
Maximum time to wait for reset to complete.
Definition: uhci.h:298
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
static int uhci_stop(struct uhci_device *uhci)
Stop UHCI device.
Definition: uhci.c:98

References DBGC, ETIMEDOUT, inw(), mdelay(), uhci_device::name, outw, rc, uhci_device::regs, UHCI_RESET_MAX_WAIT_MS, uhci_stop(), UHCI_USBCMD, and UHCI_USBCMD_HCRESET.

Referenced by uhci_probe(), and uhci_remove().

◆ uhci_ring_alloc()

static int uhci_ring_alloc ( struct uhci_ring ring)
static

Allocate transfer ring.

Parameters
ringTransfer ring
Return values
rcReturn status code

Definition at line 175 of file uhci.c.

175  {
176  int rc;
177 
178  /* Initialise structure */
179  memset ( ring, 0, sizeof ( *ring ) );
180 
181  /* Allocate queue head */
182  ring->head = malloc_dma ( sizeof ( *ring->head ), UHCI_ALIGN );
183  if ( ! ring->head ) {
184  rc = -ENOMEM;
185  goto err_alloc;
186  }
187  if ( ( rc = uhci_reachable ( ring->head,
188  sizeof ( *ring->head ) ) ) != 0 )
189  goto err_unreachable;
190 
191  /* Initialise queue head */
193 
194  return 0;
195 
196  err_unreachable:
197  free_dma ( ring->head, sizeof ( *ring->head ) );
198  err_alloc:
199  return rc;
200 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t current
Current transfer descriptor.
Definition: uhci.h:196
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct uhci_queue_head * head
Queue head.
Definition: uhci.h:257
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define UHCI_LINK_TERMINATE
List terminator.
Definition: uhci.h:87
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
static int uhci_reachable(void *addr, size_t len)
Check that address is reachable.
Definition: uhci.c:57
#define UHCI_ALIGN
Minimum alignment required for data structures.
Definition: uhci.h:21
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
void * memset(void *dest, int character, size_t len) __nonnull

References cpu_to_le32, uhci_queue_head::current, ENOMEM, free_dma(), uhci_ring::head, malloc_dma(), memset(), rc, UHCI_ALIGN, UHCI_LINK_TERMINATE, and uhci_reachable().

Referenced by uhci_endpoint_open().

◆ uhci_ring_free()

static void uhci_ring_free ( struct uhci_ring ring)
static

Free transfer ring.

Parameters
ringTransfer ring

Definition at line 207 of file uhci.c.

207  {
208  unsigned int i;
209 
210  /* Sanity checks */
211  assert ( uhci_ring_fill ( ring ) == 0 );
212  for ( i = 0 ; i < UHCI_RING_COUNT ; i++ )
213  assert ( ring->xfer[i] == NULL );
214 
215  /* Free queue head */
216  free_dma ( ring->head, sizeof ( *ring->head ) );
217 }
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
Definition: uhci.h:267
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: uhci.h:228
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct uhci_queue_head * head
Queue head.
Definition: uhci.h:257
struct uhci_transfer * xfer[UHCI_RING_COUNT]
Transfers.
Definition: uhci.h:252
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), free_dma(), uhci_ring::head, NULL, UHCI_RING_COUNT, uhci_ring_fill(), and uhci_ring::xfer.

Referenced by uhci_endpoint_close(), and uhci_endpoint_open().

◆ uhci_enqueue()

static int uhci_enqueue ( struct uhci_ring ring,
struct io_buffer iobuf,
unsigned int  count 
)
static

Enqueue new transfer.

Parameters
ringTransfer ring
iobufI/O buffer
countNumber of descriptors
Return values
rcReturn status code

Definition at line 227 of file uhci.c.

228  {
229  struct uhci_transfer *xfer;
230  struct uhci_transfer *end;
231  struct uhci_transfer_descriptor *desc;
232  unsigned int index = ( ring->prod % UHCI_RING_COUNT );
233  uint32_t link;
234  size_t len;
235  int rc;
236 
237  /* Sanity check */
238  assert ( count > 0 );
239  assert ( iobuf != NULL );
240 
241  /* Check for space in ring */
242  if ( ! uhci_ring_remaining ( ring ) ) {
243  rc = -ENOBUFS;
244  goto err_ring_full;
245  }
246 
247  /* Check for reachability of I/O buffer */
248  if ( ( rc = uhci_reachable ( iobuf->data, iob_len ( iobuf ) ) ) != 0 )
249  goto err_unreachable_iobuf;
250 
251  /* Allocate transfer */
252  xfer = malloc ( sizeof ( *xfer ) );
253  if ( ! xfer ) {
254  rc = -ENOMEM;
255  goto err_alloc_xfer;
256  }
257 
258  /* Initialise transfer */
259  xfer->prod = 0;
260  xfer->cons = 0;
261  xfer->len = 0;
262  xfer->iobuf = iobuf;
263 
264  /* Allocate transfer descriptors */
265  len = ( count * sizeof ( xfer->desc[0] ) );
266  xfer->desc = malloc_dma ( len, UHCI_ALIGN );
267  if ( ! xfer->desc ) {
268  rc = -ENOMEM;
269  goto err_alloc_desc;
270  }
271  if ( ( rc = uhci_reachable ( xfer->desc, len ) ) != 0 )
272  goto err_unreachable_desc;
273 
274  /* Initialise transfer descriptors */
275  memset ( xfer->desc, 0, len );
276  desc = xfer->desc;
277  for ( ; --count ; desc++ ) {
278  link = ( virt_to_phys ( desc + 1 ) | UHCI_LINK_DEPTH_FIRST );
279  desc->link = cpu_to_le32 ( link );
280  desc->flags = ring->flags;
281  }
283  desc->flags = ( ring->flags | UHCI_FL_IOC );
284 
285  /* Add to ring */
286  wmb();
287  link = virt_to_phys ( xfer->desc );
288  if ( uhci_ring_fill ( ring ) > 0 ) {
289  end = ring->end;
290  end->desc[ end->prod - 1 ].link = cpu_to_le32 ( link );
291  } else {
292  ring->head->current = cpu_to_le32 ( link );
293  }
294  assert ( ring->xfer[index] == NULL );
295  ring->xfer[index] = xfer;
296  ring->end = xfer;
297  ring->prod++;
298 
299  return 0;
300 
301  err_unreachable_desc:
302  free_dma ( xfer->desc, len );
303  err_alloc_desc:
304  free ( xfer );
305  err_alloc_xfer:
306  err_unreachable_iobuf:
307  err_ring_full:
308  return rc;
309 }
unsigned int prod
Producer counter.
Definition: uhci.h:211
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
wmb()
#define UHCI_FL_IOC
Interrupt on completion.
Definition: uhci.h:154
uint32_t link
Link pointer.
Definition: uhci.h:101
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
Definition: uhci.h:267
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: uhci.h:228
static unsigned int uhci_ring_remaining(struct uhci_ring *ring)
Calculate space remaining in transfer ring.
Definition: uhci.h:282
uint8_t flags
Flags.
Definition: uhci.h:107
uint32_t current
Current transfer descriptor.
Definition: uhci.h:196
unsigned int prod
Producer counter.
Definition: uhci.h:233
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
A single UHCI transfer.
Definition: uhci.h:209
uint8_t flags
Base flags.
Definition: uhci.h:243
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct uhci_queue_head * head
Queue head.
Definition: uhci.h:257
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
#define cpu_to_le32(value)
Definition: byteswap.h:107
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
struct io_buffer * iobuf
I/O buffer.
Definition: uhci.h:221
size_t len
Completed data length.
Definition: uhci.h:215
#define UHCI_LINK_DEPTH_FIRST
Depth-first processing.
Definition: uhci.h:81
struct uhci_transfer * xfer[UHCI_RING_COUNT]
Transfers.
Definition: uhci.h:252
#define UHCI_LINK_TERMINATE
List terminator.
Definition: uhci.h:87
unsigned int uint32_t
Definition: stdint.h:12
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
struct uhci_transfer * end
End of transfer ring (if non-empty)
Definition: uhci.h:254
uint32_t len
Length.
Definition: ena.h:14
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
void * data
Start of data.
Definition: iobuf.h:44
uint16_t count
Number of entries.
Definition: ena.h:22
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
uint32_t end
Ending offset.
Definition: netvsc.h:18
A transfer descriptor.
Definition: uhci.h:99
static int uhci_reachable(void *addr, size_t len)
Check that address is reachable.
Definition: uhci.c:57
unsigned int cons
Consumer counter.
Definition: uhci.h:213
struct uhci_transfer_descriptor * desc
Transfer descriptors.
Definition: uhci.h:218
#define UHCI_ALIGN
Minimum alignment required for data structures.
Definition: uhci.h:21
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), uhci_transfer::cons, count, cpu_to_le32, uhci_queue_head::current, io_buffer::data, uhci_transfer::desc, end, uhci_ring::end, ENOBUFS, ENOMEM, uhci_transfer_descriptor::flags, uhci_ring::flags, free, free_dma(), uhci_ring::head, index, iob_len(), uhci_transfer::iobuf, len, uhci_transfer::len, link, uhci_transfer_descriptor::link, malloc(), malloc_dma(), memset(), NULL, uhci_transfer::prod, uhci_ring::prod, rc, UHCI_ALIGN, UHCI_FL_IOC, UHCI_LINK_DEPTH_FIRST, UHCI_LINK_TERMINATE, uhci_reachable(), UHCI_RING_COUNT, uhci_ring_fill(), uhci_ring_remaining(), virt_to_phys(), wmb(), and uhci_ring::xfer.

Referenced by uhci_endpoint_message(), and uhci_endpoint_stream().

◆ uhci_describe()

static void uhci_describe ( struct uhci_ring ring,
void *  data,
size_t  len,
uint8_t  pid 
)
static

Describe transfer.

Parameters
ringTransfer ring
dataData
lenLength of data
pidPacket ID

Definition at line 319 of file uhci.c.

320  {
321  struct uhci_transfer *xfer = ring->end;
322  struct uhci_transfer_descriptor *desc;
323  size_t frag_len;
325 
326  do {
327  /* Calculate fragment length */
328  frag_len = len;
329  if ( frag_len > ring->mtu )
330  frag_len = ring->mtu;
331 
332  /* Populate descriptor */
333  desc = &xfer->desc[xfer->prod++];
334  if ( pid == USB_PID_IN )
335  desc->flags |= UHCI_FL_SPD;
336  control = ( ring->control | UHCI_CONTROL_PID ( pid ) |
337  UHCI_CONTROL_LEN ( frag_len ) );
338  desc->control = cpu_to_le32 ( control );
339  if ( data )
340  desc->data = virt_to_phys ( data );
341  wmb();
342  desc->status = UHCI_STATUS_ACTIVE;
343 
344  /* Update data toggle */
345  ring->control ^= UHCI_CONTROL_TOGGLE;
346 
347  /* Move to next descriptor */
348  data += frag_len;
349  len -= frag_len;
350 
351  } while ( len );
352 }
unsigned int prod
Producer counter.
Definition: uhci.h:211
wmb()
#define UHCI_STATUS_ACTIVE
Active.
Definition: uhci.h:121
uint32_t control
Control.
Definition: uhci.h:109
uint8_t flags
Flags.
Definition: uhci.h:107
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
A single UHCI transfer.
Definition: uhci.h:209
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define UHCI_CONTROL_TOGGLE
Data toggle.
Definition: uhci.h:169
uint8_t status
Status.
Definition: uhci.h:105
uint32_t control
Control.
Definition: myson.h:14
unsigned int uint32_t
Definition: stdint.h:12
uint32_t control
Base control word.
Definition: uhci.h:249
struct uhci_transfer * end
End of transfer ring (if non-empty)
Definition: uhci.h:254
uint32_t len
Length.
Definition: ena.h:14
uint32_t data
Buffer pointer.
Definition: uhci.h:111
A transfer descriptor.
Definition: uhci.h:99
#define UHCI_CONTROL_PID(pid)
Packet ID.
Definition: uhci.h:157
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
struct uhci_transfer_descriptor * desc
Transfer descriptors.
Definition: uhci.h:218
size_t mtu
Maximum packet length.
Definition: uhci.h:238
#define UHCI_CONTROL_LEN(len)
Data length.
Definition: uhci.h:172
#define UHCI_FL_SPD
Short packet detect.
Definition: uhci.h:142
IN PID.
Definition: usb.h:60

References control, uhci_transfer_descriptor::control, uhci_ring::control, cpu_to_le32, data, uhci_transfer_descriptor::data, uhci_transfer::desc, uhci_ring::end, uhci_transfer_descriptor::flags, len, uhci_ring::mtu, uhci_transfer::prod, uhci_transfer_descriptor::status, UHCI_CONTROL_LEN, UHCI_CONTROL_PID, UHCI_CONTROL_TOGGLE, UHCI_FL_SPD, UHCI_STATUS_ACTIVE, USB_PID_IN, virt_to_phys(), and wmb().

Referenced by uhci_endpoint_message(), and uhci_endpoint_stream().

◆ uhci_dequeue()

static struct io_buffer* uhci_dequeue ( struct uhci_ring ring)
static

Dequeue transfer.

Parameters
ringTransfer ring
Return values
iobufI/O buffer

Definition at line 360 of file uhci.c.

360  {
361  unsigned int index = ( ring->cons % UHCI_RING_COUNT );
362  struct io_buffer *iobuf;
363  struct uhci_transfer *xfer;
364  size_t len;
365 
366  /* Sanity checks */
367  assert ( uhci_ring_fill ( ring ) > 0 );
368 
369  /* Consume transfer */
370  xfer = ring->xfer[index];
371  assert ( xfer != NULL );
372  assert ( xfer->desc != NULL );
373  iobuf = xfer->iobuf;
374  assert ( iobuf != NULL );
375  ring->xfer[index] = NULL;
376  ring->cons++;
377 
378  /* Free transfer descriptors */
379  len = ( xfer->prod * sizeof ( xfer->desc[0] ) );
380  free_dma ( xfer->desc, len );
381 
382  /* Free transfer */
383  free ( xfer );
384 
385  return iobuf;
386 }
unsigned int cons
Consumer counter.
Definition: uhci.h:235
unsigned int prod
Producer counter.
Definition: uhci.h:211
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
Definition: uhci.h:267
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: uhci.h:228
A single UHCI transfer.
Definition: uhci.h:209
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct io_buffer * iobuf
I/O buffer.
Definition: uhci.h:221
struct uhci_transfer * xfer[UHCI_RING_COUNT]
Transfers.
Definition: uhci.h:252
uint32_t len
Length.
Definition: ena.h:14
struct uhci_transfer_descriptor * desc
Transfer descriptors.
Definition: uhci.h:218
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

References assert(), uhci_ring::cons, uhci_transfer::desc, free, free_dma(), index, uhci_transfer::iobuf, len, NULL, uhci_transfer::prod, UHCI_RING_COUNT, uhci_ring_fill(), and uhci_ring::xfer.

Referenced by uhci_endpoint_close(), and uhci_endpoint_poll().

◆ uhci_restart()

static void uhci_restart ( struct uhci_ring ring,
uint32_t  toggle 
)
static

Restart ring.

Parameters
ringTransfer ring
toggleExpected data toggle for next descriptor

Definition at line 394 of file uhci.c.

394  {
395  struct uhci_transfer *xfer;
396  struct uhci_transfer_descriptor *desc;
398  uint32_t link;
399  unsigned int i;
400  unsigned int j;
401 
402  /* Sanity check */
404 
405  /* If ring is empty, then just update the data toggle for the
406  * next descriptor.
407  */
408  if ( uhci_ring_fill ( ring ) == 0 ) {
409  ring->control &= ~UHCI_CONTROL_TOGGLE;
410  ring->control |= toggle;
411  return;
412  }
413 
414  /* If expected toggle does not match the toggle in the first
415  * unconsumed descriptor, then invert all toggles.
416  */
417  xfer = ring->xfer[ ring->cons % UHCI_RING_COUNT ];
418  assert ( xfer != NULL );
419  assert ( xfer->cons == 0 );
420  first = &xfer->desc[0];
421  if ( ( le32_to_cpu ( first->control ) ^ toggle ) & UHCI_CONTROL_TOGGLE){
422 
423  /* Invert toggle on all unconsumed transfer descriptors */
424  for ( i = ring->cons ; i != ring->prod ; i++ ) {
425  xfer = ring->xfer[ i % UHCI_RING_COUNT ];
426  assert ( xfer != NULL );
427  assert ( xfer->cons == 0 );
428  for ( j = 0 ; j < xfer->prod ; j++ ) {
429  desc = &xfer->desc[j];
430  desc->control ^=
432  }
433  }
434 
435  /* Invert toggle for next descriptor to be enqueued */
436  ring->control ^= UHCI_CONTROL_TOGGLE;
437  }
438 
439  /* Restart ring at first unconsumed transfer */
440  link = virt_to_phys ( first );
441  wmb();
442  ring->head->current = cpu_to_le32 ( link );
443 }
unsigned int cons
Consumer counter.
Definition: uhci.h:235
unsigned int prod
Producer counter.
Definition: uhci.h:211
wmb()
#define le32_to_cpu(value)
Definition: byteswap.h:113
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
Definition: uhci.h:267
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: uhci.h:228
uint32_t control
Control.
Definition: uhci.h:109
uint32_t current
Current transfer descriptor.
Definition: uhci.h:196
unsigned int prod
Producer counter.
Definition: uhci.h:233
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
A single UHCI transfer.
Definition: uhci.h:209
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct uhci_queue_head * head
Queue head.
Definition: uhci.h:257
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define UHCI_CONTROL_TOGGLE
Data toggle.
Definition: uhci.h:169
struct uhci_transfer * xfer[UHCI_RING_COUNT]
Transfers.
Definition: uhci.h:252
#define UHCI_LINK_TERMINATE
List terminator.
Definition: uhci.h:87
unsigned int uint32_t
Definition: stdint.h:12
uint32_t control
Base control word.
Definition: uhci.h:249
A transfer descriptor.
Definition: uhci.h:99
unsigned int cons
Consumer counter.
Definition: uhci.h:213
struct uhci_transfer_descriptor * desc
Transfer descriptors.
Definition: uhci.h:218
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23

References assert(), uhci_transfer::cons, uhci_ring::cons, uhci_transfer_descriptor::control, uhci_ring::control, cpu_to_le32, uhci_queue_head::current, uhci_transfer::desc, first, uhci_ring::head, le32_to_cpu, link, NULL, uhci_transfer::prod, uhci_ring::prod, UHCI_CONTROL_TOGGLE, UHCI_LINK_TERMINATE, UHCI_RING_COUNT, uhci_ring_fill(), virt_to_phys(), wmb(), and uhci_ring::xfer.

Referenced by uhci_endpoint_poll(), and uhci_endpoint_reset().

◆ uhci_link_qh()

static uint32_t uhci_link_qh ( struct uhci_queue_head queue)
inlinestatic

Get link value for a queue head.

Parameters
queueQueue head
Return values
linkLink value

Definition at line 458 of file uhci.c.

458  {
459 
460  return ( virt_to_phys ( queue ) | UHCI_LINK_TYPE_QH );
461 }
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define UHCI_LINK_TYPE_QH
Queue head type.
Definition: uhci.h:84
uint16_t queue
Queue ID.
Definition: ena.h:22

References queue, UHCI_LINK_TYPE_QH, and virt_to_phys().

Referenced by uhci_async_schedule(), and uhci_periodic_schedule().

◆ uhci_async_schedule()

static void uhci_async_schedule ( struct uhci_device uhci)
static

(Re)build asynchronous schedule

Parameters
uhciUHCI device

Definition at line 468 of file uhci.c.

468  {
469  struct uhci_endpoint *endpoint;
470  struct uhci_queue_head *queue;
471  uint32_t end;
472  uint32_t link;
473 
474  /* Build schedule in reverse order of execution. Provided
475  * that we only ever add or remove single endpoints, this can
476  * safely run concurrently with hardware execution of the
477  * schedule.
478  */
479  link = end = uhci_link_qh ( uhci->head );
480  list_for_each_entry_reverse ( endpoint, &uhci->async, schedule ) {
481  queue = endpoint->ring.head;
482  queue->link = cpu_to_le32 ( link );
483  wmb();
484  link = uhci_link_qh ( queue );
485  }
486  if ( link == end )
488  uhci->head->link = cpu_to_le32 ( link );
489  wmb();
490 }
A queue head.
Definition: uhci.h:192
wmb()
struct uhci_queue_head * head
Asynchronous queue head.
Definition: uhci.h:317
struct list_head async
Asynchronous schedule.
Definition: uhci.h:324
A UHCI endpoint.
Definition: uhci.h:336
struct uhci_queue_head * head
Queue head.
Definition: uhci.h:257
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
Definition: list.h:433
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define UHCI_LINK_TERMINATE
List terminator.
Definition: uhci.h:87
unsigned int uint32_t
Definition: stdint.h:12
uint32_t end
Ending offset.
Definition: netvsc.h:18
uint32_t link
Horizontal link pointer.
Definition: uhci.h:194
uint16_t queue
Queue ID.
Definition: ena.h:22
static uint32_t uhci_link_qh(struct uhci_queue_head *queue)
Get link value for a queue head.
Definition: uhci.c:458

References uhci_device::async, cpu_to_le32, end, uhci_ring::head, uhci_device::head, link, uhci_queue_head::link, list_for_each_entry_reverse, queue, uhci_endpoint::ring, uhci_link_qh(), UHCI_LINK_TERMINATE, and wmb().

Referenced by uhci_async_add(), uhci_async_del(), and uhci_bus_open().

◆ uhci_async_add()

static void uhci_async_add ( struct uhci_endpoint endpoint)
static

Add endpoint to asynchronous schedule.

Parameters
endpointEndpoint

Definition at line 497 of file uhci.c.

497  {
498  struct uhci_device *uhci = endpoint->uhci;
499 
500  /* Add to end of schedule */
501  list_add_tail ( &endpoint->schedule, &uhci->async );
502 
503  /* Rebuild schedule */
504  uhci_async_schedule ( uhci );
505 }
struct list_head async
Asynchronous schedule.
Definition: uhci.h:324
struct uhci_device * uhci
UHCI device.
Definition: uhci.h:338
static void uhci_async_schedule(struct uhci_device *uhci)
(Re)build asynchronous schedule
Definition: uhci.c:468
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head schedule
Endpoint schedule.
Definition: uhci.h:344
A UHCI device.
Definition: uhci.h:307

References uhci_device::async, list_add_tail, uhci_endpoint::schedule, uhci_endpoint::uhci, and uhci_async_schedule().

Referenced by uhci_schedule_add().

◆ uhci_async_del()

static void uhci_async_del ( struct uhci_endpoint endpoint)
static

Remove endpoint from asynchronous schedule.

Parameters
endpointEndpoint

Definition at line 512 of file uhci.c.

512  {
513  struct uhci_device *uhci = endpoint->uhci;
514 
515  /* Remove from schedule */
516  list_check_contains_entry ( endpoint, &uhci->async, schedule );
517  list_del ( &endpoint->schedule );
518 
519  /* Rebuild schedule */
520  uhci_async_schedule ( uhci );
521 
522  /* Delay for a whole USB frame (with a 100% safety margin) */
523  mdelay ( 2 );
524 }
struct list_head async
Asynchronous schedule.
Definition: uhci.h:324
struct uhci_device * uhci
UHCI device.
Definition: uhci.h:338
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void uhci_async_schedule(struct uhci_device *uhci)
(Re)build asynchronous schedule
Definition: uhci.c:468
struct list_head schedule
Endpoint schedule.
Definition: uhci.h:344
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
A UHCI device.
Definition: uhci.h:307
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition: list.h:522

References uhci_device::async, list_check_contains_entry, list_del, mdelay(), uhci_endpoint::schedule, uhci_endpoint::uhci, and uhci_async_schedule().

Referenced by uhci_schedule_del().

◆ uhci_periodic_schedule()

static void uhci_periodic_schedule ( struct uhci_device uhci)
static

(Re)build periodic schedule

Parameters
uhciUHCI device

Definition at line 531 of file uhci.c.

531  {
532  struct uhci_endpoint *endpoint;
533  struct uhci_queue_head *queue;
534  uint32_t link;
535  uint32_t end;
536  unsigned int max_interval;
537  unsigned int i;
538 
539  /* Build schedule in reverse order of execution. Provided
540  * that we only ever add or remove single endpoints, this can
541  * safely run concurrently with hardware execution of the
542  * schedule.
543  */
544  DBGCP ( uhci, "UHCI %s periodic schedule: ", uhci->name );
545  link = end = uhci_link_qh ( uhci->head );
546  list_for_each_entry_reverse ( endpoint, &uhci->periodic, schedule ) {
547  queue = endpoint->ring.head;
548  queue->link = cpu_to_le32 ( link );
549  wmb();
550  DBGCP ( uhci, "%s%d", ( ( link == end ) ? "" : "<-" ),
551  endpoint->ep->interval );
552  link = uhci_link_qh ( queue );
553  }
554  DBGCP ( uhci, "\n" );
555 
556  /* Populate periodic frame list */
557  DBGCP ( uhci, "UHCI %s periodic frame list:", uhci->name );
558  for ( i = 0 ; i < UHCI_FRAMES ; i++ ) {
559 
560  /* Calculate maximum interval (in microframes) which
561  * may appear as part of this frame list.
562  */
563  if ( i == 0 ) {
564  /* Start of list: include all endpoints */
565  max_interval = -1U;
566  } else {
567  /* Calculate highest power-of-two frame interval */
568  max_interval = ( 1 << ( ffs ( i ) - 1 ) );
569  /* Convert to microframes */
570  max_interval <<= 3;
571  /* Round up to nearest 2^n-1 */
572  max_interval = ( ( max_interval << 1 ) - 1 );
573  }
574 
575  /* Find first endpoint in schedule satisfying this
576  * maximum interval constraint.
577  */
578  link = uhci_link_qh ( uhci->head );
579  list_for_each_entry ( endpoint, &uhci->periodic, schedule ) {
580  if ( endpoint->ep->interval <= max_interval ) {
581  queue = endpoint->ring.head;
582  link = uhci_link_qh ( queue );
583  DBGCP ( uhci, " %d:%d",
584  i, endpoint->ep->interval );
585  break;
586  }
587  }
588  uhci->frame->link[i] = cpu_to_le32 ( link );
589  }
590  wmb();
591  DBGCP ( uhci, "\n" );
592 }
A queue head.
Definition: uhci.h:192
wmb()
struct uhci_frame_list * frame
Frame list.
Definition: uhci.h:319
struct uhci_queue_head * head
Asynchronous queue head.
Definition: uhci.h:317
A UHCI endpoint.
Definition: uhci.h:336
const char * name
Name.
Definition: uhci.h:311
uint32_t link[UHCI_FRAMES]
Link pointer.
Definition: uhci.h:95
struct list_head periodic
Periodic schedule.
Definition: uhci.h:329
struct uhci_queue_head * head
Queue head.
Definition: uhci.h:257
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
#define list_for_each_entry_reverse(pos, head, member)
Iterate over entries in a list in reverse order.
Definition: list.h:433
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define UHCI_FRAMES
Number of frames in frame list.
Definition: uhci.h:90
unsigned int uint32_t
Definition: stdint.h:12
#define ffs(x)
Find first (i.e.
Definition: strings.h:140
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
unsigned int interval
Interval (in microframes)
Definition: usb.h:401
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define DBGCP(...)
Definition: compiler.h:539
uint16_t queue
Queue ID.
Definition: ena.h:22
static uint32_t uhci_link_qh(struct uhci_queue_head *queue)
Get link value for a queue head.
Definition: uhci.c:458

References cpu_to_le32, DBGCP, end, uhci_endpoint::ep, ffs, uhci_device::frame, uhci_ring::head, uhci_device::head, usb_endpoint::interval, link, uhci_frame_list::link, list_for_each_entry, list_for_each_entry_reverse, uhci_device::name, uhci_device::periodic, queue, uhci_endpoint::ring, UHCI_FRAMES, uhci_link_qh(), and wmb().

Referenced by uhci_bus_open(), uhci_periodic_add(), and uhci_periodic_del().

◆ uhci_periodic_add()

static void uhci_periodic_add ( struct uhci_endpoint endpoint)
static

Add endpoint to periodic schedule.

Parameters
endpointEndpoint

Definition at line 599 of file uhci.c.

599  {
600  struct uhci_device *uhci = endpoint->uhci;
601  struct uhci_endpoint *before;
602  unsigned int interval = endpoint->ep->interval;
603 
604  /* Find first endpoint with a smaller interval */
605  list_for_each_entry ( before, &uhci->periodic, schedule ) {
606  if ( before->ep->interval < interval )
607  break;
608  }
609  list_add_tail ( &endpoint->schedule, &before->schedule );
610 
611  /* Rebuild schedule */
613 }
struct uhci_device * uhci
UHCI device.
Definition: uhci.h:338
A UHCI endpoint.
Definition: uhci.h:336
struct list_head periodic
Periodic schedule.
Definition: uhci.h:329
static void uhci_periodic_schedule(struct uhci_device *uhci)
(Re)build periodic schedule
Definition: uhci.c:531
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head schedule
Endpoint schedule.
Definition: uhci.h:344
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
A UHCI device.
Definition: uhci.h:307
unsigned int interval
Interval (in microframes)
Definition: usb.h:401

References uhci_endpoint::ep, usb_endpoint::interval, list_add_tail, list_for_each_entry, uhci_device::periodic, uhci_endpoint::schedule, uhci_endpoint::uhci, and uhci_periodic_schedule().

Referenced by uhci_schedule_add().

◆ uhci_periodic_del()

static void uhci_periodic_del ( struct uhci_endpoint endpoint)
static

Remove endpoint from periodic schedule.

Parameters
endpointEndpoint

Definition at line 620 of file uhci.c.

620  {
621  struct uhci_device *uhci = endpoint->uhci;
622 
623  /* Remove from schedule */
624  list_check_contains_entry ( endpoint, &uhci->periodic, schedule );
625  list_del ( &endpoint->schedule );
626 
627  /* Rebuild schedule */
628  uhci_periodic_schedule ( uhci );
629 
630  /* Delay for a whole USB frame (with a 100% safety margin) */
631  mdelay ( 2 );
632 }
struct uhci_device * uhci
UHCI device.
Definition: uhci.h:338
struct list_head periodic
Periodic schedule.
Definition: uhci.h:329
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void uhci_periodic_schedule(struct uhci_device *uhci)
(Re)build periodic schedule
Definition: uhci.c:531
struct list_head schedule
Endpoint schedule.
Definition: uhci.h:344
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
A UHCI device.
Definition: uhci.h:307
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition: list.h:522

References list_check_contains_entry, list_del, mdelay(), uhci_device::periodic, uhci_endpoint::schedule, uhci_endpoint::uhci, and uhci_periodic_schedule().

Referenced by uhci_schedule_del().

◆ uhci_schedule_add()

static void uhci_schedule_add ( struct uhci_endpoint endpoint)
static

Add endpoint to appropriate schedule.

Parameters
endpointEndpoint

Definition at line 639 of file uhci.c.

639  {
640  struct usb_endpoint *ep = endpoint->ep;
641  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
642 
644  uhci_periodic_add ( endpoint );
645  } else {
646  uhci_async_add ( endpoint );
647  }
648 }
static void uhci_async_add(struct uhci_endpoint *endpoint)
Add endpoint to asynchronous schedule.
Definition: uhci.c:497
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:266
uint8_t attr
Type and attributes.
Definition: librm.h:256
A USB endpoint.
Definition: usb.h:389
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:278
static void uhci_periodic_add(struct uhci_endpoint *endpoint)
Add endpoint to periodic schedule.
Definition: uhci.c:599
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
unsigned int attributes
Attributes.
Definition: usb.h:395

References attr, usb_endpoint::attributes, uhci_endpoint::ep, uhci_async_add(), uhci_periodic_add(), USB_ENDPOINT_ATTR_INTERRUPT, and USB_ENDPOINT_ATTR_TYPE_MASK.

Referenced by uhci_endpoint_open().

◆ uhci_schedule_del()

static void uhci_schedule_del ( struct uhci_endpoint endpoint)
static

Remove endpoint from appropriate schedule.

Parameters
endpointEndpoint

Definition at line 655 of file uhci.c.

655  {
656  struct usb_endpoint *ep = endpoint->ep;
657  unsigned int attr = ( ep->attributes & USB_ENDPOINT_ATTR_TYPE_MASK );
658 
660  uhci_periodic_del ( endpoint );
661  } else {
662  uhci_async_del ( endpoint );
663  }
664 }
static void uhci_periodic_del(struct uhci_endpoint *endpoint)
Remove endpoint from periodic schedule.
Definition: uhci.c:620
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:266
uint8_t attr
Type and attributes.
Definition: librm.h:256
static void uhci_async_del(struct uhci_endpoint *endpoint)
Remove endpoint from asynchronous schedule.
Definition: uhci.c:512
A USB endpoint.
Definition: usb.h:389
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:278
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
unsigned int attributes
Attributes.
Definition: usb.h:395

References attr, usb_endpoint::attributes, uhci_endpoint::ep, uhci_async_del(), uhci_periodic_del(), USB_ENDPOINT_ATTR_INTERRUPT, and USB_ENDPOINT_ATTR_TYPE_MASK.

Referenced by uhci_endpoint_close().

◆ uhci_endpoint_open()

static int uhci_endpoint_open ( struct usb_endpoint ep)
static

Open endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 679 of file uhci.c.

679  {
680  struct usb_device *usb = ep->usb;
681  struct uhci_device *uhci = usb_get_hostdata ( usb );
682  struct uhci_endpoint *endpoint;
683  int rc;
684 
685  /* Allocate and initialise structure */
686  endpoint = zalloc ( sizeof ( *endpoint ) );
687  if ( ! endpoint ) {
688  rc = -ENOMEM;
689  goto err_alloc;
690  }
691  endpoint->uhci = uhci;
692  endpoint->ep = ep;
693  usb_endpoint_set_hostdata ( ep, endpoint );
694 
695  /* Initialise descriptor ring */
696  if ( ( rc = uhci_ring_alloc ( &endpoint->ring ) ) != 0 )
697  goto err_ring_alloc;
698  endpoint->ring.mtu = ep->mtu;
699  endpoint->ring.flags = UHCI_FL_CERR_MAX;
700  if ( usb->speed < USB_SPEED_FULL )
701  endpoint->ring.flags |= UHCI_FL_LS;
702  endpoint->ring.control = ( UHCI_CONTROL_DEVICE ( usb->address ) |
704 
705  /* Add to list of endpoints */
706  list_add_tail ( &endpoint->list, &uhci->endpoints );
707 
708  /* Add to schedule */
709  uhci_schedule_add ( endpoint );
710 
711  return 0;
712 
713  uhci_ring_free ( &endpoint->ring );
714  err_ring_alloc:
715  free ( endpoint );
716  err_alloc:
717  return rc;
718 }
static void usb_endpoint_set_hostdata(struct usb_endpoint *ep, void *priv)
Set USB endpoint host controller private data.
Definition: usb.h:561
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define UHCI_FL_CERR_MAX
Error counter maximum value.
Definition: uhci.h:148
#define UHCI_CONTROL_ENDPOINT(address)
Endpoint address.
Definition: uhci.h:166
struct uhci_device * uhci
UHCI device.
Definition: uhci.h:338
A UHCI endpoint.
Definition: uhci.h:336
#define UHCI_CONTROL_DEVICE(address)
Device address.
Definition: uhci.h:163
unsigned int address
Device address, if assigned.
Definition: usb.h:716
unsigned int speed
Device speed.
Definition: usb.h:712
uint8_t flags
Base flags.
Definition: uhci.h:243
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
A USB device.
Definition: usb.h:706
struct list_head endpoints
List of all endpoints.
Definition: uhci.h:322
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
static int uhci_ring_alloc(struct uhci_ring *ring)
Allocate transfer ring.
Definition: uhci.c:175
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:778
#define UHCI_FL_LS
Low speed device.
Definition: uhci.h:151
size_t mtu
Maximum transfer size.
Definition: usb.h:397
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
uint32_t control
Base control word.
Definition: uhci.h:249
A UHCI device.
Definition: uhci.h:307
static void uhci_schedule_add(struct uhci_endpoint *endpoint)
Add endpoint to appropriate schedule.
Definition: uhci.c:639
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:728
struct list_head list
List of all endpoints.
Definition: uhci.h:342
struct usb_device * usb
USB device.
Definition: usb.h:391
static void uhci_ring_free(struct uhci_ring *ring)
Free transfer ring.
Definition: uhci.c:207
size_t mtu
Maximum packet length.
Definition: uhci.h:238
Full speed (12Mbps)
Definition: usb.h:50
unsigned int address
Endpoint address.
Definition: usb.h:393

References usb_endpoint::address, usb_device::address, uhci_ring::control, uhci_device::endpoints, ENOMEM, uhci_endpoint::ep, usb_device::ep, uhci_ring::flags, free, uhci_endpoint::list, list_add_tail, uhci_ring::mtu, usb_endpoint::mtu, rc, uhci_endpoint::ring, usb_device::speed, uhci_endpoint::uhci, UHCI_CONTROL_DEVICE, UHCI_CONTROL_ENDPOINT, UHCI_FL_CERR_MAX, UHCI_FL_LS, uhci_ring_alloc(), uhci_ring_free(), uhci_schedule_add(), usb_endpoint::usb, usb_endpoint_set_hostdata(), usb_get_hostdata(), USB_SPEED_FULL, and zalloc().

◆ uhci_endpoint_close()

static void uhci_endpoint_close ( struct usb_endpoint ep)
static

Close endpoint.

Parameters
epUSB endpoint

Definition at line 725 of file uhci.c.

725  {
726  struct uhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
727  struct io_buffer *iobuf;
728 
729  /* Remove from schedule */
730  uhci_schedule_del ( endpoint );
731 
732  /* Cancel any incomplete transfers */
733  while ( uhci_ring_fill ( &endpoint->ring ) ) {
734  iobuf = uhci_dequeue ( &endpoint->ring );
735  if ( iobuf )
736  usb_complete_err ( ep, iobuf, -ECANCELED );
737  }
738 
739  /* Remove from list of endpoints */
740  list_del ( &endpoint->list );
741 
742  /* Free descriptor ring */
743  uhci_ring_free ( &endpoint->ring );
744 
745  /* Free endpoint */
746  free ( endpoint );
747 }
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
Definition: uhci.h:267
A UHCI endpoint.
Definition: uhci.h:336
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void uhci_schedule_del(struct uhci_endpoint *endpoint)
Remove endpoint from appropriate schedule.
Definition: uhci.c:655
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
static struct io_buffer * uhci_dequeue(struct uhci_ring *ring)
Dequeue transfer.
Definition: uhci.c:360
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
struct list_head list
List of all endpoints.
Definition: uhci.h:342
static void uhci_ring_free(struct uhci_ring *ring)
Free transfer ring.
Definition: uhci.c:207
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:569
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572
A persistent I/O buffer.
Definition: iobuf.h:32

References ECANCELED, uhci_endpoint::ep, free, uhci_endpoint::list, list_del, uhci_endpoint::ring, uhci_dequeue(), uhci_ring_fill(), uhci_ring_free(), uhci_schedule_del(), usb_complete_err(), and usb_endpoint_get_hostdata().

◆ uhci_endpoint_reset()

static int uhci_endpoint_reset ( struct usb_endpoint ep)
static

Reset endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 755 of file uhci.c.

755  {
756  struct uhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
757  struct uhci_ring *ring = &endpoint->ring;
758 
759  /* Restart ring */
760  uhci_restart ( ring, 0 );
761 
762  return 0;
763 }
static void uhci_restart(struct uhci_ring *ring, uint32_t toggle)
Restart ring.
Definition: uhci.c:394
A UHCI endpoint.
Definition: uhci.h:336
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
A transfer ring.
Definition: uhci.h:231
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572

References uhci_endpoint::ep, uhci_endpoint::ring, uhci_restart(), and usb_endpoint_get_hostdata().

◆ uhci_endpoint_mtu()

static int uhci_endpoint_mtu ( struct usb_endpoint ep)
static

Update MTU.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 771 of file uhci.c.

771  {
772  struct uhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
773 
774  /* Update endpoint MTU */
775  endpoint->ring.mtu = ep->mtu;
776 
777  return 0;
778 }
A UHCI endpoint.
Definition: uhci.h:336
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
size_t mtu
Maximum transfer size.
Definition: usb.h:397
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
size_t mtu
Maximum packet length.
Definition: uhci.h:238
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572

References uhci_endpoint::ep, uhci_ring::mtu, usb_endpoint::mtu, uhci_endpoint::ring, and usb_endpoint_get_hostdata().

◆ uhci_endpoint_message()

static int uhci_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 787 of file uhci.c.

788  {
789  struct uhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
790  struct uhci_ring *ring = &endpoint->ring;
791  struct usb_setup_packet *packet;
792  unsigned int count;
793  size_t len;
794  int input;
795  int rc;
796 
797  /* Calculate number of descriptors */
798  assert ( iob_len ( iobuf ) >= sizeof ( *packet ) );
799  len = ( iob_len ( iobuf ) - sizeof ( *packet ) );
800  count = ( 1 /* setup stage */ +
801  ( ( len + ring->mtu - 1 ) / ring->mtu ) /* data stage */ +
802  1 /* status stage */ );
803 
804  /* Enqueue transfer */
805  if ( ( rc = uhci_enqueue ( ring, iobuf, count ) ) != 0 )
806  return rc;
807 
808  /* Describe setup stage */
809  packet = iobuf->data;
810  ring->control &= ~UHCI_CONTROL_TOGGLE;
811  uhci_describe ( ring, packet, sizeof ( *packet ), USB_PID_SETUP );
812  iob_pull ( iobuf, sizeof ( *packet ) );
813 
814  /* Describe data stage, if applicable */
815  assert ( ring->control & UHCI_CONTROL_TOGGLE );
816  input = ( packet->request & cpu_to_le16 ( USB_DIR_IN ) );
817  if ( len ) {
818  uhci_describe ( ring, iobuf->data, len,
819  ( input ? USB_PID_IN : USB_PID_OUT ) );
820  }
821 
822  /* Describe status stage */
823  ring->control |= UHCI_CONTROL_TOGGLE;
824  uhci_describe ( ring, NULL, 0,
825  ( ( len && input ) ? USB_PID_OUT : USB_PID_IN ) );
826 
827  /* Sanity check */
828  assert ( ring->end->prod == count );
829 
830  return 0;
831 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
unsigned int prod
Producer counter.
Definition: uhci.h:211
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
OUT PID.
Definition: usb.h:62
A UHCI endpoint.
Definition: uhci.h:336
Definition: bnxt_hsi.h:68
static int uhci_enqueue(struct uhci_ring *ring, struct io_buffer *iobuf, unsigned int count)
Enqueue new transfer.
Definition: uhci.c:227
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
A transfer ring.
Definition: uhci.h:231
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:83
#define UHCI_CONTROL_TOGGLE
Data toggle.
Definition: uhci.h:169
SETUP PID.
Definition: usb.h:64
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
A USB setup data packet.
Definition: usb.h:68
uint16_t request
Request.
Definition: usb.h:70
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
static void uhci_describe(struct uhci_ring *ring, void *data, size_t len, uint8_t pid)
Describe transfer.
Definition: uhci.c:319
uint32_t control
Base control word.
Definition: uhci.h:249
struct uhci_transfer * end
End of transfer ring (if non-empty)
Definition: uhci.h:254
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:44
uint16_t count
Number of entries.
Definition: ena.h:22
#define cpu_to_le16(value)
Definition: byteswap.h:106
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
size_t mtu
Maximum packet length.
Definition: uhci.h:238
IN PID.
Definition: usb.h:60
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572

References assert(), uhci_ring::control, count, cpu_to_le16, io_buffer::data, uhci_ring::end, uhci_endpoint::ep, iob_len(), iob_pull, len, uhci_ring::mtu, NULL, uhci_transfer::prod, rc, usb_setup_packet::request, uhci_endpoint::ring, UHCI_CONTROL_TOGGLE, uhci_describe(), uhci_enqueue(), USB_DIR_IN, usb_endpoint_get_hostdata(), USB_PID_IN, USB_PID_OUT, and USB_PID_SETUP.

◆ uhci_endpoint_stream()

static int uhci_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 841 of file uhci.c.

842  {
843  struct uhci_endpoint *endpoint = usb_endpoint_get_hostdata ( ep );
844  struct uhci_ring *ring = &endpoint->ring;
845  unsigned int count;
846  size_t len;
847  int input;
848  int rc;
849 
850  /* Calculate number of descriptors */
851  len = iob_len ( iobuf );
852  count = ( ( ( len + ring->mtu - 1 ) / ring->mtu ) + ( zlp ? 1 : 0 ) );
853 
854  /* Enqueue transfer */
855  if ( ( rc = uhci_enqueue ( ring, iobuf, count ) ) != 0 )
856  return rc;
857 
858  /* Describe data packet */
859  input = ( ep->address & USB_DIR_IN );
860  uhci_describe ( ring, iobuf->data, len,
861  ( input ? USB_PID_IN : USB_PID_OUT ) );
862 
863  /* Describe zero-length packet, if applicable */
864  if ( zlp )
865  uhci_describe ( ring, NULL, 0, USB_PID_OUT );
866 
867  /* Sanity check */
868  assert ( ring->end->prod == count );
869 
870  return 0;
871 }
unsigned int prod
Producer counter.
Definition: uhci.h:211
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
OUT PID.
Definition: usb.h:62
A UHCI endpoint.
Definition: uhci.h:336
Definition: bnxt_hsi.h:68
static int uhci_enqueue(struct uhci_ring *ring, struct io_buffer *iobuf, unsigned int count)
Enqueue new transfer.
Definition: uhci.c:227
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
A transfer ring.
Definition: uhci.h:231
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:83
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
static void uhci_describe(struct uhci_ring *ring, void *data, size_t len, uint8_t pid)
Describe transfer.
Definition: uhci.c:319
struct uhci_transfer * end
End of transfer ring (if non-empty)
Definition: uhci.h:254
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:44
uint16_t count
Number of entries.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
size_t mtu
Maximum packet length.
Definition: uhci.h:238
unsigned int address
Endpoint address.
Definition: usb.h:393
IN PID.
Definition: usb.h:60
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572

References usb_endpoint::address, assert(), count, io_buffer::data, uhci_ring::end, uhci_endpoint::ep, iob_len(), len, uhci_ring::mtu, NULL, uhci_transfer::prod, rc, uhci_endpoint::ring, uhci_describe(), uhci_enqueue(), USB_DIR_IN, usb_endpoint_get_hostdata(), USB_PID_IN, and USB_PID_OUT.

◆ uhci_is_message()

static int uhci_is_message ( struct uhci_transfer xfer)
inlinestatic

Check if transfer is a message transfer.

Parameters
xferUHCI transfer
Return values
is_messageTransfer is a message transfer

Definition at line 879 of file uhci.c.

879  {
880  struct uhci_transfer_descriptor *desc = &xfer->desc[0];
881 
882  return ( ( desc->control & cpu_to_le32 ( UHCI_CONTROL_PID_MASK ) ) ==
884 }
uint32_t control
Control.
Definition: uhci.h:109
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define UHCI_CONTROL_PID_MASK
Packet ID mask.
Definition: uhci.h:160
SETUP PID.
Definition: usb.h:64
A transfer descriptor.
Definition: uhci.h:99
#define UHCI_CONTROL_PID(pid)
Packet ID.
Definition: uhci.h:157
struct uhci_transfer_descriptor * desc
Transfer descriptors.
Definition: uhci.h:218

References uhci_transfer_descriptor::control, cpu_to_le32, uhci_transfer::desc, UHCI_CONTROL_PID, UHCI_CONTROL_PID_MASK, and USB_PID_SETUP.

Referenced by uhci_endpoint_poll().

◆ uhci_endpoint_poll()

static void uhci_endpoint_poll ( struct uhci_endpoint endpoint)
static

Poll for completions.

Parameters
endpointEndpoint

Definition at line 891 of file uhci.c.

891  {
892  struct uhci_ring *ring = &endpoint->ring;
893  struct uhci_device *uhci = endpoint->uhci;
894  struct usb_endpoint *ep = endpoint->ep;
895  struct usb_device *usb = ep->usb;
896  struct uhci_transfer *xfer;
897  struct uhci_transfer_descriptor *desc;
898  struct io_buffer *iobuf;
899  unsigned int index;
900  uint32_t link;
901  uint32_t toggle;
903  uint16_t actual;
904  size_t len;
905 
906  /* Consume all completed descriptors */
907  while ( uhci_ring_fill ( ring ) ) {
908 
909  /* Stop if we reach an uncompleted descriptor */
910  index = ( ring->cons % UHCI_RING_COUNT );
911  xfer = ring->xfer[index];
912  assert ( xfer != NULL );
913  assert ( xfer->cons < xfer->prod );
914  desc = &xfer->desc[xfer->cons];
915  rmb();
916  if ( desc->status & UHCI_STATUS_ACTIVE )
917  break;
918  control = le32_to_cpu ( desc->control );
919  actual = le16_to_cpu ( desc->actual );
920 
921  /* Update data length, if applicable */
922  if ( UHCI_DATA_PACKET ( control ) )
923  xfer->len += UHCI_ACTUAL_LEN ( actual );
924 
925  /* If we have encountered an error, then deactivate
926  * the queue head (to prevent further hardware
927  * accesses to this transfer), consume the transfer,
928  * and report the error to the USB core.
929  */
930  if ( desc->status & UHCI_STATUS_STALLED ) {
931  DBGC ( uhci, "UHCI %s %s completion %d.%d failed "
932  "(status %02x)\n", usb->name,
933  usb_endpoint_name ( ep ), index,
934  xfer->cons, desc->status );
936  ring->head->current = cpu_to_le32 ( link );
937  wmb();
938  iobuf = uhci_dequeue ( ring );
939  usb_complete_err ( ep, iobuf, -EIO );
940  break;
941  }
942 
943  /* Consume this descriptor */
944  xfer->cons++;
945 
946  /* Check for short packets */
947  if ( UHCI_SHORT_PACKET ( control, actual ) ) {
948 
949  /* Sanity checks */
950  assert ( desc->flags & UHCI_FL_SPD );
951  link = virt_to_phys ( desc );
952  assert ( ( le32_to_cpu ( ring->head->current ) &
953  ~( UHCI_ALIGN - 1 ) ) == link );
954 
955  /* If this is a message transfer, then restart
956  * at the status stage.
957  */
958  if ( uhci_is_message ( xfer ) ) {
959  xfer->cons = ( xfer->prod - 1 );
960  link = virt_to_phys ( &xfer->desc[xfer->cons] );
961  ring->head->current = cpu_to_le32 ( link );
962  break;
963  }
964 
965  /* Otherwise, this is a stream transfer.
966  * First, prevent further hardware access to
967  * this transfer.
968  */
970  ring->head->current = cpu_to_le32 ( link );
971  wmb();
972 
973  /* Determine expected data toggle for next descriptor */
974  toggle = ( ( control ^ UHCI_CONTROL_TOGGLE ) &
976 
977  /* Consume this transfer */
978  len = xfer->len;
979  iobuf = uhci_dequeue ( ring );
980 
981  /* Update packet length */
982  assert ( len <= iob_len ( iobuf ) );
983  iob_unput ( iobuf, ( iob_len ( iobuf ) - len ) );
984 
985  /* Restart ring */
986  uhci_restart ( ring, toggle );
987 
988  } else if ( xfer->cons == xfer->prod ) {
989 
990  /* Completed a transfer: consume it */
991  len = xfer->len;
992  iobuf = uhci_dequeue ( ring );
993  assert ( len == iob_len ( iobuf ) );
994 
995  } else {
996 
997  /* Not a short packet and not yet complete:
998  * continue processing.
999  */
1000  continue;
1001  }
1002 
1003  /* Report completion to USB core */
1004  usb_complete ( ep, iobuf );
1005  }
1006 }
unsigned int cons
Consumer counter.
Definition: uhci.h:235
unsigned int prod
Producer counter.
Definition: uhci.h:211
unsigned short uint16_t
Definition: stdint.h:11
wmb()
static void uhci_restart(struct uhci_ring *ring, uint32_t toggle)
Restart ring.
Definition: uhci.c:394
#define le32_to_cpu(value)
Definition: byteswap.h:113
#define UHCI_STATUS_ACTIVE
Active.
Definition: uhci.h:121
static unsigned int uhci_ring_fill(struct uhci_ring *ring)
Calculate space used in transfer ring.
Definition: uhci.h:267
#define UHCI_RING_COUNT
Number of transfer descriptors in a ring.
Definition: uhci.h:228
struct uhci_device * uhci
UHCI device.
Definition: uhci.h:338
#define DBGC(...)
Definition: compiler.h:505
uint32_t control
Control.
Definition: uhci.h:109
uint8_t flags
Flags.
Definition: uhci.h:107
uint32_t current
Current transfer descriptor.
Definition: uhci.h:196
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
A single UHCI transfer.
Definition: uhci.h:209
#define rmb()
Definition: io.h:484
A USB endpoint.
Definition: usb.h:389
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct uhci_queue_head * head
Queue head.
Definition: uhci.h:257
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
static struct io_buffer * uhci_dequeue(struct uhci_ring *ring)
Dequeue transfer.
Definition: uhci.c:360
uint16_t actual
Actual length.
Definition: uhci.h:103
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
A transfer ring.
Definition: uhci.h:231
#define UHCI_STATUS_STALLED
Stalled.
Definition: uhci.h:124
char name[32]
Name.
Definition: usb.h:708
#define cpu_to_le32(value)
Definition: byteswap.h:107
A USB device.
Definition: usb.h:706
#define UHCI_CONTROL_TOGGLE
Data toggle.
Definition: uhci.h:169
#define iob_unput(iobuf, len)
Definition: iobuf.h:131
static int uhci_is_message(struct uhci_transfer *xfer)
Check if transfer is a message transfer.
Definition: uhci.c:879
uint8_t status
Status.
Definition: uhci.h:105
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
size_t len
Completed data length.
Definition: uhci.h:215
uint32_t control
Control.
Definition: myson.h:14
struct uhci_transfer * xfer[UHCI_RING_COUNT]
Transfers.
Definition: uhci.h:252
#define UHCI_LINK_TERMINATE
List terminator.
Definition: uhci.h:87
#define le16_to_cpu(value)
Definition: byteswap.h:112
unsigned int uint32_t
Definition: stdint.h:12
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
struct usb_endpoint * ep
USB endpoint.
Definition: uhci.h:340
#define UHCI_DATA_PACKET(control)
Check for data packet.
Definition: uhci.h:179
uint32_t len
Length.
Definition: ena.h:14
#define UHCI_SHORT_PACKET(control, actual)
Check for short packet.
Definition: uhci.h:182
A UHCI device.
Definition: uhci.h:307
static void usb_complete(struct usb_endpoint *ep, struct io_buffer *iobuf)
Complete transfer (without error)
Definition: usb.h:1064
#define EIO
Input/output error.
Definition: errno.h:433
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:728
A transfer descriptor.
Definition: uhci.h:99
struct usb_device * usb
USB device.
Definition: usb.h:391
unsigned int cons
Consumer counter.
Definition: uhci.h:213
struct uhci_transfer_descriptor * desc
Transfer descriptors.
Definition: uhci.h:218
#define UHCI_ALIGN
Minimum alignment required for data structures.
Definition: uhci.h:21
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define UHCI_FL_SPD
Short packet detect.
Definition: uhci.h:142
#define UHCI_ACTUAL_LEN(actual)
Actual length.
Definition: uhci.h:118
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:569
A persistent I/O buffer.
Definition: iobuf.h:32

References uhci_transfer_descriptor::actual, assert(), uhci_transfer::cons, uhci_ring::cons, control, uhci_transfer_descriptor::control, cpu_to_le32, uhci_queue_head::current, DBGC, uhci_transfer::desc, EIO, uhci_endpoint::ep, usb_device::ep, uhci_transfer_descriptor::flags, uhci_ring::head, index, iob_len(), iob_unput, le16_to_cpu, le32_to_cpu, len, uhci_transfer::len, link, usb_device::name, NULL, uhci_transfer::prod, uhci_endpoint::ring, rmb, uhci_transfer_descriptor::status, uhci_endpoint::uhci, UHCI_ACTUAL_LEN, UHCI_ALIGN, UHCI_CONTROL_TOGGLE, UHCI_DATA_PACKET, uhci_dequeue(), UHCI_FL_SPD, uhci_is_message(), UHCI_LINK_TERMINATE, uhci_restart(), UHCI_RING_COUNT, uhci_ring_fill(), UHCI_SHORT_PACKET, UHCI_STATUS_ACTIVE, UHCI_STATUS_STALLED, usb_endpoint::usb, usb_complete(), usb_complete_err(), usb_endpoint_name(), virt_to_phys(), wmb(), and uhci_ring::xfer.

Referenced by uhci_bus_poll().

◆ uhci_device_open()

static int uhci_device_open ( struct usb_device usb)
static

Open device.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 1021 of file uhci.c.

1021  {
1022  struct uhci_device *uhci = usb_bus_get_hostdata ( usb->port->hub->bus );
1023 
1024  usb_set_hostdata ( usb, uhci );
1025  return 0;
1026 }
static void usb_set_hostdata(struct usb_device *usb, void *priv)
Set USB device host controller private data.
Definition: usb.h:767
struct usb_port * port
USB port.
Definition: usb.h:710
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1039
A UHCI device.
Definition: uhci.h:307
struct usb_hub * hub
USB hub.
Definition: usb.h:798
struct usb_bus * bus
USB bus.
Definition: usb.h:828

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

◆ uhci_device_close()

static void uhci_device_close ( struct usb_device usb)
static

Close device.

Parameters
usbUSB device

Definition at line 1033 of file uhci.c.

1033  {
1034  struct uhci_device *uhci = usb_get_hostdata ( usb );
1035  struct usb_bus *bus = uhci->bus;
1036 
1037  /* Free device address, if assigned */
1038  if ( usb->address )
1039  usb_free_address ( bus, usb->address );
1040 }
unsigned int address
Device address, if assigned.
Definition: usb.h:716
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
Definition: usb.c:2200
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:778
A UHCI device.
Definition: uhci.h:307
A USB bus.
Definition: usb.h:949
uint8_t bus
Bus.
Definition: edd.h:14
struct usb_bus * bus
USB bus.
Definition: uhci.h:332

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

◆ uhci_device_address()

static int uhci_device_address ( struct usb_device usb)
static

Assign device address.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 1048 of file uhci.c.

1048  {
1049  struct uhci_device *uhci = usb_get_hostdata ( usb );
1050  struct usb_bus *bus = uhci->bus;
1051  struct usb_endpoint *ep0 = usb_endpoint ( usb, USB_EP0_ADDRESS );
1052  struct uhci_endpoint *endpoint0 = usb_endpoint_get_hostdata ( ep0 );
1053  int address;
1054  int rc;
1055 
1056  /* Sanity checks */
1057  assert ( usb->address == 0 );
1058  assert ( ep0 != NULL );
1059 
1060  /* Allocate device address */
1062  if ( address < 0 ) {
1063  rc = address;
1064  DBGC ( uhci, "UHCI %s could not allocate address: %s\n",
1065  usb->name, strerror ( rc ) );
1066  goto err_alloc_address;
1067  }
1068 
1069  /* Set address */
1070  if ( ( rc = usb_set_address ( usb, address ) ) != 0 )
1071  goto err_set_address;
1072 
1073  /* Update device address */
1074  usb->address = address;
1075  endpoint0->ring.control |= UHCI_CONTROL_DEVICE ( address );
1076 
1077  return 0;
1078 
1079  err_set_address:
1081  err_alloc_address:
1082  return rc;
1083 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct uhci_device * uhci
UHCI device.
Definition: uhci.h:338
uint64_t address
Base address.
Definition: ena.h:24
A UHCI endpoint.
Definition: uhci.h:336
#define DBGC(...)
Definition: compiler.h:505
#define UHCI_CONTROL_DEVICE(address)
Device address.
Definition: uhci.h:163
unsigned int address
Device address, if assigned.
Definition: usb.h:716
static int usb_set_address(struct usb_device *usb, unsigned int address)
Set address.
Definition: usb.h:1136
A USB endpoint.
Definition: usb.h:389
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct uhci_ring ring
Transfer ring.
Definition: uhci.h:347
char name[32]
Name.
Definition: usb.h:708
static struct usb_endpoint * usb_endpoint(struct usb_device *usb, unsigned int address)
Get USB endpoint.
Definition: usb.h:789
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void usb_free_address(struct usb_bus *bus, unsigned int address)
Free device address.
Definition: usb.c:2200
static void * usb_get_hostdata(struct usb_device *usb)
Get USB device host controller private data.
Definition: usb.h:778
uint32_t control
Base control word.
Definition: uhci.h:249
A UHCI device.
Definition: uhci.h:307
struct usb_device * usb
USB device.
Definition: usb.h:391
#define USB_EP0_ADDRESS
Control endpoint address.
Definition: usb.h:486
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
int usb_alloc_address(struct usb_bus *bus)
Allocate device address.
Definition: usb.c:2180
A USB bus.
Definition: usb.h:949
uint8_t bus
Bus.
Definition: edd.h:14
static void * usb_endpoint_get_hostdata(struct usb_endpoint *ep)
Get USB endpoint host controller private data.
Definition: usb.h:572
struct usb_bus * bus
USB bus.
Definition: uhci.h:332

References address, usb_device::address, assert(), bus, uhci_device::bus, uhci_ring::control, DBGC, usb_device::name, NULL, rc, uhci_endpoint::ring, strerror(), uhci_endpoint::uhci, UHCI_CONTROL_DEVICE, usb_endpoint::usb, usb_alloc_address(), usb_endpoint(), usb_endpoint_get_hostdata(), USB_EP0_ADDRESS, usb_free_address(), usb_get_hostdata(), and usb_set_address().

◆ uhci_hub_open()

static int uhci_hub_open ( struct usb_hub *hub  __unused)
static

Open hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 1098 of file uhci.c.

1098  {
1099 
1100  /* Nothing to do */
1101  return 0;
1102 }

◆ uhci_hub_close()

static void uhci_hub_close ( struct usb_hub *hub  __unused)
static

Close hub.

Parameters
hubUSB hub

Definition at line 1109 of file uhci.c.

1109  {
1110 
1111  /* Nothing to do */
1112 }

◆ uhci_root_open()

static int uhci_root_open ( struct usb_hub *hub  __unused)
static

Open root hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 1127 of file uhci.c.

1127  {
1128 
1129  /* Nothing to do */
1130  return 0;
1131 }

◆ uhci_root_close()

static void uhci_root_close ( struct usb_hub *hub  __unused)
static

Close root hub.

Parameters
hubUSB hub

Definition at line 1138 of file uhci.c.

1138  {
1139 
1140  /* Nothing to do */
1141 }

◆ uhci_root_enable()

static int uhci_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 1150 of file uhci.c.

1150  {
1151  struct uhci_device *uhci = usb_hub_get_drvdata ( hub );
1152  uint16_t portsc;
1153  unsigned int i;
1154 
1155  /* Reset port */
1156  portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
1157  portsc |= UHCI_PORTSC_PR;
1158  outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
1160  portsc &= ~UHCI_PORTSC_PR;
1161  outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
1163 
1164  /* Enable port */
1165  portsc |= UHCI_PORTSC_PED;
1166  outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
1168 
1169  /* Wait for port to become enabled */
1170  for ( i = 0 ; i < UHCI_PORT_ENABLE_MAX_WAIT_MS ; i++ ) {
1171 
1172  /* Check port status */
1173  portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
1174  if ( portsc & UHCI_PORTSC_PED )
1175  return 0;
1176 
1177  /* Delay */
1178  mdelay ( 1 );
1179  }
1180 
1181  DBGC ( uhci, "UHCI %s-%d timed out waiting for port to enable "
1182  "(status %04x)\n", uhci->name, port->address, portsc );
1183  return -ETIMEDOUT;
1184 }
#define UHCI_PORTSC_PED
Port enabled.
Definition: uhci.h:69
unsigned short uint16_t
Definition: stdint.h:11
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
#define outw(data, io_addr)
Definition: io.h:319
#define USB_RESET_RECOVER_DELAY_MS
Reset recovery time.
Definition: usb.h:1291
#define UHCI_PORTSC(port)
Port status and control register.
Definition: uhci.h:57
#define DBGC(...)
Definition: compiler.h:505
#define USB_RESET_DELAY_MS
Minimum reset time.
Definition: usb.h:1284
const char * name
Name.
Definition: uhci.h:311
#define UHCI_PORTSC_PR
Port reset.
Definition: uhci.h:60
#define UHCI_PORT_ENABLE_MAX_WAIT_MS
Maximum time to wait for a port to be enabled.
Definition: uhci.h:304
u8 port
Port number.
Definition: CIB_PRM.h:31
unsigned long regs
Registers.
Definition: uhci.h:309
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
A UHCI device.
Definition: uhci.h:307
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:931

References DBGC, ETIMEDOUT, inw(), mdelay(), uhci_device::name, outw, port, uhci_device::regs, UHCI_PORT_ENABLE_MAX_WAIT_MS, UHCI_PORTSC, UHCI_PORTSC_PED, UHCI_PORTSC_PR, usb_hub_get_drvdata(), USB_RESET_DELAY_MS, and USB_RESET_RECOVER_DELAY_MS.

◆ uhci_root_disable()

static int uhci_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 1193 of file uhci.c.

1193  {
1194  struct uhci_device *uhci = usb_hub_get_drvdata ( hub );
1195  uint16_t portsc;
1196 
1197  /* Disable port */
1198  portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
1199  portsc &= ~UHCI_PORTSC_PED;
1200  outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
1201 
1202  return 0;
1203 }
#define UHCI_PORTSC_PED
Port enabled.
Definition: uhci.h:69
unsigned short uint16_t
Definition: stdint.h:11
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
#define outw(data, io_addr)
Definition: io.h:319
#define UHCI_PORTSC(port)
Port status and control register.
Definition: uhci.h:57
u8 port
Port number.
Definition: CIB_PRM.h:31
unsigned long regs
Registers.
Definition: uhci.h:309
A UHCI device.
Definition: uhci.h:307
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:931

References inw(), outw, port, uhci_device::regs, UHCI_PORTSC, UHCI_PORTSC_PED, and usb_hub_get_drvdata().

◆ uhci_root_speed()

static int uhci_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 1212 of file uhci.c.

1212  {
1213  struct uhci_device *uhci = usb_hub_get_drvdata ( hub );
1214  struct pci_device pci;
1215  uint16_t portsc;
1216  unsigned int speed;
1217 
1218  /* Read port status */
1219  portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
1220  if ( ! ( portsc & UHCI_PORTSC_CCS ) ) {
1221  /* Port not connected */
1222  speed = USB_SPEED_NONE;
1223  } else if ( uhci->companion &&
1225  uhci->companion ) ) {
1226  /* Defer connection detection until companion
1227  * controller has been enumerated.
1228  */
1229  pci_init ( &pci, uhci->companion );
1230  DBGC ( uhci, "UHCI %s-%d deferring for companion " PCI_FMT "\n",
1231  uhci->name, port->address, PCI_ARGS ( &pci ) );
1232  speed = USB_SPEED_NONE;
1233  } else if ( portsc & UHCI_PORTSC_LS ) {
1234  /* Low-speed device */
1235  speed = USB_SPEED_LOW;
1236  } else {
1237  /* Full-speed device */
1238  speed = USB_SPEED_FULL;
1239  }
1240  port->speed = speed;
1241 
1242  /* Record disconnections and clear changes */
1243  port->disconnected |= ( portsc & UHCI_PORTSC_CSC );
1244  outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
1245 
1246  return 0;
1247 }
unsigned short uint16_t
Definition: stdint.h:11
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
struct usb_bus * find_usb_bus_by_location(unsigned int bus_type, unsigned int location)
Find USB bus by device location.
Definition: usb.c:2154
#define outw(data, io_addr)
Definition: io.h:319
Low speed (1.5Mbps)
Definition: usb.h:48
#define UHCI_PORTSC(port)
Port status and control register.
Definition: uhci.h:57
#define DBGC(...)
Definition: compiler.h:505
#define UHCI_PORTSC_CSC
Connect status change.
Definition: uhci.h:72
const char * name
Name.
Definition: uhci.h:311
#define UHCI_PORTSC_CCS
Current connect status.
Definition: uhci.h:75
u8 port
Port number.
Definition: CIB_PRM.h:31
#define BUS_TYPE_PCI
PCI bus type.
Definition: device.h:43
Not connected.
Definition: usb.h:46
#define UHCI_PORTSC_LS
Low-speed device attached.
Definition: uhci.h:63
unsigned int companion
EHCI companion controller bus:dev.fn address (if any)
Definition: uhci.h:314
unsigned long regs
Registers.
Definition: uhci.h:309
#define PCI_FMT
PCI device debug message format.
Definition: pci.h:287
A PCI device.
Definition: pci.h:187
A UHCI device.
Definition: uhci.h:307
#define PCI_ARGS(pci)
PCI device debug message arguments.
Definition: pci.h:290
static void pci_init(struct pci_device *pci, unsigned int busdevfn)
Initialise PCI device.
Definition: pci.h:313
Full speed (12Mbps)
Definition: usb.h:50
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:931

References BUS_TYPE_PCI, uhci_device::companion, DBGC, find_usb_bus_by_location(), inw(), uhci_device::name, outw, PCI_ARGS, PCI_FMT, pci_init(), port, uhci_device::regs, UHCI_PORTSC, UHCI_PORTSC_CCS, UHCI_PORTSC_CSC, UHCI_PORTSC_LS, usb_hub_get_drvdata(), USB_SPEED_FULL, USB_SPEED_LOW, and USB_SPEED_NONE.

◆ uhci_root_clear_tt()

static int uhci_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 1257 of file uhci.c.

1258  {
1259  struct uhci_device *uhci = usb_hub_get_drvdata ( hub );
1260 
1261  /* Should never be called; this is a root hub */
1262  DBGC ( uhci, "UHCI %s-%d nonsensical CLEAR_TT for %s %s\n", uhci->name,
1263  port->address, ep->usb->name, usb_endpoint_name ( ep ) );
1264 
1265  return -ENOTSUP;
1266 }
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: uhci.h:311
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
u8 port
Port number.
Definition: CIB_PRM.h:31
char name[32]
Name.
Definition: usb.h:708
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
A UHCI device.
Definition: uhci.h:307
struct usb_device * usb
USB device.
Definition: usb.h:391
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:931

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

◆ uhci_root_poll()

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

Poll for port status changes.

Parameters
hubUSB hub
portUSB port

Definition at line 1274 of file uhci.c.

1274  {
1275  struct uhci_device *uhci = usb_hub_get_drvdata ( hub );
1276  uint16_t portsc;
1277  uint16_t change;
1278 
1279  /* Do nothing unless something has changed */
1280  portsc = inw ( uhci->regs + UHCI_PORTSC ( port->address ) );
1281  change = ( portsc & UHCI_PORTSC_CHANGE );
1282  if ( ! change )
1283  return;
1284 
1285  /* Record disconnections and clear changes */
1286  port->disconnected |= ( portsc & UHCI_PORTSC_CSC );
1287  outw ( portsc, uhci->regs + UHCI_PORTSC ( port->address ) );
1288 
1289  /* Report port status change */
1290  usb_port_changed ( port );
1291 }
unsigned short uint16_t
Definition: stdint.h:11
uint16_t inw(volatile uint16_t *io_addr)
Read 16-bit word from I/O-mapped device.
#define outw(data, io_addr)
Definition: io.h:319
#define UHCI_PORTSC(port)
Port status and control register.
Definition: uhci.h:57
#define UHCI_PORTSC_CSC
Connect status change.
Definition: uhci.h:72
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition: usb.c:1796
u8 port
Port number.
Definition: CIB_PRM.h:31
unsigned long regs
Registers.
Definition: uhci.h:309
#define UHCI_PORTSC_CHANGE
Port status change mask.
Definition: uhci.h:78
A UHCI device.
Definition: uhci.h:307
static void * usb_hub_get_drvdata(struct usb_hub *hub)
Get USB hub driver private data.
Definition: usb.h:931

References inw(), outw, port, uhci_device::regs, UHCI_PORTSC, UHCI_PORTSC_CHANGE, UHCI_PORTSC_CSC, usb_hub_get_drvdata(), and usb_port_changed().

Referenced by uhci_bus_poll().

◆ uhci_bus_open()

static int uhci_bus_open ( struct usb_bus bus)
static

Open USB bus.

Parameters
busUSB bus
Return values
rcReturn status code

Definition at line 1306 of file uhci.c.

1306  {
1307  struct uhci_device *uhci = usb_bus_get_hostdata ( bus );
1308  int rc;
1309 
1310  /* Sanity checks */
1311  assert ( list_empty ( &uhci->async ) );
1312  assert ( list_empty ( &uhci->periodic ) );
1313 
1314  /* Allocate and initialise asynchronous queue head */
1315  uhci->head = malloc_dma ( sizeof ( *uhci->head ), UHCI_ALIGN );
1316  if ( ! uhci->head ) {
1317  rc = -ENOMEM;
1318  goto err_alloc_head;
1319  }
1320  if ( ( rc = uhci_reachable ( uhci->head, sizeof ( *uhci->head ) ) ) !=0)
1321  goto err_unreachable_head;
1322  memset ( uhci->head, 0, sizeof ( *uhci->head ) );
1324  uhci_async_schedule ( uhci );
1325 
1326  /* Allocate periodic frame list */
1327  uhci->frame = malloc_dma ( sizeof ( *uhci->frame ),
1328  sizeof ( *uhci->frame ) );
1329  if ( ! uhci->frame ) {
1330  rc = -ENOMEM;
1331  goto err_alloc_frame;
1332  }
1333  if ( ( rc = uhci_reachable ( uhci->frame,
1334  sizeof ( *uhci->frame ) ) ) != 0 )
1335  goto err_unreachable_frame;
1336  uhci_periodic_schedule ( uhci );
1337  outl ( virt_to_phys ( uhci->frame ), uhci->regs + UHCI_FLBASEADD );
1338 
1339  /* Start controller */
1340  uhci_run ( uhci );
1341 
1342  return 0;
1343 
1344  uhci_stop ( uhci );
1345  err_unreachable_frame:
1346  free_dma ( uhci->frame, sizeof ( *uhci->frame ) );
1347  err_alloc_frame:
1348  err_unreachable_head:
1349  free_dma ( uhci->head, sizeof ( *uhci->head ) );
1350  err_alloc_head:
1351  return rc;
1352 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void uhci_run(struct uhci_device *uhci)
Start UHCI device.
Definition: uhci.c:83
struct uhci_frame_list * frame
Frame list.
Definition: uhci.h:319
struct uhci_queue_head * head
Asynchronous queue head.
Definition: uhci.h:317
struct list_head async
Asynchronous schedule.
Definition: uhci.h:324
uint32_t current
Current transfer descriptor.
Definition: uhci.h:196
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
struct list_head periodic
Periodic schedule.
Definition: uhci.h:329
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void uhci_periodic_schedule(struct uhci_device *uhci)
(Re)build periodic schedule
Definition: uhci.c:531
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void uhci_async_schedule(struct uhci_device *uhci)
(Re)build asynchronous schedule
Definition: uhci.c:468
unsigned long regs
Registers.
Definition: uhci.h:309
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define outl(data, io_addr)
Definition: io.h:329
#define UHCI_LINK_TERMINATE
List terminator.
Definition: uhci.h:87
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1039
A UHCI device.
Definition: uhci.h:307
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
static int uhci_reachable(void *addr, size_t len)
Check that address is reachable.
Definition: uhci.c:57
#define UHCI_ALIGN
Minimum alignment required for data structures.
Definition: uhci.h:21
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
uint8_t bus
Bus.
Definition: edd.h:14
static int uhci_stop(struct uhci_device *uhci)
Stop UHCI device.
Definition: uhci.c:98
#define UHCI_FLBASEADD
Frame list base address register.
Definition: uhci.h:54
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), uhci_device::async, bus, cpu_to_le32, uhci_queue_head::current, ENOMEM, uhci_device::frame, free_dma(), uhci_device::head, list_empty, malloc_dma(), memset(), outl, uhci_device::periodic, rc, uhci_device::regs, UHCI_ALIGN, uhci_async_schedule(), UHCI_FLBASEADD, UHCI_LINK_TERMINATE, uhci_periodic_schedule(), uhci_reachable(), uhci_run(), uhci_stop(), usb_bus_get_hostdata(), and virt_to_phys().

◆ uhci_bus_close()

static void uhci_bus_close ( struct usb_bus bus)
static

Close USB bus.

Parameters
busUSB bus

Definition at line 1359 of file uhci.c.

1359  {
1360  struct uhci_device *uhci = usb_bus_get_hostdata ( bus );
1361 
1362  /* Sanity checks */
1363  assert ( list_empty ( &uhci->async ) );
1364  assert ( list_empty ( &uhci->periodic ) );
1365 
1366  /* Stop controller */
1367  uhci_stop ( uhci );
1368 
1369  /* Free periodic frame list */
1370  free_dma ( uhci->frame, sizeof ( *uhci->frame ) );
1371 
1372  /* Free asynchronous schedule */
1373  free_dma ( uhci->head, sizeof ( *uhci->head ) );
1374 }
struct uhci_frame_list * frame
Frame list.
Definition: uhci.h:319
struct uhci_queue_head * head
Asynchronous queue head.
Definition: uhci.h:317
struct list_head async
Asynchronous schedule.
Definition: uhci.h:324
struct list_head periodic
Periodic schedule.
Definition: uhci.h:329
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1039
A UHCI device.
Definition: uhci.h:307
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
uint8_t bus
Bus.
Definition: edd.h:14
static int uhci_stop(struct uhci_device *uhci)
Stop UHCI device.
Definition: uhci.c:98

References assert(), uhci_device::async, bus, uhci_device::frame, free_dma(), uhci_device::head, list_empty, uhci_device::periodic, uhci_stop(), and usb_bus_get_hostdata().

◆ uhci_bus_poll()

static void uhci_bus_poll ( struct usb_bus bus)
static

Poll USB bus.

Parameters
busUSB bus

Definition at line 1381 of file uhci.c.

1381  {
1382  struct uhci_device *uhci = usb_bus_get_hostdata ( bus );
1383  struct usb_hub *hub = bus->hub;
1384  struct uhci_endpoint *endpoint;
1385  unsigned int i;
1386 
1387  /* UHCI defers interrupts (including short packet detection)
1388  * until the end of the frame. This can result in bulk IN
1389  * endpoints remaining halted for much of the time, waiting
1390  * for software action to reset the data toggles. We
1391  * therefore ignore USBSTS and unconditionally poll all
1392  * endpoints for completed transfer descriptors.
1393  *
1394  * As with EHCI, we trust that completion handlers are minimal
1395  * and will not do anything that could plausibly affect the
1396  * endpoint list itself.
1397  */
1398  list_for_each_entry ( endpoint, &uhci->endpoints, list )
1399  uhci_endpoint_poll ( endpoint );
1400 
1401  /* UHCI provides no single bit to indicate that a port status
1402  * change has occurred. We therefore unconditionally iterate
1403  * over all ports looking for status changes.
1404  */
1405  for ( i = 1 ; i <= UHCI_PORTS ; i++ )
1406  uhci_root_poll ( hub, usb_port ( hub, i ) );
1407 }
A USB hub.
Definition: usb.h:824
struct uhci_device * uhci
UHCI device.
Definition: uhci.h:338
A UHCI endpoint.
Definition: uhci.h:336
A USB port.
Definition: usb.h:796
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
struct list_head endpoints
List of all endpoints.
Definition: uhci.h:322
static void uhci_endpoint_poll(struct uhci_endpoint *endpoint)
Poll for completions.
Definition: uhci.c:891
static void * usb_bus_get_hostdata(struct usb_bus *bus)
Get USB bus host controller private data.
Definition: usb.h:1039
A UHCI device.
Definition: uhci.h:307
static void uhci_root_poll(struct usb_hub *hub, struct usb_port *port)
Poll for port status changes.
Definition: uhci.c:1274
struct list_head list
List of all endpoints.
Definition: uhci.h:342
uint8_t bus
Bus.
Definition: edd.h:14
#define UHCI_PORTS
Number of ports.
Definition: uhci.h:24

References bus, uhci_device::endpoints, uhci_endpoint::list, list_for_each_entry, uhci_endpoint::uhci, uhci_endpoint_poll(), UHCI_PORTS, uhci_root_poll(), and usb_bus_get_hostdata().

◆ ehci_companion()

__weak unsigned int ehci_companion ( struct pci_device *pci  __unused)

Locate EHCI companion controller (when no EHCI support is present)

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

Definition at line 1456 of file uhci.c.

1456  {
1457  return 0;
1458 }

Referenced by uhci_probe().

◆ uhci_probe()

static int uhci_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 1466 of file uhci.c.

1466  {
1467  struct uhci_device *uhci;
1468  struct usb_port *port;
1469  unsigned int i;
1470  int rc;
1471 
1472  /* Allocate and initialise structure */
1473  uhci = zalloc ( sizeof ( *uhci ) );
1474  if ( ! uhci ) {
1475  rc = -ENOMEM;
1476  goto err_alloc;
1477  }
1478  uhci->name = pci->dev.name;
1479  INIT_LIST_HEAD ( &uhci->endpoints );
1480  INIT_LIST_HEAD ( &uhci->async );
1481  INIT_LIST_HEAD ( &uhci->periodic );
1482 
1483  /* Fix up PCI device */
1484  adjust_pci_device ( pci );
1485 
1486  /* Identify EHCI companion controller, if any */
1487  uhci->companion = ehci_companion ( pci );
1488 
1489  /* Claim ownership from BIOS. (There is no release mechanism
1490  * for UHCI.)
1491  */
1493 
1494  /* Map registers */
1495  uhci->regs = pci->ioaddr;
1496  if ( ! uhci->regs ) {
1497  rc = -ENODEV;
1498  goto err_ioremap;
1499  }
1500 
1501  /* Reset device */
1502  if ( ( rc = uhci_reset ( uhci ) ) != 0 )
1503  goto err_reset;
1504 
1505  /* Allocate USB bus */
1506  uhci->bus = alloc_usb_bus ( &pci->dev, UHCI_PORTS, UHCI_MTU,
1507  &uhci_operations );
1508  if ( ! uhci->bus ) {
1509  rc = -ENOMEM;
1510  goto err_alloc_bus;
1511  }
1512  usb_bus_set_hostdata ( uhci->bus, uhci );
1513  usb_hub_set_drvdata ( uhci->bus->hub, uhci );
1514 
1515  /* Set port protocols */
1516  for ( i = 1 ; i <= UHCI_PORTS ; i++ ) {
1517  port = usb_port ( uhci->bus->hub, i );
1518  port->protocol = USB_PROTO_2_0;
1519  }
1520 
1521  /* Register USB bus */
1522  if ( ( rc = register_usb_bus ( uhci->bus ) ) != 0 )
1523  goto err_register;
1524 
1525  pci_set_drvdata ( pci, uhci );
1526  return 0;
1527 
1528  unregister_usb_bus ( uhci->bus );
1529  err_register:
1530  free_usb_bus ( uhci->bus );
1531  err_alloc_bus:
1532  uhci_reset ( uhci );
1533  err_reset:
1534  err_ioremap:
1535  free ( uhci );
1536  err_alloc:
1537  return rc;
1538 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned long ioaddr
I/O address.
Definition: pci.h:200
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:2033
struct list_head async
Asynchronous schedule.
Definition: uhci.h:324
USB 2.0.
Definition: usb.h:22
__weak unsigned int ehci_companion(struct pci_device *pci __unused)
Locate EHCI companion controller (when no EHCI support is present)
Definition: uhci.c:1456
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
char name[40]
Name.
Definition: device.h:75
#define UHCI_MTU
Maximum transfer size.
Definition: uhci.h:27
const char * name
Name.
Definition: uhci.h:311
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct device dev
Generic device.
Definition: pci.h:189
struct list_head periodic
Periodic schedule.
Definition: uhci.h:329
static void usb_bus_set_hostdata(struct usb_bus *bus, void *priv)
Set USB bus host controller private data.
Definition: usb.h:1028
A USB port.
Definition: usb.h:796
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#define ENOMEM
Not enough space.
Definition: errno.h:534
u8 port
Port number.
Definition: CIB_PRM.h:31
static struct usb_host_operations uhci_operations
USB host controller operations.
Definition: uhci.c:1417
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2104
unsigned int companion
EHCI companion controller bus:dev.fn address (if any)
Definition: uhci.h:314
unsigned long regs
Registers.
Definition: uhci.h:309
struct list_head endpoints
List of all endpoints.
Definition: uhci.h:322
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define UHCI_USBLEGSUP
USB legacy support register (in PCI configuration space)
Definition: uhci.h:186
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define ENODEV
No such device.
Definition: errno.h:509
static int uhci_reset(struct uhci_device *uhci)
Reset UHCI device.
Definition: uhci.c:130
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define UHCI_USBLEGSUP_DEFAULT
USB legacy support default value.
Definition: uhci.h:189
int register_usb_bus(struct usb_bus *bus)
Register USB bus.
Definition: usb.c:2069
A UHCI device.
Definition: uhci.h:307
struct usb_hub * hub
Root hub.
Definition: usb.h:972
static void usb_hub_set_drvdata(struct usb_hub *hub, void *priv)
Set USB hub driver private data.
Definition: usb.h:920
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:943
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2128
struct usb_bus * bus
USB bus.
Definition: uhci.h:332
#define UHCI_PORTS
Number of ports.
Definition: uhci.h:24

References adjust_pci_device(), alloc_usb_bus(), uhci_device::async, uhci_device::bus, uhci_device::companion, pci_device::dev, ehci_companion(), uhci_device::endpoints, ENODEV, ENOMEM, free, free_usb_bus(), usb_bus::hub, INIT_LIST_HEAD, pci_device::ioaddr, device::name, uhci_device::name, pci_set_drvdata(), pci_write_config_word(), uhci_device::periodic, port, rc, register_usb_bus(), uhci_device::regs, UHCI_MTU, uhci_operations, UHCI_PORTS, uhci_reset(), UHCI_USBLEGSUP, UHCI_USBLEGSUP_DEFAULT, unregister_usb_bus(), usb_bus_set_hostdata(), usb_hub_set_drvdata(), usb_port(), USB_PROTO_2_0, and zalloc().

◆ uhci_remove()

static void uhci_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 1545 of file uhci.c.

1545  {
1546  struct uhci_device *uhci = pci_get_drvdata ( pci );
1547  struct usb_bus *bus = uhci->bus;
1548 
1549  unregister_usb_bus ( bus );
1550  assert ( list_empty ( &uhci->async ) );
1551  assert ( list_empty ( &uhci->periodic ) );
1552  free_usb_bus ( bus );
1553  uhci_reset ( uhci );
1554  free ( uhci );
1555 }
struct list_head async
Asynchronous schedule.
Definition: uhci.h:324
struct list_head periodic
Periodic schedule.
Definition: uhci.h:329
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
void unregister_usb_bus(struct usb_bus *bus)
Unregister USB bus.
Definition: usb.c:2104
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static int uhci_reset(struct uhci_device *uhci)
Reset UHCI device.
Definition: uhci.c:130
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348
A UHCI device.
Definition: uhci.h:307
A USB bus.
Definition: usb.h:949
uint8_t bus
Bus.
Definition: edd.h:14
void free_usb_bus(struct usb_bus *bus)
Free USB bus.
Definition: usb.c:2128
struct usb_bus * bus
USB bus.
Definition: uhci.h:332

References assert(), uhci_device::async, bus, uhci_device::bus, free, free_usb_bus(), list_empty, pci_get_drvdata(), uhci_device::periodic, uhci_reset(), and unregister_usb_bus().

Variable Documentation

◆ uhci_operations

struct usb_host_operations uhci_operations
static

USB host controller operations.

Definition at line 1417 of file uhci.c.

Referenced by uhci_probe().

◆ uhci_ids

struct pci_device_id uhci_ids[]
static
Initial value:
= {
PCI_ROM ( 0xffff, 0xffff, "uhci", "UHCI", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:283

UHCI PCI device IDs.

Definition at line 1558 of file uhci.c.

◆ __pci_driver

struct pci_driver uhci_driver __pci_driver
Initial value:
= {
.ids = uhci_ids,
.id_count = ( sizeof ( uhci_ids ) / sizeof ( uhci_ids[0] ) ),
.probe = uhci_probe,
.remove = uhci_remove,
}
#define PCI_CLASS_ID(base, sub, progif)
Construct PCI class ID.
Definition: pci.h:179
#define PCI_CLASS_SERIAL
Definition: Pci22.h:272
static struct pci_device_id uhci_ids[]
UHCI PCI device IDs.
Definition: uhci.c:1558
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:278
#define PCI_CLASS_SERIAL_USB_UHCI
UHCI USB controller.
Definition: pci.h:132
static void uhci_remove(struct pci_device *pci)
Remove PCI device.
Definition: uhci.c:1545
static int uhci_probe(struct pci_device *pci)
Probe PCI device.
Definition: uhci.c:1466

UHCI PCI driver.

Definition at line 1563 of file uhci.c.