1#include <linux/kernel.h> 2#include <linux/errno.h> 3#include <linux/init.h> 4#include <linux/slab.h> 5#include <linux/mm.h> 6#include <linux/module.h> 7#include <linux/moduleparam.h> 8#include <linux/scatterlist.h> 9 10#include <linux/usb.h> 11 12 13/*-------------------------------------------------------------------------*/ 14 15// 16struct usbtest_param { 17 // inputs 18 unsigned test_num; /* 0..(TEST_CASES-1) */ 19 unsigned iterations; 20 unsigned length; 21 unsigned vary; 22 unsigned sglen; 23 24 // outputs 25 struct timeval duration; 26}; 27#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param) 28 29/*-------------------------------------------------------------------------*/ 30 31#define GENERIC /* let probe() bind using module params */ 32 33/* Some devices that can be used for testing will have "real" drivers. 34 * Entries for those need to be enabled here by hand, after disabling 35 * that "real" driver. 36 */ 37//#define IBOT2 /* grab iBOT2 webcams */ 38//#define KEYSPAN_19Qi /* grab un-renumerated serial adapter */ 39 40/*-------------------------------------------------------------------------*/ 41 42struct usbtest_info { 43 const char *name; 44 u8 ep_in; /* bulk/intr source */ 45 u8 ep_out; /* bulk/intr sink */ 46 unsigned autoconf : 1; 47 unsigned ctrl_out : 1; 48 unsigned iso : 1; /* try iso in/out */ 49 int alt; 50}; 51 52/* this is accessed only through usbfs ioctl calls. 53 * one ioctl to issue a test ... one lock per device. 54 * tests create other threads if they need them. 55 * urbs and buffers are allocated dynamically, 56 * and data generated deterministically. 57 */ 58struct usbtest_dev { 59 struct usb_interface *intf; 60 struct usbtest_info *info; 61 int in_pipe; 62 int out_pipe; 63 int in_iso_pipe; 64 int out_iso_pipe; 65 struct usb_endpoint_descriptor *iso_in, *iso_out; 66 struct semaphore sem; 67 68#define TBUF_SIZE 256 69 u8 *buf; 70}; 71 72static struct usb_device *testdev_to_usbdev (struct usbtest_dev *test) 73{ 74 return interface_to_usbdev (test->intf); 75} 76 77/* set up all urbs so they can be used with either bulk or interrupt */ 78#define INTERRUPT_RATE 1 /* msec/transfer */ 79 80#define xprintk(tdev,level,fmt,args...) \ 81 dev_printk(level , &(tdev)->intf->dev , fmt , ## args) 82 83#ifdef DEBUG 84#define DBG(dev,fmt,args...) \ 85 xprintk(dev , KERN_DEBUG , fmt , ## args) 86#else 87#define DBG(dev,fmt,args...) \ 88 do { } while (0) 89#endif /* DEBUG */ 90 91#ifdef VERBOSE 92#define VDBG DBG 93#else 94#define VDBG(dev,fmt,args...) \ 95 do { } while (0) 96#endif /* VERBOSE */ 97 98#define ERROR(dev,fmt,args...) \ 99 xprintk(dev , KERN_ERR , fmt , ## args) 100#define WARN(dev,fmt,args...) \ 101 xprintk(dev , KERN_WARNING , fmt , ## args) 102#define INFO(dev,fmt,args...) \ 103 xprintk(dev , KERN_INFO , fmt , ## args) 104 105/*-------------------------------------------------------------------------*/ 106 107static int 108get_endpoints (struct usbtest_dev *dev, struct usb_interface *intf) 109{ 110 int tmp; 111 struct usb_host_interface *alt; 112 struct usb_host_endpoint *in, *out; 113 struct usb_host_endpoint *iso_in, *iso_out; 114 struct usb_device *udev; 115 116 for (tmp = 0; tmp < intf->num_altsetting; tmp++) { 117 unsigned ep; 118 119 in = out = NULL; 120 iso_in = iso_out = NULL; 121 alt = intf->altsetting + tmp; 122 123 /* take the first altsetting with in-bulk + out-bulk; 124 * ignore other endpoints and altsetttings. 125 */ 126 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { 127 struct usb_host_endpoint *e; 128 129 e = alt->endpoint + ep; 130 switch (e->desc.bmAttributes) { 131 case USB_ENDPOINT_XFER_BULK: 132 break; 133 case USB_ENDPOINT_XFER_ISOC: 134 if (dev->info->iso) 135 goto try_iso; 136 // FALLTHROUGH 137 default: 138 continue; 139 } 140 if (usb_endpoint_dir_in(&e->desc)) { 141 if (!in) 142 in = e; 143 } else { 144 if (!out) 145 out = e; 146 } 147 continue; 148try_iso: 149 if (usb_endpoint_dir_in(&e->desc)) { 150 if (!iso_in) 151 iso_in = e; 152 } else { 153 if (!iso_out) 154 iso_out = e; 155 } 156 } 157 if ((in && out) || (iso_in && iso_out)) 158 goto found; 159 } 160 return -EINVAL; 161 162found: 163 udev = testdev_to_usbdev (dev); 164 if (alt->desc.bAlternateSetting != 0) { 165 tmp = usb_set_interface (udev, 166 alt->desc.bInterfaceNumber, 167 alt->desc.bAlternateSetting); 168 if (tmp < 0) 169 return tmp; 170 } 171 172 if (in) { 173 dev->in_pipe = usb_rcvbulkpipe (udev, 174 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 175 dev->out_pipe = usb_sndbulkpipe (udev, 176 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 177 } 178 if (iso_in) { 179 dev->iso_in = &iso_in->desc; 180 dev->in_iso_pipe = usb_rcvisocpipe (udev, 181 iso_in->desc.bEndpointAddress 182 & USB_ENDPOINT_NUMBER_MASK); 183 dev->iso_out = &iso_out->desc; 184 dev->out_iso_pipe = usb_sndisocpipe (udev, 185 iso_out->desc.bEndpointAddress 186 & USB_ENDPOINT_NUMBER_MASK); 187 } 188 return 0; 189} 190 191/*-------------------------------------------------------------------------*/ 192 193/* Support for testing basic non-queued I/O streams. 194 * 195 * These just package urbs as requests that can be easily canceled. 196 * Each urb's data buffer is dynamically allocated; callers can fill 197 * them with non-zero test data (or test for it) when appropriate. 198 */ 199 200static void simple_callback (struct urb *urb) 201{ 202 complete ((struct completion *) urb->context); 203} 204 205static struct urb *simple_alloc_urb ( 206 struct usb_device *udev, 207 int pipe, 208 unsigned long bytes 209) 210{ 211 struct urb *urb; 212 213 if (bytes < 0) 214 return NULL; 215 urb = usb_alloc_urb (0, GFP_KERNEL); 216 if (!urb) 217 return urb; 218 usb_fill_bulk_urb (urb, udev, pipe, NULL, bytes, simple_callback, NULL); 219 urb->interval = (udev->speed == USB_SPEED_HIGH) 220 ? (INTERRUPT_RATE << 3) 221 : INTERRUPT_RATE; 222 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 223 if (usb_pipein (pipe)) 224 urb->transfer_flags |= URB_SHORT_NOT_OK; 225 urb->transfer_buffer = usb_buffer_alloc (udev, bytes, GFP_KERNEL, 226 &urb->transfer_dma); 227 if (!urb->transfer_buffer) { 228 usb_free_urb (urb); 229 urb = NULL; 230 } else 231 memset (urb->transfer_buffer, 0, bytes); 232 return urb; 233} 234 235static unsigned pattern = 0; 236module_param (pattern, uint, S_IRUGO); 237// MODULE_PARM_DESC (pattern, "i/o pattern (0 == zeroes)"); 238 239static inline void simple_fill_buf (struct urb *urb) 240{ 241 unsigned i; 242 u8 *buf = urb->transfer_buffer; 243 unsigned len = urb->transfer_buffer_length; 244 245 switch (pattern) { 246 default: 247 // FALLTHROUGH 248 case 0: 249 memset (buf, 0, len); 250 break; 251 case 1: /* mod63 */ 252 for (i = 0; i < len; i++) 253 *buf++ = (u8) (i % 63); 254 break; 255 } 256} 257 258static inline int simple_check_buf (struct urb *urb) 259{ 260 unsigned i; 261 u8 expected; 262 u8 *buf = urb->transfer_buffer; 263 unsigned len = urb->actual_length; 264 265 for (i = 0; i < len; i++, buf++) { 266 switch (pattern) { 267 /* all-zeroes has no synchronization issues */ 268 case 0: 269 expected = 0; 270 break; 271 /* mod63 stays in sync with short-terminated transfers, 272 * or otherwise when host and gadget agree on how large 273 * each usb transfer request should be. resync is done 274 * with set_interface or set_config. 275 */ 276 case 1: /* mod63 */ 277 expected = i % 63; 278 break; 279 /* always fail unsupported patterns */ 280 default: 281 expected = !*buf; 282 break; 283 } 284 if (*buf == expected) 285 continue; 286 dbg ("buf[%d] = %d (not %d)", i, *buf, expected); 287 return -EINVAL; 288 } 289 return 0; 290} 291 292static void simple_free_urb (struct urb *urb) 293{ 294 usb_buffer_free (urb->dev, urb->transfer_buffer_length, 295 urb->transfer_buffer, urb->transfer_dma); 296 usb_free_urb (urb); 297} 298 299static int simple_io ( 300 struct urb *urb, 301 int iterations, 302 int vary, 303 int expected, 304 const char *label 305) 306{ 307 struct usb_device *udev = urb->dev; 308 int max = urb->transfer_buffer_length; 309 struct completion completion; 310 int retval = 0; 311 312 urb->context = &completion; 313 while (retval == 0 && iterations-- > 0) { 314 init_completion (&completion); 315 if (usb_pipeout (urb->pipe)) 316 simple_fill_buf (urb); 317 if ((retval = usb_submit_urb (urb, GFP_KERNEL)) != 0) 318 break; 319 320 /* NOTE: no timeouts; can't be broken out of by interrupt */ 321 wait_for_completion (&completion); 322 retval = urb->status; 323 urb->dev = udev; 324 if (retval == 0 && usb_pipein (urb->pipe)) 325 retval = simple_check_buf (urb); 326 327 if (vary) { 328 int len = urb->transfer_buffer_length; 329 330 len += vary; 331 len %= max; 332 if (len == 0) 333 len = (vary < max) ? vary : max; 334 urb->transfer_buffer_length = len; 335 } 336 337 } 338 urb->transfer_buffer_length = max; 339 340 if (expected != retval) 341 dev_dbg (&udev->dev, 342 "%s failed, iterations left %d, status %d (not %d)\n", 343 label, iterations, retval, expected); 344 return retval; 345} 346 347 348/*-------------------------------------------------------------------------*/ 349 350/* We use scatterlist primitives to test queued I/O. 351 * Yes, this also tests the scatterlist primitives. 352 */ 353 354static void free_sglist (struct scatterlist *sg, int nents) 355{ 356 unsigned i; 357 358 if (!sg) 359 return; 360 for (i = 0; i < nents; i++) { 361 if (!sg [i].page) 362 continue; 363 kfree (page_address (sg [i].page) + sg [i].offset); 364 } 365 kfree (sg); 366} 367 368static struct scatterlist * 369alloc_sglist (int nents, int max, int vary) 370{ 371 struct scatterlist *sg; 372 unsigned i; 373 unsigned size = max; 374 375 sg = kmalloc (nents * sizeof *sg, GFP_KERNEL); 376 if (!sg) 377 return NULL; 378 379 for (i = 0; i < nents; i++) { 380 char *buf; 381 unsigned j; 382 383 buf = kzalloc (size, GFP_KERNEL); 384 if (!buf) { 385 free_sglist (sg, i); 386 return NULL; 387 } 388 389 /* kmalloc pages are always physically contiguous! */ 390 sg_init_one(&sg[i], buf, size); 391 392 switch (pattern) { 393 case 0: 394 /* already zeroed */ 395 break; 396 case 1: 397 for (j = 0; j < size; j++) 398 *buf++ = (u8) (j % 63); 399 break; 400 } 401 402 if (vary) { 403 size += vary; 404 size %= max; 405 if (size == 0) 406 size = (vary < max) ? vary : max; 407 } 408 } 409 410 return sg; 411} 412 413static int perform_sglist ( 414 struct usb_device *udev, 415 unsigned iterations, 416 int pipe, 417 struct usb_sg_request *req, 418 struct scatterlist *sg, 419 int nents 420) 421{ 422 int retval = 0; 423 424 while (retval == 0 && iterations-- > 0) { 425 retval = usb_sg_init (req, udev, pipe, 426 (udev->speed == USB_SPEED_HIGH) 427 ? (INTERRUPT_RATE << 3) 428 : INTERRUPT_RATE, 429 sg, nents, 0, GFP_KERNEL); 430 431 if (retval) 432 break; 433 usb_sg_wait (req); 434 retval = req->status; 435 436 437 } 438 439 // failure if retval is as we expected ... 440 441 if (retval) 442 dbg ("perform_sglist failed, iterations left %d, status %d", 443 iterations, retval); 444 return retval; 445} 446 447 448/*-------------------------------------------------------------------------*/ 449 450/* unqueued control message testing 451 * 452 * there's a nice set of device functional requirements in chapter 9 of the 453 * usb 2.0 spec, which we can apply to ANY device, even ones that don't use 454 * special test firmware. 455 * 456 * we know the device is configured (or suspended) by the time it's visible 457 * through usbfs. we can't change that, so we won't test enumeration (which 458 * worked 'well enough' to get here, this time), power management (ditto), 459 * or remote wakeup (which needs human interaction). 460 */ 461 462static unsigned realworld = 1; 463module_param (realworld, uint, 0); 464MODULE_PARM_DESC (realworld, "clear to demand stricter spec compliance"); 465 466static int get_altsetting (struct usbtest_dev *dev) 467{ 468 struct usb_interface *iface = dev->intf; 469 struct usb_device *udev = interface_to_usbdev (iface); 470 int retval; 471 472 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev, 0), 473 USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE, 474 0, iface->altsetting [0].desc.bInterfaceNumber, 475 dev->buf, 1, USB_CTRL_GET_TIMEOUT); 476 switch (retval) { 477 case 1: 478 return dev->buf [0]; 479 case 0: 480 retval = -ERANGE; 481 // FALLTHROUGH 482 default: 483 return retval; 484 } 485} 486 487static int set_altsetting (struct usbtest_dev *dev, int alternate) 488{ 489 struct usb_interface *iface = dev->intf; 490 struct usb_device *udev; 491 492 if (alternate < 0 || alternate >= 256) 493 return -EINVAL; 494 495 udev = interface_to_usbdev (iface); 496 return usb_set_interface (udev, 497 iface->altsetting [0].desc.bInterfaceNumber, 498 alternate); 499} 500 501static int is_good_config (char *buf, int len) 502{ 503 struct usb_config_descriptor *config; 504 505 if (len < sizeof *config) 506 return 0; 507 config = (struct usb_config_descriptor *) buf; 508 509 switch (config->bDescriptorType) { 510 case USB_DT_CONFIG: 511 case USB_DT_OTHER_SPEED_CONFIG: 512 if (config->bLength != 9) { 513 dbg ("bogus config descriptor length"); 514 return 0; 515 } 516 /* this bit 'must be 1' but often isn't */ 517 if (!realworld && !(config->bmAttributes & 0x80)) { 518 dbg ("high bit of config attributes not set"); 519 return 0; 520 } 521 if (config->bmAttributes & 0x1f) { /* reserved == 0 */ 522 dbg ("reserved config bits set"); 523 return 0; 524 } 525 break; 526 default: 527 return 0; 528 } 529 530 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */ 531 return 1; 532 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */ 533 return 1; 534 dbg ("bogus config descriptor read size"); 535 return 0; 536} 537 538/* sanity test for standard requests working with usb_control_mesg() and some 539 * of the utility functions which use it. 540 * 541 * this doesn't test how endpoint halts behave or data toggles get set, since 542 * we won't do I/O to bulk/interrupt endpoints here (which is how to change 543 * halt or toggle). toggle testing is impractical without support from hcds. 544 * 545 * this avoids failing devices linux would normally work with, by not testing 546 * config/altsetting operations for devices that only support their defaults. 547 * such devices rarely support those needless operations. 548 * 549 * NOTE that since this is a sanity test, it's not examining boundary cases 550 * to see if usbcore, hcd, and device all behave right. such testing would 551 * involve varied read sizes and other operation sequences. 552 */ 553static int ch9_postconfig (struct usbtest_dev *dev) 554{ 555 struct usb_interface *iface = dev->intf; 556 struct usb_device *udev = interface_to_usbdev (iface); 557 int i, alt, retval; 558 559 /* [9.2.3] if there's more than one altsetting, we need to be able to 560 * set and get each one. mostly trusts the descriptors from usbcore. 561 */ 562 for (i = 0; i < iface->num_altsetting; i++) { 563 564 /* 9.2.3 constrains the range here */ 565 alt = iface->altsetting [i].desc.bAlternateSetting; 566 if (alt < 0 || alt >= iface->num_altsetting) { 567 dev_dbg (&iface->dev, 568 "invalid alt [%d].bAltSetting = %d\n", 569 i, alt); 570 } 571 572 /* [real world] get/set unimplemented if there's only one */ 573 if (realworld && iface->num_altsetting == 1) 574 continue; 575 576 /* [9.4.10] set_interface */ 577 retval = set_altsetting (dev, alt); 578 if (retval) { 579 dev_dbg (&iface->dev, "can't set_interface = %d, %d\n", 580 alt, retval); 581 return retval; 582 } 583 584 /* [9.4.4] get_interface always works */ 585 retval = get_altsetting (dev); 586 if (retval != alt) { 587 dev_dbg (&iface->dev, "get alt should be %d, was %d\n", 588 alt, retval); 589 return (retval < 0) ? retval : -EDOM; 590 } 591 592 } 593 594 /* [real world] get_config unimplemented if there's only one */ 595 if (!realworld || udev->descriptor.bNumConfigurations != 1) { 596 int expected = udev->actconfig->desc.bConfigurationValue; 597 598 /* [9.4.2] get_configuration always works 599 * ... although some cheap devices (like one TI Hub I've got) 600 * won't return config descriptors except before set_config. 601 */ 602 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev, 0), 603 USB_REQ_GET_CONFIGURATION, 604 USB_DIR_IN | USB_RECIP_DEVICE, 605 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); 606 if (retval != 1 || dev->buf [0] != expected) { 607 dev_dbg (&iface->dev, "get config --> %d %d (1 %d)\n", 608 retval, dev->buf[0], expected); 609 return (retval < 0) ? retval : -EDOM; 610 } 611 } 612 613 /* there's always [9.4.3] a device descriptor [9.6.1] */ 614 retval = usb_get_descriptor (udev, USB_DT_DEVICE, 0, 615 dev->buf, sizeof udev->descriptor); 616 if (retval != sizeof udev->descriptor) { 617 dev_dbg (&iface->dev, "dev descriptor --> %d\n", retval); 618 return (retval < 0) ? retval : -EDOM; 619 } 620 621 /* there's always [9.4.3] at least one config descriptor [9.6.3] */ 622 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 623 retval = usb_get_descriptor (udev, USB_DT_CONFIG, i, 624 dev->buf, TBUF_SIZE); 625 if (!is_good_config (dev->buf, retval)) { 626 dev_dbg (&iface->dev, 627 "config [%d] descriptor --> %d\n", 628 i, retval); 629 return (retval < 0) ? retval : -EDOM; 630 } 631 632 // parsed it right (etc) would be good testing paranoia 633 } 634 635 /* and sometimes [9.2.6.6] speed dependent descriptors */ 636 if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) { 637 struct usb_qualifier_descriptor *d = NULL; 638 639 /* device qualifier [9.6.2] */ 640 retval = usb_get_descriptor (udev, 641 USB_DT_DEVICE_QUALIFIER, 0, dev->buf, 642 sizeof (struct usb_qualifier_descriptor)); 643 if (retval == -EPIPE) { 644 if (udev->speed == USB_SPEED_HIGH) { 645 dev_dbg (&iface->dev, 646 "hs dev qualifier --> %d\n", 647 retval); 648 return (retval < 0) ? retval : -EDOM; 649 } 650 /* usb2.0 but not high-speed capable; fine */ 651 } else if (retval != sizeof (struct usb_qualifier_descriptor)) { 652 dev_dbg (&iface->dev, "dev qualifier --> %d\n", retval); 653 return (retval < 0) ? retval : -EDOM; 654 } else 655 d = (struct usb_qualifier_descriptor *) dev->buf; 656 657 /* might not have [9.6.2] any other-speed configs [9.6.4] */ 658 if (d) { 659 unsigned max = d->bNumConfigurations; 660 for (i = 0; i < max; i++) { 661 retval = usb_get_descriptor (udev, 662 USB_DT_OTHER_SPEED_CONFIG, i, 663 dev->buf, TBUF_SIZE); 664 if (!is_good_config (dev->buf, retval)) { 665 dev_dbg (&iface->dev, 666 "other speed config --> %d\n", 667 retval); 668 return (retval < 0) ? retval : -EDOM; 669 } 670 } 671 } 672 } 673 674 /* [9.4.5] get_status always works */ 675 retval = usb_get_status (udev, USB_RECIP_DEVICE, 0, dev->buf); 676 if (retval != 2) { 677 dev_dbg (&iface->dev, "get dev status --> %d\n", retval); 678 return (retval < 0) ? retval : -EDOM; 679 } 680 681 // the device's remote wakeup feature ... if we can, test that here 682 683 retval = usb_get_status (udev, USB_RECIP_INTERFACE, 684 iface->altsetting [0].desc.bInterfaceNumber, dev->buf); 685 if (retval != 2) { 686 dev_dbg (&iface->dev, "get interface status --> %d\n", retval); 687 return (retval < 0) ? retval : -EDOM; 688 } 689 690 return 0; 691} 692 693/*-------------------------------------------------------------------------*/ 694 695/* use ch9 requests to test whether: 696 * (a) queues work for control, keeping N subtests queued and 697 * active (auto-resubmit) for M loops through the queue. 698 * (b) protocol stalls (control-only) will autorecover. 699 * it's not like bulk/intr; no halt clearing. 700 * (c) short control reads are reported and handled. 701 * (d) queues are always processed in-order 702 */ 703 704struct ctrl_ctx { 705 spinlock_t lock; 706 struct usbtest_dev *dev; 707 struct completion complete; 708 unsigned count; 709 unsigned pending; 710 int status; 711 struct urb **urb; 712 struct usbtest_param *param; 713 int last; 714}; 715 716#define NUM_SUBCASES 15 /* how many test subcases here? */ 717 718struct subcase { 719 struct usb_ctrlrequest setup; 720 int number; 721 int expected; 722}; 723 724static void ctrl_complete (struct urb *urb) 725{ 726 struct ctrl_ctx *ctx = urb->context; 727 struct usb_ctrlrequest *reqp; 728 struct subcase *subcase; 729 int status = urb->status; 730 731 reqp = (struct usb_ctrlrequest *)urb->setup_packet; 732 subcase = container_of (reqp, struct subcase, setup); 733 734 spin_lock (&ctx->lock); 735 ctx->count--; 736 ctx->pending--; 737 738 /* queue must transfer and complete in fifo order, unless 739 * usb_unlink_urb() is used to unlink something not at the 740 * physical queue head (not tested). 741 */ 742 if (subcase->number > 0) { 743 if ((subcase->number - ctx->last) != 1) { 744 dbg ("subcase %d completed out of order, last %d", 745 subcase->number, ctx->last); 746 status = -EDOM; 747 ctx->last = subcase->number; 748 goto error; 749 } 750 } 751 ctx->last = subcase->number; 752 753 /* succeed or fault in only one way? */ 754 if (status == subcase->expected) 755 status = 0; 756 757 /* async unlink for cleanup? */ 758 else if (status != -ECONNRESET) { 759 760 /* some faults are allowed, not required */ 761 if (subcase->expected > 0 && ( 762 ((urb->status == -subcase->expected /* happened */ 763 || urb->status == 0)))) /* didn't */ 764 status = 0; 765 /* sometimes more than one fault is allowed */ 766 else if (subcase->number == 12 && status == -EPIPE) 767 status = 0; 768 else 769 dbg ("subtest %d error, status %d", 770 subcase->number, status); 771 } 772 773 /* unexpected status codes mean errors; ideally, in hardware */ 774 if (status) { 775error: 776 if (ctx->status == 0) { 777 int i; 778 779 ctx->status = status; 780 info ("control queue %02x.%02x, err %d, %d left", 781 reqp->bRequestType, reqp->bRequest, 782 status, ctx->count); 783 784 785 /* unlink whatever's still pending */ 786 for (i = 1; i < ctx->param->sglen; i++) { 787 struct urb *u = ctx->urb [ 788 (i + subcase->number) % ctx->param->sglen]; 789 790 if (u == urb || !u->dev) 791 continue; 792 spin_unlock(&ctx->lock); 793 status = usb_unlink_urb (u); 794 spin_lock(&ctx->lock); 795 switch (status) { 796 case -EINPROGRESS: 797 case -EBUSY: 798 case -EIDRM: 799 continue; 800 default: 801 dbg ("urb unlink --> %d", status); 802 } 803 } 804 status = ctx->status; 805 } 806 } 807 808 /* resubmit if we need to, else mark this as done */ 809 if ((status == 0) && (ctx->pending < ctx->count)) { 810 if ((status = usb_submit_urb (urb, GFP_ATOMIC)) != 0) { 811 dbg ("can't resubmit ctrl %02x.%02x, err %d", 812 reqp->bRequestType, reqp->bRequest, status); 813 urb->dev = NULL; 814 } else 815 ctx->pending++; 816 } else 817 urb->dev = NULL; 818 819 /* signal completion when nothing's queued */ 820 if (ctx->pending == 0) 821 complete (&ctx->complete); 822 spin_unlock (&ctx->lock); 823} 824 825static int 826test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param) 827{ 828 struct usb_device *udev = testdev_to_usbdev (dev); 829 struct urb **urb; 830 struct ctrl_ctx context; 831 int i; 832 833 spin_lock_init (&context.lock); 834 context.dev = dev; 835 init_completion (&context.complete); 836 context.count = param->sglen * param->iterations; 837 context.pending = 0; 838 context.status = -ENOMEM; 839 context.param = param; 840 context.last = -1; 841 842 /* allocate and init the urbs we'll queue. 843 * as with bulk/intr sglists, sglen is the queue depth; it also 844 * controls which subtests run (more tests than sglen) or rerun. 845 */ 846 urb = kcalloc(param->sglen, sizeof(struct urb *), GFP_KERNEL); 847 if (!urb) 848 return -ENOMEM; 849 for (i = 0; i < param->sglen; i++) { 850 int pipe = usb_rcvctrlpipe (udev, 0); 851 unsigned len; 852 struct urb *u; 853 struct usb_ctrlrequest req; 854 struct subcase *reqp; 855 int expected = 0; 856 857 /* requests here are mostly expected to succeed on any 858 * device, but some are chosen to trigger protocol stalls 859 * or short reads. 860 */ 861 memset (&req, 0, sizeof req); 862 req.bRequest = USB_REQ_GET_DESCRIPTOR; 863 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 864 865 switch (i % NUM_SUBCASES) { 866 case 0: // get device descriptor 867 req.wValue = cpu_to_le16 (USB_DT_DEVICE << 8); 868 len = sizeof (struct usb_device_descriptor); 869 break; 870 case 1: // get first config descriptor (only) 871 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 872 len = sizeof (struct usb_config_descriptor); 873 break; 874 case 2: // get altsetting (OFTEN STALLS) 875 req.bRequest = USB_REQ_GET_INTERFACE; 876 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; 877 // index = 0 means first interface 878 len = 1; 879 expected = EPIPE; 880 break; 881 case 3: // get interface status 882 req.bRequest = USB_REQ_GET_STATUS; 883 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; 884 // interface 0 885 len = 2; 886 break; 887 case 4: // get device status 888 req.bRequest = USB_REQ_GET_STATUS; 889 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 890 len = 2; 891 break; 892 case 5: // get device qualifier (MAY STALL) 893 req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8); 894 len = sizeof (struct usb_qualifier_descriptor); 895 if (udev->speed != USB_SPEED_HIGH) 896 expected = EPIPE; 897 break; 898 case 6: // get first config descriptor, plus interface 899 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 900 len = sizeof (struct usb_config_descriptor); 901 len += sizeof (struct usb_interface_descriptor); 902 break; 903 case 7: // get interface descriptor (ALWAYS STALLS) 904 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8); 905 // interface == 0 906 len = sizeof (struct usb_interface_descriptor); 907 expected = EPIPE; 908 break; 909 // NOTE: two consecutive stalls in the queue here. 910 // that tests fault recovery a bit more aggressively. 911 case 8: // clear endpoint halt (USUALLY STALLS) 912 req.bRequest = USB_REQ_CLEAR_FEATURE; 913 req.bRequestType = USB_RECIP_ENDPOINT; 914 // wValue 0 == ep halt 915 // wIndex 0 == ep0 (shouldn't halt!) 916 len = 0; 917 pipe = usb_sndctrlpipe (udev, 0); 918 expected = EPIPE; 919 break; 920 case 9: // get endpoint status 921 req.bRequest = USB_REQ_GET_STATUS; 922 req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT; 923 // endpoint 0 924 len = 2; 925 break; 926 case 10: // trigger short read (EREMOTEIO) 927 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 928 len = 1024; 929 expected = -EREMOTEIO; 930 break; 931 // NOTE: two consecutive _different_ faults in the queue. 932 case 11: // get endpoint descriptor (ALWAYS STALLS) 933 req.wValue = cpu_to_le16 (USB_DT_ENDPOINT << 8); 934 // endpoint == 0 935 len = sizeof (struct usb_interface_descriptor); 936 expected = EPIPE; 937 break; 938 // NOTE: sometimes even a third fault in the queue! 939 case 12: // get string 0 descriptor (MAY STALL) 940 req.wValue = cpu_to_le16 (USB_DT_STRING << 8); 941 // string == 0, for language IDs 942 len = sizeof (struct usb_interface_descriptor); 943 // may succeed when > 4 languages 944 expected = EREMOTEIO; // or EPIPE, if no strings 945 break; 946 case 13: // short read, resembling case 10 947 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 948 // last data packet "should" be DATA1, not DATA0 949 len = 1024 - udev->descriptor.bMaxPacketSize0; 950 expected = -EREMOTEIO; 951 break; 952 case 14: // short read; try to fill the last packet 953 req.wValue = cpu_to_le16 ((USB_DT_DEVICE << 8) | 0); 954 // device descriptor size == 18 bytes 955 len = udev->descriptor.bMaxPacketSize0; 956 switch (len) { 957 case 8: len = 24; break; 958 case 16: len = 32; break; 959 } 960 expected = -EREMOTEIO; 961 break; 962 default: 963 err ("bogus number of ctrl queue testcases!"); 964 context.status = -EINVAL; 965 goto cleanup; 966 } 967 req.wLength = cpu_to_le16 (len); 968 urb [i] = u = simple_alloc_urb (udev, pipe, len); 969 if (!u) 970 goto cleanup; 971 972 reqp = usb_buffer_alloc (udev, sizeof *reqp, GFP_KERNEL, 973 &u->setup_dma); 974 if (!reqp) 975 goto cleanup; 976 reqp->setup = req; 977 reqp->number = i % NUM_SUBCASES; 978 reqp->expected = expected; 979 u->setup_packet = (char *) &reqp->setup; 980 u->transfer_flags |= URB_NO_SETUP_DMA_MAP; 981 982 u->context = &context; 983 u->complete = ctrl_complete; 984 } 985 986 /* queue the urbs */ 987 context.urb = urb; 988 spin_lock_irq (&context.lock); 989 for (i = 0; i < param->sglen; i++) { 990 context.status = usb_submit_urb (urb [i], GFP_ATOMIC); 991 if (context.status != 0) { 992 dbg ("can't submit urb[%d], status %d", 993 i, context.status); 994 context.count = context.pending; 995 break; 996 } 997 context.pending++; 998 } 999 spin_unlock_irq (&context.lock); 1000 1001 1002 /* wait for the last one to complete */ 1003 if (context.pending > 0) 1004 wait_for_completion (&context.complete); 1005 1006cleanup: 1007 for (i = 0; i < param->sglen; i++) { 1008 if (!urb [i]) 1009 continue; 1010 urb [i]->dev = udev; 1011 if (urb [i]->setup_packet) 1012 usb_buffer_free (udev, sizeof (struct usb_ctrlrequest), 1013 urb [i]->setup_packet, 1014 urb [i]->setup_dma); 1015 simple_free_urb (urb [i]); 1016 } 1017 kfree (urb); 1018 return context.status; 1019} 1020#undef NUM_SUBCASES 1021 1022 1023/*-------------------------------------------------------------------------*/ 1024 1025static void unlink1_callback (struct urb *urb) 1026{ 1027 int status = urb->status; 1028 1029 // we "know" -EPIPE (stall) never happens 1030 if (!status) 1031 status = usb_submit_urb (urb, GFP_ATOMIC); 1032 if (status) { 1033 urb->status = status; 1034 complete ((struct completion *) urb->context); 1035 } 1036} 1037 1038static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async) 1039{ 1040 struct urb *urb; 1041 struct completion completion; 1042 int retval = 0; 1043 1044 init_completion (&completion); 1045 urb = simple_alloc_urb (testdev_to_usbdev (dev), pipe, size); 1046 if (!urb) 1047 return -ENOMEM; 1048 urb->context = &completion; 1049 urb->complete = unlink1_callback; 1050 1051 if ((retval = usb_submit_urb (urb, GFP_KERNEL)) != 0) { 1052 dev_dbg (&dev->intf->dev, "submit fail %d\n", retval); 1053 return retval; 1054 } 1055 1056 /* unlinking that should always work. variable delay tests more 1057 * hcd states and code paths, even with little other system load. 1058 */ 1059 msleep (jiffies % (2 * INTERRUPT_RATE)); 1060 if (async) { 1061retry: 1062 retval = usb_unlink_urb (urb); 1063 if (retval == -EBUSY || retval == -EIDRM) { 1064 /* we can't unlink urbs while they're completing. 1065 * or if they've completed, and we haven't resubmitted. 1066 * "normal" drivers would prevent resubmission, but 1067 * since we're testing unlink paths, we can't. 1068 */ 1069 dev_dbg (&dev->intf->dev, "unlink retry\n"); 1070 goto retry; 1071 } 1072 } else 1073 usb_kill_urb (urb); 1074 if (!(retval == 0 || retval == -EINPROGRESS)) { 1075 dev_dbg (&dev->intf->dev, "unlink fail %d\n", retval); 1076 return retval; 1077 } 1078 1079 wait_for_completion (&completion); 1080 retval = urb->status; 1081 simple_free_urb (urb); 1082 1083 if (async) 1084 return (retval == -ECONNRESET) ? 0 : retval - 1000; 1085 else 1086 return (retval == -ENOENT || retval == -EPERM) ? 1087 0 : retval - 2000; 1088} 1089 1090static int unlink_simple (struct usbtest_dev *dev, int pipe, int len) 1091{ 1092 int retval = 0; 1093 1094 /* test sync and async paths */ 1095 retval = unlink1 (dev, pipe, len, 1); 1096 if (!retval) 1097 retval = unlink1 (dev, pipe, len, 0); 1098 return retval; 1099} 1100 1101/*-------------------------------------------------------------------------*/ 1102 1103static int verify_not_halted (int ep, struct urb *urb) 1104{ 1105 int retval; 1106 u16 status; 1107 1108 /* shouldn't look or act halted */ 1109 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status); 1110 if (retval < 0) { 1111 dbg ("ep %02x couldn't get no-halt status, %d", ep, retval); 1112 return retval; 1113 } 1114 if (status != 0) { 1115 dbg ("ep %02x bogus status: %04x != 0", ep, status); 1116 return -EINVAL; 1117 } 1118 retval = simple_io (urb, 1, 0, 0, __FUNCTION__); 1119 if (retval != 0) 1120 return -EINVAL; 1121 return 0; 1122} 1123 1124static int verify_halted (int ep, struct urb *urb) 1125{ 1126 int retval; 1127 u16 status; 1128 1129 /* should look and act halted */ 1130 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status); 1131 if (retval < 0) { 1132 dbg ("ep %02x couldn't get halt status, %d", ep, retval); 1133 return retval; 1134 } 1135 if (status != 1) { 1136 dbg ("ep %02x bogus status: %04x != 1", ep, status); 1137 return -EINVAL; 1138 } 1139 retval = simple_io (urb, 1, 0, -EPIPE, __FUNCTION__); 1140 if (retval != -EPIPE) 1141 return -EINVAL; 1142 retval = simple_io (urb, 1, 0, -EPIPE, "verify_still_halted"); 1143 if (retval != -EPIPE) 1144 return -EINVAL; 1145 return 0; 1146} 1147 1148static int test_halt (int ep, struct urb *urb) 1149{ 1150 int retval; 1151 1152 /* shouldn't look or act halted now */ 1153 retval = verify_not_halted (ep, urb); 1154 if (retval < 0) 1155 return retval; 1156 1157 /* set halt (protocol test only), verify it worked */ 1158 retval = usb_control_msg (urb->dev, usb_sndctrlpipe (urb->dev, 0), 1159 USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT, 1160 USB_ENDPOINT_HALT, ep, 1161 NULL, 0, USB_CTRL_SET_TIMEOUT); 1162 if (retval < 0) { 1163 dbg ("ep %02x couldn't set halt, %d", ep, retval); 1164 return retval; 1165 } 1166 retval = verify_halted (ep, urb); 1167 if (retval < 0) 1168 return retval; 1169 1170 /* clear halt (tests API + protocol), verify it worked */ 1171 retval = usb_clear_halt (urb->dev, urb->pipe); 1172 if (retval < 0) { 1173 dbg ("ep %02x couldn't clear halt, %d", ep, retval); 1174 return retval; 1175 } 1176 retval = verify_not_halted (ep, urb); 1177 if (retval < 0) 1178 return retval; 1179 1180 /* NOTE: could also verify SET_INTERFACE clear halts ... */ 1181 1182 return 0; 1183} 1184 1185static int halt_simple (struct usbtest_dev *dev) 1186{ 1187 int ep; 1188 int retval = 0; 1189 struct urb *urb; 1190 1191 urb = simple_alloc_urb (testdev_to_usbdev (dev), 0, 512); 1192 if (urb == NULL) 1193 return -ENOMEM; 1194 1195 if (dev->in_pipe) { 1196 ep = usb_pipeendpoint (dev->in_pipe) | USB_DIR_IN; 1197 urb->pipe = dev->in_pipe; 1198 retval = test_halt (ep, urb); 1199 if (retval < 0) 1200 goto done; 1201 } 1202 1203 if (dev->out_pipe) { 1204 ep = usb_pipeendpoint (dev->out_pipe); 1205 urb->pipe = dev->out_pipe; 1206 retval = test_halt (ep, urb); 1207 } 1208done: 1209 simple_free_urb (urb); 1210 return retval; 1211} 1212 1213/*-------------------------------------------------------------------------*/ 1214 1215/* Control OUT tests use the vendor control requests from Intel's 1216 * USB 2.0 compliance test device: write a buffer, read it back. 1217 * 1218 * Intel's spec only _requires_ that it work for one packet, which 1219 * is pretty weak. Some HCDs place limits here; most devices will 1220 * need to be able to handle more than one OUT data packet. We'll 1221 * try whatever we're told to try. 1222 */ 1223static int ctrl_out (struct usbtest_dev *dev, 1224 unsigned count, unsigned length, unsigned vary) 1225{ 1226 unsigned i, j, len; 1227 int retval; 1228 u8 *buf; 1229 char *what = "?"; 1230 struct usb_device *udev; 1231 1232 if (length < 1 || length > 0xffff || vary >= length) 1233 return -EINVAL; 1234 1235 buf = kmalloc(length, GFP_KERNEL); 1236 if (!buf) 1237 return -ENOMEM; 1238 1239 udev = testdev_to_usbdev (dev); 1240 len = length; 1241 retval = 0; 1242 1243 /* NOTE: hardware might well act differently if we pushed it 1244 * with lots back-to-back queued requests. 1245 */ 1246 for (i = 0; i < count; i++) { 1247 /* write patterned data */ 1248 for (j = 0; j < len; j++) 1249 buf [j] = i + j; 1250 retval = usb_control_msg (udev, usb_sndctrlpipe (udev,0), 1251 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR, 1252 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); 1253 if (retval != len) { 1254 what = "write"; 1255 if (retval >= 0) { 1256 INFO(dev, "ctrl_out, wlen %d (expected %d)\n", 1257 retval, len); 1258 retval = -EBADMSG; 1259 } 1260 break; 1261 } 1262 1263 /* read it back -- assuming nothing intervened!! */ 1264 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev,0), 1265 0x5c, USB_DIR_IN|USB_TYPE_VENDOR, 1266 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); 1267 if (retval != len) { 1268 what = "read"; 1269 if (retval >= 0) { 1270 INFO(dev, "ctrl_out, rlen %d (expected %d)\n", 1271 retval, len); 1272 retval = -EBADMSG; 1273 } 1274 break; 1275 } 1276 1277 /* fail if we can't verify */ 1278 for (j = 0; j < len; j++) { 1279 if (buf [j] != (u8) (i + j)) { 1280 INFO (dev, "ctrl_out, byte %d is %d not %d\n", 1281 j, buf [j], (u8) i + j); 1282 retval = -EBADMSG; 1283 break; 1284 } 1285 } 1286 if (retval < 0) { 1287 what = "verify"; 1288 break; 1289 } 1290 1291 len += vary; 1292 1293 /* [real world] the "zero bytes IN" case isn't really used. 1294 * hardware can easily trip up in this wierd case, since its 1295 * status stage is IN, not OUT like other ep0in transfers. 1296 */ 1297 if (len > length) 1298 len = realworld ? 1 : 0; 1299 } 1300 1301 if (retval < 0) 1302 INFO (dev, "ctrl_out %s failed, code %d, count %d\n", 1303 what, retval, i); 1304 1305 kfree (buf); 1306 return retval; 1307} 1308 1309/*-------------------------------------------------------------------------*/ 1310 1311/* ISO tests ... mimics common usage 1312 * - buffer length is split into N packets (mostly maxpacket sized) 1313 * - multi-buffers according to sglen 1314 */ 1315 1316struct iso_context { 1317 unsigned count; 1318 unsigned pending; 1319 spinlock_t lock; 1320 struct completion done; 1321 int submit_error; 1322 unsigned long errors; 1323 unsigned long packet_count; 1324 struct usbtest_dev *dev; 1325}; 1326 1327static void iso_callback (struct urb *urb) 1328{ 1329 struct iso_context *ctx = urb->context; 1330 1331 spin_lock(&ctx->lock); 1332 ctx->count--; 1333 1334 ctx->packet_count += urb->number_of_packets; 1335 if (urb->error_count > 0) 1336 ctx->errors += urb->error_count; 1337 else if (urb->status != 0) 1338 ctx->errors += urb->number_of_packets; 1339 1340 if (urb->status == 0 && ctx->count > (ctx->pending - 1) 1341 && !ctx->submit_error) { 1342 int status = usb_submit_urb (urb, GFP_ATOMIC); 1343 switch (status) { 1344 case 0: 1345 goto done; 1346 default: 1347 dev_dbg (&ctx->dev->intf->dev, 1348 "iso resubmit err %d\n", 1349 status); 1350 /* FALLTHROUGH */ 1351 case -ENODEV: /* disconnected */ 1352 case -ESHUTDOWN: /* endpoint disabled */ 1353 ctx->submit_error = 1; 1354 break; 1355 } 1356 } 1357 simple_free_urb (urb); 1358 1359 ctx->pending--; 1360 if (ctx->pending == 0) { 1361 if (ctx->errors) 1362 dev_dbg (&ctx->dev->intf->dev, 1363 "iso test, %lu errors out of %lu\n", 1364 ctx->errors, ctx->packet_count); 1365 complete (&ctx->done); 1366 } 1367done: 1368 spin_unlock(&ctx->lock); 1369} 1370 1371static struct urb *iso_alloc_urb ( 1372 struct usb_device *udev, 1373 int pipe, 1374 struct usb_endpoint_descriptor *desc, 1375 long bytes 1376) 1377{ 1378 struct urb *urb; 1379 unsigned i, maxp, packets; 1380 1381 if (bytes < 0 || !desc) 1382 return NULL; 1383 maxp = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); 1384 maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11)); 1385 packets = (bytes + maxp - 1) / maxp; 1386 1387 urb = usb_alloc_urb (packets, GFP_KERNEL); 1388 if (!urb) 1389 return urb; 1390 urb->dev = udev; 1391 urb->pipe = pipe; 1392 1393 urb->number_of_packets = packets; 1394 urb->transfer_buffer_length = bytes; 1395 urb->transfer_buffer = usb_buffer_alloc (udev, bytes, GFP_KERNEL, 1396 &urb->transfer_dma); 1397 if (!urb->transfer_buffer) { 1398 usb_free_urb (urb); 1399 return NULL; 1400 } 1401 memset (urb->transfer_buffer, 0, bytes); 1402 for (i = 0; i < packets; i++) { 1403 /* here, only the last packet will be short */ 1404 urb->iso_frame_desc[i].length = min ((unsigned) bytes, maxp); 1405 bytes -= urb->iso_frame_desc[i].length; 1406 1407 urb->iso_frame_desc[i].offset = maxp * i; 1408 } 1409 1410 urb->complete = iso_callback; 1411 // urb->context = SET BY CALLER 1412 urb->interval = 1 << (desc->bInterval - 1); 1413 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1414 return urb; 1415} 1416 1417static int 1418test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param, 1419 int pipe, struct usb_endpoint_descriptor *desc) 1420{ 1421 struct iso_context context; 1422 struct usb_device *udev; 1423 unsigned i; 1424 unsigned long packets = 0; 1425 int status = 0; 1426 struct urb *urbs[10]; 1427 1428 if (param->sglen > 10) 1429 return -EDOM; 1430 1431 memset(&context, 0, sizeof context); 1432 context.count = param->iterations * param->sglen; 1433 context.dev = dev; 1434 init_completion (&context.done); 1435 spin_lock_init (&context.lock); 1436 1437 memset (urbs, 0, sizeof urbs); 1438 udev = testdev_to_usbdev (dev); 1439 dev_dbg (&dev->intf->dev, 1440 "... iso period %d %sframes, wMaxPacket %04x\n", 1441 1 << (desc->bInterval - 1), 1442 (udev->speed == USB_SPEED_HIGH) ? "micro" : "", 1443 le16_to_cpu(desc->wMaxPacketSize)); 1444 1445 for (i = 0; i < param->sglen; i++) { 1446 urbs [i] = iso_alloc_urb (udev, pipe, desc, 1447 param->length); 1448 if (!urbs [i]) { 1449 status = -ENOMEM; 1450 goto fail; 1451 } 1452 packets += urbs[i]->number_of_packets; 1453 urbs [i]->context = &context; 1454 } 1455 packets *= param->iterations; 1456 dev_dbg (&dev->intf->dev, 1457 "... total %lu msec (%lu packets)\n", 1458 (packets * (1 << (desc->bInterval - 1))) 1459 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1), 1460 packets); 1461 1462 spin_lock_irq (&context.lock); 1463 for (i = 0; i < param->sglen; i++) { 1464 ++context.pending; 1465 status = usb_submit_urb (urbs [i], GFP_ATOMIC); 1466 if (status < 0) { 1467 ERROR (dev, "submit iso[%d], error %d\n", i, status); 1468 if (i == 0) { 1469 spin_unlock_irq (&context.lock); 1470 goto fail; 1471 } 1472 1473 simple_free_urb (urbs [i]); 1474 context.pending--; 1475 context.submit_error = 1; 1476 break; 1477 } 1478 } 1479 spin_unlock_irq (&context.lock); 1480 1481 wait_for_completion (&context.done); 1482 1483 /* 1484 * Isochronous transfers are expected to fail sometimes. As an 1485 * arbitrary limit, we will report an error if any submissions 1486 * fail or if the transfer failure rate is > 10%. 1487 */ 1488 if (status != 0) 1489 ; 1490 else if (context.submit_error) 1491 status = -EACCES; 1492 else if (context.errors > context.packet_count / 10) 1493 status = -EIO; 1494 return status; 1495 1496fail: 1497 for (i = 0; i < param->sglen; i++) { 1498 if (urbs [i]) 1499 simple_free_urb (urbs [i]); 1500 } 1501 return status; 1502} 1503 1504/*-------------------------------------------------------------------------*/ 1505 1506/* We only have this one interface to user space, through usbfs. 1507 * User mode code can scan usbfs to find N different devices (maybe on 1508 * different busses) to use when testing, and allocate one thread per 1509 * test. So discovery is simplified, and we have no device naming issues. 1510 * 1511 * Don't use these only as stress/load tests. Use them along with with 1512 * other USB bus activity: plugging, unplugging, mousing, mp3 playback, 1513 * video capture, and so on. Run different tests at different times, in 1514 * different sequences. Nothing here should interact with other devices, 1515 * except indirectly by consuming USB bandwidth and CPU resources for test 1516 * threads and request completion. But the only way to know that for sure 1517 * is to test when HC queues are in use by many devices. 1518 */ 1519 1520static int 1521usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) 1522{ 1523 struct usbtest_dev *dev = usb_get_intfdata (intf); 1524 struct usb_device *udev = testdev_to_usbdev (dev); 1525 struct usbtest_param *param = buf; 1526 int retval = -EOPNOTSUPP; 1527 struct urb *urb; 1528 struct scatterlist *sg; 1529 struct usb_sg_request req; 1530 struct timeval start; 1531 unsigned i; 1532 1533 1534 if (code != USBTEST_REQUEST) 1535 return -EOPNOTSUPP; 1536 1537 if (param->iterations <= 0 || param->length < 0 1538 || param->sglen < 0 || param->vary < 0) 1539 return -EINVAL; 1540 1541 if (down_interruptible (&dev->sem)) 1542 return -ERESTARTSYS; 1543 1544 if (intf->dev.power.power_state.event != PM_EVENT_ON) { 1545 up (&dev->sem); 1546 return -EHOSTUNREACH; 1547 } 1548 1549 /* some devices, like ez-usb default devices, need a non-default 1550 * altsetting to have any active endpoints. some tests change 1551 * altsettings; force a default so most tests don't need to check. 1552 */ 1553 if (dev->info->alt >= 0) { 1554 int res; 1555 1556 if (intf->altsetting->desc.bInterfaceNumber) { 1557 up (&dev->sem); 1558 return -ENODEV; 1559 } 1560 res = set_altsetting (dev, dev->info->alt); 1561 if (res) { 1562 dev_err (&intf->dev, 1563 "set altsetting to %d failed, %d\n", 1564 dev->info->alt, res); 1565 up (&dev->sem); 1566 return res; 1567 } 1568 } 1569 1570 do_gettimeofday (&start); 1571 switch (param->test_num) { 1572 1573 case 0: 1574 dev_dbg (&intf->dev, "TEST 0: NOP\n"); 1575 retval = 0; 1576 break; 1577 1578 /* Simple non-queued bulk I/O tests */ 1579 case 1: 1580 if (dev->out_pipe == 0) 1581 break; 1582 dev_dbg (&intf->dev, 1583 "TEST 1: write %d bytes %u times\n", 1584 param->length, param->iterations); 1585 urb = simple_alloc_urb (udev, dev->out_pipe, param->length); 1586 if (!urb) { 1587 retval = -ENOMEM; 1588 break; 1589 } 1590 // FIRMWARE: bulk sink (maybe accepts short writes) 1591 retval = simple_io (urb, param->iterations, 0, 0, "test1"); 1592 simple_free_urb (urb); 1593 break; 1594 case 2: 1595 if (dev->in_pipe == 0) 1596 break; 1597 dev_dbg (&intf->dev, 1598 "TEST 2: read %d bytes %u times\n", 1599 param->length, param->iterations); 1600 urb = simple_alloc_urb (udev, dev->in_pipe, param->length); 1601 if (!urb) { 1602 retval = -ENOMEM; 1603 break; 1604 } 1605 // FIRMWARE: bulk source (maybe generates short writes) 1606 retval = simple_io (urb, param->iterations, 0, 0, "test2"); 1607 simple_free_urb (urb); 1608 break; 1609 case 3: 1610 if (dev->out_pipe == 0 || param->vary == 0) 1611 break; 1612 dev_dbg (&intf->dev, 1613 "TEST 3: write/%d 0..%d bytes %u times\n", 1614 param->vary, param->length, param->iterations); 1615 urb = simple_alloc_urb (udev, dev->out_pipe, param->length); 1616 if (!urb) { 1617 retval = -ENOMEM; 1618 break; 1619 } 1620 // FIRMWARE: bulk sink (maybe accepts short writes) 1621 retval = simple_io (urb, param->iterations, param->vary, 1622 0, "test3"); 1623 simple_free_urb (urb); 1624 break; 1625 case 4: 1626 if (dev->in_pipe == 0 || param->vary == 0) 1627 break; 1628 dev_dbg (&intf->dev, 1629 "TEST 4: read/%d 0..%d bytes %u times\n", 1630 param->vary, param->length, param->iterations); 1631 urb = simple_alloc_urb (udev, dev->in_pipe, param->length); 1632 if (!urb) { 1633 retval = -ENOMEM; 1634 break; 1635 } 1636 // FIRMWARE: bulk source (maybe generates short writes) 1637 retval = simple_io (urb, param->iterations, param->vary, 1638 0, "test4"); 1639 simple_free_urb (urb); 1640 break; 1641 1642 /* Queued bulk I/O tests */ 1643 case 5: 1644 if (dev->out_pipe == 0 || param->sglen == 0) 1645 break; 1646 dev_dbg (&intf->dev, 1647 "TEST 5: write %d sglists %d entries of %d bytes\n", 1648 param->iterations, 1649 param->sglen, param->length); 1650 sg = alloc_sglist (param->sglen, param->length, 0); 1651 if (!sg) { 1652 retval = -ENOMEM; 1653 break; 1654 } 1655 // FIRMWARE: bulk sink (maybe accepts short writes) 1656 retval = perform_sglist (udev, param->iterations, dev->out_pipe, 1657 &req, sg, param->sglen); 1658 free_sglist (sg, param->sglen); 1659 break; 1660 1661 case 6: 1662 if (dev->in_pipe == 0 || param->sglen == 0) 1663 break; 1664 dev_dbg (&intf->dev, 1665 "TEST 6: read %d sglists %d entries of %d bytes\n", 1666 param->iterations, 1667 param->sglen, param->length); 1668 sg = alloc_sglist (param->sglen, param->length, 0); 1669 if (!sg) { 1670 retval = -ENOMEM; 1671 break; 1672 } 1673 // FIRMWARE: bulk source (maybe generates short writes) 1674 retval = perform_sglist (udev, param->iterations, dev->in_pipe, 1675 &req, sg, param->sglen); 1676 free_sglist (sg, param->sglen); 1677 break; 1678 case 7: 1679 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0) 1680 break; 1681 dev_dbg (&intf->dev, 1682 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n", 1683 param->vary, param->iterations, 1684 param->sglen, param->length); 1685 sg = alloc_sglist (param->sglen, param->length, param->vary); 1686 if (!sg) { 1687 retval = -ENOMEM; 1688 break; 1689 } 1690 // FIRMWARE: bulk sink (maybe accepts short writes) 1691 retval = perform_sglist (udev, param->iterations, dev->out_pipe, 1692 &req, sg, param->sglen); 1693 free_sglist (sg, param->sglen); 1694 break; 1695 case 8: 1696 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0) 1697 break; 1698 dev_dbg (&intf->dev, 1699 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n", 1700 param->vary, param->iterations, 1701 param->sglen, param->length); 1702 sg = alloc_sglist (param->sglen, param->length, param->vary); 1703 if (!sg) { 1704 retval = -ENOMEM; 1705 break; 1706 } 1707 // FIRMWARE: bulk source (maybe generates short writes) 1708 retval = perform_sglist (udev, param->iterations, dev->in_pipe, 1709 &req, sg, param->sglen); 1710 free_sglist (sg, param->sglen); 1711 break; 1712 1713 /* non-queued sanity tests for control (chapter 9 subset) */ 1714 case 9: 1715 retval = 0; 1716 dev_dbg (&intf->dev, 1717 "TEST 9: ch9 (subset) control tests, %d times\n", 1718 param->iterations); 1719 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1720 retval = ch9_postconfig (dev); 1721 if (retval) 1722 dbg ("ch9 subset failed, iterations left %d", i); 1723 break; 1724 1725 /* queued control messaging */ 1726 case 10: 1727 if (param->sglen == 0) 1728 break; 1729 retval = 0; 1730 dev_dbg (&intf->dev, 1731 "TEST 10: queue %d control calls, %d times\n", 1732 param->sglen, 1733 param->iterations); 1734 retval = test_ctrl_queue (dev, param); 1735 break; 1736 1737 /* simple non-queued unlinks (ring with one urb) */ 1738 case 11: 1739 if (dev->in_pipe == 0 || !param->length) 1740 break; 1741 retval = 0; 1742 dev_dbg (&intf->dev, "TEST 11: unlink %d reads of %d\n", 1743 param->iterations, param->length); 1744 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1745 retval = unlink_simple (dev, dev->in_pipe, 1746 param->length); 1747 if (retval) 1748 dev_dbg (&intf->dev, "unlink reads failed %d, " 1749 "iterations left %d\n", retval, i); 1750 break; 1751 case 12: 1752 if (dev->out_pipe == 0 || !param->length) 1753 break; 1754 retval = 0; 1755 dev_dbg (&intf->dev, "TEST 12: unlink %d writes of %d\n", 1756 param->iterations, param->length); 1757 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1758 retval = unlink_simple (dev, dev->out_pipe, 1759 param->length); 1760 if (retval) 1761 dev_dbg (&intf->dev, "unlink writes failed %d, " 1762 "iterations left %d\n", retval, i); 1763 break; 1764 1765 /* ep halt tests */ 1766 case 13: 1767 if (dev->out_pipe == 0 && dev->in_pipe == 0) 1768 break; 1769 retval = 0; 1770 dev_dbg (&intf->dev, "TEST 13: set/clear %d halts\n", 1771 param->iterations); 1772 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1773 retval = halt_simple (dev); 1774 1775 if (retval) 1776 DBG (dev, "halts failed, iterations left %d\n", i); 1777 break; 1778 1779 /* control write tests */ 1780 case 14: 1781 if (!dev->info->ctrl_out) 1782 break; 1783 dev_dbg (&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n", 1784 param->iterations, 1785 realworld ? 1 : 0, param->length, 1786 param->vary); 1787 retval = ctrl_out (dev, param->iterations, 1788 param->length, param->vary); 1789 break; 1790 1791 /* iso write tests */ 1792 case 15: 1793 if (dev->out_iso_pipe == 0 || param->sglen == 0) 1794 break; 1795 dev_dbg (&intf->dev, 1796 "TEST 15: write %d iso, %d entries of %d bytes\n", 1797 param->iterations, 1798 param->sglen, param->length); 1799 // FIRMWARE: iso sink 1800 retval = test_iso_queue (dev, param, 1801 dev->out_iso_pipe, dev->iso_out); 1802 break; 1803 1804 /* iso read tests */ 1805 case 16: 1806 if (dev->in_iso_pipe == 0 || param->sglen == 0) 1807 break; 1808 dev_dbg (&intf->dev, 1809 "TEST 16: read %d iso, %d entries of %d bytes\n", 1810 param->iterations, 1811 param->sglen, param->length); 1812 // FIRMWARE: iso source 1813 retval = test_iso_queue (dev, param, 1814 dev->in_iso_pipe, dev->iso_in); 1815 break; 1816 1817 1818 1819 } 1820 do_gettimeofday (¶m->duration); 1821 param->duration.tv_sec -= start.tv_sec; 1822 param->duration.tv_usec -= start.tv_usec; 1823 if (param->duration.tv_usec < 0) { 1824 param->duration.tv_usec += 1000 * 1000; 1825 param->duration.tv_sec -= 1; 1826 } 1827 up (&dev->sem); 1828 return retval; 1829} 1830 1831/*-------------------------------------------------------------------------*/ 1832 1833static unsigned force_interrupt = 0; 1834module_param (force_interrupt, uint, 0); 1835MODULE_PARM_DESC (force_interrupt, "0 = test default; else interrupt"); 1836 1837#ifdef GENERIC 1838static unsigned short vendor; 1839module_param(vendor, ushort, 0); 1840MODULE_PARM_DESC (vendor, "vendor code (from usb-if)"); 1841 1842static unsigned short product; 1843module_param(product, ushort, 0); 1844MODULE_PARM_DESC (product, "product code (from vendor)"); 1845#endif 1846 1847static int 1848usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id) 1849{ 1850 struct usb_device *udev; 1851 struct usbtest_dev *dev; 1852 struct usbtest_info *info; 1853 char *rtest, *wtest; 1854 char *irtest, *iwtest; 1855 1856 udev = interface_to_usbdev (intf); 1857 1858#ifdef GENERIC 1859 /* specify devices by module parameters? */ 1860 if (id->match_flags == 0) { 1861 /* vendor match required, product match optional */ 1862 if (!vendor || le16_to_cpu(udev->descriptor.idVendor) != (u16)vendor) 1863 return -ENODEV; 1864 if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product) 1865 return -ENODEV; 1866 dbg ("matched module params, vend=0x%04x prod=0x%04x", 1867 le16_to_cpu(udev->descriptor.idVendor), 1868 le16_to_cpu(udev->descriptor.idProduct)); 1869 } 1870#endif 1871 1872 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1873 if (!dev) 1874 return -ENOMEM; 1875 info = (struct usbtest_info *) id->driver_info; 1876 dev->info = info; 1877 init_MUTEX (&dev->sem); 1878 1879 dev->intf = intf; 1880 1881 /* cacheline-aligned scratch for i/o */ 1882 if ((dev->buf = kmalloc (TBUF_SIZE, GFP_KERNEL)) == NULL) { 1883 kfree (dev); 1884 return -ENOMEM; 1885 } 1886 1887 /* NOTE this doesn't yet test the handful of difference that are 1888 * visible with high speed interrupts: bigger maxpacket (1K) and 1889 * "high bandwidth" modes (up to 3 packets/uframe). 1890 */ 1891 rtest = wtest = ""; 1892 irtest = iwtest = ""; 1893 if (force_interrupt || udev->speed == USB_SPEED_LOW) { 1894 if (info->ep_in) { 1895 dev->in_pipe = usb_rcvintpipe (udev, info->ep_in); 1896 rtest = " intr-in"; 1897 } 1898 if (info->ep_out) { 1899 dev->out_pipe = usb_sndintpipe (udev, info->ep_out); 1900 wtest = " intr-out"; 1901 } 1902 } else { 1903 if (info->autoconf) { 1904 int status; 1905 1906 status = get_endpoints (dev, intf); 1907 if (status < 0) { 1908 dbg ("couldn't get endpoints, %d\n", status); 1909 return status; 1910 } 1911 /* may find bulk or ISO pipes */ 1912 } else { 1913 if (info->ep_in) 1914 dev->in_pipe = usb_rcvbulkpipe (udev, 1915 info->ep_in); 1916 if (info->ep_out) 1917 dev->out_pipe = usb_sndbulkpipe (udev, 1918 info->ep_out); 1919 } 1920 if (dev->in_pipe) 1921 rtest = " bulk-in"; 1922 if (dev->out_pipe) 1923 wtest = " bulk-out"; 1924 if (dev->in_iso_pipe) 1925 irtest = " iso-in"; 1926 if (dev->out_iso_pipe) 1927 iwtest = " iso-out"; 1928 } 1929 1930 usb_set_intfdata (intf, dev); 1931 dev_info (&intf->dev, "%s\n", info->name); 1932 dev_info (&intf->dev, "%s speed {control%s%s%s%s%s} tests%s\n", 1933 ({ char *tmp; 1934 switch (udev->speed) { 1935 case USB_SPEED_LOW: tmp = "low"; break; 1936 case USB_SPEED_FULL: tmp = "full"; break; 1937 case USB_SPEED_HIGH: tmp = "high"; break; 1938 default: tmp = "unknown"; break; 1939 }; tmp; }), 1940 info->ctrl_out ? " in/out" : "", 1941 rtest, wtest, 1942 irtest, iwtest, 1943 info->alt >= 0 ? " (+alt)" : ""); 1944 return 0; 1945} 1946 1947static int usbtest_suspend (struct usb_interface *intf, pm_message_t message) 1948{ 1949 return 0; 1950} 1951 1952static int usbtest_resume (struct usb_interface *intf) 1953{ 1954 return 0; 1955} 1956 1957 1958static void usbtest_disconnect (struct usb_interface *intf) 1959{ 1960 struct usbtest_dev *dev = usb_get_intfdata (intf); 1961 1962 down (&dev->sem); 1963 1964 usb_set_intfdata (intf, NULL); 1965 dev_dbg (&intf->dev, "disconnect\n"); 1966 kfree (dev); 1967} 1968 1969/* Basic testing only needs a device that can source or sink bulk traffic. 1970 * Any device can test control transfers (default with GENERIC binding). 1971 * 1972 * Several entries work with the default EP0 implementation that's built 1973 * into EZ-USB chips. There's a default vendor ID which can be overridden 1974 * by (very) small config EEPROMS, but otherwise all these devices act 1975 * identically until firmware is loaded: only EP0 works. It turns out 1976 * to be easy to make other endpoints work, without modifying that EP0 1977 * behavior. For now, we expect that kind of firmware. 1978 */ 1979 1980/* an21xx or fx versions of ez-usb */ 1981static struct usbtest_info ez1_info = { 1982 .name = "EZ-USB device", 1983 .ep_in = 2, 1984 .ep_out = 2, 1985 .alt = 1, 1986}; 1987 1988/* fx2 version of ez-usb */ 1989static struct usbtest_info ez2_info = { 1990 .name = "FX2 device", 1991 .ep_in = 6, 1992 .ep_out = 2, 1993 .alt = 1, 1994}; 1995 1996/* ezusb family device with dedicated usb test firmware, 1997 */ 1998static struct usbtest_info fw_info = { 1999 .name = "usb test device", 2000 .ep_in = 2, 2001 .ep_out = 2, 2002 .alt = 1, 2003 .autoconf = 1, // iso and ctrl_out need autoconf 2004 .ctrl_out = 1, 2005 .iso = 1, // iso_ep's are #8 in/out 2006}; 2007 2008/* peripheral running Linux and 'zero.c' test firmware, or 2009 * its user-mode cousin. different versions of this use 2010 * different hardware with the same vendor/product codes. 2011 * host side MUST rely on the endpoint descriptors. 2012 */ 2013static struct usbtest_info gz_info = { 2014 .name = "Linux gadget zero", 2015 .autoconf = 1, 2016 .ctrl_out = 1, 2017 .alt = 0, 2018}; 2019 2020static struct usbtest_info um_info = { 2021 .name = "Linux user mode test driver", 2022 .autoconf = 1, 2023 .alt = -1, 2024}; 2025 2026static struct usbtest_info um2_info = { 2027 .name = "Linux user mode ISO test driver", 2028 .autoconf = 1, 2029 .iso = 1, 2030 .alt = -1, 2031}; 2032 2033#ifdef IBOT2 2034/* this is a nice source of high speed bulk data; 2035 * uses an FX2, with firmware provided in the device 2036 */ 2037static struct usbtest_info ibot2_info = { 2038 .name = "iBOT2 webcam", 2039 .ep_in = 2, 2040 .alt = -1, 2041}; 2042#endif 2043 2044#ifdef GENERIC 2045/* we can use any device to test control traffic */ 2046static struct usbtest_info generic_info = { 2047 .name = "Generic USB device", 2048 .alt = -1, 2049}; 2050#endif 2051 2052static struct usbtest_info hact_info = { 2053 .name = "FX2/hact", 2054 //.ep_in = 6, 2055 .ep_out = 2, 2056 .alt = -1, 2057}; 2058 2059 2060static struct usb_device_id id_table [] = { 2061 2062 { USB_DEVICE (0x0547, 0x1002), 2063 .driver_info = (unsigned long) &hact_info, 2064 }, 2065 2066 /*-------------------------------------------------------------*/ 2067 2068 /* EZ-USB devices which download firmware to replace (or in our 2069 * case augment) the default device implementation. 2070 */ 2071 2072 /* generic EZ-USB FX controller */ 2073 { USB_DEVICE (0x0547, 0x2235), 2074 .driver_info = (unsigned long) &ez1_info, 2075 }, 2076 2077 /* CY3671 development board with EZ-USB FX */ 2078 { USB_DEVICE (0x0547, 0x0080), 2079 .driver_info = (unsigned long) &ez1_info, 2080 }, 2081 2082 /* generic EZ-USB FX2 controller (or development board) */ 2083 { USB_DEVICE (0x04b4, 0x8613), 2084 .driver_info = (unsigned long) &ez2_info, 2085 }, 2086 2087 /* re-enumerated usb test device firmware */ 2088 { USB_DEVICE (0xfff0, 0xfff0), 2089 .driver_info = (unsigned long) &fw_info, 2090 }, 2091 2092 /* "Gadget Zero" firmware runs under Linux */ 2093 { USB_DEVICE (0x0525, 0xa4a0), 2094 .driver_info = (unsigned long) &gz_info, 2095 }, 2096 2097 /* so does a user-mode variant */ 2098 { USB_DEVICE (0x0525, 0xa4a4), 2099 .driver_info = (unsigned long) &um_info, 2100 }, 2101 2102 /* ... and a user-mode variant that talks iso */ 2103 { USB_DEVICE (0x0525, 0xa4a3), 2104 .driver_info = (unsigned long) &um2_info, 2105 }, 2106 2107#ifdef KEYSPAN_19Qi 2108 /* Keyspan 19qi uses an21xx (original EZ-USB) */ 2109 // this does not coexist with the real Keyspan 19qi driver! 2110 { USB_DEVICE (0x06cd, 0x010b), 2111 .driver_info = (unsigned long) &ez1_info, 2112 }, 2113#endif 2114 2115 /*-------------------------------------------------------------*/ 2116 2117#ifdef IBOT2 2118 /* iBOT2 makes a nice source of high speed bulk-in data */ 2119 // this does not coexist with a real iBOT2 driver! 2120 { USB_DEVICE (0x0b62, 0x0059), 2121 .driver_info = (unsigned long) &ibot2_info, 2122 }, 2123#endif 2124 2125 /*-------------------------------------------------------------*/ 2126 2127#ifdef GENERIC 2128 /* module params can specify devices to use for control tests */ 2129 { .driver_info = (unsigned long) &generic_info, }, 2130#endif 2131 2132 /*-------------------------------------------------------------*/ 2133 2134 { } 2135}; 2136MODULE_DEVICE_TABLE (usb, id_table); 2137 2138static struct usb_driver usbtest_driver = { 2139 .name = "usbtest", 2140 .id_table = id_table, 2141 .probe = usbtest_probe, 2142 .ioctl = usbtest_ioctl, 2143 .disconnect = usbtest_disconnect, 2144 .suspend = usbtest_suspend, 2145 .resume = usbtest_resume, 2146}; 2147 2148/*-------------------------------------------------------------------------*/ 2149 2150static int __init usbtest_init (void) 2151{ 2152#ifdef GENERIC 2153 if (vendor) 2154 dbg ("params: vend=0x%04x prod=0x%04x", vendor, product); 2155#endif 2156 return usb_register (&usbtest_driver); 2157} 2158module_init (usbtest_init); 2159 2160static void __exit usbtest_exit (void) 2161{ 2162 usb_deregister (&usbtest_driver); 2163} 2164module_exit (usbtest_exit); 2165 2166MODULE_DESCRIPTION ("USB Core/HCD Testing Driver"); 2167MODULE_LICENSE ("GPL"); 2168