2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2005-09-17 15:55:31 +08:00
|
|
|
#include <linux/scatterlist.h>
|
2007-12-14 08:15:33 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <linux/usb.h>
|
|
|
|
|
|
|
|
|
USB: altsetting overrides for usbtest
The usbtest driver includes some rather simple-minded logic for
selecting an altsetting to test. It doesn't work well for the g_zero
gadget, because it selects altsetting 0 (which doesn't have
isochronous endpoints) rather than altsetting 1 (which does have them,
if the gadget's hardware supports them). This prevents usbtest's
isochronous tests (15, 16, 22, and 23) from working with g_zero.
Since g_zero is one of the most common gadget drivers used for USB
testing, usbtest should do a better job of supporting it. But since
some programs may rely on the current scheme for selecting
altsettings, I didn't want to change it.
Instead, this patch (as1655) adds a module parameter to usbtest, which
can be used to override the default altsetting. Since usbtest is
never used by normal users (most distributions probably don't even
build it), the new module parameter won't inconvenience anybody. In
any case, it is entirely optional -- leaving it unset preserves the
existing behavior.
The patch also fixes a related bug in usbtest: After selecting an
altsetting, the driver neglects to store its selection.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-31 05:38:11 +08:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int override_alt = -1;
|
|
|
|
module_param_named(alt, override_alt, int, 0644);
|
|
|
|
MODULE_PARM_DESC(alt, ">= 0 to override altsetting selection");
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIXME make these public somewhere; usbdevfs.h? */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usbtest_param {
|
2010-10-01 06:20:42 +08:00
|
|
|
/* inputs */
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned test_num; /* 0..(TEST_CASES-1) */
|
|
|
|
unsigned iterations;
|
|
|
|
unsigned length;
|
|
|
|
unsigned vary;
|
|
|
|
unsigned sglen;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
/* outputs */
|
2005-04-17 06:20:36 +08:00
|
|
|
struct timeval duration;
|
|
|
|
};
|
|
|
|
#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#define GENERIC /* let probe() bind using module params */
|
|
|
|
|
|
|
|
/* Some devices that can be used for testing will have "real" drivers.
|
|
|
|
* Entries for those need to be enabled here by hand, after disabling
|
|
|
|
* that "real" driver.
|
|
|
|
*/
|
|
|
|
//#define IBOT2 /* grab iBOT2 webcams */
|
|
|
|
//#define KEYSPAN_19Qi /* grab un-renumerated serial adapter */
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
struct usbtest_info {
|
|
|
|
const char *name;
|
|
|
|
u8 ep_in; /* bulk/intr source */
|
|
|
|
u8 ep_out; /* bulk/intr sink */
|
2010-10-01 06:20:42 +08:00
|
|
|
unsigned autoconf:1;
|
|
|
|
unsigned ctrl_out:1;
|
|
|
|
unsigned iso:1; /* try iso in/out */
|
2005-04-17 06:20:36 +08:00
|
|
|
int alt;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* this is accessed only through usbfs ioctl calls.
|
|
|
|
* one ioctl to issue a test ... one lock per device.
|
|
|
|
* tests create other threads if they need them.
|
|
|
|
* urbs and buffers are allocated dynamically,
|
|
|
|
* and data generated deterministically.
|
|
|
|
*/
|
|
|
|
struct usbtest_dev {
|
|
|
|
struct usb_interface *intf;
|
|
|
|
struct usbtest_info *info;
|
|
|
|
int in_pipe;
|
|
|
|
int out_pipe;
|
|
|
|
int in_iso_pipe;
|
|
|
|
int out_iso_pipe;
|
|
|
|
struct usb_endpoint_descriptor *iso_in, *iso_out;
|
2007-12-14 08:15:33 +08:00
|
|
|
struct mutex lock;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define TBUF_SIZE 256
|
|
|
|
u8 *buf;
|
|
|
|
};
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-10-01 06:20:42 +08:00
|
|
|
return interface_to_usbdev(test->intf);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set up all urbs so they can be used with either bulk or interrupt */
|
|
|
|
#define INTERRUPT_RATE 1 /* msec/transfer */
|
|
|
|
|
2008-04-26 09:51:10 +08:00
|
|
|
#define ERROR(tdev, fmt, args...) \
|
|
|
|
dev_err(&(tdev)->intf->dev , fmt , ## args)
|
2008-07-25 16:45:52 +08:00
|
|
|
#define WARNING(tdev, fmt, args...) \
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_warn(&(tdev)->intf->dev , fmt , ## args)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
#define GUARD_BYTE 0xA5
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int
|
2010-10-01 06:20:42 +08:00
|
|
|
get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
struct usb_host_interface *alt;
|
|
|
|
struct usb_host_endpoint *in, *out;
|
|
|
|
struct usb_host_endpoint *iso_in, *iso_out;
|
|
|
|
struct usb_device *udev;
|
|
|
|
|
|
|
|
for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
|
|
|
|
unsigned ep;
|
|
|
|
|
|
|
|
in = out = NULL;
|
|
|
|
iso_in = iso_out = NULL;
|
|
|
|
alt = intf->altsetting + tmp;
|
|
|
|
|
USB: altsetting overrides for usbtest
The usbtest driver includes some rather simple-minded logic for
selecting an altsetting to test. It doesn't work well for the g_zero
gadget, because it selects altsetting 0 (which doesn't have
isochronous endpoints) rather than altsetting 1 (which does have them,
if the gadget's hardware supports them). This prevents usbtest's
isochronous tests (15, 16, 22, and 23) from working with g_zero.
Since g_zero is one of the most common gadget drivers used for USB
testing, usbtest should do a better job of supporting it. But since
some programs may rely on the current scheme for selecting
altsettings, I didn't want to change it.
Instead, this patch (as1655) adds a module parameter to usbtest, which
can be used to override the default altsetting. Since usbtest is
never used by normal users (most distributions probably don't even
build it), the new module parameter won't inconvenience anybody. In
any case, it is entirely optional -- leaving it unset preserves the
existing behavior.
The patch also fixes a related bug in usbtest: After selecting an
altsetting, the driver neglects to store its selection.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-31 05:38:11 +08:00
|
|
|
if (override_alt >= 0 &&
|
|
|
|
override_alt != alt->desc.bAlternateSetting)
|
|
|
|
continue;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* take the first altsetting with in-bulk + out-bulk;
|
2011-05-10 16:16:21 +08:00
|
|
|
* ignore other endpoints and altsettings.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
|
|
|
|
struct usb_host_endpoint *e;
|
|
|
|
|
|
|
|
e = alt->endpoint + ep;
|
2013-09-24 00:03:43 +08:00
|
|
|
switch (usb_endpoint_type(&e->desc)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case USB_ENDPOINT_XFER_BULK:
|
|
|
|
break;
|
|
|
|
case USB_ENDPOINT_XFER_ISOC:
|
|
|
|
if (dev->info->iso)
|
|
|
|
goto try_iso;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2006-10-27 00:03:02 +08:00
|
|
|
if (usb_endpoint_dir_in(&e->desc)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!in)
|
|
|
|
in = e;
|
|
|
|
} else {
|
|
|
|
if (!out)
|
|
|
|
out = e;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
try_iso:
|
2006-10-27 00:03:02 +08:00
|
|
|
if (usb_endpoint_dir_in(&e->desc)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!iso_in)
|
|
|
|
iso_in = e;
|
|
|
|
} else {
|
|
|
|
if (!iso_out)
|
|
|
|
iso_out = e;
|
|
|
|
}
|
|
|
|
}
|
2010-08-02 22:09:17 +08:00
|
|
|
if ((in && out) || iso_in || iso_out)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
found:
|
2010-10-01 06:20:42 +08:00
|
|
|
udev = testdev_to_usbdev(dev);
|
USB: altsetting overrides for usbtest
The usbtest driver includes some rather simple-minded logic for
selecting an altsetting to test. It doesn't work well for the g_zero
gadget, because it selects altsetting 0 (which doesn't have
isochronous endpoints) rather than altsetting 1 (which does have them,
if the gadget's hardware supports them). This prevents usbtest's
isochronous tests (15, 16, 22, and 23) from working with g_zero.
Since g_zero is one of the most common gadget drivers used for USB
testing, usbtest should do a better job of supporting it. But since
some programs may rely on the current scheme for selecting
altsettings, I didn't want to change it.
Instead, this patch (as1655) adds a module parameter to usbtest, which
can be used to override the default altsetting. Since usbtest is
never used by normal users (most distributions probably don't even
build it), the new module parameter won't inconvenience anybody. In
any case, it is entirely optional -- leaving it unset preserves the
existing behavior.
The patch also fixes a related bug in usbtest: After selecting an
altsetting, the driver neglects to store its selection.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-31 05:38:11 +08:00
|
|
|
dev->info->alt = alt->desc.bAlternateSetting;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (alt->desc.bAlternateSetting != 0) {
|
2010-10-01 06:20:42 +08:00
|
|
|
tmp = usb_set_interface(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
alt->desc.bInterfaceNumber,
|
|
|
|
alt->desc.bAlternateSetting);
|
|
|
|
if (tmp < 0)
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in) {
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->in_pipe = usb_rcvbulkpipe(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->out_pipe = usb_sndbulkpipe(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
|
|
|
|
}
|
|
|
|
if (iso_in) {
|
|
|
|
dev->iso_in = &iso_in->desc;
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->in_iso_pipe = usb_rcvisocpipe(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
iso_in->desc.bEndpointAddress
|
|
|
|
& USB_ENDPOINT_NUMBER_MASK);
|
2010-08-02 22:09:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (iso_out) {
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->iso_out = &iso_out->desc;
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->out_iso_pipe = usb_sndisocpipe(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
iso_out->desc.bEndpointAddress
|
|
|
|
& USB_ENDPOINT_NUMBER_MASK);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* Support for testing basic non-queued I/O streams.
|
|
|
|
*
|
|
|
|
* These just package urbs as requests that can be easily canceled.
|
|
|
|
* Each urb's data buffer is dynamically allocated; callers can fill
|
|
|
|
* them with non-zero test data (or test for it) when appropriate.
|
|
|
|
*/
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static void simple_callback(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-24 18:41:47 +08:00
|
|
|
complete(urb->context);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
static struct urb *usbtest_alloc_urb(
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_device *udev,
|
|
|
|
int pipe,
|
2011-01-17 02:17:11 +08:00
|
|
|
unsigned long bytes,
|
|
|
|
unsigned transfer_flags,
|
|
|
|
unsigned offset)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct urb *urb;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb)
|
|
|
|
return urb;
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
urb->interval = (udev->speed == USB_SPEED_HIGH)
|
|
|
|
? (INTERRUPT_RATE << 3)
|
|
|
|
: INTERRUPT_RATE;
|
2011-01-17 02:17:11 +08:00
|
|
|
urb->transfer_flags = transfer_flags;
|
2010-10-01 06:20:42 +08:00
|
|
|
if (usb_pipein(pipe))
|
2005-04-17 06:20:36 +08:00
|
|
|
urb->transfer_flags |= URB_SHORT_NOT_OK;
|
2011-01-17 02:17:11 +08:00
|
|
|
|
|
|
|
if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
|
|
|
|
urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
|
|
|
|
GFP_KERNEL, &urb->transfer_dma);
|
|
|
|
else
|
|
|
|
urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb->transfer_buffer) {
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_free_urb(urb);
|
2011-01-17 02:17:11 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* To test unaligned transfers add an offset and fill the
|
|
|
|
unused memory with a guard value */
|
|
|
|
if (offset) {
|
|
|
|
memset(urb->transfer_buffer, GUARD_BYTE, offset);
|
|
|
|
urb->transfer_buffer += offset;
|
|
|
|
if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
|
|
|
|
urb->transfer_dma += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For inbound transfers use guard byte so that test fails if
|
|
|
|
data not correctly copied */
|
|
|
|
memset(urb->transfer_buffer,
|
|
|
|
usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
|
|
|
|
bytes);
|
2005-04-17 06:20:36 +08:00
|
|
|
return urb;
|
|
|
|
}
|
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
static struct urb *simple_alloc_urb(
|
|
|
|
struct usb_device *udev,
|
|
|
|
int pipe,
|
|
|
|
unsigned long bytes)
|
|
|
|
{
|
|
|
|
return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0);
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static unsigned pattern;
|
2009-11-10 11:24:32 +08:00
|
|
|
static unsigned mod_pattern;
|
|
|
|
module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static inline void simple_fill_buf(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
u8 *buf = urb->transfer_buffer;
|
|
|
|
unsigned len = urb->transfer_buffer_length;
|
|
|
|
|
|
|
|
switch (pattern) {
|
|
|
|
default:
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0:
|
2010-10-01 06:20:42 +08:00
|
|
|
memset(buf, 0, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 1: /* mod63 */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
*buf++ = (u8) (i % 63);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-09 11:51:43 +08:00
|
|
|
static inline unsigned long buffer_offset(void *buf)
|
2011-01-17 02:17:11 +08:00
|
|
|
{
|
2011-05-09 11:51:43 +08:00
|
|
|
return (unsigned long)buf & (ARCH_KMALLOC_MINALIGN - 1);
|
2011-01-17 02:17:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb)
|
|
|
|
{
|
|
|
|
u8 *buf = urb->transfer_buffer;
|
|
|
|
u8 *guard = buf - buffer_offset(buf);
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; guard < buf; i++, guard++) {
|
|
|
|
if (*guard != GUARD_BYTE) {
|
|
|
|
ERROR(tdev, "guard byte[%d] %d (not %d)\n",
|
|
|
|
i, *guard, GUARD_BYTE);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
u8 expected;
|
|
|
|
u8 *buf = urb->transfer_buffer;
|
|
|
|
unsigned len = urb->actual_length;
|
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
int ret = check_guard_bytes(tdev, urb);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < len; i++, buf++) {
|
|
|
|
switch (pattern) {
|
|
|
|
/* all-zeroes has no synchronization issues */
|
|
|
|
case 0:
|
|
|
|
expected = 0;
|
|
|
|
break;
|
|
|
|
/* mod63 stays in sync with short-terminated transfers,
|
|
|
|
* or otherwise when host and gadget agree on how large
|
|
|
|
* each usb transfer request should be. resync is done
|
|
|
|
* with set_interface or set_config.
|
|
|
|
*/
|
|
|
|
case 1: /* mod63 */
|
|
|
|
expected = i % 63;
|
|
|
|
break;
|
|
|
|
/* always fail unsupported patterns */
|
|
|
|
default:
|
|
|
|
expected = !*buf;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*buf == expected)
|
|
|
|
continue;
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "buf[%d] = %d (not %d)\n", i, *buf, expected);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static void simple_free_urb(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-05-09 11:51:43 +08:00
|
|
|
unsigned long offset = buffer_offset(urb->transfer_buffer);
|
2011-01-17 02:17:11 +08:00
|
|
|
|
|
|
|
if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
|
|
|
|
usb_free_coherent(
|
|
|
|
urb->dev,
|
|
|
|
urb->transfer_buffer_length + offset,
|
|
|
|
urb->transfer_buffer - offset,
|
|
|
|
urb->transfer_dma - offset);
|
|
|
|
else
|
|
|
|
kfree(urb->transfer_buffer - offset);
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_free_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int simple_io(
|
2008-04-26 09:51:10 +08:00
|
|
|
struct usbtest_dev *tdev,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct urb *urb,
|
|
|
|
int iterations,
|
|
|
|
int vary,
|
|
|
|
int expected,
|
|
|
|
const char *label
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct usb_device *udev = urb->dev;
|
|
|
|
int max = urb->transfer_buffer_length;
|
|
|
|
struct completion completion;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
urb->context = &completion;
|
|
|
|
while (retval == 0 && iterations-- > 0) {
|
2010-10-01 06:20:42 +08:00
|
|
|
init_completion(&completion);
|
2011-08-23 16:44:54 +08:00
|
|
|
if (usb_pipeout(urb->pipe)) {
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_fill_buf(urb);
|
2011-08-23 16:44:54 +08:00
|
|
|
urb->transfer_flags |= URB_ZERO_PACKET;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_submit_urb(urb, GFP_KERNEL);
|
|
|
|
if (retval != 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* NOTE: no timeouts; can't be broken out of by interrupt */
|
2010-10-01 06:20:42 +08:00
|
|
|
wait_for_completion(&completion);
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = urb->status;
|
|
|
|
urb->dev = udev;
|
2010-10-01 06:20:42 +08:00
|
|
|
if (retval == 0 && usb_pipein(urb->pipe))
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = simple_check_buf(tdev, urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (vary) {
|
|
|
|
int len = urb->transfer_buffer_length;
|
|
|
|
|
|
|
|
len += vary;
|
|
|
|
len %= max;
|
|
|
|
if (len == 0)
|
|
|
|
len = (vary < max) ? vary : max;
|
|
|
|
urb->transfer_buffer_length = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME if endpoint halted, clear halt (and log) */
|
|
|
|
}
|
|
|
|
urb->transfer_buffer_length = max;
|
|
|
|
|
|
|
|
if (expected != retval)
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&udev->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"%s failed, iterations left %d, status %d (not %d)\n",
|
|
|
|
label, iterations, retval, expected);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* We use scatterlist primitives to test queued I/O.
|
|
|
|
* Yes, this also tests the scatterlist primitives.
|
|
|
|
*/
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static void free_sglist(struct scatterlist *sg, int nents)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned i;
|
2008-04-26 09:51:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sg)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < nents; i++) {
|
2007-10-23 03:19:53 +08:00
|
|
|
if (!sg_page(&sg[i]))
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2010-10-01 06:20:42 +08:00
|
|
|
kfree(sg_virt(&sg[i]));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
kfree(sg);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct scatterlist *
|
2010-10-01 06:20:42 +08:00
|
|
|
alloc_sglist(int nents, int max, int vary)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct scatterlist *sg;
|
|
|
|
unsigned i;
|
|
|
|
unsigned size = max;
|
|
|
|
|
2012-11-17 23:06:11 +08:00
|
|
|
if (max == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-21 23:15:30 +08:00
|
|
|
sg = kmalloc_array(nents, sizeof(*sg), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sg)
|
|
|
|
return NULL;
|
2008-03-27 22:15:22 +08:00
|
|
|
sg_init_table(sg, nents);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < nents; i++) {
|
|
|
|
char *buf;
|
2006-04-03 02:20:15 +08:00
|
|
|
unsigned j;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
buf = kzalloc(size, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!buf) {
|
2010-10-01 06:20:42 +08:00
|
|
|
free_sglist(sg, i);
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* kmalloc pages are always physically contiguous! */
|
2008-03-27 22:15:22 +08:00
|
|
|
sg_set_buf(&sg[i], buf, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-04-03 02:20:15 +08:00
|
|
|
switch (pattern) {
|
|
|
|
case 0:
|
|
|
|
/* already zeroed */
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
for (j = 0; j < size; j++)
|
|
|
|
*buf++ = (u8) (j % 63);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (vary) {
|
|
|
|
size += vary;
|
|
|
|
size %= max;
|
|
|
|
if (size == 0)
|
|
|
|
size = (vary < max) ? vary : max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sg;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int perform_sglist(
|
2008-04-26 09:51:10 +08:00
|
|
|
struct usbtest_dev *tdev,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned iterations,
|
|
|
|
int pipe,
|
|
|
|
struct usb_sg_request *req,
|
|
|
|
struct scatterlist *sg,
|
|
|
|
int nents
|
|
|
|
)
|
|
|
|
{
|
2008-04-26 09:51:10 +08:00
|
|
|
struct usb_device *udev = testdev_to_usbdev(tdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
while (retval == 0 && iterations-- > 0) {
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_sg_init(req, udev, pipe,
|
2005-04-17 06:20:36 +08:00
|
|
|
(udev->speed == USB_SPEED_HIGH)
|
|
|
|
? (INTERRUPT_RATE << 3)
|
|
|
|
: INTERRUPT_RATE,
|
2006-12-07 12:33:17 +08:00
|
|
|
sg, nents, 0, GFP_KERNEL);
|
2008-04-26 09:51:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval)
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_sg_wait(req);
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = req->status;
|
|
|
|
|
2006-04-03 02:20:15 +08:00
|
|
|
/* FIXME check resulting data pattern */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* FIXME if endpoint halted, clear halt (and log) */
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIXME for unlink or fault handling tests, don't report
|
|
|
|
* failure if retval is as we expected ...
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval)
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "perform_sglist failed, "
|
|
|
|
"iterations left %d, status %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
iterations, retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* unqueued control message testing
|
|
|
|
*
|
|
|
|
* there's a nice set of device functional requirements in chapter 9 of the
|
|
|
|
* usb 2.0 spec, which we can apply to ANY device, even ones that don't use
|
|
|
|
* special test firmware.
|
|
|
|
*
|
|
|
|
* we know the device is configured (or suspended) by the time it's visible
|
|
|
|
* through usbfs. we can't change that, so we won't test enumeration (which
|
|
|
|
* worked 'well enough' to get here, this time), power management (ditto),
|
|
|
|
* or remote wakeup (which needs human interaction).
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned realworld = 1;
|
2010-10-01 06:20:42 +08:00
|
|
|
module_param(realworld, uint, 0);
|
|
|
|
MODULE_PARM_DESC(realworld, "clear to demand stricter spec compliance");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int get_altsetting(struct usbtest_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct usb_interface *iface = dev->intf;
|
2010-10-01 06:20:42 +08:00
|
|
|
struct usb_device *udev = interface_to_usbdev(iface);
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
|
2005-04-17 06:20:36 +08:00
|
|
|
USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE,
|
2010-10-01 06:20:42 +08:00
|
|
|
0, iface->altsetting[0].desc.bInterfaceNumber,
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->buf, 1, USB_CTRL_GET_TIMEOUT);
|
|
|
|
switch (retval) {
|
|
|
|
case 1:
|
2010-10-01 06:20:42 +08:00
|
|
|
return dev->buf[0];
|
2005-04-17 06:20:36 +08:00
|
|
|
case 0:
|
|
|
|
retval = -ERANGE;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FALLTHROUGH */
|
2005-04-17 06:20:36 +08:00
|
|
|
default:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int set_altsetting(struct usbtest_dev *dev, int alternate)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct usb_interface *iface = dev->intf;
|
|
|
|
struct usb_device *udev;
|
|
|
|
|
|
|
|
if (alternate < 0 || alternate >= 256)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
udev = interface_to_usbdev(iface);
|
|
|
|
return usb_set_interface(udev,
|
|
|
|
iface->altsetting[0].desc.bInterfaceNumber,
|
2005-04-17 06:20:36 +08:00
|
|
|
alternate);
|
|
|
|
}
|
|
|
|
|
2008-04-26 09:51:10 +08:00
|
|
|
static int is_good_config(struct usbtest_dev *tdev, int len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct usb_config_descriptor *config;
|
2008-04-26 09:51:10 +08:00
|
|
|
|
2013-10-21 23:15:30 +08:00
|
|
|
if (len < sizeof(*config))
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2008-04-26 09:51:10 +08:00
|
|
|
config = (struct usb_config_descriptor *) tdev->buf;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (config->bDescriptorType) {
|
|
|
|
case USB_DT_CONFIG:
|
|
|
|
case USB_DT_OTHER_SPEED_CONFIG:
|
|
|
|
if (config->bLength != 9) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "bogus config descriptor length\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* this bit 'must be 1' but often isn't */
|
|
|
|
if (!realworld && !(config->bmAttributes & 0x80)) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "high bit of config attributes not set\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (config->bmAttributes & 0x1f) { /* reserved == 0 */
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "reserved config bits set\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
if (le16_to_cpu(config->wTotalLength) == len) /* read it all */
|
2005-04-17 06:20:36 +08:00
|
|
|
return 1;
|
2010-10-01 06:20:42 +08:00
|
|
|
if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */
|
2005-04-17 06:20:36 +08:00
|
|
|
return 1;
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "bogus config descriptor read size\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-30 11:27:38 +08:00
|
|
|
static int is_good_ext(struct usbtest_dev *tdev, u8 *buf)
|
|
|
|
{
|
|
|
|
struct usb_ext_cap_descriptor *ext;
|
|
|
|
u32 attr;
|
|
|
|
|
|
|
|
ext = (struct usb_ext_cap_descriptor *) buf;
|
|
|
|
|
|
|
|
if (ext->bLength != USB_DT_USB_EXT_CAP_SIZE) {
|
|
|
|
ERROR(tdev, "bogus usb 2.0 extension descriptor length\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr = le32_to_cpu(ext->bmAttributes);
|
|
|
|
/* bits[1:4] is used and others are reserved */
|
|
|
|
if (attr & ~0x1e) { /* reserved == 0 */
|
|
|
|
ERROR(tdev, "reserved bits set\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-10-30 11:27:39 +08:00
|
|
|
static int is_good_ss_cap(struct usbtest_dev *tdev, u8 *buf)
|
|
|
|
{
|
|
|
|
struct usb_ss_cap_descriptor *ss;
|
|
|
|
|
|
|
|
ss = (struct usb_ss_cap_descriptor *) buf;
|
|
|
|
|
|
|
|
if (ss->bLength != USB_DT_USB_SS_CAP_SIZE) {
|
|
|
|
ERROR(tdev, "bogus superspeed device capability descriptor length\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* only bit[1] of bmAttributes is used for LTM and others are
|
|
|
|
* reserved
|
|
|
|
*/
|
|
|
|
if (ss->bmAttributes & ~0x02) { /* reserved == 0 */
|
|
|
|
ERROR(tdev, "reserved bits set in bmAttributes\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bits[0:3] of wSpeedSupported is used and others are reserved */
|
|
|
|
if (le16_to_cpu(ss->wSpeedSupported) & ~0x0f) { /* reserved == 0 */
|
|
|
|
ERROR(tdev, "reserved bits set in wSpeedSupported\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-10-30 11:27:40 +08:00
|
|
|
static int is_good_con_id(struct usbtest_dev *tdev, u8 *buf)
|
|
|
|
{
|
|
|
|
struct usb_ss_container_id_descriptor *con_id;
|
|
|
|
|
|
|
|
con_id = (struct usb_ss_container_id_descriptor *) buf;
|
|
|
|
|
|
|
|
if (con_id->bLength != USB_DT_USB_SS_CONTN_ID_SIZE) {
|
|
|
|
ERROR(tdev, "bogus container id descriptor length\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (con_id->bReserved) { /* reserved == 0 */
|
|
|
|
ERROR(tdev, "reserved bits set\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* sanity test for standard requests working with usb_control_mesg() and some
|
|
|
|
* of the utility functions which use it.
|
|
|
|
*
|
|
|
|
* this doesn't test how endpoint halts behave or data toggles get set, since
|
|
|
|
* we won't do I/O to bulk/interrupt endpoints here (which is how to change
|
|
|
|
* halt or toggle). toggle testing is impractical without support from hcds.
|
|
|
|
*
|
|
|
|
* this avoids failing devices linux would normally work with, by not testing
|
|
|
|
* config/altsetting operations for devices that only support their defaults.
|
|
|
|
* such devices rarely support those needless operations.
|
|
|
|
*
|
|
|
|
* NOTE that since this is a sanity test, it's not examining boundary cases
|
|
|
|
* to see if usbcore, hcd, and device all behave right. such testing would
|
|
|
|
* involve varied read sizes and other operation sequences.
|
|
|
|
*/
|
2010-10-01 06:20:42 +08:00
|
|
|
static int ch9_postconfig(struct usbtest_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct usb_interface *iface = dev->intf;
|
2010-10-01 06:20:42 +08:00
|
|
|
struct usb_device *udev = interface_to_usbdev(iface);
|
2005-04-17 06:20:36 +08:00
|
|
|
int i, alt, retval;
|
|
|
|
|
|
|
|
/* [9.2.3] if there's more than one altsetting, we need to be able to
|
|
|
|
* set and get each one. mostly trusts the descriptors from usbcore.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < iface->num_altsetting; i++) {
|
|
|
|
|
|
|
|
/* 9.2.3 constrains the range here */
|
2010-10-01 06:20:42 +08:00
|
|
|
alt = iface->altsetting[i].desc.bAlternateSetting;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (alt < 0 || alt >= iface->num_altsetting) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"invalid alt [%d].bAltSetting = %d\n",
|
|
|
|
i, alt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [real world] get/set unimplemented if there's only one */
|
|
|
|
if (realworld && iface->num_altsetting == 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* [9.4.10] set_interface */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = set_altsetting(dev, alt);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev, "can't set_interface = %d, %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
alt, retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [9.4.4] get_interface always works */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = get_altsetting(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval != alt) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev, "get alt should be %d, was %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
alt, retval);
|
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [real world] get_config unimplemented if there's only one */
|
|
|
|
if (!realworld || udev->descriptor.bNumConfigurations != 1) {
|
|
|
|
int expected = udev->actconfig->desc.bConfigurationValue;
|
|
|
|
|
|
|
|
/* [9.4.2] get_configuration always works
|
|
|
|
* ... although some cheap devices (like one TI Hub I've got)
|
|
|
|
* won't return config descriptors except before set_config.
|
|
|
|
*/
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
|
2005-04-17 06:20:36 +08:00
|
|
|
USB_REQ_GET_CONFIGURATION,
|
|
|
|
USB_DIR_IN | USB_RECIP_DEVICE,
|
|
|
|
0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
|
2010-10-01 06:20:42 +08:00
|
|
|
if (retval != 1 || dev->buf[0] != expected) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev, "get config --> %d %d (1 %d)\n",
|
2005-04-23 04:17:00 +08:00
|
|
|
retval, dev->buf[0], expected);
|
2005-04-17 06:20:36 +08:00
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* there's always [9.4.3] a device descriptor [9.6.1] */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0,
|
2013-10-21 23:15:30 +08:00
|
|
|
dev->buf, sizeof(udev->descriptor));
|
|
|
|
if (retval != sizeof(udev->descriptor)) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
|
2005-04-17 06:20:36 +08:00
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
}
|
|
|
|
|
2013-10-28 23:31:32 +08:00
|
|
|
/*
|
|
|
|
* there's always [9.4.3] a bos device descriptor [9.6.2] in USB
|
|
|
|
* 3.0 spec
|
|
|
|
*/
|
|
|
|
if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0300) {
|
2013-10-30 11:27:38 +08:00
|
|
|
struct usb_bos_descriptor *bos = NULL;
|
|
|
|
struct usb_dev_cap_header *header = NULL;
|
|
|
|
unsigned total, num, length;
|
|
|
|
u8 *buf;
|
|
|
|
|
2013-10-28 23:31:32 +08:00
|
|
|
retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf,
|
|
|
|
sizeof(*udev->bos->desc));
|
|
|
|
if (retval != sizeof(*udev->bos->desc)) {
|
|
|
|
dev_err(&iface->dev, "bos descriptor --> %d\n", retval);
|
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
}
|
2013-10-30 11:27:38 +08:00
|
|
|
|
|
|
|
bos = (struct usb_bos_descriptor *)dev->buf;
|
|
|
|
total = le16_to_cpu(bos->wTotalLength);
|
|
|
|
num = bos->bNumDeviceCaps;
|
|
|
|
|
|
|
|
if (total > TBUF_SIZE)
|
|
|
|
total = TBUF_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get generic device-level capability descriptors [9.6.2]
|
|
|
|
* in USB 3.0 spec
|
|
|
|
*/
|
|
|
|
retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf,
|
|
|
|
total);
|
|
|
|
if (retval != total) {
|
|
|
|
dev_err(&iface->dev, "bos descriptor set --> %d\n",
|
|
|
|
retval);
|
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = sizeof(*udev->bos->desc);
|
|
|
|
buf = dev->buf;
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
buf += length;
|
|
|
|
if (buf + sizeof(struct usb_dev_cap_header) >
|
|
|
|
dev->buf + total)
|
|
|
|
break;
|
|
|
|
|
|
|
|
header = (struct usb_dev_cap_header *)buf;
|
|
|
|
length = header->bLength;
|
|
|
|
|
|
|
|
if (header->bDescriptorType !=
|
|
|
|
USB_DT_DEVICE_CAPABILITY) {
|
|
|
|
dev_warn(&udev->dev, "not device capability descriptor, skip\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (header->bDevCapabilityType) {
|
|
|
|
case USB_CAP_TYPE_EXT:
|
|
|
|
if (buf + USB_DT_USB_EXT_CAP_SIZE >
|
|
|
|
dev->buf + total ||
|
|
|
|
!is_good_ext(dev, buf)) {
|
|
|
|
dev_err(&iface->dev, "bogus usb 2.0 extension descriptor\n");
|
|
|
|
return -EDOM;
|
|
|
|
}
|
|
|
|
break;
|
2013-10-30 11:27:39 +08:00
|
|
|
case USB_SS_CAP_TYPE:
|
|
|
|
if (buf + USB_DT_USB_SS_CAP_SIZE >
|
|
|
|
dev->buf + total ||
|
|
|
|
!is_good_ss_cap(dev, buf)) {
|
|
|
|
dev_err(&iface->dev, "bogus superspeed device capability descriptor\n");
|
|
|
|
return -EDOM;
|
|
|
|
}
|
|
|
|
break;
|
2013-10-30 11:27:40 +08:00
|
|
|
case CONTAINER_ID_TYPE:
|
|
|
|
if (buf + USB_DT_USB_SS_CONTN_ID_SIZE >
|
|
|
|
dev->buf + total ||
|
|
|
|
!is_good_con_id(dev, buf)) {
|
|
|
|
dev_err(&iface->dev, "bogus container id descriptor\n");
|
|
|
|
return -EDOM;
|
|
|
|
}
|
|
|
|
break;
|
2013-10-30 11:27:38 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-10-28 23:31:32 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* there's always [9.4.3] at least one config descriptor [9.6.3] */
|
|
|
|
for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_get_descriptor(udev, USB_DT_CONFIG, i,
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->buf, TBUF_SIZE);
|
2008-04-26 09:51:10 +08:00
|
|
|
if (!is_good_config(dev, retval)) {
|
|
|
|
dev_err(&iface->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"config [%d] descriptor --> %d\n",
|
|
|
|
i, retval);
|
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIXME cross-checking udev->config[i] to make sure usbcore
|
|
|
|
* parsed it right (etc) would be good testing paranoia
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* and sometimes [9.2.6.6] speed dependent descriptors */
|
|
|
|
if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) {
|
2010-10-01 06:20:42 +08:00
|
|
|
struct usb_qualifier_descriptor *d = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* device qualifier [9.6.2] */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_get_descriptor(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
USB_DT_DEVICE_QUALIFIER, 0, dev->buf,
|
2010-10-01 06:20:42 +08:00
|
|
|
sizeof(struct usb_qualifier_descriptor));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval == -EPIPE) {
|
|
|
|
if (udev->speed == USB_SPEED_HIGH) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"hs dev qualifier --> %d\n",
|
|
|
|
retval);
|
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
}
|
|
|
|
/* usb2.0 but not high-speed capable; fine */
|
2010-10-01 06:20:42 +08:00
|
|
|
} else if (retval != sizeof(struct usb_qualifier_descriptor)) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev, "dev qualifier --> %d\n", retval);
|
2005-04-17 06:20:36 +08:00
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
} else
|
|
|
|
d = (struct usb_qualifier_descriptor *) dev->buf;
|
|
|
|
|
|
|
|
/* might not have [9.6.2] any other-speed configs [9.6.4] */
|
|
|
|
if (d) {
|
|
|
|
unsigned max = d->bNumConfigurations;
|
|
|
|
for (i = 0; i < max; i++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_get_descriptor(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
USB_DT_OTHER_SPEED_CONFIG, i,
|
|
|
|
dev->buf, TBUF_SIZE);
|
2008-04-26 09:51:10 +08:00
|
|
|
if (!is_good_config(dev, retval)) {
|
|
|
|
dev_err(&iface->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"other speed config --> %d\n",
|
|
|
|
retval);
|
|
|
|
return (retval < 0) ? retval : -EDOM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIXME fetch strings from at least the device descriptor */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* [9.4.5] get_status always works */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
|
2013-07-31 03:35:40 +08:00
|
|
|
if (retval) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev, "get dev status --> %d\n", retval);
|
2013-07-31 03:35:40 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIXME configuration.bmAttributes says if we could try to set/clear
|
|
|
|
* the device's remote wakeup feature ... if we can, test that here
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_get_status(udev, USB_RECIP_INTERFACE,
|
|
|
|
iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
|
2013-07-31 03:35:40 +08:00
|
|
|
if (retval) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&iface->dev, "get interface status --> %d\n", retval);
|
2013-07-31 03:35:40 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIXME get status for each endpoint in the interface */
|
2008-04-26 09:51:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* use ch9 requests to test whether:
|
|
|
|
* (a) queues work for control, keeping N subtests queued and
|
|
|
|
* active (auto-resubmit) for M loops through the queue.
|
|
|
|
* (b) protocol stalls (control-only) will autorecover.
|
|
|
|
* it's not like bulk/intr; no halt clearing.
|
|
|
|
* (c) short control reads are reported and handled.
|
|
|
|
* (d) queues are always processed in-order
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ctrl_ctx {
|
|
|
|
spinlock_t lock;
|
|
|
|
struct usbtest_dev *dev;
|
|
|
|
struct completion complete;
|
|
|
|
unsigned count;
|
|
|
|
unsigned pending;
|
|
|
|
int status;
|
|
|
|
struct urb **urb;
|
|
|
|
struct usbtest_param *param;
|
|
|
|
int last;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_SUBCASES 15 /* how many test subcases here? */
|
|
|
|
|
|
|
|
struct subcase {
|
|
|
|
struct usb_ctrlrequest setup;
|
|
|
|
int number;
|
|
|
|
int expected;
|
|
|
|
};
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static void ctrl_complete(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ctrl_ctx *ctx = urb->context;
|
|
|
|
struct usb_ctrlrequest *reqp;
|
|
|
|
struct subcase *subcase;
|
|
|
|
int status = urb->status;
|
|
|
|
|
|
|
|
reqp = (struct usb_ctrlrequest *)urb->setup_packet;
|
2010-10-01 06:20:42 +08:00
|
|
|
subcase = container_of(reqp, struct subcase, setup);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
spin_lock(&ctx->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
ctx->count--;
|
|
|
|
ctx->pending--;
|
|
|
|
|
|
|
|
/* queue must transfer and complete in fifo order, unless
|
|
|
|
* usb_unlink_urb() is used to unlink something not at the
|
|
|
|
* physical queue head (not tested).
|
|
|
|
*/
|
|
|
|
if (subcase->number > 0) {
|
|
|
|
if ((subcase->number - ctx->last) != 1) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(ctx->dev,
|
|
|
|
"subcase %d completed out of order, last %d\n",
|
|
|
|
subcase->number, ctx->last);
|
2005-04-17 06:20:36 +08:00
|
|
|
status = -EDOM;
|
|
|
|
ctx->last = subcase->number;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx->last = subcase->number;
|
|
|
|
|
|
|
|
/* succeed or fault in only one way? */
|
|
|
|
if (status == subcase->expected)
|
|
|
|
status = 0;
|
|
|
|
|
|
|
|
/* async unlink for cleanup? */
|
|
|
|
else if (status != -ECONNRESET) {
|
|
|
|
|
|
|
|
/* some faults are allowed, not required */
|
|
|
|
if (subcase->expected > 0 && (
|
2007-07-19 01:58:02 +08:00
|
|
|
((status == -subcase->expected /* happened */
|
|
|
|
|| status == 0)))) /* didn't */
|
2005-04-17 06:20:36 +08:00
|
|
|
status = 0;
|
|
|
|
/* sometimes more than one fault is allowed */
|
|
|
|
else if (subcase->number == 12 && status == -EPIPE)
|
|
|
|
status = 0;
|
|
|
|
else
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(ctx->dev, "subtest %d error, status %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
subcase->number, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unexpected status codes mean errors; ideally, in hardware */
|
|
|
|
if (status) {
|
|
|
|
error:
|
|
|
|
if (ctx->status == 0) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ctx->status = status;
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(ctx->dev, "control queue %02x.%02x, err %d, "
|
|
|
|
"%d left, subcase %d, len %d/%d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
reqp->bRequestType, reqp->bRequest,
|
2008-04-26 09:51:10 +08:00
|
|
|
status, ctx->count, subcase->number,
|
|
|
|
urb->actual_length,
|
|
|
|
urb->transfer_buffer_length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* FIXME this "unlink everything" exit route should
|
|
|
|
* be a separate test case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* unlink whatever's still pending */
|
|
|
|
for (i = 1; i < ctx->param->sglen; i++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
struct urb *u = ctx->urb[
|
|
|
|
(i + subcase->number)
|
|
|
|
% ctx->param->sglen];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (u == urb || !u->dev)
|
|
|
|
continue;
|
2006-05-16 01:23:53 +08:00
|
|
|
spin_unlock(&ctx->lock);
|
2010-10-01 06:20:42 +08:00
|
|
|
status = usb_unlink_urb(u);
|
2006-05-16 01:23:53 +08:00
|
|
|
spin_lock(&ctx->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (status) {
|
|
|
|
case -EINPROGRESS:
|
|
|
|
case -EBUSY:
|
|
|
|
case -EIDRM:
|
|
|
|
continue;
|
|
|
|
default:
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(ctx->dev, "urb unlink --> %d\n",
|
|
|
|
status);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
status = ctx->status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* resubmit if we need to, else mark this as done */
|
|
|
|
if ((status == 0) && (ctx->pending < ctx->count)) {
|
2010-10-01 06:20:42 +08:00
|
|
|
status = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (status != 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(ctx->dev,
|
|
|
|
"can't resubmit ctrl %02x.%02x, err %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
reqp->bRequestType, reqp->bRequest, status);
|
|
|
|
urb->dev = NULL;
|
|
|
|
} else
|
|
|
|
ctx->pending++;
|
|
|
|
} else
|
|
|
|
urb->dev = NULL;
|
2008-04-26 09:51:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* signal completion when nothing's queued */
|
|
|
|
if (ctx->pending == 0)
|
2010-10-01 06:20:42 +08:00
|
|
|
complete(&ctx->complete);
|
|
|
|
spin_unlock(&ctx->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-10-01 06:20:42 +08:00
|
|
|
test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-10-01 06:20:42 +08:00
|
|
|
struct usb_device *udev = testdev_to_usbdev(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct urb **urb;
|
|
|
|
struct ctrl_ctx context;
|
|
|
|
int i;
|
|
|
|
|
2012-04-10 03:48:55 +08:00
|
|
|
if (param->sglen == 0 || param->iterations > UINT_MAX / param->sglen)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
spin_lock_init(&context.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
context.dev = dev;
|
2010-10-01 06:20:42 +08:00
|
|
|
init_completion(&context.complete);
|
2005-04-17 06:20:36 +08:00
|
|
|
context.count = param->sglen * param->iterations;
|
|
|
|
context.pending = 0;
|
|
|
|
context.status = -ENOMEM;
|
|
|
|
context.param = param;
|
|
|
|
context.last = -1;
|
|
|
|
|
|
|
|
/* allocate and init the urbs we'll queue.
|
|
|
|
* as with bulk/intr sglists, sglen is the queue depth; it also
|
|
|
|
* controls which subtests run (more tests than sglen) or rerun.
|
|
|
|
*/
|
2006-12-07 12:33:17 +08:00
|
|
|
urb = kcalloc(param->sglen, sizeof(struct urb *), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb)
|
|
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < param->sglen; i++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
int pipe = usb_rcvctrlpipe(udev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned len;
|
|
|
|
struct urb *u;
|
|
|
|
struct usb_ctrlrequest req;
|
|
|
|
struct subcase *reqp;
|
usbtest: comment on why this code "expects" negative and positive errnos
On Mon, May 12, 2008 at 01:02:22AM -0700, David Brownell wrote:
> On Sunday 11 May 2008, Marcin Slusarz wrote:
> >
> > test_ctrl_queue expects (?) positive and negative errnos.
> > what is going on here?
>
> The sign is just a way to flag something:
>
> /* some faults are allowed, not required */
>
> The negative ones are required. Positive codes are optional,
> in the sense that, depending on how the peripheral happens
> to be implemented, they won't necessarily be triggered.
>
> For example, the test to fetch a device qualifier desriptor
> must succeed if the device is running at high speed. So that
> test is marked as negative. But when it's full speed, it
> could legitimately fail; marked as positive. And so on for
> other tests.
>
> Look at how the codes are *interpreted* to see it work.
Lets document it.
Based on comment from David Brownell <david-b@pacbell.net>.
Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-05-13 02:17:25 +08:00
|
|
|
|
|
|
|
/* sign of this variable means:
|
|
|
|
* -: tested code must return this (negative) error code
|
|
|
|
* +: tested code may return this (negative too) error code
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int expected = 0;
|
|
|
|
|
|
|
|
/* requests here are mostly expected to succeed on any
|
|
|
|
* device, but some are chosen to trigger protocol stalls
|
|
|
|
* or short reads.
|
|
|
|
*/
|
2013-10-21 23:15:30 +08:00
|
|
|
memset(&req, 0, sizeof(req));
|
2005-04-17 06:20:36 +08:00
|
|
|
req.bRequest = USB_REQ_GET_DESCRIPTOR;
|
|
|
|
req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
|
|
|
|
|
|
|
|
switch (i % NUM_SUBCASES) {
|
2010-10-01 06:20:42 +08:00
|
|
|
case 0: /* get device descriptor */
|
|
|
|
req.wValue = cpu_to_le16(USB_DT_DEVICE << 8);
|
|
|
|
len = sizeof(struct usb_device_descriptor);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 1: /* get first config descriptor (only) */
|
|
|
|
req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
|
|
|
|
len = sizeof(struct usb_config_descriptor);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 2: /* get altsetting (OFTEN STALLS) */
|
2005-04-17 06:20:36 +08:00
|
|
|
req.bRequest = USB_REQ_GET_INTERFACE;
|
|
|
|
req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* index = 0 means first interface */
|
2005-04-17 06:20:36 +08:00
|
|
|
len = 1;
|
|
|
|
expected = EPIPE;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 3: /* get interface status */
|
2005-04-17 06:20:36 +08:00
|
|
|
req.bRequest = USB_REQ_GET_STATUS;
|
|
|
|
req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* interface 0 */
|
2005-04-17 06:20:36 +08:00
|
|
|
len = 2;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 4: /* get device status */
|
2005-04-17 06:20:36 +08:00
|
|
|
req.bRequest = USB_REQ_GET_STATUS;
|
|
|
|
req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
|
|
|
|
len = 2;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 5: /* get device qualifier (MAY STALL) */
|
2005-04-17 06:20:36 +08:00
|
|
|
req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8);
|
2010-10-01 06:20:42 +08:00
|
|
|
len = sizeof(struct usb_qualifier_descriptor);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (udev->speed != USB_SPEED_HIGH)
|
|
|
|
expected = EPIPE;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 6: /* get first config descriptor, plus interface */
|
|
|
|
req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
|
|
|
|
len = sizeof(struct usb_config_descriptor);
|
|
|
|
len += sizeof(struct usb_interface_descriptor);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 7: /* get interface descriptor (ALWAYS STALLS) */
|
2005-04-17 06:20:36 +08:00
|
|
|
req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8);
|
2010-10-01 06:20:42 +08:00
|
|
|
/* interface == 0 */
|
|
|
|
len = sizeof(struct usb_interface_descriptor);
|
2008-04-26 09:51:10 +08:00
|
|
|
expected = -EPIPE;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* NOTE: two consecutive stalls in the queue here.
|
|
|
|
* that tests fault recovery a bit more aggressively. */
|
|
|
|
case 8: /* clear endpoint halt (MAY STALL) */
|
2005-04-17 06:20:36 +08:00
|
|
|
req.bRequest = USB_REQ_CLEAR_FEATURE;
|
|
|
|
req.bRequestType = USB_RECIP_ENDPOINT;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* wValue 0 == ep halt */
|
|
|
|
/* wIndex 0 == ep0 (shouldn't halt!) */
|
2005-04-17 06:20:36 +08:00
|
|
|
len = 0;
|
2010-10-01 06:20:42 +08:00
|
|
|
pipe = usb_sndctrlpipe(udev, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
expected = EPIPE;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 9: /* get endpoint status */
|
2005-04-17 06:20:36 +08:00
|
|
|
req.bRequest = USB_REQ_GET_STATUS;
|
|
|
|
req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* endpoint 0 */
|
2005-04-17 06:20:36 +08:00
|
|
|
len = 2;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 10: /* trigger short read (EREMOTEIO) */
|
|
|
|
req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
len = 1024;
|
|
|
|
expected = -EREMOTEIO;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* NOTE: two consecutive _different_ faults in the queue. */
|
|
|
|
case 11: /* get endpoint descriptor (ALWAYS STALLS) */
|
|
|
|
req.wValue = cpu_to_le16(USB_DT_ENDPOINT << 8);
|
|
|
|
/* endpoint == 0 */
|
|
|
|
len = sizeof(struct usb_interface_descriptor);
|
2005-04-17 06:20:36 +08:00
|
|
|
expected = EPIPE;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* NOTE: sometimes even a third fault in the queue! */
|
|
|
|
case 12: /* get string 0 descriptor (MAY STALL) */
|
|
|
|
req.wValue = cpu_to_le16(USB_DT_STRING << 8);
|
|
|
|
/* string == 0, for language IDs */
|
|
|
|
len = sizeof(struct usb_interface_descriptor);
|
|
|
|
/* may succeed when > 4 languages */
|
|
|
|
expected = EREMOTEIO; /* or EPIPE, if no strings */
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 13: /* short read, resembling case 10 */
|
|
|
|
req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
|
|
|
|
/* last data packet "should" be DATA1, not DATA0 */
|
2012-04-17 05:19:07 +08:00
|
|
|
if (udev->speed == USB_SPEED_SUPER)
|
|
|
|
len = 1024 - 512;
|
|
|
|
else
|
|
|
|
len = 1024 - udev->descriptor.bMaxPacketSize0;
|
2005-04-17 06:20:36 +08:00
|
|
|
expected = -EREMOTEIO;
|
|
|
|
break;
|
2010-10-01 06:20:42 +08:00
|
|
|
case 14: /* short read; try to fill the last packet */
|
|
|
|
req.wValue = cpu_to_le16((USB_DT_DEVICE << 8) | 0);
|
2008-04-26 09:51:10 +08:00
|
|
|
/* device descriptor size == 18 bytes */
|
2005-04-17 06:20:36 +08:00
|
|
|
len = udev->descriptor.bMaxPacketSize0;
|
2011-04-14 22:17:21 +08:00
|
|
|
if (udev->speed == USB_SPEED_SUPER)
|
|
|
|
len = 512;
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (len) {
|
2010-10-01 06:20:42 +08:00
|
|
|
case 8:
|
|
|
|
len = 24;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
len = 32;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
expected = -EREMOTEIO;
|
|
|
|
break;
|
|
|
|
default:
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(dev, "bogus number of ctrl queue testcases!\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
context.status = -EINVAL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
req.wLength = cpu_to_le16(len);
|
|
|
|
urb[i] = u = simple_alloc_urb(udev, pipe, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!u)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-10-21 23:15:30 +08:00
|
|
|
reqp = kmalloc(sizeof(*reqp), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!reqp)
|
|
|
|
goto cleanup;
|
|
|
|
reqp->setup = req;
|
|
|
|
reqp->number = i % NUM_SUBCASES;
|
|
|
|
reqp->expected = expected;
|
|
|
|
u->setup_packet = (char *) &reqp->setup;
|
|
|
|
|
|
|
|
u->context = &context;
|
|
|
|
u->complete = ctrl_complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* queue the urbs */
|
|
|
|
context.urb = urb;
|
2010-10-01 06:20:42 +08:00
|
|
|
spin_lock_irq(&context.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < param->sglen; i++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
context.status = usb_submit_urb(urb[i], GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (context.status != 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(dev, "can't submit urb[%d], status %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
i, context.status);
|
|
|
|
context.count = context.pending;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
context.pending++;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
spin_unlock_irq(&context.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* FIXME set timer and time out; provide a disconnect hook */
|
|
|
|
|
|
|
|
/* wait for the last one to complete */
|
|
|
|
if (context.pending > 0)
|
2010-10-01 06:20:42 +08:00
|
|
|
wait_for_completion(&context.complete);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (i = 0; i < param->sglen; i++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
if (!urb[i])
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2010-10-01 06:20:42 +08:00
|
|
|
urb[i]->dev = udev;
|
2010-03-06 04:10:17 +08:00
|
|
|
kfree(urb[i]->setup_packet);
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_free_urb(urb[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
kfree(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
return context.status;
|
|
|
|
}
|
|
|
|
#undef NUM_SUBCASES
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static void unlink1_callback(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int status = urb->status;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
/* we "know" -EPIPE (stall) never happens */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!status)
|
2010-10-01 06:20:42 +08:00
|
|
|
status = usb_submit_urb(urb, GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status) {
|
|
|
|
urb->status = status;
|
2008-02-24 18:41:47 +08:00
|
|
|
complete(urb->context);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct urb *urb;
|
|
|
|
struct completion completion;
|
|
|
|
int retval = 0;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
init_completion(&completion);
|
|
|
|
urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb)
|
|
|
|
return -ENOMEM;
|
|
|
|
urb->context = &completion;
|
|
|
|
urb->complete = unlink1_callback;
|
|
|
|
|
|
|
|
/* keep the endpoint busy. there are lots of hc/hcd-internal
|
|
|
|
* states, and testing should get to all of them over time.
|
|
|
|
*
|
|
|
|
* FIXME want additional tests for when endpoint is STALLing
|
|
|
|
* due to errors, or is just NAKing requests.
|
|
|
|
*/
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_submit_urb(urb, GFP_KERNEL);
|
|
|
|
if (retval != 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&dev->intf->dev, "submit fail %d\n", retval);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unlinking that should always work. variable delay tests more
|
|
|
|
* hcd states and code paths, even with little other system load.
|
|
|
|
*/
|
2010-10-01 06:20:42 +08:00
|
|
|
msleep(jiffies % (2 * INTERRUPT_RATE));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (async) {
|
2009-06-05 05:20:38 +08:00
|
|
|
while (!completion_done(&completion)) {
|
|
|
|
retval = usb_unlink_urb(urb);
|
|
|
|
|
|
|
|
switch (retval) {
|
|
|
|
case -EBUSY:
|
|
|
|
case -EIDRM:
|
|
|
|
/* we can't unlink urbs while they're completing
|
|
|
|
* or if they've completed, and we haven't
|
|
|
|
* resubmitted. "normal" drivers would prevent
|
|
|
|
* resubmission, but since we're testing unlink
|
|
|
|
* paths, we can't.
|
|
|
|
*/
|
|
|
|
ERROR(dev, "unlink retry\n");
|
|
|
|
continue;
|
|
|
|
case 0:
|
|
|
|
case -EINPROGRESS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev_err(&dev->intf->dev,
|
|
|
|
"unlink fail %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_kill_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
wait_for_completion(&completion);
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = urb->status;
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_free_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (async)
|
|
|
|
return (retval == -ECONNRESET) ? 0 : retval - 1000;
|
|
|
|
else
|
|
|
|
return (retval == -ENOENT || retval == -EPERM) ?
|
|
|
|
0 : retval - 2000;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int unlink_simple(struct usbtest_dev *dev, int pipe, int len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
/* test sync and async paths */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = unlink1(dev, pipe, len, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!retval)
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = unlink1(dev, pipe, len, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2011-04-14 23:21:04 +08:00
|
|
|
struct queued_ctx {
|
|
|
|
struct completion complete;
|
|
|
|
atomic_t pending;
|
|
|
|
unsigned num;
|
|
|
|
int status;
|
|
|
|
struct urb **urbs;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void unlink_queued_callback(struct urb *urb)
|
|
|
|
{
|
|
|
|
int status = urb->status;
|
|
|
|
struct queued_ctx *ctx = urb->context;
|
|
|
|
|
|
|
|
if (ctx->status)
|
|
|
|
goto done;
|
|
|
|
if (urb == ctx->urbs[ctx->num - 4] || urb == ctx->urbs[ctx->num - 2]) {
|
|
|
|
if (status == -ECONNRESET)
|
|
|
|
goto done;
|
|
|
|
/* What error should we report if the URB completed normally? */
|
|
|
|
}
|
|
|
|
if (status != 0)
|
|
|
|
ctx->status = status;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (atomic_dec_and_test(&ctx->pending))
|
|
|
|
complete(&ctx->complete);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
struct queued_ctx ctx;
|
|
|
|
struct usb_device *udev = testdev_to_usbdev(dev);
|
|
|
|
void *buf;
|
|
|
|
dma_addr_t buf_dma;
|
|
|
|
int i;
|
|
|
|
int retval = -ENOMEM;
|
|
|
|
|
|
|
|
init_completion(&ctx.complete);
|
|
|
|
atomic_set(&ctx.pending, 1); /* One more than the actual value */
|
|
|
|
ctx.num = num;
|
|
|
|
ctx.status = 0;
|
|
|
|
|
|
|
|
buf = usb_alloc_coherent(udev, size, GFP_KERNEL, &buf_dma);
|
|
|
|
if (!buf)
|
|
|
|
return retval;
|
|
|
|
memset(buf, 0, size);
|
|
|
|
|
|
|
|
/* Allocate and init the urbs we'll queue */
|
|
|
|
ctx.urbs = kcalloc(num, sizeof(struct urb *), GFP_KERNEL);
|
|
|
|
if (!ctx.urbs)
|
|
|
|
goto free_buf;
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
ctx.urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!ctx.urbs[i])
|
|
|
|
goto free_urbs;
|
|
|
|
usb_fill_bulk_urb(ctx.urbs[i], udev, pipe, buf, size,
|
|
|
|
unlink_queued_callback, &ctx);
|
|
|
|
ctx.urbs[i]->transfer_dma = buf_dma;
|
|
|
|
ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Submit all the URBs and then unlink URBs num - 4 and num - 2. */
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
atomic_inc(&ctx.pending);
|
|
|
|
retval = usb_submit_urb(ctx.urbs[i], GFP_KERNEL);
|
|
|
|
if (retval != 0) {
|
|
|
|
dev_err(&dev->intf->dev, "submit urbs[%d] fail %d\n",
|
|
|
|
i, retval);
|
|
|
|
atomic_dec(&ctx.pending);
|
|
|
|
ctx.status = retval;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == num) {
|
|
|
|
usb_unlink_urb(ctx.urbs[num - 4]);
|
|
|
|
usb_unlink_urb(ctx.urbs[num - 2]);
|
|
|
|
} else {
|
|
|
|
while (--i >= 0)
|
|
|
|
usb_unlink_urb(ctx.urbs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atomic_dec_and_test(&ctx.pending)) /* The extra count */
|
|
|
|
complete(&ctx.complete);
|
|
|
|
wait_for_completion(&ctx.complete);
|
|
|
|
retval = ctx.status;
|
|
|
|
|
|
|
|
free_urbs:
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
usb_free_urb(ctx.urbs[i]);
|
|
|
|
kfree(ctx.urbs);
|
|
|
|
free_buf:
|
|
|
|
usb_free_coherent(udev, size, buf, buf_dma);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2008-04-26 09:51:10 +08:00
|
|
|
static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
u16 status;
|
|
|
|
|
|
|
|
/* shouldn't look or act halted */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n",
|
|
|
|
ep, retval);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
if (status != 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "ep %02x bogus status: %04x != 0\n", ep, status);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = simple_io(tdev, urb, 1, 0, 0, __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-26 09:51:10 +08:00
|
|
|
static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
u16 status;
|
|
|
|
|
|
|
|
/* should look and act halted */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "ep %02x couldn't get halt status, %d\n",
|
|
|
|
ep, retval);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
if (status != 1) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = simple_io(tdev, urb, 1, 0, -EPIPE, __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval != -EPIPE)
|
|
|
|
return -EINVAL;
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = simple_io(tdev, urb, 1, 0, -EPIPE, "verify_still_halted");
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval != -EPIPE)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-26 09:51:10 +08:00
|
|
|
static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* shouldn't look or act halted now */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = verify_not_halted(tdev, ep, urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* set halt (protocol test only), verify it worked */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0),
|
2005-04-17 06:20:36 +08:00
|
|
|
USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT,
|
|
|
|
USB_ENDPOINT_HALT, ep,
|
|
|
|
NULL, 0, USB_CTRL_SET_TIMEOUT);
|
|
|
|
if (retval < 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "ep %02x couldn't set halt, %d\n", ep, retval);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = verify_halted(tdev, ep, urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* clear halt (tests API + protocol), verify it worked */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_clear_halt(urb->dev, urb->pipe);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = verify_not_halted(tdev, ep, urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* NOTE: could also verify SET_INTERFACE clear halts ... */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int halt_simple(struct usbtest_dev *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-04-17 05:19:07 +08:00
|
|
|
int ep;
|
|
|
|
int retval = 0;
|
|
|
|
struct urb *urb;
|
|
|
|
struct usb_device *udev = testdev_to_usbdev(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-04-17 05:19:07 +08:00
|
|
|
if (udev->speed == USB_SPEED_SUPER)
|
|
|
|
urb = simple_alloc_urb(udev, 0, 1024);
|
|
|
|
else
|
|
|
|
urb = simple_alloc_urb(udev, 0, 512);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (urb == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (dev->in_pipe) {
|
2010-10-01 06:20:42 +08:00
|
|
|
ep = usb_pipeendpoint(dev->in_pipe) | USB_DIR_IN;
|
2005-04-17 06:20:36 +08:00
|
|
|
urb->pipe = dev->in_pipe;
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = test_halt(dev, ep, urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->out_pipe) {
|
2010-10-01 06:20:42 +08:00
|
|
|
ep = usb_pipeendpoint(dev->out_pipe);
|
2005-04-17 06:20:36 +08:00
|
|
|
urb->pipe = dev->out_pipe;
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = test_halt(dev, ep, urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
done:
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_free_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* Control OUT tests use the vendor control requests from Intel's
|
|
|
|
* USB 2.0 compliance test device: write a buffer, read it back.
|
|
|
|
*
|
|
|
|
* Intel's spec only _requires_ that it work for one packet, which
|
|
|
|
* is pretty weak. Some HCDs place limits here; most devices will
|
|
|
|
* need to be able to handle more than one OUT data packet. We'll
|
|
|
|
* try whatever we're told to try.
|
|
|
|
*/
|
2010-10-01 06:20:42 +08:00
|
|
|
static int ctrl_out(struct usbtest_dev *dev,
|
2011-01-17 02:17:11 +08:00
|
|
|
unsigned count, unsigned length, unsigned vary, unsigned offset)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-08-09 14:31:40 +08:00
|
|
|
unsigned i, j, len;
|
|
|
|
int retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
u8 *buf;
|
|
|
|
char *what = "?";
|
|
|
|
struct usb_device *udev;
|
2006-08-09 14:31:40 +08:00
|
|
|
|
2005-04-23 04:17:00 +08:00
|
|
|
if (length < 1 || length > 0xffff || vary >= length)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
buf = kmalloc(length + offset, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
buf += offset;
|
2010-10-01 06:20:42 +08:00
|
|
|
udev = testdev_to_usbdev(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
len = length;
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
/* NOTE: hardware might well act differently if we pushed it
|
|
|
|
* with lots back-to-back queued requests.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
/* write patterned data */
|
|
|
|
for (j = 0; j < len; j++)
|
2010-10-01 06:20:42 +08:00
|
|
|
buf[j] = i + j;
|
|
|
|
retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
|
2005-04-17 06:20:36 +08:00
|
|
|
0x5b, USB_DIR_OUT|USB_TYPE_VENDOR,
|
|
|
|
0, 0, buf, len, USB_CTRL_SET_TIMEOUT);
|
|
|
|
if (retval != len) {
|
|
|
|
what = "write";
|
2005-04-23 04:17:00 +08:00
|
|
|
if (retval >= 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(dev, "ctrl_out, wlen %d (expected %d)\n",
|
2005-04-23 04:17:00 +08:00
|
|
|
retval, len);
|
|
|
|
retval = -EBADMSG;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read it back -- assuming nothing intervened!! */
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
|
2005-04-17 06:20:36 +08:00
|
|
|
0x5c, USB_DIR_IN|USB_TYPE_VENDOR,
|
|
|
|
0, 0, buf, len, USB_CTRL_GET_TIMEOUT);
|
|
|
|
if (retval != len) {
|
|
|
|
what = "read";
|
2005-04-23 04:17:00 +08:00
|
|
|
if (retval >= 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(dev, "ctrl_out, rlen %d (expected %d)\n",
|
2005-04-23 04:17:00 +08:00
|
|
|
retval, len);
|
|
|
|
retval = -EBADMSG;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fail if we can't verify */
|
|
|
|
for (j = 0; j < len; j++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
if (buf[j] != (u8) (i + j)) {
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(dev, "ctrl_out, byte %d is %d not %d\n",
|
2010-10-01 06:20:42 +08:00
|
|
|
j, buf[j], (u8) i + j);
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = -EBADMSG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (retval < 0) {
|
|
|
|
what = "verify";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
len += vary;
|
2005-04-23 04:17:00 +08:00
|
|
|
|
|
|
|
/* [real world] the "zero bytes IN" case isn't really used.
|
2007-12-18 03:40:18 +08:00
|
|
|
* hardware can easily trip up in this weird case, since its
|
2005-04-23 04:17:00 +08:00
|
|
|
* status stage is IN, not OUT like other ep0in transfers.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (len > length)
|
2005-04-23 04:17:00 +08:00
|
|
|
len = realworld ? 1 : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (retval < 0)
|
2010-10-01 06:20:42 +08:00
|
|
|
ERROR(dev, "ctrl_out %s failed, code %d, count %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
what, retval, i);
|
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
kfree(buf - offset);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* ISO tests ... mimics common usage
|
|
|
|
* - buffer length is split into N packets (mostly maxpacket sized)
|
|
|
|
* - multi-buffers according to sglen
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct iso_context {
|
|
|
|
unsigned count;
|
|
|
|
unsigned pending;
|
|
|
|
spinlock_t lock;
|
|
|
|
struct completion done;
|
2006-05-23 04:47:13 +08:00
|
|
|
int submit_error;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long errors;
|
2006-05-23 04:47:13 +08:00
|
|
|
unsigned long packet_count;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usbtest_dev *dev;
|
|
|
|
};
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static void iso_callback(struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct iso_context *ctx = urb->context;
|
|
|
|
|
|
|
|
spin_lock(&ctx->lock);
|
|
|
|
ctx->count--;
|
|
|
|
|
2006-05-23 04:47:13 +08:00
|
|
|
ctx->packet_count += urb->number_of_packets;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (urb->error_count > 0)
|
|
|
|
ctx->errors += urb->error_count;
|
2006-05-23 04:47:13 +08:00
|
|
|
else if (urb->status != 0)
|
|
|
|
ctx->errors += urb->number_of_packets;
|
2010-10-01 06:20:48 +08:00
|
|
|
else if (urb->actual_length != urb->transfer_buffer_length)
|
|
|
|
ctx->errors++;
|
2011-01-17 02:17:11 +08:00
|
|
|
else if (check_guard_bytes(ctx->dev, urb) != 0)
|
|
|
|
ctx->errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-05-23 04:47:13 +08:00
|
|
|
if (urb->status == 0 && ctx->count > (ctx->pending - 1)
|
|
|
|
&& !ctx->submit_error) {
|
2010-10-01 06:20:42 +08:00
|
|
|
int status = usb_submit_urb(urb, GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (status) {
|
|
|
|
case 0:
|
|
|
|
goto done;
|
|
|
|
default:
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&ctx->dev->intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"iso resubmit err %d\n",
|
|
|
|
status);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case -ENODEV: /* disconnected */
|
2006-05-23 04:47:13 +08:00
|
|
|
case -ESHUTDOWN: /* endpoint disabled */
|
|
|
|
ctx->submit_error = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->pending--;
|
|
|
|
if (ctx->pending == 0) {
|
|
|
|
if (ctx->errors)
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&ctx->dev->intf->dev,
|
2006-05-23 04:47:13 +08:00
|
|
|
"iso test, %lu errors out of %lu\n",
|
|
|
|
ctx->errors, ctx->packet_count);
|
2010-10-01 06:20:42 +08:00
|
|
|
complete(&ctx->done);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
done:
|
|
|
|
spin_unlock(&ctx->lock);
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static struct urb *iso_alloc_urb(
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usb_device *udev,
|
|
|
|
int pipe,
|
|
|
|
struct usb_endpoint_descriptor *desc,
|
2011-01-17 02:17:11 +08:00
|
|
|
long bytes,
|
|
|
|
unsigned offset
|
2005-04-17 06:20:36 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
struct urb *urb;
|
|
|
|
unsigned i, maxp, packets;
|
|
|
|
|
|
|
|
if (bytes < 0 || !desc)
|
|
|
|
return NULL;
|
2011-08-23 18:12:03 +08:00
|
|
|
maxp = 0x7ff & usb_endpoint_maxp(desc);
|
|
|
|
maxp *= 1 + (0x3 & (usb_endpoint_maxp(desc) >> 11));
|
2008-03-05 07:25:11 +08:00
|
|
|
packets = DIV_ROUND_UP(bytes, maxp);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
urb = usb_alloc_urb(packets, GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb)
|
|
|
|
return urb;
|
|
|
|
urb->dev = udev;
|
|
|
|
urb->pipe = pipe;
|
|
|
|
|
|
|
|
urb->number_of_packets = packets;
|
|
|
|
urb->transfer_buffer_length = bytes;
|
2011-01-17 02:17:11 +08:00
|
|
|
urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
|
|
|
|
GFP_KERNEL,
|
|
|
|
&urb->transfer_dma);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb->transfer_buffer) {
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_free_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-17 02:17:11 +08:00
|
|
|
if (offset) {
|
|
|
|
memset(urb->transfer_buffer, GUARD_BYTE, offset);
|
|
|
|
urb->transfer_buffer += offset;
|
|
|
|
urb->transfer_dma += offset;
|
|
|
|
}
|
|
|
|
/* For inbound transfers use guard byte so that test fails if
|
|
|
|
data not correctly copied */
|
|
|
|
memset(urb->transfer_buffer,
|
|
|
|
usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
|
|
|
|
bytes);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < packets; i++) {
|
|
|
|
/* here, only the last packet will be short */
|
2010-10-01 06:20:42 +08:00
|
|
|
urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp);
|
2005-04-17 06:20:36 +08:00
|
|
|
bytes -= urb->iso_frame_desc[i].length;
|
|
|
|
|
|
|
|
urb->iso_frame_desc[i].offset = maxp * i;
|
|
|
|
}
|
|
|
|
|
|
|
|
urb->complete = iso_callback;
|
2010-10-01 06:20:42 +08:00
|
|
|
/* urb->context = SET BY CALLER */
|
2005-04-17 06:20:36 +08:00
|
|
|
urb->interval = 1 << (desc->bInterval - 1);
|
|
|
|
urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
|
|
|
|
return urb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-10-01 06:20:42 +08:00
|
|
|
test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
|
2011-01-17 02:17:11 +08:00
|
|
|
int pipe, struct usb_endpoint_descriptor *desc, unsigned offset)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct iso_context context;
|
|
|
|
struct usb_device *udev;
|
|
|
|
unsigned i;
|
|
|
|
unsigned long packets = 0;
|
2006-05-23 04:47:13 +08:00
|
|
|
int status = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct urb *urbs[10]; /* FIXME no limit */
|
|
|
|
|
|
|
|
if (param->sglen > 10)
|
|
|
|
return -EDOM;
|
|
|
|
|
2013-10-21 23:15:30 +08:00
|
|
|
memset(&context, 0, sizeof(context));
|
2005-04-17 06:20:36 +08:00
|
|
|
context.count = param->iterations * param->sglen;
|
|
|
|
context.dev = dev;
|
2010-10-01 06:20:42 +08:00
|
|
|
init_completion(&context.done);
|
|
|
|
spin_lock_init(&context.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-21 23:15:30 +08:00
|
|
|
memset(urbs, 0, sizeof(urbs));
|
2010-10-01 06:20:42 +08:00
|
|
|
udev = testdev_to_usbdev(dev);
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&dev->intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"... iso period %d %sframes, wMaxPacket %04x\n",
|
|
|
|
1 << (desc->bInterval - 1),
|
|
|
|
(udev->speed == USB_SPEED_HIGH) ? "micro" : "",
|
2011-08-23 18:12:03 +08:00
|
|
|
usb_endpoint_maxp(desc));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < param->sglen; i++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
urbs[i] = iso_alloc_urb(udev, pipe, desc,
|
2011-01-17 02:17:11 +08:00
|
|
|
param->length, offset);
|
2010-10-01 06:20:42 +08:00
|
|
|
if (!urbs[i]) {
|
2005-04-17 06:20:36 +08:00
|
|
|
status = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
packets += urbs[i]->number_of_packets;
|
2010-10-01 06:20:42 +08:00
|
|
|
urbs[i]->context = &context;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
packets *= param->iterations;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&dev->intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"... total %lu msec (%lu packets)\n",
|
|
|
|
(packets * (1 << (desc->bInterval - 1)))
|
|
|
|
/ ((udev->speed == USB_SPEED_HIGH) ? 8 : 1),
|
|
|
|
packets);
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
spin_lock_irq(&context.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < param->sglen; i++) {
|
2006-05-23 04:47:13 +08:00
|
|
|
++context.pending;
|
2010-10-01 06:20:42 +08:00
|
|
|
status = usb_submit_urb(urbs[i], GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status < 0) {
|
2010-10-01 06:20:42 +08:00
|
|
|
ERROR(dev, "submit iso[%d], error %d\n", i, status);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (i == 0) {
|
2010-10-01 06:20:42 +08:00
|
|
|
spin_unlock_irq(&context.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_free_urb(urbs[i]);
|
2010-08-02 22:09:01 +08:00
|
|
|
urbs[i] = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
context.pending--;
|
2006-05-23 04:47:13 +08:00
|
|
|
context.submit_error = 1;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
spin_unlock_irq(&context.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
wait_for_completion(&context.done);
|
2006-05-23 04:47:13 +08:00
|
|
|
|
2010-08-02 22:09:01 +08:00
|
|
|
for (i = 0; i < param->sglen; i++) {
|
|
|
|
if (urbs[i])
|
|
|
|
simple_free_urb(urbs[i]);
|
|
|
|
}
|
2006-05-23 04:47:13 +08:00
|
|
|
/*
|
|
|
|
* Isochronous transfers are expected to fail sometimes. As an
|
|
|
|
* arbitrary limit, we will report an error if any submissions
|
|
|
|
* fail or if the transfer failure rate is > 10%.
|
|
|
|
*/
|
|
|
|
if (status != 0)
|
|
|
|
;
|
|
|
|
else if (context.submit_error)
|
|
|
|
status = -EACCES;
|
|
|
|
else if (context.errors > context.packet_count / 10)
|
|
|
|
status = -EIO;
|
|
|
|
return status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
for (i = 0; i < param->sglen; i++) {
|
2010-10-01 06:20:42 +08:00
|
|
|
if (urbs[i])
|
|
|
|
simple_free_urb(urbs[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
static int test_unaligned_bulk(
|
|
|
|
struct usbtest_dev *tdev,
|
|
|
|
int pipe,
|
|
|
|
unsigned length,
|
|
|
|
int iterations,
|
|
|
|
unsigned transfer_flags,
|
|
|
|
const char *label)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
struct urb *urb = usbtest_alloc_urb(
|
|
|
|
testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1);
|
|
|
|
|
|
|
|
if (!urb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
retval = simple_io(tdev, urb, iterations, 0, 0, label);
|
|
|
|
simple_free_urb(urb);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* We only have this one interface to user space, through usbfs.
|
|
|
|
* User mode code can scan usbfs to find N different devices (maybe on
|
|
|
|
* different busses) to use when testing, and allocate one thread per
|
|
|
|
* test. So discovery is simplified, and we have no device naming issues.
|
|
|
|
*
|
|
|
|
* Don't use these only as stress/load tests. Use them along with with
|
|
|
|
* other USB bus activity: plugging, unplugging, mousing, mp3 playback,
|
|
|
|
* video capture, and so on. Run different tests at different times, in
|
|
|
|
* different sequences. Nothing here should interact with other devices,
|
|
|
|
* except indirectly by consuming USB bandwidth and CPU resources for test
|
|
|
|
* threads and request completion. But the only way to know that for sure
|
|
|
|
* is to test when HC queues are in use by many devices.
|
2008-04-26 09:51:10 +08:00
|
|
|
*
|
|
|
|
* WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(),
|
|
|
|
* it locks out usbcore in certain code paths. Notably, if you disconnect
|
|
|
|
* the device-under-test, khubd will wait block forever waiting for the
|
|
|
|
* ioctl to complete ... so that usb_disconnect() can abort the pending
|
|
|
|
* urbs and then call usbtest_disconnect(). To abort a test, you're best
|
|
|
|
* off just killing the userspace task and waiting for it to exit.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2010-10-01 06:20:42 +08:00
|
|
|
usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-10-01 06:20:42 +08:00
|
|
|
struct usbtest_dev *dev = usb_get_intfdata(intf);
|
|
|
|
struct usb_device *udev = testdev_to_usbdev(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct usbtest_param *param = buf;
|
|
|
|
int retval = -EOPNOTSUPP;
|
|
|
|
struct urb *urb;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
struct usb_sg_request req;
|
|
|
|
struct timeval start;
|
|
|
|
unsigned i;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-10 11:24:32 +08:00
|
|
|
pattern = mod_pattern;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (code != USBTEST_REQUEST)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2008-10-21 12:36:44 +08:00
|
|
|
if (param->iterations <= 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2007-12-14 08:15:33 +08:00
|
|
|
if (mutex_lock_interruptible(&dev->lock))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
2008-03-07 06:00:58 +08:00
|
|
|
/* FIXME: What if a system sleep starts while a test is running? */
|
2005-04-23 04:17:00 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* some devices, like ez-usb default devices, need a non-default
|
|
|
|
* altsetting to have any active endpoints. some tests change
|
|
|
|
* altsettings; force a default so most tests don't need to check.
|
|
|
|
*/
|
|
|
|
if (dev->info->alt >= 0) {
|
2008-04-26 09:51:10 +08:00
|
|
|
int res;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (intf->altsetting->desc.bInterfaceNumber) {
|
2007-12-14 08:15:33 +08:00
|
|
|
mutex_unlock(&dev->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
res = set_altsetting(dev, dev->info->alt);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (res) {
|
2010-10-01 06:20:42 +08:00
|
|
|
dev_err(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"set altsetting to %d failed, %d\n",
|
|
|
|
dev->info->alt, res);
|
2007-12-14 08:15:33 +08:00
|
|
|
mutex_unlock(&dev->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just a bunch of test cases that every HCD is expected to handle.
|
|
|
|
*
|
|
|
|
* Some may need specific firmware, though it'd be good to have
|
|
|
|
* one firmware image to handle all the test cases.
|
|
|
|
*
|
|
|
|
* FIXME add more tests! cancel requests, verify the data, control
|
|
|
|
* queueing, concurrent read+write threads, and so on.
|
|
|
|
*/
|
2010-10-01 06:20:42 +08:00
|
|
|
do_gettimeofday(&start);
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (param->test_num) {
|
|
|
|
|
|
|
|
case 0:
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev, "TEST 0: NOP\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Simple non-queued bulk I/O tests */
|
|
|
|
case 1:
|
|
|
|
if (dev->out_pipe == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 1: write %d bytes %u times\n",
|
|
|
|
param->length, param->iterations);
|
2010-10-01 06:20:42 +08:00
|
|
|
urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: bulk sink (maybe accepts short writes) */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = simple_io(dev, urb, param->iterations, 0, 0, "test1");
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_free_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (dev->in_pipe == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 2: read %d bytes %u times\n",
|
|
|
|
param->length, param->iterations);
|
2010-10-01 06:20:42 +08:00
|
|
|
urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: bulk source (maybe generates short writes) */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = simple_io(dev, urb, param->iterations, 0, 0, "test2");
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_free_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (dev->out_pipe == 0 || param->vary == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 3: write/%d 0..%d bytes %u times\n",
|
|
|
|
param->vary, param->length, param->iterations);
|
2010-10-01 06:20:42 +08:00
|
|
|
urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: bulk sink (maybe accepts short writes) */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = simple_io(dev, urb, param->iterations, param->vary,
|
2005-04-17 06:20:36 +08:00
|
|
|
0, "test3");
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_free_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (dev->in_pipe == 0 || param->vary == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 4: read/%d 0..%d bytes %u times\n",
|
|
|
|
param->vary, param->length, param->iterations);
|
2010-10-01 06:20:42 +08:00
|
|
|
urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!urb) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: bulk source (maybe generates short writes) */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = simple_io(dev, urb, param->iterations, param->vary,
|
2005-04-17 06:20:36 +08:00
|
|
|
0, "test4");
|
2010-10-01 06:20:42 +08:00
|
|
|
simple_free_urb(urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Queued bulk I/O tests */
|
|
|
|
case 5:
|
|
|
|
if (dev->out_pipe == 0 || param->sglen == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 5: write %d sglists %d entries of %d bytes\n",
|
|
|
|
param->iterations,
|
|
|
|
param->sglen, param->length);
|
2010-10-01 06:20:42 +08:00
|
|
|
sg = alloc_sglist(param->sglen, param->length, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sg) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: bulk sink (maybe accepts short writes) */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = perform_sglist(dev, param->iterations, dev->out_pipe,
|
2005-04-17 06:20:36 +08:00
|
|
|
&req, sg, param->sglen);
|
2010-10-01 06:20:42 +08:00
|
|
|
free_sglist(sg, param->sglen);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
if (dev->in_pipe == 0 || param->sglen == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 6: read %d sglists %d entries of %d bytes\n",
|
|
|
|
param->iterations,
|
|
|
|
param->sglen, param->length);
|
2010-10-01 06:20:42 +08:00
|
|
|
sg = alloc_sglist(param->sglen, param->length, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sg) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: bulk source (maybe generates short writes) */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = perform_sglist(dev, param->iterations, dev->in_pipe,
|
2005-04-17 06:20:36 +08:00
|
|
|
&req, sg, param->sglen);
|
2010-10-01 06:20:42 +08:00
|
|
|
free_sglist(sg, param->sglen);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 7: write/%d %d sglists %d entries 0..%d bytes\n",
|
|
|
|
param->vary, param->iterations,
|
|
|
|
param->sglen, param->length);
|
2010-10-01 06:20:42 +08:00
|
|
|
sg = alloc_sglist(param->sglen, param->length, param->vary);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sg) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: bulk sink (maybe accepts short writes) */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = perform_sglist(dev, param->iterations, dev->out_pipe,
|
2005-04-17 06:20:36 +08:00
|
|
|
&req, sg, param->sglen);
|
2010-10-01 06:20:42 +08:00
|
|
|
free_sglist(sg, param->sglen);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 8: read/%d %d sglists %d entries 0..%d bytes\n",
|
|
|
|
param->vary, param->iterations,
|
|
|
|
param->sglen, param->length);
|
2010-10-01 06:20:42 +08:00
|
|
|
sg = alloc_sglist(param->sglen, param->length, param->vary);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sg) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: bulk source (maybe generates short writes) */
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = perform_sglist(dev, param->iterations, dev->in_pipe,
|
2005-04-17 06:20:36 +08:00
|
|
|
&req, sg, param->sglen);
|
2010-10-01 06:20:42 +08:00
|
|
|
free_sglist(sg, param->sglen);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* non-queued sanity tests for control (chapter 9 subset) */
|
|
|
|
case 9:
|
|
|
|
retval = 0;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 9: ch9 (subset) control tests, %d times\n",
|
|
|
|
param->iterations);
|
|
|
|
for (i = param->iterations; retval == 0 && i--; /* NOP */)
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = ch9_postconfig(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval)
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&intf->dev, "ch9 subset failed, "
|
|
|
|
"iterations left %d\n", i);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* queued control messaging */
|
|
|
|
case 10:
|
|
|
|
retval = 0;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 10: queue %d control calls, %d times\n",
|
|
|
|
param->sglen,
|
|
|
|
param->iterations);
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = test_ctrl_queue(dev, param);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* simple non-queued unlinks (ring with one urb) */
|
|
|
|
case 11:
|
|
|
|
if (dev->in_pipe == 0 || !param->length)
|
|
|
|
break;
|
|
|
|
retval = 0;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
param->iterations, param->length);
|
|
|
|
for (i = param->iterations; retval == 0 && i--; /* NOP */)
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = unlink_simple(dev, dev->in_pipe,
|
2005-04-17 06:20:36 +08:00
|
|
|
param->length);
|
|
|
|
if (retval)
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&intf->dev, "unlink reads failed %d, "
|
2005-04-17 06:20:36 +08:00
|
|
|
"iterations left %d\n", retval, i);
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
if (dev->out_pipe == 0 || !param->length)
|
|
|
|
break;
|
|
|
|
retval = 0;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
param->iterations, param->length);
|
|
|
|
for (i = param->iterations; retval == 0 && i--; /* NOP */)
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = unlink_simple(dev, dev->out_pipe,
|
2005-04-17 06:20:36 +08:00
|
|
|
param->length);
|
|
|
|
if (retval)
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_err(&intf->dev, "unlink writes failed %d, "
|
2005-04-17 06:20:36 +08:00
|
|
|
"iterations left %d\n", retval, i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* ep halt tests */
|
|
|
|
case 13:
|
|
|
|
if (dev->out_pipe == 0 && dev->in_pipe == 0)
|
|
|
|
break;
|
|
|
|
retval = 0;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev, "TEST 13: set/clear %d halts\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
param->iterations);
|
|
|
|
for (i = param->iterations; retval == 0 && i--; /* NOP */)
|
2010-10-01 06:20:42 +08:00
|
|
|
retval = halt_simple(dev);
|
2008-04-26 09:51:10 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval)
|
2008-04-26 09:51:10 +08:00
|
|
|
ERROR(dev, "halts failed, iterations left %d\n", i);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* control write tests */
|
|
|
|
case 14:
|
|
|
|
if (!dev->info->ctrl_out)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n",
|
2005-04-23 04:17:00 +08:00
|
|
|
param->iterations,
|
|
|
|
realworld ? 1 : 0, param->length,
|
|
|
|
param->vary);
|
2008-04-26 09:51:10 +08:00
|
|
|
retval = ctrl_out(dev, param->iterations,
|
2011-01-17 02:17:11 +08:00
|
|
|
param->length, param->vary, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* iso write tests */
|
|
|
|
case 15:
|
|
|
|
if (dev->out_iso_pipe == 0 || param->sglen == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 15: write %d iso, %d entries of %d bytes\n",
|
|
|
|
param->iterations,
|
|
|
|
param->sglen, param->length);
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: iso sink */
|
|
|
|
retval = test_iso_queue(dev, param,
|
2011-01-17 02:17:11 +08:00
|
|
|
dev->out_iso_pipe, dev->iso_out, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* iso read tests */
|
|
|
|
case 16:
|
|
|
|
if (dev->in_iso_pipe == 0 || param->sglen == 0)
|
|
|
|
break;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"TEST 16: read %d iso, %d entries of %d bytes\n",
|
|
|
|
param->iterations,
|
|
|
|
param->sglen, param->length);
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIRMWARE: iso source */
|
|
|
|
retval = test_iso_queue(dev, param,
|
2011-01-17 02:17:11 +08:00
|
|
|
dev->in_iso_pipe, dev->iso_in, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
/* FIXME scatterlist cancel (needs helper thread) */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-01-17 02:17:11 +08:00
|
|
|
/* Tests for bulk I/O using DMA mapping by core and odd address */
|
|
|
|
case 17:
|
|
|
|
if (dev->out_pipe == 0)
|
|
|
|
break;
|
|
|
|
dev_info(&intf->dev,
|
|
|
|
"TEST 17: write odd addr %d bytes %u times core map\n",
|
|
|
|
param->length, param->iterations);
|
|
|
|
|
|
|
|
retval = test_unaligned_bulk(
|
|
|
|
dev, dev->out_pipe,
|
|
|
|
param->length, param->iterations,
|
|
|
|
0, "test17");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 18:
|
|
|
|
if (dev->in_pipe == 0)
|
|
|
|
break;
|
|
|
|
dev_info(&intf->dev,
|
|
|
|
"TEST 18: read odd addr %d bytes %u times core map\n",
|
|
|
|
param->length, param->iterations);
|
|
|
|
|
|
|
|
retval = test_unaligned_bulk(
|
|
|
|
dev, dev->in_pipe,
|
|
|
|
param->length, param->iterations,
|
|
|
|
0, "test18");
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Tests for bulk I/O using premapped coherent buffer and odd address */
|
|
|
|
case 19:
|
|
|
|
if (dev->out_pipe == 0)
|
|
|
|
break;
|
|
|
|
dev_info(&intf->dev,
|
|
|
|
"TEST 19: write odd addr %d bytes %u times premapped\n",
|
|
|
|
param->length, param->iterations);
|
|
|
|
|
|
|
|
retval = test_unaligned_bulk(
|
|
|
|
dev, dev->out_pipe,
|
|
|
|
param->length, param->iterations,
|
|
|
|
URB_NO_TRANSFER_DMA_MAP, "test19");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 20:
|
|
|
|
if (dev->in_pipe == 0)
|
|
|
|
break;
|
|
|
|
dev_info(&intf->dev,
|
|
|
|
"TEST 20: read odd addr %d bytes %u times premapped\n",
|
|
|
|
param->length, param->iterations);
|
|
|
|
|
|
|
|
retval = test_unaligned_bulk(
|
|
|
|
dev, dev->in_pipe,
|
|
|
|
param->length, param->iterations,
|
|
|
|
URB_NO_TRANSFER_DMA_MAP, "test20");
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* control write tests with unaligned buffer */
|
|
|
|
case 21:
|
|
|
|
if (!dev->info->ctrl_out)
|
|
|
|
break;
|
|
|
|
dev_info(&intf->dev,
|
|
|
|
"TEST 21: %d ep0out odd addr, %d..%d vary %d\n",
|
|
|
|
param->iterations,
|
|
|
|
realworld ? 1 : 0, param->length,
|
|
|
|
param->vary);
|
|
|
|
retval = ctrl_out(dev, param->iterations,
|
|
|
|
param->length, param->vary, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* unaligned iso tests */
|
|
|
|
case 22:
|
|
|
|
if (dev->out_iso_pipe == 0 || param->sglen == 0)
|
|
|
|
break;
|
|
|
|
dev_info(&intf->dev,
|
|
|
|
"TEST 22: write %d iso odd, %d entries of %d bytes\n",
|
|
|
|
param->iterations,
|
|
|
|
param->sglen, param->length);
|
|
|
|
retval = test_iso_queue(dev, param,
|
|
|
|
dev->out_iso_pipe, dev->iso_out, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 23:
|
|
|
|
if (dev->in_iso_pipe == 0 || param->sglen == 0)
|
|
|
|
break;
|
|
|
|
dev_info(&intf->dev,
|
|
|
|
"TEST 23: read %d iso odd, %d entries of %d bytes\n",
|
|
|
|
param->iterations,
|
|
|
|
param->sglen, param->length);
|
|
|
|
retval = test_iso_queue(dev, param,
|
|
|
|
dev->in_iso_pipe, dev->iso_in, 1);
|
|
|
|
break;
|
|
|
|
|
2011-04-14 23:21:04 +08:00
|
|
|
/* unlink URBs from a bulk-OUT queue */
|
|
|
|
case 24:
|
|
|
|
if (dev->out_pipe == 0 || !param->length || param->sglen < 4)
|
|
|
|
break;
|
|
|
|
retval = 0;
|
2013-01-03 02:58:18 +08:00
|
|
|
dev_info(&intf->dev, "TEST 24: unlink from %d queues of "
|
2011-04-14 23:21:04 +08:00
|
|
|
"%d %d-byte writes\n",
|
|
|
|
param->iterations, param->sglen, param->length);
|
|
|
|
for (i = param->iterations; retval == 0 && i > 0; --i) {
|
|
|
|
retval = unlink_queued(dev, dev->out_pipe,
|
|
|
|
param->sglen, param->length);
|
|
|
|
if (retval) {
|
|
|
|
dev_err(&intf->dev,
|
|
|
|
"unlink queued writes failed %d, "
|
|
|
|
"iterations left %d\n", retval, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
do_gettimeofday(¶m->duration);
|
2005-04-17 06:20:36 +08:00
|
|
|
param->duration.tv_sec -= start.tv_sec;
|
|
|
|
param->duration.tv_usec -= start.tv_usec;
|
|
|
|
if (param->duration.tv_usec < 0) {
|
|
|
|
param->duration.tv_usec += 1000 * 1000;
|
|
|
|
param->duration.tv_sec -= 1;
|
|
|
|
}
|
2007-12-14 08:15:33 +08:00
|
|
|
mutex_unlock(&dev->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static unsigned force_interrupt;
|
|
|
|
module_param(force_interrupt, uint, 0);
|
|
|
|
MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef GENERIC
|
|
|
|
static unsigned short vendor;
|
|
|
|
module_param(vendor, ushort, 0);
|
2010-10-01 06:20:42 +08:00
|
|
|
MODULE_PARM_DESC(vendor, "vendor code (from usb-if)");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static unsigned short product;
|
|
|
|
module_param(product, ushort, 0);
|
2010-10-01 06:20:42 +08:00
|
|
|
MODULE_PARM_DESC(product, "product code (from vendor)");
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2010-10-01 06:20:42 +08:00
|
|
|
usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct usb_device *udev;
|
|
|
|
struct usbtest_dev *dev;
|
|
|
|
struct usbtest_info *info;
|
|
|
|
char *rtest, *wtest;
|
|
|
|
char *irtest, *iwtest;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
udev = interface_to_usbdev(intf);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef GENERIC
|
|
|
|
/* specify devices by module parameters? */
|
|
|
|
if (id->match_flags == 0) {
|
|
|
|
/* vendor match required, product match optional */
|
|
|
|
if (!vendor || le16_to_cpu(udev->descriptor.idVendor) != (u16)vendor)
|
|
|
|
return -ENODEV;
|
|
|
|
if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product)
|
|
|
|
return -ENODEV;
|
2008-04-26 09:51:10 +08:00
|
|
|
dev_info(&intf->dev, "matched module params, "
|
|
|
|
"vend=0x%04x prod=0x%04x\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
le16_to_cpu(udev->descriptor.idVendor),
|
|
|
|
le16_to_cpu(udev->descriptor.idProduct));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-12-07 12:33:17 +08:00
|
|
|
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
info = (struct usbtest_info *) id->driver_info;
|
|
|
|
dev->info = info;
|
2007-12-14 08:15:33 +08:00
|
|
|
mutex_init(&dev->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dev->intf = intf;
|
|
|
|
|
|
|
|
/* cacheline-aligned scratch for i/o */
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL);
|
|
|
|
if (dev->buf == NULL) {
|
|
|
|
kfree(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE this doesn't yet test the handful of difference that are
|
|
|
|
* visible with high speed interrupts: bigger maxpacket (1K) and
|
|
|
|
* "high bandwidth" modes (up to 3 packets/uframe).
|
|
|
|
*/
|
|
|
|
rtest = wtest = "";
|
|
|
|
irtest = iwtest = "";
|
|
|
|
if (force_interrupt || udev->speed == USB_SPEED_LOW) {
|
|
|
|
if (info->ep_in) {
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->in_pipe = usb_rcvintpipe(udev, info->ep_in);
|
2005-04-17 06:20:36 +08:00
|
|
|
rtest = " intr-in";
|
|
|
|
}
|
|
|
|
if (info->ep_out) {
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->out_pipe = usb_sndintpipe(udev, info->ep_out);
|
2005-04-17 06:20:36 +08:00
|
|
|
wtest = " intr-out";
|
|
|
|
}
|
|
|
|
} else {
|
USB: altsetting overrides for usbtest
The usbtest driver includes some rather simple-minded logic for
selecting an altsetting to test. It doesn't work well for the g_zero
gadget, because it selects altsetting 0 (which doesn't have
isochronous endpoints) rather than altsetting 1 (which does have them,
if the gadget's hardware supports them). This prevents usbtest's
isochronous tests (15, 16, 22, and 23) from working with g_zero.
Since g_zero is one of the most common gadget drivers used for USB
testing, usbtest should do a better job of supporting it. But since
some programs may rely on the current scheme for selecting
altsettings, I didn't want to change it.
Instead, this patch (as1655) adds a module parameter to usbtest, which
can be used to override the default altsetting. Since usbtest is
never used by normal users (most distributions probably don't even
build it), the new module parameter won't inconvenience anybody. In
any case, it is entirely optional -- leaving it unset preserves the
existing behavior.
The patch also fixes a related bug in usbtest: After selecting an
altsetting, the driver neglects to store its selection.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-01-31 05:38:11 +08:00
|
|
|
if (override_alt >= 0 || info->autoconf) {
|
2005-04-17 06:20:36 +08:00
|
|
|
int status;
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
status = get_endpoints(dev, intf);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status < 0) {
|
2008-07-25 16:45:52 +08:00
|
|
|
WARNING(dev, "couldn't get endpoints, %d\n",
|
2008-04-26 09:51:10 +08:00
|
|
|
status);
|
2012-03-26 03:08:32 +08:00
|
|
|
kfree(dev->buf);
|
|
|
|
kfree(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/* may find bulk or ISO pipes */
|
|
|
|
} else {
|
|
|
|
if (info->ep_in)
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->in_pipe = usb_rcvbulkpipe(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
info->ep_in);
|
|
|
|
if (info->ep_out)
|
2010-10-01 06:20:42 +08:00
|
|
|
dev->out_pipe = usb_sndbulkpipe(udev,
|
2005-04-17 06:20:36 +08:00
|
|
|
info->ep_out);
|
|
|
|
}
|
|
|
|
if (dev->in_pipe)
|
|
|
|
rtest = " bulk-in";
|
|
|
|
if (dev->out_pipe)
|
|
|
|
wtest = " bulk-out";
|
|
|
|
if (dev->in_iso_pipe)
|
|
|
|
irtest = " iso-in";
|
|
|
|
if (dev->out_iso_pipe)
|
|
|
|
iwtest = " iso-out";
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_set_intfdata(intf, dev);
|
|
|
|
dev_info(&intf->dev, "%s\n", info->name);
|
2011-08-30 23:11:19 +08:00
|
|
|
dev_info(&intf->dev, "%s {control%s%s%s%s%s} tests%s\n",
|
|
|
|
usb_speed_string(udev->speed),
|
2005-04-17 06:20:36 +08:00
|
|
|
info->ctrl_out ? " in/out" : "",
|
|
|
|
rtest, wtest,
|
|
|
|
irtest, iwtest,
|
|
|
|
info->alt >= 0 ? " (+alt)" : "");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int usbtest_suspend(struct usb_interface *intf, pm_message_t message)
|
2005-04-23 04:17:00 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int usbtest_resume(struct usb_interface *intf)
|
2005-04-23 04:17:00 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static void usbtest_disconnect(struct usb_interface *intf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-10-01 06:20:42 +08:00
|
|
|
struct usbtest_dev *dev = usb_get_intfdata(intf);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
dev_dbg(&intf->dev, "disconnect\n");
|
|
|
|
kfree(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Basic testing only needs a device that can source or sink bulk traffic.
|
|
|
|
* Any device can test control transfers (default with GENERIC binding).
|
|
|
|
*
|
|
|
|
* Several entries work with the default EP0 implementation that's built
|
|
|
|
* into EZ-USB chips. There's a default vendor ID which can be overridden
|
|
|
|
* by (very) small config EEPROMS, but otherwise all these devices act
|
|
|
|
* identically until firmware is loaded: only EP0 works. It turns out
|
|
|
|
* to be easy to make other endpoints work, without modifying that EP0
|
|
|
|
* behavior. For now, we expect that kind of firmware.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* an21xx or fx versions of ez-usb */
|
|
|
|
static struct usbtest_info ez1_info = {
|
|
|
|
.name = "EZ-USB device",
|
|
|
|
.ep_in = 2,
|
|
|
|
.ep_out = 2,
|
|
|
|
.alt = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* fx2 version of ez-usb */
|
|
|
|
static struct usbtest_info ez2_info = {
|
|
|
|
.name = "FX2 device",
|
|
|
|
.ep_in = 6,
|
|
|
|
.ep_out = 2,
|
|
|
|
.alt = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ezusb family device with dedicated usb test firmware,
|
|
|
|
*/
|
|
|
|
static struct usbtest_info fw_info = {
|
|
|
|
.name = "usb test device",
|
|
|
|
.ep_in = 2,
|
|
|
|
.ep_out = 2,
|
|
|
|
.alt = 1,
|
2010-10-01 06:20:42 +08:00
|
|
|
.autoconf = 1, /* iso and ctrl_out need autoconf */
|
2005-04-17 06:20:36 +08:00
|
|
|
.ctrl_out = 1,
|
2010-10-01 06:20:42 +08:00
|
|
|
.iso = 1, /* iso_ep's are #8 in/out */
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* peripheral running Linux and 'zero.c' test firmware, or
|
|
|
|
* its user-mode cousin. different versions of this use
|
|
|
|
* different hardware with the same vendor/product codes.
|
|
|
|
* host side MUST rely on the endpoint descriptors.
|
|
|
|
*/
|
|
|
|
static struct usbtest_info gz_info = {
|
|
|
|
.name = "Linux gadget zero",
|
|
|
|
.autoconf = 1,
|
|
|
|
.ctrl_out = 1,
|
2012-11-12 19:06:06 +08:00
|
|
|
.iso = 1,
|
2005-04-17 06:20:36 +08:00
|
|
|
.alt = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usbtest_info um_info = {
|
|
|
|
.name = "Linux user mode test driver",
|
|
|
|
.autoconf = 1,
|
|
|
|
.alt = -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usbtest_info um2_info = {
|
|
|
|
.name = "Linux user mode ISO test driver",
|
|
|
|
.autoconf = 1,
|
|
|
|
.iso = 1,
|
|
|
|
.alt = -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef IBOT2
|
|
|
|
/* this is a nice source of high speed bulk data;
|
|
|
|
* uses an FX2, with firmware provided in the device
|
|
|
|
*/
|
|
|
|
static struct usbtest_info ibot2_info = {
|
|
|
|
.name = "iBOT2 webcam",
|
|
|
|
.ep_in = 2,
|
|
|
|
.alt = -1,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GENERIC
|
|
|
|
/* we can use any device to test control traffic */
|
|
|
|
static struct usbtest_info generic_info = {
|
|
|
|
.name = "Generic USB device",
|
|
|
|
.alt = -1,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-01-10 22:34:45 +08:00
|
|
|
static const struct usb_device_id id_table[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* EZ-USB devices which download firmware to replace (or in our
|
|
|
|
* case augment) the default device implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* generic EZ-USB FX controller */
|
2010-10-01 06:20:42 +08:00
|
|
|
{ USB_DEVICE(0x0547, 0x2235),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &ez1_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* CY3671 development board with EZ-USB FX */
|
2010-10-01 06:20:42 +08:00
|
|
|
{ USB_DEVICE(0x0547, 0x0080),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &ez1_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* generic EZ-USB FX2 controller (or development board) */
|
2010-10-01 06:20:42 +08:00
|
|
|
{ USB_DEVICE(0x04b4, 0x8613),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &ez2_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* re-enumerated usb test device firmware */
|
2010-10-01 06:20:42 +08:00
|
|
|
{ USB_DEVICE(0xfff0, 0xfff0),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &fw_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* "Gadget Zero" firmware runs under Linux */
|
2010-10-01 06:20:42 +08:00
|
|
|
{ USB_DEVICE(0x0525, 0xa4a0),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &gz_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* so does a user-mode variant */
|
2010-10-01 06:20:42 +08:00
|
|
|
{ USB_DEVICE(0x0525, 0xa4a4),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &um_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* ... and a user-mode variant that talks iso */
|
2010-10-01 06:20:42 +08:00
|
|
|
{ USB_DEVICE(0x0525, 0xa4a3),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &um2_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef KEYSPAN_19Qi
|
|
|
|
/* Keyspan 19qi uses an21xx (original EZ-USB) */
|
2010-10-01 06:20:42 +08:00
|
|
|
/* this does not coexist with the real Keyspan 19qi driver! */
|
|
|
|
{ USB_DEVICE(0x06cd, 0x010b),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &ez1_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#ifdef IBOT2
|
|
|
|
/* iBOT2 makes a nice source of high speed bulk-in data */
|
2010-10-01 06:20:42 +08:00
|
|
|
/* this does not coexist with a real iBOT2 driver! */
|
|
|
|
{ USB_DEVICE(0x0b62, 0x0059),
|
2005-04-17 06:20:36 +08:00
|
|
|
.driver_info = (unsigned long) &ibot2_info,
|
2010-10-01 06:20:42 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#ifdef GENERIC
|
|
|
|
/* module params can specify devices to use for control tests */
|
|
|
|
{ .driver_info = (unsigned long) &generic_info, },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------*/
|
|
|
|
|
|
|
|
{ }
|
|
|
|
};
|
2010-10-01 06:20:42 +08:00
|
|
|
MODULE_DEVICE_TABLE(usb, id_table);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct usb_driver usbtest_driver = {
|
|
|
|
.name = "usbtest",
|
|
|
|
.id_table = id_table,
|
|
|
|
.probe = usbtest_probe,
|
2010-06-02 05:04:41 +08:00
|
|
|
.unlocked_ioctl = usbtest_ioctl,
|
2005-04-17 06:20:36 +08:00
|
|
|
.disconnect = usbtest_disconnect,
|
2005-04-23 04:17:00 +08:00
|
|
|
.suspend = usbtest_suspend,
|
|
|
|
.resume = usbtest_resume,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static int __init usbtest_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
#ifdef GENERIC
|
|
|
|
if (vendor)
|
2008-04-26 09:51:10 +08:00
|
|
|
pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2010-10-01 06:20:42 +08:00
|
|
|
return usb_register(&usbtest_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
module_init(usbtest_init);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
static void __exit usbtest_exit(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-10-01 06:20:42 +08:00
|
|
|
usb_deregister(&usbtest_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-01 06:20:42 +08:00
|
|
|
module_exit(usbtest_exit);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-10-01 06:20:42 +08:00
|
|
|
MODULE_DESCRIPTION("USB Core/HCD Testing Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2005-04-17 06:20:36 +08:00
|
|
|
|