1 #include <linux/kernel.h>
2 #include <linux/errno.h>
3 #include <linux/init.h>
4 #include <linux/slab.h>
6 #include <linux/module.h>
7 #include <linux/moduleparam.h>
8 #include <linux/scatterlist.h>
9 #include <linux/mutex.h>
10 #include <linux/timer.h>
11 #include <linux/usb.h>
13 #define SIMPLE_IO_TIMEOUT 10000 /* in milliseconds */
15 /*-------------------------------------------------------------------------*/
17 static int override_alt = -1;
18 module_param_named(alt, override_alt, int, 0644);
19 MODULE_PARM_DESC(alt, ">= 0 to override altsetting selection");
21 /*-------------------------------------------------------------------------*/
23 /* FIXME make these public somewhere; usbdevfs.h? */
24 struct usbtest_param {
26 unsigned test_num; /* 0..(TEST_CASES-1) */
33 struct timeval duration;
35 #define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
37 /*-------------------------------------------------------------------------*/
39 #define GENERIC /* let probe() bind using module params */
41 /* Some devices that can be used for testing will have "real" drivers.
42 * Entries for those need to be enabled here by hand, after disabling
45 //#define IBOT2 /* grab iBOT2 webcams */
46 //#define KEYSPAN_19Qi /* grab un-renumerated serial adapter */
48 /*-------------------------------------------------------------------------*/
52 u8 ep_in; /* bulk/intr source */
53 u8 ep_out; /* bulk/intr sink */
56 unsigned iso:1; /* try iso in/out */
57 unsigned intr:1; /* try interrupt in/out */
61 /* this is accessed only through usbfs ioctl calls.
62 * one ioctl to issue a test ... one lock per device.
63 * tests create other threads if they need them.
64 * urbs and buffers are allocated dynamically,
65 * and data generated deterministically.
68 struct usb_interface *intf;
69 struct usbtest_info *info;
76 struct usb_endpoint_descriptor *iso_in, *iso_out;
77 struct usb_endpoint_descriptor *int_in, *int_out;
84 static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
86 return interface_to_usbdev(test->intf);
89 /* set up all urbs so they can be used with either bulk or interrupt */
90 #define INTERRUPT_RATE 1 /* msec/transfer */
92 #define ERROR(tdev, fmt, args...) \
93 dev_err(&(tdev)->intf->dev , fmt , ## args)
94 #define WARNING(tdev, fmt, args...) \
95 dev_warn(&(tdev)->intf->dev , fmt , ## args)
97 #define GUARD_BYTE 0xA5
99 /*-------------------------------------------------------------------------*/
102 get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
105 struct usb_host_interface *alt;
106 struct usb_host_endpoint *in, *out;
107 struct usb_host_endpoint *iso_in, *iso_out;
108 struct usb_host_endpoint *int_in, *int_out;
109 struct usb_device *udev;
111 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
115 iso_in = iso_out = NULL;
116 int_in = int_out = NULL;
117 alt = intf->altsetting + tmp;
119 if (override_alt >= 0 &&
120 override_alt != alt->desc.bAlternateSetting)
123 /* take the first altsetting with in-bulk + out-bulk;
124 * ignore other endpoints and altsettings.
126 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
127 struct usb_host_endpoint *e;
129 e = alt->endpoint + ep;
130 switch (usb_endpoint_type(&e->desc)) {
131 case USB_ENDPOINT_XFER_BULK:
133 case USB_ENDPOINT_XFER_INT:
137 case USB_ENDPOINT_XFER_ISOC:
144 if (usb_endpoint_dir_in(&e->desc)) {
153 if (usb_endpoint_dir_in(&e->desc)) {
162 if (usb_endpoint_dir_in(&e->desc)) {
170 if ((in && out) || iso_in || iso_out || int_in || int_out)
176 udev = testdev_to_usbdev(dev);
177 dev->info->alt = alt->desc.bAlternateSetting;
178 if (alt->desc.bAlternateSetting != 0) {
179 tmp = usb_set_interface(udev,
180 alt->desc.bInterfaceNumber,
181 alt->desc.bAlternateSetting);
187 dev->in_pipe = usb_rcvbulkpipe(udev,
188 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
190 dev->out_pipe = usb_sndbulkpipe(udev,
191 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
194 dev->iso_in = &iso_in->desc;
195 dev->in_iso_pipe = usb_rcvisocpipe(udev,
196 iso_in->desc.bEndpointAddress
197 & USB_ENDPOINT_NUMBER_MASK);
201 dev->iso_out = &iso_out->desc;
202 dev->out_iso_pipe = usb_sndisocpipe(udev,
203 iso_out->desc.bEndpointAddress
204 & USB_ENDPOINT_NUMBER_MASK);
208 dev->int_in = &int_in->desc;
209 dev->in_int_pipe = usb_rcvintpipe(udev,
210 int_in->desc.bEndpointAddress
211 & USB_ENDPOINT_NUMBER_MASK);
215 dev->int_out = &int_out->desc;
216 dev->out_int_pipe = usb_sndintpipe(udev,
217 int_out->desc.bEndpointAddress
218 & USB_ENDPOINT_NUMBER_MASK);
223 /*-------------------------------------------------------------------------*/
225 /* Support for testing basic non-queued I/O streams.
227 * These just package urbs as requests that can be easily canceled.
228 * Each urb's data buffer is dynamically allocated; callers can fill
229 * them with non-zero test data (or test for it) when appropriate.
232 static void simple_callback(struct urb *urb)
234 complete(urb->context);
237 static struct urb *usbtest_alloc_urb(
238 struct usb_device *udev,
241 unsigned transfer_flags,
247 urb = usb_alloc_urb(0, GFP_KERNEL);
252 usb_fill_int_urb(urb, udev, pipe, NULL, bytes, simple_callback,
255 usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback,
258 urb->interval = (udev->speed == USB_SPEED_HIGH)
259 ? (INTERRUPT_RATE << 3)
261 urb->transfer_flags = transfer_flags;
262 if (usb_pipein(pipe))
263 urb->transfer_flags |= URB_SHORT_NOT_OK;
265 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
266 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
267 GFP_KERNEL, &urb->transfer_dma);
269 urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL);
271 if (!urb->transfer_buffer) {
276 /* To test unaligned transfers add an offset and fill the
277 unused memory with a guard value */
279 memset(urb->transfer_buffer, GUARD_BYTE, offset);
280 urb->transfer_buffer += offset;
281 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
282 urb->transfer_dma += offset;
285 /* For inbound transfers use guard byte so that test fails if
286 data not correctly copied */
287 memset(urb->transfer_buffer,
288 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
293 static struct urb *simple_alloc_urb(
294 struct usb_device *udev,
299 return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0,
303 static unsigned pattern;
304 static unsigned mod_pattern;
305 module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR);
306 MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)");
308 static unsigned get_maxpacket(struct usb_device *udev, int pipe)
310 struct usb_host_endpoint *ep;
312 ep = usb_pipe_endpoint(udev, pipe);
313 return le16_to_cpup(&ep->desc.wMaxPacketSize);
316 static void simple_fill_buf(struct urb *urb)
319 u8 *buf = urb->transfer_buffer;
320 unsigned len = urb->transfer_buffer_length;
330 maxpacket = get_maxpacket(urb->dev, urb->pipe);
331 for (i = 0; i < len; i++)
332 *buf++ = (u8) ((i % maxpacket) % 63);
337 static inline unsigned long buffer_offset(void *buf)
339 return (unsigned long)buf & (ARCH_KMALLOC_MINALIGN - 1);
342 static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb)
344 u8 *buf = urb->transfer_buffer;
345 u8 *guard = buf - buffer_offset(buf);
348 for (i = 0; guard < buf; i++, guard++) {
349 if (*guard != GUARD_BYTE) {
350 ERROR(tdev, "guard byte[%d] %d (not %d)\n",
351 i, *guard, GUARD_BYTE);
358 static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
362 u8 *buf = urb->transfer_buffer;
363 unsigned len = urb->actual_length;
364 unsigned maxpacket = get_maxpacket(urb->dev, urb->pipe);
366 int ret = check_guard_bytes(tdev, urb);
370 for (i = 0; i < len; i++, buf++) {
372 /* all-zeroes has no synchronization issues */
376 /* mod63 stays in sync with short-terminated transfers,
377 * or otherwise when host and gadget agree on how large
378 * each usb transfer request should be. resync is done
379 * with set_interface or set_config.
382 expected = (i % maxpacket) % 63;
384 /* always fail unsupported patterns */
389 if (*buf == expected)
391 ERROR(tdev, "buf[%d] = %d (not %d)\n", i, *buf, expected);
397 static void simple_free_urb(struct urb *urb)
399 unsigned long offset = buffer_offset(urb->transfer_buffer);
401 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
404 urb->transfer_buffer_length + offset,
405 urb->transfer_buffer - offset,
406 urb->transfer_dma - offset);
408 kfree(urb->transfer_buffer - offset);
412 static int simple_io(
413 struct usbtest_dev *tdev,
421 struct usb_device *udev = urb->dev;
422 int max = urb->transfer_buffer_length;
423 struct completion completion;
425 unsigned long expire;
427 urb->context = &completion;
428 while (retval == 0 && iterations-- > 0) {
429 init_completion(&completion);
430 if (usb_pipeout(urb->pipe)) {
431 simple_fill_buf(urb);
432 urb->transfer_flags |= URB_ZERO_PACKET;
434 retval = usb_submit_urb(urb, GFP_KERNEL);
438 expire = msecs_to_jiffies(SIMPLE_IO_TIMEOUT);
439 if (!wait_for_completion_timeout(&completion, expire)) {
441 retval = (urb->status == -ENOENT ?
442 -ETIMEDOUT : urb->status);
444 retval = urb->status;
448 if (retval == 0 && usb_pipein(urb->pipe))
449 retval = simple_check_buf(tdev, urb);
452 int len = urb->transfer_buffer_length;
457 len = (vary < max) ? vary : max;
458 urb->transfer_buffer_length = len;
461 /* FIXME if endpoint halted, clear halt (and log) */
463 urb->transfer_buffer_length = max;
465 if (expected != retval)
467 "%s failed, iterations left %d, status %d (not %d)\n",
468 label, iterations, retval, expected);
473 /*-------------------------------------------------------------------------*/
475 /* We use scatterlist primitives to test queued I/O.
476 * Yes, this also tests the scatterlist primitives.
479 static void free_sglist(struct scatterlist *sg, int nents)
485 for (i = 0; i < nents; i++) {
486 if (!sg_page(&sg[i]))
488 kfree(sg_virt(&sg[i]));
493 static struct scatterlist *
494 alloc_sglist(int nents, int max, int vary, struct usbtest_dev *dev, int pipe)
496 struct scatterlist *sg;
497 unsigned int n_size = 0;
501 get_maxpacket(interface_to_usbdev(dev->intf), pipe);
506 sg = kmalloc_array(nents, sizeof(*sg), GFP_KERNEL);
509 sg_init_table(sg, nents);
511 for (i = 0; i < nents; i++) {
515 buf = kzalloc(size, GFP_KERNEL);
521 /* kmalloc pages are always physically contiguous! */
522 sg_set_buf(&sg[i], buf, size);
529 for (j = 0; j < size; j++)
530 *buf++ = (u8) (((j + n_size) % maxpacket) % 63);
539 size = (vary < max) ? vary : max;
546 static void sg_timeout(unsigned long _req)
548 struct usb_sg_request *req = (struct usb_sg_request *) _req;
553 static int perform_sglist(
554 struct usbtest_dev *tdev,
557 struct usb_sg_request *req,
558 struct scatterlist *sg,
562 struct usb_device *udev = testdev_to_usbdev(tdev);
564 struct timer_list sg_timer;
566 setup_timer_on_stack(&sg_timer, sg_timeout, (unsigned long) req);
568 while (retval == 0 && iterations-- > 0) {
569 retval = usb_sg_init(req, udev, pipe,
570 (udev->speed == USB_SPEED_HIGH)
571 ? (INTERRUPT_RATE << 3)
573 sg, nents, 0, GFP_KERNEL);
577 mod_timer(&sg_timer, jiffies +
578 msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
580 if (!del_timer_sync(&sg_timer))
583 retval = req->status;
585 /* FIXME check resulting data pattern */
587 /* FIXME if endpoint halted, clear halt (and log) */
590 /* FIXME for unlink or fault handling tests, don't report
591 * failure if retval is as we expected ...
594 ERROR(tdev, "perform_sglist failed, "
595 "iterations left %d, status %d\n",
601 /*-------------------------------------------------------------------------*/
603 /* unqueued control message testing
605 * there's a nice set of device functional requirements in chapter 9 of the
606 * usb 2.0 spec, which we can apply to ANY device, even ones that don't use
607 * special test firmware.
609 * we know the device is configured (or suspended) by the time it's visible
610 * through usbfs. we can't change that, so we won't test enumeration (which
611 * worked 'well enough' to get here, this time), power management (ditto),
612 * or remote wakeup (which needs human interaction).
615 static unsigned realworld = 1;
616 module_param(realworld, uint, 0);
617 MODULE_PARM_DESC(realworld, "clear to demand stricter spec compliance");
619 static int get_altsetting(struct usbtest_dev *dev)
621 struct usb_interface *iface = dev->intf;
622 struct usb_device *udev = interface_to_usbdev(iface);
625 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
626 USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE,
627 0, iface->altsetting[0].desc.bInterfaceNumber,
628 dev->buf, 1, USB_CTRL_GET_TIMEOUT);
640 static int set_altsetting(struct usbtest_dev *dev, int alternate)
642 struct usb_interface *iface = dev->intf;
643 struct usb_device *udev;
645 if (alternate < 0 || alternate >= 256)
648 udev = interface_to_usbdev(iface);
649 return usb_set_interface(udev,
650 iface->altsetting[0].desc.bInterfaceNumber,
654 static int is_good_config(struct usbtest_dev *tdev, int len)
656 struct usb_config_descriptor *config;
658 if (len < sizeof(*config))
660 config = (struct usb_config_descriptor *) tdev->buf;
662 switch (config->bDescriptorType) {
664 case USB_DT_OTHER_SPEED_CONFIG:
665 if (config->bLength != 9) {
666 ERROR(tdev, "bogus config descriptor length\n");
669 /* this bit 'must be 1' but often isn't */
670 if (!realworld && !(config->bmAttributes & 0x80)) {
671 ERROR(tdev, "high bit of config attributes not set\n");
674 if (config->bmAttributes & 0x1f) { /* reserved == 0 */
675 ERROR(tdev, "reserved config bits set\n");
683 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */
685 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */
687 ERROR(tdev, "bogus config descriptor read size\n");
691 static int is_good_ext(struct usbtest_dev *tdev, u8 *buf)
693 struct usb_ext_cap_descriptor *ext;
696 ext = (struct usb_ext_cap_descriptor *) buf;
698 if (ext->bLength != USB_DT_USB_EXT_CAP_SIZE) {
699 ERROR(tdev, "bogus usb 2.0 extension descriptor length\n");
703 attr = le32_to_cpu(ext->bmAttributes);
704 /* bits[1:15] is used and others are reserved */
705 if (attr & ~0xfffe) { /* reserved == 0 */
706 ERROR(tdev, "reserved bits set\n");
713 static int is_good_ss_cap(struct usbtest_dev *tdev, u8 *buf)
715 struct usb_ss_cap_descriptor *ss;
717 ss = (struct usb_ss_cap_descriptor *) buf;
719 if (ss->bLength != USB_DT_USB_SS_CAP_SIZE) {
720 ERROR(tdev, "bogus superspeed device capability descriptor length\n");
725 * only bit[1] of bmAttributes is used for LTM and others are
728 if (ss->bmAttributes & ~0x02) { /* reserved == 0 */
729 ERROR(tdev, "reserved bits set in bmAttributes\n");
733 /* bits[0:3] of wSpeedSupported is used and others are reserved */
734 if (le16_to_cpu(ss->wSpeedSupported) & ~0x0f) { /* reserved == 0 */
735 ERROR(tdev, "reserved bits set in wSpeedSupported\n");
742 static int is_good_con_id(struct usbtest_dev *tdev, u8 *buf)
744 struct usb_ss_container_id_descriptor *con_id;
746 con_id = (struct usb_ss_container_id_descriptor *) buf;
748 if (con_id->bLength != USB_DT_USB_SS_CONTN_ID_SIZE) {
749 ERROR(tdev, "bogus container id descriptor length\n");
753 if (con_id->bReserved) { /* reserved == 0 */
754 ERROR(tdev, "reserved bits set\n");
761 /* sanity test for standard requests working with usb_control_mesg() and some
762 * of the utility functions which use it.
764 * this doesn't test how endpoint halts behave or data toggles get set, since
765 * we won't do I/O to bulk/interrupt endpoints here (which is how to change
766 * halt or toggle). toggle testing is impractical without support from hcds.
768 * this avoids failing devices linux would normally work with, by not testing
769 * config/altsetting operations for devices that only support their defaults.
770 * such devices rarely support those needless operations.
772 * NOTE that since this is a sanity test, it's not examining boundary cases
773 * to see if usbcore, hcd, and device all behave right. such testing would
774 * involve varied read sizes and other operation sequences.
776 static int ch9_postconfig(struct usbtest_dev *dev)
778 struct usb_interface *iface = dev->intf;
779 struct usb_device *udev = interface_to_usbdev(iface);
782 /* [9.2.3] if there's more than one altsetting, we need to be able to
783 * set and get each one. mostly trusts the descriptors from usbcore.
785 for (i = 0; i < iface->num_altsetting; i++) {
787 /* 9.2.3 constrains the range here */
788 alt = iface->altsetting[i].desc.bAlternateSetting;
789 if (alt < 0 || alt >= iface->num_altsetting) {
791 "invalid alt [%d].bAltSetting = %d\n",
795 /* [real world] get/set unimplemented if there's only one */
796 if (realworld && iface->num_altsetting == 1)
799 /* [9.4.10] set_interface */
800 retval = set_altsetting(dev, alt);
802 dev_err(&iface->dev, "can't set_interface = %d, %d\n",
807 /* [9.4.4] get_interface always works */
808 retval = get_altsetting(dev);
810 dev_err(&iface->dev, "get alt should be %d, was %d\n",
812 return (retval < 0) ? retval : -EDOM;
817 /* [real world] get_config unimplemented if there's only one */
818 if (!realworld || udev->descriptor.bNumConfigurations != 1) {
819 int expected = udev->actconfig->desc.bConfigurationValue;
821 /* [9.4.2] get_configuration always works
822 * ... although some cheap devices (like one TI Hub I've got)
823 * won't return config descriptors except before set_config.
825 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
826 USB_REQ_GET_CONFIGURATION,
827 USB_DIR_IN | USB_RECIP_DEVICE,
828 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
829 if (retval != 1 || dev->buf[0] != expected) {
830 dev_err(&iface->dev, "get config --> %d %d (1 %d)\n",
831 retval, dev->buf[0], expected);
832 return (retval < 0) ? retval : -EDOM;
836 /* there's always [9.4.3] a device descriptor [9.6.1] */
837 retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0,
838 dev->buf, sizeof(udev->descriptor));
839 if (retval != sizeof(udev->descriptor)) {
840 dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
841 return (retval < 0) ? retval : -EDOM;
845 * there's always [9.4.3] a bos device descriptor [9.6.2] in USB
848 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0210) {
849 struct usb_bos_descriptor *bos = NULL;
850 struct usb_dev_cap_header *header = NULL;
851 unsigned total, num, length;
854 retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf,
855 sizeof(*udev->bos->desc));
856 if (retval != sizeof(*udev->bos->desc)) {
857 dev_err(&iface->dev, "bos descriptor --> %d\n", retval);
858 return (retval < 0) ? retval : -EDOM;
861 bos = (struct usb_bos_descriptor *)dev->buf;
862 total = le16_to_cpu(bos->wTotalLength);
863 num = bos->bNumDeviceCaps;
865 if (total > TBUF_SIZE)
869 * get generic device-level capability descriptors [9.6.2]
872 retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf,
874 if (retval != total) {
875 dev_err(&iface->dev, "bos descriptor set --> %d\n",
877 return (retval < 0) ? retval : -EDOM;
880 length = sizeof(*udev->bos->desc);
882 for (i = 0; i < num; i++) {
884 if (buf + sizeof(struct usb_dev_cap_header) >
888 header = (struct usb_dev_cap_header *)buf;
889 length = header->bLength;
891 if (header->bDescriptorType !=
892 USB_DT_DEVICE_CAPABILITY) {
893 dev_warn(&udev->dev, "not device capability descriptor, skip\n");
897 switch (header->bDevCapabilityType) {
898 case USB_CAP_TYPE_EXT:
899 if (buf + USB_DT_USB_EXT_CAP_SIZE >
901 !is_good_ext(dev, buf)) {
902 dev_err(&iface->dev, "bogus usb 2.0 extension descriptor\n");
906 case USB_SS_CAP_TYPE:
907 if (buf + USB_DT_USB_SS_CAP_SIZE >
909 !is_good_ss_cap(dev, buf)) {
910 dev_err(&iface->dev, "bogus superspeed device capability descriptor\n");
914 case CONTAINER_ID_TYPE:
915 if (buf + USB_DT_USB_SS_CONTN_ID_SIZE >
917 !is_good_con_id(dev, buf)) {
918 dev_err(&iface->dev, "bogus container id descriptor\n");
928 /* there's always [9.4.3] at least one config descriptor [9.6.3] */
929 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
930 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i,
931 dev->buf, TBUF_SIZE);
932 if (!is_good_config(dev, retval)) {
934 "config [%d] descriptor --> %d\n",
936 return (retval < 0) ? retval : -EDOM;
939 /* FIXME cross-checking udev->config[i] to make sure usbcore
940 * parsed it right (etc) would be good testing paranoia
944 /* and sometimes [9.2.6.6] speed dependent descriptors */
945 if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) {
946 struct usb_qualifier_descriptor *d = NULL;
948 /* device qualifier [9.6.2] */
949 retval = usb_get_descriptor(udev,
950 USB_DT_DEVICE_QUALIFIER, 0, dev->buf,
951 sizeof(struct usb_qualifier_descriptor));
952 if (retval == -EPIPE) {
953 if (udev->speed == USB_SPEED_HIGH) {
955 "hs dev qualifier --> %d\n",
957 return (retval < 0) ? retval : -EDOM;
959 /* usb2.0 but not high-speed capable; fine */
960 } else if (retval != sizeof(struct usb_qualifier_descriptor)) {
961 dev_err(&iface->dev, "dev qualifier --> %d\n", retval);
962 return (retval < 0) ? retval : -EDOM;
964 d = (struct usb_qualifier_descriptor *) dev->buf;
966 /* might not have [9.6.2] any other-speed configs [9.6.4] */
968 unsigned max = d->bNumConfigurations;
969 for (i = 0; i < max; i++) {
970 retval = usb_get_descriptor(udev,
971 USB_DT_OTHER_SPEED_CONFIG, i,
972 dev->buf, TBUF_SIZE);
973 if (!is_good_config(dev, retval)) {
975 "other speed config --> %d\n",
977 return (retval < 0) ? retval : -EDOM;
982 /* FIXME fetch strings from at least the device descriptor */
984 /* [9.4.5] get_status always works */
985 retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
987 dev_err(&iface->dev, "get dev status --> %d\n", retval);
991 /* FIXME configuration.bmAttributes says if we could try to set/clear
992 * the device's remote wakeup feature ... if we can, test that here
995 retval = usb_get_status(udev, USB_RECIP_INTERFACE,
996 iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
998 dev_err(&iface->dev, "get interface status --> %d\n", retval);
1001 /* FIXME get status for each endpoint in the interface */
1006 /*-------------------------------------------------------------------------*/
1008 /* use ch9 requests to test whether:
1009 * (a) queues work for control, keeping N subtests queued and
1010 * active (auto-resubmit) for M loops through the queue.
1011 * (b) protocol stalls (control-only) will autorecover.
1012 * it's not like bulk/intr; no halt clearing.
1013 * (c) short control reads are reported and handled.
1014 * (d) queues are always processed in-order
1019 struct usbtest_dev *dev;
1020 struct completion complete;
1025 struct usbtest_param *param;
1029 #define NUM_SUBCASES 16 /* how many test subcases here? */
1032 struct usb_ctrlrequest setup;
1037 static void ctrl_complete(struct urb *urb)
1039 struct ctrl_ctx *ctx = urb->context;
1040 struct usb_ctrlrequest *reqp;
1041 struct subcase *subcase;
1042 int status = urb->status;
1044 reqp = (struct usb_ctrlrequest *)urb->setup_packet;
1045 subcase = container_of(reqp, struct subcase, setup);
1047 spin_lock(&ctx->lock);
1051 /* queue must transfer and complete in fifo order, unless
1052 * usb_unlink_urb() is used to unlink something not at the
1053 * physical queue head (not tested).
1055 if (subcase->number > 0) {
1056 if ((subcase->number - ctx->last) != 1) {
1058 "subcase %d completed out of order, last %d\n",
1059 subcase->number, ctx->last);
1061 ctx->last = subcase->number;
1065 ctx->last = subcase->number;
1067 /* succeed or fault in only one way? */
1068 if (status == subcase->expected)
1071 /* async unlink for cleanup? */
1072 else if (status != -ECONNRESET) {
1074 /* some faults are allowed, not required */
1075 if (subcase->expected > 0 && (
1076 ((status == -subcase->expected /* happened */
1077 || status == 0)))) /* didn't */
1079 /* sometimes more than one fault is allowed */
1080 else if (subcase->number == 12 && status == -EPIPE)
1083 ERROR(ctx->dev, "subtest %d error, status %d\n",
1084 subcase->number, status);
1087 /* unexpected status codes mean errors; ideally, in hardware */
1090 if (ctx->status == 0) {
1093 ctx->status = status;
1094 ERROR(ctx->dev, "control queue %02x.%02x, err %d, "
1095 "%d left, subcase %d, len %d/%d\n",
1096 reqp->bRequestType, reqp->bRequest,
1097 status, ctx->count, subcase->number,
1099 urb->transfer_buffer_length);
1101 /* FIXME this "unlink everything" exit route should
1102 * be a separate test case.
1105 /* unlink whatever's still pending */
1106 for (i = 1; i < ctx->param->sglen; i++) {
1107 struct urb *u = ctx->urb[
1108 (i + subcase->number)
1109 % ctx->param->sglen];
1111 if (u == urb || !u->dev)
1113 spin_unlock(&ctx->lock);
1114 status = usb_unlink_urb(u);
1115 spin_lock(&ctx->lock);
1122 ERROR(ctx->dev, "urb unlink --> %d\n",
1126 status = ctx->status;
1130 /* resubmit if we need to, else mark this as done */
1131 if ((status == 0) && (ctx->pending < ctx->count)) {
1132 status = usb_submit_urb(urb, GFP_ATOMIC);
1135 "can't resubmit ctrl %02x.%02x, err %d\n",
1136 reqp->bRequestType, reqp->bRequest, status);
1143 /* signal completion when nothing's queued */
1144 if (ctx->pending == 0)
1145 complete(&ctx->complete);
1146 spin_unlock(&ctx->lock);
1150 test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
1152 struct usb_device *udev = testdev_to_usbdev(dev);
1154 struct ctrl_ctx context;
1157 if (param->sglen == 0 || param->iterations > UINT_MAX / param->sglen)
1160 spin_lock_init(&context.lock);
1162 init_completion(&context.complete);
1163 context.count = param->sglen * param->iterations;
1164 context.pending = 0;
1165 context.status = -ENOMEM;
1166 context.param = param;
1169 /* allocate and init the urbs we'll queue.
1170 * as with bulk/intr sglists, sglen is the queue depth; it also
1171 * controls which subtests run (more tests than sglen) or rerun.
1173 urb = kcalloc(param->sglen, sizeof(struct urb *), GFP_KERNEL);
1176 for (i = 0; i < param->sglen; i++) {
1177 int pipe = usb_rcvctrlpipe(udev, 0);
1180 struct usb_ctrlrequest req;
1181 struct subcase *reqp;
1183 /* sign of this variable means:
1184 * -: tested code must return this (negative) error code
1185 * +: tested code may return this (negative too) error code
1189 /* requests here are mostly expected to succeed on any
1190 * device, but some are chosen to trigger protocol stalls
1193 memset(&req, 0, sizeof(req));
1194 req.bRequest = USB_REQ_GET_DESCRIPTOR;
1195 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
1197 switch (i % NUM_SUBCASES) {
1198 case 0: /* get device descriptor */
1199 req.wValue = cpu_to_le16(USB_DT_DEVICE << 8);
1200 len = sizeof(struct usb_device_descriptor);
1202 case 1: /* get first config descriptor (only) */
1203 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
1204 len = sizeof(struct usb_config_descriptor);
1206 case 2: /* get altsetting (OFTEN STALLS) */
1207 req.bRequest = USB_REQ_GET_INTERFACE;
1208 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
1209 /* index = 0 means first interface */
1213 case 3: /* get interface status */
1214 req.bRequest = USB_REQ_GET_STATUS;
1215 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
1219 case 4: /* get device status */
1220 req.bRequest = USB_REQ_GET_STATUS;
1221 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
1224 case 5: /* get device qualifier (MAY STALL) */
1225 req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8);
1226 len = sizeof(struct usb_qualifier_descriptor);
1227 if (udev->speed != USB_SPEED_HIGH)
1230 case 6: /* get first config descriptor, plus interface */
1231 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
1232 len = sizeof(struct usb_config_descriptor);
1233 len += sizeof(struct usb_interface_descriptor);
1235 case 7: /* get interface descriptor (ALWAYS STALLS) */
1236 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8);
1237 /* interface == 0 */
1238 len = sizeof(struct usb_interface_descriptor);
1241 /* NOTE: two consecutive stalls in the queue here.
1242 * that tests fault recovery a bit more aggressively. */
1243 case 8: /* clear endpoint halt (MAY STALL) */
1244 req.bRequest = USB_REQ_CLEAR_FEATURE;
1245 req.bRequestType = USB_RECIP_ENDPOINT;
1246 /* wValue 0 == ep halt */
1247 /* wIndex 0 == ep0 (shouldn't halt!) */
1249 pipe = usb_sndctrlpipe(udev, 0);
1252 case 9: /* get endpoint status */
1253 req.bRequest = USB_REQ_GET_STATUS;
1254 req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT;
1258 case 10: /* trigger short read (EREMOTEIO) */
1259 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
1261 expected = -EREMOTEIO;
1263 /* NOTE: two consecutive _different_ faults in the queue. */
1264 case 11: /* get endpoint descriptor (ALWAYS STALLS) */
1265 req.wValue = cpu_to_le16(USB_DT_ENDPOINT << 8);
1267 len = sizeof(struct usb_interface_descriptor);
1270 /* NOTE: sometimes even a third fault in the queue! */
1271 case 12: /* get string 0 descriptor (MAY STALL) */
1272 req.wValue = cpu_to_le16(USB_DT_STRING << 8);
1273 /* string == 0, for language IDs */
1274 len = sizeof(struct usb_interface_descriptor);
1275 /* may succeed when > 4 languages */
1276 expected = EREMOTEIO; /* or EPIPE, if no strings */
1278 case 13: /* short read, resembling case 10 */
1279 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
1280 /* last data packet "should" be DATA1, not DATA0 */
1281 if (udev->speed == USB_SPEED_SUPER)
1284 len = 1024 - udev->descriptor.bMaxPacketSize0;
1285 expected = -EREMOTEIO;
1287 case 14: /* short read; try to fill the last packet */
1288 req.wValue = cpu_to_le16((USB_DT_DEVICE << 8) | 0);
1289 /* device descriptor size == 18 bytes */
1290 len = udev->descriptor.bMaxPacketSize0;
1291 if (udev->speed == USB_SPEED_SUPER)
1301 expected = -EREMOTEIO;
1304 req.wValue = cpu_to_le16(USB_DT_BOS << 8);
1306 len = le16_to_cpu(udev->bos->desc->wTotalLength);
1308 len = sizeof(struct usb_bos_descriptor);
1309 if (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0201)
1313 ERROR(dev, "bogus number of ctrl queue testcases!\n");
1314 context.status = -EINVAL;
1317 req.wLength = cpu_to_le16(len);
1318 urb[i] = u = simple_alloc_urb(udev, pipe, len, 0);
1322 reqp = kmalloc(sizeof(*reqp), GFP_KERNEL);
1326 reqp->number = i % NUM_SUBCASES;
1327 reqp->expected = expected;
1328 u->setup_packet = (char *) &reqp->setup;
1330 u->context = &context;
1331 u->complete = ctrl_complete;
1334 /* queue the urbs */
1336 spin_lock_irq(&context.lock);
1337 for (i = 0; i < param->sglen; i++) {
1338 context.status = usb_submit_urb(urb[i], GFP_ATOMIC);
1339 if (context.status != 0) {
1340 ERROR(dev, "can't submit urb[%d], status %d\n",
1342 context.count = context.pending;
1347 spin_unlock_irq(&context.lock);
1349 /* FIXME set timer and time out; provide a disconnect hook */
1351 /* wait for the last one to complete */
1352 if (context.pending > 0)
1353 wait_for_completion(&context.complete);
1356 for (i = 0; i < param->sglen; i++) {
1360 kfree(urb[i]->setup_packet);
1361 simple_free_urb(urb[i]);
1364 return context.status;
1369 /*-------------------------------------------------------------------------*/
1371 static void unlink1_callback(struct urb *urb)
1373 int status = urb->status;
1375 /* we "know" -EPIPE (stall) never happens */
1377 status = usb_submit_urb(urb, GFP_ATOMIC);
1379 urb->status = status;
1380 complete(urb->context);
1384 static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async)
1387 struct completion completion;
1390 init_completion(&completion);
1391 urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size, 0);
1394 urb->context = &completion;
1395 urb->complete = unlink1_callback;
1397 if (usb_pipeout(urb->pipe)) {
1398 simple_fill_buf(urb);
1399 urb->transfer_flags |= URB_ZERO_PACKET;
1402 /* keep the endpoint busy. there are lots of hc/hcd-internal
1403 * states, and testing should get to all of them over time.
1405 * FIXME want additional tests for when endpoint is STALLing
1406 * due to errors, or is just NAKing requests.
1408 retval = usb_submit_urb(urb, GFP_KERNEL);
1410 dev_err(&dev->intf->dev, "submit fail %d\n", retval);
1414 /* unlinking that should always work. variable delay tests more
1415 * hcd states and code paths, even with little other system load.
1417 msleep(jiffies % (2 * INTERRUPT_RATE));
1419 while (!completion_done(&completion)) {
1420 retval = usb_unlink_urb(urb);
1422 if (retval == 0 && usb_pipein(urb->pipe))
1423 retval = simple_check_buf(dev, urb);
1428 /* we can't unlink urbs while they're completing
1429 * or if they've completed, and we haven't
1430 * resubmitted. "normal" drivers would prevent
1431 * resubmission, but since we're testing unlink
1434 ERROR(dev, "unlink retry\n");
1441 dev_err(&dev->intf->dev,
1442 "unlink fail %d\n", retval);
1451 wait_for_completion(&completion);
1452 retval = urb->status;
1453 simple_free_urb(urb);
1456 return (retval == -ECONNRESET) ? 0 : retval - 1000;
1458 return (retval == -ENOENT || retval == -EPERM) ?
1462 static int unlink_simple(struct usbtest_dev *dev, int pipe, int len)
1466 /* test sync and async paths */
1467 retval = unlink1(dev, pipe, len, 1);
1469 retval = unlink1(dev, pipe, len, 0);
1473 /*-------------------------------------------------------------------------*/
1476 struct completion complete;
1483 static void unlink_queued_callback(struct urb *urb)
1485 int status = urb->status;
1486 struct queued_ctx *ctx = urb->context;
1490 if (urb == ctx->urbs[ctx->num - 4] || urb == ctx->urbs[ctx->num - 2]) {
1491 if (status == -ECONNRESET)
1493 /* What error should we report if the URB completed normally? */
1496 ctx->status = status;
1499 if (atomic_dec_and_test(&ctx->pending))
1500 complete(&ctx->complete);
1503 static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num,
1506 struct queued_ctx ctx;
1507 struct usb_device *udev = testdev_to_usbdev(dev);
1511 int retval = -ENOMEM;
1513 init_completion(&ctx.complete);
1514 atomic_set(&ctx.pending, 1); /* One more than the actual value */
1518 buf = usb_alloc_coherent(udev, size, GFP_KERNEL, &buf_dma);
1521 memset(buf, 0, size);
1523 /* Allocate and init the urbs we'll queue */
1524 ctx.urbs = kcalloc(num, sizeof(struct urb *), GFP_KERNEL);
1527 for (i = 0; i < num; i++) {
1528 ctx.urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1531 usb_fill_bulk_urb(ctx.urbs[i], udev, pipe, buf, size,
1532 unlink_queued_callback, &ctx);
1533 ctx.urbs[i]->transfer_dma = buf_dma;
1534 ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1536 if (usb_pipeout(ctx.urbs[i]->pipe)) {
1537 simple_fill_buf(ctx.urbs[i]);
1538 ctx.urbs[i]->transfer_flags |= URB_ZERO_PACKET;
1542 /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */
1543 for (i = 0; i < num; i++) {
1544 atomic_inc(&ctx.pending);
1545 retval = usb_submit_urb(ctx.urbs[i], GFP_KERNEL);
1547 dev_err(&dev->intf->dev, "submit urbs[%d] fail %d\n",
1549 atomic_dec(&ctx.pending);
1550 ctx.status = retval;
1555 usb_unlink_urb(ctx.urbs[num - 4]);
1556 usb_unlink_urb(ctx.urbs[num - 2]);
1559 usb_unlink_urb(ctx.urbs[i]);
1562 if (atomic_dec_and_test(&ctx.pending)) /* The extra count */
1563 complete(&ctx.complete);
1564 wait_for_completion(&ctx.complete);
1565 retval = ctx.status;
1568 for (i = 0; i < num; i++)
1569 usb_free_urb(ctx.urbs[i]);
1572 usb_free_coherent(udev, size, buf, buf_dma);
1576 /*-------------------------------------------------------------------------*/
1578 static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1583 /* shouldn't look or act halted */
1584 retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
1586 ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n",
1591 ERROR(tdev, "ep %02x bogus status: %04x != 0\n", ep, status);
1594 retval = simple_io(tdev, urb, 1, 0, 0, __func__);
1600 static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1605 /* should look and act halted */
1606 retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
1608 ERROR(tdev, "ep %02x couldn't get halt status, %d\n",
1613 ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status);
1616 retval = simple_io(tdev, urb, 1, 0, -EPIPE, __func__);
1617 if (retval != -EPIPE)
1619 retval = simple_io(tdev, urb, 1, 0, -EPIPE, "verify_still_halted");
1620 if (retval != -EPIPE)
1625 static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
1629 /* shouldn't look or act halted now */
1630 retval = verify_not_halted(tdev, ep, urb);
1634 /* set halt (protocol test only), verify it worked */
1635 retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0),
1636 USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT,
1637 USB_ENDPOINT_HALT, ep,
1638 NULL, 0, USB_CTRL_SET_TIMEOUT);
1640 ERROR(tdev, "ep %02x couldn't set halt, %d\n", ep, retval);
1643 retval = verify_halted(tdev, ep, urb);
1647 /* clear halt anyways, else further tests will fail */
1648 ret = usb_clear_halt(urb->dev, urb->pipe);
1650 ERROR(tdev, "ep %02x couldn't clear halt, %d\n",
1656 /* clear halt (tests API + protocol), verify it worked */
1657 retval = usb_clear_halt(urb->dev, urb->pipe);
1659 ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval);
1662 retval = verify_not_halted(tdev, ep, urb);
1666 /* NOTE: could also verify SET_INTERFACE clear halts ... */
1671 static int halt_simple(struct usbtest_dev *dev)
1676 struct usb_device *udev = testdev_to_usbdev(dev);
1678 if (udev->speed == USB_SPEED_SUPER)
1679 urb = simple_alloc_urb(udev, 0, 1024, 0);
1681 urb = simple_alloc_urb(udev, 0, 512, 0);
1686 ep = usb_pipeendpoint(dev->in_pipe) | USB_DIR_IN;
1687 urb->pipe = dev->in_pipe;
1688 retval = test_halt(dev, ep, urb);
1693 if (dev->out_pipe) {
1694 ep = usb_pipeendpoint(dev->out_pipe);
1695 urb->pipe = dev->out_pipe;
1696 retval = test_halt(dev, ep, urb);
1699 simple_free_urb(urb);
1703 /*-------------------------------------------------------------------------*/
1705 /* Control OUT tests use the vendor control requests from Intel's
1706 * USB 2.0 compliance test device: write a buffer, read it back.
1708 * Intel's spec only _requires_ that it work for one packet, which
1709 * is pretty weak. Some HCDs place limits here; most devices will
1710 * need to be able to handle more than one OUT data packet. We'll
1711 * try whatever we're told to try.
1713 static int ctrl_out(struct usbtest_dev *dev,
1714 unsigned count, unsigned length, unsigned vary, unsigned offset)
1720 struct usb_device *udev;
1722 if (length < 1 || length > 0xffff || vary >= length)
1725 buf = kmalloc(length + offset, GFP_KERNEL);
1730 udev = testdev_to_usbdev(dev);
1734 /* NOTE: hardware might well act differently if we pushed it
1735 * with lots back-to-back queued requests.
1737 for (i = 0; i < count; i++) {
1738 /* write patterned data */
1739 for (j = 0; j < len; j++)
1741 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1742 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR,
1743 0, 0, buf, len, USB_CTRL_SET_TIMEOUT);
1744 if (retval != len) {
1747 ERROR(dev, "ctrl_out, wlen %d (expected %d)\n",
1754 /* read it back -- assuming nothing intervened!! */
1755 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1756 0x5c, USB_DIR_IN|USB_TYPE_VENDOR,
1757 0, 0, buf, len, USB_CTRL_GET_TIMEOUT);
1758 if (retval != len) {
1761 ERROR(dev, "ctrl_out, rlen %d (expected %d)\n",
1768 /* fail if we can't verify */
1769 for (j = 0; j < len; j++) {
1770 if (buf[j] != (u8) (i + j)) {
1771 ERROR(dev, "ctrl_out, byte %d is %d not %d\n",
1772 j, buf[j], (u8) i + j);
1784 /* [real world] the "zero bytes IN" case isn't really used.
1785 * hardware can easily trip up in this weird case, since its
1786 * status stage is IN, not OUT like other ep0in transfers.
1789 len = realworld ? 1 : 0;
1793 ERROR(dev, "ctrl_out %s failed, code %d, count %d\n",
1796 kfree(buf - offset);
1800 /*-------------------------------------------------------------------------*/
1802 /* ISO tests ... mimics common usage
1803 * - buffer length is split into N packets (mostly maxpacket sized)
1804 * - multi-buffers according to sglen
1807 struct iso_context {
1811 struct completion done;
1813 unsigned long errors;
1814 unsigned long packet_count;
1815 struct usbtest_dev *dev;
1818 static void iso_callback(struct urb *urb)
1820 struct iso_context *ctx = urb->context;
1822 spin_lock(&ctx->lock);
1825 ctx->packet_count += urb->number_of_packets;
1826 if (urb->error_count > 0)
1827 ctx->errors += urb->error_count;
1828 else if (urb->status != 0)
1829 ctx->errors += urb->number_of_packets;
1830 else if (urb->actual_length != urb->transfer_buffer_length)
1832 else if (check_guard_bytes(ctx->dev, urb) != 0)
1835 if (urb->status == 0 && ctx->count > (ctx->pending - 1)
1836 && !ctx->submit_error) {
1837 int status = usb_submit_urb(urb, GFP_ATOMIC);
1842 dev_err(&ctx->dev->intf->dev,
1843 "iso resubmit err %d\n",
1846 case -ENODEV: /* disconnected */
1847 case -ESHUTDOWN: /* endpoint disabled */
1848 ctx->submit_error = 1;
1854 if (ctx->pending == 0) {
1856 dev_err(&ctx->dev->intf->dev,
1857 "iso test, %lu errors out of %lu\n",
1858 ctx->errors, ctx->packet_count);
1859 complete(&ctx->done);
1862 spin_unlock(&ctx->lock);
1865 static struct urb *iso_alloc_urb(
1866 struct usb_device *udev,
1868 struct usb_endpoint_descriptor *desc,
1874 unsigned i, maxp, packets;
1876 if (bytes < 0 || !desc)
1878 maxp = 0x7ff & usb_endpoint_maxp(desc);
1879 maxp *= 1 + (0x3 & (usb_endpoint_maxp(desc) >> 11));
1880 packets = DIV_ROUND_UP(bytes, maxp);
1882 urb = usb_alloc_urb(packets, GFP_KERNEL);
1888 urb->number_of_packets = packets;
1889 urb->transfer_buffer_length = bytes;
1890 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
1892 &urb->transfer_dma);
1893 if (!urb->transfer_buffer) {
1898 memset(urb->transfer_buffer, GUARD_BYTE, offset);
1899 urb->transfer_buffer += offset;
1900 urb->transfer_dma += offset;
1902 /* For inbound transfers use guard byte so that test fails if
1903 data not correctly copied */
1904 memset(urb->transfer_buffer,
1905 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
1908 for (i = 0; i < packets; i++) {
1909 /* here, only the last packet will be short */
1910 urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp);
1911 bytes -= urb->iso_frame_desc[i].length;
1913 urb->iso_frame_desc[i].offset = maxp * i;
1916 urb->complete = iso_callback;
1917 /* urb->context = SET BY CALLER */
1918 urb->interval = 1 << (desc->bInterval - 1);
1919 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
1924 test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
1925 int pipe, struct usb_endpoint_descriptor *desc, unsigned offset)
1927 struct iso_context context;
1928 struct usb_device *udev;
1930 unsigned long packets = 0;
1932 struct urb *urbs[10]; /* FIXME no limit */
1934 if (param->sglen > 10)
1937 memset(&context, 0, sizeof(context));
1938 context.count = param->iterations * param->sglen;
1940 init_completion(&context.done);
1941 spin_lock_init(&context.lock);
1943 memset(urbs, 0, sizeof(urbs));
1944 udev = testdev_to_usbdev(dev);
1945 dev_info(&dev->intf->dev,
1946 "... iso period %d %sframes, wMaxPacket %04x\n",
1947 1 << (desc->bInterval - 1),
1948 (udev->speed == USB_SPEED_HIGH) ? "micro" : "",
1949 usb_endpoint_maxp(desc));
1951 for (i = 0; i < param->sglen; i++) {
1952 urbs[i] = iso_alloc_urb(udev, pipe, desc,
1953 param->length, offset);
1958 packets += urbs[i]->number_of_packets;
1959 urbs[i]->context = &context;
1961 packets *= param->iterations;
1962 dev_info(&dev->intf->dev,
1963 "... total %lu msec (%lu packets)\n",
1964 (packets * (1 << (desc->bInterval - 1)))
1965 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1),
1968 spin_lock_irq(&context.lock);
1969 for (i = 0; i < param->sglen; i++) {
1971 status = usb_submit_urb(urbs[i], GFP_ATOMIC);
1973 ERROR(dev, "submit iso[%d], error %d\n", i, status);
1975 spin_unlock_irq(&context.lock);
1979 simple_free_urb(urbs[i]);
1982 context.submit_error = 1;
1986 spin_unlock_irq(&context.lock);
1988 wait_for_completion(&context.done);
1990 for (i = 0; i < param->sglen; i++) {
1992 simple_free_urb(urbs[i]);
1995 * Isochronous transfers are expected to fail sometimes. As an
1996 * arbitrary limit, we will report an error if any submissions
1997 * fail or if the transfer failure rate is > 10%.
2001 else if (context.submit_error)
2003 else if (context.errors > context.packet_count / 10)
2008 for (i = 0; i < param->sglen; i++) {
2010 simple_free_urb(urbs[i]);
2015 static int test_unaligned_bulk(
2016 struct usbtest_dev *tdev,
2020 unsigned transfer_flags,
2024 struct urb *urb = usbtest_alloc_urb(
2025 testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1, 0);
2030 retval = simple_io(tdev, urb, iterations, 0, 0, label);
2031 simple_free_urb(urb);
2035 /*-------------------------------------------------------------------------*/
2037 /* We only have this one interface to user space, through usbfs.
2038 * User mode code can scan usbfs to find N different devices (maybe on
2039 * different busses) to use when testing, and allocate one thread per
2040 * test. So discovery is simplified, and we have no device naming issues.
2042 * Don't use these only as stress/load tests. Use them along with with
2043 * other USB bus activity: plugging, unplugging, mousing, mp3 playback,
2044 * video capture, and so on. Run different tests at different times, in
2045 * different sequences. Nothing here should interact with other devices,
2046 * except indirectly by consuming USB bandwidth and CPU resources for test
2047 * threads and request completion. But the only way to know that for sure
2048 * is to test when HC queues are in use by many devices.
2050 * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(),
2051 * it locks out usbcore in certain code paths. Notably, if you disconnect
2052 * the device-under-test, hub_wq will wait block forever waiting for the
2053 * ioctl to complete ... so that usb_disconnect() can abort the pending
2054 * urbs and then call usbtest_disconnect(). To abort a test, you're best
2055 * off just killing the userspace task and waiting for it to exit.
2059 usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
2061 struct usbtest_dev *dev = usb_get_intfdata(intf);
2062 struct usb_device *udev = testdev_to_usbdev(dev);
2063 struct usbtest_param *param = buf;
2064 int retval = -EOPNOTSUPP;
2066 struct scatterlist *sg;
2067 struct usb_sg_request req;
2068 struct timeval start;
2071 /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */
2073 pattern = mod_pattern;
2075 if (code != USBTEST_REQUEST)
2078 if (param->iterations <= 0)
2081 if (mutex_lock_interruptible(&dev->lock))
2082 return -ERESTARTSYS;
2084 /* FIXME: What if a system sleep starts while a test is running? */
2086 /* some devices, like ez-usb default devices, need a non-default
2087 * altsetting to have any active endpoints. some tests change
2088 * altsettings; force a default so most tests don't need to check.
2090 if (dev->info->alt >= 0) {
2093 if (intf->altsetting->desc.bInterfaceNumber) {
2094 mutex_unlock(&dev->lock);
2097 res = set_altsetting(dev, dev->info->alt);
2100 "set altsetting to %d failed, %d\n",
2101 dev->info->alt, res);
2102 mutex_unlock(&dev->lock);
2108 * Just a bunch of test cases that every HCD is expected to handle.
2110 * Some may need specific firmware, though it'd be good to have
2111 * one firmware image to handle all the test cases.
2113 * FIXME add more tests! cancel requests, verify the data, control
2114 * queueing, concurrent read+write threads, and so on.
2116 do_gettimeofday(&start);
2117 switch (param->test_num) {
2120 dev_info(&intf->dev, "TEST 0: NOP\n");
2124 /* Simple non-queued bulk I/O tests */
2126 if (dev->out_pipe == 0)
2128 dev_info(&intf->dev,
2129 "TEST 1: write %d bytes %u times\n",
2130 param->length, param->iterations);
2131 urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0);
2136 /* FIRMWARE: bulk sink (maybe accepts short writes) */
2137 retval = simple_io(dev, urb, param->iterations, 0, 0, "test1");
2138 simple_free_urb(urb);
2141 if (dev->in_pipe == 0)
2143 dev_info(&intf->dev,
2144 "TEST 2: read %d bytes %u times\n",
2145 param->length, param->iterations);
2146 urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0);
2151 /* FIRMWARE: bulk source (maybe generates short writes) */
2152 retval = simple_io(dev, urb, param->iterations, 0, 0, "test2");
2153 simple_free_urb(urb);
2156 if (dev->out_pipe == 0 || param->vary == 0)
2158 dev_info(&intf->dev,
2159 "TEST 3: write/%d 0..%d bytes %u times\n",
2160 param->vary, param->length, param->iterations);
2161 urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0);
2166 /* FIRMWARE: bulk sink (maybe accepts short writes) */
2167 retval = simple_io(dev, urb, param->iterations, param->vary,
2169 simple_free_urb(urb);
2172 if (dev->in_pipe == 0 || param->vary == 0)
2174 dev_info(&intf->dev,
2175 "TEST 4: read/%d 0..%d bytes %u times\n",
2176 param->vary, param->length, param->iterations);
2177 urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0);
2182 /* FIRMWARE: bulk source (maybe generates short writes) */
2183 retval = simple_io(dev, urb, param->iterations, param->vary,
2185 simple_free_urb(urb);
2188 /* Queued bulk I/O tests */
2190 if (dev->out_pipe == 0 || param->sglen == 0)
2192 dev_info(&intf->dev,
2193 "TEST 5: write %d sglists %d entries of %d bytes\n",
2195 param->sglen, param->length);
2196 sg = alloc_sglist(param->sglen, param->length,
2197 0, dev, dev->out_pipe);
2202 /* FIRMWARE: bulk sink (maybe accepts short writes) */
2203 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
2204 &req, sg, param->sglen);
2205 free_sglist(sg, param->sglen);
2209 if (dev->in_pipe == 0 || param->sglen == 0)
2211 dev_info(&intf->dev,
2212 "TEST 6: read %d sglists %d entries of %d bytes\n",
2214 param->sglen, param->length);
2215 sg = alloc_sglist(param->sglen, param->length,
2216 0, dev, dev->in_pipe);
2221 /* FIRMWARE: bulk source (maybe generates short writes) */
2222 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
2223 &req, sg, param->sglen);
2224 free_sglist(sg, param->sglen);
2227 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0)
2229 dev_info(&intf->dev,
2230 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n",
2231 param->vary, param->iterations,
2232 param->sglen, param->length);
2233 sg = alloc_sglist(param->sglen, param->length,
2234 param->vary, dev, dev->out_pipe);
2239 /* FIRMWARE: bulk sink (maybe accepts short writes) */
2240 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
2241 &req, sg, param->sglen);
2242 free_sglist(sg, param->sglen);
2245 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0)
2247 dev_info(&intf->dev,
2248 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n",
2249 param->vary, param->iterations,
2250 param->sglen, param->length);
2251 sg = alloc_sglist(param->sglen, param->length,
2252 param->vary, dev, dev->in_pipe);
2257 /* FIRMWARE: bulk source (maybe generates short writes) */
2258 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
2259 &req, sg, param->sglen);
2260 free_sglist(sg, param->sglen);
2263 /* non-queued sanity tests for control (chapter 9 subset) */
2266 dev_info(&intf->dev,
2267 "TEST 9: ch9 (subset) control tests, %d times\n",
2269 for (i = param->iterations; retval == 0 && i--; /* NOP */)
2270 retval = ch9_postconfig(dev);
2272 dev_err(&intf->dev, "ch9 subset failed, "
2273 "iterations left %d\n", i);
2276 /* queued control messaging */
2279 dev_info(&intf->dev,
2280 "TEST 10: queue %d control calls, %d times\n",
2283 retval = test_ctrl_queue(dev, param);
2286 /* simple non-queued unlinks (ring with one urb) */
2288 if (dev->in_pipe == 0 || !param->length)
2291 dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n",
2292 param->iterations, param->length);
2293 for (i = param->iterations; retval == 0 && i--; /* NOP */)
2294 retval = unlink_simple(dev, dev->in_pipe,
2297 dev_err(&intf->dev, "unlink reads failed %d, "
2298 "iterations left %d\n", retval, i);
2301 if (dev->out_pipe == 0 || !param->length)
2304 dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n",
2305 param->iterations, param->length);
2306 for (i = param->iterations; retval == 0 && i--; /* NOP */)
2307 retval = unlink_simple(dev, dev->out_pipe,
2310 dev_err(&intf->dev, "unlink writes failed %d, "
2311 "iterations left %d\n", retval, i);
2316 if (dev->out_pipe == 0 && dev->in_pipe == 0)
2319 dev_info(&intf->dev, "TEST 13: set/clear %d halts\n",
2321 for (i = param->iterations; retval == 0 && i--; /* NOP */)
2322 retval = halt_simple(dev);
2325 ERROR(dev, "halts failed, iterations left %d\n", i);
2328 /* control write tests */
2330 if (!dev->info->ctrl_out)
2332 dev_info(&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n",
2334 realworld ? 1 : 0, param->length,
2336 retval = ctrl_out(dev, param->iterations,
2337 param->length, param->vary, 0);
2340 /* iso write tests */
2342 if (dev->out_iso_pipe == 0 || param->sglen == 0)
2344 dev_info(&intf->dev,
2345 "TEST 15: write %d iso, %d entries of %d bytes\n",
2347 param->sglen, param->length);
2348 /* FIRMWARE: iso sink */
2349 retval = test_iso_queue(dev, param,
2350 dev->out_iso_pipe, dev->iso_out, 0);
2353 /* iso read tests */
2355 if (dev->in_iso_pipe == 0 || param->sglen == 0)
2357 dev_info(&intf->dev,
2358 "TEST 16: read %d iso, %d entries of %d bytes\n",
2360 param->sglen, param->length);
2361 /* FIRMWARE: iso source */
2362 retval = test_iso_queue(dev, param,
2363 dev->in_iso_pipe, dev->iso_in, 0);
2366 /* FIXME scatterlist cancel (needs helper thread) */
2368 /* Tests for bulk I/O using DMA mapping by core and odd address */
2370 if (dev->out_pipe == 0)
2372 dev_info(&intf->dev,
2373 "TEST 17: write odd addr %d bytes %u times core map\n",
2374 param->length, param->iterations);
2376 retval = test_unaligned_bulk(
2378 param->length, param->iterations,
2383 if (dev->in_pipe == 0)
2385 dev_info(&intf->dev,
2386 "TEST 18: read odd addr %d bytes %u times core map\n",
2387 param->length, param->iterations);
2389 retval = test_unaligned_bulk(
2391 param->length, param->iterations,
2395 /* Tests for bulk I/O using premapped coherent buffer and odd address */
2397 if (dev->out_pipe == 0)
2399 dev_info(&intf->dev,
2400 "TEST 19: write odd addr %d bytes %u times premapped\n",
2401 param->length, param->iterations);
2403 retval = test_unaligned_bulk(
2405 param->length, param->iterations,
2406 URB_NO_TRANSFER_DMA_MAP, "test19");
2410 if (dev->in_pipe == 0)
2412 dev_info(&intf->dev,
2413 "TEST 20: read odd addr %d bytes %u times premapped\n",
2414 param->length, param->iterations);
2416 retval = test_unaligned_bulk(
2418 param->length, param->iterations,
2419 URB_NO_TRANSFER_DMA_MAP, "test20");
2422 /* control write tests with unaligned buffer */
2424 if (!dev->info->ctrl_out)
2426 dev_info(&intf->dev,
2427 "TEST 21: %d ep0out odd addr, %d..%d vary %d\n",
2429 realworld ? 1 : 0, param->length,
2431 retval = ctrl_out(dev, param->iterations,
2432 param->length, param->vary, 1);
2435 /* unaligned iso tests */
2437 if (dev->out_iso_pipe == 0 || param->sglen == 0)
2439 dev_info(&intf->dev,
2440 "TEST 22: write %d iso odd, %d entries of %d bytes\n",
2442 param->sglen, param->length);
2443 retval = test_iso_queue(dev, param,
2444 dev->out_iso_pipe, dev->iso_out, 1);
2448 if (dev->in_iso_pipe == 0 || param->sglen == 0)
2450 dev_info(&intf->dev,
2451 "TEST 23: read %d iso odd, %d entries of %d bytes\n",
2453 param->sglen, param->length);
2454 retval = test_iso_queue(dev, param,
2455 dev->in_iso_pipe, dev->iso_in, 1);
2458 /* unlink URBs from a bulk-OUT queue */
2460 if (dev->out_pipe == 0 || !param->length || param->sglen < 4)
2463 dev_info(&intf->dev, "TEST 24: unlink from %d queues of "
2464 "%d %d-byte writes\n",
2465 param->iterations, param->sglen, param->length);
2466 for (i = param->iterations; retval == 0 && i > 0; --i) {
2467 retval = unlink_queued(dev, dev->out_pipe,
2468 param->sglen, param->length);
2471 "unlink queued writes failed %d, "
2472 "iterations left %d\n", retval, i);
2478 /* Simple non-queued interrupt I/O tests */
2480 if (dev->out_int_pipe == 0)
2482 dev_info(&intf->dev,
2483 "TEST 25: write %d bytes %u times\n",
2484 param->length, param->iterations);
2485 urb = simple_alloc_urb(udev, dev->out_int_pipe, param->length,
2486 dev->int_out->bInterval);
2491 /* FIRMWARE: interrupt sink (maybe accepts short writes) */
2492 retval = simple_io(dev, urb, param->iterations, 0, 0, "test25");
2493 simple_free_urb(urb);
2496 if (dev->in_int_pipe == 0)
2498 dev_info(&intf->dev,
2499 "TEST 26: read %d bytes %u times\n",
2500 param->length, param->iterations);
2501 urb = simple_alloc_urb(udev, dev->in_int_pipe, param->length,
2502 dev->int_in->bInterval);
2507 /* FIRMWARE: interrupt source (maybe generates short writes) */
2508 retval = simple_io(dev, urb, param->iterations, 0, 0, "test26");
2509 simple_free_urb(urb);
2512 do_gettimeofday(¶m->duration);
2513 param->duration.tv_sec -= start.tv_sec;
2514 param->duration.tv_usec -= start.tv_usec;
2515 if (param->duration.tv_usec < 0) {
2516 param->duration.tv_usec += 1000 * 1000;
2517 param->duration.tv_sec -= 1;
2519 mutex_unlock(&dev->lock);
2523 /*-------------------------------------------------------------------------*/
2525 static unsigned force_interrupt;
2526 module_param(force_interrupt, uint, 0);
2527 MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt");
2530 static unsigned short vendor;
2531 module_param(vendor, ushort, 0);
2532 MODULE_PARM_DESC(vendor, "vendor code (from usb-if)");
2534 static unsigned short product;
2535 module_param(product, ushort, 0);
2536 MODULE_PARM_DESC(product, "product code (from vendor)");
2540 usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
2542 struct usb_device *udev;
2543 struct usbtest_dev *dev;
2544 struct usbtest_info *info;
2545 char *rtest, *wtest;
2546 char *irtest, *iwtest;
2547 char *intrtest, *intwtest;
2549 udev = interface_to_usbdev(intf);
2552 /* specify devices by module parameters? */
2553 if (id->match_flags == 0) {
2554 /* vendor match required, product match optional */
2555 if (!vendor || le16_to_cpu(udev->descriptor.idVendor) != (u16)vendor)
2557 if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product)
2559 dev_info(&intf->dev, "matched module params, "
2560 "vend=0x%04x prod=0x%04x\n",
2561 le16_to_cpu(udev->descriptor.idVendor),
2562 le16_to_cpu(udev->descriptor.idProduct));
2566 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2569 info = (struct usbtest_info *) id->driver_info;
2571 mutex_init(&dev->lock);
2575 /* cacheline-aligned scratch for i/o */
2576 dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL);
2577 if (dev->buf == NULL) {
2582 /* NOTE this doesn't yet test the handful of difference that are
2583 * visible with high speed interrupts: bigger maxpacket (1K) and
2584 * "high bandwidth" modes (up to 3 packets/uframe).
2587 irtest = iwtest = "";
2588 intrtest = intwtest = "";
2589 if (force_interrupt || udev->speed == USB_SPEED_LOW) {
2591 dev->in_pipe = usb_rcvintpipe(udev, info->ep_in);
2595 dev->out_pipe = usb_sndintpipe(udev, info->ep_out);
2596 wtest = " intr-out";
2599 if (override_alt >= 0 || info->autoconf) {
2602 status = get_endpoints(dev, intf);
2604 WARNING(dev, "couldn't get endpoints, %d\n",
2610 /* may find bulk or ISO pipes */
2613 dev->in_pipe = usb_rcvbulkpipe(udev,
2616 dev->out_pipe = usb_sndbulkpipe(udev,
2622 wtest = " bulk-out";
2623 if (dev->in_iso_pipe)
2625 if (dev->out_iso_pipe)
2626 iwtest = " iso-out";
2627 if (dev->in_int_pipe)
2628 intrtest = " int-in";
2629 if (dev->out_int_pipe)
2630 intwtest = " int-out";
2633 usb_set_intfdata(intf, dev);
2634 dev_info(&intf->dev, "%s\n", info->name);
2635 dev_info(&intf->dev, "%s {control%s%s%s%s%s%s%s} tests%s\n",
2636 usb_speed_string(udev->speed),
2637 info->ctrl_out ? " in/out" : "",
2641 info->alt >= 0 ? " (+alt)" : "");
2645 static int usbtest_suspend(struct usb_interface *intf, pm_message_t message)
2650 static int usbtest_resume(struct usb_interface *intf)
2656 static void usbtest_disconnect(struct usb_interface *intf)
2658 struct usbtest_dev *dev = usb_get_intfdata(intf);
2660 usb_set_intfdata(intf, NULL);
2661 dev_dbg(&intf->dev, "disconnect\n");
2665 /* Basic testing only needs a device that can source or sink bulk traffic.
2666 * Any device can test control transfers (default with GENERIC binding).
2668 * Several entries work with the default EP0 implementation that's built
2669 * into EZ-USB chips. There's a default vendor ID which can be overridden
2670 * by (very) small config EEPROMS, but otherwise all these devices act
2671 * identically until firmware is loaded: only EP0 works. It turns out
2672 * to be easy to make other endpoints work, without modifying that EP0
2673 * behavior. For now, we expect that kind of firmware.
2676 /* an21xx or fx versions of ez-usb */
2677 static struct usbtest_info ez1_info = {
2678 .name = "EZ-USB device",
2684 /* fx2 version of ez-usb */
2685 static struct usbtest_info ez2_info = {
2686 .name = "FX2 device",
2692 /* ezusb family device with dedicated usb test firmware,
2694 static struct usbtest_info fw_info = {
2695 .name = "usb test device",
2699 .autoconf = 1, /* iso and ctrl_out need autoconf */
2701 .iso = 1, /* iso_ep's are #8 in/out */
2704 /* peripheral running Linux and 'zero.c' test firmware, or
2705 * its user-mode cousin. different versions of this use
2706 * different hardware with the same vendor/product codes.
2707 * host side MUST rely on the endpoint descriptors.
2709 static struct usbtest_info gz_info = {
2710 .name = "Linux gadget zero",
2718 static struct usbtest_info um_info = {
2719 .name = "Linux user mode test driver",
2724 static struct usbtest_info um2_info = {
2725 .name = "Linux user mode ISO test driver",
2732 /* this is a nice source of high speed bulk data;
2733 * uses an FX2, with firmware provided in the device
2735 static struct usbtest_info ibot2_info = {
2736 .name = "iBOT2 webcam",
2743 /* we can use any device to test control traffic */
2744 static struct usbtest_info generic_info = {
2745 .name = "Generic USB device",
2751 static const struct usb_device_id id_table[] = {
2753 /*-------------------------------------------------------------*/
2755 /* EZ-USB devices which download firmware to replace (or in our
2756 * case augment) the default device implementation.
2759 /* generic EZ-USB FX controller */
2760 { USB_DEVICE(0x0547, 0x2235),
2761 .driver_info = (unsigned long) &ez1_info,
2764 /* CY3671 development board with EZ-USB FX */
2765 { USB_DEVICE(0x0547, 0x0080),
2766 .driver_info = (unsigned long) &ez1_info,
2769 /* generic EZ-USB FX2 controller (or development board) */
2770 { USB_DEVICE(0x04b4, 0x8613),
2771 .driver_info = (unsigned long) &ez2_info,
2774 /* re-enumerated usb test device firmware */
2775 { USB_DEVICE(0xfff0, 0xfff0),
2776 .driver_info = (unsigned long) &fw_info,
2779 /* "Gadget Zero" firmware runs under Linux */
2780 { USB_DEVICE(0x0525, 0xa4a0),
2781 .driver_info = (unsigned long) &gz_info,
2784 /* so does a user-mode variant */
2785 { USB_DEVICE(0x0525, 0xa4a4),
2786 .driver_info = (unsigned long) &um_info,
2789 /* ... and a user-mode variant that talks iso */
2790 { USB_DEVICE(0x0525, 0xa4a3),
2791 .driver_info = (unsigned long) &um2_info,
2795 /* Keyspan 19qi uses an21xx (original EZ-USB) */
2796 /* this does not coexist with the real Keyspan 19qi driver! */
2797 { USB_DEVICE(0x06cd, 0x010b),
2798 .driver_info = (unsigned long) &ez1_info,
2802 /*-------------------------------------------------------------*/
2805 /* iBOT2 makes a nice source of high speed bulk-in data */
2806 /* this does not coexist with a real iBOT2 driver! */
2807 { USB_DEVICE(0x0b62, 0x0059),
2808 .driver_info = (unsigned long) &ibot2_info,
2812 /*-------------------------------------------------------------*/
2815 /* module params can specify devices to use for control tests */
2816 { .driver_info = (unsigned long) &generic_info, },
2819 /*-------------------------------------------------------------*/
2823 MODULE_DEVICE_TABLE(usb, id_table);
2825 static struct usb_driver usbtest_driver = {
2827 .id_table = id_table,
2828 .probe = usbtest_probe,
2829 .unlocked_ioctl = usbtest_ioctl,
2830 .disconnect = usbtest_disconnect,
2831 .suspend = usbtest_suspend,
2832 .resume = usbtest_resume,
2835 /*-------------------------------------------------------------------------*/
2837 static int __init usbtest_init(void)
2841 pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product);
2843 return usb_register(&usbtest_driver);
2845 module_init(usbtest_init);
2847 static void __exit usbtest_exit(void)
2849 usb_deregister(&usbtest_driver);
2851 module_exit(usbtest_exit);
2853 MODULE_DESCRIPTION("USB Core/HCD Testing Driver");
2854 MODULE_LICENSE("GPL");