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