2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* message.c - synchronous message handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pci.h> /* for scatterlist macros */
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/ctype.h>
|
2009-04-24 15:12:18 +07:00
|
|
|
#include <linux/nls.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/device.h>
|
2007-10-24 01:42:11 +07:00
|
|
|
#include <linux/scatterlist.h>
|
2007-01-26 20:26:21 +07:00
|
|
|
#include <linux/usb/quirks.h>
|
2010-04-25 04:21:52 +07:00
|
|
|
#include <linux/usb/hcd.h> /* for usbcore internals */
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/byteorder.h>
|
|
|
|
|
|
|
|
#include "usb.h"
|
|
|
|
|
2008-12-19 22:27:56 +07:00
|
|
|
static void cancel_async_set_config(struct usb_device *udev);
|
|
|
|
|
2007-07-25 05:23:23 +07:00
|
|
|
struct api_context {
|
|
|
|
struct completion done;
|
|
|
|
int status;
|
|
|
|
};
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 20:55:46 +07:00
|
|
|
static void usb_api_blocking_completion(struct urb *urb)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-07-25 05:23:23 +07:00
|
|
|
struct api_context *ctx = urb->context;
|
|
|
|
|
|
|
|
ctx->status = urb->status;
|
|
|
|
complete(&ctx->done);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-12 15:09:41 +07:00
|
|
|
/*
|
|
|
|
* Starts urb and waits for completion or timeout. Note that this call
|
|
|
|
* is NOT interruptible. Many device driver i/o requests should be
|
|
|
|
* interruptible and therefore these drivers should implement their
|
|
|
|
* own interruptible routines.
|
|
|
|
*/
|
|
|
|
static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
|
2008-01-31 06:21:33 +07:00
|
|
|
{
|
2007-07-25 05:23:23 +07:00
|
|
|
struct api_context ctx;
|
2006-07-12 15:09:41 +07:00
|
|
|
unsigned long expire;
|
2007-07-19 00:58:02 +07:00
|
|
|
int retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-25 05:23:23 +07:00
|
|
|
init_completion(&ctx.done);
|
|
|
|
urb->context = &ctx;
|
2005-04-17 05:20:36 +07:00
|
|
|
urb->actual_length = 0;
|
2007-07-19 00:58:02 +07:00
|
|
|
retval = usb_submit_urb(urb, GFP_NOIO);
|
|
|
|
if (unlikely(retval))
|
2006-07-12 15:09:41 +07:00
|
|
|
goto out;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-07-12 15:09:41 +07:00
|
|
|
expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT;
|
2007-07-25 05:23:23 +07:00
|
|
|
if (!wait_for_completion_timeout(&ctx.done, expire)) {
|
|
|
|
usb_kill_urb(urb);
|
|
|
|
retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status);
|
2006-07-12 15:09:41 +07:00
|
|
|
|
|
|
|
dev_dbg(&urb->dev->dev,
|
2009-03-13 18:19:18 +07:00
|
|
|
"%s timed out on ep%d%s len=%u/%u\n",
|
2006-07-12 15:09:41 +07:00
|
|
|
current->comm,
|
2007-07-31 04:07:21 +07:00
|
|
|
usb_endpoint_num(&urb->ep->desc),
|
|
|
|
usb_urb_dir_in(urb) ? "in" : "out",
|
2006-07-12 15:09:41 +07:00
|
|
|
urb->actual_length,
|
|
|
|
urb->transfer_buffer_length);
|
|
|
|
} else
|
2007-07-25 05:23:23 +07:00
|
|
|
retval = ctx.status;
|
2006-07-12 15:09:41 +07:00
|
|
|
out:
|
2005-04-17 05:20:36 +07:00
|
|
|
if (actual_length)
|
|
|
|
*actual_length = urb->actual_length;
|
2006-07-12 15:09:41 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
usb_free_urb(urb);
|
2007-07-19 00:58:02 +07:00
|
|
|
return retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------*/
|
2008-01-31 06:21:33 +07:00
|
|
|
/* returns status (negative) or length (positive) */
|
2005-04-17 05:20:36 +07:00
|
|
|
static int usb_internal_control_msg(struct usb_device *usb_dev,
|
2008-01-31 06:21:33 +07:00
|
|
|
unsigned int pipe,
|
2005-04-17 05:20:36 +07:00
|
|
|
struct usb_ctrlrequest *cmd,
|
|
|
|
void *data, int len, int timeout)
|
|
|
|
{
|
|
|
|
struct urb *urb;
|
|
|
|
int retv;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
urb = usb_alloc_urb(0, GFP_NOIO);
|
|
|
|
if (!urb)
|
|
|
|
return -ENOMEM;
|
2008-01-31 06:21:33 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data,
|
|
|
|
len, usb_api_blocking_completion, NULL);
|
|
|
|
|
|
|
|
retv = usb_start_wait_urb(urb, timeout, &length);
|
|
|
|
if (retv < 0)
|
|
|
|
return retv;
|
|
|
|
else
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-01-31 06:21:33 +07:00
|
|
|
* usb_control_msg - Builds a control urb, sends it off and waits for completion
|
|
|
|
* @dev: pointer to the usb device to send the message to
|
|
|
|
* @pipe: endpoint "pipe" to send the message to
|
|
|
|
* @request: USB message request value
|
|
|
|
* @requesttype: USB message request type value
|
|
|
|
* @value: USB message value
|
|
|
|
* @index: USB message index value
|
|
|
|
* @data: pointer to the data to send
|
|
|
|
* @size: length in bytes of the data to send
|
|
|
|
* @timeout: time in msecs to wait for the message to complete before timing
|
|
|
|
* out (if 0 the wait is forever)
|
|
|
|
*
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* This function sends a simple control message to a specified endpoint and
|
|
|
|
* waits for the message to complete, or timeout.
|
|
|
|
*
|
|
|
|
* Don't use this function from within an interrupt context, like a bottom half
|
|
|
|
* handler. If you need an asynchronous message, or need to send a message
|
|
|
|
* from within interrupt context, use usb_submit_urb().
|
|
|
|
* If a thread in your driver uses this call, make sure your disconnect()
|
|
|
|
* method can wait for it to complete. Since you don't have a handle on the
|
|
|
|
* URB used, you can't cancel the request.
|
2013-08-03 01:10:04 +07:00
|
|
|
*
|
|
|
|
* Return: If successful, the number of bytes transferred. Otherwise, a negative
|
|
|
|
* error number.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
|
|
|
|
__u8 requesttype, __u16 value, __u16 index, void *data,
|
|
|
|
__u16 size, int timeout)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
struct usb_ctrlrequest *dr;
|
2005-04-17 05:20:36 +07:00
|
|
|
int ret;
|
2008-01-31 06:21:33 +07:00
|
|
|
|
|
|
|
dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!dr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
dr->bRequestType = requesttype;
|
2005-04-17 05:20:36 +07:00
|
|
|
dr->bRequest = request;
|
2008-10-30 04:25:51 +07:00
|
|
|
dr->wValue = cpu_to_le16(value);
|
|
|
|
dr->wIndex = cpu_to_le16(index);
|
|
|
|
dr->wLength = cpu_to_le16(size);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
|
|
|
|
|
|
|
|
kfree(dr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_control_msg);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-05-20 03:20:20 +07:00
|
|
|
/**
|
|
|
|
* usb_interrupt_msg - Builds an interrupt urb, sends it off and waits for completion
|
|
|
|
* @usb_dev: pointer to the usb device to send the message to
|
|
|
|
* @pipe: endpoint "pipe" to send the message to
|
|
|
|
* @data: pointer to the data to send
|
|
|
|
* @len: length in bytes of the data to send
|
2008-01-31 06:21:33 +07:00
|
|
|
* @actual_length: pointer to a location to put the actual length transferred
|
|
|
|
* in bytes
|
2006-05-20 03:20:20 +07:00
|
|
|
* @timeout: time in msecs to wait for the message to complete before
|
|
|
|
* timing out (if 0 the wait is forever)
|
2008-01-31 06:21:33 +07:00
|
|
|
*
|
2006-05-20 03:20:20 +07:00
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* This function sends a simple interrupt message to a specified endpoint and
|
|
|
|
* waits for the message to complete, or timeout.
|
|
|
|
*
|
|
|
|
* Don't use this function from within an interrupt context, like a bottom half
|
|
|
|
* handler. If you need an asynchronous message, or need to send a message
|
|
|
|
* from within interrupt context, use usb_submit_urb() If a thread in your
|
|
|
|
* driver uses this call, make sure your disconnect() method can wait for it to
|
|
|
|
* complete. Since you don't have a handle on the URB used, you can't cancel
|
|
|
|
* the request.
|
2013-08-03 01:10:04 +07:00
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* If successful, 0. Otherwise a negative error number. The number of actual
|
2014-02-18 20:54:36 +07:00
|
|
|
* bytes transferred will be stored in the @actual_length parameter.
|
2006-05-20 03:20:20 +07:00
|
|
|
*/
|
|
|
|
int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
|
|
|
|
void *data, int len, int *actual_length, int timeout)
|
|
|
|
{
|
|
|
|
return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usb_interrupt_msg);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
2008-01-31 06:21:33 +07:00
|
|
|
* usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion
|
|
|
|
* @usb_dev: pointer to the usb device to send the message to
|
|
|
|
* @pipe: endpoint "pipe" to send the message to
|
|
|
|
* @data: pointer to the data to send
|
|
|
|
* @len: length in bytes of the data to send
|
|
|
|
* @actual_length: pointer to a location to put the actual length transferred
|
|
|
|
* in bytes
|
|
|
|
* @timeout: time in msecs to wait for the message to complete before
|
|
|
|
* timing out (if 0 the wait is forever)
|
|
|
|
*
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* This function sends a simple bulk message to a specified endpoint
|
|
|
|
* and waits for the message to complete, or timeout.
|
|
|
|
*
|
|
|
|
* Don't use this function from within an interrupt context, like a bottom half
|
|
|
|
* handler. If you need an asynchronous message, or need to send a message
|
|
|
|
* from within interrupt context, use usb_submit_urb() If a thread in your
|
|
|
|
* driver uses this call, make sure your disconnect() method can wait for it to
|
|
|
|
* complete. Since you don't have a handle on the URB used, you can't cancel
|
|
|
|
* the request.
|
|
|
|
*
|
|
|
|
* Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT ioctl,
|
|
|
|
* users are forced to abuse this routine by using it to submit URBs for
|
|
|
|
* interrupt endpoints. We will take the liberty of creating an interrupt URB
|
|
|
|
* (with the default interval) if the target is an interrupt endpoint.
|
2013-08-03 01:10:04 +07:00
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* If successful, 0. Otherwise a negative error number. The number of actual
|
2014-01-04 12:54:41 +07:00
|
|
|
* bytes transferred will be stored in the @actual_length parameter.
|
2013-08-03 01:10:04 +07:00
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
|
|
|
|
void *data, int len, int *actual_length, int timeout)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct urb *urb;
|
2005-09-27 03:22:45 +07:00
|
|
|
struct usb_host_endpoint *ep;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-05-01 02:11:29 +07:00
|
|
|
ep = usb_pipe_endpoint(usb_dev, pipe);
|
2005-09-27 03:22:45 +07:00
|
|
|
if (!ep || len < 0)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2005-09-27 03:22:45 +07:00
|
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!urb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2005-09-27 03:22:45 +07:00
|
|
|
if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
|
|
|
|
USB_ENDPOINT_XFER_INT) {
|
|
|
|
pipe = (pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30);
|
|
|
|
usb_fill_int_urb(urb, usb_dev, pipe, data, len,
|
2007-04-24 04:30:32 +07:00
|
|
|
usb_api_blocking_completion, NULL,
|
|
|
|
ep->desc.bInterval);
|
2005-09-27 03:22:45 +07:00
|
|
|
} else
|
|
|
|
usb_fill_bulk_urb(urb, usb_dev, pipe, data, len,
|
|
|
|
usb_api_blocking_completion, NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return usb_start_wait_urb(urb, timeout, actual_length);
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_bulk_msg);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
static void sg_clean(struct usb_sg_request *io)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
if (io->urbs) {
|
|
|
|
while (io->entries--)
|
2013-05-17 14:32:35 +07:00
|
|
|
usb_free_urb(io->urbs[io->entries]);
|
2008-01-31 06:21:33 +07:00
|
|
|
kfree(io->urbs);
|
2005-04-17 05:20:36 +07:00
|
|
|
io->urbs = NULL;
|
|
|
|
}
|
|
|
|
io->dev = NULL;
|
|
|
|
}
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
static void sg_complete(struct urb *urb)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
struct usb_sg_request *io = urb->context;
|
2007-07-19 00:58:02 +07:00
|
|
|
int status = urb->status;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_lock(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* In 2.5 we require hcds' endpoint queues not to progress after fault
|
|
|
|
* reports, until the completion callback (this!) returns. That lets
|
|
|
|
* device driver code (like this routine) unlink queued urbs first,
|
|
|
|
* if it needs to, since the HC won't work on them at all. So it's
|
|
|
|
* not possible for page N+1 to overwrite page N, and so on.
|
|
|
|
*
|
|
|
|
* That's only for "hard" faults; "soft" faults (unlinks) sometimes
|
|
|
|
* complete before the HCD can get requests away from hardware,
|
|
|
|
* though never during cleanup after a hard fault.
|
|
|
|
*/
|
|
|
|
if (io->status
|
|
|
|
&& (io->status != -ECONNRESET
|
2007-07-19 00:58:02 +07:00
|
|
|
|| status != -ECONNRESET)
|
2005-04-17 05:20:36 +07:00
|
|
|
&& urb->actual_length) {
|
2008-01-31 06:21:33 +07:00
|
|
|
dev_err(io->dev->bus->controller,
|
2005-04-17 05:20:36 +07:00
|
|
|
"dev %s ep%d%s scatterlist error %d/%d\n",
|
|
|
|
io->dev->devpath,
|
2007-07-31 04:07:21 +07:00
|
|
|
usb_endpoint_num(&urb->ep->desc),
|
|
|
|
usb_urb_dir_in(urb) ? "in" : "out",
|
2007-07-19 00:58:02 +07:00
|
|
|
status, io->status);
|
2008-01-31 06:21:33 +07:00
|
|
|
/* BUG (); */
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2007-07-19 00:58:02 +07:00
|
|
|
if (io->status == 0 && status && status != -ECONNRESET) {
|
|
|
|
int i, found, retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-07-19 00:58:02 +07:00
|
|
|
io->status = status;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* the previous urbs, and this one, completed already.
|
|
|
|
* unlink pending urbs so they won't rx/tx bad data.
|
|
|
|
* careful: unlink can sometimes be synchronous...
|
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_unlock(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
for (i = 0, found = 0; i < io->entries; i++) {
|
2013-05-17 14:32:35 +07:00
|
|
|
if (!io->urbs[i] || !io->urbs[i]->dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
continue;
|
|
|
|
if (found) {
|
2013-05-17 14:32:35 +07:00
|
|
|
retval = usb_unlink_urb(io->urbs[i]);
|
2007-07-19 00:58:02 +07:00
|
|
|
if (retval != -EINPROGRESS &&
|
|
|
|
retval != -ENODEV &&
|
2012-03-22 22:00:21 +07:00
|
|
|
retval != -EBUSY &&
|
|
|
|
retval != -EIDRM)
|
2008-01-31 06:21:33 +07:00
|
|
|
dev_err(&io->dev->dev,
|
2005-04-17 05:20:36 +07:00
|
|
|
"%s, unlink --> %d\n",
|
2008-03-04 07:08:34 +07:00
|
|
|
__func__, retval);
|
2013-05-17 14:32:35 +07:00
|
|
|
} else if (urb == io->urbs[i])
|
2005-04-17 05:20:36 +07:00
|
|
|
found = 1;
|
|
|
|
}
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_lock(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* on the last completion, signal usb_sg_wait() */
|
|
|
|
io->bytes += urb->actual_length;
|
|
|
|
io->count--;
|
|
|
|
if (!io->count)
|
2008-01-31 06:21:33 +07:00
|
|
|
complete(&io->complete);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_unlock(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_sg_init - initializes scatterlist-based bulk/interrupt I/O request
|
|
|
|
* @io: request block being initialized. until usb_sg_wait() returns,
|
|
|
|
* treat this as a pointer to an opaque block of memory,
|
|
|
|
* @dev: the usb device that will send or receive the data
|
|
|
|
* @pipe: endpoint "pipe" used to transfer the data
|
|
|
|
* @period: polling rate for interrupt endpoints, in frames or
|
|
|
|
* (for high speed endpoints) microframes; ignored for bulk
|
|
|
|
* @sg: scatterlist entries
|
|
|
|
* @nents: how many entries in the scatterlist
|
|
|
|
* @length: how many bytes to send from the scatterlist, or zero to
|
|
|
|
* send every byte identified in the list.
|
|
|
|
* @mem_flags: SLAB_* flags affecting memory allocations in this call
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* This initializes a scatter/gather request, allocating resources such as
|
|
|
|
* I/O mappings and urb memory (except maybe memory used by USB controller
|
|
|
|
* drivers).
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* The request must be issued using usb_sg_wait(), which waits for the I/O to
|
|
|
|
* complete (or to be canceled) and then cleans up all resources allocated by
|
|
|
|
* usb_sg_init().
|
|
|
|
*
|
|
|
|
* The request may be canceled with usb_sg_cancel(), either before or after
|
|
|
|
* usb_sg_wait() is called.
|
2013-08-03 01:10:04 +07:00
|
|
|
*
|
|
|
|
* Return: Zero for success, else a negative errno value.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
|
|
|
|
unsigned pipe, unsigned period, struct scatterlist *sg,
|
|
|
|
int nents, size_t length, gfp_t mem_flags)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
int i;
|
|
|
|
int urb_flags;
|
2009-04-28 09:59:01 +07:00
|
|
|
int use_sg;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (!io || !dev || !sg
|
2008-01-31 06:21:33 +07:00
|
|
|
|| usb_pipecontrol(pipe)
|
|
|
|
|| usb_pipeisoc(pipe)
|
2005-04-17 05:20:36 +07:00
|
|
|
|| nents <= 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_lock_init(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
io->dev = dev;
|
|
|
|
io->pipe = pipe;
|
|
|
|
|
2009-08-24 20:44:30 +07:00
|
|
|
if (dev->bus->sg_tablesize > 0) {
|
2009-04-28 09:59:01 +07:00
|
|
|
use_sg = true;
|
2010-05-06 02:26:17 +07:00
|
|
|
io->entries = 1;
|
2009-04-28 09:59:01 +07:00
|
|
|
} else {
|
|
|
|
use_sg = false;
|
2010-05-06 02:26:17 +07:00
|
|
|
io->entries = nents;
|
2009-04-28 09:59:01 +07:00
|
|
|
}
|
2010-05-06 02:26:17 +07:00
|
|
|
|
|
|
|
/* initialize all the urbs we'll use */
|
2013-05-17 14:33:05 +07:00
|
|
|
io->urbs = kmalloc(io->entries * sizeof(*io->urbs), mem_flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!io->urbs)
|
|
|
|
goto nomem;
|
|
|
|
|
2010-05-06 02:26:17 +07:00
|
|
|
urb_flags = URB_NO_INTERRUPT;
|
2008-01-31 06:21:33 +07:00
|
|
|
if (usb_pipein(pipe))
|
2005-04-17 05:20:36 +07:00
|
|
|
urb_flags |= URB_SHORT_NOT_OK;
|
|
|
|
|
2010-05-06 02:26:17 +07:00
|
|
|
for_each_sg(sg, sg, io->entries, i) {
|
|
|
|
struct urb *urb;
|
|
|
|
unsigned len;
|
2010-04-03 00:27:28 +07:00
|
|
|
|
2010-05-06 02:26:17 +07:00
|
|
|
urb = usb_alloc_urb(0, mem_flags);
|
|
|
|
if (!urb) {
|
|
|
|
io->entries = i;
|
|
|
|
goto nomem;
|
2009-04-28 09:59:01 +07:00
|
|
|
}
|
2010-05-06 02:26:17 +07:00
|
|
|
io->urbs[i] = urb;
|
|
|
|
|
|
|
|
urb->dev = NULL;
|
|
|
|
urb->pipe = pipe;
|
|
|
|
urb->interval = period;
|
|
|
|
urb->transfer_flags = urb_flags;
|
|
|
|
urb->complete = sg_complete;
|
|
|
|
urb->context = io;
|
|
|
|
urb->sg = sg;
|
|
|
|
|
|
|
|
if (use_sg) {
|
|
|
|
/* There is no single transfer buffer */
|
|
|
|
urb->transfer_buffer = NULL;
|
|
|
|
urb->num_sgs = nents;
|
|
|
|
|
|
|
|
/* A length of zero means transfer the whole sg list */
|
|
|
|
len = length;
|
|
|
|
if (len == 0) {
|
2010-06-18 21:16:33 +07:00
|
|
|
struct scatterlist *sg2;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for_each_sg(sg, sg2, nents, j)
|
|
|
|
len += sg2->length;
|
2009-04-28 09:59:01 +07:00
|
|
|
}
|
2010-05-06 02:26:17 +07:00
|
|
|
} else {
|
2009-04-28 09:59:01 +07:00
|
|
|
/*
|
2010-04-03 00:27:28 +07:00
|
|
|
* Some systems can't use DMA; they use PIO instead.
|
|
|
|
* For their sakes, transfer_buffer is set whenever
|
|
|
|
* possible.
|
2009-04-28 09:59:01 +07:00
|
|
|
*/
|
2010-04-03 00:27:28 +07:00
|
|
|
if (!PageHighMem(sg_page(sg)))
|
2010-05-06 02:26:17 +07:00
|
|
|
urb->transfer_buffer = sg_virt(sg);
|
2009-06-11 21:40:39 +07:00
|
|
|
else
|
2010-05-06 02:26:17 +07:00
|
|
|
urb->transfer_buffer = NULL;
|
2009-06-11 21:40:39 +07:00
|
|
|
|
2010-04-03 00:27:28 +07:00
|
|
|
len = sg->length;
|
2009-04-28 09:59:01 +07:00
|
|
|
if (length) {
|
2011-09-27 13:25:19 +07:00
|
|
|
len = min_t(size_t, len, length);
|
2009-04-28 09:59:01 +07:00
|
|
|
length -= len;
|
|
|
|
if (length == 0)
|
|
|
|
io->entries = i + 1;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2010-05-06 02:26:17 +07:00
|
|
|
urb->transfer_buffer_length = len;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2010-05-06 02:26:17 +07:00
|
|
|
io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* transaction state */
|
2008-08-06 00:05:17 +07:00
|
|
|
io->count = io->entries;
|
2005-04-17 05:20:36 +07:00
|
|
|
io->status = 0;
|
|
|
|
io->bytes = 0;
|
2008-01-31 06:21:33 +07:00
|
|
|
init_completion(&io->complete);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
nomem:
|
2008-01-31 06:21:33 +07:00
|
|
|
sg_clean(io);
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_sg_init);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_sg_wait - synchronously execute scatter/gather request
|
|
|
|
* @io: request block handle, as initialized with usb_sg_init().
|
|
|
|
* some fields become accessible when this call returns.
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* This function blocks until the specified I/O operation completes. It
|
|
|
|
* leverages the grouping of the related I/O requests to get good transfer
|
|
|
|
* rates, by queueing the requests. At higher speeds, such queuing can
|
|
|
|
* significantly improve USB throughput.
|
|
|
|
*
|
|
|
|
* There are three kinds of completion for this function.
|
|
|
|
* (1) success, where io->status is zero. The number of io->bytes
|
|
|
|
* transferred is as requested.
|
|
|
|
* (2) error, where io->status is a negative errno value. The number
|
|
|
|
* of io->bytes transferred before the error is usually less
|
|
|
|
* than requested, and can be nonzero.
|
2005-05-04 08:07:24 +07:00
|
|
|
* (3) cancellation, a type of error with status -ECONNRESET that
|
2005-04-17 05:20:36 +07:00
|
|
|
* is initiated by usb_sg_cancel().
|
|
|
|
*
|
|
|
|
* When this function returns, all memory allocated through usb_sg_init() or
|
|
|
|
* this call will have been freed. The request block parameter may still be
|
|
|
|
* passed to usb_sg_cancel(), or it may be freed. It could also be
|
|
|
|
* reinitialized and then reused.
|
|
|
|
*
|
|
|
|
* Data Transfer Rates:
|
|
|
|
*
|
|
|
|
* Bulk transfers are valid for full or high speed endpoints.
|
|
|
|
* The best full speed data rate is 19 packets of 64 bytes each
|
|
|
|
* per frame, or 1216 bytes per millisecond.
|
|
|
|
* The best high speed data rate is 13 packets of 512 bytes each
|
|
|
|
* per microframe, or 52 KBytes per millisecond.
|
|
|
|
*
|
|
|
|
* The reason to use interrupt transfers through this API would most likely
|
|
|
|
* be to reserve high speed bandwidth, where up to 24 KBytes per millisecond
|
|
|
|
* could be transferred. That capability is less useful for low or full
|
|
|
|
* speed interrupt endpoints, which allow at most one packet per millisecond,
|
|
|
|
* of at most 8 or 64 bytes (respectively).
|
USB: Support for bandwidth allocation.
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: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-04-28 09:58:26 +07:00
|
|
|
*
|
|
|
|
* It is not necessary to call this function to reserve bandwidth for devices
|
|
|
|
* under an xHCI host controller, as the bandwidth is reserved when the
|
|
|
|
* configuration or interface alt setting is selected.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
void usb_sg_wait(struct usb_sg_request *io)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
int i;
|
|
|
|
int entries = io->entries;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* queue the urbs. */
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_lock_irq(&io->lock);
|
2007-06-22 03:26:46 +07:00
|
|
|
i = 0;
|
|
|
|
while (i < entries && !io->status) {
|
2008-01-31 06:21:33 +07:00
|
|
|
int retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
io->urbs[i]->dev = io->dev;
|
2013-05-17 14:32:35 +07:00
|
|
|
retval = usb_submit_urb(io->urbs[i], GFP_ATOMIC);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-01-04 12:54:41 +07:00
|
|
|
/* after we submit, let completions or cancellations fire;
|
2005-04-17 05:20:36 +07:00
|
|
|
* we handshake using io->status.
|
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_unlock_irq(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
switch (retval) {
|
|
|
|
/* maybe we retrying will recover */
|
2008-01-31 06:21:33 +07:00
|
|
|
case -ENXIO: /* hc didn't queue this one */
|
2005-04-17 05:20:36 +07:00
|
|
|
case -EAGAIN:
|
|
|
|
case -ENOMEM:
|
|
|
|
retval = 0;
|
2008-01-31 06:21:33 +07:00
|
|
|
yield();
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* no error? continue immediately.
|
|
|
|
*
|
|
|
|
* NOTE: to work better with UHCI (4K I/O buffer may
|
|
|
|
* need 3K of TDs) it may be good to limit how many
|
|
|
|
* URBs are queued at once; N milliseconds?
|
|
|
|
*/
|
|
|
|
case 0:
|
2007-06-22 03:26:46 +07:00
|
|
|
++i;
|
2008-01-31 06:21:33 +07:00
|
|
|
cpu_relax();
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* fail any uncompleted urbs */
|
|
|
|
default:
|
2008-01-31 06:21:33 +07:00
|
|
|
io->urbs[i]->status = retval;
|
|
|
|
dev_dbg(&io->dev->dev, "%s, submit --> %d\n",
|
2008-03-04 07:08:34 +07:00
|
|
|
__func__, retval);
|
2008-01-31 06:21:33 +07:00
|
|
|
usb_sg_cancel(io);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_lock_irq(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (retval && (io->status == 0 || io->status == -ECONNRESET))
|
|
|
|
io->status = retval;
|
|
|
|
}
|
|
|
|
io->count -= entries - i;
|
|
|
|
if (io->count == 0)
|
2008-01-31 06:21:33 +07:00
|
|
|
complete(&io->complete);
|
|
|
|
spin_unlock_irq(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* OK, yes, this could be packaged as non-blocking.
|
|
|
|
* So could the submit loop above ... but it's easier to
|
|
|
|
* solve neither problem than to solve both!
|
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
wait_for_completion(&io->complete);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
sg_clean(io);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_sg_wait);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_sg_cancel - stop scatter/gather i/o issued by usb_sg_wait()
|
|
|
|
* @io: request block, initialized with usb_sg_init()
|
|
|
|
*
|
|
|
|
* This stops a request after it has been started by usb_sg_wait().
|
|
|
|
* It can also prevents one initialized by usb_sg_init() from starting,
|
|
|
|
* so that call just frees resources allocated to the request.
|
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
void usb_sg_cancel(struct usb_sg_request *io)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
unsigned long flags;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_lock_irqsave(&io->lock, flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* shut everything down, if it didn't already */
|
|
|
|
if (!io->status) {
|
2008-01-31 06:21:33 +07:00
|
|
|
int i;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
io->status = -ECONNRESET;
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_unlock(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
for (i = 0; i < io->entries; i++) {
|
2008-01-31 06:21:33 +07:00
|
|
|
int retval;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-05-17 14:32:35 +07:00
|
|
|
if (!io->urbs[i]->dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
continue;
|
2013-05-17 14:32:35 +07:00
|
|
|
retval = usb_unlink_urb(io->urbs[i]);
|
2012-03-22 22:00:21 +07:00
|
|
|
if (retval != -EINPROGRESS
|
|
|
|
&& retval != -ENODEV
|
|
|
|
&& retval != -EBUSY
|
|
|
|
&& retval != -EIDRM)
|
2008-01-31 06:21:33 +07:00
|
|
|
dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
|
2008-03-04 07:08:34 +07:00
|
|
|
__func__, retval);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_lock(&io->lock);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-01-31 06:21:33 +07:00
|
|
|
spin_unlock_irqrestore(&io->lock, flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_sg_cancel);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_get_descriptor - issues a generic GET_DESCRIPTOR request
|
|
|
|
* @dev: the device whose descriptor is being retrieved
|
|
|
|
* @type: the descriptor type (USB_DT_*)
|
|
|
|
* @index: the number of the descriptor
|
|
|
|
* @buf: where to put the descriptor
|
|
|
|
* @size: how big is "buf"?
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* Gets a USB descriptor. Convenience functions exist to simplify
|
|
|
|
* getting some types of descriptors. Use
|
|
|
|
* usb_get_string() or usb_string() for USB_DT_STRING.
|
|
|
|
* Device (USB_DT_DEVICE) and configuration descriptors (USB_DT_CONFIG)
|
|
|
|
* are part of the device structure.
|
|
|
|
* In addition to a number of USB-standard descriptors, some
|
|
|
|
* devices also use class-specific or vendor-specific descriptors.
|
|
|
|
*
|
|
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: The number of bytes received on success, or else the status code
|
2005-04-17 05:20:36 +07:00
|
|
|
* returned by the underlying usb_control_msg() call.
|
|
|
|
*/
|
2008-01-31 06:21:33 +07:00
|
|
|
int usb_get_descriptor(struct usb_device *dev, unsigned char type,
|
|
|
|
unsigned char index, void *buf, int size)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int result;
|
2008-01-31 06:21:33 +07:00
|
|
|
|
|
|
|
memset(buf, 0, size); /* Make sure we parse really received data */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
for (i = 0; i < 3; ++i) {
|
2007-08-20 21:45:28 +07:00
|
|
|
/* retry on length 0 or error; some devices are flakey */
|
2005-04-17 05:20:36 +07:00
|
|
|
result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
|
|
|
USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
|
|
|
|
(type << 8) + index, 0, buf, size,
|
|
|
|
USB_CTRL_GET_TIMEOUT);
|
2007-08-20 21:45:28 +07:00
|
|
|
if (result <= 0 && result != -ETIMEDOUT)
|
2005-04-17 05:20:36 +07:00
|
|
|
continue;
|
|
|
|
if (result > 1 && ((u8 *)buf)[1] != type) {
|
2009-02-21 04:33:08 +07:00
|
|
|
result = -ENODATA;
|
2005-04-17 05:20:36 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_get_descriptor);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_get_string - gets a string descriptor
|
|
|
|
* @dev: the device whose string descriptor is being retrieved
|
|
|
|
* @langid: code for language chosen (from string descriptor zero)
|
|
|
|
* @index: the number of the descriptor
|
|
|
|
* @buf: where to put the string
|
|
|
|
* @size: how big is "buf"?
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* Retrieves a string, encoded using UTF-16LE (Unicode, 16 bits per character,
|
|
|
|
* in little-endian byte order).
|
|
|
|
* The usb_string() function will often be a convenient way to turn
|
|
|
|
* these strings into kernel-printable form.
|
|
|
|
*
|
|
|
|
* Strings may be referenced in device, configuration, interface, or other
|
|
|
|
* descriptors, and could also be used in vendor-specific ways.
|
|
|
|
*
|
|
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: The number of bytes received on success, or else the status code
|
2005-04-17 05:20:36 +07:00
|
|
|
* returned by the underlying usb_control_msg() call.
|
|
|
|
*/
|
2005-11-09 03:05:43 +07:00
|
|
|
static int usb_get_string(struct usb_device *dev, unsigned short langid,
|
|
|
|
unsigned char index, void *buf, int size)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
/* retry on length 0 or stall; some devices are flakey */
|
|
|
|
result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
|
|
|
USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
|
|
|
|
(USB_DT_STRING << 8) + index, langid, buf, size,
|
|
|
|
USB_CTRL_GET_TIMEOUT);
|
2009-02-21 04:33:08 +07:00
|
|
|
if (result == 0 || result == -EPIPE)
|
|
|
|
continue;
|
|
|
|
if (result > 1 && ((u8 *) buf)[1] != USB_DT_STRING) {
|
|
|
|
result = -ENODATA;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_try_string_workarounds(unsigned char *buf, int *length)
|
|
|
|
{
|
|
|
|
int newlength, oldlength = *length;
|
|
|
|
|
|
|
|
for (newlength = 2; newlength + 1 < oldlength; newlength += 2)
|
|
|
|
if (!isprint(buf[newlength]) || buf[newlength + 1])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (newlength > 2) {
|
|
|
|
buf[0] = newlength;
|
|
|
|
*length = newlength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usb_string_sub(struct usb_device *dev, unsigned int langid,
|
2008-01-31 06:21:33 +07:00
|
|
|
unsigned int index, unsigned char *buf)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Try to read the string descriptor by asking for the maximum
|
|
|
|
* possible number of bytes */
|
2007-01-26 20:26:21 +07:00
|
|
|
if (dev->quirks & USB_QUIRK_STRING_FETCH_255)
|
|
|
|
rc = -EIO;
|
|
|
|
else
|
|
|
|
rc = usb_get_string(dev, langid, index, buf, 255);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* If that failed try to read the descriptor length, then
|
|
|
|
* ask for just that many bytes */
|
|
|
|
if (rc < 2) {
|
|
|
|
rc = usb_get_string(dev, langid, index, buf, 2);
|
|
|
|
if (rc == 2)
|
|
|
|
rc = usb_get_string(dev, langid, index, buf, buf[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc >= 2) {
|
|
|
|
if (!buf[0] && !buf[1])
|
|
|
|
usb_try_string_workarounds(buf, &rc);
|
|
|
|
|
|
|
|
/* There might be extra junk at the end of the descriptor */
|
|
|
|
if (buf[0] < rc)
|
|
|
|
rc = buf[0];
|
|
|
|
|
|
|
|
rc = rc - (rc & 1); /* force a multiple of two */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc < 2)
|
|
|
|
rc = (rc < 0 ? rc : -EINVAL);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-07-10 16:04:58 +07:00
|
|
|
static int usb_get_langid(struct usb_device *dev, unsigned char *tbuf)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (dev->have_langid)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (dev->string_langid < 0)
|
|
|
|
return -EPIPE;
|
|
|
|
|
|
|
|
err = usb_string_sub(dev, 0, 0, tbuf);
|
|
|
|
|
|
|
|
/* If the string was reported but is malformed, default to english
|
|
|
|
* (0x0409) */
|
|
|
|
if (err == -ENODATA || (err > 0 && err < 4)) {
|
|
|
|
dev->string_langid = 0x0409;
|
|
|
|
dev->have_langid = 1;
|
|
|
|
dev_err(&dev->dev,
|
2014-09-25 22:16:48 +07:00
|
|
|
"language id specifier not provided by device, defaulting to English\n");
|
2009-07-10 16:04:58 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In case of all other errors, we assume the device is not able to
|
|
|
|
* deal with strings at all. Set string_langid to -1 in order to
|
|
|
|
* prevent any string to be retrieved from the device */
|
|
|
|
if (err < 0) {
|
|
|
|
dev_err(&dev->dev, "string descriptor 0 read error: %d\n",
|
|
|
|
err);
|
|
|
|
dev->string_langid = -1;
|
|
|
|
return -EPIPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* always use the first langid listed */
|
|
|
|
dev->string_langid = tbuf[2] | (tbuf[3] << 8);
|
|
|
|
dev->have_langid = 1;
|
|
|
|
dev_dbg(&dev->dev, "default language 0x%04x\n",
|
|
|
|
dev->string_langid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
2009-04-24 15:12:18 +07:00
|
|
|
* usb_string - returns UTF-8 version of a string descriptor
|
2005-04-17 05:20:36 +07:00
|
|
|
* @dev: the device whose string descriptor is being retrieved
|
|
|
|
* @index: the number of the descriptor
|
|
|
|
* @buf: where to put the string
|
|
|
|
* @size: how big is "buf"?
|
|
|
|
* Context: !in_interrupt ()
|
2008-01-31 06:21:33 +07:00
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* This converts the UTF-16LE encoded strings returned by devices, from
|
2009-04-24 15:12:18 +07:00
|
|
|
* usb_get_string_descriptor(), to null-terminated UTF-8 encoded ones
|
|
|
|
* that are more usable in most kernel contexts. Note that this function
|
2005-04-17 05:20:36 +07:00
|
|
|
* chooses strings in the first language supported by the device.
|
|
|
|
*
|
|
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: length of the string (>= 0) or usb_control_msg status (< 0).
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
|
|
|
|
{
|
|
|
|
unsigned char *tbuf;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (dev->state == USB_STATE_SUSPENDED)
|
|
|
|
return -EHOSTUNREACH;
|
|
|
|
if (size <= 0 || !buf || !index)
|
|
|
|
return -EINVAL;
|
|
|
|
buf[0] = 0;
|
2009-04-30 21:08:18 +07:00
|
|
|
tbuf = kmalloc(256, GFP_NOIO);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!tbuf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-07-10 16:04:58 +07:00
|
|
|
err = usb_get_langid(dev, tbuf);
|
|
|
|
if (err < 0)
|
|
|
|
goto errout;
|
2008-01-31 06:21:33 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
err = usb_string_sub(dev, dev->string_langid, index, tbuf);
|
|
|
|
if (err < 0)
|
|
|
|
goto errout;
|
|
|
|
|
|
|
|
size--; /* leave room for trailing NULL char in output buffer */
|
2009-04-30 21:08:18 +07:00
|
|
|
err = utf16s_to_utf8s((wchar_t *) &tbuf[2], (err - 2) / 2,
|
|
|
|
UTF16_LITTLE_ENDIAN, buf, size);
|
2009-04-24 15:12:18 +07:00
|
|
|
buf[err] = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (tbuf[1] != USB_DT_STRING)
|
2008-01-31 06:21:33 +07:00
|
|
|
dev_dbg(&dev->dev,
|
|
|
|
"wrong descriptor type %02x for string %d (\"%s\")\n",
|
|
|
|
tbuf[1], index, buf);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
errout:
|
|
|
|
kfree(tbuf);
|
|
|
|
return err;
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_string);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-04-24 15:12:18 +07:00
|
|
|
/* one UTF-8-encoded 16-bit character has at most three bytes */
|
|
|
|
#define MAX_USB_STRING_SIZE (127 * 3 + 1)
|
|
|
|
|
2005-10-25 03:24:14 +07:00
|
|
|
/**
|
|
|
|
* usb_cache_string - read a string descriptor and cache it for later use
|
|
|
|
* @udev: the device whose string descriptor is being read
|
|
|
|
* @index: the descriptor index
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: A pointer to a kmalloc'ed buffer containing the descriptor string,
|
|
|
|
* or %NULL if the index is 0 or the string could not be read.
|
2005-10-25 03:24:14 +07:00
|
|
|
*/
|
|
|
|
char *usb_cache_string(struct usb_device *udev, int index)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
char *smallbuf = NULL;
|
|
|
|
int len;
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
if (index <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
2010-01-12 18:32:50 +07:00
|
|
|
buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
|
2008-01-31 06:21:33 +07:00
|
|
|
if (buf) {
|
2009-04-24 15:12:18 +07:00
|
|
|
len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
|
2008-01-31 06:21:33 +07:00
|
|
|
if (len > 0) {
|
2010-01-12 18:32:50 +07:00
|
|
|
smallbuf = kmalloc(++len, GFP_NOIO);
|
2008-01-31 06:21:33 +07:00
|
|
|
if (!smallbuf)
|
2005-10-25 03:24:14 +07:00
|
|
|
return buf;
|
|
|
|
memcpy(smallbuf, buf, len);
|
|
|
|
}
|
|
|
|
kfree(buf);
|
|
|
|
}
|
|
|
|
return smallbuf;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* usb_get_device_descriptor - (re)reads the device descriptor (usbcore)
|
|
|
|
* @dev: the device whose device descriptor is being updated
|
|
|
|
* @size: how much of the descriptor to read
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* Updates the copy of the device descriptor stored in the device structure,
|
2006-11-07 16:16:25 +07:00
|
|
|
* which dedicates space for this purpose.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Not exported, only for use by the core. If drivers really want to read
|
|
|
|
* the device descriptor directly, they can call usb_get_descriptor() with
|
|
|
|
* type = USB_DT_DEVICE and index = 0.
|
|
|
|
*
|
|
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: The number of bytes received on success, or else the status code
|
2005-04-17 05:20:36 +07:00
|
|
|
* returned by the underlying usb_control_msg() call.
|
|
|
|
*/
|
|
|
|
int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
|
|
|
|
{
|
|
|
|
struct usb_device_descriptor *desc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (size > sizeof(*desc))
|
|
|
|
return -EINVAL;
|
|
|
|
desc = kmalloc(sizeof(*desc), GFP_NOIO);
|
|
|
|
if (!desc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size);
|
2008-01-31 06:21:33 +07:00
|
|
|
if (ret >= 0)
|
2005-04-17 05:20:36 +07:00
|
|
|
memcpy(&dev->descriptor, desc, size);
|
|
|
|
kfree(desc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_get_status - issues a GET_STATUS call
|
|
|
|
* @dev: the device whose status is being checked
|
|
|
|
* @type: USB_RECIP_*; for device, interface, or endpoint
|
|
|
|
* @target: zero (for device), else interface or endpoint number
|
|
|
|
* @data: pointer to two bytes of bitmap data
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* Returns device, interface, or endpoint status. Normally only of
|
|
|
|
* interest to see if the device is self powered, or has enabled the
|
|
|
|
* remote wakeup facility; or whether a bulk or interrupt endpoint
|
|
|
|
* is halted ("stalled").
|
|
|
|
*
|
|
|
|
* Bits in these status bitmaps are set using the SET_FEATURE request,
|
|
|
|
* and cleared using the CLEAR_FEATURE request. The usb_clear_halt()
|
|
|
|
* function should be used to clear halt ("stall") status.
|
|
|
|
*
|
|
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
|
|
*
|
2013-07-31 02:35:40 +07:00
|
|
|
* Returns 0 and the status value in *@data (in host byte order) on success,
|
|
|
|
* or else the status code from the underlying usb_control_msg() call.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
int usb_get_status(struct usb_device *dev, int type, int target, void *data)
|
|
|
|
{
|
|
|
|
int ret;
|
2013-07-31 02:35:40 +07:00
|
|
|
__le16 *status = kmalloc(sizeof(*status), GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (!status)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
|
|
|
USB_REQ_GET_STATUS, USB_DIR_IN | type, 0, target, status,
|
|
|
|
sizeof(*status), USB_CTRL_GET_TIMEOUT);
|
|
|
|
|
2013-07-31 02:35:40 +07:00
|
|
|
if (ret == 2) {
|
|
|
|
*(u16 *) data = le16_to_cpu(*status);
|
|
|
|
ret = 0;
|
|
|
|
} else if (ret >= 0) {
|
|
|
|
ret = -EIO;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
kfree(status);
|
|
|
|
return ret;
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_get_status);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_clear_halt - tells device to clear endpoint halt/stall condition
|
|
|
|
* @dev: device whose endpoint is halted
|
|
|
|
* @pipe: endpoint "pipe" being cleared
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* This is used to clear halt conditions for bulk and interrupt endpoints,
|
|
|
|
* as reported by URB completion status. Endpoints that are halted are
|
|
|
|
* sometimes referred to as being "stalled". Such endpoints are unable
|
|
|
|
* to transmit or receive data until the halt status is cleared. Any URBs
|
|
|
|
* queued for such an endpoint should normally be unlinked by the driver
|
|
|
|
* before clearing the halt condition, as described in sections 5.7.5
|
|
|
|
* and 5.8.5 of the USB 2.0 spec.
|
|
|
|
*
|
|
|
|
* Note that control and isochronous endpoints don't halt, although control
|
|
|
|
* endpoints report "protocol stall" (for unsupported requests) using the
|
|
|
|
* same status code used to report a true stall.
|
|
|
|
*
|
|
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: Zero on success, or else the status code returned by the
|
2005-04-17 05:20:36 +07:00
|
|
|
* underlying usb_control_msg() call.
|
|
|
|
*/
|
|
|
|
int usb_clear_halt(struct usb_device *dev, int pipe)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
int endp = usb_pipeendpoint(pipe);
|
2008-01-31 06:21:33 +07:00
|
|
|
|
|
|
|
if (usb_pipein(pipe))
|
2005-04-17 05:20:36 +07:00
|
|
|
endp |= USB_DIR_IN;
|
|
|
|
|
|
|
|
/* we don't care if it wasn't halted first. in fact some devices
|
|
|
|
* (like some ibmcam model 1 units) seem to expect hosts to make
|
|
|
|
* this request for iso endpoints, which can't halt!
|
|
|
|
*/
|
|
|
|
result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
|
|
|
USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT,
|
|
|
|
USB_ENDPOINT_HALT, endp, NULL, 0,
|
|
|
|
USB_CTRL_SET_TIMEOUT);
|
|
|
|
|
|
|
|
/* don't un-halt or force to DATA0 except on success */
|
|
|
|
if (result < 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* NOTE: seems like Microsoft and Apple don't bother verifying
|
|
|
|
* the clear "took", so some devices could lock up if you check...
|
|
|
|
* such as the Hagiwara FlashGate DUAL. So we won't bother.
|
|
|
|
*
|
|
|
|
* NOTE: make sure the logic here doesn't diverge much from
|
|
|
|
* the copy in usb-storage, for as long as we need two copies.
|
|
|
|
*/
|
|
|
|
|
2009-04-09 00:36:28 +07:00
|
|
|
usb_reset_endpoint(dev, endp);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_clear_halt);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-12-06 02:10:34 +07:00
|
|
|
static int create_intf_ep_devs(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct usb_device *udev = interface_to_usbdev(intf);
|
|
|
|
struct usb_host_interface *alt = intf->cur_altsetting;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (intf->ep_devs_created || intf->unregistering)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; ++i)
|
|
|
|
(void) usb_create_ep_devs(&intf->dev, &alt->endpoint[i], udev);
|
|
|
|
intf->ep_devs_created = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_intf_ep_devs(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct usb_host_interface *alt = intf->cur_altsetting;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!intf->ep_devs_created)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; ++i)
|
|
|
|
usb_remove_ep_devs(&alt->endpoint[i]);
|
|
|
|
intf->ep_devs_created = 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* usb_disable_endpoint -- Disable an endpoint by address
|
|
|
|
* @dev: the device whose endpoint is being disabled
|
|
|
|
* @epaddr: the endpoint's address. Endpoint number for output,
|
|
|
|
* endpoint number + USB_DIR_IN for input
|
2009-01-16 05:03:33 +07:00
|
|
|
* @reset_hardware: flag to erase any endpoint state stored in the
|
|
|
|
* controller hardware
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2009-01-16 05:03:33 +07:00
|
|
|
* Disables the endpoint for URB submission and nukes all pending URBs.
|
|
|
|
* If @reset_hardware is set then also deallocates hcd/hardware state
|
|
|
|
* for the endpoint.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2009-01-16 05:03:33 +07:00
|
|
|
void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
|
|
|
|
bool reset_hardware)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
unsigned int epnum = epaddr & USB_ENDPOINT_NUMBER_MASK;
|
|
|
|
struct usb_host_endpoint *ep;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (usb_endpoint_out(epaddr)) {
|
|
|
|
ep = dev->ep_out[epnum];
|
2009-01-16 05:03:33 +07:00
|
|
|
if (reset_hardware)
|
|
|
|
dev->ep_out[epnum] = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
} else {
|
|
|
|
ep = dev->ep_in[epnum];
|
2009-01-16 05:03:33 +07:00
|
|
|
if (reset_hardware)
|
|
|
|
dev->ep_in[epnum] = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2007-07-31 04:05:22 +07:00
|
|
|
if (ep) {
|
|
|
|
ep->enabled = 0;
|
2007-09-10 22:33:05 +07:00
|
|
|
usb_hcd_flush_endpoint(dev, ep);
|
2009-01-16 05:03:33 +07:00
|
|
|
if (reset_hardware)
|
|
|
|
usb_hcd_disable_endpoint(dev, ep);
|
2007-07-31 04:05:22 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2009-04-09 00:36:28 +07:00
|
|
|
/**
|
|
|
|
* usb_reset_endpoint - Reset an endpoint's state.
|
|
|
|
* @dev: the device whose endpoint is to be reset
|
|
|
|
* @epaddr: the endpoint's address. Endpoint number for output,
|
|
|
|
* endpoint number + USB_DIR_IN for input
|
|
|
|
*
|
|
|
|
* Resets any host-side endpoint state such as the toggle bit,
|
|
|
|
* sequence number or current window.
|
|
|
|
*/
|
|
|
|
void usb_reset_endpoint(struct usb_device *dev, unsigned int epaddr)
|
|
|
|
{
|
|
|
|
unsigned int epnum = epaddr & USB_ENDPOINT_NUMBER_MASK;
|
|
|
|
struct usb_host_endpoint *ep;
|
|
|
|
|
|
|
|
if (usb_endpoint_out(epaddr))
|
|
|
|
ep = dev->ep_out[epnum];
|
|
|
|
else
|
|
|
|
ep = dev->ep_in[epnum];
|
|
|
|
if (ep)
|
|
|
|
usb_hcd_reset_endpoint(dev, ep);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usb_reset_endpoint);
|
|
|
|
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* usb_disable_interface -- Disable all endpoints for an interface
|
|
|
|
* @dev: the device whose interface is being disabled
|
|
|
|
* @intf: pointer to the interface descriptor
|
2009-01-16 05:03:33 +07:00
|
|
|
* @reset_hardware: flag to erase any endpoint state stored in the
|
|
|
|
* controller hardware
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Disables all the endpoints for the interface's current altsetting.
|
|
|
|
*/
|
2009-01-16 05:03:33 +07:00
|
|
|
void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf,
|
|
|
|
bool reset_hardware)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct usb_host_interface *alt = intf->cur_altsetting;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; ++i) {
|
|
|
|
usb_disable_endpoint(dev,
|
2009-01-16 05:03:33 +07:00
|
|
|
alt->endpoint[i].desc.bEndpointAddress,
|
|
|
|
reset_hardware);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
/**
|
2005-04-17 05:20:36 +07:00
|
|
|
* usb_disable_device - Disable all the endpoints for a USB device
|
|
|
|
* @dev: the device whose endpoints are being disabled
|
|
|
|
* @skip_ep0: 0 to disable endpoint 0, 1 to skip it.
|
|
|
|
*
|
|
|
|
* Disables all the device's endpoints, potentially including endpoint 0.
|
|
|
|
* Deallocates hcd/hardware state for the endpoints (nuking all or most
|
|
|
|
* pending urbs) and usbcore state for the interfaces, so that usbcore
|
|
|
|
* must usb_set_configuration() before any interfaces could be used.
|
|
|
|
*/
|
|
|
|
void usb_disable_device(struct usb_device *dev, int skip_ep0)
|
|
|
|
{
|
|
|
|
int i;
|
USB: Free bandwidth when usb_disable_device is called.
Tanya ran into an issue when trying to switch a UAS device from the BOT
configuration to the UAS configuration via the bConfigurationValue sysfs
file. Before installing the UAS configuration, set_bConfigurationValue()
calls usb_disable_device(). That function is supposed to remove all host
controller resources associated with that device, but it leaves some state
in the xHCI host controller.
Commit 0791971ba8fbc44e4f476079f856335ed45e6324
usb: allow drivers to use allocated bandwidth until unbound
added a call to usb_disable_device() in usb_set_configuration(), before
the xHCI bandwidth functions were invoked. That commit fixed a bug, but
also introduced a bug that is triggered when a configured device is
switched to a new configuration.
usb_disable_device() goes through all the motions of unbinding the drivers
attached to active interfaces and removing the USB core structures
associated with those interfaces, but it doesn't actually remove the
endpoints from the internal xHCI host controller bandwidth structures.
When usb_disable_device() calls usb_disable_endpoint() with reset_hardware
set to true, the entries in udev->ep_out and udev->ep_in will be set to
NULL. Usually, when the USB core installs a new configuration,
usb_hcd_alloc_bandwidth() will drop all non-NULL endpoints in udev->ep_out
and udev->ep_in before adding any new endpoints. However, when the new
UAS configuration was added, all those entries were null, so none of the
old endpoints in the BOT configuration were dropped.
The xHCI driver blindly added the UAS configuration endpoints, and some of
the endpoint addresses overlapped with the old BOT configuration
endpoints. This caused the xHCI host to reject the Configure Endpoint
command. Now that the xHCI driver code is cleaned up to reject a
double-add of active endpoints, we need to fix the USB core to properly
drop old endpoints in usb_disable_device().
If the host controller driver needs bandwidth checking support, make
usb_disable_device() call usb_disable_endpoint() with
reset_hardware set to false, drop the endpoints from the xHCI host
controller, and then call usb_disable_endpoint() again with
reset_hardware set to true.
The first call to usb_disable_endpoint() will cancel any pending URBs and
wait on them to be freed in usb_hcd_disable_endpoint(), but will keep the
pointers in udev->ep_out and udev->ep in intact. Then
usb_hcd_alloc_bandwidth() will use those pointers to know which endpoints
to drop.
The final call to usb_disable_endpoint() will do two things:
1. It will call usb_hcd_disable_endpoint() again, which should be harmless
since the ep->urb_list should be empty after the first call to
usb_disable_endpoint() returns.
2. It will set the entries in udev->ep_out and udev->ep in to NULL, and call
usb_hcd_disable_endpoint(). That call will have no effect, since the xHCI
driver doesn't set the endpoint_disable function pointer.
Note that usb_disable_device() will now need to be called with
hcd->bandwidth_mutex held.
This should be backported to kernels as old as 2.6.32.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Reported-by: Tanya Brokhman <tlinder@codeaurora.org>
Cc: ablay@codeaurora.org
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: stable@kernel.org
2011-06-06 13:22:22 +07:00
|
|
|
struct usb_hcd *hcd = bus_to_hcd(dev->bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* getting rid of interfaces will disconnect
|
|
|
|
* any drivers bound to them (a key side effect)
|
|
|
|
*/
|
|
|
|
if (dev->actconfig) {
|
2011-07-07 04:03:45 +07:00
|
|
|
/*
|
|
|
|
* FIXME: In order to avoid self-deadlock involving the
|
|
|
|
* bandwidth_mutex, we have to mark all the interfaces
|
|
|
|
* before unregistering any of them.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
|
|
|
|
dev->actconfig->interface[i]->unregistering = 1;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
|
|
|
|
struct usb_interface *interface;
|
|
|
|
|
2005-07-30 02:17:16 +07:00
|
|
|
/* remove this interface if it has been registered */
|
2005-04-17 05:20:36 +07:00
|
|
|
interface = dev->actconfig->interface[i];
|
2005-09-22 14:47:24 +07:00
|
|
|
if (!device_is_registered(&interface->dev))
|
2005-07-30 02:17:16 +07:00
|
|
|
continue;
|
2008-01-31 06:21:33 +07:00
|
|
|
dev_dbg(&dev->dev, "unregistering interface %s\n",
|
2008-05-02 11:02:41 +07:00
|
|
|
dev_name(&interface->dev));
|
2008-12-06 02:10:34 +07:00
|
|
|
remove_intf_ep_devs(interface);
|
2008-07-30 22:31:50 +07:00
|
|
|
device_del(&interface->dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now that the interfaces are unbound, nobody should
|
|
|
|
* try to access them.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
|
2008-01-31 06:21:33 +07:00
|
|
|
put_device(&dev->actconfig->interface[i]->dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
dev->actconfig->interface[i] = NULL;
|
|
|
|
}
|
2013-10-08 22:28:43 +07:00
|
|
|
|
|
|
|
if (dev->usb2_hw_lpm_enabled == 1)
|
|
|
|
usb_set_usb2_hardware_lpm(dev, 0);
|
2012-07-06 04:09:30 +07:00
|
|
|
usb_unlocked_disable_lpm(dev);
|
2012-06-26 02:08:08 +07:00
|
|
|
usb_disable_ltm(dev);
|
2013-10-08 22:28:43 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
dev->actconfig = NULL;
|
|
|
|
if (dev->state == USB_STATE_CONFIGURED)
|
|
|
|
usb_set_device_state(dev, USB_STATE_ADDRESS);
|
|
|
|
}
|
2010-10-01 02:16:23 +07:00
|
|
|
|
|
|
|
dev_dbg(&dev->dev, "%s nuking %s URBs\n", __func__,
|
|
|
|
skip_ep0 ? "non-ep0" : "all");
|
USB: Free bandwidth when usb_disable_device is called.
Tanya ran into an issue when trying to switch a UAS device from the BOT
configuration to the UAS configuration via the bConfigurationValue sysfs
file. Before installing the UAS configuration, set_bConfigurationValue()
calls usb_disable_device(). That function is supposed to remove all host
controller resources associated with that device, but it leaves some state
in the xHCI host controller.
Commit 0791971ba8fbc44e4f476079f856335ed45e6324
usb: allow drivers to use allocated bandwidth until unbound
added a call to usb_disable_device() in usb_set_configuration(), before
the xHCI bandwidth functions were invoked. That commit fixed a bug, but
also introduced a bug that is triggered when a configured device is
switched to a new configuration.
usb_disable_device() goes through all the motions of unbinding the drivers
attached to active interfaces and removing the USB core structures
associated with those interfaces, but it doesn't actually remove the
endpoints from the internal xHCI host controller bandwidth structures.
When usb_disable_device() calls usb_disable_endpoint() with reset_hardware
set to true, the entries in udev->ep_out and udev->ep_in will be set to
NULL. Usually, when the USB core installs a new configuration,
usb_hcd_alloc_bandwidth() will drop all non-NULL endpoints in udev->ep_out
and udev->ep_in before adding any new endpoints. However, when the new
UAS configuration was added, all those entries were null, so none of the
old endpoints in the BOT configuration were dropped.
The xHCI driver blindly added the UAS configuration endpoints, and some of
the endpoint addresses overlapped with the old BOT configuration
endpoints. This caused the xHCI host to reject the Configure Endpoint
command. Now that the xHCI driver code is cleaned up to reject a
double-add of active endpoints, we need to fix the USB core to properly
drop old endpoints in usb_disable_device().
If the host controller driver needs bandwidth checking support, make
usb_disable_device() call usb_disable_endpoint() with
reset_hardware set to false, drop the endpoints from the xHCI host
controller, and then call usb_disable_endpoint() again with
reset_hardware set to true.
The first call to usb_disable_endpoint() will cancel any pending URBs and
wait on them to be freed in usb_hcd_disable_endpoint(), but will keep the
pointers in udev->ep_out and udev->ep in intact. Then
usb_hcd_alloc_bandwidth() will use those pointers to know which endpoints
to drop.
The final call to usb_disable_endpoint() will do two things:
1. It will call usb_hcd_disable_endpoint() again, which should be harmless
since the ep->urb_list should be empty after the first call to
usb_disable_endpoint() returns.
2. It will set the entries in udev->ep_out and udev->ep in to NULL, and call
usb_hcd_disable_endpoint(). That call will have no effect, since the xHCI
driver doesn't set the endpoint_disable function pointer.
Note that usb_disable_device() will now need to be called with
hcd->bandwidth_mutex held.
This should be backported to kernels as old as 2.6.32.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Reported-by: Tanya Brokhman <tlinder@codeaurora.org>
Cc: ablay@codeaurora.org
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: stable@kernel.org
2011-06-06 13:22:22 +07:00
|
|
|
if (hcd->driver->check_bandwidth) {
|
|
|
|
/* First pass: Cancel URBs, leave endpoint pointers intact. */
|
|
|
|
for (i = skip_ep0; i < 16; ++i) {
|
|
|
|
usb_disable_endpoint(dev, i, false);
|
|
|
|
usb_disable_endpoint(dev, i + USB_DIR_IN, false);
|
|
|
|
}
|
|
|
|
/* Remove endpoints from the host controller internal state */
|
2012-04-18 02:22:39 +07:00
|
|
|
mutex_lock(hcd->bandwidth_mutex);
|
USB: Free bandwidth when usb_disable_device is called.
Tanya ran into an issue when trying to switch a UAS device from the BOT
configuration to the UAS configuration via the bConfigurationValue sysfs
file. Before installing the UAS configuration, set_bConfigurationValue()
calls usb_disable_device(). That function is supposed to remove all host
controller resources associated with that device, but it leaves some state
in the xHCI host controller.
Commit 0791971ba8fbc44e4f476079f856335ed45e6324
usb: allow drivers to use allocated bandwidth until unbound
added a call to usb_disable_device() in usb_set_configuration(), before
the xHCI bandwidth functions were invoked. That commit fixed a bug, but
also introduced a bug that is triggered when a configured device is
switched to a new configuration.
usb_disable_device() goes through all the motions of unbinding the drivers
attached to active interfaces and removing the USB core structures
associated with those interfaces, but it doesn't actually remove the
endpoints from the internal xHCI host controller bandwidth structures.
When usb_disable_device() calls usb_disable_endpoint() with reset_hardware
set to true, the entries in udev->ep_out and udev->ep_in will be set to
NULL. Usually, when the USB core installs a new configuration,
usb_hcd_alloc_bandwidth() will drop all non-NULL endpoints in udev->ep_out
and udev->ep_in before adding any new endpoints. However, when the new
UAS configuration was added, all those entries were null, so none of the
old endpoints in the BOT configuration were dropped.
The xHCI driver blindly added the UAS configuration endpoints, and some of
the endpoint addresses overlapped with the old BOT configuration
endpoints. This caused the xHCI host to reject the Configure Endpoint
command. Now that the xHCI driver code is cleaned up to reject a
double-add of active endpoints, we need to fix the USB core to properly
drop old endpoints in usb_disable_device().
If the host controller driver needs bandwidth checking support, make
usb_disable_device() call usb_disable_endpoint() with
reset_hardware set to false, drop the endpoints from the xHCI host
controller, and then call usb_disable_endpoint() again with
reset_hardware set to true.
The first call to usb_disable_endpoint() will cancel any pending URBs and
wait on them to be freed in usb_hcd_disable_endpoint(), but will keep the
pointers in udev->ep_out and udev->ep in intact. Then
usb_hcd_alloc_bandwidth() will use those pointers to know which endpoints
to drop.
The final call to usb_disable_endpoint() will do two things:
1. It will call usb_hcd_disable_endpoint() again, which should be harmless
since the ep->urb_list should be empty after the first call to
usb_disable_endpoint() returns.
2. It will set the entries in udev->ep_out and udev->ep in to NULL, and call
usb_hcd_disable_endpoint(). That call will have no effect, since the xHCI
driver doesn't set the endpoint_disable function pointer.
Note that usb_disable_device() will now need to be called with
hcd->bandwidth_mutex held.
This should be backported to kernels as old as 2.6.32.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Reported-by: Tanya Brokhman <tlinder@codeaurora.org>
Cc: ablay@codeaurora.org
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: stable@kernel.org
2011-06-06 13:22:22 +07:00
|
|
|
usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
|
2012-04-18 02:22:39 +07:00
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
USB: Free bandwidth when usb_disable_device is called.
Tanya ran into an issue when trying to switch a UAS device from the BOT
configuration to the UAS configuration via the bConfigurationValue sysfs
file. Before installing the UAS configuration, set_bConfigurationValue()
calls usb_disable_device(). That function is supposed to remove all host
controller resources associated with that device, but it leaves some state
in the xHCI host controller.
Commit 0791971ba8fbc44e4f476079f856335ed45e6324
usb: allow drivers to use allocated bandwidth until unbound
added a call to usb_disable_device() in usb_set_configuration(), before
the xHCI bandwidth functions were invoked. That commit fixed a bug, but
also introduced a bug that is triggered when a configured device is
switched to a new configuration.
usb_disable_device() goes through all the motions of unbinding the drivers
attached to active interfaces and removing the USB core structures
associated with those interfaces, but it doesn't actually remove the
endpoints from the internal xHCI host controller bandwidth structures.
When usb_disable_device() calls usb_disable_endpoint() with reset_hardware
set to true, the entries in udev->ep_out and udev->ep_in will be set to
NULL. Usually, when the USB core installs a new configuration,
usb_hcd_alloc_bandwidth() will drop all non-NULL endpoints in udev->ep_out
and udev->ep_in before adding any new endpoints. However, when the new
UAS configuration was added, all those entries were null, so none of the
old endpoints in the BOT configuration were dropped.
The xHCI driver blindly added the UAS configuration endpoints, and some of
the endpoint addresses overlapped with the old BOT configuration
endpoints. This caused the xHCI host to reject the Configure Endpoint
command. Now that the xHCI driver code is cleaned up to reject a
double-add of active endpoints, we need to fix the USB core to properly
drop old endpoints in usb_disable_device().
If the host controller driver needs bandwidth checking support, make
usb_disable_device() call usb_disable_endpoint() with
reset_hardware set to false, drop the endpoints from the xHCI host
controller, and then call usb_disable_endpoint() again with
reset_hardware set to true.
The first call to usb_disable_endpoint() will cancel any pending URBs and
wait on them to be freed in usb_hcd_disable_endpoint(), but will keep the
pointers in udev->ep_out and udev->ep in intact. Then
usb_hcd_alloc_bandwidth() will use those pointers to know which endpoints
to drop.
The final call to usb_disable_endpoint() will do two things:
1. It will call usb_hcd_disable_endpoint() again, which should be harmless
since the ep->urb_list should be empty after the first call to
usb_disable_endpoint() returns.
2. It will set the entries in udev->ep_out and udev->ep in to NULL, and call
usb_hcd_disable_endpoint(). That call will have no effect, since the xHCI
driver doesn't set the endpoint_disable function pointer.
Note that usb_disable_device() will now need to be called with
hcd->bandwidth_mutex held.
This should be backported to kernels as old as 2.6.32.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Reported-by: Tanya Brokhman <tlinder@codeaurora.org>
Cc: ablay@codeaurora.org
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: stable@kernel.org
2011-06-06 13:22:22 +07:00
|
|
|
/* Second pass: remove endpoint pointers */
|
|
|
|
}
|
2010-10-01 02:16:23 +07:00
|
|
|
for (i = skip_ep0; i < 16; ++i) {
|
|
|
|
usb_disable_endpoint(dev, i, true);
|
|
|
|
usb_disable_endpoint(dev, i + USB_DIR_IN, true);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
/**
|
2005-04-17 05:20:36 +07:00
|
|
|
* usb_enable_endpoint - Enable an endpoint for USB communications
|
|
|
|
* @dev: the device whose interface is being enabled
|
|
|
|
* @ep: the endpoint
|
2009-04-09 00:36:28 +07:00
|
|
|
* @reset_ep: flag to reset the endpoint state
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2009-04-09 00:36:28 +07:00
|
|
|
* Resets the endpoint state if asked, and sets dev->ep_{in,out} pointers.
|
2005-04-17 05:20:36 +07:00
|
|
|
* For control endpoints, both the input and output sides are handled.
|
|
|
|
*/
|
2008-12-31 23:31:33 +07:00
|
|
|
void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep,
|
2009-04-09 00:36:28 +07:00
|
|
|
bool reset_ep)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2007-07-31 04:05:22 +07:00
|
|
|
int epnum = usb_endpoint_num(&ep->desc);
|
|
|
|
int is_out = usb_endpoint_dir_out(&ep->desc);
|
|
|
|
int is_control = usb_endpoint_xfer_control(&ep->desc);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-04-09 00:36:28 +07:00
|
|
|
if (reset_ep)
|
|
|
|
usb_hcd_reset_endpoint(dev, ep);
|
|
|
|
if (is_out || is_control)
|
2005-04-17 05:20:36 +07:00
|
|
|
dev->ep_out[epnum] = ep;
|
2009-04-09 00:36:28 +07:00
|
|
|
if (!is_out || is_control)
|
2005-04-17 05:20:36 +07:00
|
|
|
dev->ep_in[epnum] = ep;
|
2007-07-31 04:05:22 +07:00
|
|
|
ep->enabled = 1;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
/**
|
2005-04-17 05:20:36 +07:00
|
|
|
* usb_enable_interface - Enable all the endpoints for an interface
|
|
|
|
* @dev: the device whose interface is being enabled
|
|
|
|
* @intf: pointer to the interface descriptor
|
2009-04-09 00:36:28 +07:00
|
|
|
* @reset_eps: flag to reset the endpoints' state
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Enables all the endpoints for the interface's current altsetting.
|
|
|
|
*/
|
2008-12-31 23:31:33 +07:00
|
|
|
void usb_enable_interface(struct usb_device *dev,
|
2009-04-09 00:36:28 +07:00
|
|
|
struct usb_interface *intf, bool reset_eps)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct usb_host_interface *alt = intf->cur_altsetting;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; ++i)
|
2009-04-09 00:36:28 +07:00
|
|
|
usb_enable_endpoint(dev, &alt->endpoint[i], reset_eps);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_set_interface - Makes a particular alternate setting be current
|
|
|
|
* @dev: the device whose interface is being updated
|
|
|
|
* @interface: the interface being updated
|
|
|
|
* @alternate: the setting being chosen.
|
|
|
|
* Context: !in_interrupt ()
|
|
|
|
*
|
|
|
|
* This is used to enable data transfers on interfaces that may not
|
|
|
|
* be enabled by default. Not all devices support such configurability.
|
|
|
|
* Only the driver bound to an interface may change its setting.
|
|
|
|
*
|
|
|
|
* Within any given configuration, each interface may have several
|
|
|
|
* alternative settings. These are often used to control levels of
|
|
|
|
* bandwidth consumption. For example, the default setting for a high
|
|
|
|
* speed interrupt endpoint may not send more than 64 bytes per microframe,
|
|
|
|
* while interrupt transfers of up to 3KBytes per microframe are legal.
|
|
|
|
* Also, isochronous endpoints may never be part of an
|
|
|
|
* interface's default setting. To access such bandwidth, alternate
|
|
|
|
* interface settings must be made current.
|
|
|
|
*
|
|
|
|
* Note that in the Linux USB subsystem, bandwidth associated with
|
|
|
|
* an endpoint in a given alternate setting is not reserved until an URB
|
|
|
|
* is submitted that needs that bandwidth. Some other operating systems
|
|
|
|
* allocate bandwidth early, when a configuration is chosen.
|
|
|
|
*
|
|
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
|
|
* Also, drivers must not change altsettings while urbs are scheduled for
|
|
|
|
* endpoints in that interface; all such urbs must first be completed
|
|
|
|
* (perhaps forced by unlinking).
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: Zero on success, or else the status code returned by the
|
2005-04-17 05:20:36 +07:00
|
|
|
* underlying usb_control_msg() call.
|
|
|
|
*/
|
|
|
|
int usb_set_interface(struct usb_device *dev, int interface, int alternate)
|
|
|
|
{
|
|
|
|
struct usb_interface *iface;
|
|
|
|
struct usb_host_interface *alt;
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
struct usb_hcd *hcd = bus_to_hcd(dev->bus);
|
2013-11-08 22:37:26 +07:00
|
|
|
int i, ret, manual = 0;
|
2008-01-31 06:21:33 +07:00
|
|
|
unsigned int epaddr;
|
|
|
|
unsigned int pipe;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (dev->state == USB_STATE_SUSPENDED)
|
|
|
|
return -EHOSTUNREACH;
|
|
|
|
|
|
|
|
iface = usb_ifnum_to_if(dev, interface);
|
|
|
|
if (!iface) {
|
|
|
|
dev_dbg(&dev->dev, "selecting invalid interface %d\n",
|
|
|
|
interface);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-07-02 03:43:02 +07:00
|
|
|
if (iface->unregistering)
|
|
|
|
return -ENODEV;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
alt = usb_altnum_to_altsetting(iface, alternate);
|
|
|
|
if (!alt) {
|
2010-01-18 04:24:03 +07:00
|
|
|
dev_warn(&dev->dev, "selecting invalid altsetting %d\n",
|
2008-08-14 23:37:34 +07:00
|
|
|
alternate);
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
/* Make sure we have enough bandwidth for this alternate interface.
|
|
|
|
* Remove the current alt setting and add the new alt setting.
|
|
|
|
*/
|
2010-10-15 22:55:24 +07:00
|
|
|
mutex_lock(hcd->bandwidth_mutex);
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
/* Disable LPM, and re-enable it once the new alt setting is installed,
|
|
|
|
* so that the xHCI driver can recalculate the U1/U2 timeouts.
|
|
|
|
*/
|
|
|
|
if (usb_disable_lpm(dev)) {
|
|
|
|
dev_err(&iface->dev, "%s Failed to disable LPM\n.", __func__);
|
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2013-11-08 22:37:26 +07:00
|
|
|
/* Changing alt-setting also frees any allocated streams */
|
|
|
|
for (i = 0; i < iface->cur_altsetting->desc.bNumEndpoints; i++)
|
|
|
|
iface->cur_altsetting->endpoint[i].streams = 0;
|
|
|
|
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n",
|
|
|
|
alternate);
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
usb_enable_lpm(dev);
|
2010-10-15 22:55:24 +07:00
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-03-11 21:20:12 +07:00
|
|
|
if (dev->quirks & USB_QUIRK_NO_SET_INTF)
|
|
|
|
ret = -EPIPE;
|
|
|
|
else
|
|
|
|
ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
2005-04-17 05:20:36 +07:00
|
|
|
USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
|
|
|
|
alternate, interface, NULL, 0, 5000);
|
|
|
|
|
|
|
|
/* 9.4.10 says devices don't need this and are free to STALL the
|
|
|
|
* request if the interface only has one alternate setting.
|
|
|
|
*/
|
|
|
|
if (ret == -EPIPE && iface->num_altsetting == 1) {
|
|
|
|
dev_dbg(&dev->dev,
|
|
|
|
"manual set_interface for iface %d, alt %d\n",
|
|
|
|
interface, alternate);
|
|
|
|
manual = 1;
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
} else if (ret < 0) {
|
|
|
|
/* Re-instate the old alt setting */
|
|
|
|
usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting);
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
usb_enable_lpm(dev);
|
2010-10-15 22:55:24 +07:00
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
return ret;
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
}
|
2010-10-15 22:55:24 +07:00
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* FIXME drivers shouldn't need to replicate/bugfix the logic here
|
|
|
|
* when they implement async or easily-killable versions of this or
|
|
|
|
* other "should-be-internal" functions (like clear_halt).
|
|
|
|
* should hcd+usbcore postprocess control requests?
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* prevent submissions using previous endpoint settings */
|
2008-12-06 02:10:34 +07:00
|
|
|
if (iface->cur_altsetting != alt) {
|
|
|
|
remove_intf_ep_devs(iface);
|
2005-10-25 02:33:03 +07:00
|
|
|
usb_remove_sysfs_intf_files(iface);
|
2008-12-06 02:10:34 +07:00
|
|
|
}
|
2009-01-16 05:03:33 +07:00
|
|
|
usb_disable_interface(dev, iface, true);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
iface->cur_altsetting = alt;
|
|
|
|
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
/* Now that the interface is installed, re-enable LPM. */
|
|
|
|
usb_unlocked_enable_lpm(dev);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* If the interface only has one altsetting and the device didn't
|
2005-04-19 07:39:25 +07:00
|
|
|
* accept the request, we attempt to carry out the equivalent action
|
2005-04-17 05:20:36 +07:00
|
|
|
* by manually clearing the HALT feature for each endpoint in the
|
|
|
|
* new altsetting.
|
|
|
|
*/
|
|
|
|
if (manual) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; i++) {
|
2008-01-31 06:21:33 +07:00
|
|
|
epaddr = alt->endpoint[i].desc.bEndpointAddress;
|
|
|
|
pipe = __create_pipe(dev,
|
|
|
|
USB_ENDPOINT_NUMBER_MASK & epaddr) |
|
|
|
|
(usb_endpoint_out(epaddr) ?
|
|
|
|
USB_DIR_OUT : USB_DIR_IN);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
usb_clear_halt(dev, pipe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 9.1.1.5: reset toggles for all endpoints in the new altsetting
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* Despite EP0 is always present in all interfaces/AS, the list of
|
|
|
|
* endpoints from the descriptor does not contain EP0. Due to its
|
|
|
|
* omnipresence one might expect EP0 being considered "affected" by
|
|
|
|
* any SetInterface request and hence assume toggles need to be reset.
|
|
|
|
* However, EP0 toggles are re-synced for every individual transfer
|
|
|
|
* during the SETUP stage - hence EP0 toggles are "don't care" here.
|
|
|
|
* (Likewise, EP0 never "halts" on well designed devices.)
|
|
|
|
*/
|
2008-12-31 23:31:33 +07:00
|
|
|
usb_enable_interface(dev, iface, true);
|
2008-12-06 02:10:34 +07:00
|
|
|
if (device_is_registered(&iface->dev)) {
|
2005-10-25 02:33:03 +07:00
|
|
|
usb_create_sysfs_intf_files(iface);
|
2008-12-06 02:10:34 +07:00
|
|
|
create_intf_ep_devs(iface);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_set_interface);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* usb_reset_configuration - lightweight device reset
|
|
|
|
* @dev: the device whose configuration is being reset
|
|
|
|
*
|
|
|
|
* This issues a standard SET_CONFIGURATION request to the device using
|
|
|
|
* the current configuration. The effect is to reset most USB-related
|
|
|
|
* state in the device, including interface altsettings (reset to zero),
|
2009-04-09 00:36:28 +07:00
|
|
|
* endpoint halts (cleared), and endpoint state (only for bulk and interrupt
|
2005-04-17 05:20:36 +07:00
|
|
|
* endpoints). Other usbcore state is unchanged, including bindings of
|
|
|
|
* usb device drivers to interfaces.
|
|
|
|
*
|
|
|
|
* Because this affects multiple interfaces, avoid using this with composite
|
|
|
|
* (multi-interface) devices. Instead, the driver for each interface may
|
2005-04-19 07:39:25 +07:00
|
|
|
* use usb_set_interface() on the interfaces it claims. Be careful though;
|
|
|
|
* some devices don't support the SET_INTERFACE request, and others won't
|
2009-04-09 00:36:28 +07:00
|
|
|
* reset all the interface state (notably endpoint state). Resetting the whole
|
2005-04-17 05:20:36 +07:00
|
|
|
* configuration would affect other drivers' interfaces.
|
|
|
|
*
|
|
|
|
* The caller must own the device lock.
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: Zero on success, else a negative error code.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
int usb_reset_configuration(struct usb_device *dev)
|
|
|
|
{
|
|
|
|
int i, retval;
|
|
|
|
struct usb_host_config *config;
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
struct usb_hcd *hcd = bus_to_hcd(dev->bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (dev->state == USB_STATE_SUSPENDED)
|
|
|
|
return -EHOSTUNREACH;
|
|
|
|
|
|
|
|
/* caller must have locked the device and must own
|
|
|
|
* the usb bus readlock (so driver bindings are stable);
|
|
|
|
* calls during probe() are fine
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 1; i < 16; ++i) {
|
2009-01-16 05:03:33 +07:00
|
|
|
usb_disable_endpoint(dev, i, true);
|
|
|
|
usb_disable_endpoint(dev, i + USB_DIR_IN, true);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
config = dev->actconfig;
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
retval = 0;
|
2010-10-15 22:55:24 +07:00
|
|
|
mutex_lock(hcd->bandwidth_mutex);
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
/* Disable LPM, and re-enable it once the configuration is reset, so
|
|
|
|
* that the xHCI driver can recalculate the U1/U2 timeouts.
|
|
|
|
*/
|
|
|
|
if (usb_disable_lpm(dev)) {
|
|
|
|
dev_err(&dev->dev, "%s Failed to disable LPM\n.", __func__);
|
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
/* Make sure we have enough bandwidth for each alternate setting 0 */
|
|
|
|
for (i = 0; i < config->desc.bNumInterfaces; i++) {
|
|
|
|
struct usb_interface *intf = config->interface[i];
|
|
|
|
struct usb_host_interface *alt;
|
|
|
|
|
|
|
|
alt = usb_altnum_to_altsetting(intf, 0);
|
|
|
|
if (!alt)
|
|
|
|
alt = &intf->altsetting[0];
|
|
|
|
if (alt != intf->cur_altsetting)
|
|
|
|
retval = usb_hcd_alloc_bandwidth(dev, NULL,
|
|
|
|
intf->cur_altsetting, alt);
|
|
|
|
if (retval < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* If not, reinstate the old alternate settings */
|
|
|
|
if (retval < 0) {
|
|
|
|
reset_old_alts:
|
2010-02-18 08:36:23 +07:00
|
|
|
for (i--; i >= 0; i--) {
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
struct usb_interface *intf = config->interface[i];
|
|
|
|
struct usb_host_interface *alt;
|
|
|
|
|
|
|
|
alt = usb_altnum_to_altsetting(intf, 0);
|
|
|
|
if (!alt)
|
|
|
|
alt = &intf->altsetting[0];
|
|
|
|
if (alt != intf->cur_altsetting)
|
|
|
|
usb_hcd_alloc_bandwidth(dev, NULL,
|
|
|
|
alt, intf->cur_altsetting);
|
|
|
|
}
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
usb_enable_lpm(dev);
|
2010-10-15 22:55:24 +07:00
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
return retval;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
|
|
|
USB_REQ_SET_CONFIGURATION, 0,
|
|
|
|
config->desc.bConfigurationValue, 0,
|
|
|
|
NULL, 0, USB_CTRL_SET_TIMEOUT);
|
2005-10-25 02:33:03 +07:00
|
|
|
if (retval < 0)
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
goto reset_old_alts;
|
2010-10-15 22:55:24 +07:00
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* re-init hc/hcd interface/endpoint state */
|
|
|
|
for (i = 0; i < config->desc.bNumInterfaces; i++) {
|
|
|
|
struct usb_interface *intf = config->interface[i];
|
|
|
|
struct usb_host_interface *alt;
|
|
|
|
|
|
|
|
alt = usb_altnum_to_altsetting(intf, 0);
|
|
|
|
|
|
|
|
/* No altsetting 0? We'll assume the first altsetting.
|
|
|
|
* We could use a GetInterface call, but if a device is
|
|
|
|
* so non-compliant that it doesn't have altsetting 0
|
|
|
|
* then I wouldn't trust its reply anyway.
|
|
|
|
*/
|
|
|
|
if (!alt)
|
|
|
|
alt = &intf->altsetting[0];
|
|
|
|
|
2008-12-06 02:10:34 +07:00
|
|
|
if (alt != intf->cur_altsetting) {
|
|
|
|
remove_intf_ep_devs(intf);
|
|
|
|
usb_remove_sysfs_intf_files(intf);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
intf->cur_altsetting = alt;
|
2008-12-31 23:31:33 +07:00
|
|
|
usb_enable_interface(dev, intf, true);
|
2008-12-06 02:10:34 +07:00
|
|
|
if (device_is_registered(&intf->dev)) {
|
2005-10-25 02:33:03 +07:00
|
|
|
usb_create_sysfs_intf_files(intf);
|
2008-12-06 02:10:34 +07:00
|
|
|
create_intf_ep_devs(intf);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
/* Now that the interfaces are installed, re-enable LPM. */
|
|
|
|
usb_unlocked_enable_lpm(dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2008-01-26 00:12:21 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_reset_configuration);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-08-03 11:44:27 +07:00
|
|
|
static void usb_release_interface(struct device *dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
struct usb_interface *intf = to_usb_interface(dev);
|
|
|
|
struct usb_interface_cache *intfc =
|
|
|
|
altsetting_to_usb_interface_cache(intf->altsetting);
|
|
|
|
|
|
|
|
kref_put(&intfc->ref, usb_release_interface_cache);
|
2015-01-22 02:02:43 +07:00
|
|
|
usb_put_dev(interface_to_usbdev(intf));
|
2005-04-17 05:20:36 +07:00
|
|
|
kfree(intf);
|
|
|
|
}
|
|
|
|
|
2007-08-14 20:15:12 +07:00
|
|
|
static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
|
2007-03-13 21:59:31 +07:00
|
|
|
{
|
|
|
|
struct usb_device *usb_dev;
|
|
|
|
struct usb_interface *intf;
|
|
|
|
struct usb_host_interface *alt;
|
|
|
|
|
|
|
|
intf = to_usb_interface(dev);
|
|
|
|
usb_dev = interface_to_usbdev(intf);
|
|
|
|
alt = intf->cur_altsetting;
|
|
|
|
|
2007-08-14 20:15:12 +07:00
|
|
|
if (add_uevent_var(env, "INTERFACE=%d/%d/%d",
|
2007-03-13 21:59:31 +07:00
|
|
|
alt->desc.bInterfaceClass,
|
|
|
|
alt->desc.bInterfaceSubClass,
|
|
|
|
alt->desc.bInterfaceProtocol))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2007-08-14 20:15:12 +07:00
|
|
|
if (add_uevent_var(env,
|
2008-01-31 06:21:33 +07:00
|
|
|
"MODALIAS=usb:"
|
2012-05-19 02:27:43 +07:00
|
|
|
"v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02Xin%02X",
|
2007-03-13 21:59:31 +07:00
|
|
|
le16_to_cpu(usb_dev->descriptor.idVendor),
|
|
|
|
le16_to_cpu(usb_dev->descriptor.idProduct),
|
|
|
|
le16_to_cpu(usb_dev->descriptor.bcdDevice),
|
|
|
|
usb_dev->descriptor.bDeviceClass,
|
|
|
|
usb_dev->descriptor.bDeviceSubClass,
|
|
|
|
usb_dev->descriptor.bDeviceProtocol,
|
|
|
|
alt->desc.bInterfaceClass,
|
|
|
|
alt->desc.bInterfaceSubClass,
|
2012-05-19 02:27:43 +07:00
|
|
|
alt->desc.bInterfaceProtocol,
|
|
|
|
alt->desc.bInterfaceNumber))
|
2007-03-13 21:59:31 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct device_type usb_if_device_type = {
|
|
|
|
.name = "usb_interface",
|
|
|
|
.release = usb_release_interface,
|
|
|
|
.uevent = usb_if_uevent,
|
|
|
|
};
|
|
|
|
|
2007-06-16 10:14:35 +07:00
|
|
|
static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
|
2008-01-31 06:21:33 +07:00
|
|
|
struct usb_host_config *config,
|
|
|
|
u8 inum)
|
2007-06-16 10:14:35 +07:00
|
|
|
{
|
|
|
|
struct usb_interface_assoc_descriptor *retval = NULL;
|
|
|
|
struct usb_interface_assoc_descriptor *intf_assoc;
|
|
|
|
int first_intf;
|
|
|
|
int last_intf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; (i < USB_MAXIADS && config->intf_assoc[i]); i++) {
|
|
|
|
intf_assoc = config->intf_assoc[i];
|
|
|
|
if (intf_assoc->bInterfaceCount == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
first_intf = intf_assoc->bFirstInterface;
|
|
|
|
last_intf = first_intf + (intf_assoc->bInterfaceCount - 1);
|
|
|
|
if (inum >= first_intf && inum <= last_intf) {
|
|
|
|
if (!retval)
|
|
|
|
retval = intf_assoc;
|
|
|
|
else
|
|
|
|
dev_err(&dev->dev, "Interface #%d referenced"
|
|
|
|
" by multiple IADs\n", inum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-11-14 01:31:35 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal function to queue a device reset
|
|
|
|
* See usb_queue_reset_device() for more details
|
|
|
|
*/
|
2009-12-04 20:47:44 +07:00
|
|
|
static void __usb_queue_reset_device(struct work_struct *ws)
|
2008-11-14 01:31:35 +07:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct usb_interface *iface =
|
|
|
|
container_of(ws, struct usb_interface, reset_ws);
|
|
|
|
struct usb_device *udev = interface_to_usbdev(iface);
|
|
|
|
|
|
|
|
rc = usb_lock_device_for_reset(udev, iface);
|
|
|
|
if (rc >= 0) {
|
|
|
|
usb_reset_device(udev);
|
|
|
|
usb_unlock_device(udev);
|
|
|
|
}
|
2015-01-22 02:02:43 +07:00
|
|
|
usb_put_intf(iface); /* Undo _get_ in usb_queue_reset_device() */
|
2008-11-14 01:31:35 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* usb_set_configuration - Makes a particular device setting be current
|
|
|
|
* @dev: the device whose configuration is being updated
|
|
|
|
* @configuration: the configuration being chosen.
|
|
|
|
* Context: !in_interrupt(), caller owns the device lock
|
|
|
|
*
|
|
|
|
* This is used to enable non-default device modes. Not all devices
|
|
|
|
* use this kind of configurability; many devices only have one
|
|
|
|
* configuration.
|
|
|
|
*
|
2007-02-09 04:40:43 +07:00
|
|
|
* @configuration is the value of the configuration to be installed.
|
|
|
|
* According to the USB spec (e.g. section 9.1.1.5), configuration values
|
|
|
|
* must be non-zero; a value of zero indicates that the device in
|
|
|
|
* unconfigured. However some devices erroneously use 0 as one of their
|
|
|
|
* configuration values. To help manage such devices, this routine will
|
|
|
|
* accept @configuration = -1 as indicating the device should be put in
|
|
|
|
* an unconfigured state.
|
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* USB device configurations may affect Linux interoperability,
|
|
|
|
* power consumption and the functionality available. For example,
|
|
|
|
* the default configuration is limited to using 100mA of bus power,
|
|
|
|
* so that when certain device functionality requires more power,
|
|
|
|
* and the device is bus powered, that functionality should be in some
|
|
|
|
* non-default device configuration. Other device modes may also be
|
|
|
|
* reflected as configuration options, such as whether two ISDN
|
|
|
|
* channels are available independently; and choosing between open
|
|
|
|
* standard device protocols (like CDC) or proprietary ones.
|
|
|
|
*
|
2007-08-01 10:34:01 +07:00
|
|
|
* Note that a non-authorized device (dev->authorized == 0) will only
|
|
|
|
* be put in unconfigured mode.
|
|
|
|
*
|
2005-04-17 05:20:36 +07:00
|
|
|
* Note that USB has an additional level of device configurability,
|
|
|
|
* associated with interfaces. That configurability is accessed using
|
|
|
|
* usb_set_interface().
|
|
|
|
*
|
|
|
|
* This call is synchronous. The calling context must be able to sleep,
|
|
|
|
* must own the device lock, and must not hold the driver model's USB
|
2008-06-17 22:24:08 +07:00
|
|
|
* bus mutex; usb interface driver probe() methods cannot use this routine.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Returns zero on success, or else the status code returned by the
|
2005-05-04 08:07:24 +07:00
|
|
|
* underlying call that failed. On successful completion, each interface
|
2005-04-17 05:20:36 +07:00
|
|
|
* in the original device configuration has been destroyed, and each one
|
|
|
|
* in the new configuration has been probed by all relevant usb device
|
|
|
|
* drivers currently known to the kernel.
|
|
|
|
*/
|
|
|
|
int usb_set_configuration(struct usb_device *dev, int configuration)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
struct usb_host_config *cp = NULL;
|
|
|
|
struct usb_interface **new_interfaces = NULL;
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
struct usb_hcd *hcd = bus_to_hcd(dev->bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
int n, nintf;
|
|
|
|
|
2007-08-01 10:34:01 +07:00
|
|
|
if (dev->authorized == 0 || configuration == -1)
|
2007-02-09 04:40:43 +07:00
|
|
|
configuration = 0;
|
|
|
|
else {
|
|
|
|
for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
|
|
|
|
if (dev->config[i].desc.bConfigurationValue ==
|
|
|
|
configuration) {
|
|
|
|
cp = &dev->config[i];
|
|
|
|
break;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((!cp && configuration != 0))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* The USB spec says configuration 0 means unconfigured.
|
|
|
|
* But if a device includes a configuration numbered 0,
|
|
|
|
* we will accept it as a correctly configured state.
|
2007-02-09 04:40:43 +07:00
|
|
|
* Use -1 if you really want to unconfigure the device.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
if (cp && configuration == 0)
|
|
|
|
dev_warn(&dev->dev, "config 0 descriptor??\n");
|
|
|
|
|
|
|
|
/* Allocate memory for new interfaces before doing anything else,
|
|
|
|
* so that if we run out then nothing will have changed. */
|
|
|
|
n = nintf = 0;
|
|
|
|
if (cp) {
|
|
|
|
nintf = cp->desc.bNumInterfaces;
|
|
|
|
new_interfaces = kmalloc(nintf * sizeof(*new_interfaces),
|
2010-01-12 18:32:50 +07:00
|
|
|
GFP_NOIO);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!new_interfaces) {
|
2007-10-18 17:06:30 +07:00
|
|
|
dev_err(&dev->dev, "Out of memory\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; n < nintf; ++n) {
|
2005-10-25 02:38:24 +07:00
|
|
|
new_interfaces[n] = kzalloc(
|
2005-04-17 05:20:36 +07:00
|
|
|
sizeof(struct usb_interface),
|
2010-01-12 18:32:50 +07:00
|
|
|
GFP_NOIO);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!new_interfaces[n]) {
|
2007-10-18 17:06:30 +07:00
|
|
|
dev_err(&dev->dev, "Out of memory\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
ret = -ENOMEM;
|
|
|
|
free_interfaces:
|
|
|
|
while (--n >= 0)
|
|
|
|
kfree(new_interfaces[n]);
|
|
|
|
kfree(new_interfaces);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 21:25:46 +07:00
|
|
|
i = dev->bus_mA - usb_get_max_power(dev, cp);
|
2006-03-09 20:10:49 +07:00
|
|
|
if (i < 0)
|
|
|
|
dev_warn(&dev->dev, "new config #%d exceeds power "
|
|
|
|
"limit by %dmA\n",
|
|
|
|
configuration, -i);
|
|
|
|
}
|
2005-11-24 00:03:12 +07:00
|
|
|
|
2006-08-31 02:47:18 +07:00
|
|
|
/* Wake up the device so we can send it the Set-Config request */
|
2006-11-20 23:38:46 +07:00
|
|
|
ret = usb_autoresume_device(dev);
|
2006-08-31 02:47:18 +07:00
|
|
|
if (ret)
|
|
|
|
goto free_interfaces;
|
|
|
|
|
2010-08-28 13:06:29 +07:00
|
|
|
/* if it's already configured, clear out old state first.
|
|
|
|
* getting rid of old interfaces means unbinding their drivers.
|
|
|
|
*/
|
|
|
|
if (dev->state != USB_STATE_ADDRESS)
|
|
|
|
usb_disable_device(dev, 1); /* Skip ep0 */
|
|
|
|
|
|
|
|
/* Get rid of pending async Set-Config requests for this device */
|
|
|
|
cancel_async_set_config(dev);
|
|
|
|
|
USB: Support for bandwidth allocation.
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: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-04-28 09:58:26 +07:00
|
|
|
/* Make sure we have bandwidth (and available HCD resources) for this
|
|
|
|
* configuration. Remove endpoints from the schedule if we're dropping
|
|
|
|
* this configuration to set configuration 0. After this point, the
|
|
|
|
* host controller will not allow submissions to dropped endpoints. If
|
|
|
|
* this call fails, the device state is unchanged.
|
|
|
|
*/
|
2012-04-18 02:22:39 +07:00
|
|
|
mutex_lock(hcd->bandwidth_mutex);
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
/* Disable LPM, and re-enable it once the new configuration is
|
|
|
|
* installed, so that the xHCI driver can recalculate the U1/U2
|
|
|
|
* timeouts.
|
|
|
|
*/
|
2012-07-04 13:22:38 +07:00
|
|
|
if (dev->actconfig && usb_disable_lpm(dev)) {
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
dev_err(&dev->dev, "%s Failed to disable LPM\n.", __func__);
|
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
2012-11-21 12:31:19 +07:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto free_interfaces;
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
}
|
USB: Check bandwidth when switching alt settings.
Make the USB core check the bandwidth when switching from one
interface alternate setting to another. Also check the bandwidth
when resetting a configuration (so that alt setting 0 is used). If
this check fails, the device's state is unchanged. If the device
refuses the new alt setting, re-instate the old alt setting in the
host controller hardware.
If a USB device doesn't have an alternate interface setting 0, install
the first alt setting in its descriptors when a new configuration is
requested, or the device is reset.
Add a mutex per root hub to protect bandwidth operations:
adding/reseting/changing configurations, and changing alternate interface
settings. We want to ensure that the xHCI host controller and the USB
device are set up for the same configurations and alternate settings.
There are two (possibly three) steps to do this:
1. The host controller needs to check that bandwidth is available for a
different setting, by issuing and waiting for a configure endpoint
command.
2. Once that returns successfully, a control message is sent to the
device.
3. If that fails, the host controller must be notified through another
configure endpoint command.
The mutex is used to make these three operations seem atomic, to prevent
another driver from using more bandwidth for a different device while
we're in the middle of these operations.
While we're touching the bandwidth code, rename usb_hcd_check_bandwidth()
to usb_hcd_alloc_bandwidth(). This function does more than just check
that the bandwidth change won't exceed the bus bandwidth; it actually
changes the bandwidth configuration in the xHCI host controller.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-12-04 00:44:36 +07:00
|
|
|
ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL);
|
USB: Support for bandwidth allocation.
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: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-04-28 09:58:26 +07:00
|
|
|
if (ret < 0) {
|
2012-07-04 13:22:38 +07:00
|
|
|
if (dev->actconfig)
|
|
|
|
usb_enable_lpm(dev);
|
2010-10-15 22:55:24 +07:00
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
2010-08-28 13:06:29 +07:00
|
|
|
usb_autosuspend_device(dev);
|
USB: Support for bandwidth allocation.
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: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2009-04-28 09:58:26 +07:00
|
|
|
goto free_interfaces;
|
|
|
|
}
|
|
|
|
|
2012-11-07 22:31:30 +07:00
|
|
|
/*
|
|
|
|
* Initialize the new interface structures and the
|
2006-06-02 00:59:16 +07:00
|
|
|
* hc/hcd/usbcore interface/endpoint state.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < nintf; ++i) {
|
|
|
|
struct usb_interface_cache *intfc;
|
|
|
|
struct usb_interface *intf;
|
|
|
|
struct usb_host_interface *alt;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-06-02 00:59:16 +07:00
|
|
|
cp->interface[i] = intf = new_interfaces[i];
|
|
|
|
intfc = cp->intf_cache[i];
|
|
|
|
intf->altsetting = intfc->altsetting;
|
|
|
|
intf->num_altsetting = intfc->num_altsetting;
|
|
|
|
kref_get(&intfc->ref);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-06-02 00:59:16 +07:00
|
|
|
alt = usb_altnum_to_altsetting(intf, 0);
|
|
|
|
|
|
|
|
/* No altsetting 0? We'll assume the first altsetting.
|
|
|
|
* We could use a GetInterface call, but if a device is
|
|
|
|
* so non-compliant that it doesn't have altsetting 0
|
|
|
|
* then I wouldn't trust its reply anyway.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2006-06-02 00:59:16 +07:00
|
|
|
if (!alt)
|
|
|
|
alt = &intf->altsetting[0];
|
|
|
|
|
2012-06-13 01:23:52 +07:00
|
|
|
intf->intf_assoc =
|
|
|
|
find_iad(dev, cp, alt->desc.bInterfaceNumber);
|
2006-06-02 00:59:16 +07:00
|
|
|
intf->cur_altsetting = alt;
|
2008-12-31 23:31:33 +07:00
|
|
|
usb_enable_interface(dev, intf, true);
|
2006-06-02 00:59:16 +07:00
|
|
|
intf->dev.parent = &dev->dev;
|
|
|
|
intf->dev.driver = NULL;
|
|
|
|
intf->dev.bus = &usb_bus_type;
|
2007-03-13 21:59:31 +07:00
|
|
|
intf->dev.type = &usb_if_device_type;
|
2008-05-01 02:37:19 +07:00
|
|
|
intf->dev.groups = usb_interface_groups;
|
2006-06-02 00:59:16 +07:00
|
|
|
intf->dev.dma_mask = dev->dev.dma_mask;
|
2008-11-14 01:31:35 +07:00
|
|
|
INIT_WORK(&intf->reset_ws, __usb_queue_reset_device);
|
2010-09-22 02:01:53 +07:00
|
|
|
intf->minor = -1;
|
2008-01-31 06:21:33 +07:00
|
|
|
device_initialize(&intf->dev);
|
2010-11-16 03:56:54 +07:00
|
|
|
pm_runtime_no_callbacks(&intf->dev);
|
2008-05-02 11:02:41 +07:00
|
|
|
dev_set_name(&intf->dev, "%d-%s:%d.%d",
|
2008-01-31 06:21:33 +07:00
|
|
|
dev->bus->busnum, dev->devpath,
|
|
|
|
configuration, alt->desc.bInterfaceNumber);
|
2015-01-22 02:02:43 +07:00
|
|
|
usb_get_dev(dev);
|
2006-06-02 00:59:16 +07:00
|
|
|
}
|
|
|
|
kfree(new_interfaces);
|
|
|
|
|
2012-11-07 22:31:30 +07:00
|
|
|
ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
|
|
|
USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
|
|
|
|
NULL, 0, USB_CTRL_SET_TIMEOUT);
|
|
|
|
if (ret < 0 && cp) {
|
|
|
|
/*
|
|
|
|
* All the old state is gone, so what else can we do?
|
|
|
|
* The device is probably useless now anyway.
|
|
|
|
*/
|
|
|
|
usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
|
|
|
|
for (i = 0; i < nintf; ++i) {
|
|
|
|
usb_disable_interface(dev, cp->interface[i], true);
|
|
|
|
put_device(&cp->interface[i]->dev);
|
|
|
|
cp->interface[i] = NULL;
|
|
|
|
}
|
|
|
|
cp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->actconfig = cp;
|
|
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
|
|
|
|
|
|
if (!cp) {
|
|
|
|
usb_set_device_state(dev, USB_STATE_ADDRESS);
|
|
|
|
|
|
|
|
/* Leave LPM disabled while the device is unconfigured. */
|
|
|
|
usb_autosuspend_device(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
usb_set_device_state(dev, USB_STATE_CONFIGURED);
|
|
|
|
|
2009-03-19 01:28:53 +07:00
|
|
|
if (cp->string == NULL &&
|
|
|
|
!(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
|
2006-06-02 00:59:16 +07:00
|
|
|
cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
|
|
|
|
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
/* Now that the interfaces are installed, re-enable LPM. */
|
|
|
|
usb_unlocked_enable_lpm(dev);
|
2012-06-26 02:08:08 +07:00
|
|
|
/* Enable LTM if it was turned off by usb_disable_device. */
|
|
|
|
usb_enable_ltm(dev);
|
USB: Disable USB 3.0 LPM in critical sections.
There are several places where the USB core needs to disable USB 3.0
Link PM:
- usb_bind_interface
- usb_unbind_interface
- usb_driver_claim_interface
- usb_port_suspend/usb_port_resume
- usb_reset_and_verify_device
- usb_set_interface
- usb_reset_configuration
- usb_set_configuration
Use the new LPM disable/enable functions to temporarily disable LPM
around these critical sections.
We need to protect the critical section around binding and unbinding USB
interface drivers. USB drivers may want to disable hub-initiated USB
3.0 LPM, which will change the value of the U1/U2 timeouts that the xHCI
driver will install. We need to disable LPM completely until the driver
is bound to the interface, and the driver has a chance to enable
whatever alternate interface setting it needs in its probe routine.
Then re-enable USB3 LPM, and recalculate the U1/U2 timeout values.
We also need to disable LPM in usb_driver_claim_interface,
because drivers like usbfs can bind to an interface through that
function. Note, there is no way currently for userspace drivers to
disable hub-initiated USB 3.0 LPM. Revisit this later.
When a driver is unbound, the U1/U2 timeouts may change because we are
unbinding the last driver that needed hub-initiated USB 3.0 LPM to be
disabled.
USB LPM must be disabled when a USB device is going to be suspended.
The USB 3.0 spec does not define a state transition from U1 or U2 into
U3, so we need to bring the device into U0 by disabling LPM before we
can place it into U3. Therefore, call usb_unlocked_disable_lpm() in
usb_port_suspend(), and call usb_unlocked_enable_lpm() in
usb_port_resume(). If the port suspend fails, make sure to re-enable
LPM by calling usb_unlocked_enable_lpm(), since usb_port_resume() will
not be called on a failed port suspend.
USB 3.0 devices lose their USB 3.0 LPM settings (including whether USB
device-initiated LPM is enabled) across device suspend. Therefore,
disable LPM before the device will be reset in
usb_reset_and_verify_device(), and re-enable LPM after the reset is
complete and the configuration/alt settings are re-installed.
The calculated U1/U2 timeout values are heavily dependent on what USB
device endpoints are currently enabled. When any of the enabled
endpoints on the device might change, due to a new configuration, or new
alternate interface setting, we need to first disable USB 3.0 LPM, add
or delete endpoints from the xHCI schedule, install the new interfaces
and alt settings, and then re-enable LPM. Do this in usb_set_interface,
usb_reset_configuration, and usb_set_configuration.
Basically, there is a call to disable and then enable LPM in all
functions that lock the bandwidth_mutex. One exception is
usb_disable_device, because the device is disconnecting or otherwise
going away, and we should not care about whether USB 3.0 LPM is enabled.
Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
2012-05-03 04:25:52 +07:00
|
|
|
|
2006-06-02 00:59:16 +07:00
|
|
|
/* Now that all the interfaces are set up, register them
|
|
|
|
* to trigger binding of drivers to interfaces. probe()
|
|
|
|
* routines may install different altsettings and may
|
|
|
|
* claim() any interfaces not yet bound. Many class drivers
|
|
|
|
* need that: CDC, audio, video, etc.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < nintf; ++i) {
|
|
|
|
struct usb_interface *intf = cp->interface[i];
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
dev_dbg(&dev->dev,
|
2006-06-02 00:59:16 +07:00
|
|
|
"adding %s (config #%d, interface %d)\n",
|
2008-05-02 11:02:41 +07:00
|
|
|
dev_name(&intf->dev), configuration,
|
2006-06-02 00:59:16 +07:00
|
|
|
intf->cur_altsetting->desc.bInterfaceNumber);
|
2010-02-09 01:18:16 +07:00
|
|
|
device_enable_async_suspend(&intf->dev);
|
2008-01-31 06:21:33 +07:00
|
|
|
ret = device_add(&intf->dev);
|
2006-06-02 00:59:16 +07:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&dev->dev, "device_add(%s) --> %d\n",
|
2008-05-02 11:02:41 +07:00
|
|
|
dev_name(&intf->dev), ret);
|
2006-06-02 00:59:16 +07:00
|
|
|
continue;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2008-12-06 02:10:34 +07:00
|
|
|
create_intf_ep_devs(intf);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-11-20 23:38:46 +07:00
|
|
|
usb_autosuspend_device(dev);
|
2005-07-30 02:17:16 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2014-01-24 04:12:29 +07:00
|
|
|
EXPORT_SYMBOL_GPL(usb_set_configuration);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-12-19 22:27:56 +07:00
|
|
|
static LIST_HEAD(set_config_list);
|
|
|
|
static DEFINE_SPINLOCK(set_config_lock);
|
|
|
|
|
2006-08-21 23:08:19 +07:00
|
|
|
struct set_config_request {
|
|
|
|
struct usb_device *udev;
|
|
|
|
int config;
|
|
|
|
struct work_struct work;
|
2008-12-19 22:27:56 +07:00
|
|
|
struct list_head node;
|
2006-08-21 23:08:19 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Worker routine for usb_driver_set_configuration() */
|
2006-11-22 21:57:56 +07:00
|
|
|
static void driver_set_config_work(struct work_struct *work)
|
2006-08-21 23:08:19 +07:00
|
|
|
{
|
2006-11-22 21:57:56 +07:00
|
|
|
struct set_config_request *req =
|
|
|
|
container_of(work, struct set_config_request, work);
|
2008-12-19 22:27:56 +07:00
|
|
|
struct usb_device *udev = req->udev;
|
2006-08-21 23:08:19 +07:00
|
|
|
|
2008-12-19 22:27:56 +07:00
|
|
|
usb_lock_device(udev);
|
|
|
|
spin_lock(&set_config_lock);
|
|
|
|
list_del(&req->node);
|
|
|
|
spin_unlock(&set_config_lock);
|
|
|
|
|
|
|
|
if (req->config >= -1) /* Is req still valid? */
|
|
|
|
usb_set_configuration(udev, req->config);
|
|
|
|
usb_unlock_device(udev);
|
|
|
|
usb_put_dev(udev);
|
2006-08-21 23:08:19 +07:00
|
|
|
kfree(req);
|
|
|
|
}
|
|
|
|
|
2008-12-19 22:27:56 +07:00
|
|
|
/* Cancel pending Set-Config requests for a device whose configuration
|
|
|
|
* was just changed
|
|
|
|
*/
|
|
|
|
static void cancel_async_set_config(struct usb_device *udev)
|
|
|
|
{
|
|
|
|
struct set_config_request *req;
|
|
|
|
|
|
|
|
spin_lock(&set_config_lock);
|
|
|
|
list_for_each_entry(req, &set_config_list, node) {
|
|
|
|
if (req->udev == udev)
|
|
|
|
req->config = -999; /* Mark as cancelled */
|
|
|
|
}
|
|
|
|
spin_unlock(&set_config_lock);
|
|
|
|
}
|
|
|
|
|
2006-08-21 23:08:19 +07:00
|
|
|
/**
|
|
|
|
* usb_driver_set_configuration - Provide a way for drivers to change device configurations
|
|
|
|
* @udev: the device whose configuration is being updated
|
|
|
|
* @config: the configuration being chosen.
|
|
|
|
* Context: In process context, must be able to sleep
|
|
|
|
*
|
|
|
|
* Device interface drivers are not allowed to change device configurations.
|
|
|
|
* This is because changing configurations will destroy the interface the
|
|
|
|
* driver is bound to and create new ones; it would be like a floppy-disk
|
|
|
|
* driver telling the computer to replace the floppy-disk drive with a
|
|
|
|
* tape drive!
|
|
|
|
*
|
|
|
|
* Still, in certain specialized circumstances the need may arise. This
|
|
|
|
* routine gets around the normal restrictions by using a work thread to
|
|
|
|
* submit the change-config request.
|
|
|
|
*
|
2013-08-03 01:10:04 +07:00
|
|
|
* Return: 0 if the request was successfully queued, error code otherwise.
|
2006-08-21 23:08:19 +07:00
|
|
|
* The caller has no way to know whether the queued request will eventually
|
|
|
|
* succeed.
|
|
|
|
*/
|
|
|
|
int usb_driver_set_configuration(struct usb_device *udev, int config)
|
|
|
|
{
|
|
|
|
struct set_config_request *req;
|
|
|
|
|
|
|
|
req = kmalloc(sizeof(*req), GFP_KERNEL);
|
|
|
|
if (!req)
|
|
|
|
return -ENOMEM;
|
|
|
|
req->udev = udev;
|
|
|
|
req->config = config;
|
2006-11-22 21:57:56 +07:00
|
|
|
INIT_WORK(&req->work, driver_set_config_work);
|
2006-08-21 23:08:19 +07:00
|
|
|
|
2008-12-19 22:27:56 +07:00
|
|
|
spin_lock(&set_config_lock);
|
|
|
|
list_add(&req->node, &set_config_list);
|
|
|
|
spin_unlock(&set_config_lock);
|
|
|
|
|
2006-08-21 23:08:19 +07:00
|
|
|
usb_get_dev(udev);
|
2006-12-16 04:04:52 +07:00
|
|
|
schedule_work(&req->work);
|
2006-08-21 23:08:19 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(usb_driver_set_configuration);
|