iPXE
Data Structures | Macros | 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...
 

Macros

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

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_headerusb_next_descriptor (struct usb_descriptor_header *desc)
 Get next USB descriptor. More...
 
static int usb_is_within_config (struct usb_configuration_descriptor *config, struct usb_descriptor_header *desc)
 Check that descriptor lies within a configuration descriptor. More...
 
static void usb_endpoint_init (struct usb_endpoint *ep, struct usb_device *usb, struct usb_endpoint_driver_operations *driver)
 Initialise USB endpoint. More...
 
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. More...
 
static void usb_endpoint_set_hostdata (struct usb_endpoint *ep, void *priv)
 Set USB endpoint host controller private data. More...
 
static void * usb_endpoint_get_hostdata (struct usb_endpoint *ep)
 Get USB endpoint host controller private data. 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...
 
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...
 
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...
 
static void usb_refill_init (struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
 Initialise USB endpoint refill. More...
 
static void usb_recycle (struct usb_endpoint *ep, struct io_buffer *iobuf)
 Recycle I/O buffer. 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_func_set_drvdata (struct usb_function *func, void *priv)
 Set USB function driver private data. More...
 
static void * usb_func_get_drvdata (struct usb_function *func)
 Get USB function driver private data. More...
 
static void usb_set_hostdata (struct usb_device *usb, void *priv)
 Set USB device host controller private data. More...
 
static void * usb_get_hostdata (struct usb_device *usb)
 Get USB device host controller private data. More...
 
static struct usb_endpointusb_endpoint (struct usb_device *usb, unsigned int address)
 Get USB endpoint. More...
 
static void usb_hub_set_drvdata (struct usb_hub *hub, void *priv)
 Set USB hub driver private data. More...
 
static void * usb_hub_get_drvdata (struct usb_hub *hub)
 Get USB hub driver private data. More...
 
static struct usb_portusb_port (struct usb_hub *hub, unsigned int address)
 Get USB port. More...
 
static void usb_bus_set_hostdata (struct usb_bus *bus, void *priv)
 Set USB bus host controller private data. More...
 
static void * usb_bus_get_hostdata (struct usb_bus *bus)
 Get USB bus host controller private data. More...
 
static void usb_poll (struct usb_bus *bus)
 Poll USB bus. More...
 
static void usb_complete (struct usb_endpoint *ep, struct io_buffer *iobuf)
 Complete transfer (without error) 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...
 
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_get_status (struct usb_device *usb, unsigned int type, unsigned int index, void *data, size_t len)
 Get status. More...
 
static int usb_clear_feature (struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
 Clear feature. More...
 
static int usb_set_feature (struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
 Set feature. More...
 
static int usb_set_address (struct usb_device *usb, unsigned int address)
 Set address. More...
 
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. More...
 
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) More...
 
static int usb_get_device_descriptor (struct usb_device *usb, struct usb_device_descriptor *data)
 Get USB device descriptor. More...
 
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. More...
 
static int usb_set_configuration (struct usb_device *usb, unsigned int index)
 Set USB configuration. More...
 
static int usb_set_interface (struct usb_device *usb, unsigned int interface, unsigned int alternate)
 Set USB interface alternate setting. More...
 
static unsigned int usb_depth (struct usb_device *usb)
 Get USB depth. 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...
 
struct usb_devicefind_usb (struct usb_bus *bus, unsigned int address)
 Find USB device by address. More...
 
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. 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...
 
void usb_port_changed (struct usb_port *port)
 Report port status change. 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...
 
struct usb_driverusb_find_driver (struct usb_function_descriptor *desc, struct usb_device_id **id)
 Find USB device driver. More...
 

Variables

struct list_head usb_buses
 List of USB buses. More...
 

Detailed Description

Universal Serial Bus (USB)

Definition in file usb.h.

Macro Definition Documentation

◆ USB_SPEED

#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.

◆ USB_SPEED_MANTISSA

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

Extract USB speed mantissa.

Definition at line 38 of file usb.h.

◆ USB_SPEED_EXPONENT

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

Extract USB speed exponent.

Definition at line 41 of file usb.h.

◆ USB_BUSDEV

#define USB_BUSDEV (   bus,
  dev 
)    ( ( (bus) << 8 ) | (dev) )

Define a USB bus:device address.

Parameters
busBus address
devDevice address
Return values
busdevBus:device address

Definition at line 63 of file usb.h.

◆ USB_BUS

#define USB_BUS (   busdev)    ( (busdev) >> 8 )

Extract USB bus address.

Definition at line 66 of file usb.h.

◆ USB_DEV

#define USB_DEV (   busdev)    ( (busdev) & 0xff )

Extract USB device address.

Definition at line 69 of file usb.h.

◆ USB_DIR_OUT

#define USB_DIR_OUT   ( 0 << 7 )

Data transfer is from host to device.

Definition at line 94 of file usb.h.

◆ USB_DIR_IN

#define USB_DIR_IN   ( 1 << 7 )

Data transfer is from device to host.

Definition at line 97 of file usb.h.

◆ USB_TYPE_STANDARD

#define USB_TYPE_STANDARD   ( 0 << 5 )

Standard request type.

Definition at line 100 of file usb.h.

◆ USB_TYPE_CLASS

#define USB_TYPE_CLASS   ( 1 << 5 )

Class-specific request type.

Definition at line 103 of file usb.h.

◆ USB_TYPE_VENDOR

#define USB_TYPE_VENDOR   ( 2 << 5 )

Vendor-specific request type.

Definition at line 106 of file usb.h.

◆ USB_RECIP_MASK

#define USB_RECIP_MASK   ( 0x1f << 0 )

Request recipient mask.

Definition at line 109 of file usb.h.

◆ USB_RECIP_DEVICE

#define USB_RECIP_DEVICE   ( 0 << 0 )

Request recipient is the device.

Definition at line 112 of file usb.h.

◆ USB_RECIP_INTERFACE

#define USB_RECIP_INTERFACE   ( 1 << 0 )

Request recipient is an interface.

Definition at line 115 of file usb.h.

◆ USB_RECIP_ENDPOINT

#define USB_RECIP_ENDPOINT   ( 2 << 0 )

Request recipient is an endpoint.

Definition at line 118 of file usb.h.

◆ USB_REQUEST_TYPE

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

Construct USB request type.

Definition at line 121 of file usb.h.

◆ USB_GET_STATUS

#define USB_GET_STATUS   ( USB_DIR_IN | USB_REQUEST_TYPE ( 0 ) )

Get status.

Definition at line 124 of file usb.h.

◆ USB_CLEAR_FEATURE

#define USB_CLEAR_FEATURE   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 1 ) )

Clear feature.

Definition at line 127 of file usb.h.

◆ USB_SET_FEATURE

#define USB_SET_FEATURE   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 3 ) )

Set feature.

Definition at line 130 of file usb.h.

◆ USB_SET_ADDRESS

#define USB_SET_ADDRESS   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 5 ) )

Set address.

Definition at line 133 of file usb.h.

◆ USB_GET_DESCRIPTOR

#define USB_GET_DESCRIPTOR   ( USB_DIR_IN | USB_REQUEST_TYPE ( 6 ) )

Get descriptor.

Definition at line 136 of file usb.h.

◆ USB_SET_DESCRIPTOR

#define USB_SET_DESCRIPTOR   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 7 ) )

Set descriptor.

Definition at line 139 of file usb.h.

◆ USB_GET_CONFIGURATION

#define USB_GET_CONFIGURATION   ( USB_DIR_IN | USB_REQUEST_TYPE ( 8 ) )

Get configuration.

Definition at line 142 of file usb.h.

◆ USB_SET_CONFIGURATION

#define USB_SET_CONFIGURATION   ( USB_DIR_OUT | USB_REQUEST_TYPE ( 9 ) )

Set configuration.

Definition at line 145 of file usb.h.

◆ USB_GET_INTERFACE

#define USB_GET_INTERFACE   ( USB_DIR_IN | USB_RECIP_INTERFACE | USB_REQUEST_TYPE ( 10 ) )

Get interface.

Definition at line 148 of file usb.h.

◆ USB_SET_INTERFACE

#define USB_SET_INTERFACE   ( USB_DIR_OUT | USB_RECIP_INTERFACE | USB_REQUEST_TYPE ( 11 ) )

Set interface.

Definition at line 152 of file usb.h.

◆ USB_ENDPOINT_HALT

#define USB_ENDPOINT_HALT   0

Endpoint halt feature.

Definition at line 156 of file usb.h.

◆ USB_CLASS_HUB

#define USB_CLASS_HUB   9

Class code for USB hubs.

Definition at line 169 of file usb.h.

◆ USB_DEVICE_DESCRIPTOR

#define USB_DEVICE_DESCRIPTOR   1

A USB device descriptor.

Definition at line 206 of file usb.h.

◆ USB_CONFIGURATION_DESCRIPTOR

#define USB_CONFIGURATION_DESCRIPTOR   2

A USB configuration descriptor.

Definition at line 227 of file usb.h.

◆ USB_STRING_DESCRIPTOR

#define USB_STRING_DESCRIPTOR   3

A USB string descriptor.

Definition at line 238 of file usb.h.

◆ USB_LANG_ENGLISH

#define USB_LANG_ENGLISH   0x0409

Language ID for English.

Definition at line 241 of file usb.h.

◆ USB_INTERFACE_DESCRIPTOR

#define USB_INTERFACE_DESCRIPTOR   4

A USB interface descriptor.

Definition at line 260 of file usb.h.

◆ USB_ENDPOINT_DESCRIPTOR

#define USB_ENDPOINT_DESCRIPTOR   5

A USB endpoint descriptor.

Definition at line 277 of file usb.h.

◆ USB_ENDPOINT_ATTR_TYPE_MASK

#define USB_ENDPOINT_ATTR_TYPE_MASK   0x03

Endpoint attribute transfer type mask.

Definition at line 280 of file usb.h.

◆ USB_ENDPOINT_ATTR_PERIODIC

#define USB_ENDPOINT_ATTR_PERIODIC   0x01

Endpoint periodic type.

Definition at line 283 of file usb.h.

◆ USB_ENDPOINT_ATTR_CONTROL

#define USB_ENDPOINT_ATTR_CONTROL   0x00

Control endpoint transfer type.

Definition at line 286 of file usb.h.

◆ USB_ENDPOINT_ATTR_BULK

#define USB_ENDPOINT_ATTR_BULK   0x02

Bulk endpoint transfer type.

Definition at line 289 of file usb.h.

◆ USB_ENDPOINT_ATTR_INTERRUPT

#define USB_ENDPOINT_ATTR_INTERRUPT   0x03

Interrupt endpoint transfer type.

Definition at line 292 of file usb.h.

◆ USB_BULK_OUT

#define USB_BULK_OUT   ( USB_ENDPOINT_ATTR_BULK | USB_DIR_OUT )

Bulk OUT endpoint (internal) type.

Definition at line 295 of file usb.h.

◆ USB_BULK_IN

#define USB_BULK_IN   ( USB_ENDPOINT_ATTR_BULK | USB_DIR_IN )

Bulk IN endpoint (internal) type.

Definition at line 298 of file usb.h.

◆ USB_INTERRUPT_IN

#define USB_INTERRUPT_IN   ( USB_ENDPOINT_ATTR_INTERRUPT | USB_DIR_IN )

Interrupt IN endpoint (internal) type.

Definition at line 301 of file usb.h.

◆ USB_INTERRUPT_OUT

#define USB_INTERRUPT_OUT   ( USB_ENDPOINT_ATTR_INTERRUPT | USB_DIR_OUT )

Interrupt OUT endpoint (internal) type.

Definition at line 304 of file usb.h.

◆ USB_ENDPOINT_MTU

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

USB endpoint MTU.

Definition at line 307 of file usb.h.

◆ USB_ENDPOINT_BURST

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

USB endpoint maximum burst size.

Definition at line 310 of file usb.h.

◆ USB_ENDPOINT_COMPANION_DESCRIPTOR

#define USB_ENDPOINT_COMPANION_DESCRIPTOR   48

A USB endpoint companion descriptor.

Definition at line 325 of file usb.h.

◆ USB_INTERFACE_ASSOCIATION_DESCRIPTOR

A USB interface association descriptor.

Definition at line 342 of file usb.h.

◆ USB_CS_INTERFACE_DESCRIPTOR

#define USB_CS_INTERFACE_DESCRIPTOR   36

A class-specific interface descriptor.

Definition at line 345 of file usb.h.

◆ USB_CS_ENDPOINT_DESCRIPTOR

#define USB_CS_ENDPOINT_DESCRIPTOR   37

A class-specific endpoint descriptor.

Definition at line 348 of file usb.h.

◆ for_each_config_descriptor

#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 ) )
static struct usb_descriptor_header * usb_next_descriptor(struct usb_descriptor_header *desc)
Get next USB descriptor.
Definition: usb.h:357
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct ena_aq_header header
Header.
Definition: ena.h:12
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45

Iterate over all configuration descriptors.

Definition at line 385 of file usb.h.

◆ for_each_interface_descriptor

#define for_each_interface_descriptor (   desc,
  config,
  interface 
)
Value:
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 ) )
static struct usb_descriptor_header * usb_next_descriptor(struct usb_descriptor_header *desc)
Get next USB descriptor.
Definition: usb.h:357
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define USB_INTERFACE_DESCRIPTOR
A USB interface descriptor.
Definition: usb.h:260
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An object interface.
Definition: interface.h:124
struct ena_aq_header header
Header.
Definition: ena.h:12
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:370
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45

Iterate over all configuration descriptors within an interface descriptor.

Definition at line 393 of file usb.h.

◆ USB_EP0_ADDRESS

#define USB_EP0_ADDRESS   0x00

Control endpoint address.

Definition at line 500 of file usb.h.

◆ USB_EP0_ATTRIBUTES

#define USB_EP0_ATTRIBUTES   0x00

Control endpoint attributes.

Definition at line 503 of file usb.h.

◆ USB_EP0_DEFAULT_MTU

#define USB_EP0_DEFAULT_MTU (   speed)
Value:
( ( (speed) >= USB_SPEED_SUPER ) ? 512 : \
( ( (speed) >= USB_SPEED_FULL ) ? 64 : 8 ) )
Super speed (5Gbps)
Definition: usb.h:54
Full speed (12Mbps)
Definition: usb.h:50

Calculate default MTU based on device speed.

Parameters
speedDevice speed
Return values
mtuDefault MTU

Definition at line 510 of file usb.h.

◆ USB_EP0_BURST

#define USB_EP0_BURST   0

Control endpoint maximum burst size.

Definition at line 515 of file usb.h.

◆ USB_EP0_INTERVAL

#define USB_EP0_INTERVAL   0

Control endpoint interval.

Definition at line 518 of file usb.h.

◆ USB_ENDPOINT_MAX

#define USB_ENDPOINT_MAX   0x0f

Maximum endpoint number.

Definition at line 521 of file usb.h.

◆ USB_ENDPOINT_IN

#define USB_ENDPOINT_IN   0x80

Endpoint direction is in.

Definition at line 524 of file usb.h.

◆ USB_ENDPOINT_IDX

#define USB_ENDPOINT_IDX (   address)
Value:
( ( (address) & USB_ENDPOINT_IN ) >> 3 ) )
uint64_t address
Base address.
Definition: ena.h:24
#define USB_ENDPOINT_MAX
Maximum endpoint number.
Definition: usb.h:521
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition: usb.h:524

Construct endpoint index from endpoint address.

Definition at line 527 of file usb.h.

◆ for_each_usb_bus

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

Iterate over all USB buses.

Definition at line 1076 of file usb.h.

◆ USB_RESET_DELAY_MS

#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 1327 of file usb.h.

◆ USB_RESET_RECOVER_DELAY_MS

#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 1334 of file usb.h.

◆ USB_CONTROL_MAX_WAIT_MS

#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 1341 of file usb.h.

◆ USB_SET_ADDRESS_RECOVER_DELAY_MS

#define USB_SET_ADDRESS_RECOVER_DELAY_MS   2

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 1348 of file usb.h.

◆ USB_PORT_DELAY_MS

#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 1357 of file usb.h.

◆ USB_ANY_ID

#define USB_ANY_ID   0xffff

Match-anything ID.

Definition at line 1372 of file usb.h.

◆ USB_CLASS_ID

#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 ), \
}, \
}, \
}
uint32_t base
Base.
Definition: librm.h:252
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1372
uint16_t protocol
Protocol ID.
Definition: stp.h:18

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 1388 of file usb.h.

◆ USB_DRIVERS

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

USB driver table.

Definition at line 1437 of file usb.h.

◆ __usb_driver

struct usb_driver iphone_driver __usb_driver   __table_entry ( USB_DRIVERS, 01 )

Declare a USB driver.

iPhone driver

USB RF-RNDIS driver.

Definition at line 1440 of file usb.h.

◆ __usb_fallback_driver

#define __usb_fallback_driver   __table_entry ( USB_DRIVERS, 02 )

Declare a USB fallback driver.

Definition at line 1443 of file usb.h.

Enumeration Type Documentation

◆ usb_protocol

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.

20  {
21  /** USB 2.0 */
22  USB_PROTO_2_0 = 0x0200,
23  /** USB 3.0 */
24  USB_PROTO_3_0 = 0x0300,
25  /** USB 3.1 */
26  USB_PROTO_3_1 = 0x0301,
27 };
USB 2.0.
Definition: usb.h:22
USB 3.0.
Definition: usb.h:24
USB 3.1.
Definition: usb.h:26

◆ usb_speed

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.

44  {
45  /** Not connected */
46  USB_SPEED_NONE = 0,
47  /** Low speed (1.5Mbps) */
48  USB_SPEED_LOW = USB_SPEED ( 1500, 1 ),
49  /** Full speed (12Mbps) */
50  USB_SPEED_FULL = USB_SPEED ( 12, 2 ),
51  /** High speed (480Mbps) */
52  USB_SPEED_HIGH = USB_SPEED ( 480, 2 ),
53  /** Super speed (5Gbps) */
54  USB_SPEED_SUPER = USB_SPEED ( 5, 3 ),
55 };
Low speed (1.5Mbps)
Definition: usb.h:48
Super speed (5Gbps)
Definition: usb.h:54
Not connected.
Definition: usb.h:46
#define USB_SPEED(mantissa, exponent)
Define a USB speed.
Definition: usb.h:35
High speed (480Mbps)
Definition: usb.h:52
Full speed (12Mbps)
Definition: usb.h:50

◆ usb_pid

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 72 of file usb.h.

72  {
73  /** IN PID */
74  USB_PID_IN = 0x69,
75  /** OUT PID */
76  USB_PID_OUT = 0xe1,
77  /** SETUP PID */
78  USB_PID_SETUP = 0x2d,
79 };
OUT PID.
Definition: usb.h:76
SETUP PID.
Definition: usb.h:78
IN PID.
Definition: usb.h:74

◆ usb_driver_score

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 1446 of file usb.h.

1446  {
1447  /** Fallback driver (has no effect on overall score) */
1448  USB_SCORE_FALLBACK = 0,
1449  /** Deprecated driver */
1451  /** Normal driver */
1452  USB_SCORE_NORMAL = 2,
1453 };
Deprecated driver.
Definition: usb.h:1450
Normal driver.
Definition: usb.h:1452
Fallback driver (has no effect on overall score)
Definition: usb.h:1448

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ usb_next_descriptor()

static struct usb_descriptor_header* usb_next_descriptor ( struct usb_descriptor_header desc)
inlinestatic

Get next USB descriptor.

Parameters
descUSB descriptor header
Return values
nextNext USB descriptor header

Definition at line 357 of file usb.h.

357  {
358 
359  return ( ( ( void * ) desc ) + desc->len );
360 }
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12

References desc.

Referenced by usb_endpoint_companion_descriptor(), and usb_is_within_config().

◆ usb_is_within_config()

static int usb_is_within_config ( struct usb_configuration_descriptor config,
struct usb_descriptor_header desc 
)
inlinestatic

Check that descriptor lies within a configuration descriptor.

Parameters
configConfiguration descriptor
descDescriptor header
is_withinDescriptor is within the configuration descriptor

Definition at line 370 of file usb.h.

371  {
372  struct usb_descriptor_header *end =
373  ( ( ( void * ) config ) + le16_to_cpu ( config->len ) );
374 
375  /* Check that descriptor starts within the configuration
376  * descriptor, and that the length does not exceed the
377  * configuration descriptor. This relies on the fact that
378  * usb_next_descriptor() needs to access only the first byte
379  * of the descriptor in order to determine the length.
380  */
381  return ( ( desc < end ) && ( usb_next_descriptor ( desc ) <= end ) );
382 }
static struct usb_descriptor_header * usb_next_descriptor(struct usb_descriptor_header *desc)
Get next USB descriptor.
Definition: usb.h:357
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define le16_to_cpu(value)
Definition: byteswap.h:112
A USB descriptor header.
Definition: usb.h:172
uint32_t end
Ending offset.
Definition: netvsc.h:18
uint16_t len
Total length.
Definition: usb.h:213

References desc, end, le16_to_cpu, usb_configuration_descriptor::len, and usb_next_descriptor().

Referenced by usb_endpoint_companion_descriptor().

◆ usb_endpoint_init()

static void usb_endpoint_init ( struct usb_endpoint ep,
struct usb_device usb,
struct usb_endpoint_driver_operations driver 
)
inlinestatic

Initialise USB endpoint.

Parameters
epUSB endpoint
usbUSB device
driverDriver operations

Definition at line 539 of file usb.h.

540  {
541 
542  ep->usb = usb;
543  ep->driver = driver;
544 }
struct usb_device * usb
USB device.
Definition: usb.h:405
struct usb_endpoint_driver_operations * driver
Driver operations.
Definition: usb.h:430

References usb_endpoint::driver, and usb_endpoint::usb.

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

◆ usb_endpoint_describe()

static void usb_endpoint_describe ( struct usb_endpoint ep,
unsigned int  address,
unsigned int  attributes,
size_t  mtu,
unsigned int  burst,
unsigned int  interval 
)
inlinestatic

Describe USB endpoint.

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

Definition at line 557 of file usb.h.

559  {
560 
561  ep->address = address;
562  ep->attributes = attributes;
563  ep->mtu = mtu;
564  ep->burst = burst;
565  ep->interval = interval;
566 }
uint64_t address
Base address.
Definition: ena.h:24
unsigned int burst
Maximum burst size.
Definition: usb.h:413
size_t mtu
Maximum transfer size.
Definition: usb.h:411
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
unsigned int interval
Interval (in microframes)
Definition: usb.h:415
unsigned int attributes
Attributes.
Definition: usb.h:409
unsigned int address
Endpoint address.
Definition: usb.h:407

References address, usb_endpoint::address, usb_endpoint::attributes, usb_endpoint::burst, usb_endpoint::interval, mtu, and usb_endpoint::mtu.

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

◆ usb_endpoint_set_hostdata()

static void usb_endpoint_set_hostdata ( struct usb_endpoint ep,
void *  priv 
)
inlinestatic

Set USB endpoint host controller private data.

Parameters
epUSB endpoint
privHost controller private data

Definition at line 575 of file usb.h.

575  {
576  ep->priv = priv;
577 }
void * priv
Host controller private data.
Definition: usb.h:428
static struct tlan_private * priv
Definition: tlan.c:224

References priv, and usb_endpoint::priv.

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

◆ usb_endpoint_get_hostdata()

static void* usb_endpoint_get_hostdata ( struct usb_endpoint ep)
inlinestatic

Get USB endpoint host controller private data.

Parameters
epUSB endpoint
Return values
privHost controller private data

Definition at line 586 of file usb.h.

586  {
587  return ep->priv;
588 }
void * priv
Host controller private data.
Definition: usb.h:428

References usb_endpoint::priv.

Referenced by ehci_endpoint_close(), ehci_endpoint_message(), ehci_endpoint_reset(), ehci_endpoint_stream(), ehci_endpoint_update(), uhci_device_address(), uhci_endpoint_close(), uhci_endpoint_message(), uhci_endpoint_mtu(), uhci_endpoint_reset(), uhci_endpoint_stream(), usbio_endpoint_close(), usbio_endpoint_enqueue(), xhci_endpoint_close(), xhci_endpoint_message(), xhci_endpoint_mtu(), xhci_endpoint_reset(), and xhci_endpoint_stream().

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

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

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

244  {
245  struct usb_device *usb = ep->usb;
247  struct usb_endpoint_companion_descriptor *descx;
248  unsigned int sizes;
249  unsigned int burst;
250  unsigned int interval;
251  size_t mtu;
252 
253  /* Locate endpoint descriptor */
255  if ( ! desc )
256  return -ENOENT;
257 
258  /* Locate companion descriptor, if any */
259  descx = usb_endpoint_companion_descriptor ( config, desc );
260 
261  /* Calculate MTU and burst size */
262  sizes = le16_to_cpu ( desc->sizes );
263  mtu = USB_ENDPOINT_MTU ( sizes );
264  burst = ( descx ? descx->burst : USB_ENDPOINT_BURST ( sizes ) );
265 
266  /* Calculate interval */
267  if ( ( type & USB_ENDPOINT_ATTR_TYPE_MASK ) ==
269  if ( usb->speed >= USB_SPEED_HIGH ) {
270  /* 2^(desc->interval-1) is a microframe count */
271  interval = ( 1 << ( desc->interval - 1 ) );
272  } else {
273  /* desc->interval is a (whole) frame count */
274  interval = ( desc->interval << 3 );
275  }
276  } else {
277  /* desc->interval is a microframe count */
278  interval = desc->interval;
279  }
280 
281  /* Describe endpoint */
282  usb_endpoint_describe ( ep, desc->endpoint, desc->attributes,
283  mtu, burst, interval );
284  return 0;
285 }
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:557
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:280
uint32_t type
Operating system type.
Definition: ena.h:12
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
long index
Definition: bigint.h:62
#define ENOENT
No such file or directory.
Definition: errno.h:514
unsigned int speed
Device speed.
Definition: usb.h:728
An object interface.
Definition: interface.h:124
#define USB_ENDPOINT_BURST(sizes)
USB endpoint maximum burst size.
Definition: usb.h:310
A USB device.
Definition: usb.h:722
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:292
#define le16_to_cpu(value)
Definition: byteswap.h:112
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:194
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:167
A USB endpoint descriptor.
Definition: usb.h:263
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
A USB endpoint companion descriptor.
Definition: usb.h:313
High speed (480Mbps)
Definition: usb.h:52
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
struct usb_device * usb
USB device.
Definition: usb.h:405
#define USB_ENDPOINT_MTU(sizes)
USB endpoint MTU.
Definition: usb.h:307
uint8_t burst
Maximum burst size.
Definition: usb.h:317

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

293  {
294  struct usb_device *usb = ep->usb;
295  unsigned int idx = USB_ENDPOINT_IDX ( ep->address );
296  int rc;
297 
298  /* Populate host controller operations */
299  ep->host = &usb->port->hub->bus->op->endpoint;
300 
301  /* Add to endpoint list */
302  if ( usb->ep[idx] != NULL ) {
303  DBGC ( usb, "USB %s %s is already open\n",
304  usb->name, usb_endpoint_name ( ep ) );
305  rc = -EALREADY;
306  goto err_already;
307  }
308  usb->ep[idx] = ep;
309  INIT_LIST_HEAD ( &ep->halted );
310 
311  /* Open endpoint */
312  if ( ( rc = ep->host->open ( ep ) ) != 0 ) {
313  DBGC ( usb, "USB %s %s could not open: %s\n", usb->name,
314  usb_endpoint_name ( ep ), strerror ( rc ) );
315  goto err_open;
316  }
317  ep->open = 1;
318 
319  DBGC2 ( usb, "USB %s %s opened with MTU %zd, burst %d, interval %d\n",
320  usb->name, usb_endpoint_name ( ep ), ep->mtu, ep->burst,
321  ep->interval );
322  return 0;
323 
324  ep->open = 0;
325  ep->host->close ( ep );
326  err_open:
327  usb->ep[idx] = NULL;
328  err_already:
329  if ( ep->max )
330  usb_flush ( ep );
331  return rc;
332 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void(* close)(struct usb_endpoint *ep)
Close endpoint.
Definition: usb.h:454
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:418
struct usb_port * port
USB port.
Definition: usb.h:726
struct list_head halted
List of halted endpoints.
Definition: usb.h:423
unsigned int burst
Maximum burst size.
Definition: usb.h:413
char name[32]
Name.
Definition: usb.h:724
A USB device.
Definition: usb.h:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:527
#define EALREADY
Connection already in progress.
Definition: errno.h:323
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
size_t mtu
Maximum transfer size.
Definition: usb.h:411
struct usb_host_operations * op
Host controller operations set.
Definition: usb.h:971
unsigned int max
Maximum fill level.
Definition: usb.h:439
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define DBGC2(...)
Definition: compiler.h:522
struct usb_hub * hub
USB hub.
Definition: usb.h:814
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
unsigned int interval
Interval (in microframes)
Definition: usb.h:415
struct usb_endpoint_host_operations endpoint
Endpoint operations.
Definition: usb.h:1032
struct usb_device * usb
USB device.
Definition: usb.h:405
int(* open)(struct usb_endpoint *ep)
Open endpoint.
Definition: usb.h:449
void usb_flush(struct usb_endpoint *ep)
Discard endpoint recycled buffer list.
Definition: usb.c:719
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:426
struct usb_bus * bus
USB bus.
Definition: usb.h:844
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
unsigned int address
Endpoint address.
Definition: usb.h:407

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

371  {
372  struct usb_device *usb = ep->usb;
373  unsigned int type;
374  int rc;
375 
376  /* Clear transaction translator, if applicable */
377  if ( ( rc = usb_endpoint_clear_tt ( ep ) ) != 0 )
378  return rc;
379 
380  /* Clear endpoint halt (if applicable) */
382  if ( ( type != USB_ENDPOINT_ATTR_CONTROL ) &&
385  ep->address ) ) != 0 ) ) {
386  DBGC ( usb, "USB %s %s could not clear endpoint halt: %s\n",
387  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
388  return rc;
389  }
390 
391  return 0;
392 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:280
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:118
static int usb_clear_feature(struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
Clear feature.
Definition: usb.h:1126
char name[32]
Name.
Definition: usb.h:724
A USB device.
Definition: usb.h:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
static int usb_endpoint_clear_tt(struct usb_endpoint *ep)
Clear transaction translator (if applicable)
Definition: usb.c:340
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
#define USB_ENDPOINT_ATTR_CONTROL
Control endpoint transfer type.
Definition: usb.h:286
struct usb_device * usb
USB device.
Definition: usb.h:405
#define USB_ENDPOINT_HALT
Endpoint halt feature.
Definition: usb.h:156
unsigned int attributes
Attributes.
Definition: usb.h:409
unsigned int address
Endpoint address.
Definition: usb.h:407

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

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

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

493  {
494  struct usb_device *usb = ep->usb;
495  struct usb_port *port = usb->port;
496  struct usb_setup_packet *packet;
497  size_t len = iob_len ( iobuf );
498  int rc;
499 
500  /* Sanity check */
501  assert ( iob_headroom ( iobuf ) >= sizeof ( *packet ) );
502 
503  /* Fail immediately if device has been unplugged */
504  if ( port->disconnected )
505  return -ENODEV;
506 
507  /* Reset endpoint if required */
508  if ( ( ! list_empty ( &ep->halted ) ) &&
509  ( ( rc = usb_endpoint_reset ( ep ) ) != 0 ) )
510  return rc;
511 
512  /* Zero input data buffer (if applicable) */
513  if ( request & USB_DIR_IN )
514  memset ( iobuf->data, 0, len );
515 
516  /* Construct setup packet */
517  packet = iob_push ( iobuf, sizeof ( *packet ) );
518  packet->request = cpu_to_le16 ( request );
519  packet->value = cpu_to_le16 ( value );
520  packet->index = cpu_to_le16 ( index );
521  packet->len = cpu_to_le16 ( len );
522 
523  /* Enqueue message transfer */
524  if ( ( rc = ep->host->message ( ep, iobuf ) ) != 0 ) {
525  DBGC ( usb, "USB %s %s could not enqueue message transfer: "
526  "%s\n", usb->name, usb_endpoint_name ( ep ),
527  strerror ( rc ) );
528  return rc;
529  }
530 
531  /* Increment fill level */
532  ep->fill++;
533 
534  return 0;
535 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_push(iobuf, len)
Definition: iobuf.h:84
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:834
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
A USB port.
Definition: usb.h:812
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:726
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint16_t index
Index parameter.
Definition: usb.h:88
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct list_head halted
List of halted endpoints.
Definition: usb.h:423
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:97
char name[32]
Name.
Definition: usb.h:724
A USB device.
Definition: usb.h:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
#define ENODEV
No such device.
Definition: errno.h:509
static int usb_endpoint_reset(struct usb_endpoint *ep)
Reset USB endpoint.
Definition: usb.c:429
unsigned int fill
Buffer fill level.
Definition: usb.h:420
A USB setup data packet.
Definition: usb.h:82
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
uint16_t request
Request.
Definition: usb.h:84
static size_t iob_headroom(struct io_buffer *iobuf)
Calculate available space at start of an I/O buffer.
Definition: iobuf.h:165
void * data
Start of data.
Definition: iobuf.h:48
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
#define cpu_to_le16(value)
Definition: byteswap.h:106
uint16_t len
Length of data stage.
Definition: usb.h:90
struct usb_device * usb
USB device.
Definition: usb.h:405
int(* message)(struct usb_endpoint *ep, struct io_buffer *iobuf)
Enqueue message transfer.
Definition: usb.h:474
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:426
uint16_t value
Value parameter.
Definition: usb.h:86
uint32_t len
Length.
Definition: ena.h:14
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, len, usb_setup_packet::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 545 of file usb.c.

546  {
547  struct usb_device *usb = ep->usb;
548  struct usb_port *port = usb->port;
549  int zlp;
550  int rc;
551 
552  /* Fail immediately if device has been unplugged */
553  if ( port->disconnected )
554  return -ENODEV;
555 
556  /* Reset endpoint if required */
557  if ( ( ! list_empty ( &ep->halted ) ) &&
558  ( ( rc = usb_endpoint_reset ( ep ) ) != 0 ) )
559  return rc;
560 
561  /* Append a zero-length packet if necessary */
562  zlp = terminate;
563  if ( iob_len ( iobuf ) & ( ep->mtu - 1 ) )
564  zlp = 0;
565 
566  /* Enqueue stream transfer */
567  if ( ( rc = ep->host->stream ( ep, iobuf, zlp ) ) != 0 ) {
568  DBGC ( usb, "USB %s %s could not enqueue stream transfer: %s\n",
569  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
570  return rc;
571  }
572 
573  /* Increment fill level */
574  ep->fill++;
575 
576  return 0;
577 }
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:834
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
A USB port.
Definition: usb.h:812
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:726
struct list_head halted
List of halted endpoints.
Definition: usb.h:423
char name[32]
Name.
Definition: usb.h:724
A USB device.
Definition: usb.h:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
#define ENODEV
No such device.
Definition: errno.h:509
static int usb_endpoint_reset(struct usb_endpoint *ep)
Reset USB endpoint.
Definition: usb.c:429
unsigned int fill
Buffer fill level.
Definition: usb.h:420
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
size_t mtu
Maximum transfer size.
Definition: usb.h:411
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
struct usb_device * usb
USB device.
Definition: usb.h:405
struct usb_endpoint_host_operations * host
Host controller operations.
Definition: usb.h:426
int(* stream)(struct usb_endpoint *ep, struct io_buffer *iobuf, int zlp)
Enqueue stream transfer.
Definition: usb.h:483

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

587  {
588  struct usb_device *usb = ep->usb;
589 
590  /* Decrement fill level */
591  assert ( ep->fill > 0 );
592  ep->fill--;
593 
594  /* Schedule reset, if applicable */
595  if ( ( rc != 0 ) && ep->open ) {
596  DBGC ( usb, "USB %s %s completion failed: %s\n",
597  usb->name, usb_endpoint_name ( ep ), strerror ( rc ) );
598  list_del ( &ep->halted );
600  }
601 
602  /* Report completion */
603  ep->driver->complete ( ep, iobuf, rc );
604 }
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:495
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:418
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
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:93
struct list_head halted
List of halted endpoints.
Definition: usb.h:423
char name[32]
Name.
Definition: usb.h:724
A USB device.
Definition: usb.h:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
unsigned int fill
Buffer fill level.
Definition: usb.h:420
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
static struct list_head usb_halted
List of halted endpoints.
Definition: usb.c:50
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
struct usb_device * usb
USB device.
Definition: usb.h:405
struct usb_endpoint_driver_operations * driver
Driver operations.
Definition: usb.h:430

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

static void usb_refill_init ( struct usb_endpoint ep,
size_t  reserve,
size_t  len,
unsigned int  max 
)
inlinestatic

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 616 of file usb.h.

617  {
618 
619  INIT_LIST_HEAD ( &ep->recycled );
620  ep->reserve = reserve;
621  ep->len = len;
622  ep->max = max;
623 }
#define max(x, y)
Definition: ath.h:39
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:433
size_t len
Refill buffer payload length.
Definition: usb.h:437
size_t reserve
Refill buffer reserved header length.
Definition: usb.h:435
unsigned int max
Maximum fill level.
Definition: usb.h:439
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744
uint32_t len
Length.
Definition: ena.h:14

References INIT_LIST_HEAD, len, usb_endpoint::len, max, usb_endpoint::max, usb_endpoint::recycled, and usb_endpoint::reserve.

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

◆ usb_recycle()

static void usb_recycle ( struct usb_endpoint ep,
struct io_buffer iobuf 
)
inlinestatic

Recycle I/O buffer.

Parameters
epUSB endpoint
iobufI/O buffer

Definition at line 632 of file usb.h.

632  {
633 
634  list_add_tail ( &iobuf->list, &ep->recycled );
635 }
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:433
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744

References io_buffer::list, list_add_tail, and usb_endpoint::recycled.

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

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

619  {
620  struct io_buffer *iobuf;
621  size_t reserve = ep->reserve;
622  size_t len = ( ep->len ? ep->len : ep->mtu );
623  unsigned int fill;
624  int rc;
625 
626  /* Sanity checks */
627  assert ( ep->fill == 0 );
628  assert ( ep->max > 0 );
629  assert ( list_empty ( &ep->recycled ) );
630 
631  /* Fill recycled buffer list */
632  for ( fill = 0 ; fill < ep->max ; fill++ ) {
633 
634  /* Allocate I/O buffer */
635  iobuf = alloc_iob ( reserve + len );
636  if ( ! iobuf ) {
637  rc = -ENOMEM;
638  goto err_alloc;
639  }
640  iob_reserve ( iobuf, reserve );
641 
642  /* Add to recycled buffer list */
643  list_add_tail ( &iobuf->list, &ep->recycled );
644  }
645 
646  return 0;
647 
648  err_alloc:
649  usb_flush ( ep );
650  return rc;
651 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:433
size_t len
Refill buffer payload length.
Definition: usb.h:437
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define ENOMEM
Not enough space.
Definition: errno.h:534
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:93
size_t reserve
Refill buffer reserved header length.
Definition: usb.h:435
unsigned int fill
Buffer fill level.
Definition: usb.h:420
size_t mtu
Maximum transfer size.
Definition: usb.h:411
#define iob_reserve(iobuf, len)
Definition: iobuf.h:67
unsigned int max
Maximum fill level.
Definition: usb.h:439
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
void usb_flush(struct usb_endpoint *ep)
Discard endpoint recycled buffer list.
Definition: usb.c:719
uint32_t len
Length.
Definition: ena.h:14
static int fill
Definition: string.h:208
A persistent I/O buffer.
Definition: iobuf.h:33

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

660  {
661  struct io_buffer *iobuf;
662  size_t reserve = ep->reserve;
663  size_t len = ( ep->len ? ep->len : ep->mtu );
664  int rc;
665 
666  /* Sanity checks */
667  assert ( ep->open );
668  assert ( ep->max > 0 );
669 
670  /* Refill endpoint */
671  if ( max > ep->max )
672  max = ep->max;
673  while ( ep->fill < max ) {
674 
675  /* Get or allocate buffer */
676  if ( list_empty ( &ep->recycled ) ) {
677  /* Recycled buffer list is empty; allocate new buffer */
678  iobuf = alloc_iob ( reserve + len );
679  if ( ! iobuf )
680  return -ENOMEM;
681  iob_reserve ( iobuf, reserve );
682  } else {
683  /* Get buffer from recycled buffer list */
684  iobuf = list_first_entry ( &ep->recycled,
685  struct io_buffer, list );
686  assert ( iobuf != NULL );
687  list_del ( &iobuf->list );
688  }
689 
690  /* Reset buffer to maximum size */
691  assert ( iob_len ( iobuf ) <= len );
692  iob_put ( iobuf, ( len - iob_len ( iobuf ) ) );
693 
694  /* Enqueue buffer */
695  if ( ( rc = usb_stream ( ep, iobuf, 0 ) ) != 0 ) {
696  list_add ( &iobuf->list, &ep->recycled );
697  return rc;
698  }
699  }
700 
701  return 0;
702 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
#define max(x, y)
Definition: ath.h:39
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:433
size_t len
Refill buffer payload length.
Definition: usb.h:437
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:545
int open
Endpoint is open.
Definition: usb.h:418
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
size_t reserve
Refill buffer reserved header length.
Definition: usb.h:435
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
unsigned int fill
Buffer fill level.
Definition: usb.h:420
size_t mtu
Maximum transfer size.
Definition: usb.h:411
#define iob_reserve(iobuf, len)
Definition: iobuf.h:67
unsigned int max
Maximum fill level.
Definition: usb.h:439
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:33

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

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

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

719  {
720  struct io_buffer *iobuf;
721  struct io_buffer *tmp;
722 
723  /* Sanity checks */
724  assert ( ! ep->open );
725  assert ( ep->max > 0 );
726 
727  /* Free all I/O buffers */
728  list_for_each_entry_safe ( iobuf, tmp, &ep->recycled, list ) {
729  list_del ( &iobuf->list );
730  free_iob ( iobuf );
731  }
732 }
struct list_head recycled
Recycled I/O buffer list.
Definition: usb.h:433
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
int open
Endpoint is open.
Definition: usb.h:418
unsigned long tmp
Definition: linux_pci.h:63
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
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:458
unsigned int max
Maximum fill level.
Definition: usb.h:439
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
A persistent I/O buffer.
Definition: iobuf.h:33

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

static void usb_func_set_drvdata ( struct usb_function func,
void *  priv 
)
inlinestatic

Set USB function driver private data.

Parameters
funcUSB function
privDriver private data

Definition at line 706 of file usb.h.

706  {
707  func->priv = priv;
708 }
void * priv
Driver private data.
Definition: usb.h:688
static struct tlan_private * priv
Definition: tlan.c:224

References priv, and usb_function::priv.

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

◆ usb_func_get_drvdata()

static void* usb_func_get_drvdata ( struct usb_function func)
inlinestatic

Get USB function driver private data.

Parameters
functionUSB function
Return values
privDriver private data

Definition at line 717 of file usb.h.

717  {
718  return func->priv;
719 }
void * priv
Driver private data.
Definition: usb.h:688

References usb_function::priv.

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

◆ usb_set_hostdata()

static void usb_set_hostdata ( struct usb_device usb,
void *  priv 
)
inlinestatic

Set USB device host controller private data.

Parameters
usbUSB device
privHost controller private data

Definition at line 783 of file usb.h.

783  {
784  usb->priv = priv;
785 }
void * priv
Host controller private data.
Definition: usb.h:741
static struct tlan_private * priv
Definition: tlan.c:224

References priv, and usb_device::priv.

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

◆ usb_get_hostdata()

static void* usb_get_hostdata ( struct usb_device usb)
inlinestatic

Get USB device host controller private data.

Parameters
usbUSB device
Return values
privHost controller private data

Definition at line 794 of file usb.h.

794  {
795  return usb->priv;
796 }
void * priv
Host controller private data.
Definition: usb.h:741

References usb_device::priv.

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

◆ usb_endpoint()

static struct usb_endpoint* usb_endpoint ( struct usb_device usb,
unsigned int  address 
)
inlinestatic

Get USB endpoint.

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

Definition at line 805 of file usb.h.

806  {
807 
808  return usb->ep[ USB_ENDPOINT_IDX ( address ) ];
809 }
uint64_t address
Base address.
Definition: ena.h:24
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:527
struct usb_endpoint * ep[32]
Endpoint list.
Definition: usb.h:744

References address, usb_device::ep, usb_endpoint::usb, and USB_ENDPOINT_IDX.

Referenced by ehci_device_address(), and uhci_device_address().

◆ usb_hub_set_drvdata()

static void usb_hub_set_drvdata ( struct usb_hub hub,
void *  priv 
)
inlinestatic

Set USB hub driver private data.

Parameters
hubUSB hub
privDriver private data

Definition at line 936 of file usb.h.

936  {
937  hub->priv = priv;
938 }
void * priv
Driver private data.
Definition: usb.h:860
static struct tlan_private * priv
Definition: tlan.c:224

References priv, and usb_hub::priv.

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

◆ usb_hub_get_drvdata()

static void* usb_hub_get_drvdata ( struct usb_hub hub)
inlinestatic

◆ usb_port()

static struct usb_port* usb_port ( struct usb_hub hub,
unsigned int  address 
)
inlinestatic

Get USB port.

Parameters
hubUSB hub
addressPort address
Return values
portUSB port

Definition at line 959 of file usb.h.

959  {
960 
961  return &hub->port[ address - 1 ];
962 }
uint64_t address
Base address.
Definition: ena.h:24
struct usb_port port[0]
Port list.
Definition: usb.h:866

References address, usb_port::hub, and usb_hub::port.

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

◆ usb_bus_set_hostdata()

static void usb_bus_set_hostdata ( struct usb_bus bus,
void *  priv 
)
inlinestatic

Set USB bus host controller private data.

Parameters
busUSB bus
privHost controller private data

Definition at line 1050 of file usb.h.

1050  {
1051  bus->priv = priv;
1052 }
static struct tlan_private * priv
Definition: tlan.c:224
uint8_t bus
Bus.
Definition: edd.h:14

References bus, and priv.

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

◆ usb_bus_get_hostdata()

static void* usb_bus_get_hostdata ( struct usb_bus bus)
inlinestatic

Get USB bus host controller private data.

Parameters
busUSB bus
Return values
privHost controller private data

Definition at line 1061 of file usb.h.

1061  {
1062  return bus->priv;
1063 }
uint8_t bus
Bus.
Definition: edd.h:14

References bus.

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

◆ usb_poll()

static void usb_poll ( struct usb_bus bus)
inlinestatic

Poll USB bus.

Parameters
busUSB bus

Definition at line 1071 of file usb.h.

1071  {
1072  bus->host->poll ( bus );
1073 }
uint8_t bus
Bus.
Definition: edd.h:14

References bus.

Referenced by acm_poll(), axge_poll(), dm96xx_poll(), ecm_poll(), efi_usb_sync_transfer(), efi_usb_timer(), ehci_poll_companions(), imux_step(), iphone_poll(), ncm_poll(), register_usb_hub(), smsc75xx_poll(), smsc95xx_poll(), usb_control(), usb_step(), and usbkbd_iskey().

◆ usb_complete()

static void usb_complete ( struct usb_endpoint ep,
struct io_buffer iobuf 
)
inlinestatic

Complete transfer (without error)

Parameters
epUSB endpoint
iobufI/O buffer

Definition at line 1086 of file usb.h.

1086  {
1087  usb_complete_err ( ep, iobuf, 0 );
1088 }
void usb_complete_err(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete transfer (possibly with error)
Definition: usb.c:586

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

785  {
786  struct usb_bus *bus = usb->port->hub->bus;
787  struct usb_endpoint *ep = &usb->control;
788  struct io_buffer *iobuf;
789  struct io_buffer *cmplt;
790  union {
791  struct usb_setup_packet setup;
792  struct usb_control_pseudo_header pshdr;
793  } *headroom;
794  struct usb_control_pseudo_header *pshdr;
795  unsigned int i;
796  int rc;
797 
798  /* Allocate I/O buffer */
799  iobuf = alloc_iob ( sizeof ( *headroom ) + len );
800  if ( ! iobuf ) {
801  rc = -ENOMEM;
802  goto err_alloc;
803  }
804  iob_reserve ( iobuf, sizeof ( *headroom ) );
805  iob_put ( iobuf, len );
806  if ( request & USB_DIR_IN ) {
807  memset ( data, 0, len );
808  } else {
809  memcpy ( iobuf->data, data, len );
810  }
811 
812  /* Enqueue message */
813  if ( ( rc = usb_message ( ep, request, value, index, iobuf ) ) != 0 )
814  goto err_message;
815 
816  /* Wait for completion */
817  for ( i = 0 ; i < USB_CONTROL_MAX_WAIT_MS ; i++ ) {
818 
819  /* Poll bus */
820  usb_poll ( bus );
821 
822  /* Check for completion */
823  while ( ( cmplt = list_first_entry ( &usb->complete,
824  struct io_buffer,
825  list ) ) ) {
826 
827  /* Remove from completion list */
828  list_del ( &cmplt->list );
829 
830  /* Extract and strip completion status */
831  pshdr = cmplt->data;
832  iob_pull ( cmplt, sizeof ( *pshdr ) );
833  rc = pshdr->rc;
834 
835  /* Discard stale completions */
836  if ( cmplt != iobuf ) {
837  DBGC ( usb, "USB %s stale control completion: "
838  "%s\n", usb->name, strerror ( rc ) );
839  DBGC_HDA ( usb, 0, cmplt->data,
840  iob_len ( cmplt ) );
841  free_iob ( cmplt );
842  continue;
843  }
844 
845  /* Fail immediately if completion was in error */
846  if ( rc != 0 ) {
847  DBGC ( usb, "USB %s control %04x:%04x:%04x "
848  "failed: %s\n", usb->name, request,
849  value, index, strerror ( rc ) );
850  free_iob ( cmplt );
851  usb_endpoint_reset ( ep );
852  return rc;
853  }
854 
855  /* Copy completion to data buffer, if applicable */
856  assert ( iob_len ( cmplt ) <= len );
857  if ( request & USB_DIR_IN )
858  memcpy ( data, cmplt->data, iob_len ( cmplt ) );
859  free_iob ( cmplt );
860  return 0;
861  }
862 
863  /* Delay */
864  mdelay ( 1 );
865  }
866 
867  DBGC ( usb, "USB %s timed out waiting for control %04x:%04x:%04x\n",
868  usb->name, request, value, index );
869  return -ETIMEDOUT;
870 
871  err_message:
872  free_iob ( iobuf );
873  err_alloc:
874  return rc;
875 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
int rc
Completion status.
Definition: usb.c:744
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
A USB endpoint.
Definition: usb.h:403
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:491
struct usb_port * port
USB port.
Definition: usb.h:726
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
#define USB_CONTROL_MAX_WAIT_MS
Maximum time to wait for a control transaction to complete.
Definition: usb.h:1341
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:97
char name[32]
Name.
Definition: usb.h:724
struct usb_endpoint control
Control endpoint.
Definition: usb.h:747
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1071
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
static int usb_endpoint_reset(struct usb_endpoint *ep)
Reset USB endpoint.
Definition: usb.c:429
USB control transfer pseudo-header.
Definition: usb.c:742
A USB setup data packet.
Definition: usb.h:82
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define iob_reserve(iobuf, len)
Definition: iobuf.h:67
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
struct list_head complete
Completed control transfers.
Definition: usb.h:749
void * data
Start of data.
Definition: iobuf.h:48
struct usb_hub * hub
USB hub.
Definition: usb.h:814
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:405
struct usb_bus * bus
USB bus.
Definition: usb.h:844
uint32_t len
Length.
Definition: ena.h:14
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
A USB bus.
Definition: usb.h:965
uint8_t bus
Bus.
Definition: edd.h:14
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33

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

916  {
917  struct {
919  uint16_t character[len];
920  } __attribute__ (( packed )) *desc;
921  unsigned int actual;
922  unsigned int i;
923  int rc;
924 
925  /* Use default language ID, if applicable */
926  if ( ( language == 0 ) && ( index != 0 ) ) {
927  if ( ! usb->language )
928  usb->language = usb_get_default_language ( usb );
929  language = usb->language;
930  }
931 
932  /* Allocate buffer for string */
933  desc = malloc ( sizeof ( *desc ) );
934  if ( ! desc ) {
935  rc = -ENOMEM;
936  goto err_alloc;
937  }
938 
939  /* Get descriptor */
940  if ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, index,
941  language, &desc->header,
942  sizeof ( *desc ) ) ) != 0 )
943  goto err_get_descriptor;
944 
945  /* Calculate string length */
946  if ( desc->header.len < sizeof ( desc->header ) ) {
947  rc = -EINVAL;
948  goto err_len;
949  }
950  actual = ( ( desc->header.len - sizeof ( desc->header ) ) /
951  sizeof ( desc->character[0] ) );
952 
953  /* Copy to buffer */
954  memset ( buf, 0, len );
955  for ( i = 0 ; ( ( i < actual ) && ( i < len ) ) ; i++ )
956  buf[i] = le16_to_cpu ( desc->character[i] );
957 
958  /* Free buffer */
959  free ( desc );
960 
961  return actual;
962 
963  err_len:
964  err_get_descriptor:
965  free ( desc );
966  err_alloc:
967  return rc;
968 }
#define __attribute__(x)
Definition: compiler.h:10
#define EINVAL
Invalid argument.
Definition: errno.h:428
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:883
#define USB_STRING_DESCRIPTOR
A USB string descriptor.
Definition: usb.h:238
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
long index
Definition: bigint.h:62
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define le16_to_cpu(value)
Definition: byteswap.h:112
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
A USB descriptor header.
Definition: usb.h:172
unsigned int language
Default language ID (if known)
Definition: usb.h:752
struct ena_aq_header header
Header.
Definition: ena.h:12
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:1176
uint32_t len
Length.
Definition: ena.h:14
void * memset(void *dest, int character, size_t len) __nonnull

References __attribute__, desc, EINVAL, ENOMEM, free, header, index, usb_device::language, le16_to_cpu, len, usb_descriptor_header::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_get_status()

static int usb_get_status ( struct usb_device usb,
unsigned int  type,
unsigned int  index,
void *  data,
size_t  len 
)
inlinestatic

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 1109 of file usb.h.

1110  {
1111 
1112  return usb_control ( usb, ( USB_GET_STATUS | type ), 0, index,
1113  data, len );
1114 }
uint32_t type
Operating system type.
Definition: ena.h:12
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.
Definition: usb.c:783
long index
Definition: bigint.h:62
#define USB_GET_STATUS
Get status.
Definition: usb.h:124
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

References data, index, len, type, usb_control(), and USB_GET_STATUS.

Referenced by usb_hub_get_port_status().

◆ usb_clear_feature()

static int usb_clear_feature ( struct usb_device usb,
unsigned int  type,
unsigned int  feature,
unsigned int  index 
)
inlinestatic

Clear feature.

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

Definition at line 1126 of file usb.h.

1127  {
1128 
1129  return usb_control ( usb, ( USB_CLEAR_FEATURE | type ),
1130  feature, index, NULL, 0 );
1131 }
uint32_t type
Operating system type.
Definition: ena.h:12
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.
Definition: usb.c:783
long index
Definition: bigint.h:62
#define USB_CLEAR_FEATURE
Clear feature.
Definition: usb.h:127
A named feature.
Definition: features.h:78
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References index, NULL, type, USB_CLEAR_FEATURE, and usb_control().

Referenced by usb_endpoint_clear_halt(), and usb_hub_clear_port_feature().

◆ usb_set_feature()

static int usb_set_feature ( struct usb_device usb,
unsigned int  type,
unsigned int  feature,
unsigned int  index 
)
inlinestatic

Set feature.

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

Definition at line 1143 of file usb.h.

1144  {
1145 
1146  return usb_control ( usb, ( USB_SET_FEATURE | type ),
1147  feature, index, NULL, 0 );
1148 }
uint32_t type
Operating system type.
Definition: ena.h:12
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.
Definition: usb.c:783
long index
Definition: bigint.h:62
A named feature.
Definition: features.h:78
#define USB_SET_FEATURE
Set feature.
Definition: usb.h:130
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References index, NULL, type, usb_control(), and USB_SET_FEATURE.

Referenced by usb_hub_set_port_feature().

◆ usb_set_address()

static int usb_set_address ( struct usb_device usb,
unsigned int  address 
)
inlinestatic

Set address.

Parameters
usbUSB device
addressDevice address
Return values
rcReturn status code

Definition at line 1158 of file usb.h.

1158  {
1159 
1160  return usb_control ( usb, USB_SET_ADDRESS, address, 0, NULL, 0 );
1161 }
uint64_t address
Base address.
Definition: ena.h:24
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.
Definition: usb.c:783
#define USB_SET_ADDRESS
Set address.
Definition: usb.h:133
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References address, NULL, usb_control(), and USB_SET_ADDRESS.

Referenced by ehci_device_address(), and uhci_device_address().

◆ usb_get_descriptor()

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

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 1176 of file usb.h.

1179  {
1180 
1181  return usb_control ( usb, ( USB_GET_DESCRIPTOR | type ),
1182  ( ( desc << 8 ) | index ), language, data, len );
1183 }
#define USB_GET_DESCRIPTOR
Get descriptor.
Definition: usb.h:136
uint32_t type
Operating system type.
Definition: ena.h:12
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
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.
Definition: usb.c:783
long index
Definition: bigint.h:62
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

References data, desc, index, len, type, 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().

◆ usb_get_mtu()

static int usb_get_mtu ( struct usb_device usb,
struct usb_device_descriptor data 
)
inlinestatic

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 1193 of file usb.h.

1193  {
1194 
1195  return usb_get_descriptor ( usb, 0, USB_DEVICE_DESCRIPTOR, 0, 0,
1196  &data->header,
1197  ( offsetof ( typeof ( *data ), mtu ) +
1198  sizeof ( data->mtu ) ) );
1199 }
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
uint8_t data[48]
Additional event data.
Definition: ena.h:22
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
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:1176
Standard Device Descriptor USB 2.0 spec, Section 9.6.1.
Definition: Usb.h:106

References data, mtu, offsetof, typeof(), and usb_get_descriptor().

Referenced by register_usb().

◆ usb_get_device_descriptor()

static int usb_get_device_descriptor ( struct usb_device usb,
struct usb_device_descriptor data 
)
inlinestatic

Get USB device descriptor.

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

Definition at line 1209 of file usb.h.

1210  {
1211 
1212  return usb_get_descriptor ( usb, 0, USB_DEVICE_DESCRIPTOR, 0, 0,
1213  &data->header, sizeof ( *data ) );
1214 }
uint8_t data[48]
Additional event data.
Definition: ena.h:22
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:1176
Standard Device Descriptor USB 2.0 spec, Section 9.6.1.
Definition: Usb.h:106

References data, and usb_get_descriptor().

Referenced by register_usb().

◆ usb_get_config_descriptor()

static int usb_get_config_descriptor ( struct usb_device usb,
unsigned int  index,
struct usb_configuration_descriptor data,
size_t  len 
)
inlinestatic

Get USB configuration descriptor.

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

Definition at line 1225 of file usb.h.

1227  {
1228 
1230  0, &data->header, len );
1231 }
long index
Definition: bigint.h:62
#define USB_CONFIGURATION_DESCRIPTOR
A USB configuration descriptor.
Definition: usb.h:227
uint8_t data[48]
Additional event data.
Definition: ena.h:22
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:1176
uint32_t len
Length.
Definition: ena.h:14

References data, index, len, USB_CONFIGURATION_DESCRIPTOR, and usb_get_descriptor().

Referenced by usb_config_descriptor().

◆ usb_set_configuration()

static int usb_set_configuration ( struct usb_device usb,
unsigned int  index 
)
inlinestatic

Set USB configuration.

Parameters
usbUSB device
indexConfiguration index
Return values
rcReturn status code

Definition at line 1241 of file usb.h.

1241  {
1242 
1243  return usb_control ( usb, USB_SET_CONFIGURATION, index, 0, NULL, 0 );
1244 }
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.
Definition: usb.c:783
long index
Definition: bigint.h:62
#define USB_SET_CONFIGURATION
Set configuration.
Definition: usb.h:145
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References index, NULL, usb_control(), and USB_SET_CONFIGURATION.

Referenced by axge_open(), usb_autoconfigure(), and usb_deconfigure().

◆ usb_set_interface()

static int usb_set_interface ( struct usb_device usb,
unsigned int  interface,
unsigned int  alternate 
)
inlinestatic

Set USB interface alternate setting.

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

Definition at line 1255 of file usb.h.

1256  {
1257 
1259  NULL, 0 );
1260 }
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.
Definition: usb.c:783
An object interface.
Definition: interface.h:124
struct ib_cm_path alternate
Alternate path.
Definition: ib_mad.h:42
#define USB_SET_INTERFACE
Set interface.
Definition: usb.h:152
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References alternate, NULL, usb_control(), and USB_SET_INTERFACE.

Referenced by usbnet_close(), and usbnet_open().

◆ usb_depth()

static unsigned int usb_depth ( struct usb_device usb)
inlinestatic

Get USB depth.

Parameters
usbUSB device
Return values
depthHub depth

Definition at line 1268 of file usb.h.

1268  {
1269  struct usb_device *parent;
1270  unsigned int depth;
1271 
1272  /* Navigate up to root hub, constructing depth as we go */
1273  for ( depth = 0 ; ( parent = usb->port->hub->usb ) ; usb = parent )
1274  depth++;
1275 
1276  return depth;
1277 }
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:846
struct usb_port * port
USB port.
Definition: usb.h:726
A USB device.
Definition: usb.h:722
struct usb_hub * hub
USB hub.
Definition: usb.h:814

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

Referenced by efi_usb_path(), and hub_probe().

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

144  {
146 
147  /* Find a matching interface descriptor */
148  for_each_config_descriptor ( desc, config ) {
149  if ( ( desc->header.type == USB_INTERFACE_DESCRIPTOR ) &&
150  ( desc->interface == interface ) &&
151  ( desc->alternate == alternate ) )
152  return desc;
153  }
154  return NULL;
155 }
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
Standard Interface Descriptor USB 2.0 spec, Section 9.6.5.
Definition: Usb.h:157
#define for_each_config_descriptor(desc, config)
Iterate over all configuration descriptors.
Definition: usb.h:385
A USB interface descriptor.
Definition: usb.h:244
An object interface.
Definition: interface.h:124
struct ib_cm_path alternate
Alternate path.
Definition: ib_mad.h:42
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

169  {
171  unsigned int attributes = ( type & USB_ENDPOINT_ATTR_TYPE_MASK );
172  unsigned int direction = ( type & USB_DIR_IN );
173 
174  /* Find a matching endpoint descriptor */
176  if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) &&
177  ( ( desc->attributes &
179  ( ( desc->endpoint & USB_DIR_IN ) == direction ) &&
180  ( index-- == 0 ) )
181  return desc;
182  }
183  return NULL;
184 }
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition: usb.h:280
uint32_t type
Operating system type.
Definition: ena.h:12
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
long index
Definition: bigint.h:62
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:393
uint8_t direction
Direction.
Definition: ena.h:14
An object interface.
Definition: interface.h:124
#define USB_DIR_IN
Data transfer is from device to host.
Definition: usb.h:97
uint8_t attributes
Attributes.
Definition: usb.h:269
Standard Endpoint Descriptor USB 2.0 spec, Section 9.6.6.
Definition: Usb.h:173
A USB endpoint descriptor.
Definition: usb.h:263
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

195  {
196  struct usb_endpoint_companion_descriptor *descx;
197 
198  /* Get companion descriptor, if present */
199  descx = container_of ( usb_next_descriptor ( &desc->header ),
201  header );
202  return ( ( usb_is_within_config ( config, &descx->header ) &&
204  ? descx : NULL );
205 }
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:315
static struct usb_descriptor_header * usb_next_descriptor(struct usb_descriptor_header *desc)
Get next USB descriptor.
Definition: usb.h:357
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define USB_ENDPOINT_COMPANION_DESCRIPTOR
A USB endpoint companion descriptor.
Definition: usb.h:325
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
uint8_t type
Descriptor type.
Definition: usb.h:176
A USB endpoint companion descriptor.
Definition: usb.h:313
struct ena_aq_header header
Header.
Definition: ena.h:12
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:370
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

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

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

Referenced by usb_find_next(), and usb_settings_fetch().

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

1938  {
1939  struct usb_hub *hub;
1940  struct usb_port *port;
1941  unsigned int i;
1942 
1943  /* Allocate and initialise structure */
1944  hub = zalloc ( sizeof ( *hub ) + ( ports * sizeof ( hub->port[0] ) ) );
1945  if ( ! hub )
1946  return NULL;
1947  hub->name = ( usb ? usb->name : bus->name );
1948  hub->bus = bus;
1949  hub->usb = usb;
1950  if ( usb )
1951  hub->protocol = usb->port->protocol;
1952  hub->ports = ports;
1953  hub->driver = driver;
1954  hub->host = &bus->op->hub;
1955 
1956  /* Initialise port list */
1957  for ( i = 1 ; i <= hub->ports ; i++ ) {
1958  port = usb_port ( hub, i );
1959  port->hub = hub;
1960  port->address = i;
1961  if ( usb )
1962  port->protocol = usb->port->protocol;
1963  INIT_LIST_HEAD ( &port->changed );
1964  }
1965 
1966  return hub;
1967 }
A USB hub.
Definition: usb.h:840
struct usb_hub_host_operations * host
Host controller operations.
Definition: usb.h:856
struct usb_device * usb
Currently attached device (if in use)
Definition: usb.h:834
unsigned int protocol
Port protocol.
Definition: usb.h:818
A USB port.
Definition: usb.h:812
struct usb_device * usb
Underlying USB device, if any.
Definition: usb.h:846
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:726
struct usb_hub_driver_operations * driver
Driver operations.
Definition: usb.h:858
char name[32]
Name.
Definition: usb.h:724
unsigned int ports
Number of ports.
Definition: usb.h:850
const char * name
Name.
Definition: usb.h:842
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct usb_hub * hub
USB hub.
Definition: usb.h:814
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:959
unsigned int protocol
Hub protocol.
Definition: usb.h:848
struct usb_bus * bus
USB bus.
Definition: usb.h:844
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t bus
Bus.
Definition: edd.h:14
struct usb_port port[0]
Port list.
Definition: usb.h:866

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

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

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

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

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

2062  {
2063  struct usb_port *port;
2064  unsigned int i;
2065 
2066  /* Sanity checks */
2067  for ( i = 1 ; i <= hub->ports ; i++ ) {
2068  port = usb_port ( hub, i );
2069  assert ( ! port->attached );
2070  assert ( port->usb == NULL );
2071  assert ( list_empty ( &port->changed ) );
2072  }
2073 
2074  /* Free hub */
2075  free ( hub );
2076 }
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
A USB port.
Definition: usb.h:812
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:850
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct usb_hub * hub
USB hub.
Definition: usb.h:814
static struct usb_port * usb_port(struct usb_hub *hub, unsigned int address)
Get USB port.
Definition: usb.h:959
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

◆ usb_port_changed()

void usb_port_changed ( struct usb_port port)

Report port status change.

Parameters
portUSB port

Definition at line 1857 of file usb.c.

1857  {
1858 
1859  /* Record hub port status change */
1860  list_del ( &port->changed );
1861  list_add_tail ( &port->changed, &usb_changed );
1862 }
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
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:93
static struct list_head usb_changed
List of changed ports.
Definition: usb.c:47

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

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

2095  {
2096  struct usb_bus *bus;
2097 
2098  /* Allocate and initialise structure */
2099  bus = zalloc ( sizeof ( *bus ) );
2100  if ( ! bus )
2101  goto err_alloc_bus;
2102  bus->name = dev->name;
2103  bus->dev = dev;
2104  bus->mtu = mtu;
2105  bus->op = op;
2106  INIT_LIST_HEAD ( &bus->devices );
2107  INIT_LIST_HEAD ( &bus->hubs );
2108  bus->host = &bus->op->bus;
2109 
2110  /* Allocate root hub */
2111  bus->hub = alloc_usb_hub ( bus, NULL, ports, &op->root );
2112  if ( ! bus->hub )
2113  goto err_alloc_hub;
2114 
2115  return bus;
2116 
2117  free_usb_hub ( bus->hub );
2118  err_alloc_hub:
2119  free ( bus );
2120  err_alloc_bus:
2121  return NULL;
2122 }
char name[40]
Name.
Definition: device.h:75
struct device * dev
Underlying hardware device.
Definition: usb.h:969
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
void free_usb_hub(struct usb_hub *hub)
Free USB hub.
Definition: usb.c:2062
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:45
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A USB bus.
Definition: usb.h:965
uint8_t bus
Bus.
Definition: edd.h:14
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:1936

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

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

2130  {
2131  int rc;
2132 
2133  /* Sanity checks */
2134  assert ( bus->hub != NULL );
2135 
2136  /* Assign the first available bus address */
2137  bus->address = 0;
2138  while ( find_usb_bus ( bus->address ) != NULL )
2139  bus->address++;
2140 
2141  /* Open bus */
2142  if ( ( rc = bus->host->open ( bus ) ) != 0 )
2143  goto err_open;
2144 
2145  /* Add to list of USB buses */
2146  list_add_tail ( &bus->list, &usb_buses );
2147 
2148  /* Register root hub */
2149  if ( ( rc = register_usb_hub ( bus->hub ) ) != 0 )
2150  goto err_register_hub;
2151 
2152  /* Attach any devices already present */
2153  usb_hotplug();
2154 
2155  return 0;
2156 
2157  unregister_usb_hub ( bus->hub );
2158  err_register_hub:
2159  list_del ( &bus->list );
2160  bus->host->close ( bus );
2161  err_open:
2162  return rc;
2163 }
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:1868
struct usb_bus * find_usb_bus(unsigned int address)
Find USB bus by address.
Definition: usb.c:2219
void unregister_usb_hub(struct usb_hub *hub)
Unregister USB hub.
Definition: usb.c:2029
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
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:93
struct list_head usb_buses
List of USB buses.
Definition: usb.c:44
int register_usb_hub(struct usb_hub *hub)
Register USB hub.
Definition: usb.c:1975
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t bus
Bus.
Definition: edd.h:14

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

◆ unregister_usb_bus()

void unregister_usb_bus ( struct usb_bus bus)

Unregister USB bus.

Parameters
busUSB bus

Definition at line 2170 of file usb.c.

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

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

◆ free_usb_bus()

void free_usb_bus ( struct usb_bus bus)

Free USB bus.

Parameters
busUSB bus

Definition at line 2194 of file usb.c.

2194  {
2195  struct usb_endpoint *ep;
2196  struct usb_port *port;
2197 
2198  /* Sanity checks */
2199  assert ( list_empty ( &bus->devices ) );
2200  assert ( list_empty ( &bus->hubs ) );
2201  list_for_each_entry ( ep, &usb_halted, halted )
2202  assert ( ep->usb->port->hub->bus != bus );
2204  assert ( port->hub->bus != bus );
2205 
2206  /* Free root hub */
2207  free_usb_hub ( bus->hub );
2208 
2209  /* Free bus */
2210  free ( bus );
2211 }
struct list_head changed
List of changed ports.
Definition: usb.h:836
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
A USB port.
Definition: usb.h:812
A USB endpoint.
Definition: usb.h:403
u8 port
Port number.
Definition: CIB_PRM.h:31
struct usb_port * port
USB port.
Definition: usb.h:726
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:431
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void free_usb_hub(struct usb_hub *hub)
Free USB hub.
Definition: usb.c:2062
static struct list_head usb_halted
List of halted endpoints.
Definition: usb.c:50
struct usb_hub * hub
USB hub.
Definition: usb.h:814
struct usb_device * usb
USB device.
Definition: usb.h:405
static struct list_head usb_changed
List of changed ports.
Definition: usb.c:47
struct usb_bus * bus
USB bus.
Definition: usb.h:844
uint8_t bus
Bus.
Definition: edd.h:14

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

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

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

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

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

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

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

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

2283  {
2284 
2285  /* Sanity check */
2286  assert ( address > 0 );
2287  assert ( bus->addresses & ( 1ULL << ( address - 1 ) ) );
2288 
2289  /* Mark address as free */
2290  bus->addresses &= ~( 1ULL << ( address - 1 ) );
2291 }
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:14

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

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

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

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

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

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

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

Referenced by xhci_device_address().

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

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

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

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

1167  {
1168  struct usb_driver *driver;
1169  unsigned int i;
1170 
1171  /* Look for a matching driver */
1172  for_each_table_entry ( driver, USB_DRIVERS ) {
1173  for ( i = 0 ; i < driver->id_count ; i++ ) {
1174 
1175  /* Ignore non-matching driver class */
1176  if ( ( driver->class.class.scalar ^ desc->class.scalar )
1177  & driver->class.mask.scalar )
1178  continue;
1179 
1180  /* Look for a matching ID */
1181  *id = &driver->ids[i];
1182  if ( ( ( (*id)->vendor == desc->vendor ) ||
1183  ( (*id)->vendor == USB_ANY_ID ) ) &&
1184  ( ( (*id)->product == desc->product ) ||
1185  ( (*id)->product == USB_ANY_ID ) ) )
1186  return driver;
1187  }
1188  }
1189 
1190  /* Not found */
1191  *id = NULL;
1192  return NULL;
1193 }
A USB driver.
Definition: usb.h:1406
union usb_class_descriptor mask
Class mask.
Definition: usb.h:1379
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
union usb_class_descriptor class
Class.
Definition: usb.h:1377
struct usb_class_id class
Class ID.
Definition: usb.h:1412
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
uint32_t scalar
Scalar value.
Definition: usb.h:647
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1372
unsigned int id_count
Number of entries in ID table.
Definition: usb.h:1410
#define USB_DRIVERS
USB driver table.
Definition: usb.h:1437
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct usb_device_id * ids
USB ID table.
Definition: usb.h:1408

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

Variable Documentation

◆ usb_buses

struct list_head usb_buses

List of USB buses.

Definition at line 44 of file usb.c.

Referenced by register_usb_bus().