iPXE
Data Structures | Defines | Enumerations | Functions | Variables
usb.h File Reference

Universal Serial Bus (USB) More...

#include <byteswap.h>
#include <ipxe/list.h>
#include <ipxe/device.h>
#include <ipxe/process.h>
#include <ipxe/iobuf.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  usb_setup_packet
 A USB setup data packet. More...
struct  usb_class
 A USB class code tuple. More...
struct  usb_descriptor_header
 A USB descriptor header. More...
struct  usb_device_descriptor
 A USB device descriptor. More...
struct  usb_configuration_descriptor
 A USB configuration descriptor. More...
struct  usb_string_descriptor
 A USB string descriptor. More...
struct  usb_interface_descriptor
 A USB interface descriptor. More...
struct  usb_endpoint_descriptor
 A USB endpoint descriptor. More...
struct  usb_endpoint_companion_descriptor
 A USB endpoint companion descriptor. More...
struct  usb_interface_association_descriptor
 A USB interface association descriptor. More...
struct  usb_endpoint
 A USB endpoint. More...
struct  usb_endpoint_host_operations
 USB endpoint host controller operations. More...
struct  usb_endpoint_driver_operations
 USB endpoint driver operations. More...
union  usb_class_descriptor
 A USB class descriptor. More...
struct  usb_function_descriptor
 A USB function descriptor. More...
struct  usb_function
 A USB function. More...
struct  usb_device
 A USB device. More...
struct  usb_device_host_operations
 USB device host controller operations. More...
struct  usb_port
 A USB port. More...
struct  usb_hub
 A USB hub. More...
struct  usb_hub_host_operations
 USB hub host controller operations. More...
struct  usb_hub_driver_operations
 USB hub driver operations. More...
struct  usb_bus
 A USB bus. More...
struct  usb_bus_host_operations
 USB bus host controller operations. More...
struct  usb_host_operations
 USB host controller operations. More...
struct  usb_device_id
 A USB device ID. More...
struct  usb_class_id
 A USB class ID. More...
struct  usb_driver
 A USB driver. More...

Defines

#define USB_SPEED(mantissa, exponent)   ( (exponent << 16) | (mantissa) )
 Define a USB speed.
#define USB_SPEED_MANTISSA(speed)   ( (speed) & 0xffff )
 Extract USB speed mantissa.
#define USB_SPEED_EXPONENT(speed)   ( ( (speed) >> 16 ) & 0x3 )
 Extract USB speed exponent.
#define USB_DIR_OUT   ( 0 << 7 )
 Data transfer is from host to device.
#define USB_DIR_IN   ( 1 << 7 )
 Data transfer is from device to host.
#define USB_TYPE_STANDARD   ( 0 << 5 )
 Standard request type.
#define USB_TYPE_CLASS   ( 1 << 5 )
 Class-specific request type.
#define USB_TYPE_VENDOR   ( 2 << 5 )
 Vendor-specific request type.
#define USB_RECIP_MASK   ( 0x1f << 0 )
 Request recipient mask.
#define USB_RECIP_DEVICE   ( 0 << 0 )
 Request recipient is the device.
#define USB_RECIP_INTERFACE   ( 1 << 0 )
 Request recipient is an interface.
#define USB_RECIP_ENDPOINT   ( 2 << 0 )
 Request recipient is an endpoint.
#define USB_REQUEST_TYPE(type)   ( (type) << 8 )
 Construct USB request type.
#define USB_GET_STATUS   ( USB_DIR_IN | USB_REQUEST_TYPE ( 0 ) )
 Get status.
#define USB_CLEAR_FEATURE   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 1 ) )
 Clear feature.
#define USB_SET_FEATURE   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 3 ) )
 Set feature.
#define USB_SET_ADDRESS   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 5 ) )
 Set address.
#define USB_GET_DESCRIPTOR   ( USB_DIR_IN | USB_REQUEST_TYPE ( 6 ) )
 Get descriptor.
#define USB_SET_DESCRIPTOR   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 7 ) )
 Set descriptor.
#define USB_GET_CONFIGURATION   ( USB_DIR_IN | USB_REQUEST_TYPE ( 8 ) )
 Get configuration.
#define USB_SET_CONFIGURATION   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 9 ) )
 Set configuration.
#define USB_GET_INTERFACE   ( USB_DIR_IN | USB_RECIP_INTERFACE | USB_REQUEST_TYPE ( 10 ) )
 Get interface.
#define USB_SET_INTERFACE   ( USB_DIR_OUT | USB_RECIP_INTERFACE | USB_REQUEST_TYPE ( 11 ) )
 Set interface.
#define USB_ENDPOINT_HALT   0
 Endpoint halt feature.
#define USB_CLASS_HUB   9
 Class code for USB hubs.
#define USB_DEVICE_DESCRIPTOR   1
 A USB device descriptor.
#define USB_CONFIGURATION_DESCRIPTOR   2
 A USB configuration descriptor.
#define USB_STRING_DESCRIPTOR   3
 A USB string descriptor.
#define USB_LANG_ENGLISH   0x0409
 Language ID for English.
#define USB_INTERFACE_DESCRIPTOR   4
 A USB interface descriptor.
#define USB_ENDPOINT_DESCRIPTOR   5
 A USB endpoint descriptor.
#define USB_ENDPOINT_ATTR_TYPE_MASK   0x03
 Endpoint attribute transfer type mask.
#define USB_ENDPOINT_ATTR_PERIODIC   0x01
 Endpoint periodic type.
#define USB_ENDPOINT_ATTR_CONTROL   0x00
 Control endpoint transfer type.
#define USB_ENDPOINT_ATTR_BULK   0x02
 Bulk endpoint transfer type.
#define USB_ENDPOINT_ATTR_INTERRUPT   0x03
 Interrupt endpoint transfer type.
#define USB_BULK_OUT   ( USB_ENDPOINT_ATTR_BULK | USB_DIR_OUT )
 Bulk OUT endpoint (internal) type.
#define USB_BULK_IN   ( USB_ENDPOINT_ATTR_BULK | USB_DIR_IN )
 Bulk IN endpoint (internal) type.
#define USB_INTERRUPT_IN   ( USB_ENDPOINT_ATTR_INTERRUPT | USB_DIR_IN )
 Interrupt IN endpoint (internal) type.
#define USB_INTERRUPT_OUT   ( USB_ENDPOINT_ATTR_INTERRUPT | USB_DIR_OUT )
 Interrupt OUT endpoint (internal) type.
#define USB_ENDPOINT_MTU(sizes)   ( ( (sizes) >> 0 ) & 0x07ff )
 USB endpoint MTU.
#define USB_ENDPOINT_BURST(sizes)   ( ( (sizes) >> 11 ) & 0x0003 )
 USB endpoint maximum burst size.
#define USB_ENDPOINT_COMPANION_DESCRIPTOR   48
 A USB endpoint companion descriptor.
#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR   11
 A USB interface association descriptor.
#define USB_CS_INTERFACE_DESCRIPTOR   36
 A class-specific interface descriptor.
#define USB_CS_ENDPOINT_DESCRIPTOR   37
 A class-specific endpoint descriptor.
#define for_each_config_descriptor(desc, config)
 Iterate over all configuration descriptors.
#define for_each_interface_descriptor(desc, config, interface)
 Iterate over all configuration descriptors within an interface descriptor.
#define USB_EP0_ADDRESS   0x00
 Control endpoint address.
#define USB_EP0_ATTRIBUTES   0x00
 Control endpoint attributes.
#define USB_EP0_DEFAULT_MTU(speed)
 Calculate default MTU based on device speed.
#define USB_EP0_BURST   0
 Control endpoint maximum burst size.
#define USB_EP0_INTERVAL   0
 Control endpoint interval.
#define USB_ENDPOINT_MAX   0x0f
 Maximum endpoint number.
#define USB_ENDPOINT_IN   0x80
 Endpoint direction is in.
#define USB_ENDPOINT_IDX(address)
 Construct endpoint index from endpoint address.
#define for_each_usb_bus(bus)   list_for_each_entry ( (bus), &usb_buses, list )
 Iterate over all USB buses.
#define USB_RESET_DELAY_MS   50
 Minimum reset time.
#define USB_RESET_RECOVER_DELAY_MS   10
 Reset recovery time.
#define USB_CONTROL_MAX_WAIT_MS   5000
 Maximum time to wait for a control transaction to complete.
#define USB_SET_ADDRESS_RECOVER_DELAY_MS   2
 Set address recovery time.
#define USB_PORT_DELAY_MS   200
 Time to wait for ports to stabilise.
#define USB_ANY_ID   0xffff
 Match-anything ID.
#define USB_CLASS_ID(base, subclass, protocol)
 Construct USB class ID.
#define USB_DRIVERS   __table ( struct usb_driver, "usb_drivers" )
 USB driver table.
#define __usb_driver   __table_entry ( USB_DRIVERS, 01 )
 Declare a USB driver.

Enumerations

enum  usb_protocol { USB_PROTO_2_0 = 0x0200, USB_PROTO_3_0 = 0x0300, USB_PROTO_3_1 = 0x0301 }
 USB protocols. More...
enum  usb_speed {
  USB_SPEED_NONE = 0, USB_SPEED_LOW = USB_SPEED ( 1500, 1 ), USB_SPEED_FULL = USB_SPEED ( 12, 2 ), USB_SPEED_HIGH = USB_SPEED ( 480, 2 ),
  USB_SPEED_SUPER = USB_SPEED ( 5, 3 )
}
 USB device speeds. More...
enum  usb_pid { USB_PID_IN = 0x69, USB_PID_OUT = 0xe1, USB_PID_SETUP = 0x2d }
 USB packet IDs. More...
enum  usb_driver_score { USB_SCORE_FALLBACK = 0, USB_SCORE_DEPRECATED = 1, USB_SCORE_NORMAL = 2 }
 USB driver scores. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static struct
usb_descriptor_header
usb_next_descriptor (struct usb_descriptor_header *desc)
 Get next USB descriptor.
static int usb_is_within_config (struct usb_configuration_descriptor *config, struct usb_descriptor_header *desc)
 Check that descriptor lies within a configuration descriptor.
static void usb_endpoint_init (struct usb_endpoint *ep, struct usb_device *usb, struct usb_endpoint_driver_operations *driver)
 Initialise USB endpoint.
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.
static void usb_endpoint_set_hostdata (struct usb_endpoint *ep, void *priv)
 Set USB endpoint host controller private data.
static void * usb_endpoint_get_hostdata (struct usb_endpoint *ep)
 Get USB endpoint host controller private data.
const char * usb_endpoint_name (struct usb_endpoint *ep)
 Get USB endpoint name (for debugging)
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.
int usb_endpoint_open (struct usb_endpoint *ep)
 Open USB endpoint.
void usb_endpoint_close (struct usb_endpoint *ep)
 Close USB endpoint.
int usb_message (struct usb_endpoint *ep, unsigned int request, unsigned int value, unsigned int index, struct io_buffer *iobuf)
 Enqueue USB message transfer.
int usb_stream (struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
 Enqueue USB stream transfer.
void usb_complete_err (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete transfer (possibly with error)
static void usb_refill_init (struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
 Initialise USB endpoint refill.
static void usb_recycle (struct usb_endpoint *ep, struct io_buffer *iobuf)
 Recycle I/O buffer.
int usb_prefill (struct usb_endpoint *ep)
 Prefill endpoint recycled buffer list.
int usb_refill (struct usb_endpoint *ep)
 Refill endpoint.
void usb_flush (struct usb_endpoint *ep)
 Discard endpoint recycled buffer list.
static void usb_func_set_drvdata (struct usb_function *func, void *priv)
 Set USB function driver private data.
static void * usb_func_get_drvdata (struct usb_function *func)
 Get USB function driver private data.
static void usb_set_hostdata (struct usb_device *usb, void *priv)
 Set USB device host controller private data.
static void * usb_get_hostdata (struct usb_device *usb)
 Get USB device host controller private data.
static struct usb_endpointusb_endpoint (struct usb_device *usb, unsigned int address)
 Get USB endpoint.
static void usb_hub_set_drvdata (struct usb_hub *hub, void *priv)
 Set USB hub driver private data.
static void * usb_hub_get_drvdata (struct usb_hub *hub)
 Get USB hub driver private data.
static struct usb_portusb_port (struct usb_hub *hub, unsigned int address)
 Get USB port.
static void usb_bus_set_hostdata (struct usb_bus *bus, void *priv)
 Set USB bus host controller private data.
static void * usb_bus_get_hostdata (struct usb_bus *bus)
 Get USB bus host controller private data.
static void usb_poll (struct usb_bus *bus)
 Poll USB bus.
static void usb_complete (struct usb_endpoint *ep, struct io_buffer *iobuf)
 Complete transfer (without error)
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.
int usb_get_string_descriptor (struct usb_device *usb, unsigned int index, unsigned int language, char *buf, size_t len)
 Get USB string descriptor.
static int usb_get_status (struct usb_device *usb, unsigned int type, unsigned int index, void *data, size_t len)
 Get status.
static int usb_clear_feature (struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
 Clear feature.
static int usb_set_feature (struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
 Set feature.
static int usb_set_address (struct usb_device *usb, unsigned int address)
 Set address.
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.
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)
static int usb_get_device_descriptor (struct usb_device *usb, struct usb_device_descriptor *data)
 Get USB device descriptor.
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.
static int usb_set_configuration (struct usb_device *usb, unsigned int index)
 Set USB configuration.
static int usb_set_interface (struct usb_device *usb, unsigned int interface, unsigned int alternate)
 Set USB interface alternate setting.
struct usb_interface_descriptorusb_interface_descriptor (struct usb_configuration_descriptor *config, unsigned int interface, unsigned int alternate)
 Locate USB interface descriptor.
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.
struct
usb_endpoint_companion_descriptor
usb_endpoint_companion_descriptor (struct usb_configuration_descriptor *config, struct usb_endpoint_descriptor *desc)
 Locate USB endpoint companion descriptor.
struct usb_huballoc_usb_hub (struct usb_bus *bus, struct usb_device *usb, unsigned int ports, struct usb_hub_driver_operations *op)
 Allocate USB hub.
int register_usb_hub (struct usb_hub *hub)
 Register USB hub.
void unregister_usb_hub (struct usb_hub *hub)
 Unregister USB hub.
void free_usb_hub (struct usb_hub *hub)
 Free USB hub.
void usb_port_changed (struct usb_port *port)
 Report port status change.
struct usb_busalloc_usb_bus (struct device *dev, unsigned int ports, size_t mtu, struct usb_host_operations *op)
 Allocate USB bus.
int register_usb_bus (struct usb_bus *bus)
 Register USB bus.
void unregister_usb_bus (struct usb_bus *bus)
 Unregister USB bus.
void free_usb_bus (struct usb_bus *bus)
 Free USB bus.
struct usb_busfind_usb_bus_by_location (unsigned int bus_type, unsigned int location)
 Find USB bus by device location.
int usb_alloc_address (struct usb_bus *bus)
 Allocate device address.
void usb_free_address (struct usb_bus *bus, unsigned int address)
 Free device address.
unsigned int usb_route_string (struct usb_device *usb)
 Get USB route string.
unsigned int usb_depth (struct usb_device *usb)
 Get USB depth.
struct usb_portusb_root_hub_port (struct usb_device *usb)
 Get USB root hub port.
struct usb_portusb_transaction_translator (struct usb_device *usb)
 Get USB transaction translator.
struct usb_driverusb_find_driver (struct usb_function_descriptor *desc, struct usb_device_id **id)
 Find USB device driver.

Variables

struct list_head usb_buses
 List of USB buses.

Detailed Description

Universal Serial Bus (USB)

Definition in file usb.h.


Define Documentation

#define USB_SPEED (   mantissa,
  exponent 
)    ( (exponent << 16) | (mantissa) )

Define a USB speed.

Parameters:
mantissaMantissa
exponentExponent (in engineering terms: 1=k, 2=M, 3=G)
Return values:
speedUSB speed

Definition at line 35 of file usb.h.

Referenced by xhci_port_psiv(), and xhci_port_speed().

#define USB_SPEED_MANTISSA (   speed)    ( (speed) & 0xffff )

Extract USB speed mantissa.

Definition at line 38 of file usb.h.

Referenced by usb_speed_name().

#define USB_SPEED_EXPONENT (   speed)    ( ( (speed) >> 16 ) & 0x3 )

Extract USB speed exponent.

Definition at line 41 of file usb.h.

Referenced by usb_speed_name().

#define USB_DIR_OUT   ( 0 << 7 )

Data transfer is from host to device.

Definition at line 80 of file usb.h.

#define USB_DIR_IN   ( 1 << 7 )
#define USB_TYPE_STANDARD   ( 0 << 5 )

Standard request type.

Definition at line 86 of file usb.h.

#define USB_TYPE_CLASS   ( 1 << 5 )

Class-specific request type.

Definition at line 89 of file usb.h.

Referenced by usb_hub_clear_port_feature(), usb_hub_get_descriptor(), usb_hub_get_port_status(), and usb_hub_set_port_feature().

#define USB_TYPE_VENDOR   ( 2 << 5 )

Vendor-specific request type.

Definition at line 92 of file usb.h.

#define USB_RECIP_MASK   ( 0x1f << 0 )

Request recipient mask.

Definition at line 95 of file usb.h.

Referenced by usbio_control_poll().

#define USB_RECIP_DEVICE   ( 0 << 0 )

Request recipient is the device.

Definition at line 98 of file usb.h.

#define USB_RECIP_INTERFACE   ( 1 << 0 )

Request recipient is an interface.

Definition at line 101 of file usb.h.

Referenced by usbio_control_poll().

#define USB_RECIP_ENDPOINT   ( 2 << 0 )

Request recipient is an endpoint.

Definition at line 104 of file usb.h.

Referenced by usb_endpoint_reset().

#define USB_REQUEST_TYPE (   type)    ( (type) << 8 )

Construct USB request type.

Definition at line 107 of file usb.h.

Referenced by efi_usb_control_transfer().

#define USB_GET_STATUS   ( USB_DIR_IN | USB_REQUEST_TYPE ( 0 ) )

Get status.

Definition at line 110 of file usb.h.

Referenced by usb_get_status().

Clear feature.

Definition at line 113 of file usb.h.

Referenced by usb_clear_feature().

#define USB_SET_FEATURE   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 3 ) )

Set feature.

Definition at line 116 of file usb.h.

Referenced by usb_set_feature().

#define USB_SET_ADDRESS   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 5 ) )

Set address.

Definition at line 119 of file usb.h.

Referenced by usb_set_address().

Get descriptor.

Definition at line 122 of file usb.h.

Referenced by usb_get_descriptor(), and usbio_config().

Set descriptor.

Definition at line 125 of file usb.h.

Get configuration.

Definition at line 128 of file usb.h.

Set configuration.

Definition at line 131 of file usb.h.

Referenced by efi_usb_control_transfer(), usb_set_configuration(), and usbio_control_poll().

Get interface.

Definition at line 134 of file usb.h.

Set interface.

Definition at line 138 of file usb.h.

Referenced by efi_usb_control_transfer(), and usb_set_interface().

#define USB_ENDPOINT_HALT   0

Endpoint halt feature.

Definition at line 142 of file usb.h.

Referenced by usb_endpoint_reset().

#define USB_CLASS_HUB   9

Class code for USB hubs.

Definition at line 155 of file usb.h.

#define USB_DEVICE_DESCRIPTOR   1

A USB device descriptor.

Definition at line 192 of file usb.h.

A USB configuration descriptor.

Definition at line 213 of file usb.h.

Referenced by usb_get_config_descriptor(), and usbio_config().

#define USB_STRING_DESCRIPTOR   3

A USB string descriptor.

Definition at line 224 of file usb.h.

Referenced by efi_usb_get_string_descriptor(), efi_usb_probe(), usb_get_default_language(), and usb_get_string_descriptor().

#define USB_LANG_ENGLISH   0x0409

Language ID for English.

Definition at line 227 of file usb.h.

Referenced by usb_get_default_language().

#define USB_INTERFACE_DESCRIPTOR   4

A USB interface descriptor.

Definition at line 246 of file usb.h.

#define USB_ENDPOINT_DESCRIPTOR   5

A USB endpoint descriptor.

Definition at line 263 of file usb.h.

#define USB_ENDPOINT_ATTR_TYPE_MASK   0x03
#define USB_ENDPOINT_ATTR_PERIODIC   0x01

Endpoint periodic type.

Definition at line 269 of file usb.h.

Referenced by usb_endpoint_clear_tt().

#define USB_ENDPOINT_ATTR_CONTROL   0x00

Control endpoint transfer type.

Definition at line 272 of file usb.h.

Referenced by ehci_endpoint_characteristics(), usb_endpoint_reset(), usbio_endpoint_open(), and xhci_endpoint_open().

#define USB_ENDPOINT_ATTR_BULK   0x02

Bulk endpoint transfer type.

Definition at line 275 of file usb.h.

Referenced by efi_usb_bulk_transfer(), and usbio_endpoint_open().

#define USB_ENDPOINT_ATTR_INTERRUPT   0x03

Bulk OUT endpoint (internal) type.

Definition at line 281 of file usb.h.

Referenced by usbnet_data_describe().

Bulk IN endpoint (internal) type.

Definition at line 284 of file usb.h.

Referenced by usbnet_data_describe().

Interrupt IN endpoint (internal) type.

Definition at line 287 of file usb.h.

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

Interrupt OUT endpoint (internal) type.

Definition at line 290 of file usb.h.

Referenced by usbhid_describe().

#define USB_ENDPOINT_MTU (   sizes)    ( ( (sizes) >> 0 ) & 0x07ff )

USB endpoint MTU.

Definition at line 293 of file usb.h.

Referenced by efi_usb_mtu(), and usb_endpoint_described().

#define USB_ENDPOINT_BURST (   sizes)    ( ( (sizes) >> 11 ) & 0x0003 )

USB endpoint maximum burst size.

Definition at line 296 of file usb.h.

Referenced by usb_endpoint_described().

A USB endpoint companion descriptor.

Definition at line 311 of file usb.h.

Referenced by usb_endpoint_companion_descriptor().

A USB interface association descriptor.

Definition at line 328 of file usb.h.

Referenced by usb_interface_association_descriptor().

#define USB_CS_INTERFACE_DESCRIPTOR   36

A class-specific interface descriptor.

Definition at line 331 of file usb.h.

Referenced by cdc_union_descriptor(), and ecm_ethernet_descriptor().

#define USB_CS_ENDPOINT_DESCRIPTOR   37

A class-specific endpoint descriptor.

Definition at line 334 of file usb.h.

#define for_each_config_descriptor (   desc,
  config 
)
Value:
for ( desc = container_of ( &(config)->header,                     \
                                    typeof ( *desc ), header ) ;           \
              usb_is_within_config ( (config), &desc->header ) ;           \
              desc = container_of ( usb_next_descriptor ( &desc->header ), \
                                    typeof ( *desc ), header ) )

Iterate over all configuration descriptors.

Definition at line 371 of file usb.h.

Referenced by usb_interface_association_descriptor(), usb_interface_descriptor(), and usbio_interface().

#define for_each_interface_descriptor (   desc,
  config,
  interface 
)
Value:
for ( desc = container_of ( usb_next_descriptor ( &(interface)->   \
                                                          header ),        \
                                    typeof ( *desc ), header ) ;           \
              ( usb_is_within_config ( (config), &desc->header ) &&        \
                ( desc->header.type != USB_INTERFACE_DESCRIPTOR ) ) ;      \
              desc = container_of ( usb_next_descriptor ( &desc->header ), \
                                    typeof ( *desc ), header ) )

Iterate over all configuration descriptors within an interface descriptor.

Definition at line 379 of file usb.h.

Referenced by cdc_union_descriptor(), ecm_ethernet_descriptor(), efi_usb_get_endpoint_descriptor(), efi_usb_mtu(), usb_endpoint_descriptor(), and usbio_interface().

#define USB_EP0_ADDRESS   0x00

Control endpoint address.

Definition at line 486 of file usb.h.

Referenced by ehci_device_address(), register_usb(), uhci_device_address(), usb_deconfigure(), and usbio_interface().

#define USB_EP0_ATTRIBUTES   0x00

Control endpoint attributes.

Definition at line 489 of file usb.h.

Referenced by register_usb().

#define USB_EP0_DEFAULT_MTU (   speed)
Value:
( ( (speed) >= USB_SPEED_SUPER ) ? 512 :        \
          ( ( (speed) >= USB_SPEED_FULL ) ? 64 : 8 ) )

Calculate default MTU based on device speed.

Parameters:
speedDevice speed
Return values:
mtuDefault MTU

Definition at line 496 of file usb.h.

Referenced by register_usb().

#define USB_EP0_BURST   0

Control endpoint maximum burst size.

Definition at line 501 of file usb.h.

Referenced by register_usb().

#define USB_EP0_INTERVAL   0

Control endpoint interval.

Definition at line 504 of file usb.h.

Referenced by register_usb().

#define USB_ENDPOINT_MAX   0x0f

Maximum endpoint number.

Definition at line 507 of file usb.h.

Referenced by usb_endpoint_name(), and usb_hub_clear_tt_buffer().

#define USB_ENDPOINT_IN   0x80
#define USB_ENDPOINT_IDX (   address)
Value:
( ( (address) & USB_ENDPOINT_MAX ) |                            \
          ( ( (address) & USB_ENDPOINT_IN ) >> 3 ) )

Construct endpoint index from endpoint address.

Definition at line 513 of file usb.h.

Referenced by efi_usb_async_start(), efi_usb_async_stop(), efi_usb_close(), efi_usb_open(), efi_usb_sync_transfer(), usb_deconfigure(), usb_endpoint(), usb_endpoint_close(), and usb_endpoint_open().

#define for_each_usb_bus (   bus)    list_for_each_entry ( (bus), &usb_buses, list )

Iterate over all USB buses.

Definition at line 1054 of file usb.h.

Referenced by ehci_poll_companions(), find_usb_bus_by_location(), and usb_step().

#define USB_RESET_DELAY_MS   50

Minimum reset time.

Section 7.1.7.5 of the USB2 specification states that root hub ports should assert reset signalling for at least 50ms.

Definition at line 1284 of file usb.h.

Referenced by ehci_root_enable(), and uhci_root_enable().

#define USB_RESET_RECOVER_DELAY_MS   10

Reset recovery time.

Section 9.2.6.2 of the USB2 specification states that the "recovery" interval after a port reset is 10ms.

Definition at line 1291 of file usb.h.

Referenced by register_usb(), and uhci_root_enable().

#define USB_CONTROL_MAX_WAIT_MS   5000

Maximum time to wait for a control transaction to complete.

Section 9.2.6.1 of the USB2 specification states that the upper limit for commands to be processed is 5 seconds.

Definition at line 1298 of file usb.h.

Referenced by usb_control().

Set address recovery time.

Section 9.2.6.3 of the USB2 specification states that devices are allowed a 2ms recovery interval after receiving a new address.

Definition at line 1305 of file usb.h.

Referenced by register_usb().

#define USB_PORT_DELAY_MS   200

Time to wait for ports to stabilise.

Section 7.1.7.3 of the USB specification states that we must allow 100ms for devices to signal attachment, and an additional 100ms for connection debouncing. (This delay is parallelised across all ports on a hub; we do not delay separately for each port.)

Definition at line 1314 of file usb.h.

Referenced by register_usb_hub().

#define USB_ANY_ID   0xffff

Match-anything ID.

Definition at line 1329 of file usb.h.

Referenced by usb_find_driver().

#define USB_CLASS_ID (   base,
  subclass,
  protocol 
)
Value:
{                       \
        .class = {                                                      \
                .class = {                                              \
                        ( (base) & 0xff ),                              \
                        ( (subclass) & 0xff ),                          \
                        ( (protocol) & 0xff ),                          \
                },                                                      \
        },                                                              \
        .mask = {                                                       \
                .class = {                                              \
                        ( ( (base) == USB_ANY_ID ) ? 0x00 : 0xff ),     \
                        ( ( (subclass) == USB_ANY_ID ) ? 0x00 : 0xff ), \
                        ( ( (protocol) == USB_ANY_ID ) ? 0x00 : 0xff ), \
                },                                                      \
                },                                                      \
        }

Construct USB class ID.

Parameters:
baseBase class code (or USB_ANY_ID)
subclassSubclass code (or USB_ANY_ID)
protocolProtocol code (or USB_ANY_ID)

Definition at line 1345 of file usb.h.

#define USB_DRIVERS   __table ( struct usb_driver, "usb_drivers" )

USB driver table.

Definition at line 1394 of file usb.h.

Referenced by usb_find_driver().

struct usb_driver rf_rndis_driver __usb_driver   __table_entry ( USB_DRIVERS, 01 )

Declare a USB driver.

USB RF-RNDIS driver.

Definition at line 1397 of file usb.h.


Enumeration Type Documentation

USB protocols.

Enumerator:
USB_PROTO_2_0 

USB 2.0.

USB_PROTO_3_0 

USB 3.0.

USB_PROTO_3_1 

USB 3.1.

Definition at line 20 of file usb.h.

                  {
        /** USB 2.0 */
        USB_PROTO_2_0 = 0x0200,
        /** USB 3.0 */
        USB_PROTO_3_0 = 0x0300,
        /** USB 3.1 */
        USB_PROTO_3_1 = 0x0301,
};
enum usb_speed

USB device speeds.

Enumerator:
USB_SPEED_NONE 

Not connected.

USB_SPEED_LOW 

Low speed (1.5Mbps)

USB_SPEED_FULL 

Full speed (12Mbps)

USB_SPEED_HIGH 

High speed (480Mbps)

USB_SPEED_SUPER 

Super speed (5Gbps)

Definition at line 44 of file usb.h.

               {
        /** Not connected */
        USB_SPEED_NONE = 0,
        /** Low speed (1.5Mbps) */
        USB_SPEED_LOW = USB_SPEED ( 1500, 1 ),
        /** Full speed (12Mbps) */
        USB_SPEED_FULL = USB_SPEED ( 12, 2 ),
        /** High speed (480Mbps) */
        USB_SPEED_HIGH = USB_SPEED ( 480, 2 ),
        /** Super speed (5Gbps) */
        USB_SPEED_SUPER = USB_SPEED ( 5, 3 ),
};
enum usb_pid

USB packet IDs.

Enumerator:
USB_PID_IN 

IN PID.

USB_PID_OUT 

OUT PID.

USB_PID_SETUP 

SETUP PID.

Definition at line 58 of file usb.h.

             {
        /** IN PID */
        USB_PID_IN = 0x69,
        /** OUT PID */
        USB_PID_OUT = 0xe1,
        /** SETUP PID */
        USB_PID_SETUP = 0x2d,
};

USB driver scores.

Enumerator:
USB_SCORE_FALLBACK 

Fallback driver (has no effect on overall score)

USB_SCORE_DEPRECATED 

Deprecated driver.

USB_SCORE_NORMAL 

Normal driver.

Definition at line 1400 of file usb.h.

                      {
        /** Fallback driver (has no effect on overall score) */
        USB_SCORE_FALLBACK = 0,
        /** Deprecated driver */
        USB_SCORE_DEPRECATED = 1,
        /** Normal driver */
        USB_SCORE_NORMAL = 2,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static struct usb_descriptor_header* usb_next_descriptor ( struct usb_descriptor_header desc) [static, read]

Get next USB descriptor.

Parameters:
descUSB descriptor header
Return values:
nextNext USB descriptor header

Definition at line 343 of file usb.h.

Referenced by usb_endpoint_companion_descriptor(), and usb_is_within_config().

                                                           {

        return ( ( ( void * ) desc ) + desc->len );
}
static int usb_is_within_config ( struct usb_configuration_descriptor config,
struct usb_descriptor_header desc 
) [inline, static]

Check that descriptor lies within a configuration descriptor.

Parameters:
configConfiguration descriptor
descDescriptor header
is_withinDescriptor is within the configuration descriptor

Definition at line 356 of file usb.h.

References end, le16_to_cpu, and usb_next_descriptor().

Referenced by usb_endpoint_companion_descriptor().

                                                            {
        struct usb_descriptor_header *end =
                ( ( ( void * ) config ) + le16_to_cpu ( config->len ) );

        /* Check that descriptor starts within the configuration
         * descriptor, and that the length does not exceed the
         * configuration descriptor.  This relies on the fact that
         * usb_next_descriptor() needs to access only the first byte
         * of the descriptor in order to determine the length.
         */
        return ( ( desc < end ) && ( usb_next_descriptor ( desc ) <= end ) );
}
static void usb_endpoint_init ( struct usb_endpoint ep,
struct usb_device usb,
struct usb_endpoint_driver_operations driver 
) [inline, static]

Initialise USB endpoint.

Parameters:
epUSB endpoint
usbUSB device
driverDriver operations

Definition at line 525 of file usb.h.

References driver.

Referenced by alloc_usb(), efi_usb_open(), hub_probe(), usbhid_init(), and usbnet_init().

                                                                    {

        ep->usb = usb;
        ep->driver = driver;
}
static void usb_endpoint_describe ( struct usb_endpoint ep,
unsigned int  address,
unsigned int  attributes,
size_t  mtu,
unsigned int  burst,
unsigned int  interval 
) [inline, static]

Describe USB endpoint.

Parameters:
epUSB endpoint
addressEndpoint address
attributesAttributes
mtuMaximum packet size
burstMaximum burst size
intervalInterval (in microframes)

Definition at line 543 of file usb.h.

References address, and mtu.

Referenced by efi_usb_open(), register_usb(), and usb_endpoint_described().

                                                                    {

        ep->address = address;
        ep->attributes = attributes;
        ep->mtu = mtu;
        ep->burst = burst;
        ep->interval = interval;
}
static void usb_endpoint_set_hostdata ( struct usb_endpoint ep,
void *  priv 
) [inline, static]

Set USB endpoint host controller private data.

Parameters:
epUSB endpoint
privHost controller private data

Definition at line 561 of file usb.h.

References priv.

Referenced by ehci_endpoint_open(), uhci_endpoint_open(), usbio_endpoint_open(), and xhci_endpoint_open().

                                                                  {
        ep->priv = priv;
}
static void* usb_endpoint_get_hostdata ( struct usb_endpoint ep) [inline, static]
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 220 of file usb.c.

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

                                                           {
        static char buf[ 9 /* "EPxx OUT" + NUL */ ];
        unsigned int address = ep->address;

        snprintf ( buf, sizeof ( buf ), "EP%d%s",
                   ( address & USB_ENDPOINT_MAX ),
                   ( address ?
                     ( ( address & USB_ENDPOINT_IN ) ? " IN" : " OUT" ) : "" ));
        return buf;
}
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 241 of file usb.c.

References usb_endpoint_descriptor::attributes, usb_endpoint_companion_descriptor::burst, usb_endpoint_descriptor::endpoint, ENOENT, usb_endpoint_descriptor::interval, le16_to_cpu, mtu, usb_endpoint_descriptor::sizes, usb_device::speed, 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(), usbhid_describe(), usbnet_comms_describe(), and usbnet_data_describe().

                                                                     {
        struct usb_device *usb = ep->usb;
        struct usb_endpoint_descriptor *desc;
        struct usb_endpoint_companion_descriptor *descx;
        unsigned int sizes;
        unsigned int burst;
        unsigned int interval;
        size_t mtu;

        /* Locate endpoint descriptor */
        desc = usb_endpoint_descriptor ( config, interface, type, index );
        if ( ! desc )
                return -ENOENT;

        /* Locate companion descriptor, if any */
        descx = usb_endpoint_companion_descriptor ( config, desc );

        /* Calculate MTU and burst size */
        sizes = le16_to_cpu ( desc->sizes );
        mtu = USB_ENDPOINT_MTU ( sizes );
        burst = ( descx ? descx->burst : USB_ENDPOINT_BURST ( sizes ) );

        /* Calculate interval */
        if ( ( type & USB_ENDPOINT_ATTR_TYPE_MASK ) ==
             USB_ENDPOINT_ATTR_INTERRUPT ) {
                if ( usb->speed >= USB_SPEED_HIGH ) {
                        /* 2^(desc->interval-1) is a microframe count */
                        interval = ( 1 << ( desc->interval - 1 ) );
                } else {
                        /* desc->interval is a (whole) frame count */
                        interval = ( desc->interval << 3 );
                }
        } else {
                /* desc->interval is a microframe count */
                interval = desc->interval;
        }

        /* Describe endpoint */
        usb_endpoint_describe ( ep, desc->endpoint, desc->attributes,
                                mtu, burst, interval );
        return 0;
}
int usb_endpoint_open ( struct usb_endpoint ep)

Open USB endpoint.

Parameters:
epUSB endpoint
Return values:
rcReturn status code

Definition at line 293 of file usb.c.

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

                                                  {
        struct usb_device *usb = ep->usb;
        unsigned int idx = USB_ENDPOINT_IDX ( ep->address );
        int rc;

        /* Populate host controller operations */
        ep->host = &usb->port->hub->bus->op->endpoint;

        /* Add to endpoint list */
        if ( usb->ep[idx] != NULL ) {
                DBGC ( usb, "USB %s %s is already open\n",
                       usb->name, usb_endpoint_name ( ep ) );
                rc = -EALREADY;
                goto err_already;
        }
        usb->ep[idx] = ep;
        INIT_LIST_HEAD ( &ep->halted );

        /* Open endpoint */
        if ( ( rc = ep->host->open ( ep ) ) != 0 ) {
                DBGC ( usb, "USB %s %s could not open: %s\n", usb->name,
                       usb_endpoint_name ( ep ), strerror ( rc ) );
                goto err_open;
        }
        ep->open = 1;

        DBGC2 ( usb, "USB %s %s opened with MTU %zd, burst %d, interval %d\n",
                usb->name, usb_endpoint_name ( ep ), ep->mtu, ep->burst,
                ep->interval );
        return 0;

        ep->open = 0;
        ep->host->close ( ep );
 err_open:
        usb->ep[idx] = NULL;
 err_already:
        if ( ep->max )
                usb_flush ( ep );
        return rc;
}
void usb_endpoint_close ( struct usb_endpoint ep)

Close USB endpoint.

Parameters:
epUSB endpoint

Definition at line 370 of file usb.c.

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(), usbhid_close(), usbhid_open(), usbnet_close(), and usbnet_open().

                                                    {
        struct usb_device *usb = ep->usb;
        unsigned int idx = USB_ENDPOINT_IDX ( ep->address );

        /* Sanity checks */
        assert ( usb->ep[idx] == ep );

        /* Close endpoint */
        ep->open = 0;
        ep->host->close ( ep );
        assert ( ep->fill == 0 );

        /* Remove from endpoint list */
        usb->ep[idx] = NULL;
        list_del ( &ep->halted );

        /* Discard any recycled buffers, if applicable */
        if ( ep->max )
                usb_flush ( ep );

        /* Clear transaction translator, if applicable */
        usb_endpoint_clear_tt ( ep );
}
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 474 of file usb.c.

References assert, cpu_to_le16, io_buffer::data, DBGC, usb_port::disconnected, ENODEV, usb_endpoint::fill, usb_endpoint::halted, usb_endpoint::host, 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, usb_setup_packet::request, strerror(), usb_endpoint::usb, USB_DIR_IN, usb_endpoint_name(), usb_endpoint_reset(), and usb_setup_packet::value.

Referenced by usb_control().

                                            {
        struct usb_device *usb = ep->usb;
        struct usb_port *port = usb->port;
        struct usb_setup_packet *packet;
        size_t len = iob_len ( iobuf );
        int rc;

        /* Sanity check */
        assert ( iob_headroom ( iobuf ) >= sizeof ( *packet ) );

        /* Fail immediately if device has been unplugged */
        if ( port->disconnected )
                return -ENODEV;

        /* Reset endpoint if required */
        if ( ( ! list_empty ( &ep->halted ) ) &&
             ( ( rc = usb_endpoint_reset ( ep ) ) != 0 ) )
                return rc;

        /* Zero input data buffer (if applicable) */
        if ( request & USB_DIR_IN )
                memset ( iobuf->data, 0, len );

        /* Construct setup packet */
        packet = iob_push ( iobuf, sizeof ( *packet ) );
        packet->request = cpu_to_le16 ( request );
        packet->value = cpu_to_le16 ( value );
        packet->index = cpu_to_le16 ( index );
        packet->len = cpu_to_le16 ( len );

        /* Enqueue message transfer */
        if ( ( rc = ep->host->message ( ep, iobuf ) ) != 0 ) {
                DBGC ( usb, "USB %s %s could not enqueue message transfer: "
                       "%s\n", usb->name, usb_endpoint_name ( ep ),
                       strerror ( rc ) );
                return rc;
        }

        /* Increment fill level */
        ep->fill++;

        return 0;
}
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 528 of file usb.c.

References DBGC, usb_port::disconnected, ENODEV, 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_endpoint_name(), and usb_endpoint_reset().

Referenced by acm_out_transmit(), axge_out_transmit(), dm96xx_out_transmit(), ecm_out_transmit(), efi_usb_sync_transfer(), ncm_out_transmit(), smsc75xx_out_transmit(), smsc95xx_out_transmit(), and usb_refill().

                                 {
        struct usb_device *usb = ep->usb;
        struct usb_port *port = usb->port;
        int zlp;
        int rc;

        /* Fail immediately if device has been unplugged */
        if ( port->disconnected )
                return -ENODEV;

        /* Reset endpoint if required */
        if ( ( ! list_empty ( &ep->halted ) ) &&
             ( ( rc = usb_endpoint_reset ( ep ) ) != 0 ) )
                return rc;

        /* Append a zero-length packet if necessary */
        zlp = terminate;
        if ( iob_len ( iobuf ) & ( ep->mtu - 1 ) )
                zlp = 0;

        /* Enqueue stream transfer */
        if ( ( rc = ep->host->stream ( ep, iobuf, zlp ) ) != 0 ) {
                DBGC ( usb, "USB %s %s could not enqueue stream transfer: %s\n",
                       usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
                return rc;
        }

        /* Increment fill level */
        ep->fill++;

        return 0;
}
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 569 of file usb.c.

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

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

                                 {
        struct usb_device *usb = ep->usb;

        /* Decrement fill level */
        assert ( ep->fill > 0 );
        ep->fill--;

        /* Schedule reset, if applicable */
        if ( ( rc != 0 ) && ep->open ) {
                DBGC ( usb, "USB %s %s completion failed: %s\n",
                       usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
                list_del ( &ep->halted );
                list_add_tail ( &ep->halted, &usb_halted );
        }

        /* Report completion */
        ep->driver->complete ( ep, iobuf, rc );
}
static void usb_refill_init ( struct usb_endpoint ep,
size_t  reserve,
size_t  len,
unsigned int  max 
) [inline, static]

Initialise USB endpoint refill.

Parameters:
epUSB endpoint
reserveRefill buffer reserved header length
lenRefill buffer payload length (zero for endpoint's MTU)
maxMaximum fill level

Definition at line 601 of file usb.h.

References INIT_LIST_HEAD, len, and max.

Referenced by acm_probe(), axge_probe(), dm96xx_probe(), ecm_probe(), efi_usb_async_start(), hub_probe(), lan78xx_probe(), ncm_in_prefill(), ncm_probe(), smsc75xx_probe(), smsc95xx_probe(), and usbkbd_probe().

                                     {

        INIT_LIST_HEAD ( &ep->recycled );
        ep->reserve = reserve;
        ep->len = len;
        ep->max = max;
}
static void usb_recycle ( struct usb_endpoint ep,
struct io_buffer iobuf 
) [inline, static]

Recycle I/O buffer.

Parameters:
epUSB endpoint
iobufI/O buffer

Definition at line 617 of file usb.h.

References list_add_tail.

Referenced by efi_usb_async_complete(), ncm_in_complete(), and usbkbd_complete().

                                                                 {

        list_add_tail ( &iobuf->list, &ep->recycled );
}
int usb_prefill ( struct usb_endpoint ep)

Prefill endpoint recycled buffer list.

Parameters:
epUSB endpoint
Return values:
rcReturn status code

Definition at line 602 of file usb.c.

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

                                            {
        struct io_buffer *iobuf;
        size_t reserve = ep->reserve;
        size_t len = ( ep->len ? ep->len : ep->mtu );
        unsigned int fill;
        int rc;

        /* Sanity checks */
        assert ( ep->fill == 0 );
        assert ( ep->max > 0 );
        assert ( list_empty ( &ep->recycled ) );

        /* Fill recycled buffer list */
        for ( fill = 0 ; fill < ep->max ; fill++ ) {

                /* Allocate I/O buffer */
                iobuf = alloc_iob ( reserve + len );
                if ( ! iobuf ) {
                        rc = -ENOMEM;
                        goto err_alloc;
                }
                iob_reserve ( iobuf, reserve );

                /* Add to recycled buffer list */
                list_add_tail ( &iobuf->list, &ep->recycled );
        }

        return 0;

 err_alloc:
        usb_flush ( ep );
        return rc;
}
int usb_refill ( struct usb_endpoint ep)

Refill endpoint.

Parameters:
epUSB endpoint
Return values:
rcReturn status code

Definition at line 642 of file usb.c.

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, usb_endpoint::max, usb_endpoint::mtu, NULL, usb_endpoint::open, rc, usb_endpoint::recycled, usb_endpoint::reserve, and usb_stream().

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

                                           {
        struct io_buffer *iobuf;
        size_t reserve = ep->reserve;
        size_t len = ( ep->len ? ep->len : ep->mtu );
        int rc;

        /* Sanity checks */
        assert ( ep->open );
        assert ( ep->max > 0 );

        /* Refill endpoint */
        while ( ep->fill < ep->max ) {

                /* Get or allocate buffer */
                if ( list_empty ( &ep->recycled ) ) {
                        /* Recycled buffer list is empty; allocate new buffer */
                        iobuf = alloc_iob ( reserve + len );
                        if ( ! iobuf )
                                return -ENOMEM;
                        iob_reserve ( iobuf, reserve );
                } else {
                        /* Get buffer from recycled buffer list */
                        iobuf = list_first_entry ( &ep->recycled,
                                                   struct io_buffer, list );
                        assert ( iobuf != NULL );
                        list_del ( &iobuf->list );
                }

                /* Reset buffer to maximum size */
                assert ( iob_len ( iobuf ) <= len );
                iob_put ( iobuf, ( len - iob_len ( iobuf ) ) );

                /* Enqueue buffer */
                if ( ( rc = usb_stream ( ep, iobuf, 0 ) ) != 0 ) {
                        list_add ( &iobuf->list, &ep->recycled );
                        return rc;
                }
        }

        return 0;
}
void usb_flush ( struct usb_endpoint ep)

Discard endpoint recycled buffer list.

Parameters:
epUSB endpoint

Definition at line 689 of file usb.c.

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

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

                                           {
        struct io_buffer *iobuf;
        struct io_buffer *tmp;

        /* Sanity checks */
        assert ( ! ep->open );
        assert ( ep->max > 0 );

        /* Free all I/O buffers */
        list_for_each_entry_safe ( iobuf, tmp, &ep->recycled, list ) {
                list_del ( &iobuf->list );
                free_iob ( iobuf );
        }
}
static void usb_func_set_drvdata ( struct usb_function func,
void *  priv 
) [inline, static]

Set USB function driver private data.

Parameters:
funcUSB function
privDriver private data

Definition at line 690 of file usb.h.

References priv.

Referenced by acm_probe(), axge_probe(), dm96xx_probe(), ecm_probe(), efi_usb_probe(), hub_probe(), lan78xx_probe(), ncm_probe(), smsc75xx_probe(), smsc95xx_probe(), and usbkbd_probe().

                                                               {
        func->priv = priv;
}
static void* usb_func_get_drvdata ( struct usb_function func) [inline, static]

Get USB function driver private data.

Parameters:
functionUSB function
Return values:
privDriver private data

Definition at line 701 of file usb.h.

Referenced by acm_remove(), axge_remove(), dm96xx_remove(), ecm_remove(), efi_usb_remove(), hub_remove(), lan78xx_remove(), ncm_remove(), smsc75xx_remove(), smsc95xx_remove(), and usbkbd_remove().

                                                   {
        return func->priv;
}
static void usb_set_hostdata ( struct usb_device usb,
void *  priv 
) [inline, static]

Set USB device host controller private data.

Parameters:
usbUSB device
privHost controller private data

Definition at line 767 of file usb.h.

References priv.

Referenced by ehci_device_open(), uhci_device_open(), usbio_device_open(), and xhci_device_open().

                                                        {
        usb->priv = priv;
}
static void* usb_get_hostdata ( struct usb_device usb) [inline, static]

Get USB device host controller private data.

Parameters:
usbUSB device
Return values:
privHost controller private data

Definition at line 778 of file usb.h.

Referenced by ehci_device_address(), ehci_device_close(), ehci_endpoint_open(), uhci_device_address(), uhci_device_close(), uhci_endpoint_open(), xhci_device_address(), xhci_device_close(), xhci_device_open(), xhci_endpoint_open(), and xhci_hub_open().

                                            {
        return usb->priv;
}
static struct usb_endpoint* usb_endpoint ( struct usb_device usb,
unsigned int  address 
) [static, read]

Get USB endpoint.

Parameters:
usbUSB device
addressEndpoint address
Return values:
epUSB endpoint, or NULL if not opened

Definition at line 789 of file usb.h.

References usb_device::ep, and USB_ENDPOINT_IDX.

Referenced by ehci_device_address(), and uhci_device_address().

                                                                          {

        return usb->ep[ USB_ENDPOINT_IDX ( address ) ];
}
static void usb_hub_set_drvdata ( struct usb_hub hub,
void *  priv 
) [inline, static]

Set USB hub driver private data.

Parameters:
hubUSB hub
privDriver private data

Definition at line 920 of file usb.h.

References priv.

Referenced by ehci_probe(), ehci_root_close(), ehci_root_open(), hub_probe(), uhci_probe(), uhci_root_close(), uhci_root_open(), usbio_start(), xhci_probe(), xhci_root_close(), and xhci_root_open().

                                                        {
        hub->priv = priv;
}
static void* usb_hub_get_drvdata ( struct usb_hub hub) [inline, static]
static struct usb_port* usb_port ( struct usb_hub hub,
unsigned int  address 
) [static, read]

Get USB port.

Parameters:
hubUSB hub
addressPort address
Return values:
portUSB port

Definition at line 943 of file usb.h.

Referenced by alloc_usb_hub(), ehci_probe(), free_usb_hub(), hub_remove(), register_usb_hub(), uhci_probe(), unregister_usb_hub(), usbio_start(), xhci_port_status(), xhci_probe(), and xhci_root_open().

                                                       {

        return &hub->port[ address - 1 ];
}
static void usb_bus_set_hostdata ( struct usb_bus bus,
void *  priv 
) [inline, static]

Set USB bus host controller private data.

Parameters:
busUSB bus
privHost controller private data

Definition at line 1028 of file usb.h.

References priv.

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

                                                         {
        bus->priv = priv;
}
static void* usb_bus_get_hostdata ( struct usb_bus bus) [inline, static]

Get USB bus host controller private data.

Parameters:
busUSB bus
Return values:
privHost controller private data

Definition at line 1039 of file usb.h.

Referenced by ehci_bus_close(), ehci_bus_open(), ehci_bus_poll(), ehci_device_open(), ehci_root_open(), uhci_bus_close(), uhci_bus_open(), uhci_bus_poll(), uhci_device_open(), uhci_root_open(), usbio_bus_poll(), usbio_device_open(), usbio_endpoint_open(), xhci_bus_close(), xhci_bus_open(), xhci_bus_poll(), xhci_device_open(), and xhci_root_open().

                                             {
        return bus->priv;
}
static void usb_poll ( struct usb_bus bus) [inline, static]
static void usb_complete ( struct usb_endpoint ep,
struct io_buffer iobuf 
) [inline, static]

Complete transfer (without error)

Parameters:
epUSB endpoint
iobufI/O buffer

Definition at line 1064 of file usb.h.

References usb_complete_err().

Referenced by ehci_endpoint_poll(), uhci_endpoint_poll(), usbio_bulk_in_poll(), usbio_bulk_out_poll(), usbio_control_poll(), usbio_interrupt_poll(), and xhci_transfer().

                                                                  {
        usb_complete_err ( ep, iobuf, 0 );
}
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 753 of file usb.c.

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

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(), 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(), usbhid_set_idle(), usbhid_set_protocol(), and usbhid_set_report().

                               {
        struct usb_bus *bus = usb->port->hub->bus;
        struct usb_endpoint *ep = &usb->control;
        struct io_buffer *iobuf;
        struct io_buffer *cmplt;
        union {
                struct usb_setup_packet setup;
                struct usb_control_pseudo_header pshdr;
        } *headroom;
        struct usb_control_pseudo_header *pshdr;
        unsigned int i;
        int rc;

        /* Allocate I/O buffer */
        iobuf = alloc_iob ( sizeof ( *headroom ) + len );
        if ( ! iobuf ) {
                rc = -ENOMEM;
                goto err_alloc;
        }
        iob_reserve ( iobuf, sizeof ( *headroom ) );
        iob_put ( iobuf, len );
        if ( request & USB_DIR_IN ) {
                memset ( data, 0, len );
        } else {
                memcpy ( iobuf->data, data, len );
        }

        /* Enqueue message */
        if ( ( rc = usb_message ( ep, request, value, index, iobuf ) ) != 0 )
                goto err_message;

        /* Wait for completion */
        for ( i = 0 ; i < USB_CONTROL_MAX_WAIT_MS ; i++ ) {

                /* Poll bus */
                usb_poll ( bus );

                /* Check for completion */
                while ( ( cmplt = list_first_entry ( &usb->complete,
                                                     struct io_buffer,
                                                     list ) ) ) {

                        /* Remove from completion list */
                        list_del ( &cmplt->list );

                        /* Extract and strip completion status */
                        pshdr = cmplt->data;
                        iob_pull ( cmplt, sizeof ( *pshdr ) );
                        rc = pshdr->rc;

                        /* Discard stale completions */
                        if ( cmplt != iobuf ) {
                                DBGC ( usb, "USB %s stale control completion: "
                                       "%s\n", usb->name, strerror ( rc ) );
                                DBGC_HDA ( usb, 0, cmplt->data,
                                           iob_len ( cmplt ) );
                                free_iob ( cmplt );
                                continue;
                        }

                        /* Fail immediately if completion was in error */
                        if ( rc != 0 ) {
                                DBGC ( usb, "USB %s control %04x:%04x:%04x "
                                       "failed: %s\n", usb->name, request,
                                       value, index, strerror ( rc ) );
                                free_iob ( cmplt );
                                return rc;
                        }

                        /* Copy completion to data buffer, if applicable */
                        assert ( iob_len ( cmplt ) <= len );
                        if ( request & USB_DIR_IN )
                                memcpy ( data, cmplt->data, iob_len ( cmplt ) );
                        free_iob ( cmplt );
                        return 0;
                }

                /* Delay */
                mdelay ( 1 );
        }

        DBGC ( usb, "USB %s timed out waiting for control %04x:%04x:%04x\n",
               usb->name, request, value, index );
        return -ETIMEDOUT;

 err_message:
        free_iob ( iobuf );
 err_alloc:
        return rc;
}
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 884 of file usb.c.

References __attribute__, ENOMEM, free, usb_device::language, le16_to_cpu, malloc(), max, rc, usb_get_default_language(), usb_get_descriptor(), and USB_STRING_DESCRIPTOR.

Referenced by ecm_fetch_mac().

                                                                               {
        size_t max = ( len ? ( len - 1 /* NUL */ ) : 0 );
        struct {
                struct usb_descriptor_header header;
                uint16_t character[max];
        } __attribute__ (( packed )) *desc;
        unsigned int actual;
        unsigned int i;
        int rc;

        /* Use default language ID, if applicable */
        if ( ( language == 0 ) && ( index != 0 ) ) {
                if ( ! usb->language )
                        usb->language = usb_get_default_language ( usb );
                language = usb->language;
        }

        /* Allocate buffer for string */
        desc = malloc ( sizeof ( *desc ) );
        if ( ! desc ) {
                rc = -ENOMEM;
                goto err_alloc;
        }

        /* Get descriptor */
        if ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, index,
                                         language, &desc->header,
                                         sizeof ( *desc ) ) ) != 0 )
                goto err_get_descriptor;

        /* Copy to buffer */
        actual = ( ( desc->header.len - sizeof ( desc->header ) ) /
                   sizeof ( desc->character[0] ) );
        for ( i = 0 ; ( ( i < actual ) && ( i < max ) ) ; i++ )
                buf[i] = le16_to_cpu ( desc->character[i] );
        if ( len )
                buf[i] = '\0';

        /* Free buffer */
        free ( desc );

        return actual;

 err_get_descriptor:
        free ( desc );
 err_alloc:
        return rc;
}
static int usb_get_status ( struct usb_device usb,
unsigned int  type,
unsigned int  index,
void *  data,
size_t  len 
) [inline, static]

Get status.

Parameters:
usbUSB device
typeRequest type
indexTarget index
dataStatus to fill in
lenLength of status descriptor
Return values:
rcReturn status code

Definition at line 1087 of file usb.h.

References usb_control(), and USB_GET_STATUS.

Referenced by usb_hub_get_port_status().

                                          {

        return usb_control ( usb, ( USB_GET_STATUS | type ), 0, index,
                             data, len );
}
static int usb_clear_feature ( struct usb_device usb,
unsigned int  type,
unsigned int  feature,
unsigned int  index 
) [inline, static]

Clear feature.

Parameters:
usbUSB device
typeRequest type
featureFeature selector
indexTarget index
Return values:
rcReturn status code

Definition at line 1104 of file usb.h.

References NULL, USB_CLEAR_FEATURE, and usb_control().

Referenced by usb_endpoint_reset(), and usb_hub_clear_port_feature().

                                                               {

        return usb_control ( usb, ( USB_CLEAR_FEATURE | type ),
                             feature, index, NULL, 0 );
}
static int usb_set_feature ( struct usb_device usb,
unsigned int  type,
unsigned int  feature,
unsigned int  index 
) [inline, static]

Set feature.

Parameters:
usbUSB device
typeRequest type
featureFeature selector
indexTarget index
Return values:
rcReturn status code

Definition at line 1121 of file usb.h.

References NULL, usb_control(), and USB_SET_FEATURE.

Referenced by usb_hub_set_port_feature().

                                                             {

        return usb_control ( usb, ( USB_SET_FEATURE | type ),
                             feature, index, NULL, 0 );
}
static int usb_set_address ( struct usb_device usb,
unsigned int  address 
) [inline, static]

Set address.

Parameters:
usbUSB device
addressDevice address
Return values:
rcReturn status code

Definition at line 1136 of file usb.h.

References NULL, usb_control(), and USB_SET_ADDRESS.

Referenced by ehci_device_address(), and uhci_device_address().

                                                                 {

        return usb_control ( usb, USB_SET_ADDRESS, address, 0, NULL, 0 );
}
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 
) [inline, static]

Get USB descriptor.

Parameters:
usbUSB device
typeRequest type
descDescriptor type
indexDescriptor index
languageLanguage ID (for string descriptors)
dataDescriptor to fill in
lenMaximum length of descriptor
Return values:
rcReturn status code

Definition at line 1154 of file usb.h.

References usb_control(), and USB_GET_DESCRIPTOR.

Referenced by efi_usb_get_string_descriptor(), efi_usb_probe(), usb_get_config_descriptor(), usb_get_default_language(), usb_get_device_descriptor(), usb_get_mtu(), usb_get_string_descriptor(), and usb_hub_get_descriptor().

                                  {

        return usb_control ( usb, ( USB_GET_DESCRIPTOR | type ),
                             ( ( desc << 8 ) | index ), language, data, len );
}
static int usb_get_mtu ( struct usb_device usb,
struct usb_device_descriptor data 
) [inline, static]

Get first part of USB device descriptor (up to and including MTU)

Parameters:
usbUSB device
dataDevice descriptor to (partially) fill in
Return values:
rcReturn status code

Definition at line 1171 of file usb.h.

References mtu, offsetof, and usb_get_descriptor().

Referenced by register_usb().

                                                                           {

        return usb_get_descriptor ( usb, 0, USB_DEVICE_DESCRIPTOR, 0, 0,
                                    &data->header,
                                    ( offsetof ( typeof ( *data ), mtu ) +
                                      sizeof ( data->mtu ) ) );
}
static int usb_get_device_descriptor ( struct usb_device usb,
struct usb_device_descriptor data 
) [inline, static]

Get USB device descriptor.

Parameters:
usbUSB device
dataDevice descriptor to fill in
Return values:
rcReturn status code

Definition at line 1187 of file usb.h.

References usb_get_descriptor().

Referenced by register_usb().

                                                                 {

        return usb_get_descriptor ( usb, 0, USB_DEVICE_DESCRIPTOR, 0, 0,
                                    &data->header, sizeof ( *data ) );
}
static int usb_get_config_descriptor ( struct usb_device usb,
unsigned int  index,
struct usb_configuration_descriptor data,
size_t  len 
) [inline, static]

Get USB configuration descriptor.

Parameters:
usbUSB device
indexConfiguration index
dataConfiguration descriptor to fill in
Return values:
rcReturn status code

Definition at line 1203 of file usb.h.

References USB_CONFIGURATION_DESCRIPTOR, and usb_get_descriptor().

Referenced by usb_config_descriptor().

                                         {

        return usb_get_descriptor ( usb, 0, USB_CONFIGURATION_DESCRIPTOR, index,
                                    0, &data->header, len );
}
static int usb_set_configuration ( struct usb_device usb,
unsigned int  index 
) [inline, static]

Set USB configuration.

Parameters:
usbUSB device
indexConfiguration index
Return values:
rcReturn status code

Definition at line 1219 of file usb.h.

References NULL, usb_control(), and USB_SET_CONFIGURATION.

Referenced by usb_autoconfigure(), and usb_deconfigure().

                                                                     {

        return usb_control ( usb, USB_SET_CONFIGURATION, index, 0, NULL, 0 );
}
static int usb_set_interface ( struct usb_device usb,
unsigned int  interface,
unsigned int  alternate 
) [inline, static]

Set USB interface alternate setting.

Parameters:
usbUSB device
interfaceInterface number
alternateAlternate setting
Return values:
rcReturn status code

Definition at line 1233 of file usb.h.

References NULL, usb_control(), and USB_SET_INTERFACE.

Referenced by usbnet_close(), and usbnet_open().

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

Locate USB interface descriptor.

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

Definition at line 143 of file usb.c.

References usb_interface_descriptor::alternate, for_each_config_descriptor, usb_interface_descriptor::header, usb_interface_descriptor::interface, NULL, and usb_descriptor_header::type.

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

                                                                            {
        struct usb_interface_descriptor *desc;

        /* Find a matching interface descriptor */
        for_each_config_descriptor ( desc, config ) {
                if ( ( desc->header.type == USB_INTERFACE_DESCRIPTOR ) &&
                     ( desc->interface == interface ) &&
                     ( desc->alternate == alternate ) )
                        return desc;
        }
        return NULL;
}
struct usb_endpoint_descriptor* usb_endpoint_descriptor ( struct usb_configuration_descriptor config,
struct usb_interface_descriptor interface,
unsigned int  type,
unsigned int  index 
) [read]

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 167 of file usb.c.

References usb_endpoint_descriptor::attributes, direction, usb_endpoint_descriptor::endpoint, for_each_interface_descriptor, usb_endpoint_descriptor::header, NULL, usb_descriptor_header::type, USB_DIR_IN, and USB_ENDPOINT_ATTR_TYPE_MASK.

Referenced by usb_endpoint_described().

                                                                  {
        struct usb_endpoint_descriptor *desc;
        unsigned int attributes = ( type & USB_ENDPOINT_ATTR_TYPE_MASK );
        unsigned int direction = ( type & USB_DIR_IN );

        /* Find a matching endpoint descriptor */
        for_each_interface_descriptor ( desc, config, interface ) {
                if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) &&
                     ( ( desc->attributes &
                         USB_ENDPOINT_ATTR_TYPE_MASK ) == attributes ) &&
                     ( ( desc->endpoint & USB_DIR_IN ) == direction ) &&
                     ( index-- == 0 ) )
                        return desc;
        }
        return NULL;
}

Locate USB endpoint companion descriptor.

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

Definition at line 194 of file usb.c.

References container_of, header, usb_endpoint_descriptor::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().

                                                                           {
        struct usb_endpoint_companion_descriptor *descx;

        /* Get companion descriptor, if present */
        descx = container_of ( usb_next_descriptor ( &desc->header ),
                               struct usb_endpoint_companion_descriptor,
                               header );
        return ( ( usb_is_within_config ( config, &descx->header ) &&
                   descx->header.type == USB_ENDPOINT_COMPANION_DESCRIPTOR )
                 ? descx : NULL );
}
struct usb_hub* alloc_usb_hub ( struct usb_bus bus,
struct usb_device usb,
unsigned int  ports,
struct usb_hub_driver_operations driver 
) [read]

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 1873 of file usb.c.

References usb_port::address, bus, usb_hub::bus, usb_port::changed, driver, usb_hub::driver, usb_hub::host, usb_port::hub, usb_host_operations::hub, INIT_LIST_HEAD, usb_device::name, usb_hub::name, usb_bus::name, NULL, usb_bus::op, 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().

                                                                            {
        struct usb_hub *hub;
        struct usb_port *port;
        unsigned int i;

        /* Allocate and initialise structure */
        hub = zalloc ( sizeof ( *hub ) + ( ports * sizeof ( hub->port[0] ) ) );
        if ( ! hub )
                return NULL;
        hub->name = ( usb ? usb->name : bus->name );
        hub->bus = bus;
        hub->usb = usb;
        if ( usb )
                hub->protocol = usb->port->protocol;
        hub->ports = ports;
        hub->driver = driver;
        hub->host = &bus->op->hub;

        /* Initialise port list */
        for ( i = 1 ; i <= hub->ports ; i++ ) {
                port = usb_port ( hub, i );
                port->hub = hub;
                port->address = i;
                if ( usb )
                        port->protocol = usb->port->protocol;
                INIT_LIST_HEAD ( &port->changed );
        }

        return hub;
}
int register_usb_hub ( struct usb_hub hub)

Register USB hub.

Parameters:
hubUSB hub
Return values:
rcReturn status code

Definition at line 1912 of file usb.c.

References bus, usb_hub::bus, usb_hub_host_operations::close, usb_hub_driver_operations::close, DBGC, usb_hub::driver, usb_hub::host, usb_bus::hubs, 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().

                                             {
        struct usb_bus *bus = hub->bus;
        struct usb_port *port;
        unsigned int i;
        int rc;

        /* Add to hub list */
        list_add_tail ( &hub->list, &bus->hubs );

        /* Open hub (host controller) */
        if ( ( rc = hub->host->open ( hub ) ) != 0 ) {
                DBGC ( hub, "USB hub %s could not open: %s\n",
                       hub->name, strerror ( rc ) );
                goto err_host_open;
        }

        /* Open hub (driver) */
        if ( ( rc = hub->driver->open ( hub ) ) != 0 ) {
                DBGC ( hub, "USB hub %s could not open: %s\n",
                       hub->name, strerror ( rc ) );
                goto err_driver_open;
        }

        /* Delay to allow ports to stabilise */
        mdelay ( USB_PORT_DELAY_MS );

        /* Mark all ports as changed */
        for ( i = 1 ; i <= hub->ports ; i++ ) {
                port = usb_port ( hub, i );
                usb_port_changed ( port );
        }

        /* Some hubs seem to defer reporting device connections until
         * their interrupt endpoint is polled for the first time.
         * Poll the bus once now in order to pick up any such
         * connections.
         */
        usb_poll ( bus );

        return 0;

        hub->driver->close ( hub );
 err_driver_open:
        hub->host->close ( hub );
 err_host_open:
        list_del ( &hub->list );
        return rc;
}
void unregister_usb_hub ( struct usb_hub hub)

Unregister USB hub.

Parameters:
hubUSB hub

Definition at line 1966 of file usb.c.

References usb_port::attached, usb_port::changed, usb_hub_host_operations::close, usb_hub_driver_operations::close, usb_hub::driver, usb_hub::host, 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().

                                                {
        struct usb_port *port;
        unsigned int i;

        /* Detach all devices */
        for ( i = 1 ; i <= hub->ports ; i++ ) {
                port = usb_port ( hub, i );
                if ( port->attached )
                        usb_detached ( port );
        }

        /* Close hub (driver) */
        hub->driver->close ( hub );

        /* Close hub (host controller) */
        hub->host->close ( hub );

        /* Cancel any pending port status changes */
        for ( i = 1 ; i <= hub->ports ; i++ ) {
                port = usb_port ( hub, i );
                list_del ( &port->changed );
                INIT_LIST_HEAD ( &port->changed );
        }

        /* Remove from hub list */
        list_del ( &hub->list );
}
void free_usb_hub ( struct usb_hub hub)

Free USB hub.

Parameters:
hubUSB hub

Definition at line 1999 of file usb.c.

References assert, usb_port::attached, usb_port::changed, free, list_empty, NULL, port, usb_hub::ports, usb_port::usb, and usb_port().

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

                                          {
        struct usb_port *port;
        unsigned int i;

        /* Sanity checks */
        for ( i = 1 ; i <= hub->ports ; i++ ) {
                port = usb_port ( hub, i );
                assert ( ! port->attached );
                assert ( port->usb == NULL );
                assert ( list_empty ( &port->changed ) );
        }

        /* Free hub */
        free ( hub );
}
void usb_port_changed ( struct usb_port port)

Report port status change.

Parameters:
portUSB port

Definition at line 1794 of file usb.c.

References usb_port::changed, list_add_tail, and list_del.

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

                                                {

        /* Record hub port status change */
        list_del ( &port->changed );
        list_add_tail ( &port->changed, &usb_changed );
}
struct usb_bus* alloc_usb_bus ( struct device dev,
unsigned int  ports,
size_t  mtu,
struct usb_host_operations op 
) [read]

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 2031 of file usb.c.

References alloc_usb_hub(), bus, usb_host_operations::bus, usb_bus::dev, usb_bus::devices, free, free_usb_hub(), usb_bus::host, usb_bus::hub, usb_bus::hubs, INIT_LIST_HEAD, mtu, usb_bus::mtu, device::name, usb_bus::name, NULL, op, usb_bus::op, usb_host_operations::root, and zalloc().

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

                                                                              {
        struct usb_bus *bus;

        /* Allocate and initialise structure */
        bus = zalloc ( sizeof ( *bus ) );
        if ( ! bus )
                goto err_alloc_bus;
        bus->name = dev->name;
        bus->dev = dev;
        bus->mtu = mtu;
        bus->op = op;
        INIT_LIST_HEAD ( &bus->devices );
        INIT_LIST_HEAD ( &bus->hubs );
        bus->host = &bus->op->bus;

        /* Allocate root hub */
        bus->hub = alloc_usb_hub ( bus, NULL, ports, &op->root );
        if ( ! bus->hub )
                goto err_alloc_hub;

        return bus;

        free_usb_hub ( bus->hub );
 err_alloc_hub:
        free ( bus );
 err_alloc_bus:
        return NULL;
}
int register_usb_bus ( struct usb_bus bus)

Register USB bus.

Parameters:
busUSB bus
Return values:
rcReturn status code

Definition at line 2067 of file usb.c.

References assert, usb_bus_host_operations::close, usb_bus::host, usb_bus::hub, usb_bus::list, list_add_tail, list_del, NULL, usb_bus_host_operations::open, rc, register_usb_hub(), unregister_usb_hub(), and usb_hotplug().

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

                                             {
        int rc;

        /* Sanity checks */
        assert ( bus->hub != NULL );

        /* Open bus */
        if ( ( rc = bus->host->open ( bus ) ) != 0 )
                goto err_open;

        /* Add to list of USB buses */
        list_add_tail ( &bus->list, &usb_buses );

        /* Register root hub */
        if ( ( rc = register_usb_hub ( bus->hub ) ) != 0 )
                goto err_register_hub;

        /* Attach any devices already present */
        usb_hotplug();

        return 0;

        unregister_usb_hub ( bus->hub );
 err_register_hub:
        list_del ( &bus->list );
        bus->host->close ( bus );
 err_open:
        return rc;
}
void unregister_usb_bus ( struct usb_bus bus)

Unregister USB bus.

Parameters:
busUSB bus

Definition at line 2102 of file usb.c.

References assert, usb_bus_host_operations::close, usb_bus::devices, usb_bus::host, usb_bus::hub, usb_bus::hubs, usb_bus::list, list_del, list_empty, NULL, and unregister_usb_hub().

Referenced by ehci_probe(), ehci_remove(), uhci_probe(), uhci_remove(), usbio_start(), usbio_stop(), xhci_probe(), and xhci_remove().

                                                {

        /* Sanity checks */
        assert ( bus->hub != NULL );

        /* Unregister root hub */
        unregister_usb_hub ( bus->hub );

        /* Remove from list of USB buses */
        list_del ( &bus->list );

        /* Close bus */
        bus->host->close ( bus );

        /* Sanity checks */
        assert ( list_empty ( &bus->devices ) );
        assert ( list_empty ( &bus->hubs ) );
}
void free_usb_bus ( struct usb_bus bus)

Free USB bus.

Parameters:
busUSB bus

Definition at line 2126 of file usb.c.

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

Referenced by ehci_probe(), ehci_remove(), uhci_probe(), uhci_remove(), usbio_start(), usbio_stop(), xhci_probe(), and xhci_remove().

                                          {
        struct usb_endpoint *ep;
        struct usb_port *port;

        /* Sanity checks */
        assert ( list_empty ( &bus->devices ) );
        assert ( list_empty ( &bus->hubs ) );
        list_for_each_entry ( ep, &usb_halted, halted )
                assert ( ep->usb->port->hub->bus != bus );
        list_for_each_entry ( port, &usb_changed, changed )
                assert ( port->hub->bus != bus );

        /* Free root hub */
        free_usb_hub ( bus->hub );

        /* Free bus */
        free ( bus );
}
struct usb_bus* find_usb_bus_by_location ( unsigned int  bus_type,
unsigned int  location 
) [read]

Find USB bus by device location.

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

Definition at line 2152 of file usb.c.

References bus, device_description::bus_type, device::desc, usb_bus::dev, for_each_usb_bus, device_description::location, and NULL.

Referenced by uhci_root_speed().

                                                                    {
        struct usb_bus *bus;

        for_each_usb_bus ( bus ) {
                if ( ( bus->dev->desc.bus_type == bus_type ) &&
                     ( bus->dev->desc.location == location ) )
                        return bus;
        }

        return NULL;
}
int usb_alloc_address ( struct usb_bus bus)

Allocate device address.

Parameters:
busUSB bus
Return values:
addressDevice address, or negative error

Definition at line 2178 of file usb.c.

References address, usb_bus::addresses, ENOENT, and ffsll.

Referenced by ehci_device_address(), and uhci_device_address().

                                              {
        unsigned int address;

        /* Find first free device address */
        address = ffsll ( ~bus->addresses );
        if ( ! address )
                return -ENOENT;

        /* Mark address as used */
        bus->addresses |= ( 1ULL << ( address - 1 ) );

        return address;
}
void usb_free_address ( struct usb_bus bus,
unsigned int  address 
)

Free device address.

Parameters:
busUSB bus
addressDevice address

Definition at line 2198 of file usb.c.

References usb_bus::addresses, and assert.

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

                                                                    {

        /* Sanity check */
        assert ( address > 0 );
        assert ( bus->addresses & ( 1ULL << ( address - 1 ) ) );

        /* Mark address as free */
        bus->addresses &= ~( 1ULL << ( address - 1 ) );
}
unsigned int usb_route_string ( struct usb_device usb)

Get USB route string.

Parameters:
usbUSB device
Return values:
routeUSB route string

Definition at line 2221 of file usb.c.

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

Referenced by xhci_device_address().

                                                         {
        struct usb_device *parent;
        unsigned int route;

        /* Navigate up to root hub, constructing route string as we go */
        for ( route = 0 ; ( parent = usb->port->hub->usb ) ; usb = parent ) {
                route <<= 4;
                route |= ( ( usb->port->address > 0xf ) ?
                           0xf : usb->port->address );
        }

        return route;
}
unsigned int usb_depth ( struct usb_device usb)

Get USB depth.

Parameters:
usbUSB device
Return values:
depthHub depth

Definition at line 2241 of file usb.c.

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

Referenced by efi_usb_install(), and hub_probe().

                                                  {
        struct usb_device *parent;
        unsigned int depth;

        /* Navigate up to root hub, constructing depth as we go */
        for ( depth = 0 ; ( parent = usb->port->hub->usb ) ; usb = parent )
                depth++;

        return depth;
}
struct usb_port* usb_root_hub_port ( struct usb_device usb) [read]

Get USB root hub port.

Parameters:
usbUSB device
Return values:
portRoot hub port

Definition at line 2258 of file usb.c.

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

Referenced by xhci_device_address().

                                                               {
        struct usb_device *parent;

        /* Navigate up to root hub */
        while ( ( parent = usb->port->hub->usb ) )
                usb = parent;

        return usb->port;
}
struct usb_port* usb_transaction_translator ( struct usb_device usb) [read]

Get USB transaction translator.

Parameters:
usbUSB device
Return values:
portTransaction translator port, or NULL

Definition at line 2274 of file usb.c.

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

                                                                        {
        struct usb_device *parent;

        /* Navigate up to root hub.  If we find a low-speed or
         * full-speed device with a higher-speed parent hub, then that
         * device's port is the transaction translator.
         */
        for ( ; ( parent = usb->port->hub->usb ) ; usb = parent ) {
                if ( ( usb->speed <= USB_SPEED_FULL ) &&
                     ( parent->speed > USB_SPEED_FULL ) )
                        return usb->port;
        }

        return NULL;
}
struct usb_driver* usb_find_driver ( struct usb_function_descriptor desc,
struct usb_device_id **  id 
) [read]

Find USB device driver.

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

Definition at line 1130 of file usb.c.

References usb_function_descriptor::class, usb_class_id::class, usb_driver::class, driver, for_each_table_entry, usb_driver::id_count, usb_driver::ids, usb_class_id::mask, NULL, usb_function_descriptor::product, usb_class_descriptor::scalar, USB_ANY_ID, USB_DRIVERS, and usb_function_descriptor::vendor.

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

                                                                  {
        struct usb_driver *driver;
        unsigned int i;

        /* Look for a matching driver */
        for_each_table_entry ( driver, USB_DRIVERS ) {
                for ( i = 0 ; i < driver->id_count ; i++ ) {

                        /* Ignore non-matching driver class */
                        if ( ( driver->class.class.scalar ^ desc->class.scalar )
                             & driver->class.mask.scalar )
                                continue;

                        /* Look for a matching ID */
                        *id = &driver->ids[i];
                        if ( ( ( (*id)->vendor == desc->vendor ) ||
                               ( (*id)->vendor == USB_ANY_ID ) ) &&
                             ( ( (*id)->product == desc->product ) ||
                               ( (*id)->product == USB_ANY_ID ) ) )
                                return driver;
                }
        }

        /* Not found */
        *id = NULL;
        return NULL;
}

Variable Documentation

List of USB buses.

Definition at line 44 of file usb.c.