iPXE
Data Structures | Functions | Variables
usb.c File Reference

Universal Serial Bus (USB) More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/usb.h>
#include <ipxe/cdc.h>

Go to the source code of this file.

Data Structures

struct  usb_control_pseudo_header
 USB control transfer pseudo-header. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static const char * usb_speed_name (unsigned int speed)
 Get USB speed name (for debugging) More...
 
static const char * usb_bcd (uint16_t bcd)
 Transcribe USB BCD-coded value (for debugging) More...
 
static struct usb_interface_association_descriptorusb_interface_association_descriptor (struct usb_configuration_descriptor *config, unsigned int first)
 Locate USB interface association descriptor. More...
 
struct usb_interface_descriptorusb_interface_descriptor (struct usb_configuration_descriptor *config, unsigned int interface, unsigned int alternate)
 Locate USB interface descriptor. More...
 
struct usb_endpoint_descriptorusb_endpoint_descriptor (struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface, unsigned int type, unsigned int index)
 Locate USB endpoint descriptor. More...
 
struct usb_endpoint_companion_descriptorusb_endpoint_companion_descriptor (struct usb_configuration_descriptor *config, struct usb_endpoint_descriptor *desc)
 Locate USB endpoint companion descriptor. More...
 
const char * usb_endpoint_name (struct usb_endpoint *ep)
 Get USB endpoint name (for debugging) More...
 
int usb_endpoint_described (struct usb_endpoint *ep, struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface, unsigned int type, unsigned int index)
 Describe USB endpoint from device configuration. More...
 
int usb_endpoint_open (struct usb_endpoint *ep)
 Open USB endpoint. More...
 
static int usb_endpoint_clear_tt (struct usb_endpoint *ep)
 Clear transaction translator (if applicable) More...
 
int usb_endpoint_clear_halt (struct usb_endpoint *ep)
 Clear endpoint halt (if applicable) More...
 
void usb_endpoint_close (struct usb_endpoint *ep)
 Close USB endpoint. More...
 
static int usb_endpoint_reset (struct usb_endpoint *ep)
 Reset USB endpoint. More...
 
static int usb_endpoint_mtu (struct usb_endpoint *ep, size_t mtu)
 Update endpoint MTU. More...
 
int usb_message (struct usb_endpoint *ep, unsigned int request, unsigned int value, unsigned int index, struct io_buffer *iobuf)
 Enqueue USB message transfer. More...
 
int usb_stream (struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
 Enqueue USB stream transfer. More...
 
void usb_complete_err (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete transfer (possibly with error) More...
 
int usb_prefill (struct usb_endpoint *ep)
 Prefill endpoint recycled buffer list. More...
 
int usb_refill_limit (struct usb_endpoint *ep, unsigned int max)
 Refill endpoint up to specified limit. More...
 
int usb_refill (struct usb_endpoint *ep)
 Refill endpoint. More...
 
void usb_flush (struct usb_endpoint *ep)
 Discard endpoint recycled buffer list. More...
 
static void usb_control_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete USB control transfer. More...
 
int usb_control (struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
 Issue USB control transaction. More...
 
static unsigned int usb_get_default_language (struct usb_device *usb)
 Get default language ID. More...
 
int usb_get_string_descriptor (struct usb_device *usb, unsigned int index, unsigned int language, char *buf, size_t len)
 Get USB string descriptor. More...
 
static int usb_config_descriptor (struct usb_device *usb, unsigned int index, struct usb_configuration_descriptor **config)
 Get USB configuration descriptor. More...
 
static int usb_describe (struct usb_device *usb, struct usb_configuration_descriptor *config, unsigned int first, uint8_t *interfaces, struct usb_function_descriptor *desc)
 Describe USB function. More...
 
static int usb_used (struct usb_device *usb, unsigned int count, uint8_t *interface, uint8_t *used)
 Update list of used interface. More...
 
struct usb_driverusb_find_driver (struct usb_function_descriptor *desc, struct usb_device_id **id)
 Find USB device driver. More...
 
static int usb_score (struct usb_device *usb, struct usb_configuration_descriptor *config)
 Get USB device configuration score. More...
 
static int usb_probe (struct usb_function *func, struct usb_configuration_descriptor *config)
 Probe USB device driver. More...
 
static void usb_remove (struct usb_function *func)
 Remove USB device driver. More...
 
static void usb_probe_all (struct usb_device *usb, struct usb_configuration_descriptor *config)
 Probe all USB device drivers. More...
 
static void usb_remove_all (struct usb_device *usb)
 Remove all device drivers. More...
 
static void usb_deconfigure (struct usb_device *usb)
 Clear USB device configuration. More...
 
static int usb_autoconfigure (struct usb_device *usb)
 Choose our preferred USB device configuration. More...
 
static struct usb_devicealloc_usb (struct usb_port *port)
 Allocate USB device. More...
 
static int register_usb (struct usb_device *usb)
 Register USB device. More...
 
static void unregister_usb (struct usb_device *usb)
 Unregister USB device. More...
 
static void free_usb (struct usb_device *usb)
 Free USB device. More...
 
struct usb_devicefind_usb (struct usb_bus *bus, unsigned int address)
 Find USB device by address. More...
 
static int usb_attached (struct usb_port *port)
 Handle newly attached USB device. More...
 
static void usb_detached (struct usb_port *port)
 Handle newly detached USB device. More...
 
static int usb_hotplugged (struct usb_port *port)
 Handle newly attached or detached USB device. More...
 
void usb_port_changed (struct usb_port *port)
 Report port status change. More...
 
static void usb_hotplug (void)
 Handle newly attached or detached USB device. More...
 
static void usb_step (struct process *process __unused)
 USB process. More...
 
 PERMANENT_PROCESS (usb_process, usb_step)
 USB process. More...
 
struct usb_huballoc_usb_hub (struct usb_bus *bus, struct usb_device *usb, unsigned int ports, struct usb_hub_driver_operations *driver)
 Allocate USB hub. More...
 
int register_usb_hub (struct usb_hub *hub)
 Register USB hub. More...
 
void unregister_usb_hub (struct usb_hub *hub)
 Unregister USB hub. More...
 
void free_usb_hub (struct usb_hub *hub)
 Free USB hub. More...
 
struct usb_busalloc_usb_bus (struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
 Allocate USB bus. More...
 
int register_usb_bus (struct usb_bus *bus)
 Register USB bus. More...
 
void unregister_usb_bus (struct usb_bus *bus)
 Unregister USB bus. More...
 
void free_usb_bus (struct usb_bus *bus)
 Free USB bus. More...
 
struct usb_busfind_usb_bus (unsigned int address)
 Find USB bus by address. More...
 
struct usb_busfind_usb_bus_by_location (unsigned int bus_type, unsigned int location)
 Find USB bus by device location. More...
 
int usb_alloc_address (struct usb_bus *bus)
 Allocate device address. More...
 
void usb_free_address (struct usb_bus *bus, unsigned int address)
 Free device address. More...
 
int usb_find_next (struct usb_device **usb, uint16_t *busdev)
 Find next USB device. More...
 
unsigned int usb_route_string (struct usb_device *usb)
 Get USB route string. More...
 
struct usb_portusb_root_hub_port (struct usb_device *usb)
 Get USB root hub port. More...
 
struct usb_portusb_transaction_translator (struct usb_device *usb)
 Get USB transaction translator. More...
 
 REQUIRING_SYMBOL (register_usb_bus)
 
 REQUIRE_OBJECT (config_usb)
 
 REQUIRE_OBJECT (usbhub)
 

Variables

struct list_head usb_buses = LIST_HEAD_INIT ( usb_buses )
 List of USB buses. More...
 
static struct list_head usb_changed = LIST_HEAD_INIT ( usb_changed )
 List of changed ports. More...
 
static struct list_head usb_halted = LIST_HEAD_INIT ( usb_halted )
 List of halted endpoints. More...
 
static struct usb_endpoint_driver_operations usb_control_operations
 USB control endpoint driver operations. More...
 

Detailed Description

Universal Serial Bus (USB)

Definition in file usb.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ usb_speed_name()

static const char* usb_speed_name ( unsigned int  speed)
inlinestatic

Get USB speed name (for debugging)

Parameters
speedSpeed
Return values
nameSpeed name

Definition at line 66 of file usb.c.

66  {
67  static const char *exponents[4] = { "", "k", "M", "G" };
68  static char buf[ 10 /* "xxxxxXbps" + NUL */ ];
69  unsigned int mantissa;
70  unsigned int exponent;
71 
72  /* Extract mantissa and exponent */
73  mantissa = USB_SPEED_MANTISSA ( speed );
74  exponent = USB_SPEED_EXPONENT ( speed );
75 
76  /* Name speed */
77  switch ( speed ) {
78  case USB_SPEED_NONE: return "DETACHED";
79  case USB_SPEED_LOW: return "low";
80  case USB_SPEED_FULL: return "full";
81  case USB_SPEED_HIGH: return "high";
82  case USB_SPEED_SUPER: return "super";
83  default:
84  snprintf ( buf, sizeof ( buf ), "%d%sbps",
85  mantissa, exponents[exponent] );
86  return buf;
87  }
88 }
#define USB_SPEED_EXPONENT(speed)
Extract USB speed exponent.
Definition: usb.h:42
Low speed (1.5Mbps)
Definition: usb.h:49
#define USB_SPEED_MANTISSA(speed)
Extract USB speed mantissa.
Definition: usb.h:39
Super speed (5Gbps)
Definition: usb.h:55
Not connected.
Definition: usb.h:47
High speed (480Mbps)
Definition: usb.h:53
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383
Full speed (12Mbps)
Definition: usb.h:51

References snprintf(), USB_SPEED_EXPONENT, USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_LOW, USB_SPEED_MANTISSA, USB_SPEED_NONE, and USB_SPEED_SUPER.

Referenced by register_usb().

◆ usb_bcd()

static const char* usb_bcd ( uint16_t  bcd)
inlinestatic

Transcribe USB BCD-coded value (for debugging)

Parameters
bcdBCD-coded value
Return values
stringTranscribed value

Definition at line 96 of file usb.c.

96  {
97  static char buf[ 6 /* "xx.xx" + NUL */ ];
98  uint8_t high = ( bcd >> 8 );
99  uint8_t low = ( bcd >> 0 );
100 
101  snprintf ( buf, sizeof ( buf ), "%x.%02x", high, low );
102  return buf;
103 }
uint32_t low
Low 16 bits of address.
Definition: myson.h:19
uint32_t high
High 32 bits of address.
Definition: myson.h:20
unsigned char uint8_t
Definition: stdint.h:10
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383

References high, low, and snprintf().

Referenced by register_usb().

◆ usb_interface_association_descriptor()

static struct usb_interface_association_descriptor* usb_interface_association_descriptor ( struct usb_configuration_descriptor config,
unsigned int  first 
)
static

Locate USB interface association descriptor.

Parameters
configConfiguraton descriptor
firstFirst interface number
Return values
descInterface association descriptor, or NULL if not found

Definition at line 120 of file usb.c.

122  {
124 
125  /* Find a matching interface association descriptor */
126  for_each_config_descriptor ( desc, config ) {
127  if ( ( desc->header.type ==
129  ( desc->first == first ) )
130  return desc;
131  }
132  return NULL;
133 }
A USB interface association descriptor.
Definition: usb.h:329
uint32_t first
First block in range.
Definition: pccrr.h:15
#define for_each_config_descriptor(desc, config)
Iterate over all configuration descriptors.
Definition: usb.h:386
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
Standard Interface Association Descriptor USB 3.0 spec, Section 9.6.4.
Definition: Usb.h:143
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References desc, first, for_each_config_descriptor, and NULL.

Referenced by usb_describe().

◆ usb_interface_descriptor()

struct usb_interface_descriptor* usb_interface_descriptor ( struct usb_configuration_descriptor config,
unsigned int  interface,
unsigned int  alternate 
)

Locate USB interface descriptor.

Parameters
configConfiguraton descriptor
interfaceInterface number
alternateAlternate setting
Return values
descInterface descriptor, or NULL if not found

Definition at line 144 of file usb.c.

145  {
147 
148  /* Find a matching interface descriptor */
149  for_each_config_descriptor ( desc, config ) {
150  if ( ( desc->header.type == USB_INTERFACE_DESCRIPTOR ) &&
151  ( desc->interface == interface ) &&
152  ( desc->alternate == alternate ) )
153  return desc;
154  }
155  return NULL;
156 }
Standard Interface Descriptor USB 2.0 spec, Section 9.6.5.
Definition: Usb.h:158
#define for_each_config_descriptor(desc, config)
Iterate over all configuration descriptors.
Definition: usb.h:386
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
A USB interface descriptor.
Definition: usb.h:245
An object interface.
Definition: interface.h:125
struct ib_cm_path alternate
Alternate path.
Definition: ib_mad.h:43
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References alternate, desc, for_each_config_descriptor, and NULL.

Referenced by ecm_probe(), efi_usb_get_interface_descriptor(), ncm_probe(), usbblk_probe(), usbhid_describe(), usbnet_comms_describe(), and usbnet_data_describe().

◆ usb_endpoint_descriptor()

struct usb_endpoint_descriptor* usb_endpoint_descriptor ( struct usb_configuration_descriptor config,
struct usb_interface_descriptor interface,
unsigned int  type,
unsigned int  index 
)

Locate USB endpoint descriptor.

Parameters
configConfiguration descriptor
interfaceInterface descriptor
typeEndpoint (internal) type
indexEndpoint index
Return values
descDescriptor, or NULL if not found

Definition at line 168 of file usb.c.

170  {
172  unsigned int attributes = ( type & USB_ENDPOINT_ATTR_TYPE_MASK );
173  unsigned int direction = ( type & USB_DIR_IN );
174 
175  /* Find a matching endpoint descriptor */
177  if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) &&
178  ( ( desc->attributes &
180  ( ( desc->endpoint & USB_DIR_IN ) == direction ) &&
181  ( index-- == 0 ) )
182  return desc;
183  }
184  return NULL;
185 }
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:281
uint32_t type
Operating system type.
Definition: ena.h:12
long index
Definition: bigint.h:65
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:394
uint8_t direction
Direction.
Definition: ena.h:14
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
An object interface.
Definition: interface.h:125
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:98
uint8_t attributes
Attributes.
Definition: usb.h:270
Standard Endpoint Descriptor USB 2.0 spec, Section 9.6.6.
Definition: Usb.h:174
A USB endpoint descriptor.
Definition: usb.h:264
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References usb_endpoint_descriptor::attributes, desc, direction, for_each_interface_descriptor, index, NULL, type, USB_DIR_IN, and USB_ENDPOINT_ATTR_TYPE_MASK.

Referenced by usb_endpoint_described().

◆ usb_endpoint_companion_descriptor()

Locate USB endpoint companion descriptor.

Parameters
configConfiguration descriptor
descEndpoint descriptor
Return values
descxCompanion descriptor, or NULL if not found

Definition at line 195 of file usb.c.

196  {
197  struct usb_endpoint_companion_descriptor *descx;
198 
199  /* Get companion descriptor, if present */
200  descx = container_of ( usb_next_descriptor ( &desc->header ),
202  header );
203  return ( ( usb_is_within_config ( config, &descx->header ) &&
205  ? descx : NULL );
206 }
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:316
static struct usb_descriptor_header * usb_next_descriptor(struct usb_descriptor_header *desc)
Get next USB descriptor.
Definition: usb.h:358
#define USB_ENDPOINT_COMPANION_DESCRIPTOR
A USB endpoint companion descriptor.
Definition: usb.h:326
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
uint8_t type
Descriptor type.
Definition: usb.h:177
A USB endpoint companion descriptor.
Definition: usb.h:314
struct ena_llq_option header
Header locations.
Definition: ena.h:16
static int usb_is_within_config(struct usb_configuration_descriptor *config, struct usb_descriptor_header *desc)
Check that descriptor lies within a configuration descriptor.
Definition: usb.h:371
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References container_of, desc, header, usb_endpoint_companion_descriptor::header, NULL, usb_descriptor_header::type, USB_ENDPOINT_COMPANION_DESCRIPTOR, usb_is_within_config(), and usb_next_descriptor().

Referenced by usb_endpoint_described().

◆ usb_endpoint_name()

const char* usb_endpoint_name ( struct usb_endpoint ep)

Get USB endpoint name (for debugging)

Parameters
epUSB endpoint
Return values
nameEndpoint name

Definition at line 221 of file usb.c.

221  {
222  static char buf[ 9 /* "EPxx OUT" + NUL */ ];
223  unsigned int address = ep->address;
224 
225  snprintf ( buf, sizeof ( buf ), "EP%d%s",
227  ( address ?
228  ( ( address & USB_ENDPOINT_IN ) ? " IN" : " OUT" ) : "" ));
229  return buf;
230 }
uint64_t address
Base address.
Definition: ena.h:24
#define USB_ENDPOINT_MAX
Maximum endpoint number.
Definition: usb.h:522
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition: usb.h:525
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383
unsigned int address
Endpoint address.
Definition: usb.h:408

References address, usb_endpoint::address, snprintf(), USB_ENDPOINT_IN, and USB_ENDPOINT_MAX.

Referenced by efi_usb_async_start(), efi_usb_close(), efi_usb_open(), efi_usb_sync_transfer(), ehci_endpoint_close(), ehci_endpoint_poll(), ehci_root_clear_tt(), uhci_endpoint_poll(), uhci_root_clear_tt(), usb_complete_err(), usb_endpoint_clear_halt(), usb_endpoint_clear_tt(), usb_endpoint_mtu(), usb_endpoint_open(), usb_endpoint_reset(), usb_message(), usb_stream(), usbio_bulk_in_poll(), usbio_bulk_out_poll(), usbio_control_poll(), usbio_endpoint_open(), usbio_interface(), usbio_interrupt_callback(), usbio_interrupt_open(), usbkbd_probe(), and xhci_root_clear_tt().

◆ usb_endpoint_described()

int usb_endpoint_described ( struct usb_endpoint ep,
struct usb_configuration_descriptor config,
struct usb_interface_descriptor interface,
unsigned int  type,
unsigned int  index 
)

Describe USB endpoint from device configuration.

Parameters
epUSB endpoint
configConfiguration descriptor
interfaceInterface descriptor
typeEndpoint (internal) type
indexEndpoint index
Return values
rcReturn status code

Definition at line 242 of file usb.c.

245  {
246  struct usb_device *usb = ep->usb;
248  struct usb_endpoint_companion_descriptor *descx;
249  unsigned int sizes;
250  unsigned int burst;
251  unsigned int interval;
252  size_t mtu;
253 
254  /* Locate endpoint descriptor */
256  if ( ! desc )
257  return -ENOENT;
258 
259  /* Locate companion descriptor, if any */
260  descx = usb_endpoint_companion_descriptor ( config, desc );
261 
262  /* Calculate MTU and burst size */
263  sizes = le16_to_cpu ( desc->sizes );
264  mtu = USB_ENDPOINT_MTU ( sizes );
265  burst = ( descx ? descx->burst : USB_ENDPOINT_BURST ( sizes ) );
266 
267  /* Calculate interval */
268  if ( ( type & USB_ENDPOINT_ATTR_TYPE_MASK ) ==
270  if ( usb->speed >= USB_SPEED_HIGH ) {
271  /* 2^(desc->interval-1) is a microframe count */
272  interval = ( 1 << ( desc->interval - 1 ) );
273  } else {
274  /* desc->interval is a (whole) frame count */
275  interval = ( desc->interval << 3 );
276  }
277  } else {
278  /* desc->interval is a microframe count */
279  interval = desc->interval;
280  }
281 
282  /* Describe endpoint */
283  usb_endpoint_describe ( ep, desc->endpoint, desc->attributes,
284  mtu, burst, interval );
285  return 0;
286 }
static void usb_endpoint_describe(struct usb_endpoint *ep, unsigned int address, unsigned int attributes, size_t mtu, unsigned int burst, unsigned int interval)
Describe USB endpoint.
Definition: usb.h:558
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:281
uint32_t type
Operating system type.
Definition: ena.h:12
long index
Definition: bigint.h:65
#define ENOENT
No such file or directory.
Definition: errno.h:515
unsigned int speed
Device speed.
Definition: usb.h:729
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
An object interface.
Definition: interface.h:125
#define USB_ENDPOINT_BURST(sizes)
USB endpoint maximum burst size.
Definition: usb.h:311
A USB device.
Definition: usb.h:723
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:293
#define le16_to_cpu(value)
Definition: byteswap.h:113
struct usb_endpoint_companion_descriptor * usb_endpoint_companion_descriptor(struct usb_configuration_descriptor *config, struct usb_endpoint_descriptor *desc)
Locate USB endpoint companion descriptor.
Definition: usb.c:195
struct usb_endpoint_descriptor * usb_endpoint_descriptor(struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface, unsigned int type, unsigned int index)
Locate USB endpoint descriptor.
Definition: usb.c:168
A USB endpoint descriptor.
Definition: usb.h:264
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
A USB endpoint companion descriptor.
Definition: usb.h:314
High speed (480Mbps)
Definition: usb.h:53
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct usb_device * usb
USB device.
Definition: usb.h:406
#define USB_ENDPOINT_MTU(sizes)
USB endpoint MTU.
Definition: usb.h:308
uint16_t burst
Maximum burst size.
Definition: ena.h:28
uint8_t burst
Maximum burst size.
Definition: usb.h:318

References burst, usb_endpoint_companion_descriptor::burst, desc, ENOENT, usb_device::ep, index, le16_to_cpu, mtu, usb_device::speed, type, usb_endpoint::usb, USB_ENDPOINT_ATTR_INTERRUPT, USB_ENDPOINT_ATTR_TYPE_MASK, USB_ENDPOINT_BURST, usb_endpoint_companion_descriptor(), usb_endpoint_describe(), usb_endpoint_descriptor(), USB_ENDPOINT_MTU, and USB_SPEED_HIGH.

Referenced by hub_probe(), usbblk_probe(), usbhid_describe(), usbnet_comms_describe(), and usbnet_data_describe().

◆ usb_endpoint_open()

int usb_endpoint_open ( struct usb_endpoint ep)

Open USB endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 294 of file usb.c.

294  {
295  struct usb_device *usb = ep->usb;
296  unsigned int idx = USB_ENDPOINT_IDX ( ep->address );
297  int rc;
298 
299  /* Populate host controller operations */
300  ep->host = &usb->port->hub->bus->op->endpoint;
301 
302  /* Add to endpoint list */
303  if ( usb->ep[idx] != NULL ) {
304  DBGC ( usb, "USB %s %s is already open\n",
305  usb->name, usb_endpoint_name ( ep ) );
306  rc = -EALREADY;
307  goto err_already;
308  }
309  usb->ep[idx] = ep;
310  INIT_LIST_HEAD ( &ep->halted );
311 
312  /* Open endpoint */
313  if ( ( rc = ep->host->open ( ep ) ) != 0 ) {
314  DBGC ( usb, "USB %s %s could not open: %s\n", usb->name,
315  usb_endpoint_name ( ep ), strerror ( rc ) );
316  goto err_open;
317  }
318  ep->open = 1;
319 
320  DBGC2 ( usb, "USB %s %s opened with MTU %zd, burst %d, interval %d\n",
321  usb->name, usb_endpoint_name ( ep ), ep->mtu, ep->burst,
322  ep->interval );
323  return 0;
324 
325  ep->open = 0;
326  ep->host->close ( ep );
327  err_open:
328  usb->ep[idx] = NULL;
329  err_already:
330  if ( ep->max )
331  usb_flush ( ep );
332  return rc;
333 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void(* close)(struct usb_endpoint *ep)
Close endpoint.
Definition: usb.h:455
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:419
struct usb_port * port
USB port.
Definition: usb.h:727
struct list_head halted
List of halted endpoints.
Definition: usb.h:424
unsigned int burst
Maximum burst size.
Definition: usb.h:414
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:528
#define EALREADY
Connection already in progress.
Definition: errno.h:324
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
size_t mtu
Maximum transfer size.
Definition: usb.h:412
struct usb_host_operations * op
Host controller operations set.
Definition: usb.h:972
unsigned int max
Maximum fill level.
Definition: usb.h:440
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
#define DBGC2(...)
Definition: compiler.h:522
struct usb_hub * hub
USB hub.
Definition: usb.h:815
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
unsigned int interval
Interval (in microframes)
Definition: usb.h:416
struct usb_endpoint_host_operations endpoint
Endpoint operations.
Definition: usb.h:1033
struct usb_device * usb
USB device.
Definition: usb.h:406
int(* open)(struct usb_endpoint *ep)
Open endpoint.
Definition: usb.h:450
void usb_flush(struct usb_endpoint *ep)
Discard endpoint recycled buffer list.
Definition: usb.c:720
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:427
struct usb_bus * bus
USB bus.
Definition: usb.h:845
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
unsigned int address
Endpoint address.
Definition: usb.h:408

References usb_endpoint::address, usb_endpoint::burst, usb_hub::bus, usb_endpoint_host_operations::close, DBGC, DBGC2, EALREADY, usb_host_operations::endpoint, usb_device::ep, usb_endpoint::halted, usb_endpoint::host, usb_port::hub, INIT_LIST_HEAD, usb_endpoint::interval, usb_endpoint::max, usb_endpoint::mtu, usb_device::name, NULL, usb_bus::op, usb_endpoint::open, usb_endpoint_host_operations::open, usb_device::port, rc, strerror(), usb_endpoint::usb, USB_ENDPOINT_IDX, usb_endpoint_name(), and usb_flush().

Referenced by efi_usb_open(), hub_open(), register_usb(), usbblk_open(), usbhid_open(), and usbnet_open().

◆ usb_endpoint_clear_tt()

static int usb_endpoint_clear_tt ( struct usb_endpoint ep)
static

Clear transaction translator (if applicable)

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 341 of file usb.c.

341  {
342  struct usb_device *usb = ep->usb;
343  struct usb_port *tt;
344  int rc;
345 
346  /* Do nothing if this is a periodic endpoint */
348  return 0;
349 
350  /* Do nothing if this endpoint is not behind a transaction translator */
352  if ( ! tt )
353  return 0;
354 
355  /* Clear transaction translator buffer */
356  if ( ( rc = tt->hub->driver->clear_tt ( tt->hub, tt, ep ) ) != 0 ) {
357  DBGC ( usb, "USB %s %s could not clear transaction translator: "
358  "%s\n", usb->name, usb_endpoint_name ( ep ),
359  strerror ( rc ) );
360  return rc;
361  }
362 
363  return 0;
364 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:835
#define USB_ENDPOINT_ATTR_PERIODIC
Endpoint periodic type.
Definition: usb.h:284
int(* clear_tt)(struct usb_hub *hub, struct usb_port *port, struct usb_endpoint *ep)
Clear transaction translator buffer.
Definition: usb.h:926
A USB port.
Definition: usb.h:813
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:859
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
struct usb_port * usb_transaction_translator(struct usb_device *usb)
Get USB transaction translator.
Definition: usb.c:2372
struct usb_hub * hub
USB hub.
Definition: usb.h:815
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct usb_device * usb
USB device.
Definition: usb.h:406
unsigned int attributes
Attributes.
Definition: usb.h:410

References usb_endpoint::attributes, usb_hub_driver_operations::clear_tt, DBGC, usb_hub::driver, usb_device::ep, usb_port::hub, usb_device::name, rc, strerror(), usb_endpoint::usb, usb_port::usb, USB_ENDPOINT_ATTR_PERIODIC, usb_endpoint_name(), and usb_transaction_translator().

Referenced by usb_endpoint_clear_halt(), and usb_endpoint_close().

◆ usb_endpoint_clear_halt()

int usb_endpoint_clear_halt ( struct usb_endpoint ep)

Clear endpoint halt (if applicable)

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 372 of file usb.c.

372  {
373  struct usb_device *usb = ep->usb;
374  unsigned int type;
375  int rc;
376 
377  /* Clear transaction translator, if applicable */
378  if ( ( rc = usb_endpoint_clear_tt ( ep ) ) != 0 )
379  return rc;
380 
381  /* Clear endpoint halt (if applicable) */
383  if ( ( type != USB_ENDPOINT_ATTR_CONTROL ) &&
386  ep->address ) ) != 0 ) ) {
387  DBGC ( usb, "USB %s %s could not clear endpoint halt: %s\n",
388  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
389  return rc;
390  }
391 
392  return 0;
393 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:281
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC(...)
Definition: compiler.h:505
#define USB_RECIP_ENDPOINT
Request recipient is an endpoint.
Definition: usb.h:119
static int usb_clear_feature(struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
Clear feature.
Definition: usb.h:1127
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
static int usb_endpoint_clear_tt(struct usb_endpoint *ep)
Clear transaction translator (if applicable)
Definition: usb.c:341
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
Definition: usb.h:287
struct usb_device * usb
USB device.
Definition: usb.h:406
#define USB_ENDPOINT_HALT
Endpoint halt feature.
Definition: usb.h:157
unsigned int attributes
Attributes.
Definition: usb.h:410
unsigned int address
Endpoint address.
Definition: usb.h:408

References usb_endpoint::address, usb_endpoint::attributes, DBGC, usb_device::ep, usb_device::name, rc, strerror(), type, usb_endpoint::usb, usb_clear_feature(), USB_ENDPOINT_ATTR_CONTROL, USB_ENDPOINT_ATTR_TYPE_MASK, usb_endpoint_clear_tt(), USB_ENDPOINT_HALT, usb_endpoint_name(), and USB_RECIP_ENDPOINT.

Referenced by usb_endpoint_reset(), and usbblk_open().

◆ usb_endpoint_close()

void usb_endpoint_close ( struct usb_endpoint ep)

Close USB endpoint.

Parameters
epUSB endpoint

Definition at line 400 of file usb.c.

400  {
401  struct usb_device *usb = ep->usb;
402  unsigned int idx = USB_ENDPOINT_IDX ( ep->address );
403 
404  /* Sanity checks */
405  assert ( usb->ep[idx] == ep );
406 
407  /* Close endpoint */
408  ep->open = 0;
409  ep->host->close ( ep );
410  assert ( ep->fill == 0 );
411 
412  /* Remove from endpoint list */
413  usb->ep[idx] = NULL;
414  list_del ( &ep->halted );
415 
416  /* Discard any recycled buffers, if applicable */
417  if ( ep->max )
418  usb_flush ( ep );
419 
420  /* Clear transaction translator, if applicable */
422 }
void(* close)(struct usb_endpoint *ep)
Close endpoint.
Definition: usb.h:455
int open
Endpoint is open.
Definition: usb.h:419
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct list_head halted
List of halted endpoints.
Definition: usb.h:424
A USB device.
Definition: usb.h:723
unsigned int fill
Buffer fill level.
Definition: usb.h:421
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:528
static int usb_endpoint_clear_tt(struct usb_endpoint *ep)
Clear transaction translator (if applicable)
Definition: usb.c:341
unsigned int max
Maximum fill level.
Definition: usb.h:440
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct usb_device * usb
USB device.
Definition: usb.h:406
void usb_flush(struct usb_endpoint *ep)
Discard endpoint recycled buffer list.
Definition: usb.c:720
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:427
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
unsigned int address
Endpoint address.
Definition: usb.h:408

References usb_endpoint::address, assert(), usb_endpoint_host_operations::close, usb_device::ep, usb_endpoint::fill, usb_endpoint::halted, usb_endpoint::host, list_del, usb_endpoint::max, NULL, usb_endpoint::open, usb_endpoint::usb, usb_endpoint_clear_tt(), USB_ENDPOINT_IDX, and usb_flush().

Referenced by efi_usb_close(), efi_usb_open(), hub_close(), hub_open(), register_usb(), unregister_usb(), usbblk_close(), usbblk_open(), usbhid_close(), usbhid_open(), usbnet_close(), and usbnet_open().

◆ usb_endpoint_reset()

static int usb_endpoint_reset ( struct usb_endpoint ep)
static

Reset USB endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 430 of file usb.c.

430  {
431  struct usb_device *usb = ep->usb;
432  int rc;
433 
434  /* Sanity check */
435  assert ( ! list_empty ( &ep->halted ) );
436 
437  /* Clear device halt, if applicable */
438  if ( ( rc = usb_endpoint_clear_halt ( ep ) ) != 0 )
439  return rc;
440 
441  /* Reset endpoint */
442  if ( ( rc = ep->host->reset ( ep ) ) != 0 ) {
443  DBGC ( usb, "USB %s %s could not reset: %s\n",
444  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
445  return rc;
446  }
447 
448  /* Remove from list of halted endpoints */
449  list_del ( &ep->halted );
450  INIT_LIST_HEAD ( &ep->halted );
451 
452  DBGC ( usb, "USB %s %s reset\n",
453  usb->name, usb_endpoint_name ( ep ) );
454  return 0;
455 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
int usb_endpoint_clear_halt(struct usb_endpoint *ep)
Clear endpoint halt (if applicable)
Definition: usb.c:372
int(* reset)(struct usb_endpoint *ep)
Reset endpoint.
Definition: usb.h:462
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct list_head halted
List of halted endpoints.
Definition: usb.h:424
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct usb_device * usb
USB device.
Definition: usb.h:406
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:427

References assert(), DBGC, usb_device::ep, usb_endpoint::halted, usb_endpoint::host, INIT_LIST_HEAD, list_del, list_empty, usb_device::name, rc, usb_endpoint_host_operations::reset, strerror(), usb_endpoint::usb, usb_endpoint_clear_halt(), and usb_endpoint_name().

Referenced by usb_control(), usb_message(), usb_step(), and usb_stream().

◆ usb_endpoint_mtu()

static int usb_endpoint_mtu ( struct usb_endpoint ep,
size_t  mtu 
)
static

Update endpoint MTU.

Parameters
epUSB endpoint
mtuNew MTU
Return values
rcReturn status code

Definition at line 464 of file usb.c.

464  {
465  struct usb_device *usb = ep->usb;
466  int rc;
467 
468  /* Update MTU */
469  ep->mtu = mtu;
470  if ( ( rc = ep->host->mtu ( ep ) ) != 0 ) {
471  DBGC ( usb, "USB %s %s could not update MTU: %s\n",
472  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
473  return rc;
474  }
475 
476  return 0;
477 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* mtu)(struct usb_endpoint *ep)
Update MTU.
Definition: usb.h:468
#define DBGC(...)
Definition: compiler.h:505
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
size_t mtu
Maximum transfer size.
Definition: usb.h:412
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct usb_device * usb
USB device.
Definition: usb.h:406
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:427

References DBGC, usb_device::ep, usb_endpoint::host, mtu, usb_endpoint::mtu, usb_endpoint_host_operations::mtu, usb_device::name, rc, strerror(), usb_endpoint::usb, and usb_endpoint_name().

Referenced by register_usb().

◆ usb_message()

int usb_message ( struct usb_endpoint ep,
unsigned int  request,
unsigned int  value,
unsigned int  index,
struct io_buffer iobuf 
)

Enqueue USB message transfer.

Parameters
epUSB endpoint
requestRequest
valueValue parameter
indexIndex parameter
iobufI/O buffer
Return values
rcReturn status code

The I/O buffer must have sufficient headroom to contain a setup packet.

Definition at line 492 of file usb.c.

494  {
495  struct usb_device *usb = ep->usb;
496  struct usb_port *port = usb->port;
497  struct usb_setup_packet *packet;
498  size_t len = iob_len ( iobuf );
499  int rc;
500 
501  /* Sanity check */
502  assert ( iob_headroom ( iobuf ) >= sizeof ( *packet ) );
503 
504  /* Fail immediately if device has been unplugged */
505  if ( port->disconnected )
506  return -ENODEV;
507 
508  /* Reset endpoint if required */
509  if ( ( ! list_empty ( &ep->halted ) ) &&
510  ( ( rc = usb_endpoint_reset ( ep ) ) != 0 ) )
511  return rc;
512 
513  /* Zero input data buffer (if applicable) */
514  if ( request & USB_DIR_IN )
515  memset ( iobuf->data, 0, len );
516 
517  /* Construct setup packet */
518  packet = iob_push ( iobuf, sizeof ( *packet ) );
519  packet->request = cpu_to_le16 ( request );
520  packet->value = cpu_to_le16 ( value );
521  packet->index = cpu_to_le16 ( index );
522  packet->len = cpu_to_le16 ( len );
523 
524  /* Enqueue message transfer */
525  if ( ( rc = ep->host->message ( ep, iobuf ) ) != 0 ) {
526  DBGC ( usb, "USB %s %s could not enqueue message transfer: "
527  "%s\n", usb->name, usb_endpoint_name ( ep ),
528  strerror ( rc ) );
529  return rc;
530  }
531 
532  /* Increment fill level */
533  ep->fill++;
534 
535  return 0;
536 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_push(iobuf, len)
Definition: iobuf.h:89
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:835
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
A USB port.
Definition: usb.h:813
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:727
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint16_t index
Index parameter.
Definition: usb.h:89
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct list_head halted
List of halted endpoints.
Definition: usb.h:424
ring len
Length.
Definition: dwmac.h:231
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:98
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
#define ENODEV
No such device.
Definition: errno.h:510
static int usb_endpoint_reset(struct usb_endpoint *ep)
Reset USB endpoint.
Definition: usb.c:430
unsigned int fill
Buffer fill level.
Definition: usb.h:421
A USB setup data packet.
Definition: usb.h:83
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
uint16_t request
Request.
Definition: usb.h:85
static size_t iob_headroom(struct io_buffer *iobuf)
Calculate available space at start of an I/O buffer.
Definition: iobuf.h:170
void * data
Start of data.
Definition: iobuf.h:53
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
#define cpu_to_le16(value)
Definition: byteswap.h:107
uint16_t len
Length of data stage.
Definition: usb.h:91
struct usb_device * usb
USB device.
Definition: usb.h:406
int(* message)(struct usb_endpoint *ep, struct io_buffer *iobuf)
Enqueue message transfer.
Definition: usb.h:475
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:427
uint16_t value
Value parameter.
Definition: usb.h:87
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), cpu_to_le16, io_buffer::data, DBGC, ENODEV, usb_device::ep, usb_endpoint::fill, usb_endpoint::halted, usb_endpoint::host, index, usb_setup_packet::index, iob_headroom(), iob_len(), iob_push, usb_setup_packet::len, len, list_empty, memset(), usb_endpoint_host_operations::message, usb_device::name, port, usb_device::port, rc, request, usb_setup_packet::request, strerror(), usb_endpoint::usb, usb_port::usb, USB_DIR_IN, usb_endpoint_name(), usb_endpoint_reset(), value, and usb_setup_packet::value.

Referenced by usb_control().

◆ usb_stream()

int usb_stream ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  terminate 
)

Enqueue USB stream transfer.

Parameters
epUSB endpoint
iobufI/O buffer
terminateTerminate using a short packet
Return values
rcReturn status code

Definition at line 546 of file usb.c.

547  {
548  struct usb_device *usb = ep->usb;
549  struct usb_port *port = usb->port;
550  int zlp;
551  int rc;
552 
553  /* Fail immediately if device has been unplugged */
554  if ( port->disconnected )
555  return -ENODEV;
556 
557  /* Reset endpoint if required */
558  if ( ( ! list_empty ( &ep->halted ) ) &&
559  ( ( rc = usb_endpoint_reset ( ep ) ) != 0 ) )
560  return rc;
561 
562  /* Append a zero-length packet if necessary */
563  zlp = terminate;
564  if ( iob_len ( iobuf ) & ( ep->mtu - 1 ) )
565  zlp = 0;
566 
567  /* Enqueue stream transfer */
568  if ( ( rc = ep->host->stream ( ep, iobuf, zlp ) ) != 0 ) {
569  DBGC ( usb, "USB %s %s could not enqueue stream transfer: %s\n",
570  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
571  return rc;
572  }
573 
574  /* Increment fill level */
575  ep->fill++;
576 
577  return 0;
578 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:835
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
A USB port.
Definition: usb.h:813
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:727
struct list_head halted
List of halted endpoints.
Definition: usb.h:424
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
#define ENODEV
No such device.
Definition: errno.h:510
static int usb_endpoint_reset(struct usb_endpoint *ep)
Reset USB endpoint.
Definition: usb.c:430
unsigned int fill
Buffer fill level.
Definition: usb.h:421
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
size_t mtu
Maximum transfer size.
Definition: usb.h:412
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct usb_device * usb
USB device.
Definition: usb.h:406
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:427
int(* stream)(struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
Enqueue stream transfer.
Definition: usb.h:484

References DBGC, ENODEV, usb_device::ep, usb_endpoint::fill, usb_endpoint::halted, usb_endpoint::host, iob_len(), list_empty, usb_endpoint::mtu, usb_device::name, port, usb_device::port, rc, usb_endpoint_host_operations::stream, strerror(), usb_endpoint::usb, usb_port::usb, usb_endpoint_name(), and usb_endpoint_reset().

Referenced by acm_out_transmit(), axge_out_transmit(), dm96xx_out_transmit(), ecm_out_transmit(), efi_usb_sync_transfer(), imux_tx(), iphone_out_transmit(), ncm_out_transmit(), smsc75xx_out_transmit(), smsc95xx_out_transmit(), usb_refill_limit(), usbblk_out_command(), and usbblk_out_data().

◆ usb_complete_err()

void usb_complete_err ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)

Complete transfer (possibly with error)

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 587 of file usb.c.

588  {
589  struct usb_device *usb = ep->usb;
590 
591  /* Decrement fill level */
592  assert ( ep->fill > 0 );
593  ep->fill--;
594 
595  /* Schedule reset, if applicable */
596  if ( ( rc != 0 ) && ep->open ) {
597  DBGC ( usb, "USB %s %s completion failed: %s\n",
598  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
599  list_del ( &ep->halted );
601  }
602 
603  /* Report completion */
604  ep->driver->complete ( ep, iobuf, rc );
605 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void(* complete)(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer.
Definition: usb.h:496
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:419
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
struct list_head halted
List of halted endpoints.
Definition: usb.h:424
char name[32]
Name.
Definition: usb.h:725
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
unsigned int fill
Buffer fill level.
Definition: usb.h:421
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:221
static struct list_head usb_halted
List of halted endpoints.
Definition: usb.c:51
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct usb_device * usb
USB device.
Definition: usb.h:406
struct usb_endpoint_driver_operations * driver
Driver operations.
Definition: usb.h:431

References assert(), usb_endpoint_driver_operations::complete, DBGC, usb_endpoint::driver, usb_device::ep, usb_endpoint::fill, usb_endpoint::halted, list_add_tail, list_del, usb_device::name, usb_endpoint::open, rc, strerror(), usb_endpoint::usb, usb_endpoint_name(), and usb_halted.

Referenced by ehci_endpoint_close(), ehci_endpoint_poll(), uhci_endpoint_close(), uhci_endpoint_poll(), usb_complete(), usbio_bulk_in_poll(), usbio_bulk_out_poll(), usbio_control_poll(), usbio_endpoint_close(), xhci_endpoint_close(), and xhci_transfer().

◆ usb_prefill()

int usb_prefill ( struct usb_endpoint ep)

Prefill endpoint recycled buffer list.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 620 of file usb.c.

620  {
621  struct io_buffer *iobuf;
622  size_t reserve = ep->reserve;
623  size_t len = ( ep->len ? ep->len : ep->mtu );
624  unsigned int fill;
625  int rc;
626 
627  /* Sanity checks */
628  assert ( ep->fill == 0 );
629  assert ( ep->max > 0 );
630  assert ( list_empty ( &ep->recycled ) );
631 
632  /* Fill recycled buffer list */
633  for ( fill = 0 ; fill < ep->max ; fill++ ) {
634 
635  /* Allocate I/O buffer */
636  iobuf = alloc_iob ( reserve + len );
637  if ( ! iobuf ) {
638  rc = -ENOMEM;
639  goto err_alloc;
640  }
641  iob_reserve ( iobuf, reserve );
642 
643  /* Add to recycled buffer list */
644  list_add_tail ( &iobuf->list, &ep->recycled );
645  }
646 
647  return 0;
648 
649  err_alloc:
650  usb_flush ( ep );
651  return rc;
652 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:434
size_t len
Refill buffer payload length.
Definition: usb.h:438
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
#define ENOMEM
Not enough space.
Definition: errno.h:535
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
ring len
Length.
Definition: dwmac.h:231
size_t reserve
Refill buffer reserved header length.
Definition: usb.h:436
unsigned int fill
Buffer fill level.
Definition: usb.h:421
size_t mtu
Maximum transfer size.
Definition: usb.h:412
#define iob_reserve(iobuf, len)
Definition: iobuf.h:72
unsigned int max
Maximum fill level.
Definition: usb.h:440
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
void usb_flush(struct usb_endpoint *ep)
Discard endpoint recycled buffer list.
Definition: usb.c:720
static int fill
Definition: string.h:209
A persistent I/O buffer.
Definition: iobuf.h:38

References alloc_iob(), assert(), ENOMEM, fill, usb_endpoint::fill, iob_reserve, len, usb_endpoint::len, io_buffer::list, list_add_tail, list_empty, usb_endpoint::max, usb_endpoint::mtu, rc, usb_endpoint::recycled, usb_endpoint::reserve, and usb_flush().

Referenced by efi_usb_async_start(), and ncm_in_prefill().

◆ usb_refill_limit()

int usb_refill_limit ( struct usb_endpoint ep,
unsigned int  max 
)

Refill endpoint up to specified limit.

Parameters
epUSB endpoint
maxFill limit
Return values
rcReturn status code

Definition at line 661 of file usb.c.

661  {
662  struct io_buffer *iobuf;
663  size_t reserve = ep->reserve;
664  size_t len = ( ep->len ? ep->len : ep->mtu );
665  int rc;
666 
667  /* Sanity checks */
668  assert ( ep->open );
669  assert ( ep->max > 0 );
670 
671  /* Refill endpoint */
672  if ( max > ep->max )
673  max = ep->max;
674  while ( ep->fill < max ) {
675 
676  /* Get or allocate buffer */
677  if ( list_empty ( &ep->recycled ) ) {
678  /* Recycled buffer list is empty; allocate new buffer */
679  iobuf = alloc_iob ( reserve + len );
680  if ( ! iobuf )
681  return -ENOMEM;
682  iob_reserve ( iobuf, reserve );
683  } else {
684  /* Get buffer from recycled buffer list */
685  iobuf = list_first_entry ( &ep->recycled,
686  struct io_buffer, list );
687  assert ( iobuf != NULL );
688  list_del ( &iobuf->list );
689  }
690 
691  /* Reset buffer to maximum size */
692  assert ( iob_len ( iobuf ) <= len );
693  iob_put ( iobuf, ( len - iob_len ( iobuf ) ) );
694 
695  /* Enqueue buffer */
696  if ( ( rc = usb_stream ( ep, iobuf, 0 ) ) != 0 ) {
697  list_add ( &iobuf->list, &ep->recycled );
698  return rc;
699  }
700  }
701 
702  return 0;
703 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:125
#define max(x, y)
Definition: ath.h:41
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:70
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:434
size_t len
Refill buffer payload length.
Definition: usb.h:438
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:546
int open
Endpoint is open.
Definition: usb.h:419
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:334
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
#define ENOMEM
Not enough space.
Definition: errno.h:535
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
size_t reserve
Refill buffer reserved header length.
Definition: usb.h:436
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
unsigned int fill
Buffer fill level.
Definition: usb.h:421
size_t mtu
Maximum transfer size.
Definition: usb.h:412
#define iob_reserve(iobuf, len)
Definition: iobuf.h:72
unsigned int max
Maximum fill level.
Definition: usb.h:440
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

References alloc_iob(), assert(), ENOMEM, usb_endpoint::fill, iob_len(), iob_put, iob_reserve, len, usb_endpoint::len, io_buffer::list, list_add, list_del, list_empty, list_first_entry, max, usb_endpoint::max, usb_endpoint::mtu, NULL, usb_endpoint::open, rc, usb_endpoint::recycled, usb_endpoint::reserve, and usb_stream().

Referenced by usb_refill(), and usbblk_in_refill().

◆ usb_refill()

int usb_refill ( struct usb_endpoint ep)

Refill endpoint.

Parameters
epUSB endpoint
Return values
rcReturn status code

Definition at line 711 of file usb.c.

711  {
712  return usb_refill_limit ( ep, ep->max );
713 }
int usb_refill_limit(struct usb_endpoint *ep, unsigned int max)
Refill endpoint up to specified limit.
Definition: usb.c:661
unsigned int max
Maximum fill level.
Definition: usb.h:440

References usb_endpoint::max, and usb_refill_limit().

Referenced by efi_usb_timer(), hub_refill(), usbhid_open(), usbhid_refill(), usbkbd_iskey(), usbnet_open(), and usbnet_refill().

◆ usb_flush()

void usb_flush ( struct usb_endpoint ep)

Discard endpoint recycled buffer list.

Parameters
epUSB endpoint

Definition at line 720 of file usb.c.

720  {
721  struct io_buffer *iobuf;
722  struct io_buffer *tmp;
723 
724  /* Sanity checks */
725  assert ( ! ep->open );
726  assert ( ep->max > 0 );
727 
728  /* Free all I/O buffers */
729  list_for_each_entry_safe ( iobuf, tmp, &ep->recycled, list ) {
730  list_del ( &iobuf->list );
731  free_iob ( iobuf );
732  }
733 }
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:434
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
int open
Endpoint is open.
Definition: usb.h:419
unsigned long tmp
Definition: linux_pci.h:65
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:459
unsigned int max
Maximum fill level.
Definition: usb.h:440
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
A persistent I/O buffer.
Definition: iobuf.h:38

References assert(), free_iob(), io_buffer::list, list_del, list_for_each_entry_safe, usb_endpoint::max, usb_endpoint::open, usb_endpoint::recycled, and tmp.

Referenced by ncm_open(), usb_endpoint_close(), usb_endpoint_open(), and usb_prefill().

◆ usb_control_complete()

static void usb_control_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete USB control transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 755 of file usb.c.

756  {
757  struct usb_device *usb = ep->usb;
758  struct usb_control_pseudo_header *pshdr;
759 
760  /* Record completion status in buffer */
761  pshdr = iob_push ( iobuf, sizeof ( *pshdr ) );
762  pshdr->rc = rc;
763 
764  /* Add to list of completed I/O buffers */
765  list_add_tail ( &iobuf->list, &usb->complete );
766 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_push(iobuf, len)
Definition: iobuf.h:89
int rc
Completion status.
Definition: usb.c:745
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
A USB device.
Definition: usb.h:723
USB control transfer pseudo-header.
Definition: usb.c:743
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
struct list_head complete
Completed control transfers.
Definition: usb.h:750
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct usb_device * usb
USB device.
Definition: usb.h:406

References usb_device::complete, usb_device::ep, iob_push, io_buffer::list, list_add_tail, rc, usb_control_pseudo_header::rc, and usb_endpoint::usb.

◆ usb_control()

int usb_control ( struct usb_device usb,
unsigned int  request,
unsigned int  value,
unsigned int  index,
void *  data,
size_t  len 
)

Issue USB control transaction.

Parameters
usbUSB device
requestRequest
valueValue parameter
indexIndex parameter
dataData buffer (if any)
lenLength of data
Return values
rcReturn status code

Definition at line 784 of file usb.c.

786  {
787  struct usb_bus *bus = usb->port->hub->bus;
788  struct usb_endpoint *ep = &usb->control;
789  struct io_buffer *iobuf;
790  struct io_buffer *cmplt;
791  union {
792  struct usb_setup_packet setup;
793  struct usb_control_pseudo_header pshdr;
794  } *headroom;
795  struct usb_control_pseudo_header *pshdr;
796  unsigned int i;
797  int rc;
798 
799  /* Allocate I/O buffer */
800  iobuf = alloc_iob ( sizeof ( *headroom ) + len );
801  if ( ! iobuf ) {
802  rc = -ENOMEM;
803  goto err_alloc;
804  }
805  iob_reserve ( iobuf, sizeof ( *headroom ) );
806  iob_put ( iobuf, len );
807  if ( request & USB_DIR_IN ) {
808  memset ( data, 0, len );
809  } else {
810  memcpy ( iobuf->data, data, len );
811  }
812 
813  /* Enqueue message */
814  if ( ( rc = usb_message ( ep, request, value, index, iobuf ) ) != 0 )
815  goto err_message;
816 
817  /* Wait for completion */
818  for ( i = 0 ; i < USB_CONTROL_MAX_WAIT_MS ; i++ ) {
819 
820  /* Poll bus */
821  usb_poll ( bus );
822 
823  /* Check for completion */
824  while ( ( cmplt = list_first_entry ( &usb->complete,
825  struct io_buffer,
826  list ) ) ) {
827 
828  /* Remove from completion list */
829  list_del ( &cmplt->list );
830 
831  /* Extract and strip completion status */
832  pshdr = cmplt->data;
833  iob_pull ( cmplt, sizeof ( *pshdr ) );
834  rc = pshdr->rc;
835 
836  /* Discard stale completions */
837  if ( cmplt != iobuf ) {
838  DBGC ( usb, "USB %s stale control completion: "
839  "%s\n", usb->name, strerror ( rc ) );
840  DBGC_HDA ( usb, 0, cmplt->data,
841  iob_len ( cmplt ) );
842  free_iob ( cmplt );
843  continue;
844  }
845 
846  /* Fail immediately if completion was in error */
847  if ( rc != 0 ) {
848  DBGC ( usb, "USB %s control %04x:%04x:%04x "
849  "failed: %s\n", usb->name, request,
850  value, index, strerror ( rc ) );
851  free_iob ( cmplt );
852  usb_endpoint_reset ( ep );
853  return rc;
854  }
855 
856  /* Copy completion to data buffer, if applicable */
857  assert ( iob_len ( cmplt ) <= len );
858  if ( request & USB_DIR_IN )
859  memcpy ( data, cmplt->data, iob_len ( cmplt ) );
860  free_iob ( cmplt );
861  return 0;
862  }
863 
864  /* Delay */
865  mdelay ( 1 );
866  }
867 
868  DBGC ( usb, "USB %s timed out waiting for control %04x:%04x:%04x\n",
869  usb->name, request, value, index );
870  return -ETIMEDOUT;
871 
872  err_message:
873  free_iob ( iobuf );
874  err_alloc:
875  return rc;
876 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:107
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:125
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
int rc
Completion status.
Definition: usb.c:745
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:334
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
#define ENOMEM
Not enough space.
Definition: errno.h:535
A USB endpoint.
Definition: usb.h:404
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int usb_message(struct usb_endpoint *ep, unsigned int request, unsigned int value, unsigned int index, struct io_buffer *iobuf)
Enqueue USB message transfer.
Definition: usb.c:492
struct usb_port * port
USB port.
Definition: usb.h:727
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define DBGC_HDA(...)
Definition: compiler.h:506
ring len
Length.
Definition: dwmac.h:231
#define USB_CONTROL_MAX_WAIT_MS
Maximum time to wait for a control transaction to complete.
Definition: usb.h:1342
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:98
char name[32]
Name.
Definition: usb.h:725
struct usb_endpoint control
Control endpoint.
Definition: usb.h:748
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1072
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
static int usb_endpoint_reset(struct usb_endpoint *ep)
Reset USB endpoint.
Definition: usb.c:430
USB control transfer pseudo-header.
Definition: usb.c:743
A USB setup data packet.
Definition: usb.h:83
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
#define iob_reserve(iobuf, len)
Definition: iobuf.h:72
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
struct list_head complete
Completed control transfers.
Definition: usb.h:750
void * data
Start of data.
Definition: iobuf.h:53
struct usb_hub * hub
USB hub.
Definition: usb.h:815
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct usb_device * usb
USB device.
Definition: usb.h:406
struct usb_bus * bus
USB bus.
Definition: usb.h:845
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:670
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:38

References alloc_iob(), assert(), bus, usb_hub::bus, usb_device::complete, usb_device::control, data, io_buffer::data, DBGC, DBGC_HDA, ENOMEM, ETIMEDOUT, free_iob(), usb_port::hub, index, iob_len(), iob_pull, iob_put, iob_reserve, len, io_buffer::list, list_del, list_first_entry, mdelay(), memcpy(), memset(), usb_device::name, usb_device::port, rc, usb_control_pseudo_header::rc, request, strerror(), usb_endpoint::usb, USB_CONTROL_MAX_WAIT_MS, USB_DIR_IN, usb_endpoint_reset(), usb_message(), usb_poll(), and value.

Referenced by axge_read_register(), axge_write_register(), cdc_get_encapsulated_response(), cdc_send_encapsulated_command(), dm96xx_read_registers(), dm96xx_write_register(), dm96xx_write_registers(), ecm_open(), efi_usb_control_transfer(), iphone_check_link(), iphone_probe(), ncm_open(), ncm_probe(), smscusb_raw_readl(), smscusb_raw_writel(), usb_clear_feature(), usb_get_descriptor(), usb_get_status(), usb_hub_clear_tt_buffer(), usb_hub_set_hub_depth(), usb_set_address(), usb_set_configuration(), usb_set_feature(), usb_set_interface(), usbblk_open(), usbhid_set_idle(), usbhid_set_protocol(), and usbhid_set_report().

◆ usb_get_default_language()

static unsigned int usb_get_default_language ( struct usb_device usb)
static

Get default language ID.

Parameters
usbUSB device
Return values
languageLanguage ID

Definition at line 884 of file usb.c.

884  {
885  struct {
887  uint16_t language[1];
888  } __attribute__ (( packed )) desc;
889  unsigned int language;
890  int rc;
891 
892  /* Get descriptor */
893  if ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, 0, 0,
894  &desc.header, sizeof ( desc ) ) ) !=0){
895  DBGC ( usb, "USB %s has no default language: %s\n",
896  usb->name, strerror ( rc ) );
897  return USB_LANG_ENGLISH;
898  }
899 
900  /* Use first language ID */
901  language = le16_to_cpu ( desc.language[0] );
902  DBGC2 ( usb, "USB %s default language %#04x\n", usb->name, language );
903  return language;
904 }
#define __attribute__(x)
Definition: compiler.h:10
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
#define USB_STRING_DESCRIPTOR
A USB string descriptor.
Definition: usb.h:239
#define DBGC(...)
Definition: compiler.h:505
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
char name[32]
Name.
Definition: usb.h:725
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define USB_LANG_ENGLISH
Language ID for English.
Definition: usb.h:242
#define le16_to_cpu(value)
Definition: byteswap.h:113
A USB descriptor header.
Definition: usb.h:173
#define DBGC2(...)
Definition: compiler.h:522
struct ena_llq_option header
Header locations.
Definition: ena.h:16
static int usb_get_descriptor(struct usb_device *usb, unsigned int type, unsigned int desc, unsigned int index, unsigned int language, struct usb_descriptor_header *data, size_t len)
Get USB descriptor.
Definition: usb.h:1177

References __attribute__, DBGC, DBGC2, desc, header, le16_to_cpu, usb_device::name, rc, strerror(), usb_get_descriptor(), USB_LANG_ENGLISH, and USB_STRING_DESCRIPTOR.

Referenced by usb_get_string_descriptor().

◆ usb_get_string_descriptor()

int usb_get_string_descriptor ( struct usb_device usb,
unsigned int  index,
unsigned int  language,
char *  buf,
size_t  len 
)

Get USB string descriptor.

Parameters
usbUSB device
indexString index
languageLanguage ID, or 0 to use default
bufData buffer
lenLength of buffer
Return values
lenString length (excluding NUL), or negative error

Definition at line 916 of file usb.c.

917  {
918  struct {
920  uint16_t character[len];
921  } __attribute__ (( packed )) *desc;
922  unsigned int actual;
923  unsigned int i;
924  int rc;
925 
926  /* Use default language ID, if applicable */
927  if ( ( language == 0 ) && ( index != 0 ) ) {
928  if ( ! usb->language )
929  usb->language = usb_get_default_language ( usb );
930  language = usb->language;
931  }
932 
933  /* Allocate buffer for string */
934  desc = malloc ( sizeof ( *desc ) );
935  if ( ! desc ) {
936  rc = -ENOMEM;
937  goto err_alloc;
938  }
939 
940  /* Get descriptor */
941  if ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, index,
942  language, &desc->header,
943  sizeof ( *desc ) ) ) != 0 )
944  goto err_get_descriptor;
945 
946  /* Calculate string length */
947  if ( desc->header.len < sizeof ( desc->header ) ) {
948  rc = -EINVAL;
949  goto err_len;
950  }
951  actual = ( ( desc->header.len - sizeof ( desc->header ) ) /
952  sizeof ( desc->character[0] ) );
953 
954  /* Copy to buffer */
955  memset ( buf, 0, len );
956  for ( i = 0 ; ( ( i < actual ) && ( i < len ) ) ; i++ )
957  buf[i] = le16_to_cpu ( desc->character[i] );
958 
959  /* Free buffer */
960  free ( desc );
961 
962  return actual;
963 
964  err_len:
965  err_get_descriptor:
966  free ( desc );
967  err_alloc:
968  return rc;
969 }
#define __attribute__(x)
Definition: compiler.h:10
#define EINVAL
Invalid argument.
Definition: errno.h:429
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
static unsigned int usb_get_default_language(struct usb_device *usb)
Get default language ID.
Definition: usb.c:884
uint8_t len
Length of descriptor.
Definition: usb.h:175
#define USB_STRING_DESCRIPTOR
A USB string descriptor.
Definition: usb.h:239
long index
Definition: bigint.h:65
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
#define ENOMEM
Not enough space.
Definition: errno.h:535
ring len
Length.
Definition: dwmac.h:231
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
#define le16_to_cpu(value)
Definition: byteswap.h:113
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
A USB descriptor header.
Definition: usb.h:173
unsigned int language
Default language ID (if known)
Definition: usb.h:753
struct ena_llq_option header
Header locations.
Definition: ena.h:16
static int usb_get_descriptor(struct usb_device *usb, unsigned int type, unsigned int desc, unsigned int index, unsigned int language, struct usb_descriptor_header *data, size_t len)
Get USB descriptor.
Definition: usb.h:1177
void * memset(void *dest, int character, size_t len) __nonnull

References __attribute__, desc, EINVAL, ENOMEM, free, header, index, usb_device::language, le16_to_cpu, usb_descriptor_header::len, len, malloc(), memset(), rc, usb_get_default_language(), usb_get_descriptor(), and USB_STRING_DESCRIPTOR.

Referenced by ecm_fetch_mac(), and usb_settings_fetch().

◆ usb_config_descriptor()

static int usb_config_descriptor ( struct usb_device usb,
unsigned int  index,
struct usb_configuration_descriptor **  config 
)
static

Get USB configuration descriptor.

Parameters
usbUSB device
indexConfiguration index
Return values
configConfiguration descriptor
rcReturn status code

The configuration descriptor is dynamically allocated and must eventually be freed by the caller.

Definition at line 990 of file usb.c.

991  {
992  struct usb_configuration_descriptor partial;
993  size_t len;
994  int rc;
995 
996  /* Read first part of configuration descriptor to get size */
997  if ( ( rc = usb_get_config_descriptor ( usb, index, &partial,
998  sizeof ( partial ) ) ) != 0 ) {
999  DBGC ( usb, "USB %s could not get configuration descriptor %d: "
1000  "%s\n", usb->name, index, strerror ( rc ) );
1001  goto err_get_partial;
1002  }
1003  len = le16_to_cpu ( partial.len );
1004  if ( len < sizeof ( partial ) ) {
1005  DBGC ( usb, "USB %s underlength configuraton descriptor %d\n",
1006  usb->name, index );
1007  rc = -EINVAL;
1008  goto err_partial_len;
1009  }
1010 
1011  /* Allocate buffer for whole configuration descriptor */
1012  *config = malloc ( len );
1013  if ( ! *config ) {
1014  rc = -ENOMEM;
1015  goto err_alloc_config;
1016  }
1017 
1018  /* Read whole configuration descriptor */
1019  if ( ( rc = usb_get_config_descriptor ( usb, index, *config,
1020  len ) ) != 0 ) {
1021  DBGC ( usb, "USB %s could not get configuration descriptor %d: "
1022  "%s\n", usb->name, index, strerror ( rc ) );
1023  goto err_get_config_descriptor;
1024  }
1025  if ( (*config)->len != partial.len ) {
1026  DBGC ( usb, "USB %s bad configuration descriptor %d length\n",
1027  usb->name, index );
1028  rc = -EINVAL;
1029  goto err_config_len;
1030  }
1031 
1032  return 0;
1033 
1034  err_config_len:
1035  err_get_config_descriptor:
1036  free ( *config );
1037  err_alloc_config:
1038  err_partial_len:
1039  err_get_partial:
1040  return rc;
1041 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int usb_get_config_descriptor(struct usb_device *usb, unsigned int index, struct usb_configuration_descriptor *data, size_t len)
Get USB configuration descriptor.
Definition: usb.h:1226
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
#define ENOMEM
Not enough space.
Definition: errno.h:535
ring len
Length.
Definition: dwmac.h:231
char name[32]
Name.
Definition: usb.h:725
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
#define le16_to_cpu(value)
Definition: byteswap.h:113
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
A USB configuration descriptor.
Definition: usb.h:210
uint8_t config
Configuration value.
Definition: usb.h:218

References usb_configuration_descriptor::config, DBGC, EINVAL, ENOMEM, free, index, le16_to_cpu, usb_configuration_descriptor::len, len, malloc(), usb_device::name, rc, strerror(), and usb_get_config_descriptor().

Referenced by usb_autoconfigure().

◆ usb_describe()

static int usb_describe ( struct usb_device usb,
struct usb_configuration_descriptor config,
unsigned int  first,
uint8_t interfaces,
struct usb_function_descriptor desc 
)
static

Describe USB function.

Parameters
usbUSB device
configConfiguration descriptor
firstFirst interface number
interfacesInterface list to fill in
descFunction descriptor to fill in
Return values
rcReturn status code

Definition at line 1053 of file usb.c.

1056  {
1057  struct usb_interface_association_descriptor *association;
1059  struct cdc_union_descriptor *cdc_union;
1060  unsigned int i;
1061 
1062  /* Fill in vendor and product ID */
1063  memset ( desc, 0, sizeof ( *desc ) );
1064  desc->vendor = le16_to_cpu ( usb->device.vendor );
1065  desc->product = le16_to_cpu ( usb->device.product );
1066 
1067  /* First, look for an interface association descriptor */
1068  association = usb_interface_association_descriptor ( config, first );
1069  if ( association ) {
1070 
1071  /* Sanity check */
1072  assert ( association->first == first );
1073  if ( ( first + association->count ) > config->interfaces ) {
1074  DBGC ( usb, "USB %s has invalid association [%d-%d)\n",
1075  usb->name, first, ( first + association->count));
1076  return -ERANGE;
1077  }
1078 
1079  /* Describe function */
1080  memcpy ( &desc->class.class, &association->class,
1081  sizeof ( desc->class.class ) );
1082  desc->count = association->count;
1083  for ( i = 0 ; i < association->count ; i++ )
1084  interfaces[i] = ( first + i );
1085  return 0;
1086  }
1087 
1088  /* Next, look for an interface descriptor */
1089  interface = usb_interface_descriptor ( config, first, 0 );
1090  if ( ! interface ) {
1091  DBGC ( usb, "USB %s has no descriptor for interface %d\n",
1092  usb->name, first );
1093  return -ENOENT;
1094  }
1095 
1096  /* Describe function */
1097  memcpy ( &desc->class.class, &interface->class,
1098  sizeof ( desc->class.class ) );
1099  desc->count = 1;
1100  interfaces[0] = first;
1101 
1102  /* Look for a CDC union descriptor, if applicable */
1103  if ( ( desc->class.class.class == USB_CLASS_CDC ) &&
1104  ( cdc_union = cdc_union_descriptor ( config, interface ) ) ) {
1105 
1106  /* Determine interface count */
1107  desc->count = ( ( cdc_union->header.len -
1108  offsetof ( typeof ( *cdc_union ),
1109  interface[0] ) ) /
1110  sizeof ( cdc_union->interface[0] ) );
1111  if ( desc->count > config->interfaces ) {
1112  DBGC ( usb, "USB %s has invalid union functional "
1113  "descriptor with %d interfaces\n",
1114  usb->name, desc->count );
1115  return -ERANGE;
1116  }
1117 
1118  /* Describe function */
1119  for ( i = 0 ; i < desc->count ; i++ ) {
1120  if ( cdc_union->interface[i] >= config->interfaces ) {
1121  DBGC ( usb, "USB %s has invalid union "
1122  "functional descriptor covering "
1123  "interface %d\n", usb->name,
1124  cdc_union->interface[i] );
1125  return -ERANGE;
1126  }
1127  interfaces[i] = cdc_union->interface[i];
1128  }
1129 
1130  return 0;
1131  }
1132 
1133  return 0;
1134 }
uint8_t len
Length of descriptor.
Definition: usb.h:175
uint16_t vendor
Vendor ID.
Definition: usb.h:191
A USB interface association descriptor.
Definition: usb.h:329
uint32_t first
First block in range.
Definition: pccrr.h:15
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:515
uint8_t interfaces
Number of interfaces.
Definition: usb.h:216
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:25
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
uint16_t product
Product ID.
Definition: usb.h:193
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A USB interface descriptor.
Definition: usb.h:245
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:125
struct usb_descriptor_header header
Descriptor header.
Definition: cdc.h:31
Union functional descriptor.
Definition: cdc.h:29
char name[32]
Name.
Definition: usb.h:725
#define ERANGE
Result too large.
Definition: errno.h:640
static const char * interfaces[2]
Definition: smc9000.c:52
struct usb_device_descriptor device
Device descriptor.
Definition: usb.h:735
#define le16_to_cpu(value)
Definition: byteswap.h:113
uint8_t count
Interface count.
Definition: usb.h:335
#define USB_CLASS_CDC
Class code for communications devices.
Definition: cdc.h:16
uint8_t first
First interface number.
Definition: usb.h:333
struct usb_class class
Association class.
Definition: usb.h:337
static struct usb_interface_association_descriptor * usb_interface_association_descriptor(struct usb_configuration_descriptor *config, unsigned int first)
Locate USB interface association descriptor.
Definition: usb.c:120
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:48
uint8_t interface
Interface number.
Definition: usb.h:249
uint8_t interface[1]
Interfaces (variable-length)
Definition: cdc.h:35
void * memset(void *dest, int character, size_t len) __nonnull

References assert(), usb_interface_association_descriptor::class, usb_interface_association_descriptor::count, DBGC, desc, usb_device::device, ENOENT, ERANGE, first, usb_interface_association_descriptor::first, cdc_union_descriptor::header, cdc_union_descriptor::interface, usb_interface_descriptor::interface, interfaces, usb_configuration_descriptor::interfaces, le16_to_cpu, usb_descriptor_header::len, memcpy(), memset(), usb_device::name, offsetof, usb_device_descriptor::product, typeof(), USB_CLASS_CDC, usb_interface_association_descriptor(), and usb_device_descriptor::vendor.

Referenced by usb_probe_all(), and usb_score().

◆ usb_used()

static int usb_used ( struct usb_device usb,
unsigned int  count,
uint8_t interface,
uint8_t used 
)
static

Update list of used interface.

Parameters
usbUSB device
countNumber of interfaces
interfaceList of interfaces
usedList of already-used interfaces
Return values
rcReturn status code

Definition at line 1145 of file usb.c.

1146  {
1147  unsigned int i;
1148 
1149  for ( i = 0 ; i < count ; i++ ) {
1150  if ( used[interface[i]] ) {
1151  DBGC ( usb, "USB %s interface %d already in use\n",
1152  usb->name, interface[i] );
1153  return -EINVAL;
1154  }
1155  used[interface[i]] = 1;
1156  }
1157  return 0;
1158 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
#define DBGC(...)
Definition: compiler.h:505
An object interface.
Definition: interface.h:125
static unsigned int count
Number of entries.
Definition: dwmac.h:225
char name[32]
Name.
Definition: usb.h:725

References count, DBGC, EINVAL, and usb_device::name.

Referenced by usb_probe_all(), and usb_score().

◆ usb_find_driver()

struct usb_driver* usb_find_driver ( struct usb_function_descriptor desc,
struct usb_device_id **  id 
)

Find USB device driver.

Parameters
descFunction descriptor
Return values
idUSB device ID, or NULL
driverUSB device driver, or NULL

Definition at line 1167 of file usb.c.

1168  {
1169  struct usb_driver *driver;
1170  unsigned int i;
1171 
1172  /* Look for a matching driver */
1173  for_each_table_entry ( driver, USB_DRIVERS ) {
1174  for ( i = 0 ; i < driver->id_count ; i++ ) {
1175 
1176  /* Ignore non-matching driver class */
1177  if ( ( driver->class.class.scalar ^ desc->class.scalar )
1178  & driver->class.mask.scalar )
1179  continue;
1180 
1181  /* Look for a matching ID */
1182  *id = &driver->ids[i];
1183  if ( ( ( (*id)->vendor == desc->vendor ) ||
1184  ( (*id)->vendor == USB_ANY_ID ) ) &&
1185  ( ( (*id)->product == desc->product ) ||
1186  ( (*id)->product == USB_ANY_ID ) ) )
1187  return driver;
1188  }
1189  }
1190 
1191  /* Not found */
1192  *id = NULL;
1193  return NULL;
1194 }
A USB driver.
Definition: usb.h:1407
union usb_class_descriptor mask
Class mask.
Definition: usb.h:1380
union usb_class_descriptor class
Class.
Definition: usb.h:1378
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
struct usb_class_id class
Class ID.
Definition: usb.h:1413
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:386
uint32_t scalar
Scalar value.
Definition: usb.h:648
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1373
unsigned int id_count
Number of entries in ID table.
Definition: usb.h:1411
#define USB_DRIVERS
USB driver table.
Definition: usb.h:1438
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct usb_device_id * ids
USB ID table.
Definition: usb.h:1409

References usb_class_id::class, usb_driver::class, desc, for_each_table_entry, usb_driver::id_count, usb_driver::ids, usb_class_id::mask, NULL, usb_class_descriptor::scalar, USB_ANY_ID, and USB_DRIVERS.

Referenced by usb_probe(), usb_score(), and usbio_supported().

◆ usb_score()

static int usb_score ( struct usb_device usb,
struct usb_configuration_descriptor config 
)
static

Get USB device configuration score.

Parameters
usbUSB device
configConfiguration descriptor
Return values
scoreDevice configuration score, or negative error

Definition at line 1203 of file usb.c.

1204  {
1205  uint8_t used[config->interfaces];
1206  uint8_t interface[config->interfaces];
1208  struct usb_driver *driver;
1209  struct usb_device_id *id;
1210  unsigned int first;
1211  unsigned int score = 0;
1212  int rc;
1213 
1214  /* Identify each function in turn */
1215  memset ( used, 0, sizeof ( used ) );
1216  for ( first = 0 ; first < config->interfaces ; first++ ) {
1217 
1218  /* Skip interfaces already used */
1219  if ( used[first] )
1220  continue;
1221 
1222  /* Describe function */
1223  if ( ( rc = usb_describe ( usb, config, first, interface,
1224  &desc ) ) != 0 )
1225  return rc;
1226 
1227  /* Update used interfaces */
1228  if ( ( rc = usb_used ( usb, desc.count, interface,
1229  used ) ) != 0 )
1230  return rc;
1231 
1232  /* Look for a driver for this function */
1233  driver = usb_find_driver ( &desc, &id );
1234  if ( driver )
1235  score += driver->score;
1236  }
1237 
1238  return score;
1239 }
A USB driver.
Definition: usb.h:1407
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A USB device ID.
Definition: usb.h:1361
uint32_t first
First block in range.
Definition: pccrr.h:15
uint8_t interfaces
Number of interfaces.
Definition: usb.h:216
static int usb_used(struct usb_device *usb, unsigned int count, uint8_t *interface, uint8_t *used)
Update list of used interface.
Definition: usb.c:1145
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
A USB function descriptor.
Definition: usb.h:657
struct usb_driver * usb_find_driver(struct usb_function_descriptor *desc, struct usb_device_id **id)
Find USB device driver.
Definition: usb.c:1167
An object interface.
Definition: interface.h:125
uint8_t id
Request identifier.
Definition: ena.h:12
unsigned int score
Driver score.
Definition: usb.h:1419
unsigned char uint8_t
Definition: stdint.h:10
static int usb_describe(struct usb_device *usb, struct usb_configuration_descriptor *config, unsigned int first, uint8_t *interfaces, struct usb_function_descriptor *desc)
Describe USB function.
Definition: usb.c:1053
void * memset(void *dest, int character, size_t len) __nonnull

References desc, first, id, usb_configuration_descriptor::interfaces, memset(), rc, usb_driver::score, usb_describe(), usb_find_driver(), and usb_used().

Referenced by usb_autoconfigure().

◆ usb_probe()

static int usb_probe ( struct usb_function func,
struct usb_configuration_descriptor config 
)
static

Probe USB device driver.

Parameters
funcUSB function
configConfiguration descriptor
Return values
rcReturn status code

Definition at line 1248 of file usb.c.

1249  {
1250  struct usb_device *usb = func->usb;
1251  struct usb_driver *driver;
1252  struct usb_device_id *id;
1253  int rc;
1254 
1255  /* Identify driver */
1256  driver = usb_find_driver ( &func->desc, &id );
1257  if ( ! driver ) {
1258  DBGC ( usb, "USB %s %04x:%04x class %d:%d:%d has no driver\n",
1259  func->name, func->desc.vendor, func->desc.product,
1260  func->desc.class.class.class,
1261  func->desc.class.class.subclass,
1262  func->desc.class.class.protocol );
1263  return -ENOENT;
1264  }
1265 
1266  /* Record driver */
1267  func->driver = driver;
1268  func->id = id;
1269  func->dev.driver_name = id->name;
1270 
1271  /* Probe driver */
1272  if ( ( rc = driver->probe ( func, config ) ) != 0 ) {
1273  DBGC ( usb, "USB %s failed to probe driver %s: %s\n",
1274  func->name, id->name, strerror ( rc ) );
1275  return rc;
1276  }
1277 
1278  return 0;
1279 }
A USB driver.
Definition: usb.h:1407
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A USB device ID.
Definition: usb.h:1361
uint8_t class
Class code.
Definition: usb.h:162
const char * name
Name.
Definition: usb.h:676
#define DBGC(...)
Definition: compiler.h:505
uint16_t vendor
Vendor ID.
Definition: usb.h:659
struct usb_driver * driver
Driver.
Definition: usb.h:687
#define ENOENT
No such file or directory.
Definition: errno.h:515
union usb_class_descriptor class
Class.
Definition: usb.h:663
int(* probe)(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: usb.h:1427
struct usb_device_id * id
Driver device ID.
Definition: usb.h:691
uint16_t product
Product ID.
Definition: usb.h:661
struct usb_driver * usb_find_driver(struct usb_function_descriptor *desc, struct usb_device_id **id)
Find USB device driver.
Definition: usb.c:1167
const char * driver_name
Driver name.
Definition: device.h:81
uint8_t id
Request identifier.
Definition: ena.h:12
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
struct usb_device * usb
USB device.
Definition: usb.h:678
uint8_t protocol
Protocol code.
Definition: usb.h:166
uint8_t subclass
Subclass code.
Definition: usb.h:164
struct usb_function_descriptor desc
Function descriptor.
Definition: usb.h:680
struct device dev
Generic device.
Definition: usb.h:682
struct usb_class class
Class.
Definition: usb.h:646

References usb_class::class, usb_class_descriptor::class, usb_function_descriptor::class, DBGC, usb_function::desc, usb_function::dev, usb_function::driver, device::driver_name, ENOENT, id, usb_function::id, usb_function::name, usb_driver::probe, usb_function_descriptor::product, usb_class::protocol, rc, strerror(), usb_class::subclass, usb_function::usb, usb_find_driver(), and usb_function_descriptor::vendor.

Referenced by usb_probe_all().

◆ usb_remove()

static void usb_remove ( struct usb_function func)
static

Remove USB device driver.

Parameters
funcUSB function

Definition at line 1286 of file usb.c.

1286  {
1287 
1288  /* Remove driver */
1289  func->driver->remove ( func );
1290 }
struct usb_driver * driver
Driver.
Definition: usb.h:687
void(* remove)(struct usb_function *func)
Remove device.
Definition: usb.h:1434

References usb_function::driver, and usb_driver::remove.

Referenced by usb_probe_all(), and usb_remove_all().

◆ usb_probe_all()

static void usb_probe_all ( struct usb_device usb,
struct usb_configuration_descriptor config 
)
static

Probe all USB device drivers.

Parameters
usbUSB device
configConfiguration descriptor

Definition at line 1299 of file usb.c.

1300  {
1301  struct usb_bus *bus = usb->port->hub->bus;
1302  struct usb_function *func;
1303  uint8_t used[config->interfaces];
1304  unsigned int first;
1305  unsigned int i;
1306  int rc;
1307 
1308  /* Identify each function in turn */
1309  memset ( used, 0, sizeof ( used ) );
1310  for ( first = 0 ; first < config->interfaces ; first++ ) {
1311 
1312  /* Skip interfaces already used */
1313  if ( used[first] )
1314  continue;
1315 
1316  /* Allocate and initialise structure */
1317  func = zalloc ( sizeof ( *func ) +
1318  ( config->interfaces *
1319  sizeof ( func->interface[0] ) ) );
1320  if ( ! func )
1321  goto err_alloc;
1322  func->name = func->dev.name;
1323  func->usb = usb;
1324  func->dev.desc.bus_type = BUS_TYPE_USB;
1325  func->dev.desc.location =
1326  USB_BUSDEV ( bus->address, usb->address );
1327  func->dev.desc.vendor = le16_to_cpu ( usb->device.vendor );
1328  func->dev.desc.device = le16_to_cpu ( usb->device.product );
1329  snprintf ( func->dev.name, sizeof ( func->dev.name ),
1330  "%s-%d.%d", usb->name, config->config, first );
1331  INIT_LIST_HEAD ( &func->dev.children );
1332  func->dev.parent = bus->dev;
1333  list_add_tail ( &func->list, &usb->functions );
1334 
1335  /* Identify function */
1336  if ( ( rc = usb_describe ( usb, config, first, func->interface,
1337  &func->desc ) ) != 0 )
1338  goto err_describe;
1339  assert ( func->desc.count <= config->interfaces );
1340 
1341  /* Mark interfaces as used */
1342  if ( ( rc = usb_used ( usb, func->desc.count, func->interface,
1343  used ) ) != 0 )
1344  goto err_used;
1345 
1346  /* Probe device driver */
1347  if ( ( rc = usb_probe ( func, config ) ) != 0 )
1348  goto err_probe;
1349  DBGC ( usb, "USB %s %04x:%04x class %d:%d:%d interfaces ",
1350  func->name, func->desc.vendor, func->desc.product,
1351  func->desc.class.class.class,
1352  func->desc.class.class.subclass,
1353  func->desc.class.class.protocol );
1354  for ( i = 0 ; i < func->desc.count ; i++ )
1355  DBGC ( usb, "%s%d", ( i ? "," : "" ),
1356  func->interface[i] );
1357  DBGC ( usb, " using driver %s\n", func->dev.driver_name );
1358 
1359  /* Add to device hierarchy */
1360  list_add_tail ( &func->dev.siblings, &bus->dev->children );
1361 
1362  continue;
1363 
1364  list_del ( &func->dev.siblings );
1365  usb_remove ( func );
1366  err_probe:
1367  err_used:
1368  err_describe:
1369  list_del ( &func->list );
1370  free ( func );
1371  err_alloc:
1372  /* Continue registering other functions */
1373  continue;
1374  }
1375 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t class
Class code.
Definition: usb.h:162
uint8_t interface[0]
List of interface numbers.
Definition: usb.h:697
const char * name
Name.
Definition: usb.h:676
unsigned int count
Number of interfaces.
Definition: usb.h:665
uint16_t vendor
Vendor ID.
Definition: usb.h:191
uint32_t first
First block in range.
Definition: pccrr.h:15
#define DBGC(...)
Definition: compiler.h:505
uint16_t vendor
Vendor ID.
Definition: usb.h:659
char name[40]
Name.
Definition: device.h:79
uint8_t interfaces
Number of interfaces.
Definition: usb.h:216
static int usb_used(struct usb_device *usb, unsigned int count, uint8_t *interface, uint8_t *used)
Update list of used interface.
Definition: usb.c:1145
union usb_class_descriptor class
Class.
Definition: usb.h:663
unsigned int vendor
Vendor ID.
Definition: device.h:32
struct device * parent
Bus device.
Definition: device.h:89
unsigned int address
Device address, if assigned.
Definition: usb.h:733
#define USB_BUSDEV(bus, dev)
Define a USB bus:device address.
Definition: usb.h:64
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
uint16_t product
Product ID.
Definition: usb.h:661
uint16_t product
Product ID.
Definition: usb.h:193
struct usb_port * port
USB port.
Definition: usb.h:727
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
char name[32]
Name.
Definition: usb.h:725
const char * driver_name
Driver name.
Definition: device.h:81
unsigned int location
Location.
Definition: device.h:30
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
unsigned char uint8_t
Definition: stdint.h:10
static void usb_remove(struct usb_function *func)
Remove USB device driver.
Definition: usb.c:1286
struct usb_device_descriptor device
Device descriptor.
Definition: usb.h:735
struct usb_device * usb
USB device.
Definition: usb.h:678
#define le16_to_cpu(value)
Definition: byteswap.h:113
uint8_t protocol
Protocol code.
Definition: usb.h:166
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
uint8_t subclass
Subclass code.
Definition: usb.h:164
unsigned int bus_type
Bus type.
Definition: device.h:25
uint8_t config
Configuration value.
Definition: usb.h:218
unsigned int device
Device ID.
Definition: device.h:34
struct list_head children
Devices attached to this device.
Definition: device.h:87
struct usb_hub * hub
USB hub.
Definition: usb.h:815
struct device_description desc
Device description.
Definition: device.h:83
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383
struct usb_function_descriptor desc
Function descriptor.
Definition: usb.h:680
struct device dev
Generic device.
Definition: usb.h:682
A USB function.
Definition: usb.h:674
#define BUS_TYPE_USB
USB bus type.
Definition: device.h:71
struct usb_bus * bus
USB bus.
Definition: usb.h:845
struct list_head functions
List of functions.
Definition: usb.h:737
struct list_head list
List of functions within this USB device.
Definition: usb.h:684
A USB bus.
Definition: usb.h:966
static int usb_describe(struct usb_device *usb, struct usb_configuration_descriptor *config, unsigned int first, uint8_t *interfaces, struct usb_function_descriptor *desc)
Describe USB function.
Definition: usb.c:1053
uint8_t bus
Bus.
Definition: edd.h:15
struct usb_class class
Class.
Definition: usb.h:646
static int usb_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe USB device driver.
Definition: usb.c:1248
void * memset(void *dest, int character, size_t len) __nonnull

References usb_device::address, assert(), bus, usb_hub::bus, device_description::bus_type, BUS_TYPE_USB, device::children, usb_class::class, usb_class_descriptor::class, usb_function_descriptor::class, usb_configuration_descriptor::config, usb_function_descriptor::count, DBGC, device::desc, usb_function::desc, usb_function::dev, device_description::device, usb_device::device, device::driver_name, first, free, usb_device::functions, usb_port::hub, INIT_LIST_HEAD, usb_function::interface, usb_configuration_descriptor::interfaces, le16_to_cpu, usb_function::list, list_add_tail, list_del, device_description::location, memset(), device::name, usb_function::name, usb_device::name, device::parent, usb_device::port, usb_device_descriptor::product, usb_function_descriptor::product, usb_class::protocol, rc, device::siblings, snprintf(), usb_class::subclass, usb_function::usb, USB_BUSDEV, usb_describe(), usb_probe(), usb_remove(), usb_used(), device_description::vendor, usb_device_descriptor::vendor, usb_function_descriptor::vendor, and zalloc().

Referenced by usb_autoconfigure().

◆ usb_remove_all()

static void usb_remove_all ( struct usb_device usb)
static

Remove all device drivers.

Parameters
usbUSB device

Definition at line 1382 of file usb.c.

1382  {
1383  struct usb_function *func;
1384  struct usb_function *tmp;
1385 
1386  /* Remove all functions */
1388 
1389  /* Remove device driver */
1390  usb_remove ( func );
1391 
1392  /* Remove from device hierarchy */
1393  assert ( list_empty ( &func->dev.children ) );
1394  list_del ( &func->dev.siblings );
1395 
1396  /* Remove from list of functions */
1397  list_del ( &func->list );
1398 
1399  /* Free function */
1400  free ( func );
1401  }
1402 }
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
unsigned long tmp
Definition: linux_pci.h:65
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:459
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
static void usb_remove(struct usb_function *func)
Remove USB device driver.
Definition: usb.c:1286
struct usb_device * usb
USB device.
Definition: usb.h:678
struct list_head children
Devices attached to this device.
Definition: device.h:87
struct device dev
Generic device.
Definition: usb.h:682
A USB function.
Definition: usb.h:674
struct list_head functions
List of functions.
Definition: usb.h:737
struct list_head list
List of functions within this USB device.
Definition: usb.h:684

References assert(), device::children, usb_function::dev, free, usb_device::functions, usb_function::list, list_del, list_empty, list_for_each_entry_safe, device::siblings, tmp, usb_function::usb, and usb_remove().

Referenced by usb_autoconfigure(), and usb_deconfigure().

◆ usb_deconfigure()

static void usb_deconfigure ( struct usb_device usb)
static

Clear USB device configuration.

Parameters
usbUSB device

Definition at line 1409 of file usb.c.

1409  {
1410  unsigned int i;
1411 
1412  /* Remove device drivers */
1413  usb_remove_all ( usb );
1414 
1415  /* Sanity checks */
1416  for ( i = 0 ; i < ( sizeof ( usb->ep ) / sizeof ( usb->ep[0] ) ) ; i++){
1417  if ( i != USB_ENDPOINT_IDX ( USB_EP0_ADDRESS ) )
1418  assert ( usb->ep[i] == NULL );
1419  }
1420 
1421  /* Clear device configuration */
1422  usb_set_configuration ( usb, 0 );
1423 }
static int usb_set_configuration(struct usb_device *usb, unsigned int index)
Set USB configuration.
Definition: usb.h:1242
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct usb_device * usb
USB device.
Definition: usb.h:678
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:528
static void usb_remove_all(struct usb_device *usb)
Remove all device drivers.
Definition: usb.c:1382
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
#define USB_EP0_ADDRESS
Control endpoint address.
Definition: usb.h:501
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References assert(), usb_device::ep, NULL, usb_function::usb, USB_ENDPOINT_IDX, USB_EP0_ADDRESS, usb_remove_all(), and usb_set_configuration().

Referenced by register_usb(), and unregister_usb().

◆ usb_autoconfigure()

static int usb_autoconfigure ( struct usb_device usb)
static

Choose our preferred USB device configuration.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 1431 of file usb.c.

1431  {
1433  unsigned int preferred = 0;
1434  unsigned int index;
1435  int score;
1436  int best = 0;
1437  int rc;
1438 
1439  /* Calculate driver score for each configuration index */
1440  for ( index = 0 ; index < usb->device.configurations ; index++ ) {
1441 
1442  /* Read configuration descriptor */
1443  if ( ( rc = usb_config_descriptor ( usb, index,
1444  &config ) ) != 0 )
1445  goto err_config;
1446 
1447  /* Get score for this configuration */
1448  score = usb_score ( usb, config );
1449  if ( score < 0 ) {
1450  rc = score;
1451  goto err_score;
1452  }
1453  DBGC2 ( usb, "USB %s configuration %d score %d\n",
1454  usb->name, config->config, score );
1455 
1456  /* Record as preferred configuration, if applicable */
1457  if ( score > best ) {
1458  best = score;
1459  preferred = index;
1460  }
1461 
1462  /* Free configuration descriptor */
1463  free ( config );
1464  config = NULL;
1465  }
1466 
1467  /* Read preferred configuration descriptor */
1468  if ( ( rc = usb_config_descriptor ( usb, preferred, &config ) ) != 0 )
1469  goto err_preferred;
1470 
1471  /* Set configuration */
1472  if ( ( rc = usb_set_configuration ( usb, config->config ) ) != 0){
1473  DBGC ( usb, "USB %s could not set configuration %d: %s\n",
1474  usb->name, config->config, strerror ( rc ) );
1475  goto err_set_configuration;
1476  }
1477 
1478  /* Probe USB device drivers */
1479  usb_probe_all ( usb, config );
1480 
1481  /* Free configuration descriptor */
1482  free ( config );
1483 
1484  return 0;
1485 
1486  usb_remove_all ( usb );
1487  usb_set_configuration ( usb, 0 );
1488  err_set_configuration:
1489  free ( config );
1490  err_preferred:
1491  return rc;
1492 
1493  err_score:
1494  free ( config );
1495  err_config:
1496  return rc;
1497 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int usb_set_configuration(struct usb_device *usb, unsigned int index)
Set USB configuration.
Definition: usb.h:1242
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:65
static void usb_probe_all(struct usb_device *usb, struct usb_configuration_descriptor *config)
Probe all USB device drivers.
Definition: usb.c:1299
uint8_t configurations
Number of possible configurations.
Definition: usb.h:203
char name[32]
Name.
Definition: usb.h:725
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
static int usb_score(struct usb_device *usb, struct usb_configuration_descriptor *config)
Get USB device configuration score.
Definition: usb.c:1203
struct usb_device_descriptor device
Device descriptor.
Definition: usb.h:735
static void usb_remove_all(struct usb_device *usb)
Remove all device drivers.
Definition: usb.c:1382
A USB configuration descriptor.
Definition: usb.h:210
static int usb_config_descriptor(struct usb_device *usb, unsigned int index, struct usb_configuration_descriptor **config)
Get USB configuration descriptor.
Definition: usb.c:990
uint8_t config
Configuration value.
Definition: usb.h:218
#define DBGC2(...)
Definition: compiler.h:522
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References usb_configuration_descriptor::config, usb_device_descriptor::configurations, DBGC, DBGC2, usb_device::device, free, index, usb_device::name, NULL, rc, strerror(), usb_config_descriptor(), usb_probe_all(), usb_remove_all(), usb_score(), and usb_set_configuration().

Referenced by register_usb().

◆ alloc_usb()

static struct usb_device* alloc_usb ( struct usb_port port)
static

Allocate USB device.

Parameters
portUSB port
Return values
usbUSB device, or NULL on allocation failure

Definition at line 1512 of file usb.c.

1512  {
1513  struct usb_hub *hub = port->hub;
1514  struct usb_bus *bus = hub->bus;
1515  struct usb_device *usb;
1516 
1517  /* Allocate and initialise structure */
1518  usb = zalloc ( sizeof ( *usb ) );
1519  if ( ! usb )
1520  return NULL;
1521  snprintf ( usb->name, sizeof ( usb->name ), "%s%c%d", hub->name,
1522  ( hub->usb ? '.' : '-' ), port->address );
1523  usb->port = port;
1524  INIT_LIST_HEAD ( &usb->functions );
1525  usb->host = &bus->op->device;
1527  INIT_LIST_HEAD ( &usb->complete );
1528 
1529  return usb;
1530 }
A USB hub.
Definition: usb.h:841
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:847
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:727
static struct usb_endpoint_driver_operations usb_control_operations
USB control endpoint driver operations.
Definition: usb.c:769
char name[32]
Name.
Definition: usb.h:725
const char * name
Name.
Definition: usb.h:843
A USB device.
Definition: usb.h:723
struct usb_endpoint control
Control endpoint.
Definition: usb.h:748
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
static void usb_endpoint_init(struct usb_endpoint *ep, struct usb_device *usb, struct usb_endpoint_driver_operations *driver)
Initialise USB endpoint.
Definition: usb.h:540
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
struct list_head complete
Completed control transfers.
Definition: usb.h:750
struct usb_hub * hub
Root hub.
Definition: usb.h:995
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383
struct usb_device_host_operations * host
Host controller operations.
Definition: usb.h:740
struct usb_bus * bus
USB bus.
Definition: usb.h:845
struct list_head functions
List of functions.
Definition: usb.h:737
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15

References bus, usb_hub::bus, usb_device::complete, usb_device::control, usb_device::functions, usb_device::host, usb_bus::hub, INIT_LIST_HEAD, usb_device::name, usb_hub::name, NULL, port, usb_device::port, snprintf(), usb_hub::usb, usb_control_operations, usb_endpoint_init(), and zalloc().

Referenced by usb_attached().

◆ register_usb()

static int register_usb ( struct usb_device usb)
static

Register USB device.

Parameters
usbUSB device
Return values
rcReturn status code

Definition at line 1538 of file usb.c.

1538  {
1539  struct usb_port *port = usb->port;
1540  struct usb_hub *hub = port->hub;
1541  struct usb_bus *bus = hub->bus;
1542  unsigned int protocol;
1543  size_t mtu;
1544  int rc;
1545 
1546  /* Add to port */
1547  if ( port->usb != NULL ) {
1548  DBGC ( hub, "USB hub %s port %d is already registered to %s\n",
1549  hub->name, port->address, port->usb->name );
1550  rc = -EALREADY;
1551  goto err_already;
1552  }
1553  port->usb = usb;
1554 
1555  /* Add to bus device list */
1556  list_add_tail ( &usb->list, &bus->devices );
1557 
1558  /* Enable device */
1559  if ( ( rc = hub->driver->enable ( hub, port ) ) != 0 ) {
1560  DBGC ( hub, "USB hub %s port %d could not enable: %s\n",
1561  hub->name, port->address, strerror ( rc ) );
1562  goto err_enable;
1563  }
1564 
1565  /* Allow recovery interval since port may have been reset */
1567 
1568  /* Get device speed */
1569  if ( ( rc = hub->driver->speed ( hub, port ) ) != 0 ) {
1570  DBGC ( hub, "USB hub %s port %d could not get speed: %s\n",
1571  hub->name, port->address, strerror ( rc ) );
1572  goto err_speed;
1573  }
1574  usb->speed = port->speed;
1575  DBGC2 ( usb, "USB %s attached as %s-speed device\n",
1576  usb->name, usb_speed_name ( usb->speed ) );
1577 
1578  /* Open device */
1579  if ( ( rc = usb->host->open ( usb ) ) != 0 ) {
1580  DBGC ( usb, "USB %s could not open: %s\n",
1581  usb->name, strerror ( rc ) );
1582  goto err_open;
1583  }
1584 
1585  /* Describe control endpoint */
1586  mtu = USB_EP0_DEFAULT_MTU ( usb->speed );
1589  USB_EP0_INTERVAL );
1590 
1591  /* Open control endpoint */
1592  if ( ( rc = usb_endpoint_open ( &usb->control ) ) != 0 )
1593  goto err_open_control;
1594  assert ( usb_endpoint ( usb, USB_EP0_ADDRESS ) == &usb->control );
1595 
1596  /* Assign device address */
1597  if ( ( rc = usb->host->address ( usb ) ) != 0 ) {
1598  DBGC ( usb, "USB %s could not set address: %s\n",
1599  usb->name, strerror ( rc ) );
1600  goto err_address;
1601  }
1602  DBGC2 ( usb, "USB %s assigned address %d\n", usb->name, usb->address );
1603 
1604  /* Allow recovery interval after Set Address command */
1606 
1607  /* Read first part of device descriptor to get EP0 MTU */
1608  if ( ( rc = usb_get_mtu ( usb, &usb->device ) ) != 0 ) {
1609  DBGC ( usb, "USB %s could not get MTU: %s\n",
1610  usb->name, strerror ( rc ) );
1611  goto err_get_mtu;
1612  }
1613 
1614  /* Calculate EP0 MTU */
1615  protocol = le16_to_cpu ( usb->device.protocol );
1616  mtu = ( ( protocol < USB_PROTO_3_0 ) ?
1617  usb->device.mtu : ( 1 << usb->device.mtu ) );
1618  DBGC2 ( usb, "USB %s has control MTU %zd (guessed %zd)\n",
1619  usb->name, mtu, usb->control.mtu );
1620 
1621  /* Update MTU */
1622  if ( ( rc = usb_endpoint_mtu ( &usb->control, mtu ) ) != 0 )
1623  goto err_mtu;
1624 
1625  /* Read whole device descriptor */
1626  if ( ( rc = usb_get_device_descriptor ( usb, &usb->device ) ) != 0 ) {
1627  DBGC ( usb, "USB %s could not get device descriptor: %s\n",
1628  usb->name, strerror ( rc ) );
1629  goto err_get_device_descriptor;
1630  }
1631  DBGC ( usb, "USB %s addr %d %04x:%04x class %d:%d:%d (v%s, %s-speed, "
1632  "MTU %zd)\n", usb->name, usb->address,
1633  le16_to_cpu ( usb->device.vendor ),
1634  le16_to_cpu ( usb->device.product ), usb->device.class.class,
1636  usb_bcd ( le16_to_cpu ( usb->device.protocol ) ),
1637  usb_speed_name ( usb->speed ), usb->control.mtu );
1638 
1639  /* Configure device */
1640  if ( ( rc = usb_autoconfigure ( usb ) ) != 0 )
1641  goto err_autoconfigure;
1642 
1643  return 0;
1644 
1645  usb_deconfigure ( usb );
1646  err_autoconfigure:
1647  err_get_device_descriptor:
1648  err_mtu:
1649  err_get_mtu:
1650  err_address:
1651  usb_endpoint_close ( &usb->control );
1652  err_open_control:
1653  usb->host->close ( usb );
1654  err_open:
1655  err_speed:
1656  /* Leave port enabled on failure, to avoid an endless loop of
1657  * failed device registrations.
1658  */
1659  err_enable:
1660  list_del ( &usb->list );
1661  port->usb = NULL;
1662  err_already:
1663  return rc;
1664 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t class
Class code.
Definition: usb.h:162
static void usb_endpoint_describe(struct usb_endpoint *ep, unsigned int address, unsigned int attributes, size_t mtu, unsigned int burst, unsigned int interval)
Describe USB endpoint.
Definition: usb.h:558
A USB hub.
Definition: usb.h:841
uint16_t vendor
Vendor ID.
Definition: usb.h:191
#define USB_EP0_DEFAULT_MTU(speed)
Calculate default MTU based on device speed.
Definition: usb.h:511
#define USB_RESET_RECOVER_DELAY_MS
Reset recovery time.
Definition: usb.h:1335
static const char * usb_bcd(uint16_t bcd)
Transcribe USB BCD-coded value (for debugging)
Definition: usb.c:96
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:835
int usb_endpoint_open(struct usb_endpoint *ep)
Open USB endpoint.
Definition: usb.c:294
static int usb_endpoint_mtu(struct usb_endpoint *ep, size_t mtu)
Update endpoint MTU.
Definition: usb.c:464
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:400
unsigned int address
Device address, if assigned.
Definition: usb.h:733
static int usb_autoconfigure(struct usb_device *usb)
Choose our preferred USB device configuration.
Definition: usb.c:1431
unsigned int speed
Device speed.
Definition: usb.h:729
#define USB_EP0_ATTRIBUTES
Control endpoint attributes.
Definition: usb.h:504
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
A USB port.
Definition: usb.h:813
uint16_t product
Product ID.
Definition: usb.h:193
A USB endpoint.
Definition: usb.h:404
#define USB_EP0_BURST
Control endpoint maximum burst size.
Definition: usb.h:516
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:727
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:859
USB 3.0.
Definition: usb.h:25
static const char * usb_speed_name(unsigned int speed)
Get USB speed name (for debugging)
Definition: usb.c:66
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
struct usb_class class
Device class.
Definition: usb.h:187
int(* enable)(struct usb_hub *hub, struct usb_port *port)
Enable port.
Definition: usb.h:904
char name[32]
Name.
Definition: usb.h:725
const char * name
Name.
Definition: usb.h:843
void(* close)(struct usb_device *usb)
Close device.
Definition: usb.h:768
struct usb_endpoint control
Control endpoint.
Definition: usb.h:748
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
struct list_head list
List of devices on this bus.
Definition: usb.h:731
static int usb_get_mtu(struct usb_device *usb, struct usb_device_descriptor *data)
Get first part of USB device descriptor (up to and including MTU)
Definition: usb.h:1194
struct usb_device_descriptor device
Device descriptor.
Definition: usb.h:735
#define le16_to_cpu(value)
Definition: byteswap.h:113
#define EALREADY
Connection already in progress.
Definition: errno.h:324
uint8_t protocol
Protocol code.
Definition: usb.h:166
#define USB_EP0_INTERVAL
Control endpoint interval.
Definition: usb.h:519
size_t mtu
Maximum transfer size.
Definition: usb.h:412
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
static int usb_get_device_descriptor(struct usb_device *usb, struct usb_device_descriptor *data)
Get USB device descriptor.
Definition: usb.h:1210
static void usb_deconfigure(struct usb_device *usb)
Clear USB device configuration.
Definition: usb.c:1409
uint8_t subclass
Subclass code.
Definition: usb.h:164
#define DBGC2(...)
Definition: compiler.h:522
uint16_t protocol
USB specification release number in BCD.
Definition: usb.h:185
uint8_t mtu
Maximum packet size for endpoint zero.
Definition: usb.h:189
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
#define USB_SET_ADDRESS_RECOVER_DELAY_MS
Set address recovery time.
Definition: usb.h:1349
int(* address)(struct usb_device *usb)
Assign device address.
Definition: usb.h:774
struct usb_hub * hub
Root hub.
Definition: usb.h:995
uint16_t protocol
Protocol ID.
Definition: stp.h:19
struct usb_device_host_operations * host
Host controller operations.
Definition: usb.h:740
struct usb_bus * bus
USB bus.
Definition: usb.h:845
#define USB_EP0_ADDRESS
Control endpoint address.
Definition: usb.h:501
int(* speed)(struct usb_hub *hub, struct usb_port *port)
Update port speed.
Definition: usb.h:918
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15
int(* open)(struct usb_device *usb)
Open device.
Definition: usb.h:763

References usb_device::address, usb_device_host_operations::address, assert(), bus, usb_hub::bus, usb_class::class, usb_device_descriptor::class, usb_device_host_operations::close, usb_device::control, DBGC, DBGC2, usb_device::device, usb_hub::driver, EALREADY, usb_hub_driver_operations::enable, usb_device::host, usb_bus::hub, le16_to_cpu, usb_device::list, list_add_tail, list_del, mdelay(), mtu, usb_device_descriptor::mtu, usb_endpoint::mtu, usb_device::name, usb_hub::name, NULL, usb_device_host_operations::open, port, usb_device::port, usb_device_descriptor::product, protocol, usb_class::protocol, usb_device_descriptor::protocol, rc, usb_device::speed, usb_hub_driver_operations::speed, strerror(), usb_class::subclass, usb_port::usb, usb_autoconfigure(), usb_bcd(), usb_deconfigure(), usb_endpoint_close(), usb_endpoint_describe(), usb_endpoint_mtu(), usb_endpoint_open(), USB_EP0_ADDRESS, USB_EP0_ATTRIBUTES, USB_EP0_BURST, USB_EP0_DEFAULT_MTU, USB_EP0_INTERVAL, usb_get_device_descriptor(), usb_get_mtu(), USB_PROTO_3_0, USB_RESET_RECOVER_DELAY_MS, USB_SET_ADDRESS_RECOVER_DELAY_MS, usb_speed_name(), and usb_device_descriptor::vendor.

Referenced by usb_attached().

◆ unregister_usb()

static void unregister_usb ( struct usb_device usb)
static

Unregister USB device.

Parameters
usbUSB device

Definition at line 1671 of file usb.c.

1671  {
1672  struct usb_port *port = usb->port;
1673  struct usb_hub *hub = port->hub;
1674  struct io_buffer *iobuf;
1675  struct io_buffer *tmp;
1676 
1677  DBGC ( usb, "USB %s addr %d %04x:%04x class %d:%d:%d removed\n",
1678  usb->name, usb->address, le16_to_cpu ( usb->device.vendor ),
1679  le16_to_cpu ( usb->device.product ), usb->device.class.class,
1680  usb->device.class.subclass, usb->device.class.protocol );
1681 
1682  /* Sanity checks */
1683  assert ( port->usb == usb );
1684 
1685  /* Clear device configuration */
1686  usb_deconfigure ( usb );
1687 
1688  /* Close control endpoint */
1689  usb_endpoint_close ( &usb->control );
1690 
1691  /* Discard any stale control completions */
1692  list_for_each_entry_safe ( iobuf, tmp, &usb->complete, list ) {
1693  list_del ( &iobuf->list );
1694  free_iob ( iobuf );
1695  }
1696 
1697  /* Close device */
1698  usb->host->close ( usb );
1699 
1700  /* Disable port */
1701  hub->driver->disable ( hub, port );
1702 
1703  /* Remove from bus device list */
1704  list_del ( &usb->list );
1705 
1706  /* Remove from port */
1707  port->usb = NULL;
1708 }
uint8_t class
Class code.
Definition: usb.h:162
A USB hub.
Definition: usb.h:841
uint16_t vendor
Vendor ID.
Definition: usb.h:191
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:835
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:400
unsigned int address
Device address, if assigned.
Definition: usb.h:733
unsigned long tmp
Definition: linux_pci.h:65
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
A USB port.
Definition: usb.h:813
uint16_t product
Product ID.
Definition: usb.h:193
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:727
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:859
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct usb_class class
Device class.
Definition: usb.h:187
char name[32]
Name.
Definition: usb.h:725
void(* close)(struct usb_device *usb)
Close device.
Definition: usb.h:768
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:459
struct usb_endpoint control
Control endpoint.
Definition: usb.h:748
struct list_head list
List of devices on this bus.
Definition: usb.h:731
struct usb_device_descriptor device
Device descriptor.
Definition: usb.h:735
#define le16_to_cpu(value)
Definition: byteswap.h:113
uint8_t protocol
Protocol code.
Definition: usb.h:166
int(* disable)(struct usb_hub *hub, struct usb_port *port)
Disable port.
Definition: usb.h:911
static void usb_deconfigure(struct usb_device *usb)
Clear USB device configuration.
Definition: usb.c:1409
uint8_t subclass
Subclass code.
Definition: usb.h:164
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:45
struct list_head complete
Completed control transfers.
Definition: usb.h:750
struct usb_device_host_operations * host
Host controller operations.
Definition: usb.h:740
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A persistent I/O buffer.
Definition: iobuf.h:38

References usb_device::address, assert(), usb_class::class, usb_device_descriptor::class, usb_device_host_operations::close, usb_device::complete, usb_device::control, DBGC, usb_device::device, usb_hub_driver_operations::disable, usb_hub::driver, free_iob(), usb_device::host, le16_to_cpu, io_buffer::list, usb_device::list, list_del, list_for_each_entry_safe, usb_device::name, NULL, port, usb_device::port, usb_device_descriptor::product, usb_class::protocol, usb_class::subclass, tmp, usb_port::usb, usb_deconfigure(), usb_endpoint_close(), and usb_device_descriptor::vendor.

Referenced by usb_attached(), and usb_detached().

◆ free_usb()

static void free_usb ( struct usb_device usb)
static

Free USB device.

Parameters
usbUSB device

Definition at line 1715 of file usb.c.

1715  {
1716  unsigned int i;
1717 
1718  /* Sanity checks */
1719  for ( i = 0 ; i < ( sizeof ( usb->ep ) / sizeof ( usb->ep[0] ) ) ; i++ )
1720  assert ( usb->ep[i] == NULL );
1721  assert ( list_empty ( &usb->functions ) );
1722  assert ( list_empty ( &usb->complete ) );
1723 
1724  /* Free device */
1725  free ( usb );
1726 }
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
struct list_head complete
Completed control transfers.
Definition: usb.h:750
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:745
struct list_head functions
List of functions.
Definition: usb.h:737
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References assert(), usb_device::complete, usb_device::ep, free, usb_device::functions, list_empty, and NULL.

Referenced by usb_attached(), and usb_detached().

◆ find_usb()

struct usb_device* find_usb ( struct usb_bus bus,
unsigned int  address 
)

Find USB device by address.

Parameters
busUSB bus
addressDevice address
Return values
usbUSB device, or NULL if not found

Definition at line 1735 of file usb.c.

1735  {
1736  struct usb_device *usb;
1737 
1738  /* Search for a matching non-zero address */
1739  list_for_each_entry ( usb, &bus->devices, list ) {
1740  if ( address && ( usb->address == address ) )
1741  return usb;
1742  }
1743 
1744  return NULL;
1745 }
uint64_t address
Base address.
Definition: ena.h:24
unsigned int address
Device address, if assigned.
Definition: usb.h:733
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
A USB device.
Definition: usb.h:723
struct list_head list
List of devices on this bus.
Definition: usb.h:731
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
uint8_t bus
Bus.
Definition: edd.h:15

References address, usb_device::address, bus, usb_device::list, list_for_each_entry, and NULL.

Referenced by usb_find_next(), and usb_settings_fetch().

◆ usb_attached()

static int usb_attached ( struct usb_port port)
static

Handle newly attached USB device.

Parameters
portUSB port
Return values
rcReturn status code

Definition at line 1760 of file usb.c.

1760  {
1761  struct usb_device *usb;
1762  int rc;
1763 
1764  /* Mark port as attached */
1765  port->attached = 1;
1766 
1767  /* Sanity checks */
1768  assert ( port->usb == NULL );
1769 
1770  /* Allocate USB device */
1771  usb = alloc_usb ( port );
1772  if ( ! usb ) {
1773  rc = -ENOMEM;
1774  goto err_alloc;
1775  }
1776 
1777  /* Register USB device */
1778  if ( ( rc = register_usb ( usb ) ) != 0 )
1779  goto err_register;
1780 
1781  return 0;
1782 
1783  unregister_usb ( usb );
1784  err_register:
1785  free_usb ( usb );
1786  err_alloc:
1787  return rc;
1788 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void unregister_usb(struct usb_device *usb)
Unregister USB device.
Definition: usb.c:1671
#define ENOMEM
Not enough space.
Definition: errno.h:535
u8 port
Port number.
Definition: CIB_PRM.h:31
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
A USB device.
Definition: usb.h:723
static void free_usb(struct usb_device *usb)
Free USB device.
Definition: usb.c:1715
static int register_usb(struct usb_device *usb)
Register USB device.
Definition: usb.c:1538
static struct usb_device * alloc_usb(struct usb_port *port)
Allocate USB device.
Definition: usb.c:1512
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References alloc_usb(), assert(), ENOMEM, free_usb(), NULL, port, rc, register_usb(), and unregister_usb().

Referenced by usb_hotplugged().

◆ usb_detached()

static void usb_detached ( struct usb_port port)
static

Handle newly detached USB device.

Parameters
portUSB port

Definition at line 1795 of file usb.c.

1795  {
1796  struct usb_device *usb = port->usb;
1797 
1798  /* Mark port as detached */
1799  port->attached = 0;
1800 
1801  /* Do nothing if we have no USB device */
1802  if ( ! usb )
1803  return;
1804 
1805  /* Unregister USB device */
1806  unregister_usb ( usb );
1807 
1808  /* Free USB device */
1809  free_usb ( usb );
1810 }
static void unregister_usb(struct usb_device *usb)
Unregister USB device.
Definition: usb.c:1671
u8 port
Port number.
Definition: CIB_PRM.h:31
A USB device.
Definition: usb.h:723
static void free_usb(struct usb_device *usb)
Free USB device.
Definition: usb.c:1715

References free_usb(), port, and unregister_usb().

Referenced by unregister_usb_hub(), and usb_hotplugged().

◆ usb_hotplugged()

static int usb_hotplugged ( struct usb_port port)
static

Handle newly attached or detached USB device.

Parameters
portUSB port
Return values
rcReturn status code

Definition at line 1818 of file usb.c.

1818  {
1819  struct usb_hub *hub = port->hub;
1820  int rc;
1821 
1822  /* Get current port speed */
1823  if ( ( rc = hub->driver->speed ( hub, port ) ) != 0 ) {
1824  DBGC ( hub, "USB hub %s port %d could not get speed: %s\n",
1825  hub->name, port->address, strerror ( rc ) );
1826  /* Treat as a disconnection */
1827  port->disconnected = 1;
1828  port->speed = USB_SPEED_NONE;
1829  }
1830 
1831  /* Detach device, if applicable */
1832  if ( port->attached && ( port->disconnected || ! port->speed ) )
1833  usb_detached ( port );
1834 
1835  /* Clear any recorded disconnections */
1836  port->disconnected = 0;
1837 
1838  /* Attach device, if applicable */
1839  if ( port->speed && ( ! port->attached ) &&
1840  ( ( rc = usb_attached ( port ) ) != 0 ) )
1841  return rc;
1842 
1843  return 0;
1844 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void usb_detached(struct usb_port *port)
Handle newly detached USB device.
Definition: usb.c:1795
A USB hub.
Definition: usb.h:841
static int usb_attached(struct usb_port *port)
Handle newly attached USB device.
Definition: usb.c:1760
#define DBGC(...)
Definition: compiler.h:505
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:859
Not connected.
Definition: usb.h:47
const char * name
Name.
Definition: usb.h:843
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
int(* speed)(struct usb_hub *hub, struct usb_port *port)
Update port speed.
Definition: usb.h:918

References DBGC, usb_hub::driver, usb_hub::name, port, rc, usb_hub_driver_operations::speed, strerror(), usb_attached(), usb_detached(), and USB_SPEED_NONE.

Referenced by usb_hotplug().

◆ usb_port_changed()

void usb_port_changed ( struct usb_port port)

Report port status change.

Parameters
portUSB port

Definition at line 1858 of file usb.c.

1858  {
1859 
1860  /* Record hub port status change */
1861  list_del ( &port->changed );
1862  list_add_tail ( &port->changed, &usb_changed );
1863 }
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
u8 port
Port number.
Definition: CIB_PRM.h:31
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
static struct list_head usb_changed
List of changed ports.
Definition: usb.c:48

References list_add_tail, list_del, port, and usb_changed.

Referenced by ehci_root_poll(), hub_complete(), register_usb_hub(), uhci_root_poll(), and xhci_port_status().

◆ usb_hotplug()

static void usb_hotplug ( void  )
static

Handle newly attached or detached USB device.

Definition at line 1869 of file usb.c.

1869  {
1870  struct usb_port *port;
1871 
1872  /* Handle any changed ports, allowing for the fact that the
1873  * port list may change as we perform hotplug actions.
1874  */
1875  while ( ! list_empty ( &usb_changed ) ) {
1876 
1877  /* Get first changed port */
1879  changed );
1880  assert ( port != NULL );
1881 
1882  /* Remove from list of changed ports */
1883  list_del ( &port->changed );
1884  INIT_LIST_HEAD ( &port->changed );
1885 
1886  /* Perform appropriate hotplug action */
1887  usb_hotplugged ( port );
1888  }
1889 }
struct list_head changed
List of changed ports.
Definition: usb.h:837
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:334
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
A USB port.
Definition: usb.h:813
u8 port
Port number.
Definition: CIB_PRM.h:31
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static int usb_hotplugged(struct usb_port *port)
Handle newly attached or detached USB device.
Definition: usb.c:1818
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
static struct list_head usb_changed
List of changed ports.
Definition: usb.c:48
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References assert(), usb_port::changed, INIT_LIST_HEAD, list_del, list_empty, list_first_entry, NULL, port, usb_changed, and usb_hotplugged().

Referenced by register_usb_bus(), and usb_step().

◆ usb_step()

static void usb_step ( struct process *process  __unused)
static

USB process.

Parameters
processUSB process

Definition at line 1896 of file usb.c.

1896  {
1897  struct usb_bus *bus;
1898  struct usb_endpoint *ep;
1899 
1900  /* Poll all buses */
1901  for_each_usb_bus ( bus )
1902  usb_poll ( bus );
1903 
1904  /* Attempt to reset first halted endpoint in list, if any. We
1905  * do not attempt to process the complete list, since this
1906  * would require extra code to allow for the facts that the
1907  * halted endpoint list may change as we do so, and that
1908  * resetting an endpoint may fail.
1909  */
1910  if ( ( ep = list_first_entry ( &usb_halted, struct usb_endpoint,
1911  halted ) ) != NULL )
1912  usb_endpoint_reset ( ep );
1913 
1914  /* Handle any changed ports */
1915  usb_hotplug();
1916 }
static void usb_hotplug(void)
Handle newly attached or detached USB device.
Definition: usb.c:1869
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:334
#define for_each_usb_bus(bus)
Iterate over all USB buses.
Definition: usb.h:1077
A USB endpoint.
Definition: usb.h:404
struct list_head halted
List of halted endpoints.
Definition: usb.h:424
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1072
static int usb_endpoint_reset(struct usb_endpoint *ep)
Reset USB endpoint.
Definition: usb.c:430
static struct list_head usb_halted
List of halted endpoints.
Definition: usb.c:51
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15

References bus, for_each_usb_bus, usb_endpoint::halted, list_first_entry, NULL, usb_endpoint_reset(), usb_halted, usb_hotplug(), and usb_poll().

◆ PERMANENT_PROCESS()

PERMANENT_PROCESS ( usb_process  ,
usb_step   
)

USB process.

◆ alloc_usb_hub()

struct usb_hub* alloc_usb_hub ( struct usb_bus bus,
struct usb_device usb,
unsigned int  ports,
struct usb_hub_driver_operations driver 
)

Allocate USB hub.

Parameters
busUSB bus
usbUnderlying USB device, if any
portsNumber of ports
driverHub driver operations
Return values
hubUSB hub, or NULL on allocation failure

Definition at line 1937 of file usb.c.

1939  {
1940  struct usb_hub *hub;
1941  struct usb_port *port;
1942  unsigned int i;
1943 
1944  /* Allocate and initialise structure */
1945  hub = zalloc ( sizeof ( *hub ) + ( ports * sizeof ( hub->port[0] ) ) );
1946  if ( ! hub )
1947  return NULL;
1948  hub->name = ( usb ? usb->name : bus->name );
1949  hub->bus = bus;
1950  hub->usb = usb;
1951  if ( usb )
1952  hub->protocol = usb->port->protocol;
1953  hub->ports = ports;
1954  hub->driver = driver;
1955  hub->host = &bus->op->hub;
1956 
1957  /* Initialise port list */
1958  for ( i = 1 ; i <= hub->ports ; i++ ) {
1959  port = usb_port ( hub, i );
1960  port->hub = hub;
1961  port->address = i;
1962  if ( usb )
1963  port->protocol = usb->port->protocol;
1964  INIT_LIST_HEAD ( &port->changed );
1965  }
1966 
1967  return hub;
1968 }
A USB hub.
Definition: usb.h:841
struct usb_hub_host_operations * host
Host controller operations.
Definition: usb.h:857
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:835
unsigned int protocol
Port protocol.
Definition: usb.h:819
A USB port.
Definition: usb.h:813
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:847
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:727
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:859
char name[32]
Name.
Definition: usb.h:725
unsigned int ports
Number of ports.
Definition: usb.h:851
const char * name
Name.
Definition: usb.h:843
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
struct usb_hub * hub
USB hub.
Definition: usb.h:815
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:960
unsigned int protocol
Hub protocol.
Definition: usb.h:849
struct usb_bus * bus
USB bus.
Definition: usb.h:845
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
uint8_t bus
Bus.
Definition: edd.h:15
struct usb_port port[0]
Port list.
Definition: usb.h:867

References bus, usb_hub::bus, usb_hub::driver, usb_hub::host, usb_port::hub, INIT_LIST_HEAD, usb_device::name, usb_hub::name, NULL, port, usb_device::port, usb_hub::port, usb_hub::ports, usb_port::protocol, usb_hub::protocol, usb_port::usb, usb_hub::usb, usb_port(), and zalloc().

Referenced by alloc_usb_bus(), and hub_probe().

◆ register_usb_hub()

int register_usb_hub ( struct usb_hub hub)

Register USB hub.

Parameters
hubUSB hub
Return values
rcReturn status code

Definition at line 1976 of file usb.c.

1976  {
1977  struct usb_bus *bus = hub->bus;
1978  struct usb_port *port;
1979  unsigned int i;
1980  int rc;
1981 
1982  /* Add to hub list */
1983  list_add_tail ( &hub->list, &bus->hubs );
1984 
1985  /* Open hub (host controller) */
1986  if ( ( rc = hub->host->open ( hub ) ) != 0 ) {
1987  DBGC ( hub, "USB hub %s could not open: %s\n",
1988  hub->name, strerror ( rc ) );
1989  goto err_host_open;
1990  }
1991 
1992  /* Open hub (driver) */
1993  if ( ( rc = hub->driver->open ( hub ) ) != 0 ) {
1994  DBGC ( hub, "USB hub %s could not open: %s\n",
1995  hub->name, strerror ( rc ) );
1996  goto err_driver_open;
1997  }
1998 
1999  /* Delay to allow ports to stabilise */
2001 
2002  /* Mark all ports as changed */
2003  for ( i = 1 ; i <= hub->ports ; i++ ) {
2004  port = usb_port ( hub, i );
2005  usb_port_changed ( port );
2006  }
2007 
2008  /* Some hubs seem to defer reporting device connections until
2009  * their interrupt endpoint is polled for the first time.
2010  * Poll the bus once now in order to pick up any such
2011  * connections.
2012  */
2013  usb_poll ( bus );
2014 
2015  return 0;
2016 
2017  hub->driver->close ( hub );
2018  err_driver_open:
2019  hub->host->close ( hub );
2020  err_host_open:
2021  list_del ( &hub->list );
2022  return rc;
2023 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usb_hub_host_operations * host
Host controller operations.
Definition: usb.h:857
#define DBGC(...)
Definition: compiler.h:505
void usb_port_changed(struct usb_port *port)
Report port status change.
Definition: usb.c:1858
int(* open)(struct usb_hub *hub)
Open hub.
Definition: usb.h:877
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
A USB port.
Definition: usb.h:813
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:859
void(* close)(struct usb_hub *hub)
Close hub.
Definition: usb.h:882
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
unsigned int ports
Number of ports.
Definition: usb.h:851
const char * name
Name.
Definition: usb.h:843
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1072
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
void(* close)(struct usb_hub *hub)
Close hub.
Definition: usb.h:897
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
struct list_head list
List of hubs.
Definition: usb.h:854
struct usb_hub * hub
USB hub.
Definition: usb.h:815
#define USB_PORT_DELAY_MS
Time to wait for ports to stabilise.
Definition: usb.h:1358
struct usb_hub * hub
Root hub.
Definition: usb.h:995
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:960
struct usb_bus * bus
USB bus.
Definition: usb.h:845
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15
int(* open)(struct usb_hub *hub)
Open hub.
Definition: usb.h:892

References bus, usb_hub::bus, usb_hub_host_operations::close, usb_hub_driver_operations::close, DBGC, usb_hub::driver, usb_hub::host, usb_port::hub, usb_bus::hub, usb_hub::list, list_add_tail, list_del, mdelay(), usb_hub::name, usb_hub_host_operations::open, usb_hub_driver_operations::open, port, usb_hub::ports, rc, strerror(), usb_poll(), usb_port(), usb_port_changed(), and USB_PORT_DELAY_MS.

Referenced by hub_probe(), and register_usb_bus().

◆ unregister_usb_hub()

void unregister_usb_hub ( struct usb_hub hub)

Unregister USB hub.

Parameters
hubUSB hub

Definition at line 2030 of file usb.c.

2030  {
2031  struct usb_port *port;
2032  unsigned int i;
2033 
2034  /* Detach all devices */
2035  for ( i = 1 ; i <= hub->ports ; i++ ) {
2036  port = usb_port ( hub, i );
2037  if ( port->attached )
2038  usb_detached ( port );
2039  }
2040 
2041  /* Close hub (driver) */
2042  hub->driver->close ( hub );
2043 
2044  /* Close hub (host controller) */
2045  hub->host->close ( hub );
2046 
2047  /* Cancel any pending port status changes */
2048  for ( i = 1 ; i <= hub->ports ; i++ ) {
2049  port = usb_port ( hub, i );
2050  list_del ( &port->changed );
2051  INIT_LIST_HEAD ( &port->changed );
2052  }
2053 
2054  /* Remove from hub list */
2055  list_del ( &hub->list );
2056 }
static void usb_detached(struct usb_port *port)
Handle newly detached USB device.
Definition: usb.c:1795
struct usb_hub_host_operations * host
Host controller operations.
Definition: usb.h:857
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
A USB port.
Definition: usb.h:813
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:859
void(* close)(struct usb_hub *hub)
Close hub.
Definition: usb.h:882
unsigned int ports
Number of ports.
Definition: usb.h:851
void(* close)(struct usb_hub *hub)
Close hub.
Definition: usb.h:897
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
struct list_head list
List of hubs.
Definition: usb.h:854
struct usb_hub * hub
USB hub.
Definition: usb.h:815
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:960

References usb_hub_host_operations::close, usb_hub_driver_operations::close, usb_hub::driver, usb_hub::host, usb_port::hub, INIT_LIST_HEAD, usb_hub::list, list_del, port, usb_hub::ports, usb_detached(), and usb_port().

Referenced by hub_probe(), hub_remove(), register_usb_bus(), and unregister_usb_bus().

◆ free_usb_hub()

void free_usb_hub ( struct usb_hub hub)

Free USB hub.

Parameters
hubUSB hub

Definition at line 2063 of file usb.c.

2063  {
2064  struct usb_port *port;
2065  unsigned int i;
2066 
2067  /* Sanity checks */
2068  for ( i = 1 ; i <= hub->ports ; i++ ) {
2069  port = usb_port ( hub, i );
2070  assert ( ! port->attached );
2071  assert ( port->usb == NULL );
2072  assert ( list_empty ( &port->changed ) );
2073  }
2074 
2075  /* Free hub */
2076  free ( hub );
2077 }
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
A USB port.
Definition: usb.h:813
u8 port
Port number.
Definition: CIB_PRM.h:31
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
unsigned int ports
Number of ports.
Definition: usb.h:851
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
struct usb_hub * hub
USB hub.
Definition: usb.h:815
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:960
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References assert(), free, usb_port::hub, list_empty, NULL, port, usb_hub::ports, and usb_port().

Referenced by alloc_usb_bus(), free_usb_bus(), hub_probe(), and hub_remove().

◆ alloc_usb_bus()

struct usb_bus* alloc_usb_bus ( struct device dev,
unsigned int  ports,
size_t  mtu,
struct usb_host_operations op 
)

Allocate USB bus.

Parameters
devUnderlying hardware device
portsNumber of root hub ports
mtuLargest transfer allowed on the bus
opHost controller operations
Return values
busUSB bus, or NULL on allocation failure

Definition at line 2095 of file usb.c.

2096  {
2097  struct usb_bus *bus;
2098 
2099  /* Allocate and initialise structure */
2100  bus = zalloc ( sizeof ( *bus ) );
2101  if ( ! bus )
2102  goto err_alloc_bus;
2103  bus->name = dev->name;
2104  bus->dev = dev;
2105  bus->mtu = mtu;
2106  bus->op = op;
2107  INIT_LIST_HEAD ( &bus->devices );
2108  INIT_LIST_HEAD ( &bus->hubs );
2109  bus->host = &bus->op->bus;
2110 
2111  /* Allocate root hub */
2112  bus->hub = alloc_usb_hub ( bus, NULL, ports, &op->root );
2113  if ( ! bus->hub )
2114  goto err_alloc_hub;
2115 
2116  return bus;
2117 
2118  free_usb_hub ( bus->hub );
2119  err_alloc_hub:
2120  free ( bus );
2121  err_alloc_bus:
2122  return NULL;
2123 }
char name[40]
Name.
Definition: device.h:79
struct device * dev
Underlying hardware device.
Definition: usb.h:970
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
void free_usb_hub(struct usb_hub *hub)
Free USB hub.
Definition: usb.c:2063
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15
struct usb_hub * alloc_usb_hub(struct usb_bus *bus, struct usb_device *usb, unsigned int ports, struct usb_hub_driver_operations *driver)
Allocate USB hub.
Definition: usb.c:1937

References alloc_usb_hub(), bus, usb_bus::dev, free, free_usb_hub(), INIT_LIST_HEAD, mtu, device::name, NULL, op, and zalloc().

Referenced by ehci_probe(), uhci_probe(), usbio_start(), and xhci_register().

◆ register_usb_bus()

int register_usb_bus ( struct usb_bus bus)

Register USB bus.

Parameters
busUSB bus
Return values
rcReturn status code

Definition at line 2131 of file usb.c.

2131  {
2132  int rc;
2133 
2134  /* Sanity checks */
2135  assert ( bus->hub != NULL );
2136 
2137  /* Assign the first available bus address */
2138  bus->address = 0;
2139  while ( find_usb_bus ( bus->address ) != NULL )
2140  bus->address++;
2141 
2142  /* Open bus */
2143  if ( ( rc = bus->host->open ( bus ) ) != 0 )
2144  goto err_open;
2145 
2146  /* Add to list of USB buses */
2147  list_add_tail ( &bus->list, &usb_buses );
2148 
2149  /* Register root hub */
2150  if ( ( rc = register_usb_hub ( bus->hub ) ) != 0 )
2151  goto err_register_hub;
2152 
2153  /* Attach any devices already present */
2154  usb_hotplug();
2155 
2156  return 0;
2157 
2158  unregister_usb_hub ( bus->hub );
2159  err_register_hub:
2160  list_del ( &bus->list );
2161  bus->host->close ( bus );
2162  err_open:
2163  return rc;
2164 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void usb_hotplug(void)
Handle newly attached or detached USB device.
Definition: usb.c:1869
struct usb_bus * find_usb_bus(unsigned int address)
Find USB bus by address.
Definition: usb.c:2220
void unregister_usb_hub(struct usb_hub *hub)
Unregister USB hub.
Definition: usb.c:2030
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
struct list_head usb_buses
List of USB buses.
Definition: usb.c:45
int register_usb_hub(struct usb_hub *hub)
Register USB hub.
Definition: usb.c:1976
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
uint8_t bus
Bus.
Definition: edd.h:15

References assert(), bus, find_usb_bus(), list_add_tail, list_del, NULL, rc, register_usb_hub(), unregister_usb_hub(), usb_buses, and usb_hotplug().

Referenced by ehci_probe(), uhci_probe(), usbio_start(), and xhci_register().

◆ unregister_usb_bus()

void unregister_usb_bus ( struct usb_bus bus)

Unregister USB bus.

Parameters
busUSB bus

Definition at line 2171 of file usb.c.

2171  {
2172 
2173  /* Sanity checks */
2174  assert ( bus->hub != NULL );
2175 
2176  /* Unregister root hub */
2177  unregister_usb_hub ( bus->hub );
2178 
2179  /* Remove from list of USB buses */
2180  list_del ( &bus->list );
2181 
2182  /* Close bus */
2183  bus->host->close ( bus );
2184 
2185  /* Sanity checks */
2186  assert ( list_empty ( &bus->devices ) );
2187  assert ( list_empty ( &bus->hubs ) );
2188 }
void unregister_usb_hub(struct usb_hub *hub)
Unregister USB hub.
Definition: usb.c:2030
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
uint8_t bus
Bus.
Definition: edd.h:15

References assert(), bus, list_del, list_empty, NULL, and unregister_usb_hub().

Referenced by ehci_probe(), ehci_remove(), uhci_probe(), uhci_remove(), usbio_start(), usbio_stop(), xhci_register(), and xhci_unregister().

◆ free_usb_bus()

void free_usb_bus ( struct usb_bus bus)

Free USB bus.

Parameters
busUSB bus

Definition at line 2195 of file usb.c.

2195  {
2196  struct usb_endpoint *ep;
2197  struct usb_port *port;
2198 
2199  /* Sanity checks */
2200  assert ( list_empty ( &bus->devices ) );
2201  assert ( list_empty ( &bus->hubs ) );
2202  list_for_each_entry ( ep, &usb_halted, halted )
2203  assert ( ep->usb->port->hub->bus != bus );
2205  assert ( port->hub->bus != bus );
2206 
2207  /* Free root hub */
2208  free_usb_hub ( bus->hub );
2209 
2210  /* Free bus */
2211  free ( bus );
2212 }
struct list_head changed
List of changed ports.
Definition: usb.h:837
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
A USB port.
Definition: usb.h:813
A USB endpoint.
Definition: usb.h:404
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:727
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void free_usb_hub(struct usb_hub *hub)
Free USB hub.
Definition: usb.c:2063
static struct list_head usb_halted
List of halted endpoints.
Definition: usb.c:51
struct usb_hub * hub
USB hub.
Definition: usb.h:815
struct usb_device * usb
USB device.
Definition: usb.h:406
static struct list_head usb_changed
List of changed ports.
Definition: usb.c:48
struct usb_bus * bus
USB bus.
Definition: usb.h:845
uint8_t bus
Bus.
Definition: edd.h:15

References assert(), bus, usb_hub::bus, usb_port::changed, free, free_usb_hub(), usb_port::hub, list_empty, list_for_each_entry, port, usb_device::port, usb_endpoint::usb, usb_changed, and usb_halted.

Referenced by ehci_probe(), ehci_remove(), uhci_probe(), uhci_remove(), usbio_start(), usbio_stop(), xhci_register(), and xhci_unregister().

◆ find_usb_bus()

struct usb_bus* find_usb_bus ( unsigned int  address)

Find USB bus by address.

Parameters
addressBus address
Return values
busUSB bus, or NULL

Definition at line 2220 of file usb.c.

2220  {
2221  struct usb_bus *bus;
2222 
2223  for_each_usb_bus ( bus ) {
2224  if ( bus->address == address )
2225  return bus;
2226  }
2227 
2228  return NULL;
2229 }
uint64_t address
Base address.
Definition: ena.h:24
#define for_each_usb_bus(bus)
Iterate over all USB buses.
Definition: usb.h:1077
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15

References address, bus, for_each_usb_bus, and NULL.

Referenced by register_usb_bus(), usb_find_next(), and usb_settings_fetch().

◆ find_usb_bus_by_location()

struct usb_bus* find_usb_bus_by_location ( unsigned int  bus_type,
unsigned int  location 
)

Find USB bus by device location.

Parameters
bus_typeBus type
locationBus location
Return values
busUSB bus, or NULL

Definition at line 2238 of file usb.c.

2239  {
2240  struct usb_bus *bus;
2241 
2242  for_each_usb_bus ( bus ) {
2243  if ( ( bus->dev->desc.bus_type == bus_type ) &&
2244  ( bus->dev->desc.location == location ) )
2245  return bus;
2246  }
2247 
2248  return NULL;
2249 }
#define for_each_usb_bus(bus)
Iterate over all USB buses.
Definition: usb.h:1077
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15

References bus, for_each_usb_bus, and NULL.

Referenced by uhci_root_speed().

◆ usb_alloc_address()

int usb_alloc_address ( struct usb_bus bus)

Allocate device address.

Parameters
busUSB bus
Return values
addressDevice address, or negative error

Definition at line 2264 of file usb.c.

2264  {
2265  unsigned int address;
2266 
2267  /* Find first free device address */
2268  address = ffsll ( ~bus->addresses );
2269  if ( ! address )
2270  return -ENOENT;
2271 
2272  /* Mark address as used */
2273  bus->addresses |= ( 1ULL << ( address - 1 ) );
2274 
2275  return address;
2276 }
uint64_t address
Base address.
Definition: ena.h:24
#define ENOENT
No such file or directory.
Definition: errno.h:515
#define ffsll(x)
Find first (i.e.
Definition: strings.h:123
uint8_t bus
Bus.
Definition: edd.h:15

References address, bus, ENOENT, and ffsll.

Referenced by ehci_device_address(), and uhci_device_address().

◆ usb_free_address()

void usb_free_address ( struct usb_bus bus,
unsigned int  address 
)

Free device address.

Parameters
busUSB bus
addressDevice address

Definition at line 2284 of file usb.c.

2284  {
2285 
2286  /* Sanity check */
2287  assert ( address > 0 );
2288  assert ( bus->addresses & ( 1ULL << ( address - 1 ) ) );
2289 
2290  /* Mark address as free */
2291  bus->addresses &= ~( 1ULL << ( address - 1 ) );
2292 }
uint64_t address
Base address.
Definition: ena.h:24
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint8_t bus
Bus.
Definition: edd.h:15

References address, assert(), and bus.

Referenced by ehci_device_address(), ehci_device_close(), uhci_device_address(), and uhci_device_close().

◆ usb_find_next()

int usb_find_next ( struct usb_device **  usb,
uint16_t busdev 
)

Find next USB device.

Parameters
usbUSB device to fill in
busdevStarting bus:dev address
Return values
busdevBus:dev address of next USB device
rcReturn status code

Definition at line 2302 of file usb.c.

2302  {
2303  struct usb_bus *bus;
2304 
2305  do {
2306  /* Find USB bus, if any */
2307  bus = find_usb_bus ( USB_BUS ( *busdev ) );
2308  if ( ! bus ) {
2309  *busdev |= ( USB_BUS ( 1 ) - 1 );
2310  continue;
2311  }
2312 
2313  /* Find USB device, if any */
2314  *usb = find_usb ( bus, USB_DEV ( *busdev ) );
2315  if ( *usb )
2316  return 0;
2317 
2318  } while ( ++(*busdev) );
2319 
2320  return -ENODEV;
2321 }
#define USB_BUS(busdev)
Extract USB bus address.
Definition: usb.h:67
struct usb_bus * find_usb_bus(unsigned int address)
Find USB bus by address.
Definition: usb.c:2220
struct usb_device * find_usb(struct usb_bus *bus, unsigned int address)
Find USB device by address.
Definition: usb.c:1735
#define ENODEV
No such device.
Definition: errno.h:510
A USB bus.
Definition: usb.h:966
uint8_t bus
Bus.
Definition: edd.h:15
#define USB_DEV(busdev)
Extract USB device address.
Definition: usb.h:70

References bus, ENODEV, find_usb(), find_usb_bus(), USB_BUS, and USB_DEV.

Referenced by usbscan_exec().

◆ usb_route_string()

unsigned int usb_route_string ( struct usb_device usb)

Get USB route string.

Parameters
usbUSB device
Return values
routeUSB route string

Definition at line 2336 of file usb.c.

2336  {
2337  struct usb_device *parent;
2338  unsigned int route;
2339 
2340  /* Navigate up to root hub, constructing route string as we go */
2341  for ( route = 0 ; ( parent = usb->port->hub->usb ) ; usb = parent ) {
2342  route <<= 4;
2343  route |= ( ( usb->port->address > 0xf ) ?
2344  0xf : usb->port->address );
2345  }
2346 
2347  return route;
2348 }
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:847
struct usb_port * port
USB port.
Definition: usb.h:727
void route(void)
Print routing table.
Definition: route.c:40
A USB device.
Definition: usb.h:723
unsigned int address
Port address.
Definition: usb.h:817
struct usb_hub * hub
USB hub.
Definition: usb.h:815

References usb_port::address, usb_port::hub, usb_device::port, route(), and usb_hub::usb.

Referenced by xhci_device_address().

◆ usb_root_hub_port()

struct usb_port* usb_root_hub_port ( struct usb_device usb)

Get USB root hub port.

Parameters
usbUSB device
Return values
portRoot hub port

Definition at line 2356 of file usb.c.

2356  {
2357  struct usb_device *parent;
2358 
2359  /* Navigate up to root hub */
2360  while ( ( parent = usb->port->hub->usb ) )
2361  usb = parent;
2362 
2363  return usb->port;
2364 }
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:847
struct usb_port * port
USB port.
Definition: usb.h:727
A USB device.
Definition: usb.h:723
struct usb_hub * hub
USB hub.
Definition: usb.h:815

References usb_port::hub, usb_device::port, and usb_hub::usb.

Referenced by xhci_device_address(), and xhci_device_open().

◆ usb_transaction_translator()

struct usb_port* usb_transaction_translator ( struct usb_device usb)

Get USB transaction translator.

Parameters
usbUSB device
Return values
portTransaction translator port, or NULL

Definition at line 2372 of file usb.c.

2372  {
2373  struct usb_device *parent;
2374 
2375  /* Navigate up to root hub. If we find a low-speed or
2376  * full-speed device with a higher-speed parent hub, then that
2377  * device's port is the transaction translator.
2378  */
2379  for ( ; ( parent = usb->port->hub->usb ) ; usb = parent ) {
2380  if ( ( usb->speed <= USB_SPEED_FULL ) &&
2381  ( parent->speed > USB_SPEED_FULL ) )
2382  return usb->port;
2383  }
2384 
2385  return NULL;
2386 }
unsigned int speed
Device speed.
Definition: usb.h:729
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:847
struct usb_port * port
USB port.
Definition: usb.h:727
A USB device.
Definition: usb.h:723
struct usb_hub * hub
USB hub.
Definition: usb.h:815
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
Full speed (12Mbps)
Definition: usb.h:51

References usb_port::hub, NULL, usb_device::port, usb_device::speed, usb_hub::usb, and USB_SPEED_FULL.

Referenced by ehci_endpoint_capabilities(), usb_endpoint_clear_tt(), and xhci_device_open().

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( register_usb_bus  )

◆ REQUIRE_OBJECT() [1/2]

REQUIRE_OBJECT ( config_usb  )

◆ REQUIRE_OBJECT() [2/2]

REQUIRE_OBJECT ( usbhub  )

Variable Documentation

◆ usb_buses

struct list_head usb_buses = LIST_HEAD_INIT ( usb_buses )

List of USB buses.

Definition at line 45 of file usb.c.

Referenced by register_usb_bus().

◆ usb_changed

struct list_head usb_changed = LIST_HEAD_INIT ( usb_changed )
static

List of changed ports.

Definition at line 48 of file usb.c.

Referenced by free_usb_bus(), usb_hotplug(), and usb_port_changed().

◆ usb_halted

struct list_head usb_halted = LIST_HEAD_INIT ( usb_halted )
static

List of halted endpoints.

Definition at line 51 of file usb.c.

Referenced by free_usb_bus(), usb_complete_err(), and usb_step().

◆ usb_control_operations

struct usb_endpoint_driver_operations usb_control_operations
static
Initial value:
= {
.complete = usb_control_complete,
}
static void usb_control_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete USB control transfer.
Definition: usb.c:755

USB control endpoint driver operations.

Definition at line 769 of file usb.c.

Referenced by alloc_usb().