Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 8 | #include <linux/scatterlist.h> |
Matthias Kaehlcke | 1cfab02 | 2007-12-13 16:15:33 -0800 | [diff] [blame] | 9 | #include <linux/mutex.h> |
Alan Stern | 32b36ee | 2014-06-03 11:11:34 -0400 | [diff] [blame] | 10 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/usb.h> |
| 12 | |
Roger Quadros | e5e4746 | 2013-12-18 15:40:10 +0530 | [diff] [blame] | 13 | #define SIMPLE_IO_TIMEOUT 10000 /* in milliseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | /*-------------------------------------------------------------------------*/ |
| 16 | |
Alan Stern | d0b4652 | 2013-01-30 16:38:11 -0500 | [diff] [blame] | 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"); |
| 20 | |
| 21 | /*-------------------------------------------------------------------------*/ |
| 22 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 23 | /* FIXME make these public somewhere; usbdevfs.h? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | struct usbtest_param { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 25 | /* inputs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | unsigned test_num; /* 0..(TEST_CASES-1) */ |
| 27 | unsigned iterations; |
| 28 | unsigned length; |
| 29 | unsigned vary; |
| 30 | unsigned sglen; |
| 31 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 32 | /* outputs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | struct timeval duration; |
| 34 | }; |
| 35 | #define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param) |
| 36 | |
| 37 | /*-------------------------------------------------------------------------*/ |
| 38 | |
| 39 | #define GENERIC /* let probe() bind using module params */ |
| 40 | |
| 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 |
| 43 | * that "real" driver. |
| 44 | */ |
| 45 | //#define IBOT2 /* grab iBOT2 webcams */ |
| 46 | //#define KEYSPAN_19Qi /* grab un-renumerated serial adapter */ |
| 47 | |
| 48 | /*-------------------------------------------------------------------------*/ |
| 49 | |
| 50 | struct usbtest_info { |
| 51 | const char *name; |
| 52 | u8 ep_in; /* bulk/intr source */ |
| 53 | u8 ep_out; /* bulk/intr sink */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 54 | unsigned autoconf:1; |
| 55 | unsigned ctrl_out:1; |
| 56 | unsigned iso:1; /* try iso in/out */ |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 57 | unsigned intr:1; /* try interrupt in/out */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | int alt; |
| 59 | }; |
| 60 | |
| 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. |
| 66 | */ |
| 67 | struct usbtest_dev { |
| 68 | struct usb_interface *intf; |
| 69 | struct usbtest_info *info; |
| 70 | int in_pipe; |
| 71 | int out_pipe; |
| 72 | int in_iso_pipe; |
| 73 | int out_iso_pipe; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 74 | int in_int_pipe; |
| 75 | int out_int_pipe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | struct usb_endpoint_descriptor *iso_in, *iso_out; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 77 | struct usb_endpoint_descriptor *int_in, *int_out; |
Matthias Kaehlcke | 1cfab02 | 2007-12-13 16:15:33 -0800 | [diff] [blame] | 78 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | #define TBUF_SIZE 256 |
| 81 | u8 *buf; |
| 82 | }; |
| 83 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 84 | static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 86 | return interface_to_usbdev(test->intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* set up all urbs so they can be used with either bulk or interrupt */ |
| 90 | #define INTERRUPT_RATE 1 /* msec/transfer */ |
| 91 | |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 92 | #define ERROR(tdev, fmt, args...) \ |
| 93 | dev_err(&(tdev)->intf->dev , fmt , ## args) |
Arjan van de Ven | b6c6393 | 2008-07-25 01:45:52 -0700 | [diff] [blame] | 94 | #define WARNING(tdev, fmt, args...) \ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 95 | dev_warn(&(tdev)->intf->dev , fmt , ## args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 97 | #define GUARD_BYTE 0xA5 |
Peter Chen | 41d3c0b | 2015-09-01 09:47:58 +0800 | [diff] [blame] | 98 | #define MAX_SGLEN 128 |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /*-------------------------------------------------------------------------*/ |
| 101 | |
| 102 | static int |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 103 | get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
| 105 | int tmp; |
| 106 | struct usb_host_interface *alt; |
| 107 | struct usb_host_endpoint *in, *out; |
| 108 | struct usb_host_endpoint *iso_in, *iso_out; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 109 | struct usb_host_endpoint *int_in, *int_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | struct usb_device *udev; |
| 111 | |
| 112 | for (tmp = 0; tmp < intf->num_altsetting; tmp++) { |
| 113 | unsigned ep; |
| 114 | |
| 115 | in = out = NULL; |
| 116 | iso_in = iso_out = NULL; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 117 | int_in = int_out = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | alt = intf->altsetting + tmp; |
| 119 | |
Alan Stern | d0b4652 | 2013-01-30 16:38:11 -0500 | [diff] [blame] | 120 | if (override_alt >= 0 && |
| 121 | override_alt != alt->desc.bAlternateSetting) |
| 122 | continue; |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | /* take the first altsetting with in-bulk + out-bulk; |
Justin P. Mattock | 70f23fd | 2011-05-10 10:16:21 +0200 | [diff] [blame] | 125 | * ignore other endpoints and altsettings. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | */ |
| 127 | for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { |
| 128 | struct usb_host_endpoint *e; |
| 129 | |
| 130 | e = alt->endpoint + ep; |
Huang Rui | 9a37a50 | 2013-09-24 00:03:43 +0800 | [diff] [blame] | 131 | switch (usb_endpoint_type(&e->desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | case USB_ENDPOINT_XFER_BULK: |
| 133 | break; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 134 | case USB_ENDPOINT_XFER_INT: |
| 135 | if (dev->info->intr) |
| 136 | goto try_intr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | case USB_ENDPOINT_XFER_ISOC: |
| 138 | if (dev->info->iso) |
| 139 | goto try_iso; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 140 | /* FALLTHROUGH */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | default: |
| 142 | continue; |
| 143 | } |
Luiz Fernando N. Capitulino | 4d823dd | 2006-10-26 13:03:02 -0300 | [diff] [blame] | 144 | if (usb_endpoint_dir_in(&e->desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | if (!in) |
| 146 | in = e; |
| 147 | } else { |
| 148 | if (!out) |
| 149 | out = e; |
| 150 | } |
| 151 | continue; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 152 | try_intr: |
| 153 | if (usb_endpoint_dir_in(&e->desc)) { |
| 154 | if (!int_in) |
| 155 | int_in = e; |
| 156 | } else { |
| 157 | if (!int_out) |
| 158 | int_out = e; |
| 159 | } |
| 160 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | try_iso: |
Luiz Fernando N. Capitulino | 4d823dd | 2006-10-26 13:03:02 -0300 | [diff] [blame] | 162 | if (usb_endpoint_dir_in(&e->desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | if (!iso_in) |
| 164 | iso_in = e; |
| 165 | } else { |
| 166 | if (!iso_out) |
| 167 | iso_out = e; |
| 168 | } |
| 169 | } |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 170 | if ((in && out) || iso_in || iso_out || int_in || int_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | goto found; |
| 172 | } |
| 173 | return -EINVAL; |
| 174 | |
| 175 | found: |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 176 | udev = testdev_to_usbdev(dev); |
Alan Stern | d0b4652 | 2013-01-30 16:38:11 -0500 | [diff] [blame] | 177 | dev->info->alt = alt->desc.bAlternateSetting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | if (alt->desc.bAlternateSetting != 0) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 179 | tmp = usb_set_interface(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | alt->desc.bInterfaceNumber, |
| 181 | alt->desc.bAlternateSetting); |
| 182 | if (tmp < 0) |
| 183 | return tmp; |
| 184 | } |
| 185 | |
| 186 | if (in) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 187 | dev->in_pipe = usb_rcvbulkpipe(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 189 | dev->out_pipe = usb_sndbulkpipe(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
| 191 | } |
| 192 | if (iso_in) { |
| 193 | dev->iso_in = &iso_in->desc; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 194 | dev->in_iso_pipe = usb_rcvisocpipe(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | iso_in->desc.bEndpointAddress |
| 196 | & USB_ENDPOINT_NUMBER_MASK); |
Ming Lei | 951fd8e | 2010-08-02 22:09:17 +0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if (iso_out) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | dev->iso_out = &iso_out->desc; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 201 | dev->out_iso_pipe = usb_sndisocpipe(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | iso_out->desc.bEndpointAddress |
| 203 | & USB_ENDPOINT_NUMBER_MASK); |
| 204 | } |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 205 | |
| 206 | if (int_in) { |
| 207 | dev->int_in = &int_in->desc; |
| 208 | dev->in_int_pipe = usb_rcvintpipe(udev, |
| 209 | int_in->desc.bEndpointAddress |
| 210 | & USB_ENDPOINT_NUMBER_MASK); |
| 211 | } |
| 212 | |
| 213 | if (int_out) { |
| 214 | dev->int_out = &int_out->desc; |
| 215 | dev->out_int_pipe = usb_sndintpipe(udev, |
| 216 | int_out->desc.bEndpointAddress |
| 217 | & USB_ENDPOINT_NUMBER_MASK); |
| 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | /*-------------------------------------------------------------------------*/ |
| 223 | |
| 224 | /* Support for testing basic non-queued I/O streams. |
| 225 | * |
| 226 | * These just package urbs as requests that can be easily canceled. |
| 227 | * Each urb's data buffer is dynamically allocated; callers can fill |
| 228 | * them with non-zero test data (or test for it) when appropriate. |
| 229 | */ |
| 230 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 231 | static void simple_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 233 | complete(urb->context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 236 | static struct urb *usbtest_alloc_urb( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | struct usb_device *udev, |
| 238 | int pipe, |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 239 | unsigned long bytes, |
| 240 | unsigned transfer_flags, |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 241 | unsigned offset, |
| 242 | u8 bInterval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
| 244 | struct urb *urb; |
| 245 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 246 | urb = usb_alloc_urb(0, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | if (!urb) |
| 248 | return urb; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 249 | |
| 250 | if (bInterval) |
| 251 | usb_fill_int_urb(urb, udev, pipe, NULL, bytes, simple_callback, |
| 252 | NULL, bInterval); |
| 253 | else |
| 254 | usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, |
| 255 | NULL); |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | urb->interval = (udev->speed == USB_SPEED_HIGH) |
| 258 | ? (INTERRUPT_RATE << 3) |
| 259 | : INTERRUPT_RATE; |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 260 | urb->transfer_flags = transfer_flags; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 261 | if (usb_pipein(pipe)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | urb->transfer_flags |= URB_SHORT_NOT_OK; |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 263 | |
| 264 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) |
| 265 | urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset, |
| 266 | GFP_KERNEL, &urb->transfer_dma); |
| 267 | else |
| 268 | urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL); |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (!urb->transfer_buffer) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 271 | usb_free_urb(urb); |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 272 | return NULL; |
| 273 | } |
| 274 | |
| 275 | /* To test unaligned transfers add an offset and fill the |
| 276 | unused memory with a guard value */ |
| 277 | if (offset) { |
| 278 | memset(urb->transfer_buffer, GUARD_BYTE, offset); |
| 279 | urb->transfer_buffer += offset; |
| 280 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) |
| 281 | urb->transfer_dma += offset; |
| 282 | } |
| 283 | |
| 284 | /* For inbound transfers use guard byte so that test fails if |
| 285 | data not correctly copied */ |
| 286 | memset(urb->transfer_buffer, |
| 287 | usb_pipein(urb->pipe) ? GUARD_BYTE : 0, |
| 288 | bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | return urb; |
| 290 | } |
| 291 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 292 | static struct urb *simple_alloc_urb( |
| 293 | struct usb_device *udev, |
| 294 | int pipe, |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 295 | unsigned long bytes, |
| 296 | u8 bInterval) |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 297 | { |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 298 | return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0, |
| 299 | bInterval); |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 302 | static unsigned pattern; |
Vikram Pandita | 7f4e985 | 2009-11-09 21:24:32 -0600 | [diff] [blame] | 303 | static unsigned mod_pattern; |
| 304 | module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR); |
| 305 | MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 307 | static unsigned get_maxpacket(struct usb_device *udev, int pipe) |
| 308 | { |
| 309 | struct usb_host_endpoint *ep; |
| 310 | |
| 311 | ep = usb_pipe_endpoint(udev, pipe); |
| 312 | return le16_to_cpup(&ep->desc.wMaxPacketSize); |
| 313 | } |
| 314 | |
| 315 | static void simple_fill_buf(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
| 317 | unsigned i; |
| 318 | u8 *buf = urb->transfer_buffer; |
| 319 | unsigned len = urb->transfer_buffer_length; |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 320 | unsigned maxpacket; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | switch (pattern) { |
| 323 | default: |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 324 | /* FALLTHROUGH */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | case 0: |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 326 | memset(buf, 0, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | break; |
| 328 | case 1: /* mod63 */ |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 329 | maxpacket = get_maxpacket(urb->dev, urb->pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | for (i = 0; i < len; i++) |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 331 | *buf++ = (u8) ((i % maxpacket) % 63); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
Greg Dietsche | 304b0b5 | 2011-05-08 22:51:43 -0500 | [diff] [blame] | 336 | static inline unsigned long buffer_offset(void *buf) |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 337 | { |
Greg Dietsche | 304b0b5 | 2011-05-08 22:51:43 -0500 | [diff] [blame] | 338 | return (unsigned long)buf & (ARCH_KMALLOC_MINALIGN - 1); |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb) |
| 342 | { |
| 343 | u8 *buf = urb->transfer_buffer; |
| 344 | u8 *guard = buf - buffer_offset(buf); |
| 345 | unsigned i; |
| 346 | |
| 347 | for (i = 0; guard < buf; i++, guard++) { |
| 348 | if (*guard != GUARD_BYTE) { |
| 349 | ERROR(tdev, "guard byte[%d] %d (not %d)\n", |
| 350 | i, *guard, GUARD_BYTE); |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | } |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
| 359 | unsigned i; |
| 360 | u8 expected; |
| 361 | u8 *buf = urb->transfer_buffer; |
| 362 | unsigned len = urb->actual_length; |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 363 | unsigned maxpacket = get_maxpacket(urb->dev, urb->pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 365 | int ret = check_guard_bytes(tdev, urb); |
| 366 | if (ret) |
| 367 | return ret; |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | for (i = 0; i < len; i++, buf++) { |
| 370 | switch (pattern) { |
| 371 | /* all-zeroes has no synchronization issues */ |
| 372 | case 0: |
| 373 | expected = 0; |
| 374 | break; |
| 375 | /* mod63 stays in sync with short-terminated transfers, |
| 376 | * or otherwise when host and gadget agree on how large |
| 377 | * each usb transfer request should be. resync is done |
| 378 | * with set_interface or set_config. |
| 379 | */ |
| 380 | case 1: /* mod63 */ |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 381 | expected = (i % maxpacket) % 63; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | break; |
| 383 | /* always fail unsupported patterns */ |
| 384 | default: |
| 385 | expected = !*buf; |
| 386 | break; |
| 387 | } |
| 388 | if (*buf == expected) |
| 389 | continue; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 390 | ERROR(tdev, "buf[%d] = %d (not %d)\n", i, *buf, expected); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | return -EINVAL; |
| 392 | } |
| 393 | return 0; |
| 394 | } |
| 395 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 396 | static void simple_free_urb(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Greg Dietsche | 304b0b5 | 2011-05-08 22:51:43 -0500 | [diff] [blame] | 398 | unsigned long offset = buffer_offset(urb->transfer_buffer); |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 399 | |
| 400 | if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) |
| 401 | usb_free_coherent( |
| 402 | urb->dev, |
| 403 | urb->transfer_buffer_length + offset, |
| 404 | urb->transfer_buffer - offset, |
| 405 | urb->transfer_dma - offset); |
| 406 | else |
| 407 | kfree(urb->transfer_buffer - offset); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 408 | usb_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 411 | static int simple_io( |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 412 | struct usbtest_dev *tdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | struct urb *urb, |
| 414 | int iterations, |
| 415 | int vary, |
| 416 | int expected, |
| 417 | const char *label |
| 418 | ) |
| 419 | { |
| 420 | struct usb_device *udev = urb->dev; |
| 421 | int max = urb->transfer_buffer_length; |
| 422 | struct completion completion; |
| 423 | int retval = 0; |
Roger Quadros | e5e4746 | 2013-12-18 15:40:10 +0530 | [diff] [blame] | 424 | unsigned long expire; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | urb->context = &completion; |
| 427 | while (retval == 0 && iterations-- > 0) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 428 | init_completion(&completion); |
Sebastian Andrzej Siewior | 7c79d09 | 2011-08-23 10:44:54 +0200 | [diff] [blame] | 429 | if (usb_pipeout(urb->pipe)) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 430 | simple_fill_buf(urb); |
Sebastian Andrzej Siewior | 7c79d09 | 2011-08-23 10:44:54 +0200 | [diff] [blame] | 431 | urb->transfer_flags |= URB_ZERO_PACKET; |
| 432 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 433 | retval = usb_submit_urb(urb, GFP_KERNEL); |
| 434 | if (retval != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | break; |
| 436 | |
Roger Quadros | e5e4746 | 2013-12-18 15:40:10 +0530 | [diff] [blame] | 437 | expire = msecs_to_jiffies(SIMPLE_IO_TIMEOUT); |
| 438 | if (!wait_for_completion_timeout(&completion, expire)) { |
| 439 | usb_kill_urb(urb); |
| 440 | retval = (urb->status == -ENOENT ? |
| 441 | -ETIMEDOUT : urb->status); |
| 442 | } else { |
| 443 | retval = urb->status; |
| 444 | } |
| 445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | urb->dev = udev; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 447 | if (retval == 0 && usb_pipein(urb->pipe)) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 448 | retval = simple_check_buf(tdev, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | if (vary) { |
| 451 | int len = urb->transfer_buffer_length; |
| 452 | |
| 453 | len += vary; |
| 454 | len %= max; |
| 455 | if (len == 0) |
| 456 | len = (vary < max) ? vary : max; |
| 457 | urb->transfer_buffer_length = len; |
| 458 | } |
| 459 | |
| 460 | /* FIXME if endpoint halted, clear halt (and log) */ |
| 461 | } |
| 462 | urb->transfer_buffer_length = max; |
| 463 | |
| 464 | if (expected != retval) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 465 | dev_err(&udev->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | "%s failed, iterations left %d, status %d (not %d)\n", |
| 467 | label, iterations, retval, expected); |
| 468 | return retval; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | /*-------------------------------------------------------------------------*/ |
| 473 | |
| 474 | /* We use scatterlist primitives to test queued I/O. |
| 475 | * Yes, this also tests the scatterlist primitives. |
| 476 | */ |
| 477 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 478 | static void free_sglist(struct scatterlist *sg, int nents) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
| 480 | unsigned i; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | if (!sg) |
| 483 | return; |
| 484 | for (i = 0; i < nents; i++) { |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 485 | if (!sg_page(&sg[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | continue; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 487 | kfree(sg_virt(&sg[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 489 | kfree(sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static struct scatterlist * |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 493 | alloc_sglist(int nents, int max, int vary, struct usbtest_dev *dev, int pipe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { |
| 495 | struct scatterlist *sg; |
| 496 | unsigned i; |
| 497 | unsigned size = max; |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 498 | unsigned maxpacket = |
| 499 | get_maxpacket(interface_to_usbdev(dev->intf), pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Dan Carpenter | 564e698 | 2012-11-17 18:06:11 +0300 | [diff] [blame] | 501 | if (max == 0) |
| 502 | return NULL; |
| 503 | |
Huang Rui | f55055b | 2013-10-21 23:15:30 +0800 | [diff] [blame] | 504 | sg = kmalloc_array(nents, sizeof(*sg), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | if (!sg) |
| 506 | return NULL; |
Alan Stern | 4756feb | 2008-03-27 10:15:22 -0400 | [diff] [blame] | 507 | sg_init_table(sg, nents); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | for (i = 0; i < nents; i++) { |
| 510 | char *buf; |
David Brownell | 8b52490 | 2006-04-02 10:20:15 -0800 | [diff] [blame] | 511 | unsigned j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 513 | buf = kzalloc(size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | if (!buf) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 515 | free_sglist(sg, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | return NULL; |
| 517 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | /* kmalloc pages are always physically contiguous! */ |
Alan Stern | 4756feb | 2008-03-27 10:15:22 -0400 | [diff] [blame] | 520 | sg_set_buf(&sg[i], buf, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
David Brownell | 8b52490 | 2006-04-02 10:20:15 -0800 | [diff] [blame] | 522 | switch (pattern) { |
| 523 | case 0: |
| 524 | /* already zeroed */ |
| 525 | break; |
| 526 | case 1: |
| 527 | for (j = 0; j < size; j++) |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 528 | *buf++ = (u8) ((j % maxpacket) % 63); |
David Brownell | 8b52490 | 2006-04-02 10:20:15 -0800 | [diff] [blame] | 529 | break; |
| 530 | } |
| 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | if (vary) { |
| 533 | size += vary; |
| 534 | size %= max; |
| 535 | if (size == 0) |
| 536 | size = (vary < max) ? vary : max; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | return sg; |
| 541 | } |
| 542 | |
Alan Stern | 32b36ee | 2014-06-03 11:11:34 -0400 | [diff] [blame] | 543 | static void sg_timeout(unsigned long _req) |
| 544 | { |
| 545 | struct usb_sg_request *req = (struct usb_sg_request *) _req; |
| 546 | |
| 547 | req->status = -ETIMEDOUT; |
| 548 | usb_sg_cancel(req); |
| 549 | } |
| 550 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 551 | static int perform_sglist( |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 552 | struct usbtest_dev *tdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | unsigned iterations, |
| 554 | int pipe, |
| 555 | struct usb_sg_request *req, |
| 556 | struct scatterlist *sg, |
| 557 | int nents |
| 558 | ) |
| 559 | { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 560 | struct usb_device *udev = testdev_to_usbdev(tdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | int retval = 0; |
Alan Stern | 32b36ee | 2014-06-03 11:11:34 -0400 | [diff] [blame] | 562 | struct timer_list sg_timer; |
| 563 | |
| 564 | setup_timer_on_stack(&sg_timer, sg_timeout, (unsigned long) req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
| 566 | while (retval == 0 && iterations-- > 0) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 567 | retval = usb_sg_init(req, udev, pipe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | (udev->speed == USB_SPEED_HIGH) |
| 569 | ? (INTERRUPT_RATE << 3) |
| 570 | : INTERRUPT_RATE, |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 571 | sg, nents, 0, GFP_KERNEL); |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | if (retval) |
| 574 | break; |
Alan Stern | 32b36ee | 2014-06-03 11:11:34 -0400 | [diff] [blame] | 575 | mod_timer(&sg_timer, jiffies + |
| 576 | msecs_to_jiffies(SIMPLE_IO_TIMEOUT)); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 577 | usb_sg_wait(req); |
Alan Stern | 32b36ee | 2014-06-03 11:11:34 -0400 | [diff] [blame] | 578 | del_timer_sync(&sg_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | retval = req->status; |
| 580 | |
David Brownell | 8b52490 | 2006-04-02 10:20:15 -0800 | [diff] [blame] | 581 | /* FIXME check resulting data pattern */ |
| 582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | /* FIXME if endpoint halted, clear halt (and log) */ |
| 584 | } |
| 585 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 586 | /* FIXME for unlink or fault handling tests, don't report |
| 587 | * failure if retval is as we expected ... |
| 588 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (retval) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 590 | ERROR(tdev, "perform_sglist failed, " |
| 591 | "iterations left %d, status %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | iterations, retval); |
| 593 | return retval; |
| 594 | } |
| 595 | |
| 596 | |
| 597 | /*-------------------------------------------------------------------------*/ |
| 598 | |
| 599 | /* unqueued control message testing |
| 600 | * |
| 601 | * there's a nice set of device functional requirements in chapter 9 of the |
| 602 | * usb 2.0 spec, which we can apply to ANY device, even ones that don't use |
| 603 | * special test firmware. |
| 604 | * |
| 605 | * we know the device is configured (or suspended) by the time it's visible |
| 606 | * through usbfs. we can't change that, so we won't test enumeration (which |
| 607 | * worked 'well enough' to get here, this time), power management (ditto), |
| 608 | * or remote wakeup (which needs human interaction). |
| 609 | */ |
| 610 | |
| 611 | static unsigned realworld = 1; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 612 | module_param(realworld, uint, 0); |
| 613 | MODULE_PARM_DESC(realworld, "clear to demand stricter spec compliance"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 615 | static int get_altsetting(struct usbtest_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
| 617 | struct usb_interface *iface = dev->intf; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 618 | struct usb_device *udev = interface_to_usbdev(iface); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | int retval; |
| 620 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 621 | retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 623 | 0, iface->altsetting[0].desc.bInterfaceNumber, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | dev->buf, 1, USB_CTRL_GET_TIMEOUT); |
| 625 | switch (retval) { |
| 626 | case 1: |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 627 | return dev->buf[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | case 0: |
| 629 | retval = -ERANGE; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 630 | /* FALLTHROUGH */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | default: |
| 632 | return retval; |
| 633 | } |
| 634 | } |
| 635 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 636 | static int set_altsetting(struct usbtest_dev *dev, int alternate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | { |
| 638 | struct usb_interface *iface = dev->intf; |
| 639 | struct usb_device *udev; |
| 640 | |
| 641 | if (alternate < 0 || alternate >= 256) |
| 642 | return -EINVAL; |
| 643 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 644 | udev = interface_to_usbdev(iface); |
| 645 | return usb_set_interface(udev, |
| 646 | iface->altsetting[0].desc.bInterfaceNumber, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | alternate); |
| 648 | } |
| 649 | |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 650 | static int is_good_config(struct usbtest_dev *tdev, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
| 652 | struct usb_config_descriptor *config; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 653 | |
Huang Rui | f55055b | 2013-10-21 23:15:30 +0800 | [diff] [blame] | 654 | if (len < sizeof(*config)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | return 0; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 656 | config = (struct usb_config_descriptor *) tdev->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
| 658 | switch (config->bDescriptorType) { |
| 659 | case USB_DT_CONFIG: |
| 660 | case USB_DT_OTHER_SPEED_CONFIG: |
| 661 | if (config->bLength != 9) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 662 | ERROR(tdev, "bogus config descriptor length\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | return 0; |
| 664 | } |
| 665 | /* this bit 'must be 1' but often isn't */ |
| 666 | if (!realworld && !(config->bmAttributes & 0x80)) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 667 | ERROR(tdev, "high bit of config attributes not set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | return 0; |
| 669 | } |
| 670 | if (config->bmAttributes & 0x1f) { /* reserved == 0 */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 671 | ERROR(tdev, "reserved config bits set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return 0; |
| 673 | } |
| 674 | break; |
| 675 | default: |
| 676 | return 0; |
| 677 | } |
| 678 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 679 | if (le16_to_cpu(config->wTotalLength) == len) /* read it all */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | return 1; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 681 | if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | return 1; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 683 | ERROR(tdev, "bogus config descriptor read size\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
Huang Rui | 82f9267 | 2013-10-30 11:27:38 +0800 | [diff] [blame] | 687 | static int is_good_ext(struct usbtest_dev *tdev, u8 *buf) |
| 688 | { |
| 689 | struct usb_ext_cap_descriptor *ext; |
| 690 | u32 attr; |
| 691 | |
| 692 | ext = (struct usb_ext_cap_descriptor *) buf; |
| 693 | |
| 694 | if (ext->bLength != USB_DT_USB_EXT_CAP_SIZE) { |
| 695 | ERROR(tdev, "bogus usb 2.0 extension descriptor length\n"); |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | attr = le32_to_cpu(ext->bmAttributes); |
Huang Rui | 875bc23 | 2013-11-13 22:35:14 +0800 | [diff] [blame] | 700 | /* bits[1:15] is used and others are reserved */ |
| 701 | if (attr & ~0xfffe) { /* reserved == 0 */ |
Huang Rui | 82f9267 | 2013-10-30 11:27:38 +0800 | [diff] [blame] | 702 | ERROR(tdev, "reserved bits set\n"); |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | return 1; |
| 707 | } |
| 708 | |
Huang Rui | b8fef79 | 2013-10-30 11:27:39 +0800 | [diff] [blame] | 709 | static int is_good_ss_cap(struct usbtest_dev *tdev, u8 *buf) |
| 710 | { |
| 711 | struct usb_ss_cap_descriptor *ss; |
| 712 | |
| 713 | ss = (struct usb_ss_cap_descriptor *) buf; |
| 714 | |
| 715 | if (ss->bLength != USB_DT_USB_SS_CAP_SIZE) { |
| 716 | ERROR(tdev, "bogus superspeed device capability descriptor length\n"); |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | /* |
| 721 | * only bit[1] of bmAttributes is used for LTM and others are |
| 722 | * reserved |
| 723 | */ |
| 724 | if (ss->bmAttributes & ~0x02) { /* reserved == 0 */ |
| 725 | ERROR(tdev, "reserved bits set in bmAttributes\n"); |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | /* bits[0:3] of wSpeedSupported is used and others are reserved */ |
| 730 | if (le16_to_cpu(ss->wSpeedSupported) & ~0x0f) { /* reserved == 0 */ |
| 731 | ERROR(tdev, "reserved bits set in wSpeedSupported\n"); |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | return 1; |
| 736 | } |
| 737 | |
Huang Rui | 8e29217 | 2013-10-30 11:27:40 +0800 | [diff] [blame] | 738 | static int is_good_con_id(struct usbtest_dev *tdev, u8 *buf) |
| 739 | { |
| 740 | struct usb_ss_container_id_descriptor *con_id; |
| 741 | |
| 742 | con_id = (struct usb_ss_container_id_descriptor *) buf; |
| 743 | |
| 744 | if (con_id->bLength != USB_DT_USB_SS_CONTN_ID_SIZE) { |
| 745 | ERROR(tdev, "bogus container id descriptor length\n"); |
| 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | if (con_id->bReserved) { /* reserved == 0 */ |
| 750 | ERROR(tdev, "reserved bits set\n"); |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | return 1; |
| 755 | } |
| 756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | /* sanity test for standard requests working with usb_control_mesg() and some |
| 758 | * of the utility functions which use it. |
| 759 | * |
| 760 | * this doesn't test how endpoint halts behave or data toggles get set, since |
| 761 | * we won't do I/O to bulk/interrupt endpoints here (which is how to change |
| 762 | * halt or toggle). toggle testing is impractical without support from hcds. |
| 763 | * |
| 764 | * this avoids failing devices linux would normally work with, by not testing |
| 765 | * config/altsetting operations for devices that only support their defaults. |
| 766 | * such devices rarely support those needless operations. |
| 767 | * |
| 768 | * NOTE that since this is a sanity test, it's not examining boundary cases |
| 769 | * to see if usbcore, hcd, and device all behave right. such testing would |
| 770 | * involve varied read sizes and other operation sequences. |
| 771 | */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 772 | static int ch9_postconfig(struct usbtest_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | { |
| 774 | struct usb_interface *iface = dev->intf; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 775 | struct usb_device *udev = interface_to_usbdev(iface); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | int i, alt, retval; |
| 777 | |
| 778 | /* [9.2.3] if there's more than one altsetting, we need to be able to |
| 779 | * set and get each one. mostly trusts the descriptors from usbcore. |
| 780 | */ |
| 781 | for (i = 0; i < iface->num_altsetting; i++) { |
| 782 | |
| 783 | /* 9.2.3 constrains the range here */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 784 | alt = iface->altsetting[i].desc.bAlternateSetting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | if (alt < 0 || alt >= iface->num_altsetting) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 786 | dev_err(&iface->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | "invalid alt [%d].bAltSetting = %d\n", |
| 788 | i, alt); |
| 789 | } |
| 790 | |
| 791 | /* [real world] get/set unimplemented if there's only one */ |
| 792 | if (realworld && iface->num_altsetting == 1) |
| 793 | continue; |
| 794 | |
| 795 | /* [9.4.10] set_interface */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 796 | retval = set_altsetting(dev, alt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | if (retval) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 798 | dev_err(&iface->dev, "can't set_interface = %d, %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | alt, retval); |
| 800 | return retval; |
| 801 | } |
| 802 | |
| 803 | /* [9.4.4] get_interface always works */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 804 | retval = get_altsetting(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | if (retval != alt) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 806 | dev_err(&iface->dev, "get alt should be %d, was %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | alt, retval); |
| 808 | return (retval < 0) ? retval : -EDOM; |
| 809 | } |
| 810 | |
| 811 | } |
| 812 | |
| 813 | /* [real world] get_config unimplemented if there's only one */ |
| 814 | if (!realworld || udev->descriptor.bNumConfigurations != 1) { |
| 815 | int expected = udev->actconfig->desc.bConfigurationValue; |
| 816 | |
| 817 | /* [9.4.2] get_configuration always works |
| 818 | * ... although some cheap devices (like one TI Hub I've got) |
| 819 | * won't return config descriptors except before set_config. |
| 820 | */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 821 | retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | USB_REQ_GET_CONFIGURATION, |
| 823 | USB_DIR_IN | USB_RECIP_DEVICE, |
| 824 | 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 825 | if (retval != 1 || dev->buf[0] != expected) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 826 | dev_err(&iface->dev, "get config --> %d %d (1 %d)\n", |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 827 | retval, dev->buf[0], expected); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | return (retval < 0) ? retval : -EDOM; |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | /* there's always [9.4.3] a device descriptor [9.6.1] */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 833 | retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0, |
Huang Rui | f55055b | 2013-10-21 23:15:30 +0800 | [diff] [blame] | 834 | dev->buf, sizeof(udev->descriptor)); |
| 835 | if (retval != sizeof(udev->descriptor)) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 836 | dev_err(&iface->dev, "dev descriptor --> %d\n", retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | return (retval < 0) ? retval : -EDOM; |
| 838 | } |
| 839 | |
Huang Rui | 9d3bd76 | 2013-10-28 23:31:32 +0800 | [diff] [blame] | 840 | /* |
| 841 | * there's always [9.4.3] a bos device descriptor [9.6.2] in USB |
| 842 | * 3.0 spec |
| 843 | */ |
Huang Rui | f625099 | 2013-11-13 22:35:13 +0800 | [diff] [blame] | 844 | if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0210) { |
Huang Rui | 82f9267 | 2013-10-30 11:27:38 +0800 | [diff] [blame] | 845 | struct usb_bos_descriptor *bos = NULL; |
| 846 | struct usb_dev_cap_header *header = NULL; |
| 847 | unsigned total, num, length; |
| 848 | u8 *buf; |
| 849 | |
Huang Rui | 9d3bd76 | 2013-10-28 23:31:32 +0800 | [diff] [blame] | 850 | retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, |
| 851 | sizeof(*udev->bos->desc)); |
| 852 | if (retval != sizeof(*udev->bos->desc)) { |
| 853 | dev_err(&iface->dev, "bos descriptor --> %d\n", retval); |
| 854 | return (retval < 0) ? retval : -EDOM; |
| 855 | } |
Huang Rui | 82f9267 | 2013-10-30 11:27:38 +0800 | [diff] [blame] | 856 | |
| 857 | bos = (struct usb_bos_descriptor *)dev->buf; |
| 858 | total = le16_to_cpu(bos->wTotalLength); |
| 859 | num = bos->bNumDeviceCaps; |
| 860 | |
| 861 | if (total > TBUF_SIZE) |
| 862 | total = TBUF_SIZE; |
| 863 | |
| 864 | /* |
| 865 | * get generic device-level capability descriptors [9.6.2] |
| 866 | * in USB 3.0 spec |
| 867 | */ |
| 868 | retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, |
| 869 | total); |
| 870 | if (retval != total) { |
| 871 | dev_err(&iface->dev, "bos descriptor set --> %d\n", |
| 872 | retval); |
| 873 | return (retval < 0) ? retval : -EDOM; |
| 874 | } |
| 875 | |
| 876 | length = sizeof(*udev->bos->desc); |
| 877 | buf = dev->buf; |
| 878 | for (i = 0; i < num; i++) { |
| 879 | buf += length; |
| 880 | if (buf + sizeof(struct usb_dev_cap_header) > |
| 881 | dev->buf + total) |
| 882 | break; |
| 883 | |
| 884 | header = (struct usb_dev_cap_header *)buf; |
| 885 | length = header->bLength; |
| 886 | |
| 887 | if (header->bDescriptorType != |
| 888 | USB_DT_DEVICE_CAPABILITY) { |
| 889 | dev_warn(&udev->dev, "not device capability descriptor, skip\n"); |
| 890 | continue; |
| 891 | } |
| 892 | |
| 893 | switch (header->bDevCapabilityType) { |
| 894 | case USB_CAP_TYPE_EXT: |
| 895 | if (buf + USB_DT_USB_EXT_CAP_SIZE > |
| 896 | dev->buf + total || |
| 897 | !is_good_ext(dev, buf)) { |
| 898 | dev_err(&iface->dev, "bogus usb 2.0 extension descriptor\n"); |
| 899 | return -EDOM; |
| 900 | } |
| 901 | break; |
Huang Rui | b8fef79 | 2013-10-30 11:27:39 +0800 | [diff] [blame] | 902 | case USB_SS_CAP_TYPE: |
| 903 | if (buf + USB_DT_USB_SS_CAP_SIZE > |
| 904 | dev->buf + total || |
| 905 | !is_good_ss_cap(dev, buf)) { |
| 906 | dev_err(&iface->dev, "bogus superspeed device capability descriptor\n"); |
| 907 | return -EDOM; |
| 908 | } |
| 909 | break; |
Huang Rui | 8e29217 | 2013-10-30 11:27:40 +0800 | [diff] [blame] | 910 | case CONTAINER_ID_TYPE: |
| 911 | if (buf + USB_DT_USB_SS_CONTN_ID_SIZE > |
| 912 | dev->buf + total || |
| 913 | !is_good_con_id(dev, buf)) { |
| 914 | dev_err(&iface->dev, "bogus container id descriptor\n"); |
| 915 | return -EDOM; |
| 916 | } |
| 917 | break; |
Huang Rui | 82f9267 | 2013-10-30 11:27:38 +0800 | [diff] [blame] | 918 | default: |
| 919 | break; |
| 920 | } |
| 921 | } |
Huang Rui | 9d3bd76 | 2013-10-28 23:31:32 +0800 | [diff] [blame] | 922 | } |
| 923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | /* there's always [9.4.3] at least one config descriptor [9.6.3] */ |
| 925 | for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 926 | retval = usb_get_descriptor(udev, USB_DT_CONFIG, i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | dev->buf, TBUF_SIZE); |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 928 | if (!is_good_config(dev, retval)) { |
| 929 | dev_err(&iface->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | "config [%d] descriptor --> %d\n", |
| 931 | i, retval); |
| 932 | return (retval < 0) ? retval : -EDOM; |
| 933 | } |
| 934 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 935 | /* FIXME cross-checking udev->config[i] to make sure usbcore |
| 936 | * parsed it right (etc) would be good testing paranoia |
| 937 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /* and sometimes [9.2.6.6] speed dependent descriptors */ |
| 941 | if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 942 | struct usb_qualifier_descriptor *d = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
| 944 | /* device qualifier [9.6.2] */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 945 | retval = usb_get_descriptor(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | USB_DT_DEVICE_QUALIFIER, 0, dev->buf, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 947 | sizeof(struct usb_qualifier_descriptor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | if (retval == -EPIPE) { |
| 949 | if (udev->speed == USB_SPEED_HIGH) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 950 | dev_err(&iface->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | "hs dev qualifier --> %d\n", |
| 952 | retval); |
| 953 | return (retval < 0) ? retval : -EDOM; |
| 954 | } |
| 955 | /* usb2.0 but not high-speed capable; fine */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 956 | } else if (retval != sizeof(struct usb_qualifier_descriptor)) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 957 | dev_err(&iface->dev, "dev qualifier --> %d\n", retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | return (retval < 0) ? retval : -EDOM; |
| 959 | } else |
| 960 | d = (struct usb_qualifier_descriptor *) dev->buf; |
| 961 | |
| 962 | /* might not have [9.6.2] any other-speed configs [9.6.4] */ |
| 963 | if (d) { |
| 964 | unsigned max = d->bNumConfigurations; |
| 965 | for (i = 0; i < max; i++) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 966 | retval = usb_get_descriptor(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | USB_DT_OTHER_SPEED_CONFIG, i, |
| 968 | dev->buf, TBUF_SIZE); |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 969 | if (!is_good_config(dev, retval)) { |
| 970 | dev_err(&iface->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | "other speed config --> %d\n", |
| 972 | retval); |
| 973 | return (retval < 0) ? retval : -EDOM; |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 978 | /* FIXME fetch strings from at least the device descriptor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
| 980 | /* [9.4.5] get_status always works */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 981 | retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf); |
Alan Stern | 15b7336 | 2013-07-30 15:35:40 -0400 | [diff] [blame] | 982 | if (retval) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 983 | dev_err(&iface->dev, "get dev status --> %d\n", retval); |
Alan Stern | 15b7336 | 2013-07-30 15:35:40 -0400 | [diff] [blame] | 984 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 987 | /* FIXME configuration.bmAttributes says if we could try to set/clear |
| 988 | * the device's remote wakeup feature ... if we can, test that here |
| 989 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 991 | retval = usb_get_status(udev, USB_RECIP_INTERFACE, |
| 992 | iface->altsetting[0].desc.bInterfaceNumber, dev->buf); |
Alan Stern | 15b7336 | 2013-07-30 15:35:40 -0400 | [diff] [blame] | 993 | if (retval) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 994 | dev_err(&iface->dev, "get interface status --> %d\n", retval); |
Alan Stern | 15b7336 | 2013-07-30 15:35:40 -0400 | [diff] [blame] | 995 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 997 | /* FIXME get status for each endpoint in the interface */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | /*-------------------------------------------------------------------------*/ |
| 1003 | |
| 1004 | /* use ch9 requests to test whether: |
| 1005 | * (a) queues work for control, keeping N subtests queued and |
| 1006 | * active (auto-resubmit) for M loops through the queue. |
| 1007 | * (b) protocol stalls (control-only) will autorecover. |
| 1008 | * it's not like bulk/intr; no halt clearing. |
| 1009 | * (c) short control reads are reported and handled. |
| 1010 | * (d) queues are always processed in-order |
| 1011 | */ |
| 1012 | |
| 1013 | struct ctrl_ctx { |
| 1014 | spinlock_t lock; |
| 1015 | struct usbtest_dev *dev; |
| 1016 | struct completion complete; |
| 1017 | unsigned count; |
| 1018 | unsigned pending; |
| 1019 | int status; |
| 1020 | struct urb **urb; |
| 1021 | struct usbtest_param *param; |
| 1022 | int last; |
| 1023 | }; |
| 1024 | |
Huang Rui | c952a8b | 2013-11-04 21:11:53 +0800 | [diff] [blame] | 1025 | #define NUM_SUBCASES 16 /* how many test subcases here? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | |
| 1027 | struct subcase { |
| 1028 | struct usb_ctrlrequest setup; |
| 1029 | int number; |
| 1030 | int expected; |
| 1031 | }; |
| 1032 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1033 | static void ctrl_complete(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | { |
| 1035 | struct ctrl_ctx *ctx = urb->context; |
| 1036 | struct usb_ctrlrequest *reqp; |
| 1037 | struct subcase *subcase; |
| 1038 | int status = urb->status; |
| 1039 | |
| 1040 | reqp = (struct usb_ctrlrequest *)urb->setup_packet; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1041 | subcase = container_of(reqp, struct subcase, setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1043 | spin_lock(&ctx->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | ctx->count--; |
| 1045 | ctx->pending--; |
| 1046 | |
| 1047 | /* queue must transfer and complete in fifo order, unless |
| 1048 | * usb_unlink_urb() is used to unlink something not at the |
| 1049 | * physical queue head (not tested). |
| 1050 | */ |
| 1051 | if (subcase->number > 0) { |
| 1052 | if ((subcase->number - ctx->last) != 1) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1053 | ERROR(ctx->dev, |
| 1054 | "subcase %d completed out of order, last %d\n", |
| 1055 | subcase->number, ctx->last); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | status = -EDOM; |
| 1057 | ctx->last = subcase->number; |
| 1058 | goto error; |
| 1059 | } |
| 1060 | } |
| 1061 | ctx->last = subcase->number; |
| 1062 | |
| 1063 | /* succeed or fault in only one way? */ |
| 1064 | if (status == subcase->expected) |
| 1065 | status = 0; |
| 1066 | |
| 1067 | /* async unlink for cleanup? */ |
| 1068 | else if (status != -ECONNRESET) { |
| 1069 | |
| 1070 | /* some faults are allowed, not required */ |
| 1071 | if (subcase->expected > 0 && ( |
Greg Kroah-Hartman | 59d9978 | 2007-07-18 10:58:02 -0700 | [diff] [blame] | 1072 | ((status == -subcase->expected /* happened */ |
| 1073 | || status == 0)))) /* didn't */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | status = 0; |
| 1075 | /* sometimes more than one fault is allowed */ |
| 1076 | else if (subcase->number == 12 && status == -EPIPE) |
| 1077 | status = 0; |
| 1078 | else |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1079 | ERROR(ctx->dev, "subtest %d error, status %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | subcase->number, status); |
| 1081 | } |
| 1082 | |
| 1083 | /* unexpected status codes mean errors; ideally, in hardware */ |
| 1084 | if (status) { |
| 1085 | error: |
| 1086 | if (ctx->status == 0) { |
| 1087 | int i; |
| 1088 | |
| 1089 | ctx->status = status; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1090 | ERROR(ctx->dev, "control queue %02x.%02x, err %d, " |
| 1091 | "%d left, subcase %d, len %d/%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | reqp->bRequestType, reqp->bRequest, |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1093 | status, ctx->count, subcase->number, |
| 1094 | urb->actual_length, |
| 1095 | urb->transfer_buffer_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* FIXME this "unlink everything" exit route should |
| 1098 | * be a separate test case. |
| 1099 | */ |
| 1100 | |
| 1101 | /* unlink whatever's still pending */ |
| 1102 | for (i = 1; i < ctx->param->sglen; i++) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1103 | struct urb *u = ctx->urb[ |
| 1104 | (i + subcase->number) |
| 1105 | % ctx->param->sglen]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
| 1107 | if (u == urb || !u->dev) |
| 1108 | continue; |
Franck Bui-Huu | caa2a12 | 2006-05-15 19:23:53 +0200 | [diff] [blame] | 1109 | spin_unlock(&ctx->lock); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1110 | status = usb_unlink_urb(u); |
Franck Bui-Huu | caa2a12 | 2006-05-15 19:23:53 +0200 | [diff] [blame] | 1111 | spin_lock(&ctx->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | switch (status) { |
| 1113 | case -EINPROGRESS: |
| 1114 | case -EBUSY: |
| 1115 | case -EIDRM: |
| 1116 | continue; |
| 1117 | default: |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1118 | ERROR(ctx->dev, "urb unlink --> %d\n", |
| 1119 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | } |
| 1121 | } |
| 1122 | status = ctx->status; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | /* resubmit if we need to, else mark this as done */ |
| 1127 | if ((status == 0) && (ctx->pending < ctx->count)) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1128 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 1129 | if (status != 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1130 | ERROR(ctx->dev, |
| 1131 | "can't resubmit ctrl %02x.%02x, err %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | reqp->bRequestType, reqp->bRequest, status); |
| 1133 | urb->dev = NULL; |
| 1134 | } else |
| 1135 | ctx->pending++; |
| 1136 | } else |
| 1137 | urb->dev = NULL; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | /* signal completion when nothing's queued */ |
| 1140 | if (ctx->pending == 0) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1141 | complete(&ctx->complete); |
| 1142 | spin_unlock(&ctx->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | static int |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1146 | test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1148 | struct usb_device *udev = testdev_to_usbdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | struct urb **urb; |
| 1150 | struct ctrl_ctx context; |
| 1151 | int i; |
| 1152 | |
Xi Wang | e65cdfa | 2012-04-09 15:48:55 -0400 | [diff] [blame] | 1153 | if (param->sglen == 0 || param->iterations > UINT_MAX / param->sglen) |
| 1154 | return -EOPNOTSUPP; |
| 1155 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1156 | spin_lock_init(&context.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | context.dev = dev; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1158 | init_completion(&context.complete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | context.count = param->sglen * param->iterations; |
| 1160 | context.pending = 0; |
| 1161 | context.status = -ENOMEM; |
| 1162 | context.param = param; |
| 1163 | context.last = -1; |
| 1164 | |
| 1165 | /* allocate and init the urbs we'll queue. |
| 1166 | * as with bulk/intr sglists, sglen is the queue depth; it also |
| 1167 | * controls which subtests run (more tests than sglen) or rerun. |
| 1168 | */ |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 1169 | urb = kcalloc(param->sglen, sizeof(struct urb *), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | if (!urb) |
| 1171 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | for (i = 0; i < param->sglen; i++) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1173 | int pipe = usb_rcvctrlpipe(udev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | unsigned len; |
| 1175 | struct urb *u; |
| 1176 | struct usb_ctrlrequest req; |
| 1177 | struct subcase *reqp; |
Marcin Slusarz | 6def755 | 2008-05-12 20:17:25 +0200 | [diff] [blame] | 1178 | |
| 1179 | /* sign of this variable means: |
| 1180 | * -: tested code must return this (negative) error code |
| 1181 | * +: tested code may return this (negative too) error code |
| 1182 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | int expected = 0; |
| 1184 | |
| 1185 | /* requests here are mostly expected to succeed on any |
| 1186 | * device, but some are chosen to trigger protocol stalls |
| 1187 | * or short reads. |
| 1188 | */ |
Huang Rui | f55055b | 2013-10-21 23:15:30 +0800 | [diff] [blame] | 1189 | memset(&req, 0, sizeof(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | req.bRequest = USB_REQ_GET_DESCRIPTOR; |
| 1191 | req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; |
| 1192 | |
| 1193 | switch (i % NUM_SUBCASES) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1194 | case 0: /* get device descriptor */ |
| 1195 | req.wValue = cpu_to_le16(USB_DT_DEVICE << 8); |
| 1196 | len = sizeof(struct usb_device_descriptor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1198 | case 1: /* get first config descriptor (only) */ |
| 1199 | req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0); |
| 1200 | len = sizeof(struct usb_config_descriptor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1202 | case 2: /* get altsetting (OFTEN STALLS) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | req.bRequest = USB_REQ_GET_INTERFACE; |
| 1204 | req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1205 | /* index = 0 means first interface */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | len = 1; |
| 1207 | expected = EPIPE; |
| 1208 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1209 | case 3: /* get interface status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | req.bRequest = USB_REQ_GET_STATUS; |
| 1211 | req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1212 | /* interface 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | len = 2; |
| 1214 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1215 | case 4: /* get device status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | req.bRequest = USB_REQ_GET_STATUS; |
| 1217 | req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; |
| 1218 | len = 2; |
| 1219 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1220 | case 5: /* get device qualifier (MAY STALL) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1222 | len = sizeof(struct usb_qualifier_descriptor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | if (udev->speed != USB_SPEED_HIGH) |
| 1224 | expected = EPIPE; |
| 1225 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1226 | case 6: /* get first config descriptor, plus interface */ |
| 1227 | req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0); |
| 1228 | len = sizeof(struct usb_config_descriptor); |
| 1229 | len += sizeof(struct usb_interface_descriptor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1231 | case 7: /* get interface descriptor (ALWAYS STALLS) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1233 | /* interface == 0 */ |
| 1234 | len = sizeof(struct usb_interface_descriptor); |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1235 | expected = -EPIPE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1237 | /* NOTE: two consecutive stalls in the queue here. |
| 1238 | * that tests fault recovery a bit more aggressively. */ |
| 1239 | case 8: /* clear endpoint halt (MAY STALL) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | req.bRequest = USB_REQ_CLEAR_FEATURE; |
| 1241 | req.bRequestType = USB_RECIP_ENDPOINT; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1242 | /* wValue 0 == ep halt */ |
| 1243 | /* wIndex 0 == ep0 (shouldn't halt!) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | len = 0; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1245 | pipe = usb_sndctrlpipe(udev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | expected = EPIPE; |
| 1247 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1248 | case 9: /* get endpoint status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | req.bRequest = USB_REQ_GET_STATUS; |
| 1250 | req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1251 | /* endpoint 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | len = 2; |
| 1253 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1254 | case 10: /* trigger short read (EREMOTEIO) */ |
| 1255 | req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | len = 1024; |
| 1257 | expected = -EREMOTEIO; |
| 1258 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1259 | /* NOTE: two consecutive _different_ faults in the queue. */ |
| 1260 | case 11: /* get endpoint descriptor (ALWAYS STALLS) */ |
| 1261 | req.wValue = cpu_to_le16(USB_DT_ENDPOINT << 8); |
| 1262 | /* endpoint == 0 */ |
| 1263 | len = sizeof(struct usb_interface_descriptor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | expected = EPIPE; |
| 1265 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1266 | /* NOTE: sometimes even a third fault in the queue! */ |
| 1267 | case 12: /* get string 0 descriptor (MAY STALL) */ |
| 1268 | req.wValue = cpu_to_le16(USB_DT_STRING << 8); |
| 1269 | /* string == 0, for language IDs */ |
| 1270 | len = sizeof(struct usb_interface_descriptor); |
| 1271 | /* may succeed when > 4 languages */ |
| 1272 | expected = EREMOTEIO; /* or EPIPE, if no strings */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1274 | case 13: /* short read, resembling case 10 */ |
| 1275 | req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0); |
| 1276 | /* last data packet "should" be DATA1, not DATA0 */ |
Paul Zimmerman | 6a23ccd | 2012-04-16 14:19:07 -0700 | [diff] [blame] | 1277 | if (udev->speed == USB_SPEED_SUPER) |
| 1278 | len = 1024 - 512; |
| 1279 | else |
| 1280 | len = 1024 - udev->descriptor.bMaxPacketSize0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | expected = -EREMOTEIO; |
| 1282 | break; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1283 | case 14: /* short read; try to fill the last packet */ |
| 1284 | req.wValue = cpu_to_le16((USB_DT_DEVICE << 8) | 0); |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1285 | /* device descriptor size == 18 bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | len = udev->descriptor.bMaxPacketSize0; |
Sebastian Andrzej Siewior | 67e7d64 | 2011-04-14 16:17:21 +0200 | [diff] [blame] | 1287 | if (udev->speed == USB_SPEED_SUPER) |
| 1288 | len = 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | switch (len) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1290 | case 8: |
| 1291 | len = 24; |
| 1292 | break; |
| 1293 | case 16: |
| 1294 | len = 32; |
| 1295 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | } |
| 1297 | expected = -EREMOTEIO; |
| 1298 | break; |
Huang Rui | c952a8b | 2013-11-04 21:11:53 +0800 | [diff] [blame] | 1299 | case 15: |
| 1300 | req.wValue = cpu_to_le16(USB_DT_BOS << 8); |
| 1301 | if (udev->bos) |
| 1302 | len = le16_to_cpu(udev->bos->desc->wTotalLength); |
| 1303 | else |
| 1304 | len = sizeof(struct usb_bos_descriptor); |
Sarah Sharp | 8cf4328 | 2013-12-13 13:44:17 -0800 | [diff] [blame] | 1305 | if (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0201) |
Huang Rui | c952a8b | 2013-11-04 21:11:53 +0800 | [diff] [blame] | 1306 | expected = -EPIPE; |
| 1307 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | default: |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1309 | ERROR(dev, "bogus number of ctrl queue testcases!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | context.status = -EINVAL; |
| 1311 | goto cleanup; |
| 1312 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1313 | req.wLength = cpu_to_le16(len); |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 1314 | urb[i] = u = simple_alloc_urb(udev, pipe, len, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | if (!u) |
| 1316 | goto cleanup; |
| 1317 | |
Huang Rui | f55055b | 2013-10-21 23:15:30 +0800 | [diff] [blame] | 1318 | reqp = kmalloc(sizeof(*reqp), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | if (!reqp) |
| 1320 | goto cleanup; |
| 1321 | reqp->setup = req; |
| 1322 | reqp->number = i % NUM_SUBCASES; |
| 1323 | reqp->expected = expected; |
| 1324 | u->setup_packet = (char *) &reqp->setup; |
| 1325 | |
| 1326 | u->context = &context; |
| 1327 | u->complete = ctrl_complete; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | /* queue the urbs */ |
| 1331 | context.urb = urb; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1332 | spin_lock_irq(&context.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | for (i = 0; i < param->sglen; i++) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1334 | context.status = usb_submit_urb(urb[i], GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | if (context.status != 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1336 | ERROR(dev, "can't submit urb[%d], status %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | i, context.status); |
| 1338 | context.count = context.pending; |
| 1339 | break; |
| 1340 | } |
| 1341 | context.pending++; |
| 1342 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1343 | spin_unlock_irq(&context.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | |
| 1345 | /* FIXME set timer and time out; provide a disconnect hook */ |
| 1346 | |
| 1347 | /* wait for the last one to complete */ |
| 1348 | if (context.pending > 0) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1349 | wait_for_completion(&context.complete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
| 1351 | cleanup: |
| 1352 | for (i = 0; i < param->sglen; i++) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1353 | if (!urb[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | continue; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1355 | urb[i]->dev = udev; |
Alan Stern | 0ede76f | 2010-03-05 15:10:17 -0500 | [diff] [blame] | 1356 | kfree(urb[i]->setup_packet); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1357 | simple_free_urb(urb[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1359 | kfree(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | return context.status; |
| 1361 | } |
| 1362 | #undef NUM_SUBCASES |
| 1363 | |
| 1364 | |
| 1365 | /*-------------------------------------------------------------------------*/ |
| 1366 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1367 | static void unlink1_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | { |
| 1369 | int status = urb->status; |
| 1370 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1371 | /* we "know" -EPIPE (stall) never happens */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | if (!status) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1373 | status = usb_submit_urb(urb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | if (status) { |
| 1375 | urb->status = status; |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 1376 | complete(urb->context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1380 | static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | { |
| 1382 | struct urb *urb; |
| 1383 | struct completion completion; |
| 1384 | int retval = 0; |
| 1385 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1386 | init_completion(&completion); |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 1387 | urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | if (!urb) |
| 1389 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | urb->context = &completion; |
| 1391 | urb->complete = unlink1_callback; |
| 1392 | |
Huang Rui | e4d58f5 | 2014-05-26 10:55:36 +0800 | [diff] [blame] | 1393 | if (usb_pipeout(urb->pipe)) { |
| 1394 | simple_fill_buf(urb); |
| 1395 | urb->transfer_flags |= URB_ZERO_PACKET; |
| 1396 | } |
| 1397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | /* keep the endpoint busy. there are lots of hc/hcd-internal |
| 1399 | * states, and testing should get to all of them over time. |
| 1400 | * |
| 1401 | * FIXME want additional tests for when endpoint is STALLing |
| 1402 | * due to errors, or is just NAKing requests. |
| 1403 | */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1404 | retval = usb_submit_urb(urb, GFP_KERNEL); |
| 1405 | if (retval != 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1406 | dev_err(&dev->intf->dev, "submit fail %d\n", retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | return retval; |
| 1408 | } |
| 1409 | |
| 1410 | /* unlinking that should always work. variable delay tests more |
| 1411 | * hcd states and code paths, even with little other system load. |
| 1412 | */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1413 | msleep(jiffies % (2 * INTERRUPT_RATE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | if (async) { |
Martin Fuzzey | 3b6c023 | 2009-06-04 23:20:38 +0200 | [diff] [blame] | 1415 | while (!completion_done(&completion)) { |
| 1416 | retval = usb_unlink_urb(urb); |
| 1417 | |
Huang Rui | a7683eb | 2014-05-22 18:06:14 +0800 | [diff] [blame] | 1418 | if (retval == 0 && usb_pipein(urb->pipe)) |
| 1419 | retval = simple_check_buf(dev, urb); |
| 1420 | |
Martin Fuzzey | 3b6c023 | 2009-06-04 23:20:38 +0200 | [diff] [blame] | 1421 | switch (retval) { |
| 1422 | case -EBUSY: |
| 1423 | case -EIDRM: |
| 1424 | /* we can't unlink urbs while they're completing |
| 1425 | * or if they've completed, and we haven't |
| 1426 | * resubmitted. "normal" drivers would prevent |
| 1427 | * resubmission, but since we're testing unlink |
| 1428 | * paths, we can't. |
| 1429 | */ |
| 1430 | ERROR(dev, "unlink retry\n"); |
| 1431 | continue; |
| 1432 | case 0: |
| 1433 | case -EINPROGRESS: |
| 1434 | break; |
| 1435 | |
| 1436 | default: |
| 1437 | dev_err(&dev->intf->dev, |
| 1438 | "unlink fail %d\n", retval); |
| 1439 | return retval; |
| 1440 | } |
| 1441 | |
| 1442 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | } |
| 1444 | } else |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1445 | usb_kill_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1447 | wait_for_completion(&completion); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | retval = urb->status; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1449 | simple_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | |
| 1451 | if (async) |
| 1452 | return (retval == -ECONNRESET) ? 0 : retval - 1000; |
| 1453 | else |
| 1454 | return (retval == -ENOENT || retval == -EPERM) ? |
| 1455 | 0 : retval - 2000; |
| 1456 | } |
| 1457 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1458 | static int unlink_simple(struct usbtest_dev *dev, int pipe, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | { |
| 1460 | int retval = 0; |
| 1461 | |
| 1462 | /* test sync and async paths */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1463 | retval = unlink1(dev, pipe, len, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | if (!retval) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1465 | retval = unlink1(dev, pipe, len, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | return retval; |
| 1467 | } |
| 1468 | |
| 1469 | /*-------------------------------------------------------------------------*/ |
| 1470 | |
Alan Stern | 869410f | 2011-04-14 11:21:04 -0400 | [diff] [blame] | 1471 | struct queued_ctx { |
| 1472 | struct completion complete; |
| 1473 | atomic_t pending; |
| 1474 | unsigned num; |
| 1475 | int status; |
| 1476 | struct urb **urbs; |
| 1477 | }; |
| 1478 | |
| 1479 | static void unlink_queued_callback(struct urb *urb) |
| 1480 | { |
| 1481 | int status = urb->status; |
| 1482 | struct queued_ctx *ctx = urb->context; |
| 1483 | |
| 1484 | if (ctx->status) |
| 1485 | goto done; |
| 1486 | if (urb == ctx->urbs[ctx->num - 4] || urb == ctx->urbs[ctx->num - 2]) { |
| 1487 | if (status == -ECONNRESET) |
| 1488 | goto done; |
| 1489 | /* What error should we report if the URB completed normally? */ |
| 1490 | } |
| 1491 | if (status != 0) |
| 1492 | ctx->status = status; |
| 1493 | |
| 1494 | done: |
| 1495 | if (atomic_dec_and_test(&ctx->pending)) |
| 1496 | complete(&ctx->complete); |
| 1497 | } |
| 1498 | |
| 1499 | static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num, |
| 1500 | unsigned size) |
| 1501 | { |
| 1502 | struct queued_ctx ctx; |
| 1503 | struct usb_device *udev = testdev_to_usbdev(dev); |
| 1504 | void *buf; |
| 1505 | dma_addr_t buf_dma; |
| 1506 | int i; |
| 1507 | int retval = -ENOMEM; |
| 1508 | |
| 1509 | init_completion(&ctx.complete); |
| 1510 | atomic_set(&ctx.pending, 1); /* One more than the actual value */ |
| 1511 | ctx.num = num; |
| 1512 | ctx.status = 0; |
| 1513 | |
| 1514 | buf = usb_alloc_coherent(udev, size, GFP_KERNEL, &buf_dma); |
| 1515 | if (!buf) |
| 1516 | return retval; |
| 1517 | memset(buf, 0, size); |
| 1518 | |
| 1519 | /* Allocate and init the urbs we'll queue */ |
| 1520 | ctx.urbs = kcalloc(num, sizeof(struct urb *), GFP_KERNEL); |
| 1521 | if (!ctx.urbs) |
| 1522 | goto free_buf; |
| 1523 | for (i = 0; i < num; i++) { |
| 1524 | ctx.urbs[i] = usb_alloc_urb(0, GFP_KERNEL); |
| 1525 | if (!ctx.urbs[i]) |
| 1526 | goto free_urbs; |
| 1527 | usb_fill_bulk_urb(ctx.urbs[i], udev, pipe, buf, size, |
| 1528 | unlink_queued_callback, &ctx); |
| 1529 | ctx.urbs[i]->transfer_dma = buf_dma; |
| 1530 | ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; |
Huang Rui | e4d58f5 | 2014-05-26 10:55:36 +0800 | [diff] [blame] | 1531 | |
| 1532 | if (usb_pipeout(ctx.urbs[i]->pipe)) { |
| 1533 | simple_fill_buf(ctx.urbs[i]); |
| 1534 | ctx.urbs[i]->transfer_flags |= URB_ZERO_PACKET; |
| 1535 | } |
Alan Stern | 869410f | 2011-04-14 11:21:04 -0400 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */ |
| 1539 | for (i = 0; i < num; i++) { |
| 1540 | atomic_inc(&ctx.pending); |
| 1541 | retval = usb_submit_urb(ctx.urbs[i], GFP_KERNEL); |
| 1542 | if (retval != 0) { |
| 1543 | dev_err(&dev->intf->dev, "submit urbs[%d] fail %d\n", |
| 1544 | i, retval); |
| 1545 | atomic_dec(&ctx.pending); |
| 1546 | ctx.status = retval; |
| 1547 | break; |
| 1548 | } |
| 1549 | } |
| 1550 | if (i == num) { |
| 1551 | usb_unlink_urb(ctx.urbs[num - 4]); |
| 1552 | usb_unlink_urb(ctx.urbs[num - 2]); |
| 1553 | } else { |
| 1554 | while (--i >= 0) |
| 1555 | usb_unlink_urb(ctx.urbs[i]); |
| 1556 | } |
| 1557 | |
| 1558 | if (atomic_dec_and_test(&ctx.pending)) /* The extra count */ |
| 1559 | complete(&ctx.complete); |
| 1560 | wait_for_completion(&ctx.complete); |
| 1561 | retval = ctx.status; |
| 1562 | |
| 1563 | free_urbs: |
| 1564 | for (i = 0; i < num; i++) |
| 1565 | usb_free_urb(ctx.urbs[i]); |
| 1566 | kfree(ctx.urbs); |
| 1567 | free_buf: |
| 1568 | usb_free_coherent(udev, size, buf, buf_dma); |
| 1569 | return retval; |
| 1570 | } |
| 1571 | |
| 1572 | /*-------------------------------------------------------------------------*/ |
| 1573 | |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1574 | static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | { |
| 1576 | int retval; |
| 1577 | u16 status; |
| 1578 | |
| 1579 | /* shouldn't look or act halted */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1580 | retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | if (retval < 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1582 | ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n", |
| 1583 | ep, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | return retval; |
| 1585 | } |
| 1586 | if (status != 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1587 | ERROR(tdev, "ep %02x bogus status: %04x != 0\n", ep, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | return -EINVAL; |
| 1589 | } |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1590 | retval = simple_io(tdev, urb, 1, 0, 0, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | if (retval != 0) |
| 1592 | return -EINVAL; |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1596 | static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | { |
| 1598 | int retval; |
| 1599 | u16 status; |
| 1600 | |
| 1601 | /* should look and act halted */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1602 | retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | if (retval < 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1604 | ERROR(tdev, "ep %02x couldn't get halt status, %d\n", |
| 1605 | ep, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | return retval; |
| 1607 | } |
| 1608 | if (status != 1) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1609 | ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | return -EINVAL; |
| 1611 | } |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1612 | retval = simple_io(tdev, urb, 1, 0, -EPIPE, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | if (retval != -EPIPE) |
| 1614 | return -EINVAL; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1615 | retval = simple_io(tdev, urb, 1, 0, -EPIPE, "verify_still_halted"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | if (retval != -EPIPE) |
| 1617 | return -EINVAL; |
| 1618 | return 0; |
| 1619 | } |
| 1620 | |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1621 | static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | { |
| 1623 | int retval; |
| 1624 | |
| 1625 | /* shouldn't look or act halted now */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1626 | retval = verify_not_halted(tdev, ep, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | if (retval < 0) |
| 1628 | return retval; |
| 1629 | |
| 1630 | /* set halt (protocol test only), verify it worked */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1631 | retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT, |
| 1633 | USB_ENDPOINT_HALT, ep, |
| 1634 | NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 1635 | if (retval < 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1636 | ERROR(tdev, "ep %02x couldn't set halt, %d\n", ep, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | return retval; |
| 1638 | } |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1639 | retval = verify_halted(tdev, ep, urb); |
Roger Quadros | 824d752 | 2013-12-18 15:40:11 +0530 | [diff] [blame] | 1640 | if (retval < 0) { |
| 1641 | int ret; |
| 1642 | |
| 1643 | /* clear halt anyways, else further tests will fail */ |
| 1644 | ret = usb_clear_halt(urb->dev, urb->pipe); |
| 1645 | if (ret) |
| 1646 | ERROR(tdev, "ep %02x couldn't clear halt, %d\n", |
| 1647 | ep, ret); |
| 1648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | return retval; |
Roger Quadros | 824d752 | 2013-12-18 15:40:11 +0530 | [diff] [blame] | 1650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
| 1652 | /* clear halt (tests API + protocol), verify it worked */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1653 | retval = usb_clear_halt(urb->dev, urb->pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | if (retval < 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1655 | ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | return retval; |
| 1657 | } |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1658 | retval = verify_not_halted(tdev, ep, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | if (retval < 0) |
| 1660 | return retval; |
| 1661 | |
| 1662 | /* NOTE: could also verify SET_INTERFACE clear halts ... */ |
| 1663 | |
| 1664 | return 0; |
| 1665 | } |
| 1666 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1667 | static int halt_simple(struct usbtest_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | { |
Paul Zimmerman | 6a23ccd | 2012-04-16 14:19:07 -0700 | [diff] [blame] | 1669 | int ep; |
| 1670 | int retval = 0; |
| 1671 | struct urb *urb; |
| 1672 | struct usb_device *udev = testdev_to_usbdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | |
Paul Zimmerman | 6a23ccd | 2012-04-16 14:19:07 -0700 | [diff] [blame] | 1674 | if (udev->speed == USB_SPEED_SUPER) |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 1675 | urb = simple_alloc_urb(udev, 0, 1024, 0); |
Paul Zimmerman | 6a23ccd | 2012-04-16 14:19:07 -0700 | [diff] [blame] | 1676 | else |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 1677 | urb = simple_alloc_urb(udev, 0, 512, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | if (urb == NULL) |
| 1679 | return -ENOMEM; |
| 1680 | |
| 1681 | if (dev->in_pipe) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1682 | ep = usb_pipeendpoint(dev->in_pipe) | USB_DIR_IN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | urb->pipe = dev->in_pipe; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1684 | retval = test_halt(dev, ep, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | if (retval < 0) |
| 1686 | goto done; |
| 1687 | } |
| 1688 | |
| 1689 | if (dev->out_pipe) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1690 | ep = usb_pipeendpoint(dev->out_pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | urb->pipe = dev->out_pipe; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1692 | retval = test_halt(dev, ep, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | } |
| 1694 | done: |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1695 | simple_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | return retval; |
| 1697 | } |
| 1698 | |
| 1699 | /*-------------------------------------------------------------------------*/ |
| 1700 | |
| 1701 | /* Control OUT tests use the vendor control requests from Intel's |
| 1702 | * USB 2.0 compliance test device: write a buffer, read it back. |
| 1703 | * |
| 1704 | * Intel's spec only _requires_ that it work for one packet, which |
| 1705 | * is pretty weak. Some HCDs place limits here; most devices will |
| 1706 | * need to be able to handle more than one OUT data packet. We'll |
| 1707 | * try whatever we're told to try. |
| 1708 | */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1709 | static int ctrl_out(struct usbtest_dev *dev, |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1710 | unsigned count, unsigned length, unsigned vary, unsigned offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | { |
Orjan Friberg | f54fa84 | 2006-08-08 23:31:40 -0700 | [diff] [blame] | 1712 | unsigned i, j, len; |
| 1713 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | u8 *buf; |
| 1715 | char *what = "?"; |
| 1716 | struct usb_device *udev; |
Orjan Friberg | f54fa84 | 2006-08-08 23:31:40 -0700 | [diff] [blame] | 1717 | |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 1718 | if (length < 1 || length > 0xffff || vary >= length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | return -EINVAL; |
| 1720 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1721 | buf = kmalloc(length + offset, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | if (!buf) |
| 1723 | return -ENOMEM; |
| 1724 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1725 | buf += offset; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1726 | udev = testdev_to_usbdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | len = length; |
| 1728 | retval = 0; |
| 1729 | |
| 1730 | /* NOTE: hardware might well act differently if we pushed it |
| 1731 | * with lots back-to-back queued requests. |
| 1732 | */ |
| 1733 | for (i = 0; i < count; i++) { |
| 1734 | /* write patterned data */ |
| 1735 | for (j = 0; j < len; j++) |
Peter Chen | 169900f | 2015-09-01 09:48:00 +0800 | [diff] [blame] | 1736 | buf[j] = (u8)(i + j); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1737 | retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR, |
| 1739 | 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); |
| 1740 | if (retval != len) { |
| 1741 | what = "write"; |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 1742 | if (retval >= 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1743 | ERROR(dev, "ctrl_out, wlen %d (expected %d)\n", |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 1744 | retval, len); |
| 1745 | retval = -EBADMSG; |
| 1746 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | break; |
| 1748 | } |
| 1749 | |
| 1750 | /* read it back -- assuming nothing intervened!! */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1751 | retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | 0x5c, USB_DIR_IN|USB_TYPE_VENDOR, |
| 1753 | 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); |
| 1754 | if (retval != len) { |
| 1755 | what = "read"; |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 1756 | if (retval >= 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1757 | ERROR(dev, "ctrl_out, rlen %d (expected %d)\n", |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 1758 | retval, len); |
| 1759 | retval = -EBADMSG; |
| 1760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | break; |
| 1762 | } |
| 1763 | |
| 1764 | /* fail if we can't verify */ |
| 1765 | for (j = 0; j < len; j++) { |
Peter Chen | 169900f | 2015-09-01 09:48:00 +0800 | [diff] [blame] | 1766 | if (buf[j] != (u8)(i + j)) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1767 | ERROR(dev, "ctrl_out, byte %d is %d not %d\n", |
Peter Chen | 169900f | 2015-09-01 09:48:00 +0800 | [diff] [blame] | 1768 | j, buf[j], (u8)(i + j)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | retval = -EBADMSG; |
| 1770 | break; |
| 1771 | } |
| 1772 | } |
| 1773 | if (retval < 0) { |
| 1774 | what = "verify"; |
| 1775 | break; |
| 1776 | } |
| 1777 | |
| 1778 | len += vary; |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 1779 | |
| 1780 | /* [real world] the "zero bytes IN" case isn't really used. |
Joe Perches | dc0d5c1 | 2007-12-17 11:40:18 -0800 | [diff] [blame] | 1781 | * hardware can easily trip up in this weird case, since its |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 1782 | * status stage is IN, not OUT like other ep0in transfers. |
| 1783 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | if (len > length) |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 1785 | len = realworld ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | if (retval < 0) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1789 | ERROR(dev, "ctrl_out %s failed, code %d, count %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | what, retval, i); |
| 1791 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1792 | kfree(buf - offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | return retval; |
| 1794 | } |
| 1795 | |
| 1796 | /*-------------------------------------------------------------------------*/ |
| 1797 | |
| 1798 | /* ISO tests ... mimics common usage |
| 1799 | * - buffer length is split into N packets (mostly maxpacket sized) |
| 1800 | * - multi-buffers according to sglen |
| 1801 | */ |
| 1802 | |
| 1803 | struct iso_context { |
| 1804 | unsigned count; |
| 1805 | unsigned pending; |
| 1806 | spinlock_t lock; |
| 1807 | struct completion done; |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1808 | int submit_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | unsigned long errors; |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1810 | unsigned long packet_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | struct usbtest_dev *dev; |
| 1812 | }; |
| 1813 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1814 | static void iso_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | { |
| 1816 | struct iso_context *ctx = urb->context; |
| 1817 | |
| 1818 | spin_lock(&ctx->lock); |
| 1819 | ctx->count--; |
| 1820 | |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1821 | ctx->packet_count += urb->number_of_packets; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | if (urb->error_count > 0) |
| 1823 | ctx->errors += urb->error_count; |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1824 | else if (urb->status != 0) |
| 1825 | ctx->errors += urb->number_of_packets; |
Martin Fuzzey | 40aed52 | 2010-10-01 00:20:48 +0200 | [diff] [blame] | 1826 | else if (urb->actual_length != urb->transfer_buffer_length) |
| 1827 | ctx->errors++; |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1828 | else if (check_guard_bytes(ctx->dev, urb) != 0) |
| 1829 | ctx->errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1831 | if (urb->status == 0 && ctx->count > (ctx->pending - 1) |
| 1832 | && !ctx->submit_error) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1833 | int status = usb_submit_urb(urb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | switch (status) { |
| 1835 | case 0: |
| 1836 | goto done; |
| 1837 | default: |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1838 | dev_err(&ctx->dev->intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | "iso resubmit err %d\n", |
| 1840 | status); |
| 1841 | /* FALLTHROUGH */ |
| 1842 | case -ENODEV: /* disconnected */ |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1843 | case -ESHUTDOWN: /* endpoint disabled */ |
| 1844 | ctx->submit_error = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | break; |
| 1846 | } |
| 1847 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | |
| 1849 | ctx->pending--; |
| 1850 | if (ctx->pending == 0) { |
| 1851 | if (ctx->errors) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1852 | dev_err(&ctx->dev->intf->dev, |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1853 | "iso test, %lu errors out of %lu\n", |
| 1854 | ctx->errors, ctx->packet_count); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1855 | complete(&ctx->done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | } |
| 1857 | done: |
| 1858 | spin_unlock(&ctx->lock); |
| 1859 | } |
| 1860 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1861 | static struct urb *iso_alloc_urb( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | struct usb_device *udev, |
| 1863 | int pipe, |
| 1864 | struct usb_endpoint_descriptor *desc, |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1865 | long bytes, |
| 1866 | unsigned offset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | ) |
| 1868 | { |
| 1869 | struct urb *urb; |
| 1870 | unsigned i, maxp, packets; |
| 1871 | |
| 1872 | if (bytes < 0 || !desc) |
| 1873 | return NULL; |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 1874 | maxp = 0x7ff & usb_endpoint_maxp(desc); |
| 1875 | maxp *= 1 + (0x3 & (usb_endpoint_maxp(desc) >> 11)); |
Julia Lawall | dfa5ec7 | 2008-03-04 15:25:11 -0800 | [diff] [blame] | 1876 | packets = DIV_ROUND_UP(bytes, maxp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1878 | urb = usb_alloc_urb(packets, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | if (!urb) |
| 1880 | return urb; |
| 1881 | urb->dev = udev; |
| 1882 | urb->pipe = pipe; |
| 1883 | |
| 1884 | urb->number_of_packets = packets; |
| 1885 | urb->transfer_buffer_length = bytes; |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1886 | urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset, |
| 1887 | GFP_KERNEL, |
| 1888 | &urb->transfer_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | if (!urb->transfer_buffer) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1890 | usb_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | return NULL; |
| 1892 | } |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1893 | if (offset) { |
| 1894 | memset(urb->transfer_buffer, GUARD_BYTE, offset); |
| 1895 | urb->transfer_buffer += offset; |
| 1896 | urb->transfer_dma += offset; |
| 1897 | } |
| 1898 | /* For inbound transfers use guard byte so that test fails if |
| 1899 | data not correctly copied */ |
| 1900 | memset(urb->transfer_buffer, |
| 1901 | usb_pipein(urb->pipe) ? GUARD_BYTE : 0, |
| 1902 | bytes); |
| 1903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | for (i = 0; i < packets; i++) { |
| 1905 | /* here, only the last packet will be short */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1906 | urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | bytes -= urb->iso_frame_desc[i].length; |
| 1908 | |
| 1909 | urb->iso_frame_desc[i].offset = maxp * i; |
| 1910 | } |
| 1911 | |
| 1912 | urb->complete = iso_callback; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1913 | /* urb->context = SET BY CALLER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | urb->interval = 1 << (desc->bInterval - 1); |
| 1915 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; |
| 1916 | return urb; |
| 1917 | } |
| 1918 | |
| 1919 | static int |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1920 | test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param, |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1921 | int pipe, struct usb_endpoint_descriptor *desc, unsigned offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | { |
| 1923 | struct iso_context context; |
| 1924 | struct usb_device *udev; |
| 1925 | unsigned i; |
| 1926 | unsigned long packets = 0; |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1927 | int status = 0; |
Peter Chen | 41d3c0b | 2015-09-01 09:47:58 +0800 | [diff] [blame] | 1928 | struct urb *urbs[param->sglen]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | |
Huang Rui | f55055b | 2013-10-21 23:15:30 +0800 | [diff] [blame] | 1930 | memset(&context, 0, sizeof(context)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | context.count = param->iterations * param->sglen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | context.dev = dev; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1933 | init_completion(&context.done); |
| 1934 | spin_lock_init(&context.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1936 | udev = testdev_to_usbdev(dev); |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1937 | dev_info(&dev->intf->dev, |
Peter Chen | a0c9d0d | 2015-08-17 16:36:53 +0800 | [diff] [blame] | 1938 | "iso period %d %sframes, wMaxPacket %d, transactions: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | 1 << (desc->bInterval - 1), |
| 1940 | (udev->speed == USB_SPEED_HIGH) ? "micro" : "", |
Peter Chen | a0c9d0d | 2015-08-17 16:36:53 +0800 | [diff] [blame] | 1941 | usb_endpoint_maxp(desc) & 0x7ff, |
| 1942 | 1 + (0x3 & (usb_endpoint_maxp(desc) >> 11))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | |
| 1944 | for (i = 0; i < param->sglen; i++) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1945 | urbs[i] = iso_alloc_urb(udev, pipe, desc, |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 1946 | param->length, offset); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1947 | if (!urbs[i]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | status = -ENOMEM; |
| 1949 | goto fail; |
| 1950 | } |
| 1951 | packets += urbs[i]->number_of_packets; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1952 | urbs[i]->context = &context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | } |
| 1954 | packets *= param->iterations; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 1955 | dev_info(&dev->intf->dev, |
Peter Chen | a0c9d0d | 2015-08-17 16:36:53 +0800 | [diff] [blame] | 1956 | "total %lu msec (%lu packets)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | (packets * (1 << (desc->bInterval - 1))) |
| 1958 | / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1), |
| 1959 | packets); |
| 1960 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1961 | spin_lock_irq(&context.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | for (i = 0; i < param->sglen; i++) { |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1963 | ++context.pending; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1964 | status = usb_submit_urb(urbs[i], GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | if (status < 0) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1966 | ERROR(dev, "submit iso[%d], error %d\n", i, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | if (i == 0) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1968 | spin_unlock_irq(&context.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | goto fail; |
| 1970 | } |
| 1971 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1972 | simple_free_urb(urbs[i]); |
Ming Lei | e10e1be | 2010-08-02 22:09:01 +0800 | [diff] [blame] | 1973 | urbs[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | context.pending--; |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1975 | context.submit_error = 1; |
| 1976 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | } |
| 1978 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1979 | spin_unlock_irq(&context.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 1981 | wait_for_completion(&context.done); |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1982 | |
Ming Lei | e10e1be | 2010-08-02 22:09:01 +0800 | [diff] [blame] | 1983 | for (i = 0; i < param->sglen; i++) { |
| 1984 | if (urbs[i]) |
| 1985 | simple_free_urb(urbs[i]); |
| 1986 | } |
Alan Stern | 9da2150 | 2006-05-22 16:47:13 -0400 | [diff] [blame] | 1987 | /* |
| 1988 | * Isochronous transfers are expected to fail sometimes. As an |
| 1989 | * arbitrary limit, we will report an error if any submissions |
| 1990 | * fail or if the transfer failure rate is > 10%. |
| 1991 | */ |
| 1992 | if (status != 0) |
| 1993 | ; |
| 1994 | else if (context.submit_error) |
| 1995 | status = -EACCES; |
| 1996 | else if (context.errors > context.packet_count / 10) |
| 1997 | status = -EIO; |
| 1998 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | |
| 2000 | fail: |
| 2001 | for (i = 0; i < param->sglen; i++) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2002 | if (urbs[i]) |
| 2003 | simple_free_urb(urbs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | } |
| 2005 | return status; |
| 2006 | } |
| 2007 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 2008 | static int test_unaligned_bulk( |
| 2009 | struct usbtest_dev *tdev, |
| 2010 | int pipe, |
| 2011 | unsigned length, |
| 2012 | int iterations, |
| 2013 | unsigned transfer_flags, |
| 2014 | const char *label) |
| 2015 | { |
| 2016 | int retval; |
| 2017 | struct urb *urb = usbtest_alloc_urb( |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2018 | testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1, 0); |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 2019 | |
| 2020 | if (!urb) |
| 2021 | return -ENOMEM; |
| 2022 | |
| 2023 | retval = simple_io(tdev, urb, iterations, 0, 0, label); |
| 2024 | simple_free_urb(urb); |
| 2025 | return retval; |
| 2026 | } |
| 2027 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | /*-------------------------------------------------------------------------*/ |
| 2029 | |
| 2030 | /* We only have this one interface to user space, through usbfs. |
| 2031 | * User mode code can scan usbfs to find N different devices (maybe on |
| 2032 | * different busses) to use when testing, and allocate one thread per |
| 2033 | * test. So discovery is simplified, and we have no device naming issues. |
| 2034 | * |
| 2035 | * Don't use these only as stress/load tests. Use them along with with |
| 2036 | * other USB bus activity: plugging, unplugging, mousing, mp3 playback, |
| 2037 | * video capture, and so on. Run different tests at different times, in |
| 2038 | * different sequences. Nothing here should interact with other devices, |
| 2039 | * except indirectly by consuming USB bandwidth and CPU resources for test |
| 2040 | * threads and request completion. But the only way to know that for sure |
| 2041 | * is to test when HC queues are in use by many devices. |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2042 | * |
| 2043 | * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(), |
| 2044 | * it locks out usbcore in certain code paths. Notably, if you disconnect |
Petr Mladek | 37ebb54 | 2014-09-19 17:32:23 +0200 | [diff] [blame] | 2045 | * the device-under-test, hub_wq will wait block forever waiting for the |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2046 | * ioctl to complete ... so that usb_disconnect() can abort the pending |
| 2047 | * urbs and then call usbtest_disconnect(). To abort a test, you're best |
| 2048 | * off just killing the userspace task and waiting for it to exit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | */ |
| 2050 | |
| 2051 | static int |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2052 | usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2054 | struct usbtest_dev *dev = usb_get_intfdata(intf); |
| 2055 | struct usb_device *udev = testdev_to_usbdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | struct usbtest_param *param = buf; |
| 2057 | int retval = -EOPNOTSUPP; |
| 2058 | struct urb *urb; |
| 2059 | struct scatterlist *sg; |
| 2060 | struct usb_sg_request req; |
| 2061 | struct timeval start; |
| 2062 | unsigned i; |
| 2063 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2064 | /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | |
Vikram Pandita | 7f4e985 | 2009-11-09 21:24:32 -0600 | [diff] [blame] | 2066 | pattern = mod_pattern; |
| 2067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | if (code != USBTEST_REQUEST) |
| 2069 | return -EOPNOTSUPP; |
| 2070 | |
roel kluin | 8aafdf6 | 2008-10-21 00:36:44 -0400 | [diff] [blame] | 2071 | if (param->iterations <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | return -EINVAL; |
| 2073 | |
Peter Chen | 41d3c0b | 2015-09-01 09:47:58 +0800 | [diff] [blame] | 2074 | if (param->sglen > MAX_SGLEN) |
| 2075 | return -EINVAL; |
| 2076 | |
Matthias Kaehlcke | 1cfab02 | 2007-12-13 16:15:33 -0800 | [diff] [blame] | 2077 | if (mutex_lock_interruptible(&dev->lock)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | return -ERESTARTSYS; |
| 2079 | |
Alan Stern | 70a1c9e | 2008-03-06 17:00:58 -0500 | [diff] [blame] | 2080 | /* FIXME: What if a system sleep starts while a test is running? */ |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 2081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | /* some devices, like ez-usb default devices, need a non-default |
| 2083 | * altsetting to have any active endpoints. some tests change |
| 2084 | * altsettings; force a default so most tests don't need to check. |
| 2085 | */ |
| 2086 | if (dev->info->alt >= 0) { |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2087 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | |
| 2089 | if (intf->altsetting->desc.bInterfaceNumber) { |
Matthias Kaehlcke | 1cfab02 | 2007-12-13 16:15:33 -0800 | [diff] [blame] | 2090 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | return -ENODEV; |
| 2092 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2093 | res = set_altsetting(dev, dev->info->alt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | if (res) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2095 | dev_err(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | "set altsetting to %d failed, %d\n", |
| 2097 | dev->info->alt, res); |
Matthias Kaehlcke | 1cfab02 | 2007-12-13 16:15:33 -0800 | [diff] [blame] | 2098 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | return res; |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | /* |
| 2104 | * Just a bunch of test cases that every HCD is expected to handle. |
| 2105 | * |
| 2106 | * Some may need specific firmware, though it'd be good to have |
| 2107 | * one firmware image to handle all the test cases. |
| 2108 | * |
| 2109 | * FIXME add more tests! cancel requests, verify the data, control |
| 2110 | * queueing, concurrent read+write threads, and so on. |
| 2111 | */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2112 | do_gettimeofday(&start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | switch (param->test_num) { |
| 2114 | |
| 2115 | case 0: |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2116 | dev_info(&intf->dev, "TEST 0: NOP\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | retval = 0; |
| 2118 | break; |
| 2119 | |
| 2120 | /* Simple non-queued bulk I/O tests */ |
| 2121 | case 1: |
| 2122 | if (dev->out_pipe == 0) |
| 2123 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2124 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | "TEST 1: write %d bytes %u times\n", |
| 2126 | param->length, param->iterations); |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2127 | urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | if (!urb) { |
| 2129 | retval = -ENOMEM; |
| 2130 | break; |
| 2131 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2132 | /* FIRMWARE: bulk sink (maybe accepts short writes) */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2133 | retval = simple_io(dev, urb, param->iterations, 0, 0, "test1"); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2134 | simple_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | break; |
| 2136 | case 2: |
| 2137 | if (dev->in_pipe == 0) |
| 2138 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2139 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | "TEST 2: read %d bytes %u times\n", |
| 2141 | param->length, param->iterations); |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2142 | urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | if (!urb) { |
| 2144 | retval = -ENOMEM; |
| 2145 | break; |
| 2146 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2147 | /* FIRMWARE: bulk source (maybe generates short writes) */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2148 | retval = simple_io(dev, urb, param->iterations, 0, 0, "test2"); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2149 | simple_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | break; |
| 2151 | case 3: |
| 2152 | if (dev->out_pipe == 0 || param->vary == 0) |
| 2153 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2154 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | "TEST 3: write/%d 0..%d bytes %u times\n", |
| 2156 | param->vary, param->length, param->iterations); |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2157 | urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | if (!urb) { |
| 2159 | retval = -ENOMEM; |
| 2160 | break; |
| 2161 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2162 | /* FIRMWARE: bulk sink (maybe accepts short writes) */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2163 | retval = simple_io(dev, urb, param->iterations, param->vary, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | 0, "test3"); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2165 | simple_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | break; |
| 2167 | case 4: |
| 2168 | if (dev->in_pipe == 0 || param->vary == 0) |
| 2169 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2170 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | "TEST 4: read/%d 0..%d bytes %u times\n", |
| 2172 | param->vary, param->length, param->iterations); |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2173 | urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | if (!urb) { |
| 2175 | retval = -ENOMEM; |
| 2176 | break; |
| 2177 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2178 | /* FIRMWARE: bulk source (maybe generates short writes) */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2179 | retval = simple_io(dev, urb, param->iterations, param->vary, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | 0, "test4"); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2181 | simple_free_urb(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | break; |
| 2183 | |
| 2184 | /* Queued bulk I/O tests */ |
| 2185 | case 5: |
| 2186 | if (dev->out_pipe == 0 || param->sglen == 0) |
| 2187 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2188 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | "TEST 5: write %d sglists %d entries of %d bytes\n", |
| 2190 | param->iterations, |
| 2191 | param->sglen, param->length); |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 2192 | sg = alloc_sglist(param->sglen, param->length, |
| 2193 | 0, dev, dev->out_pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | if (!sg) { |
| 2195 | retval = -ENOMEM; |
| 2196 | break; |
| 2197 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2198 | /* FIRMWARE: bulk sink (maybe accepts short writes) */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2199 | retval = perform_sglist(dev, param->iterations, dev->out_pipe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | &req, sg, param->sglen); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2201 | free_sglist(sg, param->sglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | break; |
| 2203 | |
| 2204 | case 6: |
| 2205 | if (dev->in_pipe == 0 || param->sglen == 0) |
| 2206 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2207 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | "TEST 6: read %d sglists %d entries of %d bytes\n", |
| 2209 | param->iterations, |
| 2210 | param->sglen, param->length); |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 2211 | sg = alloc_sglist(param->sglen, param->length, |
| 2212 | 0, dev, dev->in_pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | if (!sg) { |
| 2214 | retval = -ENOMEM; |
| 2215 | break; |
| 2216 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2217 | /* FIRMWARE: bulk source (maybe generates short writes) */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2218 | retval = perform_sglist(dev, param->iterations, dev->in_pipe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | &req, sg, param->sglen); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2220 | free_sglist(sg, param->sglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | break; |
| 2222 | case 7: |
| 2223 | if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0) |
| 2224 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2225 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n", |
| 2227 | param->vary, param->iterations, |
| 2228 | param->sglen, param->length); |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 2229 | sg = alloc_sglist(param->sglen, param->length, |
| 2230 | param->vary, dev, dev->out_pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | if (!sg) { |
| 2232 | retval = -ENOMEM; |
| 2233 | break; |
| 2234 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2235 | /* FIRMWARE: bulk sink (maybe accepts short writes) */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2236 | retval = perform_sglist(dev, param->iterations, dev->out_pipe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | &req, sg, param->sglen); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2238 | free_sglist(sg, param->sglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | break; |
| 2240 | case 8: |
| 2241 | if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0) |
| 2242 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2243 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n", |
| 2245 | param->vary, param->iterations, |
| 2246 | param->sglen, param->length); |
Alan Stern | b9a6e8e | 2015-09-01 09:48:01 +0800 | [diff] [blame^] | 2247 | sg = alloc_sglist(param->sglen, param->length, |
| 2248 | param->vary, dev, dev->in_pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | if (!sg) { |
| 2250 | retval = -ENOMEM; |
| 2251 | break; |
| 2252 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2253 | /* FIRMWARE: bulk source (maybe generates short writes) */ |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2254 | retval = perform_sglist(dev, param->iterations, dev->in_pipe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | &req, sg, param->sglen); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2256 | free_sglist(sg, param->sglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | break; |
| 2258 | |
| 2259 | /* non-queued sanity tests for control (chapter 9 subset) */ |
| 2260 | case 9: |
| 2261 | retval = 0; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2262 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | "TEST 9: ch9 (subset) control tests, %d times\n", |
| 2264 | param->iterations); |
| 2265 | for (i = param->iterations; retval == 0 && i--; /* NOP */) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2266 | retval = ch9_postconfig(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | if (retval) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2268 | dev_err(&intf->dev, "ch9 subset failed, " |
| 2269 | "iterations left %d\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | break; |
| 2271 | |
| 2272 | /* queued control messaging */ |
| 2273 | case 10: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | retval = 0; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2275 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | "TEST 10: queue %d control calls, %d times\n", |
| 2277 | param->sglen, |
| 2278 | param->iterations); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2279 | retval = test_ctrl_queue(dev, param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | break; |
| 2281 | |
| 2282 | /* simple non-queued unlinks (ring with one urb) */ |
| 2283 | case 11: |
| 2284 | if (dev->in_pipe == 0 || !param->length) |
| 2285 | break; |
| 2286 | retval = 0; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2287 | dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | param->iterations, param->length); |
| 2289 | for (i = param->iterations; retval == 0 && i--; /* NOP */) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2290 | retval = unlink_simple(dev, dev->in_pipe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | param->length); |
| 2292 | if (retval) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2293 | dev_err(&intf->dev, "unlink reads failed %d, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | "iterations left %d\n", retval, i); |
| 2295 | break; |
| 2296 | case 12: |
| 2297 | if (dev->out_pipe == 0 || !param->length) |
| 2298 | break; |
| 2299 | retval = 0; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2300 | dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | param->iterations, param->length); |
| 2302 | for (i = param->iterations; retval == 0 && i--; /* NOP */) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2303 | retval = unlink_simple(dev, dev->out_pipe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | param->length); |
| 2305 | if (retval) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2306 | dev_err(&intf->dev, "unlink writes failed %d, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | "iterations left %d\n", retval, i); |
| 2308 | break; |
| 2309 | |
| 2310 | /* ep halt tests */ |
| 2311 | case 13: |
| 2312 | if (dev->out_pipe == 0 && dev->in_pipe == 0) |
| 2313 | break; |
| 2314 | retval = 0; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2315 | dev_info(&intf->dev, "TEST 13: set/clear %d halts\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | param->iterations); |
| 2317 | for (i = param->iterations; retval == 0 && i--; /* NOP */) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2318 | retval = halt_simple(dev); |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | if (retval) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2321 | ERROR(dev, "halts failed, iterations left %d\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | break; |
| 2323 | |
| 2324 | /* control write tests */ |
| 2325 | case 14: |
| 2326 | if (!dev->info->ctrl_out) |
| 2327 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2328 | dev_info(&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n", |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 2329 | param->iterations, |
| 2330 | realworld ? 1 : 0, param->length, |
| 2331 | param->vary); |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2332 | retval = ctrl_out(dev, param->iterations, |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 2333 | param->length, param->vary, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | break; |
| 2335 | |
| 2336 | /* iso write tests */ |
| 2337 | case 15: |
| 2338 | if (dev->out_iso_pipe == 0 || param->sglen == 0) |
| 2339 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2340 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | "TEST 15: write %d iso, %d entries of %d bytes\n", |
| 2342 | param->iterations, |
| 2343 | param->sglen, param->length); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2344 | /* FIRMWARE: iso sink */ |
| 2345 | retval = test_iso_queue(dev, param, |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 2346 | dev->out_iso_pipe, dev->iso_out, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | break; |
| 2348 | |
| 2349 | /* iso read tests */ |
| 2350 | case 16: |
| 2351 | if (dev->in_iso_pipe == 0 || param->sglen == 0) |
| 2352 | break; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2353 | dev_info(&intf->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | "TEST 16: read %d iso, %d entries of %d bytes\n", |
| 2355 | param->iterations, |
| 2356 | param->sglen, param->length); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2357 | /* FIRMWARE: iso source */ |
| 2358 | retval = test_iso_queue(dev, param, |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 2359 | dev->in_iso_pipe, dev->iso_in, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | break; |
| 2361 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2362 | /* FIXME scatterlist cancel (needs helper thread) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | |
Martin Fuzzey | 084fb20 | 2011-01-16 19:17:11 +0100 | [diff] [blame] | 2364 | /* Tests for bulk I/O using DMA mapping by core and odd address */ |
| 2365 | case 17: |
| 2366 | if (dev->out_pipe == 0) |
| 2367 | break; |
| 2368 | dev_info(&intf->dev, |
| 2369 | "TEST 17: write odd addr %d bytes %u times core map\n", |
| 2370 | param->length, param->iterations); |
| 2371 | |
| 2372 | retval = test_unaligned_bulk( |
| 2373 | dev, dev->out_pipe, |
| 2374 | param->length, param->iterations, |
| 2375 | 0, "test17"); |
| 2376 | break; |
| 2377 | |
| 2378 | case 18: |
| 2379 | if (dev->in_pipe == 0) |
| 2380 | break; |
| 2381 | dev_info(&intf->dev, |
| 2382 | "TEST 18: read odd addr %d bytes %u times core map\n", |
| 2383 | param->length, param->iterations); |
| 2384 | |
| 2385 | retval = test_unaligned_bulk( |
| 2386 | dev, dev->in_pipe, |
| 2387 | param->length, param->iterations, |
| 2388 | 0, "test18"); |
| 2389 | break; |
| 2390 | |
| 2391 | /* Tests for bulk I/O using premapped coherent buffer and odd address */ |
| 2392 | case 19: |
| 2393 | if (dev->out_pipe == 0) |
| 2394 | break; |
| 2395 | dev_info(&intf->dev, |
| 2396 | "TEST 19: write odd addr %d bytes %u times premapped\n", |
| 2397 | param->length, param->iterations); |
| 2398 | |
| 2399 | retval = test_unaligned_bulk( |
| 2400 | dev, dev->out_pipe, |
| 2401 | param->length, param->iterations, |
| 2402 | URB_NO_TRANSFER_DMA_MAP, "test19"); |
| 2403 | break; |
| 2404 | |
| 2405 | case 20: |
| 2406 | if (dev->in_pipe == 0) |
| 2407 | break; |
| 2408 | dev_info(&intf->dev, |
| 2409 | "TEST 20: read odd addr %d bytes %u times premapped\n", |
| 2410 | param->length, param->iterations); |
| 2411 | |
| 2412 | retval = test_unaligned_bulk( |
| 2413 | dev, dev->in_pipe, |
| 2414 | param->length, param->iterations, |
| 2415 | URB_NO_TRANSFER_DMA_MAP, "test20"); |
| 2416 | break; |
| 2417 | |
| 2418 | /* control write tests with unaligned buffer */ |
| 2419 | case 21: |
| 2420 | if (!dev->info->ctrl_out) |
| 2421 | break; |
| 2422 | dev_info(&intf->dev, |
| 2423 | "TEST 21: %d ep0out odd addr, %d..%d vary %d\n", |
| 2424 | param->iterations, |
| 2425 | realworld ? 1 : 0, param->length, |
| 2426 | param->vary); |
| 2427 | retval = ctrl_out(dev, param->iterations, |
| 2428 | param->length, param->vary, 1); |
| 2429 | break; |
| 2430 | |
| 2431 | /* unaligned iso tests */ |
| 2432 | case 22: |
| 2433 | if (dev->out_iso_pipe == 0 || param->sglen == 0) |
| 2434 | break; |
| 2435 | dev_info(&intf->dev, |
| 2436 | "TEST 22: write %d iso odd, %d entries of %d bytes\n", |
| 2437 | param->iterations, |
| 2438 | param->sglen, param->length); |
| 2439 | retval = test_iso_queue(dev, param, |
| 2440 | dev->out_iso_pipe, dev->iso_out, 1); |
| 2441 | break; |
| 2442 | |
| 2443 | case 23: |
| 2444 | if (dev->in_iso_pipe == 0 || param->sglen == 0) |
| 2445 | break; |
| 2446 | dev_info(&intf->dev, |
| 2447 | "TEST 23: read %d iso odd, %d entries of %d bytes\n", |
| 2448 | param->iterations, |
| 2449 | param->sglen, param->length); |
| 2450 | retval = test_iso_queue(dev, param, |
| 2451 | dev->in_iso_pipe, dev->iso_in, 1); |
| 2452 | break; |
| 2453 | |
Alan Stern | 869410f | 2011-04-14 11:21:04 -0400 | [diff] [blame] | 2454 | /* unlink URBs from a bulk-OUT queue */ |
| 2455 | case 24: |
| 2456 | if (dev->out_pipe == 0 || !param->length || param->sglen < 4) |
| 2457 | break; |
| 2458 | retval = 0; |
Alan Stern | 2cb5000 | 2013-01-02 13:58:18 -0500 | [diff] [blame] | 2459 | dev_info(&intf->dev, "TEST 24: unlink from %d queues of " |
Alan Stern | 869410f | 2011-04-14 11:21:04 -0400 | [diff] [blame] | 2460 | "%d %d-byte writes\n", |
| 2461 | param->iterations, param->sglen, param->length); |
| 2462 | for (i = param->iterations; retval == 0 && i > 0; --i) { |
| 2463 | retval = unlink_queued(dev, dev->out_pipe, |
| 2464 | param->sglen, param->length); |
| 2465 | if (retval) { |
| 2466 | dev_err(&intf->dev, |
| 2467 | "unlink queued writes failed %d, " |
| 2468 | "iterations left %d\n", retval, i); |
| 2469 | break; |
| 2470 | } |
| 2471 | } |
| 2472 | break; |
| 2473 | |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2474 | /* Simple non-queued interrupt I/O tests */ |
| 2475 | case 25: |
| 2476 | if (dev->out_int_pipe == 0) |
| 2477 | break; |
| 2478 | dev_info(&intf->dev, |
| 2479 | "TEST 25: write %d bytes %u times\n", |
| 2480 | param->length, param->iterations); |
| 2481 | urb = simple_alloc_urb(udev, dev->out_int_pipe, param->length, |
| 2482 | dev->int_out->bInterval); |
| 2483 | if (!urb) { |
| 2484 | retval = -ENOMEM; |
| 2485 | break; |
| 2486 | } |
| 2487 | /* FIRMWARE: interrupt sink (maybe accepts short writes) */ |
| 2488 | retval = simple_io(dev, urb, param->iterations, 0, 0, "test25"); |
| 2489 | simple_free_urb(urb); |
| 2490 | break; |
| 2491 | case 26: |
| 2492 | if (dev->in_int_pipe == 0) |
| 2493 | break; |
| 2494 | dev_info(&intf->dev, |
| 2495 | "TEST 26: read %d bytes %u times\n", |
| 2496 | param->length, param->iterations); |
| 2497 | urb = simple_alloc_urb(udev, dev->in_int_pipe, param->length, |
| 2498 | dev->int_in->bInterval); |
| 2499 | if (!urb) { |
| 2500 | retval = -ENOMEM; |
| 2501 | break; |
| 2502 | } |
| 2503 | /* FIRMWARE: interrupt source (maybe generates short writes) */ |
| 2504 | retval = simple_io(dev, urb, param->iterations, 0, 0, "test26"); |
| 2505 | simple_free_urb(urb); |
| 2506 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2508 | do_gettimeofday(¶m->duration); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | param->duration.tv_sec -= start.tv_sec; |
| 2510 | param->duration.tv_usec -= start.tv_usec; |
| 2511 | if (param->duration.tv_usec < 0) { |
| 2512 | param->duration.tv_usec += 1000 * 1000; |
| 2513 | param->duration.tv_sec -= 1; |
| 2514 | } |
Matthias Kaehlcke | 1cfab02 | 2007-12-13 16:15:33 -0800 | [diff] [blame] | 2515 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | return retval; |
| 2517 | } |
| 2518 | |
| 2519 | /*-------------------------------------------------------------------------*/ |
| 2520 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2521 | static unsigned force_interrupt; |
| 2522 | module_param(force_interrupt, uint, 0); |
| 2523 | MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
| 2525 | #ifdef GENERIC |
| 2526 | static unsigned short vendor; |
| 2527 | module_param(vendor, ushort, 0); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2528 | MODULE_PARM_DESC(vendor, "vendor code (from usb-if)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | |
| 2530 | static unsigned short product; |
| 2531 | module_param(product, ushort, 0); |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2532 | MODULE_PARM_DESC(product, "product code (from vendor)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | #endif |
| 2534 | |
| 2535 | static int |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2536 | usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | { |
| 2538 | struct usb_device *udev; |
| 2539 | struct usbtest_dev *dev; |
| 2540 | struct usbtest_info *info; |
| 2541 | char *rtest, *wtest; |
| 2542 | char *irtest, *iwtest; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2543 | char *intrtest, *intwtest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2545 | udev = interface_to_usbdev(intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | |
| 2547 | #ifdef GENERIC |
| 2548 | /* specify devices by module parameters? */ |
| 2549 | if (id->match_flags == 0) { |
| 2550 | /* vendor match required, product match optional */ |
| 2551 | if (!vendor || le16_to_cpu(udev->descriptor.idVendor) != (u16)vendor) |
| 2552 | return -ENODEV; |
| 2553 | if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product) |
| 2554 | return -ENODEV; |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2555 | dev_info(&intf->dev, "matched module params, " |
| 2556 | "vend=0x%04x prod=0x%04x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | le16_to_cpu(udev->descriptor.idVendor), |
| 2558 | le16_to_cpu(udev->descriptor.idProduct)); |
| 2559 | } |
| 2560 | #endif |
| 2561 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 2562 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | if (!dev) |
| 2564 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | info = (struct usbtest_info *) id->driver_info; |
| 2566 | dev->info = info; |
Matthias Kaehlcke | 1cfab02 | 2007-12-13 16:15:33 -0800 | [diff] [blame] | 2567 | mutex_init(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | |
| 2569 | dev->intf = intf; |
| 2570 | |
| 2571 | /* cacheline-aligned scratch for i/o */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2572 | dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL); |
| 2573 | if (dev->buf == NULL) { |
| 2574 | kfree(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | return -ENOMEM; |
| 2576 | } |
| 2577 | |
| 2578 | /* NOTE this doesn't yet test the handful of difference that are |
| 2579 | * visible with high speed interrupts: bigger maxpacket (1K) and |
| 2580 | * "high bandwidth" modes (up to 3 packets/uframe). |
| 2581 | */ |
| 2582 | rtest = wtest = ""; |
| 2583 | irtest = iwtest = ""; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2584 | intrtest = intwtest = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | if (force_interrupt || udev->speed == USB_SPEED_LOW) { |
| 2586 | if (info->ep_in) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2587 | dev->in_pipe = usb_rcvintpipe(udev, info->ep_in); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | rtest = " intr-in"; |
| 2589 | } |
| 2590 | if (info->ep_out) { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2591 | dev->out_pipe = usb_sndintpipe(udev, info->ep_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | wtest = " intr-out"; |
| 2593 | } |
| 2594 | } else { |
Alan Stern | d0b4652 | 2013-01-30 16:38:11 -0500 | [diff] [blame] | 2595 | if (override_alt >= 0 || info->autoconf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | int status; |
| 2597 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2598 | status = get_endpoints(dev, intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | if (status < 0) { |
Arjan van de Ven | b6c6393 | 2008-07-25 01:45:52 -0700 | [diff] [blame] | 2600 | WARNING(dev, "couldn't get endpoints, %d\n", |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2601 | status); |
Julia Lawall | f4a728d | 2012-03-25 21:08:32 +0200 | [diff] [blame] | 2602 | kfree(dev->buf); |
| 2603 | kfree(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | return status; |
| 2605 | } |
| 2606 | /* may find bulk or ISO pipes */ |
| 2607 | } else { |
| 2608 | if (info->ep_in) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2609 | dev->in_pipe = usb_rcvbulkpipe(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | info->ep_in); |
| 2611 | if (info->ep_out) |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2612 | dev->out_pipe = usb_sndbulkpipe(udev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | info->ep_out); |
| 2614 | } |
| 2615 | if (dev->in_pipe) |
| 2616 | rtest = " bulk-in"; |
| 2617 | if (dev->out_pipe) |
| 2618 | wtest = " bulk-out"; |
| 2619 | if (dev->in_iso_pipe) |
| 2620 | irtest = " iso-in"; |
| 2621 | if (dev->out_iso_pipe) |
| 2622 | iwtest = " iso-out"; |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2623 | if (dev->in_int_pipe) |
| 2624 | intrtest = " int-in"; |
| 2625 | if (dev->out_int_pipe) |
| 2626 | intwtest = " int-out"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2629 | usb_set_intfdata(intf, dev); |
| 2630 | dev_info(&intf->dev, "%s\n", info->name); |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2631 | dev_info(&intf->dev, "%s {control%s%s%s%s%s%s%s} tests%s\n", |
Michal Nazarewicz | e538dfd | 2011-08-30 17:11:19 +0200 | [diff] [blame] | 2632 | usb_speed_string(udev->speed), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | info->ctrl_out ? " in/out" : "", |
| 2634 | rtest, wtest, |
| 2635 | irtest, iwtest, |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2636 | intrtest, intwtest, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | info->alt >= 0 ? " (+alt)" : ""); |
| 2638 | return 0; |
| 2639 | } |
| 2640 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2641 | static int usbtest_suspend(struct usb_interface *intf, pm_message_t message) |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 2642 | { |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 2643 | return 0; |
| 2644 | } |
| 2645 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2646 | static int usbtest_resume(struct usb_interface *intf) |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 2647 | { |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 2648 | return 0; |
| 2649 | } |
| 2650 | |
| 2651 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2652 | static void usbtest_disconnect(struct usb_interface *intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2654 | struct usbtest_dev *dev = usb_get_intfdata(intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2656 | usb_set_intfdata(intf, NULL); |
| 2657 | dev_dbg(&intf->dev, "disconnect\n"); |
| 2658 | kfree(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | } |
| 2660 | |
| 2661 | /* Basic testing only needs a device that can source or sink bulk traffic. |
| 2662 | * Any device can test control transfers (default with GENERIC binding). |
| 2663 | * |
| 2664 | * Several entries work with the default EP0 implementation that's built |
| 2665 | * into EZ-USB chips. There's a default vendor ID which can be overridden |
| 2666 | * by (very) small config EEPROMS, but otherwise all these devices act |
| 2667 | * identically until firmware is loaded: only EP0 works. It turns out |
| 2668 | * to be easy to make other endpoints work, without modifying that EP0 |
| 2669 | * behavior. For now, we expect that kind of firmware. |
| 2670 | */ |
| 2671 | |
| 2672 | /* an21xx or fx versions of ez-usb */ |
| 2673 | static struct usbtest_info ez1_info = { |
| 2674 | .name = "EZ-USB device", |
| 2675 | .ep_in = 2, |
| 2676 | .ep_out = 2, |
| 2677 | .alt = 1, |
| 2678 | }; |
| 2679 | |
| 2680 | /* fx2 version of ez-usb */ |
| 2681 | static struct usbtest_info ez2_info = { |
| 2682 | .name = "FX2 device", |
| 2683 | .ep_in = 6, |
| 2684 | .ep_out = 2, |
| 2685 | .alt = 1, |
| 2686 | }; |
| 2687 | |
| 2688 | /* ezusb family device with dedicated usb test firmware, |
| 2689 | */ |
| 2690 | static struct usbtest_info fw_info = { |
| 2691 | .name = "usb test device", |
| 2692 | .ep_in = 2, |
| 2693 | .ep_out = 2, |
| 2694 | .alt = 1, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2695 | .autoconf = 1, /* iso and ctrl_out need autoconf */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | .ctrl_out = 1, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2697 | .iso = 1, /* iso_ep's are #8 in/out */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | }; |
| 2699 | |
| 2700 | /* peripheral running Linux and 'zero.c' test firmware, or |
| 2701 | * its user-mode cousin. different versions of this use |
| 2702 | * different hardware with the same vendor/product codes. |
| 2703 | * host side MUST rely on the endpoint descriptors. |
| 2704 | */ |
| 2705 | static struct usbtest_info gz_info = { |
| 2706 | .name = "Linux gadget zero", |
| 2707 | .autoconf = 1, |
| 2708 | .ctrl_out = 1, |
Boyan Nedeltchev | 4b85c62 | 2012-11-12 13:06:06 +0200 | [diff] [blame] | 2709 | .iso = 1, |
Amit Virdi | 457a095 | 2014-08-22 14:36:37 +0530 | [diff] [blame] | 2710 | .intr = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | .alt = 0, |
| 2712 | }; |
| 2713 | |
| 2714 | static struct usbtest_info um_info = { |
| 2715 | .name = "Linux user mode test driver", |
| 2716 | .autoconf = 1, |
| 2717 | .alt = -1, |
| 2718 | }; |
| 2719 | |
| 2720 | static struct usbtest_info um2_info = { |
| 2721 | .name = "Linux user mode ISO test driver", |
| 2722 | .autoconf = 1, |
| 2723 | .iso = 1, |
| 2724 | .alt = -1, |
| 2725 | }; |
| 2726 | |
| 2727 | #ifdef IBOT2 |
| 2728 | /* this is a nice source of high speed bulk data; |
| 2729 | * uses an FX2, with firmware provided in the device |
| 2730 | */ |
| 2731 | static struct usbtest_info ibot2_info = { |
| 2732 | .name = "iBOT2 webcam", |
| 2733 | .ep_in = 2, |
| 2734 | .alt = -1, |
| 2735 | }; |
| 2736 | #endif |
| 2737 | |
| 2738 | #ifdef GENERIC |
| 2739 | /* we can use any device to test control traffic */ |
| 2740 | static struct usbtest_info generic_info = { |
| 2741 | .name = "Generic USB device", |
| 2742 | .alt = -1, |
| 2743 | }; |
| 2744 | #endif |
| 2745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | |
Németh Márton | 33b9e16 | 2010-01-10 15:34:45 +0100 | [diff] [blame] | 2747 | static const struct usb_device_id id_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | /*-------------------------------------------------------------*/ |
| 2750 | |
| 2751 | /* EZ-USB devices which download firmware to replace (or in our |
| 2752 | * case augment) the default device implementation. |
| 2753 | */ |
| 2754 | |
| 2755 | /* generic EZ-USB FX controller */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2756 | { USB_DEVICE(0x0547, 0x2235), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | .driver_info = (unsigned long) &ez1_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2758 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | |
| 2760 | /* CY3671 development board with EZ-USB FX */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2761 | { USB_DEVICE(0x0547, 0x0080), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | .driver_info = (unsigned long) &ez1_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2763 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | |
| 2765 | /* generic EZ-USB FX2 controller (or development board) */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2766 | { USB_DEVICE(0x04b4, 0x8613), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | .driver_info = (unsigned long) &ez2_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2768 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | |
| 2770 | /* re-enumerated usb test device firmware */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2771 | { USB_DEVICE(0xfff0, 0xfff0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | .driver_info = (unsigned long) &fw_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2773 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | |
| 2775 | /* "Gadget Zero" firmware runs under Linux */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2776 | { USB_DEVICE(0x0525, 0xa4a0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | .driver_info = (unsigned long) &gz_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2778 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | |
| 2780 | /* so does a user-mode variant */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2781 | { USB_DEVICE(0x0525, 0xa4a4), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | .driver_info = (unsigned long) &um_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2783 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | |
| 2785 | /* ... and a user-mode variant that talks iso */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2786 | { USB_DEVICE(0x0525, 0xa4a3), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | .driver_info = (unsigned long) &um2_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2788 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | |
| 2790 | #ifdef KEYSPAN_19Qi |
| 2791 | /* Keyspan 19qi uses an21xx (original EZ-USB) */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2792 | /* this does not coexist with the real Keyspan 19qi driver! */ |
| 2793 | { USB_DEVICE(0x06cd, 0x010b), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | .driver_info = (unsigned long) &ez1_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2795 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | #endif |
| 2797 | |
| 2798 | /*-------------------------------------------------------------*/ |
| 2799 | |
| 2800 | #ifdef IBOT2 |
| 2801 | /* iBOT2 makes a nice source of high speed bulk-in data */ |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2802 | /* this does not coexist with a real iBOT2 driver! */ |
| 2803 | { USB_DEVICE(0x0b62, 0x0059), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | .driver_info = (unsigned long) &ibot2_info, |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2805 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | #endif |
| 2807 | |
| 2808 | /*-------------------------------------------------------------*/ |
| 2809 | |
| 2810 | #ifdef GENERIC |
| 2811 | /* module params can specify devices to use for control tests */ |
| 2812 | { .driver_info = (unsigned long) &generic_info, }, |
| 2813 | #endif |
| 2814 | |
| 2815 | /*-------------------------------------------------------------*/ |
| 2816 | |
| 2817 | { } |
| 2818 | }; |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2819 | MODULE_DEVICE_TABLE(usb, id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | |
| 2821 | static struct usb_driver usbtest_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | .name = "usbtest", |
| 2823 | .id_table = id_table, |
| 2824 | .probe = usbtest_probe, |
Andi Kleen | c532b29 | 2010-06-01 23:04:41 +0200 | [diff] [blame] | 2825 | .unlocked_ioctl = usbtest_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | .disconnect = usbtest_disconnect, |
David Brownell | ff7c79e | 2005-04-22 13:17:00 -0700 | [diff] [blame] | 2827 | .suspend = usbtest_suspend, |
| 2828 | .resume = usbtest_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | }; |
| 2830 | |
| 2831 | /*-------------------------------------------------------------------------*/ |
| 2832 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2833 | static int __init usbtest_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | { |
| 2835 | #ifdef GENERIC |
| 2836 | if (vendor) |
David Brownell | 28ffd79 | 2008-04-25 18:51:10 -0700 | [diff] [blame] | 2837 | pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | #endif |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2839 | return usb_register(&usbtest_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2841 | module_init(usbtest_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2843 | static void __exit usbtest_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | { |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2845 | usb_deregister(&usbtest_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | } |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2847 | module_exit(usbtest_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | |
Martin Fuzzey | fabbf21 | 2010-10-01 00:20:42 +0200 | [diff] [blame] | 2849 | MODULE_DESCRIPTION("USB Core/HCD Testing Driver"); |
| 2850 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | |