• Sarah Sharp's avatar
    USB: Support for bandwidth allocation. · 79abb1ab
    Sarah Sharp authored
    Originally, the USB core had no support for allocating bandwidth when a
    particular configuration or alternate setting for an interface was
    selected.  Instead, the device driver's URB submission would fail if
    there was not enough bandwidth for a periodic endpoint.  Drivers could
    work around this, by using the scatter-gather list API to guarantee
    bandwidth.
    
    This patch adds host controller API to allow the USB core to allocate or
    deallocate bandwidth for an endpoint.  Endpoints are added to or dropped
    from a copy of the current schedule by calling add_endpoint() or
    drop_endpoint(), and then the schedule is atomically evaluated with a
    call to check_bandwidth().  This allows all the endpoints for a new
    configuration or alternate setting to be added at the same time that the
    endpoints from the old configuration or alt setting are dropped.
    
    Endpoints must be added to the schedule before any URBs are submitted to
    them.  The HCD must be allowed to reject a new configuration or alt
    setting before the control transfer is sent to the device requesting the
    change.  It may reject the change because there is not enough bandwidth,
    not enough internal resources (such as memory on an embedded host
    controller), or perhaps even for security reasons in a virtualized
    environment.
    
    If the call to check_bandwidth() fails, the USB core must call
    reset_bandwidth().  This causes the schedule to be reverted back to the
    state it was in just after the last successful check_bandwidth() call.
    
    If the call succeeds, the host controller driver (and hardware) will have
    changed its internal state to match the new configuration or alternate
    setting.  The USB core can then issue a control transfer to the device to
    change the configuration or alt setting.  This allows the core to test new
    configurations or alternate settings before unbinding drivers bound to
    interfaces in the old configuration.
    
    WIP:
    
    The USB core must add endpoints from all interfaces in a configuration
    to the schedule, because a driver may claim that interface at any time.
    A slight optimization might be to add the endpoints to the schedule once
    a driver claims that interface.  FIXME
    
    This patch does not cover changing alternate settings, but it does
    handle a configuration change or de-configuration.  FIXME
    
    The code for managing the schedule is currently HCD specific.  A generic
    scheduling algorithm could be added for host controllers without
    built-in scheduling support.  For now, if a host controller does not
    define the check_bandwidth() function, the call to
    usb_hcd_check_bandwidth() will always succeed.
    Signed-off-by: default avatarSarah Sharp <sarah.a.sharp@linux.intel.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
    79abb1ab
urb.c 27 KB