FreeBSD kernel usb device Code
usb_hub.c File Reference
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sbuf.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_process.h>
#include <dev/usb/usb_device.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_debug.h>
#include <dev/usb/usb_hub.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/usb_busdma.h>
#include <dev/usb/usb_transfer.h>
#include <dev/usb/usb_dynamic.h>
#include <dev/usb/usb_controller.h>
#include <dev/usb/usb_bus.h>
#include <dev/usb/usb_hub_private.h>
Include dependency graph for usb_hub.c:

Go to the source code of this file.

Macros

#define USB_DEBUG_VAR   uhub_debug
 
#define UHUB_PROTO(sc)   ((sc)->sc_udev->ddesc.bDeviceProtocol)
 
#define UHUB_IS_HIGH_SPEED(sc)   (UHUB_PROTO(sc) != UDPROTO_FSHUB)
 
#define UHUB_IS_SINGLE_TT(sc)   (UHUB_PROTO(sc) == UDPROTO_HSHUBSTT)
 
#define UHUB_IS_MULTI_TT(sc)   (UHUB_PROTO(sc) == UDPROTO_HSHUBMTT)
 
#define UHUB_IS_SUPER_SPEED(sc)   (UHUB_PROTO(sc) == UDPROTO_SSHUB)
 

Functions

static void usb_dev_resume_peer (struct usb_device *udev)
 
static void usb_dev_suspend_peer (struct usb_device *udev)
 
static uint8_t usb_peer_should_wakeup (struct usb_device *udev)
 
 DRIVER_MODULE (uhub, usbus, uhub_driver, uhub_devclass, 0, 0)
 
 DRIVER_MODULE (uhub, uhub, uhub_driver, uhub_devclass, NULL, 0)
 
 MODULE_VERSION (uhub, 1)
 
static void uhub_intr_callback (struct usb_xfer *xfer, usb_error_t error)
 
uint8_t uhub_count_active_host_ports (struct usb_device *udev, enum usb_dev_speed speed)
 
void uhub_explore_handle_re_enumerate (struct usb_device *child)
 
static usb_error_t uhub_explore_sub (struct uhub_softc *sc, struct usb_port *up)
 
static usb_error_t uhub_read_port_status (struct uhub_softc *sc, uint8_t portno)
 
static usb_error_t uhub_reattach_port (struct uhub_softc *sc, uint8_t portno)
 
static uint8_t usb_device_20_compatible (struct usb_device *udev)
 
static usb_error_t uhub_suspend_resume_port (struct uhub_softc *sc, uint8_t portno)
 
void uhub_root_intr (struct usb_bus *bus, const uint8_t *ptr, uint8_t len)
 
static uint8_t uhub_is_too_deep (struct usb_device *udev)
 
static usb_error_t uhub_explore (struct usb_device *udev)
 
int uhub_probe (device_t dev)
 
usb_error_t uhub_query_info (struct usb_device *udev, uint8_t *pnports, uint8_t *ptt)
 
int uhub_attach (device_t dev)
 
int uhub_detach (device_t dev)
 
static int uhub_suspend (device_t dev)
 
static int uhub_resume (device_t dev)
 
static void uhub_driver_added (device_t dev, driver_t *driver)
 
void uhub_find_iface_index (struct usb_hub *hub, device_t child, struct hub_result *res)
 
int uhub_child_location (device_t parent, device_t child, struct sbuf *sb)
 
int uhub_get_device_path (device_t bus, device_t child, const char *locator, struct sbuf *sb)
 
static int uhub_child_pnpinfo (device_t parent, device_t child, struct sbuf *sb)
 
static uint8_t usb_intr_find_best_slot (usb_size_t *ptr, uint8_t start, uint8_t end, uint8_t mask)
 
static uint8_t usb_hs_bandwidth_adjust (struct usb_device *udev, int16_t len, uint8_t slot, uint8_t mask)
 
void usb_hs_bandwidth_alloc (struct usb_xfer *xfer)
 
void usb_hs_bandwidth_free (struct usb_xfer *xfer)
 
uint16_t usb_isoc_time_expand (struct usb_bus *bus, uint16_t isoc_time_curr)
 
struct usb_deviceusb_bus_port_get_device (struct usb_bus *bus, struct usb_port *up)
 
void usb_bus_port_set_device (struct usb_bus *bus, struct usb_port *up, struct usb_device *udev, uint8_t device_index)
 
void usb_needs_explore (struct usb_bus *bus, uint8_t do_probe)
 
void usb_needs_explore_all (void)
 
static void usb_needs_explore_init (void *arg)
 
 SYSINIT (usb_needs_explore_init, SI_SUB_KICK_SCHEDULER, SI_ORDER_SECOND, usb_needs_explore_init, NULL)
 
static usb_error_t usbd_device_30_remote_wakeup (struct usb_device *udev, uint8_t bRequest)
 
static usb_error_t usbd_clear_dev_wakeup (struct usb_device *udev)
 
static usb_error_t usbd_set_dev_wakeup (struct usb_device *udev)
 
void usbd_set_power_mode (struct usb_device *udev, uint8_t power_mode)
 
uint8_t usbd_filter_power_mode (struct usb_device *udev, uint8_t power_mode)
 
void usbd_start_re_enumerate (struct usb_device *udev)
 
usb_error_t usbd_start_set_config (struct usb_device *udev, uint8_t index)
 

Variables

static device_suspend_t uhub_suspend
 
static device_resume_t uhub_resume
 
static bus_driver_added_t uhub_driver_added
 
static bus_child_pnpinfo_t uhub_child_pnpinfo
 
static usb_callback_t uhub_intr_callback
 
static const struct usb_config uhub_config [UHUB_N_TRANSFER]
 
static devclass_t uhub_devclass
 
static device_method_t uhub_methods []
 
driver_t uhub_driver
 

Macro Definition Documentation

◆ UHUB_IS_HIGH_SPEED

#define UHUB_IS_HIGH_SPEED (   sc)    (UHUB_PROTO(sc) != UDPROTO_FSHUB)

Definition at line 110 of file usb_hub.c.

◆ UHUB_IS_MULTI_TT

#define UHUB_IS_MULTI_TT (   sc)    (UHUB_PROTO(sc) == UDPROTO_HSHUBMTT)

Definition at line 112 of file usb_hub.c.

◆ UHUB_IS_SINGLE_TT

#define UHUB_IS_SINGLE_TT (   sc)    (UHUB_PROTO(sc) == UDPROTO_HSHUBSTT)

Definition at line 111 of file usb_hub.c.

◆ UHUB_IS_SUPER_SPEED

#define UHUB_IS_SUPER_SPEED (   sc)    (UHUB_PROTO(sc) == UDPROTO_SSHUB)

Definition at line 113 of file usb_hub.c.

◆ UHUB_PROTO

#define UHUB_PROTO (   sc)    ((sc)->sc_udev->ddesc.bDeviceProtocol)

Definition at line 109 of file usb_hub.c.

◆ USB_DEBUG_VAR

#define USB_DEBUG_VAR   uhub_debug

Definition at line 62 of file usb_hub.c.

Function Documentation

◆ DRIVER_MODULE() [1/2]

DRIVER_MODULE ( uhub  ,
uhub  ,
uhub_driver  ,
uhub_devclass  ,
NULL  ,
 
)

◆ DRIVER_MODULE() [2/2]

DRIVER_MODULE ( uhub  ,
usbus  ,
uhub_driver  ,
uhub_devclass  ,
,
 
)

◆ MODULE_VERSION()

MODULE_VERSION ( uhub  ,
 
)

◆ SYSINIT()

SYSINIT ( usb_needs_explore_init  ,
SI_SUB_KICK_SCHEDULER  ,
SI_ORDER_SECOND  ,
usb_needs_explore_init  ,
NULL   
)

◆ uhub_attach()

◆ uhub_child_location()

int uhub_child_location ( device_t  parent,
device_t  child,
struct sbuf *  sb 
)

◆ uhub_child_pnpinfo()

◆ uhub_count_active_host_ports()

uint8_t uhub_count_active_host_ports ( struct usb_device udev,
enum usb_dev_speed  speed 
)

Definition at line 386 of file usb_hub.c.

References usb_device::bus, child, usb_device::hub, usb_hub::hubsoftc, usb_hub::nports, usb_hub::ports, usb_bus_port_get_device(), and USB_MODE_HOST.

Referenced by usbd_req_re_enumerate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uhub_detach()

◆ uhub_driver_added()

static void uhub_driver_added ( device_t  dev,
driver_t *  driver 
)
static

Definition at line 1599 of file usb_hub.c.

References usb_needs_explore_all().

Here is the call graph for this function:

◆ uhub_explore()

◆ uhub_explore_handle_re_enumerate()

◆ uhub_explore_sub()

static usb_error_t uhub_explore_sub ( struct uhub_softc sc,
struct usb_port up 
)
static

◆ uhub_find_iface_index()

void uhub_find_iface_index ( struct usb_hub hub,
device_t  child,
struct hub_result res 
)

◆ uhub_get_device_path()

int uhub_get_device_path ( device_t  bus,
device_t  child,
const char *  locator,
struct sbuf *  sb 
)

Definition at line 1676 of file usb_hub.c.

References bus, child, usb_device::hub, hub_result::iface_index, hub_result::portno, uhub_softc::sc_udev, hub_result::udev, and uhub_find_iface_index().

Here is the call graph for this function:

◆ uhub_intr_callback()

static void uhub_intr_callback ( struct usb_xfer xfer,
usb_error_t  error 
)
static

◆ uhub_is_too_deep()

static uint8_t uhub_is_too_deep ( struct usb_device udev)
static

Definition at line 968 of file usb_hub.c.

References usb_device::depth, usb_device::speed, USB_HUB_MAX_DEPTH, USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_LOW, USB_SPEED_SUPER, and USB_SS_HUB_DEPTH_MAX.

Referenced by uhub_attach(), and uhub_explore().

Here is the caller graph for this function:

◆ uhub_probe()

◆ uhub_query_info()

◆ uhub_read_port_status()

static usb_error_t uhub_read_port_status ( struct uhub_softc sc,
uint8_t  portno 
)
static

◆ uhub_reattach_port()

◆ uhub_resume()

static int uhub_resume ( device_t  dev)
static

Definition at line 1591 of file usb_hub.c.

References DPRINTF.

◆ uhub_root_intr()

void uhub_root_intr ( struct usb_bus bus,
const uint8_t *  ptr,
uint8_t  len 
)

Definition at line 960 of file usb_hub.c.

References usb_device::bus, USB_BUS_LOCK_ASSERT, and usb_needs_explore().

Referenced by atmegadci_root_intr(), avr32dci_root_intr(), dwc_otg_root_intr(), ehci_root_intr(), musbotg_root_intr(), ohci_root_intr(), uhci_root_intr(), uss820dci_root_intr(), and xhci_root_intr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uhub_suspend()

static int uhub_suspend ( device_t  dev)
static

Definition at line 1583 of file usb_hub.c.

References DPRINTF.

◆ uhub_suspend_resume_port()

◆ usb_bus_port_get_device()

struct usb_device * usb_bus_port_get_device ( struct usb_bus bus,
struct usb_port up 
)

◆ usb_bus_port_set_device()

void usb_bus_port_set_device ( struct usb_bus bus,
struct usb_port up,
struct usb_device udev,
uint8_t  device_index 
)

Definition at line 2212 of file usb_hub.c.

References usb_device::bus, usb_device::device_index, usb_port::device_index, usb_bus::devices, and usb_ref_lock.

Referenced by usb_alloc_device(), and usb_free_device().

Here is the caller graph for this function:

◆ usb_dev_resume_peer()

◆ usb_dev_suspend_peer()

◆ usb_device_20_compatible()

static uint8_t usb_device_20_compatible ( struct usb_device udev)
static

Definition at line 854 of file usb_hub.c.

References usb_device::speed, USB_SPEED_FULL, USB_SPEED_HIGH, and USB_SPEED_LOW.

Referenced by uhub_suspend_resume_port(), usb_dev_resume_peer(), usb_dev_suspend_peer(), usbd_clear_dev_wakeup(), and usbd_set_dev_wakeup().

Here is the caller graph for this function:

◆ usb_hs_bandwidth_adjust()

static uint8_t usb_hs_bandwidth_adjust ( struct usb_device udev,
int16_t  len,
uint8_t  slot,
uint8_t  mask 
)
static

◆ usb_hs_bandwidth_alloc()

◆ usb_hs_bandwidth_free()

◆ usb_intr_find_best_slot()

static uint8_t usb_intr_find_best_slot ( usb_size_t ptr,
uint8_t  start,
uint8_t  end,
uint8_t  mask 
)
static

Definition at line 1802 of file usb_hub.c.

References start.

Referenced by usb_hs_bandwidth_adjust().

Here is the caller graph for this function:

◆ usb_isoc_time_expand()

uint16_t usb_isoc_time_expand ( struct usb_bus bus,
uint16_t  isoc_time_curr 
)

Definition at line 2037 of file usb_hub.c.

References usb_device::bus, usb_bus::isoc_time_last, USB_BUS_LOCK_ASSERT, and USB_ISOC_TIME_MAX.

Referenced by usbd_xfer_get_isochronous_start_frame().

Here is the caller graph for this function:

◆ usb_needs_explore()

void usb_needs_explore ( struct usb_bus bus,
uint8_t  do_probe 
)

◆ usb_needs_explore_all()

void usb_needs_explore_all ( void  )

Definition at line 2300 of file usb_hub.c.

References bus, dev, usb_devclass_ptr, and usb_needs_explore().

Referenced by uhub_driver_added(), and usb_needs_explore_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usb_needs_explore_init()

static void usb_needs_explore_init ( void *  arg)
static

Definition at line 2337 of file usb_hub.c.

References usb_needs_explore_all().

Here is the call graph for this function:

◆ usb_peer_should_wakeup()

◆ usbd_clear_dev_wakeup()

static usb_error_t usbd_clear_dev_wakeup ( struct usb_device udev)
static

Definition at line 2603 of file usb_hub.c.

References UF_DEVICE_REMOTE_WAKEUP, UR_CLEAR_FEATURE, usb_device_20_compatible(), usbd_device_30_remote_wakeup(), and usbd_req_clear_device_feature().

Referenced by usb_dev_resume_peer(), and usb_dev_suspend_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usbd_device_30_remote_wakeup()

static usb_error_t usbd_device_30_remote_wakeup ( struct usb_device udev,
uint8_t  bRequest 
)
static

◆ usbd_filter_power_mode()

uint8_t usbd_filter_power_mode ( struct usb_device udev,
uint8_t  power_mode 
)

Definition at line 2920 of file usb_hub.c.

References usb_device::bus, usb_bus_methods::get_power_mode, and usb_bus::methods.

Referenced by usb_alloc_device(), and usbd_set_power_mode().

Here is the caller graph for this function:

◆ usbd_set_dev_wakeup()

static usb_error_t usbd_set_dev_wakeup ( struct usb_device udev)
static

Definition at line 2618 of file usb_hub.c.

References UF_DEVICE_REMOTE_WAKEUP, UR_SET_FEATURE, usb_device_20_compatible(), usbd_device_30_remote_wakeup(), and usbd_req_set_device_feature().

Referenced by usb_dev_suspend_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usbd_set_power_mode()

void usbd_set_power_mode ( struct usb_device udev,
uint8_t  power_mode 
)

Definition at line 2896 of file usb_hub.c.

References usb_device::bus, usb_device::power_mode, usb_bus_power_update(), usb_needs_explore(), USB_POWER_MODE_OFF, USB_POWER_MODE_ON, USB_POWER_MODE_SAVE, and usbd_filter_power_mode().

Referenced by cfumass_attach(), uhub_attach(), usie_attach(), and ustorage_fs_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usbd_start_re_enumerate()

void usbd_start_re_enumerate ( struct usb_device udev)

Definition at line 2947 of file usb_hub.c.

References usb_device::bus, usb_device::re_enumerate_wait, usb_needs_explore(), USB_RE_ENUM_DONE, and USB_RE_ENUM_START.

Referenced by usb_do_clear_stall_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usbd_start_set_config()

usb_error_t usbd_start_set_config ( struct usb_device udev,
uint8_t  index 
)

Variable Documentation

◆ uhub_child_pnpinfo

bus_child_pnpinfo_t uhub_child_pnpinfo
static

Definition at line 121 of file usb_hub.c.

◆ uhub_config

const struct usb_config uhub_config[UHUB_N_TRANSFER]
static
Initial value:
= {
.type = UE_INTERRUPT,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_ANY,
.timeout = 0,
.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
.bufsize = 0,
.callback = &uhub_intr_callback,
.interval = UHUB_INTR_INTERVAL,
},
}
#define UE_INTERRUPT
Definition: usb.h:544
#define UE_DIR_ANY
Definition: usb.h:535
#define UE_ADDR_ANY
Definition: usb.h:537
static usb_callback_t uhub_intr_callback
Definition: usb_hub.c:123
#define UHUB_INTR_INTERVAL
@ UHUB_INTR_TRANSFER

Definition at line 132 of file usb_hub.c.

Referenced by uhub_attach().

◆ uhub_devclass

devclass_t uhub_devclass
static

Definition at line 160 of file usb_hub.c.

◆ uhub_driver

driver_t uhub_driver
Initial value:
= {
.name = "uhub",
.methods = uhub_methods,
.size = sizeof(struct uhub_softc)
}
static device_method_t uhub_methods[]
Definition: usb_hub.c:162

Definition at line 177 of file usb_hub.c.

◆ uhub_driver_added

bus_driver_added_t uhub_driver_added
static

Definition at line 120 of file usb_hub.c.

◆ uhub_intr_callback

usb_callback_t uhub_intr_callback
static

Definition at line 123 of file usb_hub.c.

◆ uhub_methods

device_method_t uhub_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, uhub_probe),
DEVMETHOD(device_attach, uhub_attach),
DEVMETHOD(device_detach, uhub_detach),
DEVMETHOD(device_suspend, uhub_suspend),
DEVMETHOD(device_resume, uhub_resume),
DEVMETHOD(bus_child_location, uhub_child_location),
DEVMETHOD(bus_child_pnpinfo, uhub_child_pnpinfo),
DEVMETHOD(bus_get_device_path, uhub_get_device_path),
DEVMETHOD(bus_driver_added, uhub_driver_added),
DEVMETHOD_END
}
static bus_child_pnpinfo_t uhub_child_pnpinfo
Definition: usb_hub.c:121
int uhub_get_device_path(device_t bus, device_t child, const char *locator, struct sbuf *sb)
Definition: usb_hub.c:1676
int uhub_attach(device_t dev)
Definition: usb_hub.c:1190
static device_suspend_t uhub_suspend
Definition: usb_hub.c:117
int uhub_child_location(device_t parent, device_t child, struct sbuf *sb)
Definition: usb_hub.c:1638
static device_resume_t uhub_resume
Definition: usb_hub.c:118
int uhub_probe(device_t dev)
Definition: usb_hub.c:1110
static bus_driver_added_t uhub_driver_added
Definition: usb_hub.c:120
int uhub_detach(device_t dev)
Definition: usb_hub.c:1536

Definition at line 162 of file usb_hub.c.

◆ uhub_resume

device_resume_t uhub_resume
static

Definition at line 118 of file usb_hub.c.

◆ uhub_suspend

device_suspend_t uhub_suspend
static

Definition at line 117 of file usb_hub.c.