15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds #include <linux/kernel.h> 31da177e4SLinus Torvalds #include <linux/errno.h> 41da177e4SLinus Torvalds #include <linux/init.h> 51da177e4SLinus Torvalds #include <linux/slab.h> 61da177e4SLinus Torvalds #include <linux/mm.h> 71da177e4SLinus Torvalds #include <linux/module.h> 81da177e4SLinus Torvalds #include <linux/moduleparam.h> 9378f058cSDavid Hardeman #include <linux/scatterlist.h> 101cfab028SMatthias Kaehlcke #include <linux/mutex.h> 1132b36eeaSAlan Stern #include <linux/timer.h> 121da177e4SLinus Torvalds #include <linux/usb.h> 131da177e4SLinus Torvalds 14e5e47465SRoger Quadros #define SIMPLE_IO_TIMEOUT 10000 /* in milliseconds */ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 171da177e4SLinus Torvalds 18d0b4652fSAlan Stern static int override_alt = -1; 19d0b4652fSAlan Stern module_param_named(alt, override_alt, int, 0644); 20d0b4652fSAlan Stern MODULE_PARM_DESC(alt, ">= 0 to override altsetting selection"); 21145f48c5SPeter Chen static void complicated_callback(struct urb *urb); 22d0b4652fSAlan Stern 23d0b4652fSAlan Stern /*-------------------------------------------------------------------------*/ 24d0b4652fSAlan Stern 25fabbf219SMartin Fuzzey /* FIXME make these public somewhere; usbdevfs.h? */ 2618fc4ebdSDeepa Dinamani 2718fc4ebdSDeepa Dinamani /* Parameter for usbtest driver. */ 2818fc4ebdSDeepa Dinamani struct usbtest_param_32 { 29fabbf219SMartin Fuzzey /* inputs */ 3018fc4ebdSDeepa Dinamani __u32 test_num; /* 0..(TEST_CASES-1) */ 3118fc4ebdSDeepa Dinamani __u32 iterations; 3218fc4ebdSDeepa Dinamani __u32 length; 3318fc4ebdSDeepa Dinamani __u32 vary; 3418fc4ebdSDeepa Dinamani __u32 sglen; 351da177e4SLinus Torvalds 36fabbf219SMartin Fuzzey /* outputs */ 3718fc4ebdSDeepa Dinamani __s32 duration_sec; 3818fc4ebdSDeepa Dinamani __s32 duration_usec; 391da177e4SLinus Torvalds }; 4018fc4ebdSDeepa Dinamani 4118fc4ebdSDeepa Dinamani /* 4218fc4ebdSDeepa Dinamani * Compat parameter to the usbtest driver. 4318fc4ebdSDeepa Dinamani * This supports older user space binaries compiled with 64 bit compiler. 4418fc4ebdSDeepa Dinamani */ 4518fc4ebdSDeepa Dinamani struct usbtest_param_64 { 4618fc4ebdSDeepa Dinamani /* inputs */ 4718fc4ebdSDeepa Dinamani __u32 test_num; /* 0..(TEST_CASES-1) */ 4818fc4ebdSDeepa Dinamani __u32 iterations; 4918fc4ebdSDeepa Dinamani __u32 length; 5018fc4ebdSDeepa Dinamani __u32 vary; 5118fc4ebdSDeepa Dinamani __u32 sglen; 5218fc4ebdSDeepa Dinamani 5318fc4ebdSDeepa Dinamani /* outputs */ 5418fc4ebdSDeepa Dinamani __s64 duration_sec; 5518fc4ebdSDeepa Dinamani __s64 duration_usec; 5618fc4ebdSDeepa Dinamani }; 5718fc4ebdSDeepa Dinamani 5818fc4ebdSDeepa Dinamani /* IOCTL interface to the driver. */ 5918fc4ebdSDeepa Dinamani #define USBTEST_REQUEST_32 _IOWR('U', 100, struct usbtest_param_32) 6018fc4ebdSDeepa Dinamani /* COMPAT IOCTL interface to the driver. */ 6118fc4ebdSDeepa Dinamani #define USBTEST_REQUEST_64 _IOWR('U', 100, struct usbtest_param_64) 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #define GENERIC /* let probe() bind using module params */ 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* Some devices that can be used for testing will have "real" drivers. 681da177e4SLinus Torvalds * Entries for those need to be enabled here by hand, after disabling 691da177e4SLinus Torvalds * that "real" driver. 701da177e4SLinus Torvalds */ 711da177e4SLinus Torvalds //#define IBOT2 /* grab iBOT2 webcams */ 721da177e4SLinus Torvalds //#define KEYSPAN_19Qi /* grab un-renumerated serial adapter */ 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds struct usbtest_info { 771da177e4SLinus Torvalds const char *name; 781da177e4SLinus Torvalds u8 ep_in; /* bulk/intr source */ 791da177e4SLinus Torvalds u8 ep_out; /* bulk/intr sink */ 801da177e4SLinus Torvalds unsigned autoconf:1; 811da177e4SLinus Torvalds unsigned ctrl_out:1; 821da177e4SLinus Torvalds unsigned iso:1; /* try iso in/out */ 83457a0955SAmit Virdi unsigned intr:1; /* try interrupt in/out */ 841da177e4SLinus Torvalds int alt; 851da177e4SLinus Torvalds }; 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds /* this is accessed only through usbfs ioctl calls. 881da177e4SLinus Torvalds * one ioctl to issue a test ... one lock per device. 891da177e4SLinus Torvalds * tests create other threads if they need them. 901da177e4SLinus Torvalds * urbs and buffers are allocated dynamically, 911da177e4SLinus Torvalds * and data generated deterministically. 921da177e4SLinus Torvalds */ 931da177e4SLinus Torvalds struct usbtest_dev { 941da177e4SLinus Torvalds struct usb_interface *intf; 951da177e4SLinus Torvalds struct usbtest_info *info; 961da177e4SLinus Torvalds int in_pipe; 971da177e4SLinus Torvalds int out_pipe; 981da177e4SLinus Torvalds int in_iso_pipe; 991da177e4SLinus Torvalds int out_iso_pipe; 100457a0955SAmit Virdi int in_int_pipe; 101457a0955SAmit Virdi int out_int_pipe; 1021da177e4SLinus Torvalds struct usb_endpoint_descriptor *iso_in, *iso_out; 103457a0955SAmit Virdi struct usb_endpoint_descriptor *int_in, *int_out; 1041cfab028SMatthias Kaehlcke struct mutex lock; 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds #define TBUF_SIZE 256 1071da177e4SLinus Torvalds u8 *buf; 1081da177e4SLinus Torvalds }; 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test) 1111da177e4SLinus Torvalds { 1121da177e4SLinus Torvalds return interface_to_usbdev(test->intf); 1131da177e4SLinus Torvalds } 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds /* set up all urbs so they can be used with either bulk or interrupt */ 1161da177e4SLinus Torvalds #define INTERRUPT_RATE 1 /* msec/transfer */ 1171da177e4SLinus Torvalds 11828ffd79cSDavid Brownell #define ERROR(tdev, fmt, args...) \ 11928ffd79cSDavid Brownell dev_err(&(tdev)->intf->dev , fmt , ## args) 120b6c63937SArjan van de Ven #define WARNING(tdev, fmt, args...) \ 12128ffd79cSDavid Brownell dev_warn(&(tdev)->intf->dev , fmt , ## args) 1221da177e4SLinus Torvalds 123084fb206SMartin Fuzzey #define GUARD_BYTE 0xA5 12441d3c0b8SPeter Chen #define MAX_SGLEN 128 125084fb206SMartin Fuzzey 1261da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 1271da177e4SLinus Torvalds 12865c7843cSGustavo A. R. Silva static inline void endpoint_update(int edi, 12965c7843cSGustavo A. R. Silva struct usb_host_endpoint **in, 13065c7843cSGustavo A. R. Silva struct usb_host_endpoint **out, 13165c7843cSGustavo A. R. Silva struct usb_host_endpoint *e) 13265c7843cSGustavo A. R. Silva { 13365c7843cSGustavo A. R. Silva if (edi) { 13465c7843cSGustavo A. R. Silva if (!*in) 13565c7843cSGustavo A. R. Silva *in = e; 13665c7843cSGustavo A. R. Silva } else { 13765c7843cSGustavo A. R. Silva if (!*out) 13865c7843cSGustavo A. R. Silva *out = e; 13965c7843cSGustavo A. R. Silva } 14065c7843cSGustavo A. R. Silva } 14165c7843cSGustavo A. R. Silva 1421da177e4SLinus Torvalds static int 1431da177e4SLinus Torvalds get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf) 1441da177e4SLinus Torvalds { 1451da177e4SLinus Torvalds int tmp; 1461da177e4SLinus Torvalds struct usb_host_interface *alt; 1471da177e4SLinus Torvalds struct usb_host_endpoint *in, *out; 1481da177e4SLinus Torvalds struct usb_host_endpoint *iso_in, *iso_out; 149457a0955SAmit Virdi struct usb_host_endpoint *int_in, *int_out; 1501da177e4SLinus Torvalds struct usb_device *udev; 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds for (tmp = 0; tmp < intf->num_altsetting; tmp++) { 1531da177e4SLinus Torvalds unsigned ep; 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds in = out = NULL; 1561da177e4SLinus Torvalds iso_in = iso_out = NULL; 157457a0955SAmit Virdi int_in = int_out = NULL; 1581da177e4SLinus Torvalds alt = intf->altsetting + tmp; 1591da177e4SLinus Torvalds 160d0b4652fSAlan Stern if (override_alt >= 0 && 161d0b4652fSAlan Stern override_alt != alt->desc.bAlternateSetting) 162d0b4652fSAlan Stern continue; 163d0b4652fSAlan Stern 1641da177e4SLinus Torvalds /* take the first altsetting with in-bulk + out-bulk; 16570f23fd6SJustin P. Mattock * ignore other endpoints and altsettings. 1661da177e4SLinus Torvalds */ 1671da177e4SLinus Torvalds for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { 1681da177e4SLinus Torvalds struct usb_host_endpoint *e; 16965c7843cSGustavo A. R. Silva int edi; 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds e = alt->endpoint + ep; 17265c7843cSGustavo A. R. Silva edi = usb_endpoint_dir_in(&e->desc); 17365c7843cSGustavo A. R. Silva 1749a37a503SHuang Rui switch (usb_endpoint_type(&e->desc)) { 1751da177e4SLinus Torvalds case USB_ENDPOINT_XFER_BULK: 17665c7843cSGustavo A. R. Silva endpoint_update(edi, &in, &out, e); 17765c7843cSGustavo A. R. Silva continue; 178457a0955SAmit Virdi case USB_ENDPOINT_XFER_INT: 179457a0955SAmit Virdi if (dev->info->intr) 18065c7843cSGustavo A. R. Silva endpoint_update(edi, &int_in, &int_out, e); 1812c930e3dSGustavo A. R. Silva continue; 1821da177e4SLinus Torvalds case USB_ENDPOINT_XFER_ISOC: 1831da177e4SLinus Torvalds if (dev->info->iso) 18465c7843cSGustavo A. R. Silva endpoint_update(edi, &iso_in, &iso_out, e); 185fabbf219SMartin Fuzzey /* FALLTHROUGH */ 1861da177e4SLinus Torvalds default: 1871da177e4SLinus Torvalds continue; 1881da177e4SLinus Torvalds } 1891da177e4SLinus Torvalds } 190457a0955SAmit Virdi if ((in && out) || iso_in || iso_out || int_in || int_out) 1911da177e4SLinus Torvalds goto found; 1921da177e4SLinus Torvalds } 1931da177e4SLinus Torvalds return -EINVAL; 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds found: 1961da177e4SLinus Torvalds udev = testdev_to_usbdev(dev); 197d0b4652fSAlan Stern dev->info->alt = alt->desc.bAlternateSetting; 1981da177e4SLinus Torvalds if (alt->desc.bAlternateSetting != 0) { 1991da177e4SLinus Torvalds tmp = usb_set_interface(udev, 2001da177e4SLinus Torvalds alt->desc.bInterfaceNumber, 2011da177e4SLinus Torvalds alt->desc.bAlternateSetting); 2021da177e4SLinus Torvalds if (tmp < 0) 2031da177e4SLinus Torvalds return tmp; 2041da177e4SLinus Torvalds } 2051da177e4SLinus Torvalds 2067c80f9e4SAlan Stern if (in) 2071da177e4SLinus Torvalds dev->in_pipe = usb_rcvbulkpipe(udev, 2081da177e4SLinus Torvalds in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 2097c80f9e4SAlan Stern if (out) 2101da177e4SLinus Torvalds dev->out_pipe = usb_sndbulkpipe(udev, 2111da177e4SLinus Torvalds out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 2127c80f9e4SAlan Stern 2131da177e4SLinus Torvalds if (iso_in) { 2141da177e4SLinus Torvalds dev->iso_in = &iso_in->desc; 2151da177e4SLinus Torvalds dev->in_iso_pipe = usb_rcvisocpipe(udev, 2161da177e4SLinus Torvalds iso_in->desc.bEndpointAddress 2171da177e4SLinus Torvalds & USB_ENDPOINT_NUMBER_MASK); 218951fd8eeSMing Lei } 219951fd8eeSMing Lei 220951fd8eeSMing Lei if (iso_out) { 2211da177e4SLinus Torvalds dev->iso_out = &iso_out->desc; 2221da177e4SLinus Torvalds dev->out_iso_pipe = usb_sndisocpipe(udev, 2231da177e4SLinus Torvalds iso_out->desc.bEndpointAddress 2241da177e4SLinus Torvalds & USB_ENDPOINT_NUMBER_MASK); 2251da177e4SLinus Torvalds } 226457a0955SAmit Virdi 227457a0955SAmit Virdi if (int_in) { 228457a0955SAmit Virdi dev->int_in = &int_in->desc; 229457a0955SAmit Virdi dev->in_int_pipe = usb_rcvintpipe(udev, 230457a0955SAmit Virdi int_in->desc.bEndpointAddress 231457a0955SAmit Virdi & USB_ENDPOINT_NUMBER_MASK); 232457a0955SAmit Virdi } 233457a0955SAmit Virdi 234457a0955SAmit Virdi if (int_out) { 235457a0955SAmit Virdi dev->int_out = &int_out->desc; 236457a0955SAmit Virdi dev->out_int_pipe = usb_sndintpipe(udev, 237457a0955SAmit Virdi int_out->desc.bEndpointAddress 238457a0955SAmit Virdi & USB_ENDPOINT_NUMBER_MASK); 239457a0955SAmit Virdi } 2401da177e4SLinus Torvalds return 0; 2411da177e4SLinus Torvalds } 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds /* Support for testing basic non-queued I/O streams. 2461da177e4SLinus Torvalds * 2471da177e4SLinus Torvalds * These just package urbs as requests that can be easily canceled. 2481da177e4SLinus Torvalds * Each urb's data buffer is dynamically allocated; callers can fill 2491da177e4SLinus Torvalds * them with non-zero test data (or test for it) when appropriate. 2501da177e4SLinus Torvalds */ 2511da177e4SLinus Torvalds 2527d12e780SDavid Howells static void simple_callback(struct urb *urb) 2531da177e4SLinus Torvalds { 254cdc97792SMing Lei complete(urb->context); 2551da177e4SLinus Torvalds } 2561da177e4SLinus Torvalds 257084fb206SMartin Fuzzey static struct urb *usbtest_alloc_urb( 2581da177e4SLinus Torvalds struct usb_device *udev, 2591da177e4SLinus Torvalds int pipe, 260084fb206SMartin Fuzzey unsigned long bytes, 261084fb206SMartin Fuzzey unsigned transfer_flags, 262457a0955SAmit Virdi unsigned offset, 263145f48c5SPeter Chen u8 bInterval, 264145f48c5SPeter Chen usb_complete_t complete_fn) 2651da177e4SLinus Torvalds { 2661da177e4SLinus Torvalds struct urb *urb; 2671da177e4SLinus Torvalds 268e94b1766SChristoph Lameter urb = usb_alloc_urb(0, GFP_KERNEL); 2691da177e4SLinus Torvalds if (!urb) 2701da177e4SLinus Torvalds return urb; 271457a0955SAmit Virdi 272457a0955SAmit Virdi if (bInterval) 273145f48c5SPeter Chen usb_fill_int_urb(urb, udev, pipe, NULL, bytes, complete_fn, 274457a0955SAmit Virdi NULL, bInterval); 275457a0955SAmit Virdi else 276145f48c5SPeter Chen usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, complete_fn, 277457a0955SAmit Virdi NULL); 278457a0955SAmit Virdi 2791da177e4SLinus Torvalds urb->interval = (udev->speed == USB_SPEED_HIGH) 2801da177e4SLinus Torvalds ? (INTERRUPT_RATE << 3) 2811da177e4SLinus Torvalds : INTERRUPT_RATE; 282084fb206SMartin Fuzzey urb->transfer_flags = transfer_flags; 2831da177e4SLinus Torvalds if (usb_pipein(pipe)) 2841da177e4SLinus Torvalds urb->transfer_flags |= URB_SHORT_NOT_OK; 285084fb206SMartin Fuzzey 28626186e5fSChunfeng Yun if ((bytes + offset) == 0) 28726186e5fSChunfeng Yun return urb; 28826186e5fSChunfeng Yun 289084fb206SMartin Fuzzey if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) 290084fb206SMartin Fuzzey urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset, 291084fb206SMartin Fuzzey GFP_KERNEL, &urb->transfer_dma); 292084fb206SMartin Fuzzey else 293084fb206SMartin Fuzzey urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL); 294084fb206SMartin Fuzzey 2951da177e4SLinus Torvalds if (!urb->transfer_buffer) { 2961da177e4SLinus Torvalds usb_free_urb(urb); 297084fb206SMartin Fuzzey return NULL; 298084fb206SMartin Fuzzey } 299084fb206SMartin Fuzzey 300084fb206SMartin Fuzzey /* To test unaligned transfers add an offset and fill the 301084fb206SMartin Fuzzey unused memory with a guard value */ 302084fb206SMartin Fuzzey if (offset) { 303084fb206SMartin Fuzzey memset(urb->transfer_buffer, GUARD_BYTE, offset); 304084fb206SMartin Fuzzey urb->transfer_buffer += offset; 305084fb206SMartin Fuzzey if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) 306084fb206SMartin Fuzzey urb->transfer_dma += offset; 307084fb206SMartin Fuzzey } 308084fb206SMartin Fuzzey 309084fb206SMartin Fuzzey /* For inbound transfers use guard byte so that test fails if 310084fb206SMartin Fuzzey data not correctly copied */ 311084fb206SMartin Fuzzey memset(urb->transfer_buffer, 312084fb206SMartin Fuzzey usb_pipein(urb->pipe) ? GUARD_BYTE : 0, 313084fb206SMartin Fuzzey bytes); 3141da177e4SLinus Torvalds return urb; 3151da177e4SLinus Torvalds } 3161da177e4SLinus Torvalds 317084fb206SMartin Fuzzey static struct urb *simple_alloc_urb( 318084fb206SMartin Fuzzey struct usb_device *udev, 319084fb206SMartin Fuzzey int pipe, 320457a0955SAmit Virdi unsigned long bytes, 321457a0955SAmit Virdi u8 bInterval) 322084fb206SMartin Fuzzey { 323457a0955SAmit Virdi return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0, 324145f48c5SPeter Chen bInterval, simple_callback); 325145f48c5SPeter Chen } 326145f48c5SPeter Chen 327145f48c5SPeter Chen static struct urb *complicated_alloc_urb( 328145f48c5SPeter Chen struct usb_device *udev, 329145f48c5SPeter Chen int pipe, 330145f48c5SPeter Chen unsigned long bytes, 331145f48c5SPeter Chen u8 bInterval) 332145f48c5SPeter Chen { 333145f48c5SPeter Chen return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0, 334145f48c5SPeter Chen bInterval, complicated_callback); 335084fb206SMartin Fuzzey } 336084fb206SMartin Fuzzey 337fabbf219SMartin Fuzzey static unsigned pattern; 3387f4e9854SVikram Pandita static unsigned mod_pattern; 3397f4e9854SVikram Pandita module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR); 3407f4e9854SVikram Pandita MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)"); 3411da177e4SLinus Torvalds 342b9a6e8e1SAlan Stern static unsigned get_maxpacket(struct usb_device *udev, int pipe) 343b9a6e8e1SAlan Stern { 344b9a6e8e1SAlan Stern struct usb_host_endpoint *ep; 345b9a6e8e1SAlan Stern 346b9a6e8e1SAlan Stern ep = usb_pipe_endpoint(udev, pipe); 347b9a6e8e1SAlan Stern return le16_to_cpup(&ep->desc.wMaxPacketSize); 348b9a6e8e1SAlan Stern } 349b9a6e8e1SAlan Stern 350*0d1ec194SPeter Chen static int ss_isoc_get_packet_num(struct usb_device *udev, int pipe) 351*0d1ec194SPeter Chen { 352*0d1ec194SPeter Chen struct usb_host_endpoint *ep = usb_pipe_endpoint(udev, pipe); 353*0d1ec194SPeter Chen 354*0d1ec194SPeter Chen return USB_SS_MULT(ep->ss_ep_comp.bmAttributes) 355*0d1ec194SPeter Chen * (1 + ep->ss_ep_comp.bMaxBurst); 356*0d1ec194SPeter Chen } 357*0d1ec194SPeter Chen 358b9a6e8e1SAlan Stern static void simple_fill_buf(struct urb *urb) 3591da177e4SLinus Torvalds { 3601da177e4SLinus Torvalds unsigned i; 3611da177e4SLinus Torvalds u8 *buf = urb->transfer_buffer; 3621da177e4SLinus Torvalds unsigned len = urb->transfer_buffer_length; 363b9a6e8e1SAlan Stern unsigned maxpacket; 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds switch (pattern) { 3661da177e4SLinus Torvalds default: 367fabbf219SMartin Fuzzey /* FALLTHROUGH */ 3681da177e4SLinus Torvalds case 0: 3691da177e4SLinus Torvalds memset(buf, 0, len); 3701da177e4SLinus Torvalds break; 3711da177e4SLinus Torvalds case 1: /* mod63 */ 372b9a6e8e1SAlan Stern maxpacket = get_maxpacket(urb->dev, urb->pipe); 3731da177e4SLinus Torvalds for (i = 0; i < len; i++) 374b9a6e8e1SAlan Stern *buf++ = (u8) ((i % maxpacket) % 63); 3751da177e4SLinus Torvalds break; 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds } 3781da177e4SLinus Torvalds 379304b0b57SGreg Dietsche static inline unsigned long buffer_offset(void *buf) 380084fb206SMartin Fuzzey { 381304b0b57SGreg Dietsche return (unsigned long)buf & (ARCH_KMALLOC_MINALIGN - 1); 382084fb206SMartin Fuzzey } 383084fb206SMartin Fuzzey 384084fb206SMartin Fuzzey static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb) 385084fb206SMartin Fuzzey { 386084fb206SMartin Fuzzey u8 *buf = urb->transfer_buffer; 387084fb206SMartin Fuzzey u8 *guard = buf - buffer_offset(buf); 388084fb206SMartin Fuzzey unsigned i; 389084fb206SMartin Fuzzey 390084fb206SMartin Fuzzey for (i = 0; guard < buf; i++, guard++) { 391084fb206SMartin Fuzzey if (*guard != GUARD_BYTE) { 392084fb206SMartin Fuzzey ERROR(tdev, "guard byte[%d] %d (not %d)\n", 393084fb206SMartin Fuzzey i, *guard, GUARD_BYTE); 394084fb206SMartin Fuzzey return -EINVAL; 395084fb206SMartin Fuzzey } 396084fb206SMartin Fuzzey } 397084fb206SMartin Fuzzey return 0; 398084fb206SMartin Fuzzey } 399084fb206SMartin Fuzzey 400084fb206SMartin Fuzzey static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb) 4011da177e4SLinus Torvalds { 4021da177e4SLinus Torvalds unsigned i; 4031da177e4SLinus Torvalds u8 expected; 4041da177e4SLinus Torvalds u8 *buf = urb->transfer_buffer; 4051da177e4SLinus Torvalds unsigned len = urb->actual_length; 406b9a6e8e1SAlan Stern unsigned maxpacket = get_maxpacket(urb->dev, urb->pipe); 4071da177e4SLinus Torvalds 408084fb206SMartin Fuzzey int ret = check_guard_bytes(tdev, urb); 409084fb206SMartin Fuzzey if (ret) 410084fb206SMartin Fuzzey return ret; 411084fb206SMartin Fuzzey 4121da177e4SLinus Torvalds for (i = 0; i < len; i++, buf++) { 4131da177e4SLinus Torvalds switch (pattern) { 4141da177e4SLinus Torvalds /* all-zeroes has no synchronization issues */ 4151da177e4SLinus Torvalds case 0: 4161da177e4SLinus Torvalds expected = 0; 4171da177e4SLinus Torvalds break; 4181da177e4SLinus Torvalds /* mod63 stays in sync with short-terminated transfers, 4191da177e4SLinus Torvalds * or otherwise when host and gadget agree on how large 4201da177e4SLinus Torvalds * each usb transfer request should be. resync is done 4211da177e4SLinus Torvalds * with set_interface or set_config. 4221da177e4SLinus Torvalds */ 4231da177e4SLinus Torvalds case 1: /* mod63 */ 424b9a6e8e1SAlan Stern expected = (i % maxpacket) % 63; 4251da177e4SLinus Torvalds break; 4261da177e4SLinus Torvalds /* always fail unsupported patterns */ 4271da177e4SLinus Torvalds default: 4281da177e4SLinus Torvalds expected = !*buf; 4291da177e4SLinus Torvalds break; 4301da177e4SLinus Torvalds } 4311da177e4SLinus Torvalds if (*buf == expected) 4321da177e4SLinus Torvalds continue; 43328ffd79cSDavid Brownell ERROR(tdev, "buf[%d] = %d (not %d)\n", i, *buf, expected); 4341da177e4SLinus Torvalds return -EINVAL; 4351da177e4SLinus Torvalds } 4361da177e4SLinus Torvalds return 0; 4371da177e4SLinus Torvalds } 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds static void simple_free_urb(struct urb *urb) 4401da177e4SLinus Torvalds { 441304b0b57SGreg Dietsche unsigned long offset = buffer_offset(urb->transfer_buffer); 442084fb206SMartin Fuzzey 443084fb206SMartin Fuzzey if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) 444084fb206SMartin Fuzzey usb_free_coherent( 445084fb206SMartin Fuzzey urb->dev, 446084fb206SMartin Fuzzey urb->transfer_buffer_length + offset, 447084fb206SMartin Fuzzey urb->transfer_buffer - offset, 448084fb206SMartin Fuzzey urb->transfer_dma - offset); 449084fb206SMartin Fuzzey else 450084fb206SMartin Fuzzey kfree(urb->transfer_buffer - offset); 4511da177e4SLinus Torvalds usb_free_urb(urb); 4521da177e4SLinus Torvalds } 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds static int simple_io( 45528ffd79cSDavid Brownell struct usbtest_dev *tdev, 4561da177e4SLinus Torvalds struct urb *urb, 4571da177e4SLinus Torvalds int iterations, 4581da177e4SLinus Torvalds int vary, 4591da177e4SLinus Torvalds int expected, 4601da177e4SLinus Torvalds const char *label 4611da177e4SLinus Torvalds ) 4621da177e4SLinus Torvalds { 4631da177e4SLinus Torvalds struct usb_device *udev = urb->dev; 4641da177e4SLinus Torvalds int max = urb->transfer_buffer_length; 4651da177e4SLinus Torvalds struct completion completion; 4661da177e4SLinus Torvalds int retval = 0; 467e5e47465SRoger Quadros unsigned long expire; 4681da177e4SLinus Torvalds 4691da177e4SLinus Torvalds urb->context = &completion; 4701da177e4SLinus Torvalds while (retval == 0 && iterations-- > 0) { 4711da177e4SLinus Torvalds init_completion(&completion); 4727c79d094SSebastian Andrzej Siewior if (usb_pipeout(urb->pipe)) { 4731da177e4SLinus Torvalds simple_fill_buf(urb); 4747c79d094SSebastian Andrzej Siewior urb->transfer_flags |= URB_ZERO_PACKET; 4757c79d094SSebastian Andrzej Siewior } 476fabbf219SMartin Fuzzey retval = usb_submit_urb(urb, GFP_KERNEL); 477fabbf219SMartin Fuzzey if (retval != 0) 4781da177e4SLinus Torvalds break; 4791da177e4SLinus Torvalds 480e5e47465SRoger Quadros expire = msecs_to_jiffies(SIMPLE_IO_TIMEOUT); 481e5e47465SRoger Quadros if (!wait_for_completion_timeout(&completion, expire)) { 482e5e47465SRoger Quadros usb_kill_urb(urb); 483e5e47465SRoger Quadros retval = (urb->status == -ENOENT ? 484e5e47465SRoger Quadros -ETIMEDOUT : urb->status); 485e5e47465SRoger Quadros } else { 4861da177e4SLinus Torvalds retval = urb->status; 487e5e47465SRoger Quadros } 488e5e47465SRoger Quadros 4891da177e4SLinus Torvalds urb->dev = udev; 4901da177e4SLinus Torvalds if (retval == 0 && usb_pipein(urb->pipe)) 49128ffd79cSDavid Brownell retval = simple_check_buf(tdev, urb); 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds if (vary) { 4941da177e4SLinus Torvalds int len = urb->transfer_buffer_length; 4951da177e4SLinus Torvalds 4961da177e4SLinus Torvalds len += vary; 4971da177e4SLinus Torvalds len %= max; 4981da177e4SLinus Torvalds if (len == 0) 4991da177e4SLinus Torvalds len = (vary < max) ? vary : max; 5001da177e4SLinus Torvalds urb->transfer_buffer_length = len; 5011da177e4SLinus Torvalds } 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds /* FIXME if endpoint halted, clear halt (and log) */ 5041da177e4SLinus Torvalds } 5051da177e4SLinus Torvalds urb->transfer_buffer_length = max; 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds if (expected != retval) 50828ffd79cSDavid Brownell dev_err(&udev->dev, 5091da177e4SLinus Torvalds "%s failed, iterations left %d, status %d (not %d)\n", 5101da177e4SLinus Torvalds label, iterations, retval, expected); 5111da177e4SLinus Torvalds return retval; 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds /* We use scatterlist primitives to test queued I/O. 5181da177e4SLinus Torvalds * Yes, this also tests the scatterlist primitives. 5191da177e4SLinus Torvalds */ 5201da177e4SLinus Torvalds 5211da177e4SLinus Torvalds static void free_sglist(struct scatterlist *sg, int nents) 5221da177e4SLinus Torvalds { 5231da177e4SLinus Torvalds unsigned i; 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds if (!sg) 5261da177e4SLinus Torvalds return; 5271da177e4SLinus Torvalds for (i = 0; i < nents; i++) { 52845711f1aSJens Axboe if (!sg_page(&sg[i])) 5291da177e4SLinus Torvalds continue; 53045711f1aSJens Axboe kfree(sg_virt(&sg[i])); 5311da177e4SLinus Torvalds } 5321da177e4SLinus Torvalds kfree(sg); 5331da177e4SLinus Torvalds } 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds static struct scatterlist * 536b9a6e8e1SAlan Stern alloc_sglist(int nents, int max, int vary, struct usbtest_dev *dev, int pipe) 5371da177e4SLinus Torvalds { 5381da177e4SLinus Torvalds struct scatterlist *sg; 539cdc77c82SMathias Nyman unsigned int n_size = 0; 5401da177e4SLinus Torvalds unsigned i; 5411da177e4SLinus Torvalds unsigned size = max; 542b9a6e8e1SAlan Stern unsigned maxpacket = 543b9a6e8e1SAlan Stern get_maxpacket(interface_to_usbdev(dev->intf), pipe); 5441da177e4SLinus Torvalds 545564e6989SDan Carpenter if (max == 0) 546564e6989SDan Carpenter return NULL; 547564e6989SDan Carpenter 548f55055b4SHuang Rui sg = kmalloc_array(nents, sizeof(*sg), GFP_KERNEL); 5491da177e4SLinus Torvalds if (!sg) 5501da177e4SLinus Torvalds return NULL; 5514756febbSAlan Stern sg_init_table(sg, nents); 5521da177e4SLinus Torvalds 5531da177e4SLinus Torvalds for (i = 0; i < nents; i++) { 5541da177e4SLinus Torvalds char *buf; 5558b524901SDavid Brownell unsigned j; 5561da177e4SLinus Torvalds 557e94b1766SChristoph Lameter buf = kzalloc(size, GFP_KERNEL); 5581da177e4SLinus Torvalds if (!buf) { 5591da177e4SLinus Torvalds free_sglist(sg, i); 5601da177e4SLinus Torvalds return NULL; 5611da177e4SLinus Torvalds } 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds /* kmalloc pages are always physically contiguous! */ 5644756febbSAlan Stern sg_set_buf(&sg[i], buf, size); 5651da177e4SLinus Torvalds 5668b524901SDavid Brownell switch (pattern) { 5678b524901SDavid Brownell case 0: 5688b524901SDavid Brownell /* already zeroed */ 5698b524901SDavid Brownell break; 5708b524901SDavid Brownell case 1: 5718b524901SDavid Brownell for (j = 0; j < size; j++) 572cdc77c82SMathias Nyman *buf++ = (u8) (((j + n_size) % maxpacket) % 63); 573cdc77c82SMathias Nyman n_size += size; 5748b524901SDavid Brownell break; 5758b524901SDavid Brownell } 5768b524901SDavid Brownell 5771da177e4SLinus Torvalds if (vary) { 5781da177e4SLinus Torvalds size += vary; 5791da177e4SLinus Torvalds size %= max; 5801da177e4SLinus Torvalds if (size == 0) 5811da177e4SLinus Torvalds size = (vary < max) ? vary : max; 5821da177e4SLinus Torvalds } 5831da177e4SLinus Torvalds } 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds return sg; 5861da177e4SLinus Torvalds } 5871da177e4SLinus Torvalds 5887d221856SKees Cook struct sg_timeout { 5897d221856SKees Cook struct timer_list timer; 5907d221856SKees Cook struct usb_sg_request *req; 5917d221856SKees Cook }; 59232b36eeaSAlan Stern 5937d221856SKees Cook static void sg_timeout(struct timer_list *t) 5947d221856SKees Cook { 5957d221856SKees Cook struct sg_timeout *timeout = from_timer(timeout, t, timer); 5967d221856SKees Cook 5977d221856SKees Cook usb_sg_cancel(timeout->req); 59832b36eeaSAlan Stern } 59932b36eeaSAlan Stern 6001da177e4SLinus Torvalds static int perform_sglist( 60128ffd79cSDavid Brownell struct usbtest_dev *tdev, 6021da177e4SLinus Torvalds unsigned iterations, 6031da177e4SLinus Torvalds int pipe, 6041da177e4SLinus Torvalds struct usb_sg_request *req, 6051da177e4SLinus Torvalds struct scatterlist *sg, 6061da177e4SLinus Torvalds int nents 6071da177e4SLinus Torvalds ) 6081da177e4SLinus Torvalds { 60928ffd79cSDavid Brownell struct usb_device *udev = testdev_to_usbdev(tdev); 6101da177e4SLinus Torvalds int retval = 0; 6117d221856SKees Cook struct sg_timeout timeout = { 6127d221856SKees Cook .req = req, 6137d221856SKees Cook }; 61432b36eeaSAlan Stern 6157d221856SKees Cook timer_setup_on_stack(&timeout.timer, sg_timeout, 0); 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds while (retval == 0 && iterations-- > 0) { 6181da177e4SLinus Torvalds retval = usb_sg_init(req, udev, pipe, 6191da177e4SLinus Torvalds (udev->speed == USB_SPEED_HIGH) 6201da177e4SLinus Torvalds ? (INTERRUPT_RATE << 3) 6211da177e4SLinus Torvalds : INTERRUPT_RATE, 622e94b1766SChristoph Lameter sg, nents, 0, GFP_KERNEL); 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds if (retval) 6251da177e4SLinus Torvalds break; 6267d221856SKees Cook mod_timer(&timeout.timer, jiffies + 62732b36eeaSAlan Stern msecs_to_jiffies(SIMPLE_IO_TIMEOUT)); 6281da177e4SLinus Torvalds usb_sg_wait(req); 6297d221856SKees Cook if (!del_timer_sync(&timeout.timer)) 63053958751SLu Baolu retval = -ETIMEDOUT; 63153958751SLu Baolu else 6321da177e4SLinus Torvalds retval = req->status; 6337d221856SKees Cook destroy_timer_on_stack(&timeout.timer); 6341da177e4SLinus Torvalds 6358b524901SDavid Brownell /* FIXME check resulting data pattern */ 6368b524901SDavid Brownell 6371da177e4SLinus Torvalds /* FIXME if endpoint halted, clear halt (and log) */ 6381da177e4SLinus Torvalds } 6391da177e4SLinus Torvalds 640fabbf219SMartin Fuzzey /* FIXME for unlink or fault handling tests, don't report 641fabbf219SMartin Fuzzey * failure if retval is as we expected ... 642fabbf219SMartin Fuzzey */ 6431da177e4SLinus Torvalds if (retval) 64428ffd79cSDavid Brownell ERROR(tdev, "perform_sglist failed, " 64528ffd79cSDavid Brownell "iterations left %d, status %d\n", 6461da177e4SLinus Torvalds iterations, retval); 6471da177e4SLinus Torvalds return retval; 6481da177e4SLinus Torvalds } 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds /* unqueued control message testing 6541da177e4SLinus Torvalds * 6551da177e4SLinus Torvalds * there's a nice set of device functional requirements in chapter 9 of the 6561da177e4SLinus Torvalds * usb 2.0 spec, which we can apply to ANY device, even ones that don't use 6571da177e4SLinus Torvalds * special test firmware. 6581da177e4SLinus Torvalds * 6591da177e4SLinus Torvalds * we know the device is configured (or suspended) by the time it's visible 6601da177e4SLinus Torvalds * through usbfs. we can't change that, so we won't test enumeration (which 6611da177e4SLinus Torvalds * worked 'well enough' to get here, this time), power management (ditto), 6621da177e4SLinus Torvalds * or remote wakeup (which needs human interaction). 6631da177e4SLinus Torvalds */ 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds static unsigned realworld = 1; 6661da177e4SLinus Torvalds module_param(realworld, uint, 0); 667ff7c79e4SDavid Brownell MODULE_PARM_DESC(realworld, "clear to demand stricter spec compliance"); 6681da177e4SLinus Torvalds 6691da177e4SLinus Torvalds static int get_altsetting(struct usbtest_dev *dev) 6701da177e4SLinus Torvalds { 6711da177e4SLinus Torvalds struct usb_interface *iface = dev->intf; 6721da177e4SLinus Torvalds struct usb_device *udev = interface_to_usbdev(iface); 6731da177e4SLinus Torvalds int retval; 6741da177e4SLinus Torvalds 6751da177e4SLinus Torvalds retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 6761da177e4SLinus Torvalds USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE, 6771da177e4SLinus Torvalds 0, iface->altsetting[0].desc.bInterfaceNumber, 6781da177e4SLinus Torvalds dev->buf, 1, USB_CTRL_GET_TIMEOUT); 6791da177e4SLinus Torvalds switch (retval) { 6801da177e4SLinus Torvalds case 1: 6811da177e4SLinus Torvalds return dev->buf[0]; 6821da177e4SLinus Torvalds case 0: 6831da177e4SLinus Torvalds retval = -ERANGE; 684fabbf219SMartin Fuzzey /* FALLTHROUGH */ 6851da177e4SLinus Torvalds default: 6861da177e4SLinus Torvalds return retval; 6871da177e4SLinus Torvalds } 6881da177e4SLinus Torvalds } 6891da177e4SLinus Torvalds 6901da177e4SLinus Torvalds static int set_altsetting(struct usbtest_dev *dev, int alternate) 6911da177e4SLinus Torvalds { 6921da177e4SLinus Torvalds struct usb_interface *iface = dev->intf; 6931da177e4SLinus Torvalds struct usb_device *udev; 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds if (alternate < 0 || alternate >= 256) 6961da177e4SLinus Torvalds return -EINVAL; 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds udev = interface_to_usbdev(iface); 6991da177e4SLinus Torvalds return usb_set_interface(udev, 7001da177e4SLinus Torvalds iface->altsetting[0].desc.bInterfaceNumber, 7011da177e4SLinus Torvalds alternate); 7021da177e4SLinus Torvalds } 7031da177e4SLinus Torvalds 70428ffd79cSDavid Brownell static int is_good_config(struct usbtest_dev *tdev, int len) 7051da177e4SLinus Torvalds { 7061da177e4SLinus Torvalds struct usb_config_descriptor *config; 7071da177e4SLinus Torvalds 708f55055b4SHuang Rui if (len < sizeof(*config)) 7091da177e4SLinus Torvalds return 0; 71028ffd79cSDavid Brownell config = (struct usb_config_descriptor *) tdev->buf; 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds switch (config->bDescriptorType) { 7131da177e4SLinus Torvalds case USB_DT_CONFIG: 7141da177e4SLinus Torvalds case USB_DT_OTHER_SPEED_CONFIG: 7151da177e4SLinus Torvalds if (config->bLength != 9) { 71628ffd79cSDavid Brownell ERROR(tdev, "bogus config descriptor length\n"); 7171da177e4SLinus Torvalds return 0; 7181da177e4SLinus Torvalds } 7191da177e4SLinus Torvalds /* this bit 'must be 1' but often isn't */ 7201da177e4SLinus Torvalds if (!realworld && !(config->bmAttributes & 0x80)) { 72128ffd79cSDavid Brownell ERROR(tdev, "high bit of config attributes not set\n"); 7221da177e4SLinus Torvalds return 0; 7231da177e4SLinus Torvalds } 7241da177e4SLinus Torvalds if (config->bmAttributes & 0x1f) { /* reserved == 0 */ 72528ffd79cSDavid Brownell ERROR(tdev, "reserved config bits set\n"); 7261da177e4SLinus Torvalds return 0; 7271da177e4SLinus Torvalds } 7281da177e4SLinus Torvalds break; 7291da177e4SLinus Torvalds default: 7301da177e4SLinus Torvalds return 0; 7311da177e4SLinus Torvalds } 7321da177e4SLinus Torvalds 7331da177e4SLinus Torvalds if (le16_to_cpu(config->wTotalLength) == len) /* read it all */ 7341da177e4SLinus Torvalds return 1; 7351da177e4SLinus Torvalds if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */ 7361da177e4SLinus Torvalds return 1; 73728ffd79cSDavid Brownell ERROR(tdev, "bogus config descriptor read size\n"); 7381da177e4SLinus Torvalds return 0; 7391da177e4SLinus Torvalds } 7401da177e4SLinus Torvalds 74182f92672SHuang Rui static int is_good_ext(struct usbtest_dev *tdev, u8 *buf) 74282f92672SHuang Rui { 74382f92672SHuang Rui struct usb_ext_cap_descriptor *ext; 74482f92672SHuang Rui u32 attr; 74582f92672SHuang Rui 74682f92672SHuang Rui ext = (struct usb_ext_cap_descriptor *) buf; 74782f92672SHuang Rui 74882f92672SHuang Rui if (ext->bLength != USB_DT_USB_EXT_CAP_SIZE) { 74982f92672SHuang Rui ERROR(tdev, "bogus usb 2.0 extension descriptor length\n"); 75082f92672SHuang Rui return 0; 75182f92672SHuang Rui } 75282f92672SHuang Rui 75382f92672SHuang Rui attr = le32_to_cpu(ext->bmAttributes); 754875bc23aSHuang Rui /* bits[1:15] is used and others are reserved */ 755875bc23aSHuang Rui if (attr & ~0xfffe) { /* reserved == 0 */ 75682f92672SHuang Rui ERROR(tdev, "reserved bits set\n"); 75782f92672SHuang Rui return 0; 75882f92672SHuang Rui } 75982f92672SHuang Rui 76082f92672SHuang Rui return 1; 76182f92672SHuang Rui } 76282f92672SHuang Rui 763b8fef795SHuang Rui static int is_good_ss_cap(struct usbtest_dev *tdev, u8 *buf) 764b8fef795SHuang Rui { 765b8fef795SHuang Rui struct usb_ss_cap_descriptor *ss; 766b8fef795SHuang Rui 767b8fef795SHuang Rui ss = (struct usb_ss_cap_descriptor *) buf; 768b8fef795SHuang Rui 769b8fef795SHuang Rui if (ss->bLength != USB_DT_USB_SS_CAP_SIZE) { 770b8fef795SHuang Rui ERROR(tdev, "bogus superspeed device capability descriptor length\n"); 771b8fef795SHuang Rui return 0; 772b8fef795SHuang Rui } 773b8fef795SHuang Rui 774b8fef795SHuang Rui /* 775b8fef795SHuang Rui * only bit[1] of bmAttributes is used for LTM and others are 776b8fef795SHuang Rui * reserved 777b8fef795SHuang Rui */ 778b8fef795SHuang Rui if (ss->bmAttributes & ~0x02) { /* reserved == 0 */ 779b8fef795SHuang Rui ERROR(tdev, "reserved bits set in bmAttributes\n"); 780b8fef795SHuang Rui return 0; 781b8fef795SHuang Rui } 782b8fef795SHuang Rui 783b8fef795SHuang Rui /* bits[0:3] of wSpeedSupported is used and others are reserved */ 784b8fef795SHuang Rui if (le16_to_cpu(ss->wSpeedSupported) & ~0x0f) { /* reserved == 0 */ 785b8fef795SHuang Rui ERROR(tdev, "reserved bits set in wSpeedSupported\n"); 786b8fef795SHuang Rui return 0; 787b8fef795SHuang Rui } 788b8fef795SHuang Rui 789b8fef795SHuang Rui return 1; 790b8fef795SHuang Rui } 791b8fef795SHuang Rui 7928e29217fSHuang Rui static int is_good_con_id(struct usbtest_dev *tdev, u8 *buf) 7938e29217fSHuang Rui { 7948e29217fSHuang Rui struct usb_ss_container_id_descriptor *con_id; 7958e29217fSHuang Rui 7968e29217fSHuang Rui con_id = (struct usb_ss_container_id_descriptor *) buf; 7978e29217fSHuang Rui 7988e29217fSHuang Rui if (con_id->bLength != USB_DT_USB_SS_CONTN_ID_SIZE) { 7998e29217fSHuang Rui ERROR(tdev, "bogus container id descriptor length\n"); 8008e29217fSHuang Rui return 0; 8018e29217fSHuang Rui } 8028e29217fSHuang Rui 8038e29217fSHuang Rui if (con_id->bReserved) { /* reserved == 0 */ 8048e29217fSHuang Rui ERROR(tdev, "reserved bits set\n"); 8058e29217fSHuang Rui return 0; 8068e29217fSHuang Rui } 8078e29217fSHuang Rui 8088e29217fSHuang Rui return 1; 8098e29217fSHuang Rui } 8108e29217fSHuang Rui 8111da177e4SLinus Torvalds /* sanity test for standard requests working with usb_control_mesg() and some 8121da177e4SLinus Torvalds * of the utility functions which use it. 8131da177e4SLinus Torvalds * 8141da177e4SLinus Torvalds * this doesn't test how endpoint halts behave or data toggles get set, since 8151da177e4SLinus Torvalds * we won't do I/O to bulk/interrupt endpoints here (which is how to change 8161da177e4SLinus Torvalds * halt or toggle). toggle testing is impractical without support from hcds. 8171da177e4SLinus Torvalds * 8181da177e4SLinus Torvalds * this avoids failing devices linux would normally work with, by not testing 8191da177e4SLinus Torvalds * config/altsetting operations for devices that only support their defaults. 8201da177e4SLinus Torvalds * such devices rarely support those needless operations. 8211da177e4SLinus Torvalds * 8221da177e4SLinus Torvalds * NOTE that since this is a sanity test, it's not examining boundary cases 8231da177e4SLinus Torvalds * to see if usbcore, hcd, and device all behave right. such testing would 8241da177e4SLinus Torvalds * involve varied read sizes and other operation sequences. 8251da177e4SLinus Torvalds */ 8261da177e4SLinus Torvalds static int ch9_postconfig(struct usbtest_dev *dev) 8271da177e4SLinus Torvalds { 8281da177e4SLinus Torvalds struct usb_interface *iface = dev->intf; 8291da177e4SLinus Torvalds struct usb_device *udev = interface_to_usbdev(iface); 8301da177e4SLinus Torvalds int i, alt, retval; 8311da177e4SLinus Torvalds 8321da177e4SLinus Torvalds /* [9.2.3] if there's more than one altsetting, we need to be able to 8331da177e4SLinus Torvalds * set and get each one. mostly trusts the descriptors from usbcore. 8341da177e4SLinus Torvalds */ 8351da177e4SLinus Torvalds for (i = 0; i < iface->num_altsetting; i++) { 8361da177e4SLinus Torvalds 8371da177e4SLinus Torvalds /* 9.2.3 constrains the range here */ 8381da177e4SLinus Torvalds alt = iface->altsetting[i].desc.bAlternateSetting; 8391da177e4SLinus Torvalds if (alt < 0 || alt >= iface->num_altsetting) { 84028ffd79cSDavid Brownell dev_err(&iface->dev, 8411da177e4SLinus Torvalds "invalid alt [%d].bAltSetting = %d\n", 8421da177e4SLinus Torvalds i, alt); 8431da177e4SLinus Torvalds } 8441da177e4SLinus Torvalds 8451da177e4SLinus Torvalds /* [real world] get/set unimplemented if there's only one */ 8461da177e4SLinus Torvalds if (realworld && iface->num_altsetting == 1) 8471da177e4SLinus Torvalds continue; 8481da177e4SLinus Torvalds 8491da177e4SLinus Torvalds /* [9.4.10] set_interface */ 8501da177e4SLinus Torvalds retval = set_altsetting(dev, alt); 8511da177e4SLinus Torvalds if (retval) { 85228ffd79cSDavid Brownell dev_err(&iface->dev, "can't set_interface = %d, %d\n", 8531da177e4SLinus Torvalds alt, retval); 8541da177e4SLinus Torvalds return retval; 8551da177e4SLinus Torvalds } 8561da177e4SLinus Torvalds 8571da177e4SLinus Torvalds /* [9.4.4] get_interface always works */ 8581da177e4SLinus Torvalds retval = get_altsetting(dev); 8591da177e4SLinus Torvalds if (retval != alt) { 86028ffd79cSDavid Brownell dev_err(&iface->dev, "get alt should be %d, was %d\n", 8611da177e4SLinus Torvalds alt, retval); 8621da177e4SLinus Torvalds return (retval < 0) ? retval : -EDOM; 8631da177e4SLinus Torvalds } 8641da177e4SLinus Torvalds 8651da177e4SLinus Torvalds } 8661da177e4SLinus Torvalds 8671da177e4SLinus Torvalds /* [real world] get_config unimplemented if there's only one */ 8681da177e4SLinus Torvalds if (!realworld || udev->descriptor.bNumConfigurations != 1) { 8691da177e4SLinus Torvalds int expected = udev->actconfig->desc.bConfigurationValue; 8701da177e4SLinus Torvalds 8711da177e4SLinus Torvalds /* [9.4.2] get_configuration always works 8721da177e4SLinus Torvalds * ... although some cheap devices (like one TI Hub I've got) 8731da177e4SLinus Torvalds * won't return config descriptors except before set_config. 8741da177e4SLinus Torvalds */ 8751da177e4SLinus Torvalds retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 8761da177e4SLinus Torvalds USB_REQ_GET_CONFIGURATION, 8771da177e4SLinus Torvalds USB_DIR_IN | USB_RECIP_DEVICE, 8781da177e4SLinus Torvalds 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); 8791da177e4SLinus Torvalds if (retval != 1 || dev->buf[0] != expected) { 88028ffd79cSDavid Brownell dev_err(&iface->dev, "get config --> %d %d (1 %d)\n", 881ff7c79e4SDavid Brownell retval, dev->buf[0], expected); 8821da177e4SLinus Torvalds return (retval < 0) ? retval : -EDOM; 8831da177e4SLinus Torvalds } 8841da177e4SLinus Torvalds } 8851da177e4SLinus Torvalds 8861da177e4SLinus Torvalds /* there's always [9.4.3] a device descriptor [9.6.1] */ 8871da177e4SLinus Torvalds retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0, 888f55055b4SHuang Rui dev->buf, sizeof(udev->descriptor)); 889f55055b4SHuang Rui if (retval != sizeof(udev->descriptor)) { 89028ffd79cSDavid Brownell dev_err(&iface->dev, "dev descriptor --> %d\n", retval); 8911da177e4SLinus Torvalds return (retval < 0) ? retval : -EDOM; 8921da177e4SLinus Torvalds } 8931da177e4SLinus Torvalds 8949d3bd768SHuang Rui /* 8959d3bd768SHuang Rui * there's always [9.4.3] a bos device descriptor [9.6.2] in USB 8969d3bd768SHuang Rui * 3.0 spec 8979d3bd768SHuang Rui */ 898f625099fSHuang Rui if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0210) { 89982f92672SHuang Rui struct usb_bos_descriptor *bos = NULL; 90082f92672SHuang Rui struct usb_dev_cap_header *header = NULL; 90182f92672SHuang Rui unsigned total, num, length; 90282f92672SHuang Rui u8 *buf; 90382f92672SHuang Rui 9049d3bd768SHuang Rui retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, 9059d3bd768SHuang Rui sizeof(*udev->bos->desc)); 9069d3bd768SHuang Rui if (retval != sizeof(*udev->bos->desc)) { 9079d3bd768SHuang Rui dev_err(&iface->dev, "bos descriptor --> %d\n", retval); 9089d3bd768SHuang Rui return (retval < 0) ? retval : -EDOM; 9099d3bd768SHuang Rui } 91082f92672SHuang Rui 91182f92672SHuang Rui bos = (struct usb_bos_descriptor *)dev->buf; 91282f92672SHuang Rui total = le16_to_cpu(bos->wTotalLength); 91382f92672SHuang Rui num = bos->bNumDeviceCaps; 91482f92672SHuang Rui 91582f92672SHuang Rui if (total > TBUF_SIZE) 91682f92672SHuang Rui total = TBUF_SIZE; 91782f92672SHuang Rui 91882f92672SHuang Rui /* 91982f92672SHuang Rui * get generic device-level capability descriptors [9.6.2] 92082f92672SHuang Rui * in USB 3.0 spec 92182f92672SHuang Rui */ 92282f92672SHuang Rui retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, 92382f92672SHuang Rui total); 92482f92672SHuang Rui if (retval != total) { 92582f92672SHuang Rui dev_err(&iface->dev, "bos descriptor set --> %d\n", 92682f92672SHuang Rui retval); 92782f92672SHuang Rui return (retval < 0) ? retval : -EDOM; 92882f92672SHuang Rui } 92982f92672SHuang Rui 93082f92672SHuang Rui length = sizeof(*udev->bos->desc); 93182f92672SHuang Rui buf = dev->buf; 93282f92672SHuang Rui for (i = 0; i < num; i++) { 93382f92672SHuang Rui buf += length; 93482f92672SHuang Rui if (buf + sizeof(struct usb_dev_cap_header) > 93582f92672SHuang Rui dev->buf + total) 93682f92672SHuang Rui break; 93782f92672SHuang Rui 93882f92672SHuang Rui header = (struct usb_dev_cap_header *)buf; 93982f92672SHuang Rui length = header->bLength; 94082f92672SHuang Rui 94182f92672SHuang Rui if (header->bDescriptorType != 94282f92672SHuang Rui USB_DT_DEVICE_CAPABILITY) { 94382f92672SHuang Rui dev_warn(&udev->dev, "not device capability descriptor, skip\n"); 94482f92672SHuang Rui continue; 94582f92672SHuang Rui } 94682f92672SHuang Rui 94782f92672SHuang Rui switch (header->bDevCapabilityType) { 94882f92672SHuang Rui case USB_CAP_TYPE_EXT: 94982f92672SHuang Rui if (buf + USB_DT_USB_EXT_CAP_SIZE > 95082f92672SHuang Rui dev->buf + total || 95182f92672SHuang Rui !is_good_ext(dev, buf)) { 95282f92672SHuang Rui dev_err(&iface->dev, "bogus usb 2.0 extension descriptor\n"); 95382f92672SHuang Rui return -EDOM; 95482f92672SHuang Rui } 95582f92672SHuang Rui break; 956b8fef795SHuang Rui case USB_SS_CAP_TYPE: 957b8fef795SHuang Rui if (buf + USB_DT_USB_SS_CAP_SIZE > 958b8fef795SHuang Rui dev->buf + total || 959b8fef795SHuang Rui !is_good_ss_cap(dev, buf)) { 960b8fef795SHuang Rui dev_err(&iface->dev, "bogus superspeed device capability descriptor\n"); 961b8fef795SHuang Rui return -EDOM; 962b8fef795SHuang Rui } 963b8fef795SHuang Rui break; 9648e29217fSHuang Rui case CONTAINER_ID_TYPE: 9658e29217fSHuang Rui if (buf + USB_DT_USB_SS_CONTN_ID_SIZE > 9668e29217fSHuang Rui dev->buf + total || 9678e29217fSHuang Rui !is_good_con_id(dev, buf)) { 9688e29217fSHuang Rui dev_err(&iface->dev, "bogus container id descriptor\n"); 9698e29217fSHuang Rui return -EDOM; 9708e29217fSHuang Rui } 9718e29217fSHuang Rui break; 97282f92672SHuang Rui default: 97382f92672SHuang Rui break; 97482f92672SHuang Rui } 97582f92672SHuang Rui } 9769d3bd768SHuang Rui } 9779d3bd768SHuang Rui 9781da177e4SLinus Torvalds /* there's always [9.4.3] at least one config descriptor [9.6.3] */ 9791da177e4SLinus Torvalds for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 9801da177e4SLinus Torvalds retval = usb_get_descriptor(udev, USB_DT_CONFIG, i, 9811da177e4SLinus Torvalds dev->buf, TBUF_SIZE); 98228ffd79cSDavid Brownell if (!is_good_config(dev, retval)) { 98328ffd79cSDavid Brownell dev_err(&iface->dev, 9841da177e4SLinus Torvalds "config [%d] descriptor --> %d\n", 9851da177e4SLinus Torvalds i, retval); 9861da177e4SLinus Torvalds return (retval < 0) ? retval : -EDOM; 9871da177e4SLinus Torvalds } 9881da177e4SLinus Torvalds 989fabbf219SMartin Fuzzey /* FIXME cross-checking udev->config[i] to make sure usbcore 990fabbf219SMartin Fuzzey * parsed it right (etc) would be good testing paranoia 991fabbf219SMartin Fuzzey */ 9921da177e4SLinus Torvalds } 9931da177e4SLinus Torvalds 9941da177e4SLinus Torvalds /* and sometimes [9.2.6.6] speed dependent descriptors */ 9951da177e4SLinus Torvalds if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) { 9961da177e4SLinus Torvalds struct usb_qualifier_descriptor *d = NULL; 9971da177e4SLinus Torvalds 9981da177e4SLinus Torvalds /* device qualifier [9.6.2] */ 9991da177e4SLinus Torvalds retval = usb_get_descriptor(udev, 10001da177e4SLinus Torvalds USB_DT_DEVICE_QUALIFIER, 0, dev->buf, 10011da177e4SLinus Torvalds sizeof(struct usb_qualifier_descriptor)); 10021da177e4SLinus Torvalds if (retval == -EPIPE) { 10031da177e4SLinus Torvalds if (udev->speed == USB_SPEED_HIGH) { 100428ffd79cSDavid Brownell dev_err(&iface->dev, 10051da177e4SLinus Torvalds "hs dev qualifier --> %d\n", 10061da177e4SLinus Torvalds retval); 1007ef5ec7f0SColin Ian King return retval; 10081da177e4SLinus Torvalds } 10091da177e4SLinus Torvalds /* usb2.0 but not high-speed capable; fine */ 10101da177e4SLinus Torvalds } else if (retval != sizeof(struct usb_qualifier_descriptor)) { 101128ffd79cSDavid Brownell dev_err(&iface->dev, "dev qualifier --> %d\n", retval); 10121da177e4SLinus Torvalds return (retval < 0) ? retval : -EDOM; 10131da177e4SLinus Torvalds } else 10141da177e4SLinus Torvalds d = (struct usb_qualifier_descriptor *) dev->buf; 10151da177e4SLinus Torvalds 10161da177e4SLinus Torvalds /* might not have [9.6.2] any other-speed configs [9.6.4] */ 10171da177e4SLinus Torvalds if (d) { 10181da177e4SLinus Torvalds unsigned max = d->bNumConfigurations; 10191da177e4SLinus Torvalds for (i = 0; i < max; i++) { 10201da177e4SLinus Torvalds retval = usb_get_descriptor(udev, 10211da177e4SLinus Torvalds USB_DT_OTHER_SPEED_CONFIG, i, 10221da177e4SLinus Torvalds dev->buf, TBUF_SIZE); 102328ffd79cSDavid Brownell if (!is_good_config(dev, retval)) { 102428ffd79cSDavid Brownell dev_err(&iface->dev, 10251da177e4SLinus Torvalds "other speed config --> %d\n", 10261da177e4SLinus Torvalds retval); 10271da177e4SLinus Torvalds return (retval < 0) ? retval : -EDOM; 10281da177e4SLinus Torvalds } 10291da177e4SLinus Torvalds } 10301da177e4SLinus Torvalds } 10311da177e4SLinus Torvalds } 1032fabbf219SMartin Fuzzey /* FIXME fetch strings from at least the device descriptor */ 10331da177e4SLinus Torvalds 10341da177e4SLinus Torvalds /* [9.4.5] get_status always works */ 1035d9e1e148SFelipe Balbi retval = usb_get_std_status(udev, USB_RECIP_DEVICE, 0, dev->buf); 103615b7336eSAlan Stern if (retval) { 103728ffd79cSDavid Brownell dev_err(&iface->dev, "get dev status --> %d\n", retval); 103815b7336eSAlan Stern return retval; 10391da177e4SLinus Torvalds } 10401da177e4SLinus Torvalds 1041fabbf219SMartin Fuzzey /* FIXME configuration.bmAttributes says if we could try to set/clear 1042fabbf219SMartin Fuzzey * the device's remote wakeup feature ... if we can, test that here 1043fabbf219SMartin Fuzzey */ 10441da177e4SLinus Torvalds 1045d9e1e148SFelipe Balbi retval = usb_get_std_status(udev, USB_RECIP_INTERFACE, 10461da177e4SLinus Torvalds iface->altsetting[0].desc.bInterfaceNumber, dev->buf); 104715b7336eSAlan Stern if (retval) { 104828ffd79cSDavid Brownell dev_err(&iface->dev, "get interface status --> %d\n", retval); 104915b7336eSAlan Stern return retval; 10501da177e4SLinus Torvalds } 1051fabbf219SMartin Fuzzey /* FIXME get status for each endpoint in the interface */ 10521da177e4SLinus Torvalds 10531da177e4SLinus Torvalds return 0; 10541da177e4SLinus Torvalds } 10551da177e4SLinus Torvalds 10561da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 10571da177e4SLinus Torvalds 10581da177e4SLinus Torvalds /* use ch9 requests to test whether: 10591da177e4SLinus Torvalds * (a) queues work for control, keeping N subtests queued and 10601da177e4SLinus Torvalds * active (auto-resubmit) for M loops through the queue. 10611da177e4SLinus Torvalds * (b) protocol stalls (control-only) will autorecover. 10621da177e4SLinus Torvalds * it's not like bulk/intr; no halt clearing. 10631da177e4SLinus Torvalds * (c) short control reads are reported and handled. 10641da177e4SLinus Torvalds * (d) queues are always processed in-order 10651da177e4SLinus Torvalds */ 10661da177e4SLinus Torvalds 10671da177e4SLinus Torvalds struct ctrl_ctx { 10681da177e4SLinus Torvalds spinlock_t lock; 10691da177e4SLinus Torvalds struct usbtest_dev *dev; 10701da177e4SLinus Torvalds struct completion complete; 10711da177e4SLinus Torvalds unsigned count; 10721da177e4SLinus Torvalds unsigned pending; 10731da177e4SLinus Torvalds int status; 10741da177e4SLinus Torvalds struct urb **urb; 107518fc4ebdSDeepa Dinamani struct usbtest_param_32 *param; 10761da177e4SLinus Torvalds int last; 10771da177e4SLinus Torvalds }; 10781da177e4SLinus Torvalds 1079c952a8baSHuang Rui #define NUM_SUBCASES 16 /* how many test subcases here? */ 10801da177e4SLinus Torvalds 10811da177e4SLinus Torvalds struct subcase { 10821da177e4SLinus Torvalds struct usb_ctrlrequest setup; 10831da177e4SLinus Torvalds int number; 10841da177e4SLinus Torvalds int expected; 10851da177e4SLinus Torvalds }; 10861da177e4SLinus Torvalds 10877d12e780SDavid Howells static void ctrl_complete(struct urb *urb) 10881da177e4SLinus Torvalds { 10891da177e4SLinus Torvalds struct ctrl_ctx *ctx = urb->context; 10901da177e4SLinus Torvalds struct usb_ctrlrequest *reqp; 10911da177e4SLinus Torvalds struct subcase *subcase; 10921da177e4SLinus Torvalds int status = urb->status; 10936f3fde68SSebastian Andrzej Siewior unsigned long flags; 10941da177e4SLinus Torvalds 10951da177e4SLinus Torvalds reqp = (struct usb_ctrlrequest *)urb->setup_packet; 10961da177e4SLinus Torvalds subcase = container_of(reqp, struct subcase, setup); 10971da177e4SLinus Torvalds 10986f3fde68SSebastian Andrzej Siewior spin_lock_irqsave(&ctx->lock, flags); 10991da177e4SLinus Torvalds ctx->count--; 11001da177e4SLinus Torvalds ctx->pending--; 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds /* queue must transfer and complete in fifo order, unless 11031da177e4SLinus Torvalds * usb_unlink_urb() is used to unlink something not at the 11041da177e4SLinus Torvalds * physical queue head (not tested). 11051da177e4SLinus Torvalds */ 11061da177e4SLinus Torvalds if (subcase->number > 0) { 11071da177e4SLinus Torvalds if ((subcase->number - ctx->last) != 1) { 110828ffd79cSDavid Brownell ERROR(ctx->dev, 110928ffd79cSDavid Brownell "subcase %d completed out of order, last %d\n", 11101da177e4SLinus Torvalds subcase->number, ctx->last); 11111da177e4SLinus Torvalds status = -EDOM; 11121da177e4SLinus Torvalds ctx->last = subcase->number; 11131da177e4SLinus Torvalds goto error; 11141da177e4SLinus Torvalds } 11151da177e4SLinus Torvalds } 11161da177e4SLinus Torvalds ctx->last = subcase->number; 11171da177e4SLinus Torvalds 11181da177e4SLinus Torvalds /* succeed or fault in only one way? */ 11191da177e4SLinus Torvalds if (status == subcase->expected) 11201da177e4SLinus Torvalds status = 0; 11211da177e4SLinus Torvalds 11221da177e4SLinus Torvalds /* async unlink for cleanup? */ 11231da177e4SLinus Torvalds else if (status != -ECONNRESET) { 11241da177e4SLinus Torvalds 11251da177e4SLinus Torvalds /* some faults are allowed, not required */ 11261da177e4SLinus Torvalds if (subcase->expected > 0 && ( 112759d99785SGreg Kroah-Hartman ((status == -subcase->expected /* happened */ 112859d99785SGreg Kroah-Hartman || status == 0)))) /* didn't */ 11291da177e4SLinus Torvalds status = 0; 11301da177e4SLinus Torvalds /* sometimes more than one fault is allowed */ 11311da177e4SLinus Torvalds else if (subcase->number == 12 && status == -EPIPE) 11321da177e4SLinus Torvalds status = 0; 11331da177e4SLinus Torvalds else 113428ffd79cSDavid Brownell ERROR(ctx->dev, "subtest %d error, status %d\n", 11351da177e4SLinus Torvalds subcase->number, status); 11361da177e4SLinus Torvalds } 11371da177e4SLinus Torvalds 11381da177e4SLinus Torvalds /* unexpected status codes mean errors; ideally, in hardware */ 11391da177e4SLinus Torvalds if (status) { 11401da177e4SLinus Torvalds error: 11411da177e4SLinus Torvalds if (ctx->status == 0) { 11421da177e4SLinus Torvalds int i; 11431da177e4SLinus Torvalds 11441da177e4SLinus Torvalds ctx->status = status; 114528ffd79cSDavid Brownell ERROR(ctx->dev, "control queue %02x.%02x, err %d, " 114628ffd79cSDavid Brownell "%d left, subcase %d, len %d/%d\n", 11471da177e4SLinus Torvalds reqp->bRequestType, reqp->bRequest, 114828ffd79cSDavid Brownell status, ctx->count, subcase->number, 114928ffd79cSDavid Brownell urb->actual_length, 115028ffd79cSDavid Brownell urb->transfer_buffer_length); 11511da177e4SLinus Torvalds 11521da177e4SLinus Torvalds /* FIXME this "unlink everything" exit route should 11531da177e4SLinus Torvalds * be a separate test case. 11541da177e4SLinus Torvalds */ 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvalds /* unlink whatever's still pending */ 11571da177e4SLinus Torvalds for (i = 1; i < ctx->param->sglen; i++) { 11581da177e4SLinus Torvalds struct urb *u = ctx->urb[ 115928ffd79cSDavid Brownell (i + subcase->number) 116028ffd79cSDavid Brownell % ctx->param->sglen]; 11611da177e4SLinus Torvalds 11621da177e4SLinus Torvalds if (u == urb || !u->dev) 11631da177e4SLinus Torvalds continue; 1164caa2a122SFranck Bui-Huu spin_unlock(&ctx->lock); 11651da177e4SLinus Torvalds status = usb_unlink_urb(u); 1166caa2a122SFranck Bui-Huu spin_lock(&ctx->lock); 11671da177e4SLinus Torvalds switch (status) { 11681da177e4SLinus Torvalds case -EINPROGRESS: 11691da177e4SLinus Torvalds case -EBUSY: 11701da177e4SLinus Torvalds case -EIDRM: 11711da177e4SLinus Torvalds continue; 11721da177e4SLinus Torvalds default: 117328ffd79cSDavid Brownell ERROR(ctx->dev, "urb unlink --> %d\n", 117428ffd79cSDavid Brownell status); 11751da177e4SLinus Torvalds } 11761da177e4SLinus Torvalds } 11771da177e4SLinus Torvalds status = ctx->status; 11781da177e4SLinus Torvalds } 11791da177e4SLinus Torvalds } 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds /* resubmit if we need to, else mark this as done */ 11821da177e4SLinus Torvalds if ((status == 0) && (ctx->pending < ctx->count)) { 1183fabbf219SMartin Fuzzey status = usb_submit_urb(urb, GFP_ATOMIC); 1184fabbf219SMartin Fuzzey if (status != 0) { 118528ffd79cSDavid Brownell ERROR(ctx->dev, 118628ffd79cSDavid Brownell "can't resubmit ctrl %02x.%02x, err %d\n", 11871da177e4SLinus Torvalds reqp->bRequestType, reqp->bRequest, status); 11881da177e4SLinus Torvalds urb->dev = NULL; 11891da177e4SLinus Torvalds } else 11901da177e4SLinus Torvalds ctx->pending++; 11911da177e4SLinus Torvalds } else 11921da177e4SLinus Torvalds urb->dev = NULL; 11931da177e4SLinus Torvalds 11941da177e4SLinus Torvalds /* signal completion when nothing's queued */ 11951da177e4SLinus Torvalds if (ctx->pending == 0) 11961da177e4SLinus Torvalds complete(&ctx->complete); 11976f3fde68SSebastian Andrzej Siewior spin_unlock_irqrestore(&ctx->lock, flags); 11981da177e4SLinus Torvalds } 11991da177e4SLinus Torvalds 12001da177e4SLinus Torvalds static int 120118fc4ebdSDeepa Dinamani test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param_32 *param) 12021da177e4SLinus Torvalds { 12031da177e4SLinus Torvalds struct usb_device *udev = testdev_to_usbdev(dev); 12041da177e4SLinus Torvalds struct urb **urb; 12051da177e4SLinus Torvalds struct ctrl_ctx context; 12061da177e4SLinus Torvalds int i; 12071da177e4SLinus Torvalds 1208e65cdfaeSXi Wang if (param->sglen == 0 || param->iterations > UINT_MAX / param->sglen) 1209e65cdfaeSXi Wang return -EOPNOTSUPP; 1210e65cdfaeSXi Wang 12111da177e4SLinus Torvalds spin_lock_init(&context.lock); 12121da177e4SLinus Torvalds context.dev = dev; 12131da177e4SLinus Torvalds init_completion(&context.complete); 12141da177e4SLinus Torvalds context.count = param->sglen * param->iterations; 12151da177e4SLinus Torvalds context.pending = 0; 12161da177e4SLinus Torvalds context.status = -ENOMEM; 12171da177e4SLinus Torvalds context.param = param; 12181da177e4SLinus Torvalds context.last = -1; 12191da177e4SLinus Torvalds 12201da177e4SLinus Torvalds /* allocate and init the urbs we'll queue. 12211da177e4SLinus Torvalds * as with bulk/intr sglists, sglen is the queue depth; it also 12221da177e4SLinus Torvalds * controls which subtests run (more tests than sglen) or rerun. 12231da177e4SLinus Torvalds */ 1224e94b1766SChristoph Lameter urb = kcalloc(param->sglen, sizeof(struct urb *), GFP_KERNEL); 12251da177e4SLinus Torvalds if (!urb) 12261da177e4SLinus Torvalds return -ENOMEM; 12271da177e4SLinus Torvalds for (i = 0; i < param->sglen; i++) { 12281da177e4SLinus Torvalds int pipe = usb_rcvctrlpipe(udev, 0); 12291da177e4SLinus Torvalds unsigned len; 12301da177e4SLinus Torvalds struct urb *u; 12311da177e4SLinus Torvalds struct usb_ctrlrequest req; 12321da177e4SLinus Torvalds struct subcase *reqp; 12336def7553SMarcin Slusarz 12346def7553SMarcin Slusarz /* sign of this variable means: 12356def7553SMarcin Slusarz * -: tested code must return this (negative) error code 12366def7553SMarcin Slusarz * +: tested code may return this (negative too) error code 12376def7553SMarcin Slusarz */ 12381da177e4SLinus Torvalds int expected = 0; 12391da177e4SLinus Torvalds 12401da177e4SLinus Torvalds /* requests here are mostly expected to succeed on any 12411da177e4SLinus Torvalds * device, but some are chosen to trigger protocol stalls 12421da177e4SLinus Torvalds * or short reads. 12431da177e4SLinus Torvalds */ 1244f55055b4SHuang Rui memset(&req, 0, sizeof(req)); 12451da177e4SLinus Torvalds req.bRequest = USB_REQ_GET_DESCRIPTOR; 12461da177e4SLinus Torvalds req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 12471da177e4SLinus Torvalds 12481da177e4SLinus Torvalds switch (i % NUM_SUBCASES) { 1249fabbf219SMartin Fuzzey case 0: /* get device descriptor */ 12501da177e4SLinus Torvalds req.wValue = cpu_to_le16(USB_DT_DEVICE << 8); 12511da177e4SLinus Torvalds len = sizeof(struct usb_device_descriptor); 12521da177e4SLinus Torvalds break; 1253fabbf219SMartin Fuzzey case 1: /* get first config descriptor (only) */ 12541da177e4SLinus Torvalds req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0); 12551da177e4SLinus Torvalds len = sizeof(struct usb_config_descriptor); 12561da177e4SLinus Torvalds break; 1257fabbf219SMartin Fuzzey case 2: /* get altsetting (OFTEN STALLS) */ 12581da177e4SLinus Torvalds req.bRequest = USB_REQ_GET_INTERFACE; 12591da177e4SLinus Torvalds req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; 1260fabbf219SMartin Fuzzey /* index = 0 means first interface */ 12611da177e4SLinus Torvalds len = 1; 12621da177e4SLinus Torvalds expected = EPIPE; 12631da177e4SLinus Torvalds break; 1264fabbf219SMartin Fuzzey case 3: /* get interface status */ 12651da177e4SLinus Torvalds req.bRequest = USB_REQ_GET_STATUS; 12661da177e4SLinus Torvalds req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; 1267fabbf219SMartin Fuzzey /* interface 0 */ 12681da177e4SLinus Torvalds len = 2; 12691da177e4SLinus Torvalds break; 1270fabbf219SMartin Fuzzey case 4: /* get device status */ 12711da177e4SLinus Torvalds req.bRequest = USB_REQ_GET_STATUS; 12721da177e4SLinus Torvalds req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 12731da177e4SLinus Torvalds len = 2; 12741da177e4SLinus Torvalds break; 1275fabbf219SMartin Fuzzey case 5: /* get device qualifier (MAY STALL) */ 12761da177e4SLinus Torvalds req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8); 12771da177e4SLinus Torvalds len = sizeof(struct usb_qualifier_descriptor); 12781da177e4SLinus Torvalds if (udev->speed != USB_SPEED_HIGH) 12791da177e4SLinus Torvalds expected = EPIPE; 12801da177e4SLinus Torvalds break; 1281fabbf219SMartin Fuzzey case 6: /* get first config descriptor, plus interface */ 12821da177e4SLinus Torvalds req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0); 12831da177e4SLinus Torvalds len = sizeof(struct usb_config_descriptor); 12841da177e4SLinus Torvalds len += sizeof(struct usb_interface_descriptor); 12851da177e4SLinus Torvalds break; 1286fabbf219SMartin Fuzzey case 7: /* get interface descriptor (ALWAYS STALLS) */ 12871da177e4SLinus Torvalds req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8); 1288fabbf219SMartin Fuzzey /* interface == 0 */ 12891da177e4SLinus Torvalds len = sizeof(struct usb_interface_descriptor); 129028ffd79cSDavid Brownell expected = -EPIPE; 12911da177e4SLinus Torvalds break; 1292fabbf219SMartin Fuzzey /* NOTE: two consecutive stalls in the queue here. 1293fabbf219SMartin Fuzzey * that tests fault recovery a bit more aggressively. */ 1294fabbf219SMartin Fuzzey case 8: /* clear endpoint halt (MAY STALL) */ 12951da177e4SLinus Torvalds req.bRequest = USB_REQ_CLEAR_FEATURE; 12961da177e4SLinus Torvalds req.bRequestType = USB_RECIP_ENDPOINT; 1297fabbf219SMartin Fuzzey /* wValue 0 == ep halt */ 1298fabbf219SMartin Fuzzey /* wIndex 0 == ep0 (shouldn't halt!) */ 12991da177e4SLinus Torvalds len = 0; 13001da177e4SLinus Torvalds pipe = usb_sndctrlpipe(udev, 0); 13011da177e4SLinus Torvalds expected = EPIPE; 13021da177e4SLinus Torvalds break; 1303fabbf219SMartin Fuzzey case 9: /* get endpoint status */ 13041da177e4SLinus Torvalds req.bRequest = USB_REQ_GET_STATUS; 13051da177e4SLinus Torvalds req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT; 1306fabbf219SMartin Fuzzey /* endpoint 0 */ 13071da177e4SLinus Torvalds len = 2; 13081da177e4SLinus Torvalds break; 1309fabbf219SMartin Fuzzey case 10: /* trigger short read (EREMOTEIO) */ 13101da177e4SLinus Torvalds req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0); 13111da177e4SLinus Torvalds len = 1024; 13121da177e4SLinus Torvalds expected = -EREMOTEIO; 13131da177e4SLinus Torvalds break; 1314fabbf219SMartin Fuzzey /* NOTE: two consecutive _different_ faults in the queue. */ 1315fabbf219SMartin Fuzzey case 11: /* get endpoint descriptor (ALWAYS STALLS) */ 13161da177e4SLinus Torvalds req.wValue = cpu_to_le16(USB_DT_ENDPOINT << 8); 1317fabbf219SMartin Fuzzey /* endpoint == 0 */ 13181da177e4SLinus Torvalds len = sizeof(struct usb_interface_descriptor); 13191da177e4SLinus Torvalds expected = EPIPE; 13201da177e4SLinus Torvalds break; 1321fabbf219SMartin Fuzzey /* NOTE: sometimes even a third fault in the queue! */ 1322fabbf219SMartin Fuzzey case 12: /* get string 0 descriptor (MAY STALL) */ 13231da177e4SLinus Torvalds req.wValue = cpu_to_le16(USB_DT_STRING << 8); 1324fabbf219SMartin Fuzzey /* string == 0, for language IDs */ 13251da177e4SLinus Torvalds len = sizeof(struct usb_interface_descriptor); 1326fabbf219SMartin Fuzzey /* may succeed when > 4 languages */ 1327fabbf219SMartin Fuzzey expected = EREMOTEIO; /* or EPIPE, if no strings */ 13281da177e4SLinus Torvalds break; 1329fabbf219SMartin Fuzzey case 13: /* short read, resembling case 10 */ 13301da177e4SLinus Torvalds req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0); 1331fabbf219SMartin Fuzzey /* last data packet "should" be DATA1, not DATA0 */ 13326a23ccd2SPaul Zimmerman if (udev->speed == USB_SPEED_SUPER) 13336a23ccd2SPaul Zimmerman len = 1024 - 512; 13346a23ccd2SPaul Zimmerman else 13351da177e4SLinus Torvalds len = 1024 - udev->descriptor.bMaxPacketSize0; 13361da177e4SLinus Torvalds expected = -EREMOTEIO; 13371da177e4SLinus Torvalds break; 1338fabbf219SMartin Fuzzey case 14: /* short read; try to fill the last packet */ 13391da177e4SLinus Torvalds req.wValue = cpu_to_le16((USB_DT_DEVICE << 8) | 0); 134028ffd79cSDavid Brownell /* device descriptor size == 18 bytes */ 13411da177e4SLinus Torvalds len = udev->descriptor.bMaxPacketSize0; 134267e7d64bSSebastian Andrzej Siewior if (udev->speed == USB_SPEED_SUPER) 134367e7d64bSSebastian Andrzej Siewior len = 512; 13441da177e4SLinus Torvalds switch (len) { 1345fabbf219SMartin Fuzzey case 8: 1346fabbf219SMartin Fuzzey len = 24; 1347fabbf219SMartin Fuzzey break; 1348fabbf219SMartin Fuzzey case 16: 1349fabbf219SMartin Fuzzey len = 32; 1350fabbf219SMartin Fuzzey break; 13511da177e4SLinus Torvalds } 13521da177e4SLinus Torvalds expected = -EREMOTEIO; 13531da177e4SLinus Torvalds break; 1354c952a8baSHuang Rui case 15: 1355c952a8baSHuang Rui req.wValue = cpu_to_le16(USB_DT_BOS << 8); 1356c952a8baSHuang Rui if (udev->bos) 1357c952a8baSHuang Rui len = le16_to_cpu(udev->bos->desc->wTotalLength); 1358c952a8baSHuang Rui else 1359c952a8baSHuang Rui len = sizeof(struct usb_bos_descriptor); 13608cf43285SSarah Sharp if (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0201) 1361c952a8baSHuang Rui expected = -EPIPE; 1362c952a8baSHuang Rui break; 13631da177e4SLinus Torvalds default: 136428ffd79cSDavid Brownell ERROR(dev, "bogus number of ctrl queue testcases!\n"); 13651da177e4SLinus Torvalds context.status = -EINVAL; 13661da177e4SLinus Torvalds goto cleanup; 13671da177e4SLinus Torvalds } 13681da177e4SLinus Torvalds req.wLength = cpu_to_le16(len); 1369457a0955SAmit Virdi urb[i] = u = simple_alloc_urb(udev, pipe, len, 0); 13701da177e4SLinus Torvalds if (!u) 13711da177e4SLinus Torvalds goto cleanup; 13721da177e4SLinus Torvalds 1373f55055b4SHuang Rui reqp = kmalloc(sizeof(*reqp), GFP_KERNEL); 13741da177e4SLinus Torvalds if (!reqp) 13751da177e4SLinus Torvalds goto cleanup; 13761da177e4SLinus Torvalds reqp->setup = req; 13771da177e4SLinus Torvalds reqp->number = i % NUM_SUBCASES; 13781da177e4SLinus Torvalds reqp->expected = expected; 13791da177e4SLinus Torvalds u->setup_packet = (char *) &reqp->setup; 13801da177e4SLinus Torvalds 13811da177e4SLinus Torvalds u->context = &context; 13821da177e4SLinus Torvalds u->complete = ctrl_complete; 13831da177e4SLinus Torvalds } 13841da177e4SLinus Torvalds 13851da177e4SLinus Torvalds /* queue the urbs */ 13861da177e4SLinus Torvalds context.urb = urb; 13871da177e4SLinus Torvalds spin_lock_irq(&context.lock); 13881da177e4SLinus Torvalds for (i = 0; i < param->sglen; i++) { 138954e6ecb2SChristoph Lameter context.status = usb_submit_urb(urb[i], GFP_ATOMIC); 13901da177e4SLinus Torvalds if (context.status != 0) { 139128ffd79cSDavid Brownell ERROR(dev, "can't submit urb[%d], status %d\n", 13921da177e4SLinus Torvalds i, context.status); 13931da177e4SLinus Torvalds context.count = context.pending; 13941da177e4SLinus Torvalds break; 13951da177e4SLinus Torvalds } 13961da177e4SLinus Torvalds context.pending++; 13971da177e4SLinus Torvalds } 13981da177e4SLinus Torvalds spin_unlock_irq(&context.lock); 13991da177e4SLinus Torvalds 14001da177e4SLinus Torvalds /* FIXME set timer and time out; provide a disconnect hook */ 14011da177e4SLinus Torvalds 14021da177e4SLinus Torvalds /* wait for the last one to complete */ 14031da177e4SLinus Torvalds if (context.pending > 0) 14041da177e4SLinus Torvalds wait_for_completion(&context.complete); 14051da177e4SLinus Torvalds 14061da177e4SLinus Torvalds cleanup: 14071da177e4SLinus Torvalds for (i = 0; i < param->sglen; i++) { 14081da177e4SLinus Torvalds if (!urb[i]) 14091da177e4SLinus Torvalds continue; 14101da177e4SLinus Torvalds urb[i]->dev = udev; 14110ede76fcSAlan Stern kfree(urb[i]->setup_packet); 14121da177e4SLinus Torvalds simple_free_urb(urb[i]); 14131da177e4SLinus Torvalds } 14141da177e4SLinus Torvalds kfree(urb); 14151da177e4SLinus Torvalds return context.status; 14161da177e4SLinus Torvalds } 14171da177e4SLinus Torvalds #undef NUM_SUBCASES 14181da177e4SLinus Torvalds 14191da177e4SLinus Torvalds 14201da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 14211da177e4SLinus Torvalds 14227d12e780SDavid Howells static void unlink1_callback(struct urb *urb) 14231da177e4SLinus Torvalds { 14241da177e4SLinus Torvalds int status = urb->status; 14251da177e4SLinus Torvalds 1426fabbf219SMartin Fuzzey /* we "know" -EPIPE (stall) never happens */ 14271da177e4SLinus Torvalds if (!status) 142854e6ecb2SChristoph Lameter status = usb_submit_urb(urb, GFP_ATOMIC); 14291da177e4SLinus Torvalds if (status) { 14301da177e4SLinus Torvalds urb->status = status; 1431cdc97792SMing Lei complete(urb->context); 14321da177e4SLinus Torvalds } 14331da177e4SLinus Torvalds } 14341da177e4SLinus Torvalds 14351da177e4SLinus Torvalds static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async) 14361da177e4SLinus Torvalds { 14371da177e4SLinus Torvalds struct urb *urb; 14381da177e4SLinus Torvalds struct completion completion; 14391da177e4SLinus Torvalds int retval = 0; 14401da177e4SLinus Torvalds 14411da177e4SLinus Torvalds init_completion(&completion); 1442457a0955SAmit Virdi urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size, 0); 14431da177e4SLinus Torvalds if (!urb) 14441da177e4SLinus Torvalds return -ENOMEM; 14451da177e4SLinus Torvalds urb->context = &completion; 14461da177e4SLinus Torvalds urb->complete = unlink1_callback; 14471da177e4SLinus Torvalds 1448e4d58f5dSHuang Rui if (usb_pipeout(urb->pipe)) { 1449e4d58f5dSHuang Rui simple_fill_buf(urb); 1450e4d58f5dSHuang Rui urb->transfer_flags |= URB_ZERO_PACKET; 1451e4d58f5dSHuang Rui } 1452e4d58f5dSHuang Rui 14531da177e4SLinus Torvalds /* keep the endpoint busy. there are lots of hc/hcd-internal 14541da177e4SLinus Torvalds * states, and testing should get to all of them over time. 14551da177e4SLinus Torvalds * 14561da177e4SLinus Torvalds * FIXME want additional tests for when endpoint is STALLing 14571da177e4SLinus Torvalds * due to errors, or is just NAKing requests. 14581da177e4SLinus Torvalds */ 1459fabbf219SMartin Fuzzey retval = usb_submit_urb(urb, GFP_KERNEL); 1460fabbf219SMartin Fuzzey if (retval != 0) { 146128ffd79cSDavid Brownell dev_err(&dev->intf->dev, "submit fail %d\n", retval); 14621da177e4SLinus Torvalds return retval; 14631da177e4SLinus Torvalds } 14641da177e4SLinus Torvalds 14651da177e4SLinus Torvalds /* unlinking that should always work. variable delay tests more 14661da177e4SLinus Torvalds * hcd states and code paths, even with little other system load. 14671da177e4SLinus Torvalds */ 14681da177e4SLinus Torvalds msleep(jiffies % (2 * INTERRUPT_RATE)); 14691da177e4SLinus Torvalds if (async) { 14703b6c023fSMartin Fuzzey while (!completion_done(&completion)) { 14711da177e4SLinus Torvalds retval = usb_unlink_urb(urb); 14723b6c023fSMartin Fuzzey 1473a7683eb3SHuang Rui if (retval == 0 && usb_pipein(urb->pipe)) 1474a7683eb3SHuang Rui retval = simple_check_buf(dev, urb); 1475a7683eb3SHuang Rui 14763b6c023fSMartin Fuzzey switch (retval) { 14773b6c023fSMartin Fuzzey case -EBUSY: 14783b6c023fSMartin Fuzzey case -EIDRM: 14793b6c023fSMartin Fuzzey /* we can't unlink urbs while they're completing 14803b6c023fSMartin Fuzzey * or if they've completed, and we haven't 14813b6c023fSMartin Fuzzey * resubmitted. "normal" drivers would prevent 14823b6c023fSMartin Fuzzey * resubmission, but since we're testing unlink 14833b6c023fSMartin Fuzzey * paths, we can't. 14841da177e4SLinus Torvalds */ 148528ffd79cSDavid Brownell ERROR(dev, "unlink retry\n"); 14863b6c023fSMartin Fuzzey continue; 14873b6c023fSMartin Fuzzey case 0: 14883b6c023fSMartin Fuzzey case -EINPROGRESS: 14893b6c023fSMartin Fuzzey break; 14903b6c023fSMartin Fuzzey 14913b6c023fSMartin Fuzzey default: 14923b6c023fSMartin Fuzzey dev_err(&dev->intf->dev, 14933b6c023fSMartin Fuzzey "unlink fail %d\n", retval); 14943b6c023fSMartin Fuzzey return retval; 14953b6c023fSMartin Fuzzey } 14963b6c023fSMartin Fuzzey 14973b6c023fSMartin Fuzzey break; 14981da177e4SLinus Torvalds } 14991da177e4SLinus Torvalds } else 15001da177e4SLinus Torvalds usb_kill_urb(urb); 15011da177e4SLinus Torvalds 15021da177e4SLinus Torvalds wait_for_completion(&completion); 15031da177e4SLinus Torvalds retval = urb->status; 15041da177e4SLinus Torvalds simple_free_urb(urb); 15051da177e4SLinus Torvalds 15061da177e4SLinus Torvalds if (async) 15071da177e4SLinus Torvalds return (retval == -ECONNRESET) ? 0 : retval - 1000; 15081da177e4SLinus Torvalds else 15091da177e4SLinus Torvalds return (retval == -ENOENT || retval == -EPERM) ? 15101da177e4SLinus Torvalds 0 : retval - 2000; 15111da177e4SLinus Torvalds } 15121da177e4SLinus Torvalds 15131da177e4SLinus Torvalds static int unlink_simple(struct usbtest_dev *dev, int pipe, int len) 15141da177e4SLinus Torvalds { 15151da177e4SLinus Torvalds int retval = 0; 15161da177e4SLinus Torvalds 15171da177e4SLinus Torvalds /* test sync and async paths */ 15181da177e4SLinus Torvalds retval = unlink1(dev, pipe, len, 1); 15191da177e4SLinus Torvalds if (!retval) 15201da177e4SLinus Torvalds retval = unlink1(dev, pipe, len, 0); 15211da177e4SLinus Torvalds return retval; 15221da177e4SLinus Torvalds } 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 15251da177e4SLinus Torvalds 1526869410f8SAlan Stern struct queued_ctx { 1527869410f8SAlan Stern struct completion complete; 1528869410f8SAlan Stern atomic_t pending; 1529869410f8SAlan Stern unsigned num; 1530869410f8SAlan Stern int status; 1531869410f8SAlan Stern struct urb **urbs; 1532869410f8SAlan Stern }; 1533869410f8SAlan Stern 1534869410f8SAlan Stern static void unlink_queued_callback(struct urb *urb) 1535869410f8SAlan Stern { 1536869410f8SAlan Stern int status = urb->status; 1537869410f8SAlan Stern struct queued_ctx *ctx = urb->context; 1538869410f8SAlan Stern 1539869410f8SAlan Stern if (ctx->status) 1540869410f8SAlan Stern goto done; 1541869410f8SAlan Stern if (urb == ctx->urbs[ctx->num - 4] || urb == ctx->urbs[ctx->num - 2]) { 1542869410f8SAlan Stern if (status == -ECONNRESET) 1543869410f8SAlan Stern goto done; 1544869410f8SAlan Stern /* What error should we report if the URB completed normally? */ 1545869410f8SAlan Stern } 1546869410f8SAlan Stern if (status != 0) 1547869410f8SAlan Stern ctx->status = status; 1548869410f8SAlan Stern 1549869410f8SAlan Stern done: 1550869410f8SAlan Stern if (atomic_dec_and_test(&ctx->pending)) 1551869410f8SAlan Stern complete(&ctx->complete); 1552869410f8SAlan Stern } 1553869410f8SAlan Stern 1554869410f8SAlan Stern static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num, 1555869410f8SAlan Stern unsigned size) 1556869410f8SAlan Stern { 1557869410f8SAlan Stern struct queued_ctx ctx; 1558869410f8SAlan Stern struct usb_device *udev = testdev_to_usbdev(dev); 1559869410f8SAlan Stern void *buf; 1560869410f8SAlan Stern dma_addr_t buf_dma; 1561869410f8SAlan Stern int i; 1562869410f8SAlan Stern int retval = -ENOMEM; 1563869410f8SAlan Stern 1564869410f8SAlan Stern init_completion(&ctx.complete); 1565869410f8SAlan Stern atomic_set(&ctx.pending, 1); /* One more than the actual value */ 1566869410f8SAlan Stern ctx.num = num; 1567869410f8SAlan Stern ctx.status = 0; 1568869410f8SAlan Stern 1569869410f8SAlan Stern buf = usb_alloc_coherent(udev, size, GFP_KERNEL, &buf_dma); 1570869410f8SAlan Stern if (!buf) 1571869410f8SAlan Stern return retval; 1572869410f8SAlan Stern memset(buf, 0, size); 1573869410f8SAlan Stern 1574869410f8SAlan Stern /* Allocate and init the urbs we'll queue */ 1575869410f8SAlan Stern ctx.urbs = kcalloc(num, sizeof(struct urb *), GFP_KERNEL); 1576869410f8SAlan Stern if (!ctx.urbs) 1577869410f8SAlan Stern goto free_buf; 1578869410f8SAlan Stern for (i = 0; i < num; i++) { 1579869410f8SAlan Stern ctx.urbs[i] = usb_alloc_urb(0, GFP_KERNEL); 1580869410f8SAlan Stern if (!ctx.urbs[i]) 1581869410f8SAlan Stern goto free_urbs; 1582869410f8SAlan Stern usb_fill_bulk_urb(ctx.urbs[i], udev, pipe, buf, size, 1583869410f8SAlan Stern unlink_queued_callback, &ctx); 1584869410f8SAlan Stern ctx.urbs[i]->transfer_dma = buf_dma; 1585869410f8SAlan Stern ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 1586e4d58f5dSHuang Rui 1587e4d58f5dSHuang Rui if (usb_pipeout(ctx.urbs[i]->pipe)) { 1588e4d58f5dSHuang Rui simple_fill_buf(ctx.urbs[i]); 1589e4d58f5dSHuang Rui ctx.urbs[i]->transfer_flags |= URB_ZERO_PACKET; 1590e4d58f5dSHuang Rui } 1591869410f8SAlan Stern } 1592869410f8SAlan Stern 1593869410f8SAlan Stern /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */ 1594869410f8SAlan Stern for (i = 0; i < num; i++) { 1595869410f8SAlan Stern atomic_inc(&ctx.pending); 1596869410f8SAlan Stern retval = usb_submit_urb(ctx.urbs[i], GFP_KERNEL); 1597869410f8SAlan Stern if (retval != 0) { 1598869410f8SAlan Stern dev_err(&dev->intf->dev, "submit urbs[%d] fail %d\n", 1599869410f8SAlan Stern i, retval); 1600869410f8SAlan Stern atomic_dec(&ctx.pending); 1601869410f8SAlan Stern ctx.status = retval; 1602869410f8SAlan Stern break; 1603869410f8SAlan Stern } 1604869410f8SAlan Stern } 1605869410f8SAlan Stern if (i == num) { 1606869410f8SAlan Stern usb_unlink_urb(ctx.urbs[num - 4]); 1607869410f8SAlan Stern usb_unlink_urb(ctx.urbs[num - 2]); 1608869410f8SAlan Stern } else { 1609869410f8SAlan Stern while (--i >= 0) 1610869410f8SAlan Stern usb_unlink_urb(ctx.urbs[i]); 1611869410f8SAlan Stern } 1612869410f8SAlan Stern 1613869410f8SAlan Stern if (atomic_dec_and_test(&ctx.pending)) /* The extra count */ 1614869410f8SAlan Stern complete(&ctx.complete); 1615869410f8SAlan Stern wait_for_completion(&ctx.complete); 1616869410f8SAlan Stern retval = ctx.status; 1617869410f8SAlan Stern 1618869410f8SAlan Stern free_urbs: 1619869410f8SAlan Stern for (i = 0; i < num; i++) 1620869410f8SAlan Stern usb_free_urb(ctx.urbs[i]); 1621869410f8SAlan Stern kfree(ctx.urbs); 1622869410f8SAlan Stern free_buf: 1623869410f8SAlan Stern usb_free_coherent(udev, size, buf, buf_dma); 1624869410f8SAlan Stern return retval; 1625869410f8SAlan Stern } 1626869410f8SAlan Stern 1627869410f8SAlan Stern /*-------------------------------------------------------------------------*/ 1628869410f8SAlan Stern 162928ffd79cSDavid Brownell static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb) 16301da177e4SLinus Torvalds { 16311da177e4SLinus Torvalds int retval; 16321da177e4SLinus Torvalds u16 status; 16331da177e4SLinus Torvalds 16341da177e4SLinus Torvalds /* shouldn't look or act halted */ 1635d9e1e148SFelipe Balbi retval = usb_get_std_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status); 16361da177e4SLinus Torvalds if (retval < 0) { 163728ffd79cSDavid Brownell ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n", 163828ffd79cSDavid Brownell ep, retval); 16391da177e4SLinus Torvalds return retval; 16401da177e4SLinus Torvalds } 16411da177e4SLinus Torvalds if (status != 0) { 164228ffd79cSDavid Brownell ERROR(tdev, "ep %02x bogus status: %04x != 0\n", ep, status); 16431da177e4SLinus Torvalds return -EINVAL; 16441da177e4SLinus Torvalds } 164528ffd79cSDavid Brownell retval = simple_io(tdev, urb, 1, 0, 0, __func__); 16461da177e4SLinus Torvalds if (retval != 0) 16471da177e4SLinus Torvalds return -EINVAL; 16481da177e4SLinus Torvalds return 0; 16491da177e4SLinus Torvalds } 16501da177e4SLinus Torvalds 165128ffd79cSDavid Brownell static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb) 16521da177e4SLinus Torvalds { 16531da177e4SLinus Torvalds int retval; 16541da177e4SLinus Torvalds u16 status; 16551da177e4SLinus Torvalds 16561da177e4SLinus Torvalds /* should look and act halted */ 1657d9e1e148SFelipe Balbi retval = usb_get_std_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status); 16581da177e4SLinus Torvalds if (retval < 0) { 165928ffd79cSDavid Brownell ERROR(tdev, "ep %02x couldn't get halt status, %d\n", 166028ffd79cSDavid Brownell ep, retval); 16611da177e4SLinus Torvalds return retval; 16621da177e4SLinus Torvalds } 16631da177e4SLinus Torvalds if (status != 1) { 166428ffd79cSDavid Brownell ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status); 16651da177e4SLinus Torvalds return -EINVAL; 16661da177e4SLinus Torvalds } 166728ffd79cSDavid Brownell retval = simple_io(tdev, urb, 1, 0, -EPIPE, __func__); 16681da177e4SLinus Torvalds if (retval != -EPIPE) 16691da177e4SLinus Torvalds return -EINVAL; 167028ffd79cSDavid Brownell retval = simple_io(tdev, urb, 1, 0, -EPIPE, "verify_still_halted"); 16711da177e4SLinus Torvalds if (retval != -EPIPE) 16721da177e4SLinus Torvalds return -EINVAL; 16731da177e4SLinus Torvalds return 0; 16741da177e4SLinus Torvalds } 16751da177e4SLinus Torvalds 167628ffd79cSDavid Brownell static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb) 16771da177e4SLinus Torvalds { 16781da177e4SLinus Torvalds int retval; 16791da177e4SLinus Torvalds 16801da177e4SLinus Torvalds /* shouldn't look or act halted now */ 168128ffd79cSDavid Brownell retval = verify_not_halted(tdev, ep, urb); 16821da177e4SLinus Torvalds if (retval < 0) 16831da177e4SLinus Torvalds return retval; 16841da177e4SLinus Torvalds 16851da177e4SLinus Torvalds /* set halt (protocol test only), verify it worked */ 16861da177e4SLinus Torvalds retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0), 16871da177e4SLinus Torvalds USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT, 16881da177e4SLinus Torvalds USB_ENDPOINT_HALT, ep, 16891da177e4SLinus Torvalds NULL, 0, USB_CTRL_SET_TIMEOUT); 16901da177e4SLinus Torvalds if (retval < 0) { 169128ffd79cSDavid Brownell ERROR(tdev, "ep %02x couldn't set halt, %d\n", ep, retval); 16921da177e4SLinus Torvalds return retval; 16931da177e4SLinus Torvalds } 169428ffd79cSDavid Brownell retval = verify_halted(tdev, ep, urb); 1695824d752bSRoger Quadros if (retval < 0) { 1696824d752bSRoger Quadros int ret; 1697824d752bSRoger Quadros 1698824d752bSRoger Quadros /* clear halt anyways, else further tests will fail */ 1699824d752bSRoger Quadros ret = usb_clear_halt(urb->dev, urb->pipe); 1700824d752bSRoger Quadros if (ret) 1701824d752bSRoger Quadros ERROR(tdev, "ep %02x couldn't clear halt, %d\n", 1702824d752bSRoger Quadros ep, ret); 1703824d752bSRoger Quadros 17041da177e4SLinus Torvalds return retval; 1705824d752bSRoger Quadros } 17061da177e4SLinus Torvalds 17071da177e4SLinus Torvalds /* clear halt (tests API + protocol), verify it worked */ 17081da177e4SLinus Torvalds retval = usb_clear_halt(urb->dev, urb->pipe); 17091da177e4SLinus Torvalds if (retval < 0) { 171028ffd79cSDavid Brownell ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval); 17111da177e4SLinus Torvalds return retval; 17121da177e4SLinus Torvalds } 171328ffd79cSDavid Brownell retval = verify_not_halted(tdev, ep, urb); 17141da177e4SLinus Torvalds if (retval < 0) 17151da177e4SLinus Torvalds return retval; 17161da177e4SLinus Torvalds 17171da177e4SLinus Torvalds /* NOTE: could also verify SET_INTERFACE clear halts ... */ 17181da177e4SLinus Torvalds 17191da177e4SLinus Torvalds return 0; 17201da177e4SLinus Torvalds } 17211da177e4SLinus Torvalds 1722cc2e60dfSMathias Nyman static int test_toggle_sync(struct usbtest_dev *tdev, int ep, struct urb *urb) 1723cc2e60dfSMathias Nyman { 1724cc2e60dfSMathias Nyman int retval; 1725cc2e60dfSMathias Nyman 1726cc2e60dfSMathias Nyman /* clear initial data toggle to DATA0 */ 1727cc2e60dfSMathias Nyman retval = usb_clear_halt(urb->dev, urb->pipe); 1728cc2e60dfSMathias Nyman if (retval < 0) { 1729cc2e60dfSMathias Nyman ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval); 1730cc2e60dfSMathias Nyman return retval; 1731cc2e60dfSMathias Nyman } 1732cc2e60dfSMathias Nyman 1733cc2e60dfSMathias Nyman /* transfer 3 data packets, should be DATA0, DATA1, DATA0 */ 1734cc2e60dfSMathias Nyman retval = simple_io(tdev, urb, 1, 0, 0, __func__); 1735cc2e60dfSMathias Nyman if (retval != 0) 1736cc2e60dfSMathias Nyman return -EINVAL; 1737cc2e60dfSMathias Nyman 1738cc2e60dfSMathias Nyman /* clear halt resets device side data toggle, host should react to it */ 1739cc2e60dfSMathias Nyman retval = usb_clear_halt(urb->dev, urb->pipe); 1740cc2e60dfSMathias Nyman if (retval < 0) { 1741cc2e60dfSMathias Nyman ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval); 1742cc2e60dfSMathias Nyman return retval; 1743cc2e60dfSMathias Nyman } 1744cc2e60dfSMathias Nyman 1745cc2e60dfSMathias Nyman /* host should use DATA0 again after clear halt */ 1746cc2e60dfSMathias Nyman retval = simple_io(tdev, urb, 1, 0, 0, __func__); 1747cc2e60dfSMathias Nyman 1748cc2e60dfSMathias Nyman return retval; 1749cc2e60dfSMathias Nyman } 1750cc2e60dfSMathias Nyman 17511da177e4SLinus Torvalds static int halt_simple(struct usbtest_dev *dev) 17521da177e4SLinus Torvalds { 17531da177e4SLinus Torvalds int ep; 17541da177e4SLinus Torvalds int retval = 0; 17551da177e4SLinus Torvalds struct urb *urb; 17566a23ccd2SPaul Zimmerman struct usb_device *udev = testdev_to_usbdev(dev); 17571da177e4SLinus Torvalds 17586a23ccd2SPaul Zimmerman if (udev->speed == USB_SPEED_SUPER) 1759457a0955SAmit Virdi urb = simple_alloc_urb(udev, 0, 1024, 0); 17606a23ccd2SPaul Zimmerman else 1761457a0955SAmit Virdi urb = simple_alloc_urb(udev, 0, 512, 0); 17621da177e4SLinus Torvalds if (urb == NULL) 17631da177e4SLinus Torvalds return -ENOMEM; 17641da177e4SLinus Torvalds 17651da177e4SLinus Torvalds if (dev->in_pipe) { 17661da177e4SLinus Torvalds ep = usb_pipeendpoint(dev->in_pipe) | USB_DIR_IN; 17671da177e4SLinus Torvalds urb->pipe = dev->in_pipe; 176828ffd79cSDavid Brownell retval = test_halt(dev, ep, urb); 17691da177e4SLinus Torvalds if (retval < 0) 17701da177e4SLinus Torvalds goto done; 17711da177e4SLinus Torvalds } 17721da177e4SLinus Torvalds 17731da177e4SLinus Torvalds if (dev->out_pipe) { 17741da177e4SLinus Torvalds ep = usb_pipeendpoint(dev->out_pipe); 17751da177e4SLinus Torvalds urb->pipe = dev->out_pipe; 177628ffd79cSDavid Brownell retval = test_halt(dev, ep, urb); 17771da177e4SLinus Torvalds } 17781da177e4SLinus Torvalds done: 17791da177e4SLinus Torvalds simple_free_urb(urb); 17801da177e4SLinus Torvalds return retval; 17811da177e4SLinus Torvalds } 17821da177e4SLinus Torvalds 1783cc2e60dfSMathias Nyman static int toggle_sync_simple(struct usbtest_dev *dev) 1784cc2e60dfSMathias Nyman { 1785cc2e60dfSMathias Nyman int ep; 1786cc2e60dfSMathias Nyman int retval = 0; 1787cc2e60dfSMathias Nyman struct urb *urb; 1788cc2e60dfSMathias Nyman struct usb_device *udev = testdev_to_usbdev(dev); 1789cc2e60dfSMathias Nyman unsigned maxp = get_maxpacket(udev, dev->out_pipe); 1790cc2e60dfSMathias Nyman 1791cc2e60dfSMathias Nyman /* 1792cc2e60dfSMathias Nyman * Create a URB that causes a transfer of uneven amount of data packets 1793cc2e60dfSMathias Nyman * This way the clear toggle has an impact on the data toggle sequence. 1794cc2e60dfSMathias Nyman * Use 2 maxpacket length packets and one zero packet. 1795cc2e60dfSMathias Nyman */ 1796cc2e60dfSMathias Nyman urb = simple_alloc_urb(udev, 0, 2 * maxp, 0); 1797cc2e60dfSMathias Nyman if (urb == NULL) 1798cc2e60dfSMathias Nyman return -ENOMEM; 1799cc2e60dfSMathias Nyman 1800cc2e60dfSMathias Nyman urb->transfer_flags |= URB_ZERO_PACKET; 1801cc2e60dfSMathias Nyman 1802cc2e60dfSMathias Nyman ep = usb_pipeendpoint(dev->out_pipe); 1803cc2e60dfSMathias Nyman urb->pipe = dev->out_pipe; 1804cc2e60dfSMathias Nyman retval = test_toggle_sync(dev, ep, urb); 1805cc2e60dfSMathias Nyman 1806cc2e60dfSMathias Nyman simple_free_urb(urb); 1807cc2e60dfSMathias Nyman return retval; 1808cc2e60dfSMathias Nyman } 1809cc2e60dfSMathias Nyman 18101da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 18111da177e4SLinus Torvalds 18121da177e4SLinus Torvalds /* Control OUT tests use the vendor control requests from Intel's 18131da177e4SLinus Torvalds * USB 2.0 compliance test device: write a buffer, read it back. 18141da177e4SLinus Torvalds * 18151da177e4SLinus Torvalds * Intel's spec only _requires_ that it work for one packet, which 18161da177e4SLinus Torvalds * is pretty weak. Some HCDs place limits here; most devices will 18171da177e4SLinus Torvalds * need to be able to handle more than one OUT data packet. We'll 18181da177e4SLinus Torvalds * try whatever we're told to try. 18191da177e4SLinus Torvalds */ 18201da177e4SLinus Torvalds static int ctrl_out(struct usbtest_dev *dev, 1821084fb206SMartin Fuzzey unsigned count, unsigned length, unsigned vary, unsigned offset) 18221da177e4SLinus Torvalds { 1823f54fa84dSOrjan Friberg unsigned i, j, len; 1824f54fa84dSOrjan Friberg int retval; 18251da177e4SLinus Torvalds u8 *buf; 18261da177e4SLinus Torvalds char *what = "?"; 18271da177e4SLinus Torvalds struct usb_device *udev; 18281da177e4SLinus Torvalds 1829ff7c79e4SDavid Brownell if (length < 1 || length > 0xffff || vary >= length) 18301da177e4SLinus Torvalds return -EINVAL; 18311da177e4SLinus Torvalds 1832084fb206SMartin Fuzzey buf = kmalloc(length + offset, GFP_KERNEL); 18331da177e4SLinus Torvalds if (!buf) 18341da177e4SLinus Torvalds return -ENOMEM; 18351da177e4SLinus Torvalds 1836084fb206SMartin Fuzzey buf += offset; 18371da177e4SLinus Torvalds udev = testdev_to_usbdev(dev); 18381da177e4SLinus Torvalds len = length; 18391da177e4SLinus Torvalds retval = 0; 18401da177e4SLinus Torvalds 18411da177e4SLinus Torvalds /* NOTE: hardware might well act differently if we pushed it 18421da177e4SLinus Torvalds * with lots back-to-back queued requests. 18431da177e4SLinus Torvalds */ 18441da177e4SLinus Torvalds for (i = 0; i < count; i++) { 18451da177e4SLinus Torvalds /* write patterned data */ 18461da177e4SLinus Torvalds for (j = 0; j < len; j++) 1847169900f9SPeter Chen buf[j] = (u8)(i + j); 18481da177e4SLinus Torvalds retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 18491da177e4SLinus Torvalds 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR, 18501da177e4SLinus Torvalds 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); 18511da177e4SLinus Torvalds if (retval != len) { 18521da177e4SLinus Torvalds what = "write"; 1853ff7c79e4SDavid Brownell if (retval >= 0) { 185428ffd79cSDavid Brownell ERROR(dev, "ctrl_out, wlen %d (expected %d)\n", 1855ff7c79e4SDavid Brownell retval, len); 1856ff7c79e4SDavid Brownell retval = -EBADMSG; 1857ff7c79e4SDavid Brownell } 18581da177e4SLinus Torvalds break; 18591da177e4SLinus Torvalds } 18601da177e4SLinus Torvalds 18611da177e4SLinus Torvalds /* read it back -- assuming nothing intervened!! */ 18621da177e4SLinus Torvalds retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 18631da177e4SLinus Torvalds 0x5c, USB_DIR_IN|USB_TYPE_VENDOR, 18641da177e4SLinus Torvalds 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); 18651da177e4SLinus Torvalds if (retval != len) { 18661da177e4SLinus Torvalds what = "read"; 1867ff7c79e4SDavid Brownell if (retval >= 0) { 186828ffd79cSDavid Brownell ERROR(dev, "ctrl_out, rlen %d (expected %d)\n", 1869ff7c79e4SDavid Brownell retval, len); 1870ff7c79e4SDavid Brownell retval = -EBADMSG; 1871ff7c79e4SDavid Brownell } 18721da177e4SLinus Torvalds break; 18731da177e4SLinus Torvalds } 18741da177e4SLinus Torvalds 18751da177e4SLinus Torvalds /* fail if we can't verify */ 18761da177e4SLinus Torvalds for (j = 0; j < len; j++) { 18771da177e4SLinus Torvalds if (buf[j] != (u8)(i + j)) { 187828ffd79cSDavid Brownell ERROR(dev, "ctrl_out, byte %d is %d not %d\n", 1879169900f9SPeter Chen j, buf[j], (u8)(i + j)); 18801da177e4SLinus Torvalds retval = -EBADMSG; 18811da177e4SLinus Torvalds break; 18821da177e4SLinus Torvalds } 18831da177e4SLinus Torvalds } 18841da177e4SLinus Torvalds if (retval < 0) { 18851da177e4SLinus Torvalds what = "verify"; 18861da177e4SLinus Torvalds break; 18871da177e4SLinus Torvalds } 18881da177e4SLinus Torvalds 18891da177e4SLinus Torvalds len += vary; 1890ff7c79e4SDavid Brownell 1891ff7c79e4SDavid Brownell /* [real world] the "zero bytes IN" case isn't really used. 1892dc0d5c1eSJoe Perches * hardware can easily trip up in this weird case, since its 1893ff7c79e4SDavid Brownell * status stage is IN, not OUT like other ep0in transfers. 1894ff7c79e4SDavid Brownell */ 18951da177e4SLinus Torvalds if (len > length) 1896ff7c79e4SDavid Brownell len = realworld ? 1 : 0; 18971da177e4SLinus Torvalds } 18981da177e4SLinus Torvalds 18991da177e4SLinus Torvalds if (retval < 0) 190028ffd79cSDavid Brownell ERROR(dev, "ctrl_out %s failed, code %d, count %d\n", 19011da177e4SLinus Torvalds what, retval, i); 19021da177e4SLinus Torvalds 1903084fb206SMartin Fuzzey kfree(buf - offset); 19041da177e4SLinus Torvalds return retval; 19051da177e4SLinus Torvalds } 19061da177e4SLinus Torvalds 19071da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 19081da177e4SLinus Torvalds 1909145f48c5SPeter Chen /* ISO/BULK tests ... mimics common usage 19101da177e4SLinus Torvalds * - buffer length is split into N packets (mostly maxpacket sized) 19111da177e4SLinus Torvalds * - multi-buffers according to sglen 19121da177e4SLinus Torvalds */ 19131da177e4SLinus Torvalds 1914145f48c5SPeter Chen struct transfer_context { 19151da177e4SLinus Torvalds unsigned count; 19161da177e4SLinus Torvalds unsigned pending; 19171da177e4SLinus Torvalds spinlock_t lock; 19181da177e4SLinus Torvalds struct completion done; 19199da2150fSAlan Stern int submit_error; 19201da177e4SLinus Torvalds unsigned long errors; 19219da2150fSAlan Stern unsigned long packet_count; 19221da177e4SLinus Torvalds struct usbtest_dev *dev; 1923145f48c5SPeter Chen bool is_iso; 19241da177e4SLinus Torvalds }; 19251da177e4SLinus Torvalds 1926145f48c5SPeter Chen static void complicated_callback(struct urb *urb) 19271da177e4SLinus Torvalds { 1928145f48c5SPeter Chen struct transfer_context *ctx = urb->context; 19296f3fde68SSebastian Andrzej Siewior unsigned long flags; 19301da177e4SLinus Torvalds 19316f3fde68SSebastian Andrzej Siewior spin_lock_irqsave(&ctx->lock, flags); 19321da177e4SLinus Torvalds ctx->count--; 19331da177e4SLinus Torvalds 19349da2150fSAlan Stern ctx->packet_count += urb->number_of_packets; 19351da177e4SLinus Torvalds if (urb->error_count > 0) 19361da177e4SLinus Torvalds ctx->errors += urb->error_count; 19379da2150fSAlan Stern else if (urb->status != 0) 1938145f48c5SPeter Chen ctx->errors += (ctx->is_iso ? urb->number_of_packets : 1); 193940aed524SMartin Fuzzey else if (urb->actual_length != urb->transfer_buffer_length) 194040aed524SMartin Fuzzey ctx->errors++; 1941084fb206SMartin Fuzzey else if (check_guard_bytes(ctx->dev, urb) != 0) 1942084fb206SMartin Fuzzey ctx->errors++; 19431da177e4SLinus Torvalds 19449da2150fSAlan Stern if (urb->status == 0 && ctx->count > (ctx->pending - 1) 19459da2150fSAlan Stern && !ctx->submit_error) { 19461da177e4SLinus Torvalds int status = usb_submit_urb(urb, GFP_ATOMIC); 19471da177e4SLinus Torvalds switch (status) { 19481da177e4SLinus Torvalds case 0: 19491da177e4SLinus Torvalds goto done; 19501da177e4SLinus Torvalds default: 195128ffd79cSDavid Brownell dev_err(&ctx->dev->intf->dev, 1952c7c78067SPeter Chen "resubmit err %d\n", 19531da177e4SLinus Torvalds status); 19541da177e4SLinus Torvalds /* FALLTHROUGH */ 19551da177e4SLinus Torvalds case -ENODEV: /* disconnected */ 19569da2150fSAlan Stern case -ESHUTDOWN: /* endpoint disabled */ 19579da2150fSAlan Stern ctx->submit_error = 1; 19581da177e4SLinus Torvalds break; 19591da177e4SLinus Torvalds } 19601da177e4SLinus Torvalds } 19611da177e4SLinus Torvalds 19621da177e4SLinus Torvalds ctx->pending--; 19631da177e4SLinus Torvalds if (ctx->pending == 0) { 19641da177e4SLinus Torvalds if (ctx->errors) 196528ffd79cSDavid Brownell dev_err(&ctx->dev->intf->dev, 1966c7c78067SPeter Chen "during the test, %lu errors out of %lu\n", 19679da2150fSAlan Stern ctx->errors, ctx->packet_count); 19681da177e4SLinus Torvalds complete(&ctx->done); 19691da177e4SLinus Torvalds } 19701da177e4SLinus Torvalds done: 19716f3fde68SSebastian Andrzej Siewior spin_unlock_irqrestore(&ctx->lock, flags); 19721da177e4SLinus Torvalds } 19731da177e4SLinus Torvalds 19741da177e4SLinus Torvalds static struct urb *iso_alloc_urb( 19751da177e4SLinus Torvalds struct usb_device *udev, 19761da177e4SLinus Torvalds int pipe, 19771da177e4SLinus Torvalds struct usb_endpoint_descriptor *desc, 1978084fb206SMartin Fuzzey long bytes, 1979084fb206SMartin Fuzzey unsigned offset 19801da177e4SLinus Torvalds ) 19811da177e4SLinus Torvalds { 19821da177e4SLinus Torvalds struct urb *urb; 19831da177e4SLinus Torvalds unsigned i, maxp, packets; 19841da177e4SLinus Torvalds 19851da177e4SLinus Torvalds if (bytes < 0 || !desc) 19861da177e4SLinus Torvalds return NULL; 1987*0d1ec194SPeter Chen 19889f8e32dfSJaejoong Kim maxp = usb_endpoint_maxp(desc); 1989*0d1ec194SPeter Chen if (udev->speed >= USB_SPEED_SUPER) 1990*0d1ec194SPeter Chen maxp *= ss_isoc_get_packet_num(udev, pipe); 1991*0d1ec194SPeter Chen else 1992131e19b9SFelipe Balbi maxp *= usb_endpoint_maxp_mult(desc); 1993*0d1ec194SPeter Chen 1994dfa5ec79SJulia Lawall packets = DIV_ROUND_UP(bytes, maxp); 19951da177e4SLinus Torvalds 1996e94b1766SChristoph Lameter urb = usb_alloc_urb(packets, GFP_KERNEL); 19971da177e4SLinus Torvalds if (!urb) 19981da177e4SLinus Torvalds return urb; 19991da177e4SLinus Torvalds urb->dev = udev; 20001da177e4SLinus Torvalds urb->pipe = pipe; 20011da177e4SLinus Torvalds 20021da177e4SLinus Torvalds urb->number_of_packets = packets; 20031da177e4SLinus Torvalds urb->transfer_buffer_length = bytes; 2004084fb206SMartin Fuzzey urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset, 2005084fb206SMartin Fuzzey GFP_KERNEL, 20061da177e4SLinus Torvalds &urb->transfer_dma); 20071da177e4SLinus Torvalds if (!urb->transfer_buffer) { 20081da177e4SLinus Torvalds usb_free_urb(urb); 20091da177e4SLinus Torvalds return NULL; 20101da177e4SLinus Torvalds } 2011084fb206SMartin Fuzzey if (offset) { 2012084fb206SMartin Fuzzey memset(urb->transfer_buffer, GUARD_BYTE, offset); 2013084fb206SMartin Fuzzey urb->transfer_buffer += offset; 2014084fb206SMartin Fuzzey urb->transfer_dma += offset; 2015084fb206SMartin Fuzzey } 2016084fb206SMartin Fuzzey /* For inbound transfers use guard byte so that test fails if 2017084fb206SMartin Fuzzey data not correctly copied */ 2018084fb206SMartin Fuzzey memset(urb->transfer_buffer, 2019084fb206SMartin Fuzzey usb_pipein(urb->pipe) ? GUARD_BYTE : 0, 2020084fb206SMartin Fuzzey bytes); 2021084fb206SMartin Fuzzey 20221da177e4SLinus Torvalds for (i = 0; i < packets; i++) { 20231da177e4SLinus Torvalds /* here, only the last packet will be short */ 20241da177e4SLinus Torvalds urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp); 20251da177e4SLinus Torvalds bytes -= urb->iso_frame_desc[i].length; 20261da177e4SLinus Torvalds 20271da177e4SLinus Torvalds urb->iso_frame_desc[i].offset = maxp * i; 20281da177e4SLinus Torvalds } 20291da177e4SLinus Torvalds 2030145f48c5SPeter Chen urb->complete = complicated_callback; 2031fabbf219SMartin Fuzzey /* urb->context = SET BY CALLER */ 20321da177e4SLinus Torvalds urb->interval = 1 << (desc->bInterval - 1); 20331da177e4SLinus Torvalds urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 20341da177e4SLinus Torvalds return urb; 20351da177e4SLinus Torvalds } 20361da177e4SLinus Torvalds 20371da177e4SLinus Torvalds static int 203818fc4ebdSDeepa Dinamani test_queue(struct usbtest_dev *dev, struct usbtest_param_32 *param, 2039084fb206SMartin Fuzzey int pipe, struct usb_endpoint_descriptor *desc, unsigned offset) 20401da177e4SLinus Torvalds { 2041145f48c5SPeter Chen struct transfer_context context; 20421da177e4SLinus Torvalds struct usb_device *udev; 20431da177e4SLinus Torvalds unsigned i; 20441da177e4SLinus Torvalds unsigned long packets = 0; 20459da2150fSAlan Stern int status = 0; 2046c53439fbSTobin C. Harding struct urb *urbs[MAX_SGLEN]; 20471da177e4SLinus Torvalds 2048cb84f568SDan Carpenter if (!param->sglen || param->iterations > UINT_MAX / param->sglen) 2049cb84f568SDan Carpenter return -EINVAL; 2050cb84f568SDan Carpenter 2051c53439fbSTobin C. Harding if (param->sglen > MAX_SGLEN) 2052c53439fbSTobin C. Harding return -EINVAL; 2053c53439fbSTobin C. Harding 2054f55055b4SHuang Rui memset(&context, 0, sizeof(context)); 20551da177e4SLinus Torvalds context.count = param->iterations * param->sglen; 20561da177e4SLinus Torvalds context.dev = dev; 2057145f48c5SPeter Chen context.is_iso = !!desc; 20581da177e4SLinus Torvalds init_completion(&context.done); 20591da177e4SLinus Torvalds spin_lock_init(&context.lock); 20601da177e4SLinus Torvalds 20611da177e4SLinus Torvalds udev = testdev_to_usbdev(dev); 20621da177e4SLinus Torvalds 20631da177e4SLinus Torvalds for (i = 0; i < param->sglen; i++) { 2064145f48c5SPeter Chen if (context.is_iso) 20651da177e4SLinus Torvalds urbs[i] = iso_alloc_urb(udev, pipe, desc, 2066084fb206SMartin Fuzzey param->length, offset); 2067145f48c5SPeter Chen else 2068145f48c5SPeter Chen urbs[i] = complicated_alloc_urb(udev, pipe, 2069145f48c5SPeter Chen param->length, 0); 2070145f48c5SPeter Chen 20711da177e4SLinus Torvalds if (!urbs[i]) { 20721da177e4SLinus Torvalds status = -ENOMEM; 20731da177e4SLinus Torvalds goto fail; 20741da177e4SLinus Torvalds } 20751da177e4SLinus Torvalds packets += urbs[i]->number_of_packets; 20761da177e4SLinus Torvalds urbs[i]->context = &context; 20771da177e4SLinus Torvalds } 20781da177e4SLinus Torvalds packets *= param->iterations; 2079145f48c5SPeter Chen 2080145f48c5SPeter Chen if (context.is_iso) { 2081*0d1ec194SPeter Chen int transaction_num; 2082*0d1ec194SPeter Chen 2083*0d1ec194SPeter Chen if (udev->speed >= USB_SPEED_SUPER) 2084*0d1ec194SPeter Chen transaction_num = ss_isoc_get_packet_num(udev, pipe); 2085*0d1ec194SPeter Chen else 2086*0d1ec194SPeter Chen transaction_num = usb_endpoint_maxp_mult(desc); 2087*0d1ec194SPeter Chen 2088145f48c5SPeter Chen dev_info(&dev->intf->dev, 2089145f48c5SPeter Chen "iso period %d %sframes, wMaxPacket %d, transactions: %d\n", 2090145f48c5SPeter Chen 1 << (desc->bInterval - 1), 2091*0d1ec194SPeter Chen (udev->speed >= USB_SPEED_HIGH) ? "micro" : "", 2092efdd17e6SFelipe Balbi usb_endpoint_maxp(desc), 2093*0d1ec194SPeter Chen transaction_num); 2094145f48c5SPeter Chen 209528ffd79cSDavid Brownell dev_info(&dev->intf->dev, 2096a0c9d0deSPeter Chen "total %lu msec (%lu packets)\n", 20971da177e4SLinus Torvalds (packets * (1 << (desc->bInterval - 1))) 2098*0d1ec194SPeter Chen / ((udev->speed >= USB_SPEED_HIGH) ? 8 : 1), 20991da177e4SLinus Torvalds packets); 2100145f48c5SPeter Chen } 21011da177e4SLinus Torvalds 21021da177e4SLinus Torvalds spin_lock_irq(&context.lock); 21031da177e4SLinus Torvalds for (i = 0; i < param->sglen; i++) { 21049da2150fSAlan Stern ++context.pending; 210554e6ecb2SChristoph Lameter status = usb_submit_urb(urbs[i], GFP_ATOMIC); 21061da177e4SLinus Torvalds if (status < 0) { 21071da177e4SLinus Torvalds ERROR(dev, "submit iso[%d], error %d\n", i, status); 21081da177e4SLinus Torvalds if (i == 0) { 21091da177e4SLinus Torvalds spin_unlock_irq(&context.lock); 21101da177e4SLinus Torvalds goto fail; 21111da177e4SLinus Torvalds } 21121da177e4SLinus Torvalds 21131da177e4SLinus Torvalds simple_free_urb(urbs[i]); 2114e10e1becSMing Lei urbs[i] = NULL; 21151da177e4SLinus Torvalds context.pending--; 21169da2150fSAlan Stern context.submit_error = 1; 21179da2150fSAlan Stern break; 21181da177e4SLinus Torvalds } 21191da177e4SLinus Torvalds } 21201da177e4SLinus Torvalds spin_unlock_irq(&context.lock); 21211da177e4SLinus Torvalds 21221da177e4SLinus Torvalds wait_for_completion(&context.done); 21239da2150fSAlan Stern 2124e10e1becSMing Lei for (i = 0; i < param->sglen; i++) { 2125e10e1becSMing Lei if (urbs[i]) 2126e10e1becSMing Lei simple_free_urb(urbs[i]); 2127e10e1becSMing Lei } 21289da2150fSAlan Stern /* 21299da2150fSAlan Stern * Isochronous transfers are expected to fail sometimes. As an 21309da2150fSAlan Stern * arbitrary limit, we will report an error if any submissions 21319da2150fSAlan Stern * fail or if the transfer failure rate is > 10%. 21329da2150fSAlan Stern */ 21339da2150fSAlan Stern if (status != 0) 21349da2150fSAlan Stern ; 21359da2150fSAlan Stern else if (context.submit_error) 21369da2150fSAlan Stern status = -EACCES; 2137145f48c5SPeter Chen else if (context.errors > 2138145f48c5SPeter Chen (context.is_iso ? context.packet_count / 10 : 0)) 21399da2150fSAlan Stern status = -EIO; 21409da2150fSAlan Stern return status; 21411da177e4SLinus Torvalds 21421da177e4SLinus Torvalds fail: 21431da177e4SLinus Torvalds for (i = 0; i < param->sglen; i++) { 21441da177e4SLinus Torvalds if (urbs[i]) 21451da177e4SLinus Torvalds simple_free_urb(urbs[i]); 21461da177e4SLinus Torvalds } 21471da177e4SLinus Torvalds return status; 21481da177e4SLinus Torvalds } 21491da177e4SLinus Torvalds 2150084fb206SMartin Fuzzey static int test_unaligned_bulk( 2151084fb206SMartin Fuzzey struct usbtest_dev *tdev, 2152084fb206SMartin Fuzzey int pipe, 2153084fb206SMartin Fuzzey unsigned length, 2154084fb206SMartin Fuzzey int iterations, 2155084fb206SMartin Fuzzey unsigned transfer_flags, 2156084fb206SMartin Fuzzey const char *label) 2157084fb206SMartin Fuzzey { 2158084fb206SMartin Fuzzey int retval; 2159145f48c5SPeter Chen struct urb *urb = usbtest_alloc_urb(testdev_to_usbdev(tdev), 2160145f48c5SPeter Chen pipe, length, transfer_flags, 1, 0, simple_callback); 2161084fb206SMartin Fuzzey 2162084fb206SMartin Fuzzey if (!urb) 2163084fb206SMartin Fuzzey return -ENOMEM; 2164084fb206SMartin Fuzzey 2165084fb206SMartin Fuzzey retval = simple_io(tdev, urb, iterations, 0, 0, label); 2166084fb206SMartin Fuzzey simple_free_urb(urb); 2167084fb206SMartin Fuzzey return retval; 2168084fb206SMartin Fuzzey } 2169084fb206SMartin Fuzzey 217018fc4ebdSDeepa Dinamani /* Run tests. */ 21711da177e4SLinus Torvalds static int 217218fc4ebdSDeepa Dinamani usbtest_do_ioctl(struct usb_interface *intf, struct usbtest_param_32 *param) 21731da177e4SLinus Torvalds { 21741da177e4SLinus Torvalds struct usbtest_dev *dev = usb_get_intfdata(intf); 21751da177e4SLinus Torvalds struct usb_device *udev = testdev_to_usbdev(dev); 21761da177e4SLinus Torvalds struct urb *urb; 21771da177e4SLinus Torvalds struct scatterlist *sg; 21781da177e4SLinus Torvalds struct usb_sg_request req; 21791da177e4SLinus Torvalds unsigned i; 218018fc4ebdSDeepa Dinamani int retval = -EOPNOTSUPP; 21811da177e4SLinus Torvalds 21828aafdf6aSroel kluin if (param->iterations <= 0) 21831da177e4SLinus Torvalds return -EINVAL; 2184cb84f568SDan Carpenter if (param->sglen > MAX_SGLEN) 2185cb84f568SDan Carpenter return -EINVAL; 21861da177e4SLinus Torvalds /* 21871da177e4SLinus Torvalds * Just a bunch of test cases that every HCD is expected to handle. 21881da177e4SLinus Torvalds * 21891da177e4SLinus Torvalds * Some may need specific firmware, though it'd be good to have 21901da177e4SLinus Torvalds * one firmware image to handle all the test cases. 21911da177e4SLinus Torvalds * 21921da177e4SLinus Torvalds * FIXME add more tests! cancel requests, verify the data, control 21931da177e4SLinus Torvalds * queueing, concurrent read+write threads, and so on. 21941da177e4SLinus Torvalds */ 21951da177e4SLinus Torvalds switch (param->test_num) { 21961da177e4SLinus Torvalds 21971da177e4SLinus Torvalds case 0: 219828ffd79cSDavid Brownell dev_info(&intf->dev, "TEST 0: NOP\n"); 21991da177e4SLinus Torvalds retval = 0; 22001da177e4SLinus Torvalds break; 22011da177e4SLinus Torvalds 22021da177e4SLinus Torvalds /* Simple non-queued bulk I/O tests */ 22031da177e4SLinus Torvalds case 1: 22041da177e4SLinus Torvalds if (dev->out_pipe == 0) 22051da177e4SLinus Torvalds break; 220628ffd79cSDavid Brownell dev_info(&intf->dev, 22071da177e4SLinus Torvalds "TEST 1: write %d bytes %u times\n", 22081da177e4SLinus Torvalds param->length, param->iterations); 2209457a0955SAmit Virdi urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0); 22101da177e4SLinus Torvalds if (!urb) { 22111da177e4SLinus Torvalds retval = -ENOMEM; 22121da177e4SLinus Torvalds break; 22131da177e4SLinus Torvalds } 2214fabbf219SMartin Fuzzey /* FIRMWARE: bulk sink (maybe accepts short writes) */ 221528ffd79cSDavid Brownell retval = simple_io(dev, urb, param->iterations, 0, 0, "test1"); 22161da177e4SLinus Torvalds simple_free_urb(urb); 22171da177e4SLinus Torvalds break; 22181da177e4SLinus Torvalds case 2: 22191da177e4SLinus Torvalds if (dev->in_pipe == 0) 22201da177e4SLinus Torvalds break; 222128ffd79cSDavid Brownell dev_info(&intf->dev, 22221da177e4SLinus Torvalds "TEST 2: read %d bytes %u times\n", 22231da177e4SLinus Torvalds param->length, param->iterations); 2224457a0955SAmit Virdi urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0); 22251da177e4SLinus Torvalds if (!urb) { 22261da177e4SLinus Torvalds retval = -ENOMEM; 22271da177e4SLinus Torvalds break; 22281da177e4SLinus Torvalds } 2229fabbf219SMartin Fuzzey /* FIRMWARE: bulk source (maybe generates short writes) */ 223028ffd79cSDavid Brownell retval = simple_io(dev, urb, param->iterations, 0, 0, "test2"); 22311da177e4SLinus Torvalds simple_free_urb(urb); 22321da177e4SLinus Torvalds break; 22331da177e4SLinus Torvalds case 3: 22341da177e4SLinus Torvalds if (dev->out_pipe == 0 || param->vary == 0) 22351da177e4SLinus Torvalds break; 223628ffd79cSDavid Brownell dev_info(&intf->dev, 22371da177e4SLinus Torvalds "TEST 3: write/%d 0..%d bytes %u times\n", 22381da177e4SLinus Torvalds param->vary, param->length, param->iterations); 2239457a0955SAmit Virdi urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0); 22401da177e4SLinus Torvalds if (!urb) { 22411da177e4SLinus Torvalds retval = -ENOMEM; 22421da177e4SLinus Torvalds break; 22431da177e4SLinus Torvalds } 2244fabbf219SMartin Fuzzey /* FIRMWARE: bulk sink (maybe accepts short writes) */ 224528ffd79cSDavid Brownell retval = simple_io(dev, urb, param->iterations, param->vary, 22461da177e4SLinus Torvalds 0, "test3"); 22471da177e4SLinus Torvalds simple_free_urb(urb); 22481da177e4SLinus Torvalds break; 22491da177e4SLinus Torvalds case 4: 22501da177e4SLinus Torvalds if (dev->in_pipe == 0 || param->vary == 0) 22511da177e4SLinus Torvalds break; 225228ffd79cSDavid Brownell dev_info(&intf->dev, 22531da177e4SLinus Torvalds "TEST 4: read/%d 0..%d bytes %u times\n", 22541da177e4SLinus Torvalds param->vary, param->length, param->iterations); 2255457a0955SAmit Virdi urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0); 22561da177e4SLinus Torvalds if (!urb) { 22571da177e4SLinus Torvalds retval = -ENOMEM; 22581da177e4SLinus Torvalds break; 22591da177e4SLinus Torvalds } 2260fabbf219SMartin Fuzzey /* FIRMWARE: bulk source (maybe generates short writes) */ 226128ffd79cSDavid Brownell retval = simple_io(dev, urb, param->iterations, param->vary, 22621da177e4SLinus Torvalds 0, "test4"); 22631da177e4SLinus Torvalds simple_free_urb(urb); 22641da177e4SLinus Torvalds break; 22651da177e4SLinus Torvalds 22661da177e4SLinus Torvalds /* Queued bulk I/O tests */ 22671da177e4SLinus Torvalds case 5: 22681da177e4SLinus Torvalds if (dev->out_pipe == 0 || param->sglen == 0) 22691da177e4SLinus Torvalds break; 227028ffd79cSDavid Brownell dev_info(&intf->dev, 22711da177e4SLinus Torvalds "TEST 5: write %d sglists %d entries of %d bytes\n", 22721da177e4SLinus Torvalds param->iterations, 22731da177e4SLinus Torvalds param->sglen, param->length); 2274b9a6e8e1SAlan Stern sg = alloc_sglist(param->sglen, param->length, 2275b9a6e8e1SAlan Stern 0, dev, dev->out_pipe); 22761da177e4SLinus Torvalds if (!sg) { 22771da177e4SLinus Torvalds retval = -ENOMEM; 22781da177e4SLinus Torvalds break; 22791da177e4SLinus Torvalds } 2280fabbf219SMartin Fuzzey /* FIRMWARE: bulk sink (maybe accepts short writes) */ 228128ffd79cSDavid Brownell retval = perform_sglist(dev, param->iterations, dev->out_pipe, 22821da177e4SLinus Torvalds &req, sg, param->sglen); 22831da177e4SLinus Torvalds free_sglist(sg, param->sglen); 22841da177e4SLinus Torvalds break; 22851da177e4SLinus Torvalds 22861da177e4SLinus Torvalds case 6: 22871da177e4SLinus Torvalds if (dev->in_pipe == 0 || param->sglen == 0) 22881da177e4SLinus Torvalds break; 228928ffd79cSDavid Brownell dev_info(&intf->dev, 22901da177e4SLinus Torvalds "TEST 6: read %d sglists %d entries of %d bytes\n", 22911da177e4SLinus Torvalds param->iterations, 22921da177e4SLinus Torvalds param->sglen, param->length); 2293b9a6e8e1SAlan Stern sg = alloc_sglist(param->sglen, param->length, 2294b9a6e8e1SAlan Stern 0, dev, dev->in_pipe); 22951da177e4SLinus Torvalds if (!sg) { 22961da177e4SLinus Torvalds retval = -ENOMEM; 22971da177e4SLinus Torvalds break; 22981da177e4SLinus Torvalds } 2299fabbf219SMartin Fuzzey /* FIRMWARE: bulk source (maybe generates short writes) */ 230028ffd79cSDavid Brownell retval = perform_sglist(dev, param->iterations, dev->in_pipe, 23011da177e4SLinus Torvalds &req, sg, param->sglen); 23021da177e4SLinus Torvalds free_sglist(sg, param->sglen); 23031da177e4SLinus Torvalds break; 23041da177e4SLinus Torvalds case 7: 23051da177e4SLinus Torvalds if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0) 23061da177e4SLinus Torvalds break; 230728ffd79cSDavid Brownell dev_info(&intf->dev, 23081da177e4SLinus Torvalds "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n", 23091da177e4SLinus Torvalds param->vary, param->iterations, 23101da177e4SLinus Torvalds param->sglen, param->length); 2311b9a6e8e1SAlan Stern sg = alloc_sglist(param->sglen, param->length, 2312b9a6e8e1SAlan Stern param->vary, dev, dev->out_pipe); 23131da177e4SLinus Torvalds if (!sg) { 23141da177e4SLinus Torvalds retval = -ENOMEM; 23151da177e4SLinus Torvalds break; 23161da177e4SLinus Torvalds } 2317fabbf219SMartin Fuzzey /* FIRMWARE: bulk sink (maybe accepts short writes) */ 231828ffd79cSDavid Brownell retval = perform_sglist(dev, param->iterations, dev->out_pipe, 23191da177e4SLinus Torvalds &req, sg, param->sglen); 23201da177e4SLinus Torvalds free_sglist(sg, param->sglen); 23211da177e4SLinus Torvalds break; 23221da177e4SLinus Torvalds case 8: 23231da177e4SLinus Torvalds if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0) 23241da177e4SLinus Torvalds break; 232528ffd79cSDavid Brownell dev_info(&intf->dev, 23261da177e4SLinus Torvalds "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n", 23271da177e4SLinus Torvalds param->vary, param->iterations, 23281da177e4SLinus Torvalds param->sglen, param->length); 2329b9a6e8e1SAlan Stern sg = alloc_sglist(param->sglen, param->length, 2330b9a6e8e1SAlan Stern param->vary, dev, dev->in_pipe); 23311da177e4SLinus Torvalds if (!sg) { 23321da177e4SLinus Torvalds retval = -ENOMEM; 23331da177e4SLinus Torvalds break; 23341da177e4SLinus Torvalds } 2335fabbf219SMartin Fuzzey /* FIRMWARE: bulk source (maybe generates short writes) */ 233628ffd79cSDavid Brownell retval = perform_sglist(dev, param->iterations, dev->in_pipe, 23371da177e4SLinus Torvalds &req, sg, param->sglen); 23381da177e4SLinus Torvalds free_sglist(sg, param->sglen); 23391da177e4SLinus Torvalds break; 23401da177e4SLinus Torvalds 23411da177e4SLinus Torvalds /* non-queued sanity tests for control (chapter 9 subset) */ 23421da177e4SLinus Torvalds case 9: 23431da177e4SLinus Torvalds retval = 0; 234428ffd79cSDavid Brownell dev_info(&intf->dev, 23451da177e4SLinus Torvalds "TEST 9: ch9 (subset) control tests, %d times\n", 23461da177e4SLinus Torvalds param->iterations); 23471da177e4SLinus Torvalds for (i = param->iterations; retval == 0 && i--; /* NOP */) 23481da177e4SLinus Torvalds retval = ch9_postconfig(dev); 23491da177e4SLinus Torvalds if (retval) 235028ffd79cSDavid Brownell dev_err(&intf->dev, "ch9 subset failed, " 235128ffd79cSDavid Brownell "iterations left %d\n", i); 23521da177e4SLinus Torvalds break; 23531da177e4SLinus Torvalds 23541da177e4SLinus Torvalds /* queued control messaging */ 23551da177e4SLinus Torvalds case 10: 23561da177e4SLinus Torvalds retval = 0; 235728ffd79cSDavid Brownell dev_info(&intf->dev, 23581da177e4SLinus Torvalds "TEST 10: queue %d control calls, %d times\n", 23591da177e4SLinus Torvalds param->sglen, 23601da177e4SLinus Torvalds param->iterations); 23611da177e4SLinus Torvalds retval = test_ctrl_queue(dev, param); 23621da177e4SLinus Torvalds break; 23631da177e4SLinus Torvalds 23641da177e4SLinus Torvalds /* simple non-queued unlinks (ring with one urb) */ 23651da177e4SLinus Torvalds case 11: 23661da177e4SLinus Torvalds if (dev->in_pipe == 0 || !param->length) 23671da177e4SLinus Torvalds break; 23681da177e4SLinus Torvalds retval = 0; 236928ffd79cSDavid Brownell dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n", 23701da177e4SLinus Torvalds param->iterations, param->length); 23711da177e4SLinus Torvalds for (i = param->iterations; retval == 0 && i--; /* NOP */) 23721da177e4SLinus Torvalds retval = unlink_simple(dev, dev->in_pipe, 23731da177e4SLinus Torvalds param->length); 23741da177e4SLinus Torvalds if (retval) 237528ffd79cSDavid Brownell dev_err(&intf->dev, "unlink reads failed %d, " 23761da177e4SLinus Torvalds "iterations left %d\n", retval, i); 23771da177e4SLinus Torvalds break; 23781da177e4SLinus Torvalds case 12: 23791da177e4SLinus Torvalds if (dev->out_pipe == 0 || !param->length) 23801da177e4SLinus Torvalds break; 23811da177e4SLinus Torvalds retval = 0; 238228ffd79cSDavid Brownell dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n", 23831da177e4SLinus Torvalds param->iterations, param->length); 23841da177e4SLinus Torvalds for (i = param->iterations; retval == 0 && i--; /* NOP */) 23851da177e4SLinus Torvalds retval = unlink_simple(dev, dev->out_pipe, 23861da177e4SLinus Torvalds param->length); 23871da177e4SLinus Torvalds if (retval) 238828ffd79cSDavid Brownell dev_err(&intf->dev, "unlink writes failed %d, " 23891da177e4SLinus Torvalds "iterations left %d\n", retval, i); 23901da177e4SLinus Torvalds break; 23911da177e4SLinus Torvalds 23921da177e4SLinus Torvalds /* ep halt tests */ 23931da177e4SLinus Torvalds case 13: 23941da177e4SLinus Torvalds if (dev->out_pipe == 0 && dev->in_pipe == 0) 23951da177e4SLinus Torvalds break; 23961da177e4SLinus Torvalds retval = 0; 239728ffd79cSDavid Brownell dev_info(&intf->dev, "TEST 13: set/clear %d halts\n", 23981da177e4SLinus Torvalds param->iterations); 23991da177e4SLinus Torvalds for (i = param->iterations; retval == 0 && i--; /* NOP */) 24001da177e4SLinus Torvalds retval = halt_simple(dev); 24011da177e4SLinus Torvalds 24021da177e4SLinus Torvalds if (retval) 240328ffd79cSDavid Brownell ERROR(dev, "halts failed, iterations left %d\n", i); 24041da177e4SLinus Torvalds break; 24051da177e4SLinus Torvalds 24061da177e4SLinus Torvalds /* control write tests */ 24071da177e4SLinus Torvalds case 14: 24081da177e4SLinus Torvalds if (!dev->info->ctrl_out) 24091da177e4SLinus Torvalds break; 241028ffd79cSDavid Brownell dev_info(&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n", 2411ff7c79e4SDavid Brownell param->iterations, 2412ff7c79e4SDavid Brownell realworld ? 1 : 0, param->length, 2413ff7c79e4SDavid Brownell param->vary); 24141da177e4SLinus Torvalds retval = ctrl_out(dev, param->iterations, 2415084fb206SMartin Fuzzey param->length, param->vary, 0); 24161da177e4SLinus Torvalds break; 24171da177e4SLinus Torvalds 24181da177e4SLinus Torvalds /* iso write tests */ 24191da177e4SLinus Torvalds case 15: 24201da177e4SLinus Torvalds if (dev->out_iso_pipe == 0 || param->sglen == 0) 24211da177e4SLinus Torvalds break; 242228ffd79cSDavid Brownell dev_info(&intf->dev, 24231da177e4SLinus Torvalds "TEST 15: write %d iso, %d entries of %d bytes\n", 24241da177e4SLinus Torvalds param->iterations, 24251da177e4SLinus Torvalds param->sglen, param->length); 2426fabbf219SMartin Fuzzey /* FIRMWARE: iso sink */ 2427145f48c5SPeter Chen retval = test_queue(dev, param, 2428084fb206SMartin Fuzzey dev->out_iso_pipe, dev->iso_out, 0); 24291da177e4SLinus Torvalds break; 24301da177e4SLinus Torvalds 24311da177e4SLinus Torvalds /* iso read tests */ 24321da177e4SLinus Torvalds case 16: 24331da177e4SLinus Torvalds if (dev->in_iso_pipe == 0 || param->sglen == 0) 24341da177e4SLinus Torvalds break; 243528ffd79cSDavid Brownell dev_info(&intf->dev, 24361da177e4SLinus Torvalds "TEST 16: read %d iso, %d entries of %d bytes\n", 24371da177e4SLinus Torvalds param->iterations, 24381da177e4SLinus Torvalds param->sglen, param->length); 2439fabbf219SMartin Fuzzey /* FIRMWARE: iso source */ 2440145f48c5SPeter Chen retval = test_queue(dev, param, 2441084fb206SMartin Fuzzey dev->in_iso_pipe, dev->iso_in, 0); 24421da177e4SLinus Torvalds break; 24431da177e4SLinus Torvalds 2444fabbf219SMartin Fuzzey /* FIXME scatterlist cancel (needs helper thread) */ 24451da177e4SLinus Torvalds 2446084fb206SMartin Fuzzey /* Tests for bulk I/O using DMA mapping by core and odd address */ 2447084fb206SMartin Fuzzey case 17: 2448084fb206SMartin Fuzzey if (dev->out_pipe == 0) 2449084fb206SMartin Fuzzey break; 2450084fb206SMartin Fuzzey dev_info(&intf->dev, 2451084fb206SMartin Fuzzey "TEST 17: write odd addr %d bytes %u times core map\n", 2452084fb206SMartin Fuzzey param->length, param->iterations); 2453084fb206SMartin Fuzzey 2454084fb206SMartin Fuzzey retval = test_unaligned_bulk( 2455084fb206SMartin Fuzzey dev, dev->out_pipe, 2456084fb206SMartin Fuzzey param->length, param->iterations, 2457084fb206SMartin Fuzzey 0, "test17"); 2458084fb206SMartin Fuzzey break; 2459084fb206SMartin Fuzzey 2460084fb206SMartin Fuzzey case 18: 2461084fb206SMartin Fuzzey if (dev->in_pipe == 0) 2462084fb206SMartin Fuzzey break; 2463084fb206SMartin Fuzzey dev_info(&intf->dev, 2464084fb206SMartin Fuzzey "TEST 18: read odd addr %d bytes %u times core map\n", 2465084fb206SMartin Fuzzey param->length, param->iterations); 2466084fb206SMartin Fuzzey 2467084fb206SMartin Fuzzey retval = test_unaligned_bulk( 2468084fb206SMartin Fuzzey dev, dev->in_pipe, 2469084fb206SMartin Fuzzey param->length, param->iterations, 2470084fb206SMartin Fuzzey 0, "test18"); 2471084fb206SMartin Fuzzey break; 2472084fb206SMartin Fuzzey 2473084fb206SMartin Fuzzey /* Tests for bulk I/O using premapped coherent buffer and odd address */ 2474084fb206SMartin Fuzzey case 19: 2475084fb206SMartin Fuzzey if (dev->out_pipe == 0) 2476084fb206SMartin Fuzzey break; 2477084fb206SMartin Fuzzey dev_info(&intf->dev, 2478084fb206SMartin Fuzzey "TEST 19: write odd addr %d bytes %u times premapped\n", 2479084fb206SMartin Fuzzey param->length, param->iterations); 2480084fb206SMartin Fuzzey 2481084fb206SMartin Fuzzey retval = test_unaligned_bulk( 2482084fb206SMartin Fuzzey dev, dev->out_pipe, 2483084fb206SMartin Fuzzey param->length, param->iterations, 2484084fb206SMartin Fuzzey URB_NO_TRANSFER_DMA_MAP, "test19"); 2485084fb206SMartin Fuzzey break; 2486084fb206SMartin Fuzzey 2487084fb206SMartin Fuzzey case 20: 2488084fb206SMartin Fuzzey if (dev->in_pipe == 0) 2489084fb206SMartin Fuzzey break; 2490084fb206SMartin Fuzzey dev_info(&intf->dev, 2491084fb206SMartin Fuzzey "TEST 20: read odd addr %d bytes %u times premapped\n", 2492084fb206SMartin Fuzzey param->length, param->iterations); 2493084fb206SMartin Fuzzey 2494084fb206SMartin Fuzzey retval = test_unaligned_bulk( 2495084fb206SMartin Fuzzey dev, dev->in_pipe, 2496084fb206SMartin Fuzzey param->length, param->iterations, 2497084fb206SMartin Fuzzey URB_NO_TRANSFER_DMA_MAP, "test20"); 2498084fb206SMartin Fuzzey break; 2499084fb206SMartin Fuzzey 2500084fb206SMartin Fuzzey /* control write tests with unaligned buffer */ 2501084fb206SMartin Fuzzey case 21: 2502084fb206SMartin Fuzzey if (!dev->info->ctrl_out) 2503084fb206SMartin Fuzzey break; 2504084fb206SMartin Fuzzey dev_info(&intf->dev, 2505084fb206SMartin Fuzzey "TEST 21: %d ep0out odd addr, %d..%d vary %d\n", 2506084fb206SMartin Fuzzey param->iterations, 2507084fb206SMartin Fuzzey realworld ? 1 : 0, param->length, 2508084fb206SMartin Fuzzey param->vary); 2509084fb206SMartin Fuzzey retval = ctrl_out(dev, param->iterations, 2510084fb206SMartin Fuzzey param->length, param->vary, 1); 2511084fb206SMartin Fuzzey break; 2512084fb206SMartin Fuzzey 2513084fb206SMartin Fuzzey /* unaligned iso tests */ 2514084fb206SMartin Fuzzey case 22: 2515084fb206SMartin Fuzzey if (dev->out_iso_pipe == 0 || param->sglen == 0) 2516084fb206SMartin Fuzzey break; 2517084fb206SMartin Fuzzey dev_info(&intf->dev, 2518084fb206SMartin Fuzzey "TEST 22: write %d iso odd, %d entries of %d bytes\n", 2519084fb206SMartin Fuzzey param->iterations, 2520084fb206SMartin Fuzzey param->sglen, param->length); 2521145f48c5SPeter Chen retval = test_queue(dev, param, 2522084fb206SMartin Fuzzey dev->out_iso_pipe, dev->iso_out, 1); 2523084fb206SMartin Fuzzey break; 2524084fb206SMartin Fuzzey 2525084fb206SMartin Fuzzey case 23: 2526084fb206SMartin Fuzzey if (dev->in_iso_pipe == 0 || param->sglen == 0) 2527084fb206SMartin Fuzzey break; 2528084fb206SMartin Fuzzey dev_info(&intf->dev, 2529084fb206SMartin Fuzzey "TEST 23: read %d iso odd, %d entries of %d bytes\n", 2530084fb206SMartin Fuzzey param->iterations, 2531084fb206SMartin Fuzzey param->sglen, param->length); 2532145f48c5SPeter Chen retval = test_queue(dev, param, 2533084fb206SMartin Fuzzey dev->in_iso_pipe, dev->iso_in, 1); 2534084fb206SMartin Fuzzey break; 2535084fb206SMartin Fuzzey 2536869410f8SAlan Stern /* unlink URBs from a bulk-OUT queue */ 2537869410f8SAlan Stern case 24: 2538869410f8SAlan Stern if (dev->out_pipe == 0 || !param->length || param->sglen < 4) 2539869410f8SAlan Stern break; 2540869410f8SAlan Stern retval = 0; 25412cb50000SAlan Stern dev_info(&intf->dev, "TEST 24: unlink from %d queues of " 2542869410f8SAlan Stern "%d %d-byte writes\n", 2543869410f8SAlan Stern param->iterations, param->sglen, param->length); 2544869410f8SAlan Stern for (i = param->iterations; retval == 0 && i > 0; --i) { 2545869410f8SAlan Stern retval = unlink_queued(dev, dev->out_pipe, 2546869410f8SAlan Stern param->sglen, param->length); 2547869410f8SAlan Stern if (retval) { 2548869410f8SAlan Stern dev_err(&intf->dev, 2549869410f8SAlan Stern "unlink queued writes failed %d, " 2550869410f8SAlan Stern "iterations left %d\n", retval, i); 2551869410f8SAlan Stern break; 2552869410f8SAlan Stern } 2553869410f8SAlan Stern } 2554869410f8SAlan Stern break; 2555869410f8SAlan Stern 2556457a0955SAmit Virdi /* Simple non-queued interrupt I/O tests */ 2557457a0955SAmit Virdi case 25: 2558457a0955SAmit Virdi if (dev->out_int_pipe == 0) 2559457a0955SAmit Virdi break; 2560457a0955SAmit Virdi dev_info(&intf->dev, 2561457a0955SAmit Virdi "TEST 25: write %d bytes %u times\n", 2562457a0955SAmit Virdi param->length, param->iterations); 2563457a0955SAmit Virdi urb = simple_alloc_urb(udev, dev->out_int_pipe, param->length, 2564457a0955SAmit Virdi dev->int_out->bInterval); 2565457a0955SAmit Virdi if (!urb) { 2566457a0955SAmit Virdi retval = -ENOMEM; 2567457a0955SAmit Virdi break; 2568457a0955SAmit Virdi } 2569457a0955SAmit Virdi /* FIRMWARE: interrupt sink (maybe accepts short writes) */ 2570457a0955SAmit Virdi retval = simple_io(dev, urb, param->iterations, 0, 0, "test25"); 2571457a0955SAmit Virdi simple_free_urb(urb); 2572457a0955SAmit Virdi break; 2573457a0955SAmit Virdi case 26: 2574457a0955SAmit Virdi if (dev->in_int_pipe == 0) 2575457a0955SAmit Virdi break; 2576457a0955SAmit Virdi dev_info(&intf->dev, 2577457a0955SAmit Virdi "TEST 26: read %d bytes %u times\n", 2578457a0955SAmit Virdi param->length, param->iterations); 2579457a0955SAmit Virdi urb = simple_alloc_urb(udev, dev->in_int_pipe, param->length, 2580457a0955SAmit Virdi dev->int_in->bInterval); 2581457a0955SAmit Virdi if (!urb) { 2582457a0955SAmit Virdi retval = -ENOMEM; 2583457a0955SAmit Virdi break; 2584457a0955SAmit Virdi } 2585457a0955SAmit Virdi /* FIRMWARE: interrupt source (maybe generates short writes) */ 2586457a0955SAmit Virdi retval = simple_io(dev, urb, param->iterations, 0, 0, "test26"); 2587457a0955SAmit Virdi simple_free_urb(urb); 2588457a0955SAmit Virdi break; 2589145f48c5SPeter Chen case 27: 2590145f48c5SPeter Chen /* We do performance test, so ignore data compare */ 2591145f48c5SPeter Chen if (dev->out_pipe == 0 || param->sglen == 0 || pattern != 0) 2592145f48c5SPeter Chen break; 2593145f48c5SPeter Chen dev_info(&intf->dev, 2594145f48c5SPeter Chen "TEST 27: bulk write %dMbytes\n", (param->iterations * 2595145f48c5SPeter Chen param->sglen * param->length) / (1024 * 1024)); 2596145f48c5SPeter Chen retval = test_queue(dev, param, 2597145f48c5SPeter Chen dev->out_pipe, NULL, 0); 2598145f48c5SPeter Chen break; 2599145f48c5SPeter Chen case 28: 2600145f48c5SPeter Chen if (dev->in_pipe == 0 || param->sglen == 0 || pattern != 0) 2601145f48c5SPeter Chen break; 2602145f48c5SPeter Chen dev_info(&intf->dev, 2603145f48c5SPeter Chen "TEST 28: bulk read %dMbytes\n", (param->iterations * 2604145f48c5SPeter Chen param->sglen * param->length) / (1024 * 1024)); 2605145f48c5SPeter Chen retval = test_queue(dev, param, 2606145f48c5SPeter Chen dev->in_pipe, NULL, 0); 2607145f48c5SPeter Chen break; 2608cc2e60dfSMathias Nyman /* Test data Toggle/seq_nr clear between bulk out transfers */ 2609cc2e60dfSMathias Nyman case 29: 2610cc2e60dfSMathias Nyman if (dev->out_pipe == 0) 2611cc2e60dfSMathias Nyman break; 2612cc2e60dfSMathias Nyman retval = 0; 2613cc2e60dfSMathias Nyman dev_info(&intf->dev, "TEST 29: Clear toggle between bulk writes %d times\n", 2614cc2e60dfSMathias Nyman param->iterations); 2615cc2e60dfSMathias Nyman for (i = param->iterations; retval == 0 && i > 0; --i) 2616cc2e60dfSMathias Nyman retval = toggle_sync_simple(dev); 2617cc2e60dfSMathias Nyman 2618cc2e60dfSMathias Nyman if (retval) 2619cc2e60dfSMathias Nyman ERROR(dev, "toggle sync failed, iterations left %d\n", 2620cc2e60dfSMathias Nyman i); 2621cc2e60dfSMathias Nyman break; 26221da177e4SLinus Torvalds } 262318fc4ebdSDeepa Dinamani return retval; 26241da177e4SLinus Torvalds } 262518fc4ebdSDeepa Dinamani 262618fc4ebdSDeepa Dinamani /*-------------------------------------------------------------------------*/ 262718fc4ebdSDeepa Dinamani 262818fc4ebdSDeepa Dinamani /* We only have this one interface to user space, through usbfs. 262918fc4ebdSDeepa Dinamani * User mode code can scan usbfs to find N different devices (maybe on 263018fc4ebdSDeepa Dinamani * different busses) to use when testing, and allocate one thread per 263118fc4ebdSDeepa Dinamani * test. So discovery is simplified, and we have no device naming issues. 263218fc4ebdSDeepa Dinamani * 263318fc4ebdSDeepa Dinamani * Don't use these only as stress/load tests. Use them along with with 263418fc4ebdSDeepa Dinamani * other USB bus activity: plugging, unplugging, mousing, mp3 playback, 263518fc4ebdSDeepa Dinamani * video capture, and so on. Run different tests at different times, in 263618fc4ebdSDeepa Dinamani * different sequences. Nothing here should interact with other devices, 263718fc4ebdSDeepa Dinamani * except indirectly by consuming USB bandwidth and CPU resources for test 263818fc4ebdSDeepa Dinamani * threads and request completion. But the only way to know that for sure 263918fc4ebdSDeepa Dinamani * is to test when HC queues are in use by many devices. 264018fc4ebdSDeepa Dinamani * 264118fc4ebdSDeepa Dinamani * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(), 264218fc4ebdSDeepa Dinamani * it locks out usbcore in certain code paths. Notably, if you disconnect 264318fc4ebdSDeepa Dinamani * the device-under-test, hub_wq will wait block forever waiting for the 264418fc4ebdSDeepa Dinamani * ioctl to complete ... so that usb_disconnect() can abort the pending 264518fc4ebdSDeepa Dinamani * urbs and then call usbtest_disconnect(). To abort a test, you're best 264618fc4ebdSDeepa Dinamani * off just killing the userspace task and waiting for it to exit. 264718fc4ebdSDeepa Dinamani */ 264818fc4ebdSDeepa Dinamani 264918fc4ebdSDeepa Dinamani static int 265018fc4ebdSDeepa Dinamani usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) 265118fc4ebdSDeepa Dinamani { 265218fc4ebdSDeepa Dinamani 265318fc4ebdSDeepa Dinamani struct usbtest_dev *dev = usb_get_intfdata(intf); 265418fc4ebdSDeepa Dinamani struct usbtest_param_64 *param_64 = buf; 265518fc4ebdSDeepa Dinamani struct usbtest_param_32 temp; 265618fc4ebdSDeepa Dinamani struct usbtest_param_32 *param_32 = buf; 265718fc4ebdSDeepa Dinamani struct timespec64 start; 265818fc4ebdSDeepa Dinamani struct timespec64 end; 265918fc4ebdSDeepa Dinamani struct timespec64 duration; 266018fc4ebdSDeepa Dinamani int retval = -EOPNOTSUPP; 266118fc4ebdSDeepa Dinamani 266218fc4ebdSDeepa Dinamani /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */ 266318fc4ebdSDeepa Dinamani 266418fc4ebdSDeepa Dinamani pattern = mod_pattern; 266518fc4ebdSDeepa Dinamani 266618fc4ebdSDeepa Dinamani if (mutex_lock_interruptible(&dev->lock)) 266718fc4ebdSDeepa Dinamani return -ERESTARTSYS; 266818fc4ebdSDeepa Dinamani 266918fc4ebdSDeepa Dinamani /* FIXME: What if a system sleep starts while a test is running? */ 267018fc4ebdSDeepa Dinamani 267118fc4ebdSDeepa Dinamani /* some devices, like ez-usb default devices, need a non-default 267218fc4ebdSDeepa Dinamani * altsetting to have any active endpoints. some tests change 267318fc4ebdSDeepa Dinamani * altsettings; force a default so most tests don't need to check. 267418fc4ebdSDeepa Dinamani */ 267518fc4ebdSDeepa Dinamani if (dev->info->alt >= 0) { 267618fc4ebdSDeepa Dinamani if (intf->altsetting->desc.bInterfaceNumber) { 267718fc4ebdSDeepa Dinamani retval = -ENODEV; 267818fc4ebdSDeepa Dinamani goto free_mutex; 267918fc4ebdSDeepa Dinamani } 268018fc4ebdSDeepa Dinamani retval = set_altsetting(dev, dev->info->alt); 268118fc4ebdSDeepa Dinamani if (retval) { 268218fc4ebdSDeepa Dinamani dev_err(&intf->dev, 268318fc4ebdSDeepa Dinamani "set altsetting to %d failed, %d\n", 268418fc4ebdSDeepa Dinamani dev->info->alt, retval); 268518fc4ebdSDeepa Dinamani goto free_mutex; 268618fc4ebdSDeepa Dinamani } 268718fc4ebdSDeepa Dinamani } 268818fc4ebdSDeepa Dinamani 268918fc4ebdSDeepa Dinamani switch (code) { 269018fc4ebdSDeepa Dinamani case USBTEST_REQUEST_64: 269118fc4ebdSDeepa Dinamani temp.test_num = param_64->test_num; 269218fc4ebdSDeepa Dinamani temp.iterations = param_64->iterations; 269318fc4ebdSDeepa Dinamani temp.length = param_64->length; 269418fc4ebdSDeepa Dinamani temp.sglen = param_64->sglen; 269518fc4ebdSDeepa Dinamani temp.vary = param_64->vary; 269618fc4ebdSDeepa Dinamani param_32 = &temp; 269718fc4ebdSDeepa Dinamani break; 269818fc4ebdSDeepa Dinamani 269918fc4ebdSDeepa Dinamani case USBTEST_REQUEST_32: 270018fc4ebdSDeepa Dinamani break; 270118fc4ebdSDeepa Dinamani 270218fc4ebdSDeepa Dinamani default: 270318fc4ebdSDeepa Dinamani retval = -EOPNOTSUPP; 270418fc4ebdSDeepa Dinamani goto free_mutex; 270518fc4ebdSDeepa Dinamani } 270618fc4ebdSDeepa Dinamani 270718fc4ebdSDeepa Dinamani ktime_get_ts64(&start); 270818fc4ebdSDeepa Dinamani 270918fc4ebdSDeepa Dinamani retval = usbtest_do_ioctl(intf, param_32); 271028324936SPeter Chen if (retval < 0) 271118fc4ebdSDeepa Dinamani goto free_mutex; 271218fc4ebdSDeepa Dinamani 271318fc4ebdSDeepa Dinamani ktime_get_ts64(&end); 271418fc4ebdSDeepa Dinamani 271518fc4ebdSDeepa Dinamani duration = timespec64_sub(end, start); 271618fc4ebdSDeepa Dinamani 271718fc4ebdSDeepa Dinamani temp.duration_sec = duration.tv_sec; 271818fc4ebdSDeepa Dinamani temp.duration_usec = duration.tv_nsec/NSEC_PER_USEC; 271918fc4ebdSDeepa Dinamani 272018fc4ebdSDeepa Dinamani switch (code) { 272118fc4ebdSDeepa Dinamani case USBTEST_REQUEST_32: 272218fc4ebdSDeepa Dinamani param_32->duration_sec = temp.duration_sec; 272318fc4ebdSDeepa Dinamani param_32->duration_usec = temp.duration_usec; 272418fc4ebdSDeepa Dinamani break; 272518fc4ebdSDeepa Dinamani 272618fc4ebdSDeepa Dinamani case USBTEST_REQUEST_64: 272718fc4ebdSDeepa Dinamani param_64->duration_sec = temp.duration_sec; 272818fc4ebdSDeepa Dinamani param_64->duration_usec = temp.duration_usec; 272918fc4ebdSDeepa Dinamani break; 273018fc4ebdSDeepa Dinamani } 273118fc4ebdSDeepa Dinamani 273218fc4ebdSDeepa Dinamani free_mutex: 27331cfab028SMatthias Kaehlcke mutex_unlock(&dev->lock); 27341da177e4SLinus Torvalds return retval; 27351da177e4SLinus Torvalds } 27361da177e4SLinus Torvalds 27371da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 27381da177e4SLinus Torvalds 2739fabbf219SMartin Fuzzey static unsigned force_interrupt; 27401da177e4SLinus Torvalds module_param(force_interrupt, uint, 0); 27411da177e4SLinus Torvalds MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt"); 27421da177e4SLinus Torvalds 27431da177e4SLinus Torvalds #ifdef GENERIC 27441da177e4SLinus Torvalds static unsigned short vendor; 27451da177e4SLinus Torvalds module_param(vendor, ushort, 0); 27461da177e4SLinus Torvalds MODULE_PARM_DESC(vendor, "vendor code (from usb-if)"); 27471da177e4SLinus Torvalds 27481da177e4SLinus Torvalds static unsigned short product; 27491da177e4SLinus Torvalds module_param(product, ushort, 0); 27501da177e4SLinus Torvalds MODULE_PARM_DESC(product, "product code (from vendor)"); 27511da177e4SLinus Torvalds #endif 27521da177e4SLinus Torvalds 27531da177e4SLinus Torvalds static int 27541da177e4SLinus Torvalds usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id) 27551da177e4SLinus Torvalds { 27561da177e4SLinus Torvalds struct usb_device *udev; 27571da177e4SLinus Torvalds struct usbtest_dev *dev; 27581da177e4SLinus Torvalds struct usbtest_info *info; 27591da177e4SLinus Torvalds char *rtest, *wtest; 27601da177e4SLinus Torvalds char *irtest, *iwtest; 2761457a0955SAmit Virdi char *intrtest, *intwtest; 27621da177e4SLinus Torvalds 27631da177e4SLinus Torvalds udev = interface_to_usbdev(intf); 27641da177e4SLinus Torvalds 27651da177e4SLinus Torvalds #ifdef GENERIC 27661da177e4SLinus Torvalds /* specify devices by module parameters? */ 27671da177e4SLinus Torvalds if (id->match_flags == 0) { 27681da177e4SLinus Torvalds /* vendor match required, product match optional */ 27691da177e4SLinus Torvalds if (!vendor || le16_to_cpu(udev->descriptor.idVendor) != (u16)vendor) 27701da177e4SLinus Torvalds return -ENODEV; 27711da177e4SLinus Torvalds if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product) 27721da177e4SLinus Torvalds return -ENODEV; 277328ffd79cSDavid Brownell dev_info(&intf->dev, "matched module params, " 277428ffd79cSDavid Brownell "vend=0x%04x prod=0x%04x\n", 27751da177e4SLinus Torvalds le16_to_cpu(udev->descriptor.idVendor), 27761da177e4SLinus Torvalds le16_to_cpu(udev->descriptor.idProduct)); 27771da177e4SLinus Torvalds } 27781da177e4SLinus Torvalds #endif 27791da177e4SLinus Torvalds 2780e94b1766SChristoph Lameter dev = kzalloc(sizeof(*dev), GFP_KERNEL); 27811da177e4SLinus Torvalds if (!dev) 27821da177e4SLinus Torvalds return -ENOMEM; 27831da177e4SLinus Torvalds info = (struct usbtest_info *) id->driver_info; 27841da177e4SLinus Torvalds dev->info = info; 27851cfab028SMatthias Kaehlcke mutex_init(&dev->lock); 27861da177e4SLinus Torvalds 27871da177e4SLinus Torvalds dev->intf = intf; 27881da177e4SLinus Torvalds 27891da177e4SLinus Torvalds /* cacheline-aligned scratch for i/o */ 2790fabbf219SMartin Fuzzey dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL); 2791fabbf219SMartin Fuzzey if (dev->buf == NULL) { 27921da177e4SLinus Torvalds kfree(dev); 27931da177e4SLinus Torvalds return -ENOMEM; 27941da177e4SLinus Torvalds } 27951da177e4SLinus Torvalds 27961da177e4SLinus Torvalds /* NOTE this doesn't yet test the handful of difference that are 27971da177e4SLinus Torvalds * visible with high speed interrupts: bigger maxpacket (1K) and 27981da177e4SLinus Torvalds * "high bandwidth" modes (up to 3 packets/uframe). 27991da177e4SLinus Torvalds */ 28001da177e4SLinus Torvalds rtest = wtest = ""; 28011da177e4SLinus Torvalds irtest = iwtest = ""; 2802457a0955SAmit Virdi intrtest = intwtest = ""; 28031da177e4SLinus Torvalds if (force_interrupt || udev->speed == USB_SPEED_LOW) { 28041da177e4SLinus Torvalds if (info->ep_in) { 28051da177e4SLinus Torvalds dev->in_pipe = usb_rcvintpipe(udev, info->ep_in); 28061da177e4SLinus Torvalds rtest = " intr-in"; 28071da177e4SLinus Torvalds } 28081da177e4SLinus Torvalds if (info->ep_out) { 28091da177e4SLinus Torvalds dev->out_pipe = usb_sndintpipe(udev, info->ep_out); 28101da177e4SLinus Torvalds wtest = " intr-out"; 28111da177e4SLinus Torvalds } 28121da177e4SLinus Torvalds } else { 2813d0b4652fSAlan Stern if (override_alt >= 0 || info->autoconf) { 28141da177e4SLinus Torvalds int status; 28151da177e4SLinus Torvalds 28161da177e4SLinus Torvalds status = get_endpoints(dev, intf); 28171da177e4SLinus Torvalds if (status < 0) { 2818b6c63937SArjan van de Ven WARNING(dev, "couldn't get endpoints, %d\n", 281928ffd79cSDavid Brownell status); 2820f4a728d0SJulia Lawall kfree(dev->buf); 2821f4a728d0SJulia Lawall kfree(dev); 28221da177e4SLinus Torvalds return status; 28231da177e4SLinus Torvalds } 28241da177e4SLinus Torvalds /* may find bulk or ISO pipes */ 28251da177e4SLinus Torvalds } else { 28261da177e4SLinus Torvalds if (info->ep_in) 28271da177e4SLinus Torvalds dev->in_pipe = usb_rcvbulkpipe(udev, 28281da177e4SLinus Torvalds info->ep_in); 28291da177e4SLinus Torvalds if (info->ep_out) 28301da177e4SLinus Torvalds dev->out_pipe = usb_sndbulkpipe(udev, 28311da177e4SLinus Torvalds info->ep_out); 28321da177e4SLinus Torvalds } 28331da177e4SLinus Torvalds if (dev->in_pipe) 28341da177e4SLinus Torvalds rtest = " bulk-in"; 28351da177e4SLinus Torvalds if (dev->out_pipe) 28361da177e4SLinus Torvalds wtest = " bulk-out"; 28371da177e4SLinus Torvalds if (dev->in_iso_pipe) 28381da177e4SLinus Torvalds irtest = " iso-in"; 28391da177e4SLinus Torvalds if (dev->out_iso_pipe) 28401da177e4SLinus Torvalds iwtest = " iso-out"; 2841457a0955SAmit Virdi if (dev->in_int_pipe) 2842457a0955SAmit Virdi intrtest = " int-in"; 2843457a0955SAmit Virdi if (dev->out_int_pipe) 2844457a0955SAmit Virdi intwtest = " int-out"; 28451da177e4SLinus Torvalds } 28461da177e4SLinus Torvalds 28471da177e4SLinus Torvalds usb_set_intfdata(intf, dev); 28481da177e4SLinus Torvalds dev_info(&intf->dev, "%s\n", info->name); 2849457a0955SAmit Virdi dev_info(&intf->dev, "%s {control%s%s%s%s%s%s%s} tests%s\n", 2850e538dfdaSMichal Nazarewicz usb_speed_string(udev->speed), 28511da177e4SLinus Torvalds info->ctrl_out ? " in/out" : "", 28521da177e4SLinus Torvalds rtest, wtest, 28531da177e4SLinus Torvalds irtest, iwtest, 2854457a0955SAmit Virdi intrtest, intwtest, 28551da177e4SLinus Torvalds info->alt >= 0 ? " (+alt)" : ""); 28561da177e4SLinus Torvalds return 0; 28571da177e4SLinus Torvalds } 28581da177e4SLinus Torvalds 2859ff7c79e4SDavid Brownell static int usbtest_suspend(struct usb_interface *intf, pm_message_t message) 2860ff7c79e4SDavid Brownell { 2861ff7c79e4SDavid Brownell return 0; 2862ff7c79e4SDavid Brownell } 2863ff7c79e4SDavid Brownell 2864ff7c79e4SDavid Brownell static int usbtest_resume(struct usb_interface *intf) 2865ff7c79e4SDavid Brownell { 2866ff7c79e4SDavid Brownell return 0; 2867ff7c79e4SDavid Brownell } 2868ff7c79e4SDavid Brownell 2869ff7c79e4SDavid Brownell 28701da177e4SLinus Torvalds static void usbtest_disconnect(struct usb_interface *intf) 28711da177e4SLinus Torvalds { 28721da177e4SLinus Torvalds struct usbtest_dev *dev = usb_get_intfdata(intf); 28731da177e4SLinus Torvalds 28741da177e4SLinus Torvalds usb_set_intfdata(intf, NULL); 28751da177e4SLinus Torvalds dev_dbg(&intf->dev, "disconnect\n"); 28761da177e4SLinus Torvalds kfree(dev); 28771da177e4SLinus Torvalds } 28781da177e4SLinus Torvalds 28791da177e4SLinus Torvalds /* Basic testing only needs a device that can source or sink bulk traffic. 28801da177e4SLinus Torvalds * Any device can test control transfers (default with GENERIC binding). 28811da177e4SLinus Torvalds * 28821da177e4SLinus Torvalds * Several entries work with the default EP0 implementation that's built 28831da177e4SLinus Torvalds * into EZ-USB chips. There's a default vendor ID which can be overridden 28841da177e4SLinus Torvalds * by (very) small config EEPROMS, but otherwise all these devices act 28851da177e4SLinus Torvalds * identically until firmware is loaded: only EP0 works. It turns out 28861da177e4SLinus Torvalds * to be easy to make other endpoints work, without modifying that EP0 28871da177e4SLinus Torvalds * behavior. For now, we expect that kind of firmware. 28881da177e4SLinus Torvalds */ 28891da177e4SLinus Torvalds 28901da177e4SLinus Torvalds /* an21xx or fx versions of ez-usb */ 28911da177e4SLinus Torvalds static struct usbtest_info ez1_info = { 28921da177e4SLinus Torvalds .name = "EZ-USB device", 28931da177e4SLinus Torvalds .ep_in = 2, 28941da177e4SLinus Torvalds .ep_out = 2, 28951da177e4SLinus Torvalds .alt = 1, 28961da177e4SLinus Torvalds }; 28971da177e4SLinus Torvalds 28981da177e4SLinus Torvalds /* fx2 version of ez-usb */ 28991da177e4SLinus Torvalds static struct usbtest_info ez2_info = { 29001da177e4SLinus Torvalds .name = "FX2 device", 29011da177e4SLinus Torvalds .ep_in = 6, 29021da177e4SLinus Torvalds .ep_out = 2, 29031da177e4SLinus Torvalds .alt = 1, 29041da177e4SLinus Torvalds }; 29051da177e4SLinus Torvalds 29061da177e4SLinus Torvalds /* ezusb family device with dedicated usb test firmware, 29071da177e4SLinus Torvalds */ 29081da177e4SLinus Torvalds static struct usbtest_info fw_info = { 29091da177e4SLinus Torvalds .name = "usb test device", 29101da177e4SLinus Torvalds .ep_in = 2, 29111da177e4SLinus Torvalds .ep_out = 2, 29121da177e4SLinus Torvalds .alt = 1, 2913fabbf219SMartin Fuzzey .autoconf = 1, /* iso and ctrl_out need autoconf */ 29141da177e4SLinus Torvalds .ctrl_out = 1, 2915fabbf219SMartin Fuzzey .iso = 1, /* iso_ep's are #8 in/out */ 29161da177e4SLinus Torvalds }; 29171da177e4SLinus Torvalds 29181da177e4SLinus Torvalds /* peripheral running Linux and 'zero.c' test firmware, or 29191da177e4SLinus Torvalds * its user-mode cousin. different versions of this use 29201da177e4SLinus Torvalds * different hardware with the same vendor/product codes. 29211da177e4SLinus Torvalds * host side MUST rely on the endpoint descriptors. 29221da177e4SLinus Torvalds */ 29231da177e4SLinus Torvalds static struct usbtest_info gz_info = { 29241da177e4SLinus Torvalds .name = "Linux gadget zero", 29251da177e4SLinus Torvalds .autoconf = 1, 29261da177e4SLinus Torvalds .ctrl_out = 1, 29274b85c624SBoyan Nedeltchev .iso = 1, 2928457a0955SAmit Virdi .intr = 1, 29291da177e4SLinus Torvalds .alt = 0, 29301da177e4SLinus Torvalds }; 29311da177e4SLinus Torvalds 29321da177e4SLinus Torvalds static struct usbtest_info um_info = { 29331da177e4SLinus Torvalds .name = "Linux user mode test driver", 29341da177e4SLinus Torvalds .autoconf = 1, 29351da177e4SLinus Torvalds .alt = -1, 29361da177e4SLinus Torvalds }; 29371da177e4SLinus Torvalds 29381da177e4SLinus Torvalds static struct usbtest_info um2_info = { 29391da177e4SLinus Torvalds .name = "Linux user mode ISO test driver", 29401da177e4SLinus Torvalds .autoconf = 1, 29411da177e4SLinus Torvalds .iso = 1, 29421da177e4SLinus Torvalds .alt = -1, 29431da177e4SLinus Torvalds }; 29441da177e4SLinus Torvalds 29451da177e4SLinus Torvalds #ifdef IBOT2 29461da177e4SLinus Torvalds /* this is a nice source of high speed bulk data; 29471da177e4SLinus Torvalds * uses an FX2, with firmware provided in the device 29481da177e4SLinus Torvalds */ 29491da177e4SLinus Torvalds static struct usbtest_info ibot2_info = { 29501da177e4SLinus Torvalds .name = "iBOT2 webcam", 29511da177e4SLinus Torvalds .ep_in = 2, 29521da177e4SLinus Torvalds .alt = -1, 29531da177e4SLinus Torvalds }; 29541da177e4SLinus Torvalds #endif 29551da177e4SLinus Torvalds 29561da177e4SLinus Torvalds #ifdef GENERIC 29571da177e4SLinus Torvalds /* we can use any device to test control traffic */ 29581da177e4SLinus Torvalds static struct usbtest_info generic_info = { 29591da177e4SLinus Torvalds .name = "Generic USB device", 29601da177e4SLinus Torvalds .alt = -1, 29611da177e4SLinus Torvalds }; 29621da177e4SLinus Torvalds #endif 29631da177e4SLinus Torvalds 29641da177e4SLinus Torvalds 296533b9e162SNémeth Márton static const struct usb_device_id id_table[] = { 29661da177e4SLinus Torvalds 29671da177e4SLinus Torvalds /*-------------------------------------------------------------*/ 29681da177e4SLinus Torvalds 29691da177e4SLinus Torvalds /* EZ-USB devices which download firmware to replace (or in our 29701da177e4SLinus Torvalds * case augment) the default device implementation. 29711da177e4SLinus Torvalds */ 29721da177e4SLinus Torvalds 29731da177e4SLinus Torvalds /* generic EZ-USB FX controller */ 29741da177e4SLinus Torvalds { USB_DEVICE(0x0547, 0x2235), 29751da177e4SLinus Torvalds .driver_info = (unsigned long) &ez1_info, 29761da177e4SLinus Torvalds }, 29771da177e4SLinus Torvalds 29781da177e4SLinus Torvalds /* CY3671 development board with EZ-USB FX */ 29791da177e4SLinus Torvalds { USB_DEVICE(0x0547, 0x0080), 29801da177e4SLinus Torvalds .driver_info = (unsigned long) &ez1_info, 29811da177e4SLinus Torvalds }, 29821da177e4SLinus Torvalds 29831da177e4SLinus Torvalds /* generic EZ-USB FX2 controller (or development board) */ 29841da177e4SLinus Torvalds { USB_DEVICE(0x04b4, 0x8613), 29851da177e4SLinus Torvalds .driver_info = (unsigned long) &ez2_info, 29861da177e4SLinus Torvalds }, 29871da177e4SLinus Torvalds 29881da177e4SLinus Torvalds /* re-enumerated usb test device firmware */ 29891da177e4SLinus Torvalds { USB_DEVICE(0xfff0, 0xfff0), 29901da177e4SLinus Torvalds .driver_info = (unsigned long) &fw_info, 29911da177e4SLinus Torvalds }, 29921da177e4SLinus Torvalds 29931da177e4SLinus Torvalds /* "Gadget Zero" firmware runs under Linux */ 29941da177e4SLinus Torvalds { USB_DEVICE(0x0525, 0xa4a0), 29951da177e4SLinus Torvalds .driver_info = (unsigned long) &gz_info, 29961da177e4SLinus Torvalds }, 29971da177e4SLinus Torvalds 29981da177e4SLinus Torvalds /* so does a user-mode variant */ 29991da177e4SLinus Torvalds { USB_DEVICE(0x0525, 0xa4a4), 30001da177e4SLinus Torvalds .driver_info = (unsigned long) &um_info, 30011da177e4SLinus Torvalds }, 30021da177e4SLinus Torvalds 30031da177e4SLinus Torvalds /* ... and a user-mode variant that talks iso */ 30041da177e4SLinus Torvalds { USB_DEVICE(0x0525, 0xa4a3), 30051da177e4SLinus Torvalds .driver_info = (unsigned long) &um2_info, 30061da177e4SLinus Torvalds }, 30071da177e4SLinus Torvalds 30081da177e4SLinus Torvalds #ifdef KEYSPAN_19Qi 30091da177e4SLinus Torvalds /* Keyspan 19qi uses an21xx (original EZ-USB) */ 3010fabbf219SMartin Fuzzey /* this does not coexist with the real Keyspan 19qi driver! */ 30111da177e4SLinus Torvalds { USB_DEVICE(0x06cd, 0x010b), 30121da177e4SLinus Torvalds .driver_info = (unsigned long) &ez1_info, 30131da177e4SLinus Torvalds }, 30141da177e4SLinus Torvalds #endif 30151da177e4SLinus Torvalds 30161da177e4SLinus Torvalds /*-------------------------------------------------------------*/ 30171da177e4SLinus Torvalds 30181da177e4SLinus Torvalds #ifdef IBOT2 30191da177e4SLinus Torvalds /* iBOT2 makes a nice source of high speed bulk-in data */ 3020fabbf219SMartin Fuzzey /* this does not coexist with a real iBOT2 driver! */ 30211da177e4SLinus Torvalds { USB_DEVICE(0x0b62, 0x0059), 30221da177e4SLinus Torvalds .driver_info = (unsigned long) &ibot2_info, 30231da177e4SLinus Torvalds }, 30241da177e4SLinus Torvalds #endif 30251da177e4SLinus Torvalds 30261da177e4SLinus Torvalds /*-------------------------------------------------------------*/ 30271da177e4SLinus Torvalds 30281da177e4SLinus Torvalds #ifdef GENERIC 30291da177e4SLinus Torvalds /* module params can specify devices to use for control tests */ 30301da177e4SLinus Torvalds { .driver_info = (unsigned long) &generic_info, }, 30311da177e4SLinus Torvalds #endif 30321da177e4SLinus Torvalds 30331da177e4SLinus Torvalds /*-------------------------------------------------------------*/ 30341da177e4SLinus Torvalds 30351da177e4SLinus Torvalds { } 30361da177e4SLinus Torvalds }; 30371da177e4SLinus Torvalds MODULE_DEVICE_TABLE(usb, id_table); 30381da177e4SLinus Torvalds 30391da177e4SLinus Torvalds static struct usb_driver usbtest_driver = { 30401da177e4SLinus Torvalds .name = "usbtest", 30411da177e4SLinus Torvalds .id_table = id_table, 30421da177e4SLinus Torvalds .probe = usbtest_probe, 3043c532b29aSAndi Kleen .unlocked_ioctl = usbtest_ioctl, 30441da177e4SLinus Torvalds .disconnect = usbtest_disconnect, 3045ff7c79e4SDavid Brownell .suspend = usbtest_suspend, 3046ff7c79e4SDavid Brownell .resume = usbtest_resume, 30471da177e4SLinus Torvalds }; 30481da177e4SLinus Torvalds 30491da177e4SLinus Torvalds /*-------------------------------------------------------------------------*/ 30501da177e4SLinus Torvalds 30511da177e4SLinus Torvalds static int __init usbtest_init(void) 30521da177e4SLinus Torvalds { 30531da177e4SLinus Torvalds #ifdef GENERIC 30541da177e4SLinus Torvalds if (vendor) 305528ffd79cSDavid Brownell pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product); 30561da177e4SLinus Torvalds #endif 30571da177e4SLinus Torvalds return usb_register(&usbtest_driver); 30581da177e4SLinus Torvalds } 30591da177e4SLinus Torvalds module_init(usbtest_init); 30601da177e4SLinus Torvalds 30611da177e4SLinus Torvalds static void __exit usbtest_exit(void) 30621da177e4SLinus Torvalds { 30631da177e4SLinus Torvalds usb_deregister(&usbtest_driver); 30641da177e4SLinus Torvalds } 30651da177e4SLinus Torvalds module_exit(usbtest_exit); 30661da177e4SLinus Torvalds 30671da177e4SLinus Torvalds MODULE_DESCRIPTION("USB Core/HCD Testing Driver"); 30681da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 30691da177e4SLinus Torvalds 3070