Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
hub.c File Reference
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/completion.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/ioctl.h>
#include <linux/usb.h>
#include <linux/usbdevice_fs.h>
#include <linux/usb/hcd.h>
#include <linux/usb/otg.h>
#include <linux/usb/quirks.h>
#include <linux/kthread.h>
#include <linux/mutex.h>
#include <linux/freezer.h>
#include <linux/random.h>
#include <asm/uaccess.h>
#include <asm/byteorder.h>
#include "usb.h"

Go to the source code of this file.

Data Structures

struct  usb_port
 
struct  usb_hub
 

Macros

#define HUB_DEBOUNCE_TIMEOUT   1500
 
#define HUB_DEBOUNCE_STEP   25
 
#define HUB_DEBOUNCE_STABLE   100
 
#define to_usb_port(_dev)   container_of(_dev, struct usb_port, dev)
 
#define LED_CYCLE_PERIOD   ((2*HZ)/3)
 
#define USB_STS_TIMEOUT   1000
 
#define USB_STS_RETRIES   5
 
#define PORT_RESET_TRIES   5
 
#define SET_ADDRESS_TRIES   2
 
#define GET_DESCRIPTOR_TRIES   2
 
#define SET_CONFIG_TRIES   (2 * (use_both_schemes + 1))
 
#define USE_NEW_SCHEME(i)   ((i) / 2 == (int)old_scheme_first)
 
#define HUB_ROOT_RESET_TIME   50 /* times are in msec */
 
#define HUB_SHORT_RESET_TIME   10
 
#define HUB_BH_RESET_TIME   50
 
#define HUB_LONG_RESET_TIME   200
 
#define HUB_RESET_TIMEOUT   500
 
#define hub_suspend   NULL
 
#define hub_resume   NULL
 
#define hub_reset_resume   NULL
 
#define usb_sndaddr0pipe()   (PIPE_CONTROL << 30)
 
#define usb_rcvaddr0pipe()   ((PIPE_CONTROL << 30) | USB_DIR_IN)
 
#define GET_DESCRIPTOR_BUFSIZE   64
 

Enumerations

enum  hub_activation_type {
  HUB_INIT, HUB_INIT2, HUB_INIT3, HUB_POST_RESET,
  HUB_RESUME, HUB_RESET_RESUME
}
 
enum  hub_quiescing_type { HUB_DISCONNECT, HUB_PRE_RESET, HUB_SUSPEND }
 

Functions

 module_param (blinkenlights, bool, S_IRUGO)
 
 MODULE_PARM_DESC (blinkenlights,"true to cycle leds on hubs")
 
 module_param (initial_descriptor_timeout, int, S_IRUGO|S_IWUSR)
 
 MODULE_PARM_DESC (initial_descriptor_timeout,"initial 64-byte descriptor request timeout in milliseconds ""(default 5000 - 5.0 seconds)")
 
 module_param (old_scheme_first, bool, S_IRUGO|S_IWUSR)
 
 MODULE_PARM_DESC (old_scheme_first,"start with the old device initialization scheme")
 
 module_param (use_both_schemes, bool, S_IRUGO|S_IWUSR)
 
 MODULE_PARM_DESC (use_both_schemes,"try the other device initialization scheme if the ""first one fails")
 
 DECLARE_RWSEM (ehci_cf_port_reset_rwsem)
 
 EXPORT_SYMBOL_GPL (ehci_cf_port_reset_rwsem)
 
void usb_kick_khubd (struct usb_device *hdev)
 
void usb_wakeup_notification (struct usb_device *hdev, unsigned int portnum)
 
 EXPORT_SYMBOL_GPL (usb_wakeup_notification)
 
int usb_hub_clear_tt_buffer (struct urb *urb)
 
 EXPORT_SYMBOL_GPL (usb_hub_clear_tt_buffer)
 
int usb_remove_device (struct usb_device *udev)
 
int usb_hub_claim_port (struct usb_device *hdev, unsigned port1, struct dev_state *owner)
 
int usb_hub_release_port (struct usb_device *hdev, unsigned port1, struct dev_state *owner)
 
void usb_hub_release_all_ports (struct usb_device *hdev, struct dev_state *owner)
 
bool usb_device_is_owned (struct usb_device *udev)
 
void usb_set_device_state (struct usb_device *udev, enum usb_device_state new_state)
 
 EXPORT_SYMBOL_GPL (usb_set_device_state)
 
void usb_disconnect (struct usb_device **pdev)
 
int usb_new_device (struct usb_device *udev)
 
int usb_deauthorize_device (struct usb_device *usb_dev)
 
int usb_authorize_device (struct usb_device *usb_dev)
 
int usb_disable_lpm (struct usb_device *udev)
 
 EXPORT_SYMBOL_GPL (usb_disable_lpm)
 
void usb_enable_lpm (struct usb_device *udev)
 
 EXPORT_SYMBOL_GPL (usb_enable_lpm)
 
int usb_unlocked_disable_lpm (struct usb_device *udev)
 
 EXPORT_SYMBOL_GPL (usb_unlocked_disable_lpm)
 
void usb_unlocked_enable_lpm (struct usb_device *udev)
 
 EXPORT_SYMBOL_GPL (usb_unlocked_enable_lpm)
 
int usb_disable_ltm (struct usb_device *udev)
 
 EXPORT_SYMBOL_GPL (usb_disable_ltm)
 
void usb_enable_ltm (struct usb_device *udev)
 
 EXPORT_SYMBOL_GPL (usb_enable_ltm)
 
void usb_ep0_reinit (struct usb_device *udev)
 
 EXPORT_SYMBOL_GPL (usb_ep0_reinit)
 
 MODULE_DEVICE_TABLE (usb, hub_id_table)
 
int usb_hub_init (void)
 
void usb_hub_cleanup (void)
 
int usb_reset_device (struct usb_device *udev)
 
 EXPORT_SYMBOL_GPL (usb_reset_device)
 
void usb_queue_reset_device (struct usb_interface *iface)
 
 EXPORT_SYMBOL_GPL (usb_queue_reset_device)
 
struct usb_device * usb_hub_find_child (struct usb_device *hdev, int port1)
 
 EXPORT_SYMBOL_GPL (usb_hub_find_child)
 
void usb_set_hub_port_connect_type (struct usb_device *hdev, int port1, enum usb_port_connect_type type)
 
enum usb_port_connect_type usb_get_hub_port_connect_type (struct usb_device *hdev, int port1)
 

Variables

struct device_type usb_port_device_type
 

Macro Definition Documentation

#define GET_DESCRIPTOR_BUFSIZE   64
#define GET_DESCRIPTOR_TRIES   2

Definition at line 2396 of file hub.c.

#define HUB_BH_RESET_TIME   50

Definition at line 2402 of file hub.c.

#define HUB_DEBOUNCE_STABLE   100

Definition at line 164 of file hub.c.

#define HUB_DEBOUNCE_STEP   25

Definition at line 163 of file hub.c.

#define HUB_DEBOUNCE_TIMEOUT   1500

Definition at line 162 of file hub.c.

#define HUB_LONG_RESET_TIME   200

Definition at line 2403 of file hub.c.

#define hub_reset_resume   NULL

Definition at line 3616 of file hub.c.

#define HUB_RESET_TIMEOUT   500

Definition at line 2404 of file hub.c.

#define hub_resume   NULL

Definition at line 3615 of file hub.c.

#define HUB_ROOT_RESET_TIME   50 /* times are in msec */

Definition at line 2400 of file hub.c.

#define HUB_SHORT_RESET_TIME   10

Definition at line 2401 of file hub.c.

#define hub_suspend   NULL

Definition at line 3614 of file hub.c.

#define LED_CYCLE_PERIOD   ((2*HZ)/3)

Definition at line 493 of file hub.c.

#define PORT_RESET_TRIES   5

Definition at line 2394 of file hub.c.

#define SET_ADDRESS_TRIES   2

Definition at line 2395 of file hub.c.

#define SET_CONFIG_TRIES   (2 * (use_both_schemes + 1))

Definition at line 2397 of file hub.c.

#define to_usb_port (   _dev)    container_of(_dev, struct usb_port, dev)

Definition at line 166 of file hub.c.

#define usb_rcvaddr0pipe ( )    ((PIPE_CONTROL << 30) | USB_DIR_IN)

Definition at line 3712 of file hub.c.

#define usb_sndaddr0pipe ( )    (PIPE_CONTROL << 30)

Definition at line 3711 of file hub.c.

#define USB_STS_RETRIES   5

Definition at line 567 of file hub.c.

#define USB_STS_TIMEOUT   1000

Definition at line 566 of file hub.c.

#define USE_NEW_SCHEME (   i)    ((i) / 2 == (int)old_scheme_first)

Definition at line 2398 of file hub.c.

Enumeration Type Documentation

Enumerator:
HUB_INIT 
HUB_INIT2 
HUB_INIT3 
HUB_POST_RESET 
HUB_RESUME 
HUB_RESET_RESUME 

Definition at line 945 of file hub.c.

Enumerator:
HUB_DISCONNECT 
HUB_PRE_RESET 
HUB_SUSPEND 

Definition at line 1189 of file hub.c.

Function Documentation

DECLARE_RWSEM ( ehci_cf_port_reset_rwsem  )
EXPORT_SYMBOL_GPL ( ehci_cf_port_reset_rwsem  )
EXPORT_SYMBOL_GPL ( usb_wakeup_notification  )
EXPORT_SYMBOL_GPL ( usb_hub_clear_tt_buffer  )
EXPORT_SYMBOL_GPL ( usb_set_device_state  )
EXPORT_SYMBOL_GPL ( usb_disable_lpm  )
EXPORT_SYMBOL_GPL ( usb_enable_lpm  )
EXPORT_SYMBOL_GPL ( usb_unlocked_disable_lpm  )
EXPORT_SYMBOL_GPL ( usb_unlocked_enable_lpm  )
EXPORT_SYMBOL_GPL ( usb_disable_ltm  )
EXPORT_SYMBOL_GPL ( usb_enable_ltm  )
EXPORT_SYMBOL_GPL ( usb_ep0_reinit  )
EXPORT_SYMBOL_GPL ( usb_reset_device  )
EXPORT_SYMBOL_GPL ( usb_queue_reset_device  )
EXPORT_SYMBOL_GPL ( usb_hub_find_child  )
MODULE_DEVICE_TABLE ( usb  ,
hub_id_table   
)
module_param ( blinkenlights  ,
bool  ,
S_IRUGO   
)
module_param ( initial_descriptor_timeout  ,
int  ,
S_IRUGO S_IWUSR 
)
module_param ( old_scheme_first  ,
bool  ,
S_IRUGO S_IWUSR 
)
module_param ( use_both_schemes  ,
bool  ,
S_IRUGO S_IWUSR 
)
MODULE_PARM_DESC ( blinkenlights  ,
"true to cycle leds on hubs"   
)
MODULE_PARM_DESC ( initial_descriptor_timeout  ,
"initial 64-byte descriptor request timeout in milliseconds ""(default 5000 - 5.0 seconds)"   
)
MODULE_PARM_DESC ( old_scheme_first  ,
"start with the old device initialization scheme"   
)
MODULE_PARM_DESC ( use_both_schemes  ,
"try the other device initialization scheme if the ""first one fails"   
)
int usb_authorize_device ( struct usb_device *  usb_dev)

Definition at line 2326 of file hub.c.

int usb_deauthorize_device ( struct usb_device *  usb_dev)

usb_deauthorize_device - deauthorize a device (usbcore-internal) : USB device

Move the USB device to a very basic state where interfaces are disabled and the device is in fact unconfigured and unusable.

We share a lock (that we have) with device_del(), so we need to defer its call.

Definition at line 2301 of file hub.c.

bool usb_device_is_owned ( struct usb_device *  udev)

Definition at line 1778 of file hub.c.

int usb_disable_lpm ( struct usb_device *  udev)

Definition at line 3618 of file hub.c.

int usb_disable_ltm ( struct usb_device *  udev)

Definition at line 3636 of file hub.c.

void usb_disconnect ( struct usb_device **  pdev)

usb_disconnect - disconnect a device (usbcore-internal) : pointer to device being disconnected Context: !in_interrupt ()

Something got disconnected. Get rid of it and all of its children.

If *pdev is a normal device then the parent hub must already be locked. If *pdev is a root hub then this routine will acquire the usb_bus_list_lock on behalf of the caller.

Only hub drivers (including virtual root hub drivers for host controllers) should ever call this.

This call is synchronous, and may not be used in an interrupt context.

Definition at line 1956 of file hub.c.

void usb_enable_lpm ( struct usb_device *  udev)

Definition at line 3624 of file hub.c.

void usb_enable_ltm ( struct usb_device *  udev)

Definition at line 3642 of file hub.c.

void usb_ep0_reinit ( struct usb_device *  udev)

Definition at line 3703 of file hub.c.

enum usb_port_connect_type usb_get_hub_port_connect_type ( struct usb_device *  hdev,
int  port1 
)

usb_get_hub_port_connect_type - Get the port's connect type : USB device belonging to the usb hub : port num of the port

Return connect type of the port and if input params are invalid, return USB_PORT_CONNECT_TYPE_UNKNOWN.

Definition at line 5119 of file hub.c.

int usb_hub_claim_port ( struct usb_device *  hdev,
unsigned  port1,
struct dev_state owner 
)

Definition at line 1735 of file hub.c.

void usb_hub_cleanup ( void  )

Definition at line 4693 of file hub.c.

int usb_hub_clear_tt_buffer ( struct urb urb)

usb_hub_clear_tt_buffer - clear control/bulk TT state in high speed hub : an URB associated with the failed or incomplete split transaction

High speed HCDs use this to tell the hub driver that some split control or bulk transaction failed in a way that requires clearing internal state of a transaction translator. This is normally detected (and reported) from interrupt context.

It may not be possible for that hub to handle additional full (or low) speed transactions until that state is fully cleared out.

Definition at line 787 of file hub.c.

struct usb_device* usb_hub_find_child ( struct usb_device *  hdev,
int  port1 
)
read

usb_hub_find_child - Get the pointer of child device attached to the port which is specified by . : USB device belonging to the usb hub : port num to indicate which port the child device is attached to.

USB drivers call this function to get hub's child device pointer.

Return NULL if input param is invalid and child's usb_device pointer if non-NULL.

Definition at line 5085 of file hub.c.

int usb_hub_init ( void  )

Definition at line 4674 of file hub.c.

void usb_hub_release_all_ports ( struct usb_device *  hdev,
struct dev_state owner 
)

Definition at line 1765 of file hub.c.

int usb_hub_release_port ( struct usb_device *  hdev,
unsigned  port1,
struct dev_state owner 
)

Definition at line 1750 of file hub.c.

void usb_kick_khubd ( struct usb_device *  hdev)

Definition at line 641 of file hub.c.

int usb_new_device ( struct usb_device *  udev)

usb_new_device - perform initial device setup (usbcore-internal) : newly addressed device (in ADDRESS state)

This is called with devices which have been detected but not fully enumerated. The device descriptor is available, but not descriptors for any device configuration. The caller must have locked either the parent hub (if udev is a normal device) or else the usb_bus_list_lock (if udev is a root hub). The parent's pointer to udev has already been installed, but udev is not yet visible through sysfs or other filesystem code.

It will return if the device is configured properly or not. Zero if the interface was registered with the driver core; else a negative errno value.

This call is synchronous, and may not be used in an interrupt context.

Only the hub driver or root-hub registrar should ever call this.

Definition at line 2214 of file hub.c.

void usb_queue_reset_device ( struct usb_interface iface)

usb_queue_reset_device - Reset a USB device from an atomic context : USB interface belonging to the device to reset

This function can be used to reset a USB device from an atomic context, where usb_reset_device() won't work (as it blocks).

Doing a reset via this method is functionally equivalent to calling usb_reset_device(), except for the fact that it is delayed to a workqueue. This means that any drivers bound to other interfaces might be unbound, as well as users from usbfs in user space.

Corner cases:

  • Scheduling two resets at the same time from two different drivers attached to two different interfaces of the same device is possible; depending on how the driver attached to each interface handles ->pre_reset(), the second reset might happen or not.
  • If a driver is unbound and it had a pending reset, the reset will be cancelled.
  • This function can be called during .probe() or .disconnect() times. On return from .disconnect(), any pending resets will be cancelled.

There is no no need to lock/unlock the as schedule_work() does its own.

NOTE: We don't do any reference count tracking because it is not needed. The lifecycle of the work_struct is tied to the usb_interface. Before destroying the interface we cancel the work_struct, so the fact that work_struct is queued and or running means the interface (and thus, the device) exist and are referenced.

Definition at line 5066 of file hub.c.

int usb_remove_device ( struct usb_device *  udev)

usb_remove_device - disable a device's port on its parent hub : device to be disabled and removed Context: locked, must be able to sleep.

After 's port has been disabled, khubd is notified and it will see that the device has been disconnected. When the device is physically unplugged and something is plugged in, the events will be received and processed normally.

Definition at line 928 of file hub.c.

int usb_reset_device ( struct usb_device *  udev)

usb_reset_device - warn interface drivers and perform a USB port reset : device to reset (not in SUSPENDED or NOTATTACHED state)

Warns all drivers bound to registered interfaces (using their pre_reset method), performs the port reset, and then lets the drivers know that the reset is over (using their post_reset method).

Return value is the same as for usb_reset_and_verify_device().

The caller must own the device lock. For example, it's safe to use this from a driver probe() routine after downloading new firmware. For calls that might not occur during probe(), drivers should lock the device using usb_lock_device_for_reset().

If an interface is currently being probed or disconnected, we assume its driver knows how to handle resets. For all other interfaces, if the driver doesn't have pre_reset and post_reset methods then we attempt to unbind it and rebind afterward.

Definition at line 4968 of file hub.c.

void usb_set_device_state ( struct usb_device *  udev,
enum usb_device_state  new_state 
)

usb_set_device_state - change a device's current state (usbcore, hcds) : pointer to device whose state should be changed : new state value to be stored

udev->state is not fully protected by the device lock. Although most transitions are made only while holding the lock, the state can can change to USB_STATE_NOTATTACHED at almost any time. This is so that devices can be marked as disconnected as soon as possible, without having to wait for any semaphores to be released. As a result, all changes to any device's state must be protected by the device_state_lock spinlock.

Once a device has been added to the device tree, all changes to its state should be made using this routine. The state should not be set directly.

If udev->state is already USB_STATE_NOTATTACHED then no change is made. Otherwise udev->state is set to new_state, and if new_state is USB_STATE_NOTATTACHED then all of udev's descendants' states are also set to USB_STATE_NOTATTACHED.

Definition at line 1823 of file hub.c.

void usb_set_hub_port_connect_type ( struct usb_device *  hdev,
int  port1,
enum usb_port_connect_type  type 
)

usb_set_hub_port_connect_type - set hub port connect type. : USB device belonging to the usb hub : port num of the port : connect type of the port

Definition at line 5102 of file hub.c.

int usb_unlocked_disable_lpm ( struct usb_device *  udev)

Definition at line 3627 of file hub.c.

void usb_unlocked_enable_lpm ( struct usb_device *  udev)

Definition at line 3633 of file hub.c.

void usb_wakeup_notification ( struct usb_device *  hdev,
unsigned int  portnum 
)

Definition at line 657 of file hub.c.

Variable Documentation

struct device_type usb_port_device_type
Initial value:
= {
.name = "usb_port",
.release = usb_port_device_release,
}

Definition at line 1250 of file hub.c.