USB hub driver
[USB]

USB hub driver. More...


Files

file  ports.c
 Hub ports functions.
file  ports.h
 Hub ports related functions.
file  usbhub.c
 usb hub main functionality
file  usbhub.h
 Hub driver.
file  usbhub_private.h
 Hub driver private definitions.
file  utils.c
 various utilities

Data Structures

struct  add_device_phase1
 Information for fibril for device discovery. More...
struct  usb_hub_info_t
 Information about attached hub. More...
struct  usb_hub_port_t
 Information about single port on a hub. More...

Defines

#define NAME   "usbhub"

Typedefs

typedef usb_hub_info_t usb_hub_info_t
typedef uint32_t usb_hub_status_t
 structure holding hub status and changes flags.
typedef uint32_t usb_port_status_t
 structure holding port status and changes flags.

Functions

static int add_device_phase1_worker_fibril (void *arg)
 Fibril for adding a new device.
static int create_add_device_fibril (usb_hub_info_t *hub, size_t port, usb_speed_t speed)
 Start device adding when connection change is detected.
static int enable_port_callback (int port_no, void *arg)
 Callback for enabling a specific port.
static int get_port_status (usb_pipe_t *ctrl_pipe, size_t port, usb_port_status_t *status)
 Retrieve port status.
bool hub_port_changes_callback (usb_device_t *dev, uint8_t *change_bitmap, size_t change_bitmap_size, void *arg)
 Callback for polling hub for changes.
int main (int argc, char *argv[])
 Main entry point.
usb_hub_descriptor_tusb_create_deserialized_hub_desriptor (void *serialized_descriptor)
 create deserialized desriptor structure out of serialized descriptor
void * usb_create_serialized_hub_descriptor (usb_hub_descriptor_t *descriptor)
 create uint8_t array with serialized descriptor
void usb_deserialize_hub_desriptor (void *serialized_descriptor, usb_hub_descriptor_t *descriptor)
 deserialize descriptor into given pointer
int usb_hub_add_device (usb_device_t *usb_dev)
 Initialize hub device driver fibril.
static int usb_hub_clear_feature (usb_pipe_t *pipe, usb_hub_class_feature_t feature)
 Clear feature on hub port.
static int usb_hub_clear_port_feature (usb_pipe_t *pipe, int port_index, usb_hub_class_feature_t feature)
 Clear feature on hub port.
static usb_device_request_setup_packet_tusb_hub_create_disable_port_request (uint16_t port)
 disable specified port
static usb_device_request_setup_packet_tusb_hub_create_enable_port_request (uint16_t port)
 enable specified port
static usb_device_request_setup_packet_tusb_hub_create_port_status_request (uint16_t port)
 create request for usb hub port status
static usb_device_request_setup_packet_tusb_hub_create_reset_port_request (uint16_t port)
 disable specified port
static usb_hub_info_tusb_hub_info_create (usb_device_t *usb_dev)
 create usb_hub_info_t structure
static bool usb_hub_is_status (usb_hub_status_t status, int idx)
 get i`th bit of hub status
static void usb_hub_polling_terminated_callback (usb_device_t *device, bool was_error, void *data)
 callback called from hub polling fibril when the fibril terminates
static void usb_hub_port_init (usb_hub_port_t *port)
 Initialize hub port information.
static void usb_hub_port_over_current (usb_hub_info_t *hub, uint16_t port, uint32_t status)
 Process over current condition on port.
static void usb_hub_port_reset_completed (usb_hub_info_t *hub, uint16_t port, uint32_t status)
 Process port reset change.
static void usb_hub_process_global_interrupt (usb_hub_info_t *hub_info)
 process hub interrupts
static int usb_hub_process_hub_specific_info (usb_hub_info_t *hub_info)
 Load hub-specific information into hub_info structure and process if needed.
void usb_hub_process_port_interrupt (usb_hub_info_t *hub, uint16_t port)
 Process interrupts on given hub port.
static void usb_hub_removed_device (usb_hub_info_t *hub, uint16_t port)
 routine called when a device on port has been removed
static int usb_hub_set_configuration (usb_hub_info_t *hub_info)
 Set configuration of hub.
static void usb_hub_set_descriptor_request (usb_device_request_setup_packet_t *request)
 Set the device request to be a get hub descriptor request.
static void usb_hub_set_disable_port_feature_request (usb_device_request_setup_packet_t *request, uint16_t port, uint16_t feature_selector)
 set the device request to be a port feature clear request
static void usb_hub_set_disable_port_request (usb_device_request_setup_packet_t *request, uint16_t port)
 set the device request to be a port disable request
static void usb_hub_set_enable_port_feature_request (usb_device_request_setup_packet_t *request, uint16_t port, uint16_t feature_selector)
 set the device request to be a port feature enable request
static void usb_hub_set_enable_port_request (usb_device_request_setup_packet_t *request, uint16_t port)
 set the device request to be a port enable request
static int usb_hub_set_feature (usb_pipe_t *pipe, usb_hub_class_feature_t feature)
 Clear feature on hub port.
static void usb_hub_set_hub_status_request (usb_device_request_setup_packet_t *request)
 set values in request to be it a port status request
static int usb_hub_set_port_feature (usb_pipe_t *pipe, int port_index, usb_hub_class_feature_t feature)
 Clear feature on hub port.
static void usb_hub_set_port_status_request (usb_device_request_setup_packet_t *request, uint16_t port)
 set values in request to be it a port status request
static void usb_hub_set_power_port_request (usb_device_request_setup_packet_t *request, uint16_t port)
 set the device request to be a port disable request
static void usb_hub_set_reset_port_request (usb_device_request_setup_packet_t *request, uint16_t port)
 set the device request to be a port disable request
static int usb_hub_start_hub_fibril (usb_hub_info_t *hub_info)
 create and start fibril with hub control loop
static void usb_hub_status_set_bit (usb_hub_status_t *status, int idx, bool value)
 set i`th bit of hub status
static void usb_hub_unset_power_port_request (usb_device_request_setup_packet_t *request, uint16_t port)
 set the device request to be a port disable request
static bool usb_port_high_speed (usb_port_status_t status)
 high speed device on the port indicator
static bool usb_port_is_status (usb_port_status_t status, int idx)
 get i`th bit of port status
static bool usb_port_low_speed (usb_port_status_t status)
 low speed device on the port indicator
static void usb_port_set_high_speed (usb_port_status_t *status, bool high_speed)
 set high speed device bit in port status
static void usb_port_set_low_speed (usb_port_status_t *status, bool low_speed)
 set low speed device connected bit in port status
static usb_speed_t usb_port_speed (usb_port_status_t status)
 speed getter for port status
static void usb_port_status_set_bit (usb_port_status_t *status, int idx, bool value)
 set i`th bit of port status
static int usb_process_hub_local_power_change (usb_hub_info_t *hub_info, usb_hub_status_t status)
 process hub local power change
static int usb_process_hub_over_current (usb_hub_info_t *hub_info, usb_hub_status_t status)
 process hub over current change
void usb_serialize_hub_descriptor (usb_hub_descriptor_t *descriptor, void *serialized_descriptor)
 serialize descriptor into given buffer

Variables

static usb_endpoint_description_t hub_status_change_endpoint_description
 Hub status-change endpoint description.
static const int non_handled_changes []
 port status changes that are not explicitly handled by any function here and must be cleared by hand
static const unsigned int non_handled_changes_count = 2
 count of port status changes that are not explicitly handled by any function here and must be cleared by hand
static usb_driver_t usb_hub_driver
 static usb hub driver information
static usb_driver_ops_t usb_hub_driver_ops
 usb hub driver operations
static usb_endpoint_description_tusb_hub_endpoints []
 hub endpoints, excluding control endpoint
size_t USB_HUB_MAX_DESCRIPTOR_SIZE = 71
 Maximum size of usb hub descriptor in bytes.

Detailed Description

USB hub driver.


Typedef Documentation

typedef uint32_t usb_hub_status_t

structure holding hub status and changes flags.

should not be accessed directly, use supplied getter/setter methods.

For more information refer to table 11.16.2.5 in "Universal Serial Bus Specification Revision 1.1"

Definition at line 58 of file port_status.h.

typedef uint32_t usb_port_status_t

structure holding port status and changes flags.

should not be accessed directly, use supplied getter/setter methods.

For more information refer to table 11-15 in "Universal Serial Bus Specification Revision 1.1"

Definition at line 48 of file port_status.h.


Function Documentation

static int add_device_phase1_worker_fibril ( void *  arg  )  [static]

Fibril for adding a new device.

Separate fibril is needed because the port reset completion is announced via interrupt pipe and thus we cannot block here.

Parameters:
arg Pointer to struct add_device_phase1.
Returns:
0 Always.

Definition at line 373 of file ports.c.

static int create_add_device_fibril ( usb_hub_info_t hub,
size_t  port,
usb_speed_t  speed 
) [static]

Start device adding when connection change is detected.

This fires a new fibril to complete the device addition.

Parameters:
hub Hub where the change occured.
port Port index (starting at 1).
speed Speed of the device.
Returns:
Error code.

Definition at line 424 of file ports.c.

static int enable_port_callback ( int  port_no,
void *  arg 
) [static]

Callback for enabling a specific port.

We wait on a CV until port is reseted. That is announced via change on interrupt pipe.

Parameters:
port_no Port number (starting at 1).
arg Custom argument, points to usb_hub_info_t.
Returns:
Error code.

Definition at line 335 of file ports.c.

static int get_port_status ( usb_pipe_t ctrl_pipe,
size_t  port,
usb_port_status_t status 
) [static]

Retrieve port status.

Parameters:
[in] ctrl_pipe Control pipe to use.
[in] port Port number (starting at 1).
[out] status Where to store the port status.
Returns:
Error code.

Definition at line 301 of file ports.c.

bool hub_port_changes_callback ( usb_device_t dev,
uint8_t *  change_bitmap,
size_t  change_bitmap_size,
void *  arg 
)

Callback for polling hub for changes.

Parameters:
dev Device where the change occured.
change_bitmap Bitmap of changed ports.
change_bitmap_size Size of the bitmap in bytes.
arg Custom argument, points to usb_hub_info_t.
Returns:
Whether to continue polling.

Definition at line 150 of file usbhub.c.

int main ( int  argc,
char *  argv[] 
)

Main entry point.

Parameters:
[in] argc Nmber of arguments in argv vector (ignored).
[in] argv Cmdline argument vector (ignored).
Returns:
Error code.
Driver debug level is set here.

Definition at line 84 of file main.c.

usb_hub_descriptor_t * usb_create_deserialized_hub_desriptor ( void *  serialized_descriptor  ) 

create deserialized desriptor structure out of serialized descriptor

The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur.

Parameters:
sdescriptor serialized descriptor
Returns:
newly created deserialized descriptor pointer

Definition at line 121 of file utils.c.

void * usb_create_serialized_hub_descriptor ( usb_hub_descriptor_t descriptor  ) 

create uint8_t array with serialized descriptor

Parameters:
descriptor 
Returns:
newly created serializd descriptor pointer

Definition at line 64 of file utils.c.

void usb_deserialize_hub_desriptor ( void *  serialized_descriptor,
usb_hub_descriptor_t descriptor 
)

deserialize descriptor into given pointer

Parameters:
serialized_descriptor 
descriptor 
Returns:

handling of endianness??

Definition at line 144 of file utils.c.

int usb_hub_add_device ( usb_device_t usb_dev  ) 

Initialize hub device driver fibril.

Creates hub representation and fibril that periodically checks hub`s status. Hub representation is passed to the fibril.

Parameters:
usb_dev generic usb device information
Returns:
error code

Definition at line 92 of file usbhub.c.

static int usb_hub_clear_feature ( usb_pipe_t pipe,
usb_hub_class_feature_t  feature 
) [inline, static]

Clear feature on hub port.

Parameters:
pipe pipe to hub control endpoint
feature Feature selector
Returns:
Operation result

Definition at line 132 of file usbhub_private.h.

static int usb_hub_clear_port_feature ( usb_pipe_t pipe,
int  port_index,
usb_hub_class_feature_t  feature 
) [inline, static]

Clear feature on hub port.

Parameters:
hc Host controller telephone
address Hub address
port_index Port
feature Feature selector
Returns:
Operation result

Definition at line 86 of file usbhub_private.h.

static usb_device_request_setup_packet_t* usb_hub_create_disable_port_request ( uint16_t  port  )  [inline, static]

disable specified port

Parameters:
port 
Returns:

Definition at line 183 of file port_status.h.

static usb_device_request_setup_packet_t* usb_hub_create_enable_port_request ( uint16_t  port  )  [inline, static]

enable specified port

Parameters:
port 
Returns:

Definition at line 155 of file port_status.h.

static usb_device_request_setup_packet_t* usb_hub_create_port_status_request ( uint16_t  port  )  [inline, static]

create request for usb hub port status

Parameters:
port 
Returns:

Definition at line 94 of file port_status.h.

static usb_device_request_setup_packet_t* usb_hub_create_reset_port_request ( uint16_t  port  )  [inline, static]

disable specified port

Parameters:
port 
Returns:

Definition at line 211 of file port_status.h.

static usb_hub_info_t * usb_hub_info_create ( usb_device_t usb_dev  )  [static]

create usb_hub_info_t structure

Does only basic copying of known information into new structure.

Parameters:
usb_dev usb device structure
Returns:
basic usb_hub_info_t structure

Definition at line 194 of file usbhub.c.

static bool usb_hub_is_status ( usb_hub_status_t  status,
int  idx 
) [inline, static]

get i`th bit of hub status

Parameters:
status 
idx 
Returns:

Definition at line 280 of file port_status.h.

static void usb_hub_polling_terminated_callback ( usb_device_t device,
bool  was_error,
void *  data 
) [static]

callback called from hub polling fibril when the fibril terminates

Should perform a cleanup - deletes hub_info.

Parameters:
device usb device afected
was_error indicates that the fibril is stoped due to an error
data pointer to usb_hub_info_t structure

Definition at line 476 of file usbhub.c.

static void usb_hub_port_init ( usb_hub_port_t port  )  [inline, static]

Initialize hub port information.

Parameters:
port Port to be initialized.

Definition at line 64 of file ports.h.

static void usb_hub_port_over_current ( usb_hub_info_t hub,
uint16_t  port,
uint32_t  status 
) [static]

Process over current condition on port.

Turn off the power on the port.

Parameters:
hub hub representation
port port number, starting from 1

Definition at line 274 of file ports.c.

static void usb_hub_port_reset_completed ( usb_hub_info_t hub,
uint16_t  port,
uint32_t  status 
) [static]

Process port reset change.

After this change port should be enabled, unless some problem occured. This functions triggers second phase of enabling new device.

Parameters:
hub 
port 
status 

Definition at line 241 of file ports.c.

static void usb_hub_process_global_interrupt ( usb_hub_info_t hub_info  )  [static]

process hub interrupts

The change can be either in the over-current condition or local-power change.

Parameters:
hub_info hub instance

Definition at line 431 of file usbhub.c.

static int usb_hub_process_hub_specific_info ( usb_hub_info_t hub_info  )  [static]

Load hub-specific information into hub_info structure and process if needed.

Particularly read port count and initialize structure holding port information. If there are non-removable devices, start initializing them. This function is hub-specific and should be run only after the hub is configured using usb_hub_set_configuration function.

Parameters:
hub_info hub representation
Returns:
error code

Definition at line 222 of file usbhub.c.

void usb_hub_process_port_interrupt ( usb_hub_info_t hub,
uint16_t  port 
)

Process interrupts on given hub port.

Accepts connection, over current and port reset change.

Parameters:
hub hub representation
port port number, starting from 1

Definition at line 97 of file ports.c.

static void usb_hub_removed_device ( usb_hub_info_t hub,
uint16_t  port 
) [static]

routine called when a device on port has been removed

If the device on port had default address, it releases default address. Otherwise does not do anything, because DDF does not allow to remove device from it`s device tree.

Parameters:
hub hub representation
port port number, starting from 1

remove device from device manager - not yet implemented in devide manager

Definition at line 190 of file ports.c.

static int usb_hub_set_configuration ( usb_hub_info_t hub_info  )  [static]

Set configuration of hub.

Check whether there is at least one configuration and sets the first one. This function should be run prior to running any hub-specific action.

Parameters:
hub_info hub representation
Returns:
error code

Definition at line 298 of file usbhub.c.

static void usb_hub_set_descriptor_request ( usb_device_request_setup_packet_t request  )  [inline, static]

Set the device request to be a get hub descriptor request.

Warning:
the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
Parameters:
request 
addr 

Definition at line 66 of file usbhub_private.h.

static void usb_hub_set_disable_port_feature_request ( usb_device_request_setup_packet_t request,
uint16_t  port,
uint16_t  feature_selector 
) [inline, static]

set the device request to be a port feature clear request

Parameters:
request 
port 
feature_selector 

Definition at line 123 of file port_status.h.

static void usb_hub_set_disable_port_request ( usb_device_request_setup_packet_t request,
uint16_t  port 
) [inline, static]

set the device request to be a port disable request

Parameters:
request 
port 

Definition at line 167 of file port_status.h.

static void usb_hub_set_enable_port_feature_request ( usb_device_request_setup_packet_t request,
uint16_t  port,
uint16_t  feature_selector 
) [inline, static]

set the device request to be a port feature enable request

Parameters:
request 
port 
feature_selector 

Definition at line 107 of file port_status.h.

static void usb_hub_set_enable_port_request ( usb_device_request_setup_packet_t request,
uint16_t  port 
) [inline, static]

set the device request to be a port enable request

Parameters:
request 
port 

Definition at line 139 of file port_status.h.

static int usb_hub_set_feature ( usb_pipe_t pipe,
usb_hub_class_feature_t  feature 
) [inline, static]

Clear feature on hub port.

Parameters:
pipe pipe to hub control endpoint
feature Feature selector
Returns:
Operation result

Definition at line 153 of file usbhub_private.h.

static void usb_hub_set_hub_status_request ( usb_device_request_setup_packet_t request  )  [inline, static]

set values in request to be it a port status request

Parameters:
request 
port 

Definition at line 79 of file port_status.h.

static int usb_hub_set_port_feature ( usb_pipe_t pipe,
int  port_index,
usb_hub_class_feature_t  feature 
) [inline, static]

Clear feature on hub port.

Parameters:
hc Host controller telephone
address Hub address
port_index Port
feature Feature selector
Returns:
Operation result

Definition at line 110 of file usbhub_private.h.

static void usb_hub_set_port_status_request ( usb_device_request_setup_packet_t request,
uint16_t  port 
) [inline, static]

set values in request to be it a port status request

Parameters:
request 
port 

Definition at line 65 of file port_status.h.

static void usb_hub_set_power_port_request ( usb_device_request_setup_packet_t request,
uint16_t  port 
) [inline, static]

set the device request to be a port disable request

Parameters:
request 
port 

Definition at line 223 of file port_status.h.

static void usb_hub_set_reset_port_request ( usb_device_request_setup_packet_t request,
uint16_t  port 
) [inline, static]

set the device request to be a port disable request

Parameters:
request 
port 

Definition at line 195 of file port_status.h.

static int usb_hub_start_hub_fibril ( usb_hub_info_t hub_info  )  [static]

create and start fibril with hub control loop

Before the fibril is started, the control pipe and host controller connection of the hub is open.

Parameters:
hub_info hub representing structure
Returns:
error code

Definition at line 338 of file usbhub.c.

static void usb_hub_status_set_bit ( usb_hub_status_t status,
int  idx,
bool  value 
) [inline, static]

set i`th bit of hub status

Parameters:
status 
idx 
value 

Definition at line 291 of file port_status.h.

static void usb_hub_unset_power_port_request ( usb_device_request_setup_packet_t request,
uint16_t  port 
) [inline, static]

set the device request to be a port disable request

Parameters:
request 
port 

Definition at line 238 of file port_status.h.

static bool usb_port_high_speed ( usb_port_status_t  status  )  [inline, static]

high speed device on the port indicator

Parameters:
status 
Returns:
true if high speed device is on port

Definition at line 326 of file port_status.h.

static bool usb_port_is_status ( usb_port_status_t  status,
int  idx 
) [inline, static]

get i`th bit of port status

Parameters:
status 
idx 
Returns:

Definition at line 255 of file port_status.h.

static bool usb_port_low_speed ( usb_port_status_t  status  )  [inline, static]

low speed device on the port indicator

Parameters:
status 
Returns:
true if low speed device is attached

Definition at line 304 of file port_status.h.

static void usb_port_set_high_speed ( usb_port_status_t status,
bool  high_speed 
) [inline, static]

set high speed device bit in port status

Parameters:
status 
high_speed value of the bit

Definition at line 336 of file port_status.h.

static void usb_port_set_low_speed ( usb_port_status_t status,
bool  low_speed 
) [inline, static]

set low speed device connected bit in port status

Parameters:
status 
low_speed value of the bit

Definition at line 314 of file port_status.h.

static usb_speed_t usb_port_speed ( usb_port_status_t  status  )  [inline, static]

speed getter for port status

Parameters:
status 
Returns:
speed of usb device (for more see usb specification)

Definition at line 346 of file port_status.h.

static void usb_port_status_set_bit ( usb_port_status_t status,
int  idx,
bool  value 
) [inline, static]

set i`th bit of port status

Parameters:
status 
idx 
value 

Definition at line 266 of file port_status.h.

static int usb_process_hub_local_power_change ( usb_hub_info_t hub_info,
usb_hub_status_t  status 
) [static]

process hub local power change

This change is ignored.

Parameters:
hub_info hub instance
status hub status bitmask
Returns:
error code

Definition at line 411 of file usbhub.c.

static int usb_process_hub_over_current ( usb_hub_info_t hub_info,
usb_hub_status_t  status 
) [static]

process hub over current change

This means either to power off the hub or power it on.

Parameters:
hub_info hub instance
status hub status bitmask
Returns:
error code

Definition at line 370 of file usbhub.c.

void usb_serialize_hub_descriptor ( usb_hub_descriptor_t descriptor,
void *  serialized_descriptor 
)

serialize descriptor into given buffer

The buffer size is not checked.

Parameters:
descriptor 
serialized_descriptor 

handling of endianness??

Definition at line 84 of file utils.c.


Variable Documentation

usb_endpoint_description_t hub_status_change_endpoint_description [static]

Initial value:

 {
        .transfer_type = USB_TRANSFER_INTERRUPT,
        .direction = USB_DIRECTION_IN,
        .interface_class = USB_CLASS_HUB,
        .interface_subclass = 0,
        .interface_protocol = 0,
        .flags = 0
}
Hub status-change endpoint description.

For more information see section 11.15.1 of USB 1.1 specification.

Definition at line 48 of file main.c.

usb_driver_ops_t usb_hub_driver_ops [static]

Initial value:

 {
        .add_device = usb_hub_add_device
}
usb hub driver operations

The most important one is add_device, which is set to usb_hub_add_device.

Definition at line 62 of file main.c.


Generated on Thu Jun 2 07:45:56 2011 for HelenOS/USB by  doxygen 1.4.7