blob: 174be05ba2c7c1852d179ea72c89bbd89b74e95a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 Hardeman378f0582005-09-17 17:55:31 +10008#include <linux/scatterlist.h>
Matthias Kaehlcke1cfab022007-12-13 16:15:33 -08009#include <linux/mutex.h>
Alan Stern35a58e82014-06-03 11:11:34 -040010#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/usb.h>
12
Roger Quadros3b0d0892013-12-18 15:40:10 +053013#define SIMPLE_IO_TIMEOUT 10000 /* in milliseconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15/*-------------------------------------------------------------------------*/
16
Martin Fuzzeyfabbf212010-10-01 00:20:42 +020017/* FIXME make these public somewhere; usbdevfs.h? */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018struct usbtest_param {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +020019 /* inputs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 unsigned test_num; /* 0..(TEST_CASES-1) */
21 unsigned iterations;
22 unsigned length;
23 unsigned vary;
24 unsigned sglen;
25
Martin Fuzzeyfabbf212010-10-01 00:20:42 +020026 /* outputs */
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 struct timeval duration;
28};
29#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
30
31/*-------------------------------------------------------------------------*/
32
33#define GENERIC /* let probe() bind using module params */
34
35/* Some devices that can be used for testing will have "real" drivers.
36 * Entries for those need to be enabled here by hand, after disabling
37 * that "real" driver.
38 */
39//#define IBOT2 /* grab iBOT2 webcams */
40//#define KEYSPAN_19Qi /* grab un-renumerated serial adapter */
41
42/*-------------------------------------------------------------------------*/
43
44struct usbtest_info {
45 const char *name;
46 u8 ep_in; /* bulk/intr source */
47 u8 ep_out; /* bulk/intr sink */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +020048 unsigned autoconf:1;
49 unsigned ctrl_out:1;
50 unsigned iso:1; /* try iso in/out */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 int alt;
52};
53
54/* this is accessed only through usbfs ioctl calls.
55 * one ioctl to issue a test ... one lock per device.
56 * tests create other threads if they need them.
57 * urbs and buffers are allocated dynamically,
58 * and data generated deterministically.
59 */
60struct usbtest_dev {
61 struct usb_interface *intf;
62 struct usbtest_info *info;
63 int in_pipe;
64 int out_pipe;
65 int in_iso_pipe;
66 int out_iso_pipe;
67 struct usb_endpoint_descriptor *iso_in, *iso_out;
Matthias Kaehlcke1cfab022007-12-13 16:15:33 -080068 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70#define TBUF_SIZE 256
71 u8 *buf;
72};
73
Martin Fuzzeyfabbf212010-10-01 00:20:42 +020074static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Martin Fuzzeyfabbf212010-10-01 00:20:42 +020076 return interface_to_usbdev(test->intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
79/* set up all urbs so they can be used with either bulk or interrupt */
80#define INTERRUPT_RATE 1 /* msec/transfer */
81
David Brownell28ffd792008-04-25 18:51:10 -070082#define ERROR(tdev, fmt, args...) \
83 dev_err(&(tdev)->intf->dev , fmt , ## args)
Arjan van de Venb6c63932008-07-25 01:45:52 -070084#define WARNING(tdev, fmt, args...) \
David Brownell28ffd792008-04-25 18:51:10 -070085 dev_warn(&(tdev)->intf->dev , fmt , ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Martin Fuzzey084fb202011-01-16 19:17:11 +010087#define GUARD_BYTE 0xA5
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/*-------------------------------------------------------------------------*/
90
91static int
Martin Fuzzeyfabbf212010-10-01 00:20:42 +020092get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 int tmp;
95 struct usb_host_interface *alt;
96 struct usb_host_endpoint *in, *out;
97 struct usb_host_endpoint *iso_in, *iso_out;
98 struct usb_device *udev;
99
100 for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
101 unsigned ep;
102
103 in = out = NULL;
104 iso_in = iso_out = NULL;
105 alt = intf->altsetting + tmp;
106
107 /* take the first altsetting with in-bulk + out-bulk;
Justin P. Mattock70f23fd2011-05-10 10:16:21 +0200108 * ignore other endpoints and altsettings.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 */
110 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
111 struct usb_host_endpoint *e;
112
113 e = alt->endpoint + ep;
114 switch (e->desc.bmAttributes) {
115 case USB_ENDPOINT_XFER_BULK:
116 break;
117 case USB_ENDPOINT_XFER_ISOC:
118 if (dev->info->iso)
119 goto try_iso;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200120 /* FALLTHROUGH */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 default:
122 continue;
123 }
Luiz Fernando N. Capitulino4d823dd2006-10-26 13:03:02 -0300124 if (usb_endpoint_dir_in(&e->desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (!in)
126 in = e;
127 } else {
128 if (!out)
129 out = e;
130 }
131 continue;
132try_iso:
Luiz Fernando N. Capitulino4d823dd2006-10-26 13:03:02 -0300133 if (usb_endpoint_dir_in(&e->desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 if (!iso_in)
135 iso_in = e;
136 } else {
137 if (!iso_out)
138 iso_out = e;
139 }
140 }
Ming Lei951fd8e2010-08-02 22:09:17 +0800141 if ((in && out) || iso_in || iso_out)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 goto found;
143 }
144 return -EINVAL;
145
146found:
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200147 udev = testdev_to_usbdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 if (alt->desc.bAlternateSetting != 0) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200149 tmp = usb_set_interface(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 alt->desc.bInterfaceNumber,
151 alt->desc.bAlternateSetting);
152 if (tmp < 0)
153 return tmp;
154 }
155
156 if (in) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200157 dev->in_pipe = usb_rcvbulkpipe(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200159 dev->out_pipe = usb_sndbulkpipe(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
161 }
162 if (iso_in) {
163 dev->iso_in = &iso_in->desc;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200164 dev->in_iso_pipe = usb_rcvisocpipe(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 iso_in->desc.bEndpointAddress
166 & USB_ENDPOINT_NUMBER_MASK);
Ming Lei951fd8e2010-08-02 22:09:17 +0800167 }
168
169 if (iso_out) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 dev->iso_out = &iso_out->desc;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200171 dev->out_iso_pipe = usb_sndisocpipe(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 iso_out->desc.bEndpointAddress
173 & USB_ENDPOINT_NUMBER_MASK);
174 }
175 return 0;
176}
177
178/*-------------------------------------------------------------------------*/
179
180/* Support for testing basic non-queued I/O streams.
181 *
182 * These just package urbs as requests that can be easily canceled.
183 * Each urb's data buffer is dynamically allocated; callers can fill
184 * them with non-zero test data (or test for it) when appropriate.
185 */
186
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200187static void simple_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
Ming Leicdc97792008-02-24 18:41:47 +0800189 complete(urb->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
Martin Fuzzey084fb202011-01-16 19:17:11 +0100192static struct urb *usbtest_alloc_urb(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 struct usb_device *udev,
194 int pipe,
Martin Fuzzey084fb202011-01-16 19:17:11 +0100195 unsigned long bytes,
196 unsigned transfer_flags,
197 unsigned offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
199 struct urb *urb;
200
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200201 urb = usb_alloc_urb(0, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (!urb)
203 return urb;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200204 usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 urb->interval = (udev->speed == USB_SPEED_HIGH)
206 ? (INTERRUPT_RATE << 3)
207 : INTERRUPT_RATE;
Martin Fuzzey084fb202011-01-16 19:17:11 +0100208 urb->transfer_flags = transfer_flags;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200209 if (usb_pipein(pipe))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 urb->transfer_flags |= URB_SHORT_NOT_OK;
Martin Fuzzey084fb202011-01-16 19:17:11 +0100211
212 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
213 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
214 GFP_KERNEL, &urb->transfer_dma);
215 else
216 urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL);
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 if (!urb->transfer_buffer) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200219 usb_free_urb(urb);
Martin Fuzzey084fb202011-01-16 19:17:11 +0100220 return NULL;
221 }
222
223 /* To test unaligned transfers add an offset and fill the
224 unused memory with a guard value */
225 if (offset) {
226 memset(urb->transfer_buffer, GUARD_BYTE, offset);
227 urb->transfer_buffer += offset;
228 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
229 urb->transfer_dma += offset;
230 }
231
232 /* For inbound transfers use guard byte so that test fails if
233 data not correctly copied */
234 memset(urb->transfer_buffer,
235 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
236 bytes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return urb;
238}
239
Martin Fuzzey084fb202011-01-16 19:17:11 +0100240static struct urb *simple_alloc_urb(
241 struct usb_device *udev,
242 int pipe,
243 unsigned long bytes)
244{
245 return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0);
246}
247
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200248static unsigned pattern;
Vikram Pandita7f4e9852009-11-09 21:24:32 -0600249static unsigned mod_pattern;
250module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR);
251MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200253static inline void simple_fill_buf(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 unsigned i;
256 u8 *buf = urb->transfer_buffer;
257 unsigned len = urb->transfer_buffer_length;
258
259 switch (pattern) {
260 default:
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200261 /* FALLTHROUGH */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 case 0:
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200263 memset(buf, 0, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 break;
265 case 1: /* mod63 */
266 for (i = 0; i < len; i++)
267 *buf++ = (u8) (i % 63);
268 break;
269 }
270}
271
Greg Dietsche304b0b52011-05-08 22:51:43 -0500272static inline unsigned long buffer_offset(void *buf)
Martin Fuzzey084fb202011-01-16 19:17:11 +0100273{
Greg Dietsche304b0b52011-05-08 22:51:43 -0500274 return (unsigned long)buf & (ARCH_KMALLOC_MINALIGN - 1);
Martin Fuzzey084fb202011-01-16 19:17:11 +0100275}
276
277static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb)
278{
279 u8 *buf = urb->transfer_buffer;
280 u8 *guard = buf - buffer_offset(buf);
281 unsigned i;
282
283 for (i = 0; guard < buf; i++, guard++) {
284 if (*guard != GUARD_BYTE) {
285 ERROR(tdev, "guard byte[%d] %d (not %d)\n",
286 i, *guard, GUARD_BYTE);
287 return -EINVAL;
288 }
289 }
290 return 0;
291}
292
293static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
295 unsigned i;
296 u8 expected;
297 u8 *buf = urb->transfer_buffer;
298 unsigned len = urb->actual_length;
299
Martin Fuzzey084fb202011-01-16 19:17:11 +0100300 int ret = check_guard_bytes(tdev, urb);
301 if (ret)
302 return ret;
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 for (i = 0; i < len; i++, buf++) {
305 switch (pattern) {
306 /* all-zeroes has no synchronization issues */
307 case 0:
308 expected = 0;
309 break;
310 /* mod63 stays in sync with short-terminated transfers,
311 * or otherwise when host and gadget agree on how large
312 * each usb transfer request should be. resync is done
313 * with set_interface or set_config.
314 */
315 case 1: /* mod63 */
316 expected = i % 63;
317 break;
318 /* always fail unsupported patterns */
319 default:
320 expected = !*buf;
321 break;
322 }
323 if (*buf == expected)
324 continue;
David Brownell28ffd792008-04-25 18:51:10 -0700325 ERROR(tdev, "buf[%d] = %d (not %d)\n", i, *buf, expected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 return -EINVAL;
327 }
328 return 0;
329}
330
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200331static void simple_free_urb(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Greg Dietsche304b0b52011-05-08 22:51:43 -0500333 unsigned long offset = buffer_offset(urb->transfer_buffer);
Martin Fuzzey084fb202011-01-16 19:17:11 +0100334
335 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
336 usb_free_coherent(
337 urb->dev,
338 urb->transfer_buffer_length + offset,
339 urb->transfer_buffer - offset,
340 urb->transfer_dma - offset);
341 else
342 kfree(urb->transfer_buffer - offset);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200343 usb_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200346static int simple_io(
David Brownell28ffd792008-04-25 18:51:10 -0700347 struct usbtest_dev *tdev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 struct urb *urb,
349 int iterations,
350 int vary,
351 int expected,
352 const char *label
353)
354{
355 struct usb_device *udev = urb->dev;
356 int max = urb->transfer_buffer_length;
357 struct completion completion;
358 int retval = 0;
Roger Quadros3b0d0892013-12-18 15:40:10 +0530359 unsigned long expire;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 urb->context = &completion;
362 while (retval == 0 && iterations-- > 0) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200363 init_completion(&completion);
Sebastian Andrzej Siewior7c79d092011-08-23 10:44:54 +0200364 if (usb_pipeout(urb->pipe)) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200365 simple_fill_buf(urb);
Sebastian Andrzej Siewior7c79d092011-08-23 10:44:54 +0200366 urb->transfer_flags |= URB_ZERO_PACKET;
367 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200368 retval = usb_submit_urb(urb, GFP_KERNEL);
369 if (retval != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 break;
371
Roger Quadros3b0d0892013-12-18 15:40:10 +0530372 expire = msecs_to_jiffies(SIMPLE_IO_TIMEOUT);
373 if (!wait_for_completion_timeout(&completion, expire)) {
374 usb_kill_urb(urb);
375 retval = (urb->status == -ENOENT ?
376 -ETIMEDOUT : urb->status);
377 } else {
378 retval = urb->status;
379 }
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 urb->dev = udev;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200382 if (retval == 0 && usb_pipein(urb->pipe))
David Brownell28ffd792008-04-25 18:51:10 -0700383 retval = simple_check_buf(tdev, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 if (vary) {
386 int len = urb->transfer_buffer_length;
387
388 len += vary;
389 len %= max;
390 if (len == 0)
391 len = (vary < max) ? vary : max;
392 urb->transfer_buffer_length = len;
393 }
394
395 /* FIXME if endpoint halted, clear halt (and log) */
396 }
397 urb->transfer_buffer_length = max;
398
399 if (expected != retval)
David Brownell28ffd792008-04-25 18:51:10 -0700400 dev_err(&udev->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 "%s failed, iterations left %d, status %d (not %d)\n",
402 label, iterations, retval, expected);
403 return retval;
404}
405
406
407/*-------------------------------------------------------------------------*/
408
409/* We use scatterlist primitives to test queued I/O.
410 * Yes, this also tests the scatterlist primitives.
411 */
412
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200413static void free_sglist(struct scatterlist *sg, int nents)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
415 unsigned i;
David Brownell28ffd792008-04-25 18:51:10 -0700416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 if (!sg)
418 return;
419 for (i = 0; i < nents; i++) {
Jens Axboe45711f12007-10-22 21:19:53 +0200420 if (!sg_page(&sg[i]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 continue;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200422 kfree(sg_virt(&sg[i]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200424 kfree(sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427static struct scatterlist *
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200428alloc_sglist(int nents, int max, int vary)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 struct scatterlist *sg;
431 unsigned i;
432 unsigned size = max;
433
Xi Wang8bde9a62012-04-09 15:48:45 -0400434 sg = kmalloc_array(nents, sizeof *sg, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 if (!sg)
436 return NULL;
Alan Stern4756feb2008-03-27 10:15:22 -0400437 sg_init_table(sg, nents);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 for (i = 0; i < nents; i++) {
440 char *buf;
David Brownell8b524902006-04-02 10:20:15 -0800441 unsigned j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200443 buf = kzalloc(size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 if (!buf) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200445 free_sglist(sg, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return NULL;
447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 /* kmalloc pages are always physically contiguous! */
Alan Stern4756feb2008-03-27 10:15:22 -0400450 sg_set_buf(&sg[i], buf, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
David Brownell8b524902006-04-02 10:20:15 -0800452 switch (pattern) {
453 case 0:
454 /* already zeroed */
455 break;
456 case 1:
457 for (j = 0; j < size; j++)
458 *buf++ = (u8) (j % 63);
459 break;
460 }
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 if (vary) {
463 size += vary;
464 size %= max;
465 if (size == 0)
466 size = (vary < max) ? vary : max;
467 }
468 }
469
470 return sg;
471}
472
Alan Stern35a58e82014-06-03 11:11:34 -0400473static void sg_timeout(unsigned long _req)
474{
475 struct usb_sg_request *req = (struct usb_sg_request *) _req;
476
477 req->status = -ETIMEDOUT;
478 usb_sg_cancel(req);
479}
480
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200481static int perform_sglist(
David Brownell28ffd792008-04-25 18:51:10 -0700482 struct usbtest_dev *tdev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 unsigned iterations,
484 int pipe,
485 struct usb_sg_request *req,
486 struct scatterlist *sg,
487 int nents
488)
489{
David Brownell28ffd792008-04-25 18:51:10 -0700490 struct usb_device *udev = testdev_to_usbdev(tdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 int retval = 0;
Alan Stern35a58e82014-06-03 11:11:34 -0400492 struct timer_list sg_timer;
493
494 setup_timer_on_stack(&sg_timer, sg_timeout, (unsigned long) req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 while (retval == 0 && iterations-- > 0) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200497 retval = usb_sg_init(req, udev, pipe,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 (udev->speed == USB_SPEED_HIGH)
499 ? (INTERRUPT_RATE << 3)
500 : INTERRUPT_RATE,
Christoph Lametere94b1762006-12-06 20:33:17 -0800501 sg, nents, 0, GFP_KERNEL);
David Brownell28ffd792008-04-25 18:51:10 -0700502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (retval)
504 break;
Alan Stern35a58e82014-06-03 11:11:34 -0400505 mod_timer(&sg_timer, jiffies +
506 msecs_to_jiffies(SIMPLE_IO_TIMEOUT));
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200507 usb_sg_wait(req);
Alan Stern35a58e82014-06-03 11:11:34 -0400508 del_timer_sync(&sg_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 retval = req->status;
510
David Brownell8b524902006-04-02 10:20:15 -0800511 /* FIXME check resulting data pattern */
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 /* FIXME if endpoint halted, clear halt (and log) */
514 }
515
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200516 /* FIXME for unlink or fault handling tests, don't report
517 * failure if retval is as we expected ...
518 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (retval)
David Brownell28ffd792008-04-25 18:51:10 -0700520 ERROR(tdev, "perform_sglist failed, "
521 "iterations left %d, status %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 iterations, retval);
523 return retval;
524}
525
526
527/*-------------------------------------------------------------------------*/
528
529/* unqueued control message testing
530 *
531 * there's a nice set of device functional requirements in chapter 9 of the
532 * usb 2.0 spec, which we can apply to ANY device, even ones that don't use
533 * special test firmware.
534 *
535 * we know the device is configured (or suspended) by the time it's visible
536 * through usbfs. we can't change that, so we won't test enumeration (which
537 * worked 'well enough' to get here, this time), power management (ditto),
538 * or remote wakeup (which needs human interaction).
539 */
540
541static unsigned realworld = 1;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200542module_param(realworld, uint, 0);
543MODULE_PARM_DESC(realworld, "clear to demand stricter spec compliance");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200545static int get_altsetting(struct usbtest_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
547 struct usb_interface *iface = dev->intf;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200548 struct usb_device *udev = interface_to_usbdev(iface);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 int retval;
550
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200551 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200553 0, iface->altsetting[0].desc.bInterfaceNumber,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 dev->buf, 1, USB_CTRL_GET_TIMEOUT);
555 switch (retval) {
556 case 1:
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200557 return dev->buf[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 case 0:
559 retval = -ERANGE;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200560 /* FALLTHROUGH */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 default:
562 return retval;
563 }
564}
565
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200566static int set_altsetting(struct usbtest_dev *dev, int alternate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567{
568 struct usb_interface *iface = dev->intf;
569 struct usb_device *udev;
570
571 if (alternate < 0 || alternate >= 256)
572 return -EINVAL;
573
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200574 udev = interface_to_usbdev(iface);
575 return usb_set_interface(udev,
576 iface->altsetting[0].desc.bInterfaceNumber,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 alternate);
578}
579
David Brownell28ffd792008-04-25 18:51:10 -0700580static int is_good_config(struct usbtest_dev *tdev, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
582 struct usb_config_descriptor *config;
David Brownell28ffd792008-04-25 18:51:10 -0700583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (len < sizeof *config)
585 return 0;
David Brownell28ffd792008-04-25 18:51:10 -0700586 config = (struct usb_config_descriptor *) tdev->buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 switch (config->bDescriptorType) {
589 case USB_DT_CONFIG:
590 case USB_DT_OTHER_SPEED_CONFIG:
591 if (config->bLength != 9) {
David Brownell28ffd792008-04-25 18:51:10 -0700592 ERROR(tdev, "bogus config descriptor length\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 return 0;
594 }
595 /* this bit 'must be 1' but often isn't */
596 if (!realworld && !(config->bmAttributes & 0x80)) {
David Brownell28ffd792008-04-25 18:51:10 -0700597 ERROR(tdev, "high bit of config attributes not set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 return 0;
599 }
600 if (config->bmAttributes & 0x1f) { /* reserved == 0 */
David Brownell28ffd792008-04-25 18:51:10 -0700601 ERROR(tdev, "reserved config bits set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 return 0;
603 }
604 break;
605 default:
606 return 0;
607 }
608
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200609 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 return 1;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200611 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 return 1;
David Brownell28ffd792008-04-25 18:51:10 -0700613 ERROR(tdev, "bogus config descriptor read size\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 return 0;
615}
616
617/* sanity test for standard requests working with usb_control_mesg() and some
618 * of the utility functions which use it.
619 *
620 * this doesn't test how endpoint halts behave or data toggles get set, since
621 * we won't do I/O to bulk/interrupt endpoints here (which is how to change
622 * halt or toggle). toggle testing is impractical without support from hcds.
623 *
624 * this avoids failing devices linux would normally work with, by not testing
625 * config/altsetting operations for devices that only support their defaults.
626 * such devices rarely support those needless operations.
627 *
628 * NOTE that since this is a sanity test, it's not examining boundary cases
629 * to see if usbcore, hcd, and device all behave right. such testing would
630 * involve varied read sizes and other operation sequences.
631 */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200632static int ch9_postconfig(struct usbtest_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
634 struct usb_interface *iface = dev->intf;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200635 struct usb_device *udev = interface_to_usbdev(iface);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 int i, alt, retval;
637
638 /* [9.2.3] if there's more than one altsetting, we need to be able to
639 * set and get each one. mostly trusts the descriptors from usbcore.
640 */
641 for (i = 0; i < iface->num_altsetting; i++) {
642
643 /* 9.2.3 constrains the range here */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200644 alt = iface->altsetting[i].desc.bAlternateSetting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (alt < 0 || alt >= iface->num_altsetting) {
David Brownell28ffd792008-04-25 18:51:10 -0700646 dev_err(&iface->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 "invalid alt [%d].bAltSetting = %d\n",
648 i, alt);
649 }
650
651 /* [real world] get/set unimplemented if there's only one */
652 if (realworld && iface->num_altsetting == 1)
653 continue;
654
655 /* [9.4.10] set_interface */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200656 retval = set_altsetting(dev, alt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 if (retval) {
David Brownell28ffd792008-04-25 18:51:10 -0700658 dev_err(&iface->dev, "can't set_interface = %d, %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 alt, retval);
660 return retval;
661 }
662
663 /* [9.4.4] get_interface always works */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200664 retval = get_altsetting(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 if (retval != alt) {
David Brownell28ffd792008-04-25 18:51:10 -0700666 dev_err(&iface->dev, "get alt should be %d, was %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 alt, retval);
668 return (retval < 0) ? retval : -EDOM;
669 }
670
671 }
672
673 /* [real world] get_config unimplemented if there's only one */
674 if (!realworld || udev->descriptor.bNumConfigurations != 1) {
675 int expected = udev->actconfig->desc.bConfigurationValue;
676
677 /* [9.4.2] get_configuration always works
678 * ... although some cheap devices (like one TI Hub I've got)
679 * won't return config descriptors except before set_config.
680 */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200681 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 USB_REQ_GET_CONFIGURATION,
683 USB_DIR_IN | USB_RECIP_DEVICE,
684 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200685 if (retval != 1 || dev->buf[0] != expected) {
David Brownell28ffd792008-04-25 18:51:10 -0700686 dev_err(&iface->dev, "get config --> %d %d (1 %d)\n",
David Brownellff7c79e2005-04-22 13:17:00 -0700687 retval, dev->buf[0], expected);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 return (retval < 0) ? retval : -EDOM;
689 }
690 }
691
692 /* there's always [9.4.3] a device descriptor [9.6.1] */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200693 retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 dev->buf, sizeof udev->descriptor);
695 if (retval != sizeof udev->descriptor) {
David Brownell28ffd792008-04-25 18:51:10 -0700696 dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 return (retval < 0) ? retval : -EDOM;
698 }
699
700 /* there's always [9.4.3] at least one config descriptor [9.6.3] */
701 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200702 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 dev->buf, TBUF_SIZE);
David Brownell28ffd792008-04-25 18:51:10 -0700704 if (!is_good_config(dev, retval)) {
705 dev_err(&iface->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 "config [%d] descriptor --> %d\n",
707 i, retval);
708 return (retval < 0) ? retval : -EDOM;
709 }
710
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200711 /* FIXME cross-checking udev->config[i] to make sure usbcore
712 * parsed it right (etc) would be good testing paranoia
713 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715
716 /* and sometimes [9.2.6.6] speed dependent descriptors */
717 if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200718 struct usb_qualifier_descriptor *d = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 /* device qualifier [9.6.2] */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200721 retval = usb_get_descriptor(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 USB_DT_DEVICE_QUALIFIER, 0, dev->buf,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200723 sizeof(struct usb_qualifier_descriptor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 if (retval == -EPIPE) {
725 if (udev->speed == USB_SPEED_HIGH) {
David Brownell28ffd792008-04-25 18:51:10 -0700726 dev_err(&iface->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 "hs dev qualifier --> %d\n",
728 retval);
729 return (retval < 0) ? retval : -EDOM;
730 }
731 /* usb2.0 but not high-speed capable; fine */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200732 } else if (retval != sizeof(struct usb_qualifier_descriptor)) {
David Brownell28ffd792008-04-25 18:51:10 -0700733 dev_err(&iface->dev, "dev qualifier --> %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return (retval < 0) ? retval : -EDOM;
735 } else
736 d = (struct usb_qualifier_descriptor *) dev->buf;
737
738 /* might not have [9.6.2] any other-speed configs [9.6.4] */
739 if (d) {
740 unsigned max = d->bNumConfigurations;
741 for (i = 0; i < max; i++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200742 retval = usb_get_descriptor(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 USB_DT_OTHER_SPEED_CONFIG, i,
744 dev->buf, TBUF_SIZE);
David Brownell28ffd792008-04-25 18:51:10 -0700745 if (!is_good_config(dev, retval)) {
746 dev_err(&iface->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 "other speed config --> %d\n",
748 retval);
749 return (retval < 0) ? retval : -EDOM;
750 }
751 }
752 }
753 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200754 /* FIXME fetch strings from at least the device descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756 /* [9.4.5] get_status always works */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200757 retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 if (retval != 2) {
David Brownell28ffd792008-04-25 18:51:10 -0700759 dev_err(&iface->dev, "get dev status --> %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 return (retval < 0) ? retval : -EDOM;
761 }
762
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200763 /* FIXME configuration.bmAttributes says if we could try to set/clear
764 * the device's remote wakeup feature ... if we can, test that here
765 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200767 retval = usb_get_status(udev, USB_RECIP_INTERFACE,
768 iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 if (retval != 2) {
David Brownell28ffd792008-04-25 18:51:10 -0700770 dev_err(&iface->dev, "get interface status --> %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 return (retval < 0) ? retval : -EDOM;
772 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200773 /* FIXME get status for each endpoint in the interface */
David Brownell28ffd792008-04-25 18:51:10 -0700774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 return 0;
776}
777
778/*-------------------------------------------------------------------------*/
779
780/* use ch9 requests to test whether:
781 * (a) queues work for control, keeping N subtests queued and
782 * active (auto-resubmit) for M loops through the queue.
783 * (b) protocol stalls (control-only) will autorecover.
784 * it's not like bulk/intr; no halt clearing.
785 * (c) short control reads are reported and handled.
786 * (d) queues are always processed in-order
787 */
788
789struct ctrl_ctx {
790 spinlock_t lock;
791 struct usbtest_dev *dev;
792 struct completion complete;
793 unsigned count;
794 unsigned pending;
795 int status;
796 struct urb **urb;
797 struct usbtest_param *param;
798 int last;
799};
800
801#define NUM_SUBCASES 15 /* how many test subcases here? */
802
803struct subcase {
804 struct usb_ctrlrequest setup;
805 int number;
806 int expected;
807};
808
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200809static void ctrl_complete(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
811 struct ctrl_ctx *ctx = urb->context;
812 struct usb_ctrlrequest *reqp;
813 struct subcase *subcase;
814 int status = urb->status;
815
816 reqp = (struct usb_ctrlrequest *)urb->setup_packet;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200817 subcase = container_of(reqp, struct subcase, setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200819 spin_lock(&ctx->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 ctx->count--;
821 ctx->pending--;
822
823 /* queue must transfer and complete in fifo order, unless
824 * usb_unlink_urb() is used to unlink something not at the
825 * physical queue head (not tested).
826 */
827 if (subcase->number > 0) {
828 if ((subcase->number - ctx->last) != 1) {
David Brownell28ffd792008-04-25 18:51:10 -0700829 ERROR(ctx->dev,
830 "subcase %d completed out of order, last %d\n",
831 subcase->number, ctx->last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 status = -EDOM;
833 ctx->last = subcase->number;
834 goto error;
835 }
836 }
837 ctx->last = subcase->number;
838
839 /* succeed or fault in only one way? */
840 if (status == subcase->expected)
841 status = 0;
842
843 /* async unlink for cleanup? */
844 else if (status != -ECONNRESET) {
845
846 /* some faults are allowed, not required */
847 if (subcase->expected > 0 && (
Greg Kroah-Hartman59d99782007-07-18 10:58:02 -0700848 ((status == -subcase->expected /* happened */
849 || status == 0)))) /* didn't */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 status = 0;
851 /* sometimes more than one fault is allowed */
852 else if (subcase->number == 12 && status == -EPIPE)
853 status = 0;
854 else
David Brownell28ffd792008-04-25 18:51:10 -0700855 ERROR(ctx->dev, "subtest %d error, status %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 subcase->number, status);
857 }
858
859 /* unexpected status codes mean errors; ideally, in hardware */
860 if (status) {
861error:
862 if (ctx->status == 0) {
863 int i;
864
865 ctx->status = status;
David Brownell28ffd792008-04-25 18:51:10 -0700866 ERROR(ctx->dev, "control queue %02x.%02x, err %d, "
867 "%d left, subcase %d, len %d/%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 reqp->bRequestType, reqp->bRequest,
David Brownell28ffd792008-04-25 18:51:10 -0700869 status, ctx->count, subcase->number,
870 urb->actual_length,
871 urb->transfer_buffer_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 /* FIXME this "unlink everything" exit route should
874 * be a separate test case.
875 */
876
877 /* unlink whatever's still pending */
878 for (i = 1; i < ctx->param->sglen; i++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200879 struct urb *u = ctx->urb[
880 (i + subcase->number)
881 % ctx->param->sglen];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 if (u == urb || !u->dev)
884 continue;
Franck Bui-Huucaa2a122006-05-15 19:23:53 +0200885 spin_unlock(&ctx->lock);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200886 status = usb_unlink_urb(u);
Franck Bui-Huucaa2a122006-05-15 19:23:53 +0200887 spin_lock(&ctx->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 switch (status) {
889 case -EINPROGRESS:
890 case -EBUSY:
891 case -EIDRM:
892 continue;
893 default:
David Brownell28ffd792008-04-25 18:51:10 -0700894 ERROR(ctx->dev, "urb unlink --> %d\n",
895 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
897 }
898 status = ctx->status;
899 }
900 }
901
902 /* resubmit if we need to, else mark this as done */
903 if ((status == 0) && (ctx->pending < ctx->count)) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200904 status = usb_submit_urb(urb, GFP_ATOMIC);
905 if (status != 0) {
David Brownell28ffd792008-04-25 18:51:10 -0700906 ERROR(ctx->dev,
907 "can't resubmit ctrl %02x.%02x, err %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 reqp->bRequestType, reqp->bRequest, status);
909 urb->dev = NULL;
910 } else
911 ctx->pending++;
912 } else
913 urb->dev = NULL;
David Brownell28ffd792008-04-25 18:51:10 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 /* signal completion when nothing's queued */
916 if (ctx->pending == 0)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200917 complete(&ctx->complete);
918 spin_unlock(&ctx->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
921static int
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200922test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200924 struct usb_device *udev = testdev_to_usbdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 struct urb **urb;
926 struct ctrl_ctx context;
927 int i;
928
Xi Wange65cdfa2012-04-09 15:48:55 -0400929 if (param->sglen == 0 || param->iterations > UINT_MAX / param->sglen)
930 return -EOPNOTSUPP;
931
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200932 spin_lock_init(&context.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 context.dev = dev;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200934 init_completion(&context.complete);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 context.count = param->sglen * param->iterations;
936 context.pending = 0;
937 context.status = -ENOMEM;
938 context.param = param;
939 context.last = -1;
940
941 /* allocate and init the urbs we'll queue.
942 * as with bulk/intr sglists, sglen is the queue depth; it also
943 * controls which subtests run (more tests than sglen) or rerun.
944 */
Christoph Lametere94b1762006-12-06 20:33:17 -0800945 urb = kcalloc(param->sglen, sizeof(struct urb *), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 if (!urb)
947 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 for (i = 0; i < param->sglen; i++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200949 int pipe = usb_rcvctrlpipe(udev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 unsigned len;
951 struct urb *u;
952 struct usb_ctrlrequest req;
953 struct subcase *reqp;
Marcin Slusarz6def7552008-05-12 20:17:25 +0200954
955 /* sign of this variable means:
956 * -: tested code must return this (negative) error code
957 * +: tested code may return this (negative too) error code
958 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 int expected = 0;
960
961 /* requests here are mostly expected to succeed on any
962 * device, but some are chosen to trigger protocol stalls
963 * or short reads.
964 */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200965 memset(&req, 0, sizeof req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 req.bRequest = USB_REQ_GET_DESCRIPTOR;
967 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
968
969 switch (i % NUM_SUBCASES) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200970 case 0: /* get device descriptor */
971 req.wValue = cpu_to_le16(USB_DT_DEVICE << 8);
972 len = sizeof(struct usb_device_descriptor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200974 case 1: /* get first config descriptor (only) */
975 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
976 len = sizeof(struct usb_config_descriptor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200978 case 2: /* get altsetting (OFTEN STALLS) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 req.bRequest = USB_REQ_GET_INTERFACE;
980 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200981 /* index = 0 means first interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 len = 1;
983 expected = EPIPE;
984 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200985 case 3: /* get interface status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 req.bRequest = USB_REQ_GET_STATUS;
987 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200988 /* interface 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 len = 2;
990 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200991 case 4: /* get device status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 req.bRequest = USB_REQ_GET_STATUS;
993 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
994 len = 2;
995 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200996 case 5: /* get device qualifier (MAY STALL) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +0200998 len = sizeof(struct usb_qualifier_descriptor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (udev->speed != USB_SPEED_HIGH)
1000 expected = EPIPE;
1001 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001002 case 6: /* get first config descriptor, plus interface */
1003 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
1004 len = sizeof(struct usb_config_descriptor);
1005 len += sizeof(struct usb_interface_descriptor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001007 case 7: /* get interface descriptor (ALWAYS STALLS) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001009 /* interface == 0 */
1010 len = sizeof(struct usb_interface_descriptor);
David Brownell28ffd792008-04-25 18:51:10 -07001011 expected = -EPIPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001013 /* NOTE: two consecutive stalls in the queue here.
1014 * that tests fault recovery a bit more aggressively. */
1015 case 8: /* clear endpoint halt (MAY STALL) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 req.bRequest = USB_REQ_CLEAR_FEATURE;
1017 req.bRequestType = USB_RECIP_ENDPOINT;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001018 /* wValue 0 == ep halt */
1019 /* wIndex 0 == ep0 (shouldn't halt!) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 len = 0;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001021 pipe = usb_sndctrlpipe(udev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 expected = EPIPE;
1023 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001024 case 9: /* get endpoint status */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 req.bRequest = USB_REQ_GET_STATUS;
1026 req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001027 /* endpoint 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 len = 2;
1029 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001030 case 10: /* trigger short read (EREMOTEIO) */
1031 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 len = 1024;
1033 expected = -EREMOTEIO;
1034 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001035 /* NOTE: two consecutive _different_ faults in the queue. */
1036 case 11: /* get endpoint descriptor (ALWAYS STALLS) */
1037 req.wValue = cpu_to_le16(USB_DT_ENDPOINT << 8);
1038 /* endpoint == 0 */
1039 len = sizeof(struct usb_interface_descriptor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 expected = EPIPE;
1041 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001042 /* NOTE: sometimes even a third fault in the queue! */
1043 case 12: /* get string 0 descriptor (MAY STALL) */
1044 req.wValue = cpu_to_le16(USB_DT_STRING << 8);
1045 /* string == 0, for language IDs */
1046 len = sizeof(struct usb_interface_descriptor);
1047 /* may succeed when > 4 languages */
1048 expected = EREMOTEIO; /* or EPIPE, if no strings */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001050 case 13: /* short read, resembling case 10 */
1051 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
1052 /* last data packet "should" be DATA1, not DATA0 */
Paul Zimmerman0053c7e2012-04-16 14:19:07 -07001053 if (udev->speed == USB_SPEED_SUPER)
1054 len = 1024 - 512;
1055 else
1056 len = 1024 - udev->descriptor.bMaxPacketSize0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 expected = -EREMOTEIO;
1058 break;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001059 case 14: /* short read; try to fill the last packet */
1060 req.wValue = cpu_to_le16((USB_DT_DEVICE << 8) | 0);
David Brownell28ffd792008-04-25 18:51:10 -07001061 /* device descriptor size == 18 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 len = udev->descriptor.bMaxPacketSize0;
Sebastian Andrzej Siewior67e7d642011-04-14 16:17:21 +02001063 if (udev->speed == USB_SPEED_SUPER)
1064 len = 512;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 switch (len) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001066 case 8:
1067 len = 24;
1068 break;
1069 case 16:
1070 len = 32;
1071 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 }
1073 expected = -EREMOTEIO;
1074 break;
1075 default:
David Brownell28ffd792008-04-25 18:51:10 -07001076 ERROR(dev, "bogus number of ctrl queue testcases!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 context.status = -EINVAL;
1078 goto cleanup;
1079 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001080 req.wLength = cpu_to_le16(len);
1081 urb[i] = u = simple_alloc_urb(udev, pipe, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 if (!u)
1083 goto cleanup;
1084
Alan Stern0ede76f2010-03-05 15:10:17 -05001085 reqp = kmalloc(sizeof *reqp, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (!reqp)
1087 goto cleanup;
1088 reqp->setup = req;
1089 reqp->number = i % NUM_SUBCASES;
1090 reqp->expected = expected;
1091 u->setup_packet = (char *) &reqp->setup;
1092
1093 u->context = &context;
1094 u->complete = ctrl_complete;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 }
1096
1097 /* queue the urbs */
1098 context.urb = urb;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001099 spin_lock_irq(&context.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 for (i = 0; i < param->sglen; i++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001101 context.status = usb_submit_urb(urb[i], GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 if (context.status != 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001103 ERROR(dev, "can't submit urb[%d], status %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 i, context.status);
1105 context.count = context.pending;
1106 break;
1107 }
1108 context.pending++;
1109 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001110 spin_unlock_irq(&context.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 /* FIXME set timer and time out; provide a disconnect hook */
1113
1114 /* wait for the last one to complete */
1115 if (context.pending > 0)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001116 wait_for_completion(&context.complete);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118cleanup:
1119 for (i = 0; i < param->sglen; i++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001120 if (!urb[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 continue;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001122 urb[i]->dev = udev;
Alan Stern0ede76f2010-03-05 15:10:17 -05001123 kfree(urb[i]->setup_packet);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001124 simple_free_urb(urb[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001126 kfree(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 return context.status;
1128}
1129#undef NUM_SUBCASES
1130
1131
1132/*-------------------------------------------------------------------------*/
1133
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001134static void unlink1_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
1136 int status = urb->status;
1137
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001138 /* we "know" -EPIPE (stall) never happens */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 if (!status)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001140 status = usb_submit_urb(urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 if (status) {
1142 urb->status = status;
Ming Leicdc97792008-02-24 18:41:47 +08001143 complete(urb->context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 }
1145}
1146
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001147static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
1149 struct urb *urb;
1150 struct completion completion;
1151 int retval = 0;
1152
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001153 init_completion(&completion);
1154 urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (!urb)
1156 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 urb->context = &completion;
1158 urb->complete = unlink1_callback;
1159
Huang Rui43e5e632014-05-26 10:55:36 +08001160 if (usb_pipeout(urb->pipe)) {
1161 simple_fill_buf(urb);
1162 urb->transfer_flags |= URB_ZERO_PACKET;
1163 }
1164
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 /* keep the endpoint busy. there are lots of hc/hcd-internal
1166 * states, and testing should get to all of them over time.
1167 *
1168 * FIXME want additional tests for when endpoint is STALLing
1169 * due to errors, or is just NAKing requests.
1170 */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001171 retval = usb_submit_urb(urb, GFP_KERNEL);
1172 if (retval != 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001173 dev_err(&dev->intf->dev, "submit fail %d\n", retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 return retval;
1175 }
1176
1177 /* unlinking that should always work. variable delay tests more
1178 * hcd states and code paths, even with little other system load.
1179 */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001180 msleep(jiffies % (2 * INTERRUPT_RATE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 if (async) {
Martin Fuzzey3b6c0232009-06-04 23:20:38 +02001182 while (!completion_done(&completion)) {
1183 retval = usb_unlink_urb(urb);
1184
1185 switch (retval) {
1186 case -EBUSY:
1187 case -EIDRM:
1188 /* we can't unlink urbs while they're completing
1189 * or if they've completed, and we haven't
1190 * resubmitted. "normal" drivers would prevent
1191 * resubmission, but since we're testing unlink
1192 * paths, we can't.
1193 */
1194 ERROR(dev, "unlink retry\n");
1195 continue;
1196 case 0:
1197 case -EINPROGRESS:
1198 break;
1199
1200 default:
1201 dev_err(&dev->intf->dev,
1202 "unlink fail %d\n", retval);
1203 return retval;
1204 }
1205
1206 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
1208 } else
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001209 usb_kill_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001211 wait_for_completion(&completion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 retval = urb->status;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001213 simple_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 if (async)
1216 return (retval == -ECONNRESET) ? 0 : retval - 1000;
1217 else
1218 return (retval == -ENOENT || retval == -EPERM) ?
1219 0 : retval - 2000;
1220}
1221
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001222static int unlink_simple(struct usbtest_dev *dev, int pipe, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
1224 int retval = 0;
1225
1226 /* test sync and async paths */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001227 retval = unlink1(dev, pipe, len, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 if (!retval)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001229 retval = unlink1(dev, pipe, len, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 return retval;
1231}
1232
1233/*-------------------------------------------------------------------------*/
1234
Alan Stern869410f2011-04-14 11:21:04 -04001235struct queued_ctx {
1236 struct completion complete;
1237 atomic_t pending;
1238 unsigned num;
1239 int status;
1240 struct urb **urbs;
1241};
1242
1243static void unlink_queued_callback(struct urb *urb)
1244{
1245 int status = urb->status;
1246 struct queued_ctx *ctx = urb->context;
1247
1248 if (ctx->status)
1249 goto done;
1250 if (urb == ctx->urbs[ctx->num - 4] || urb == ctx->urbs[ctx->num - 2]) {
1251 if (status == -ECONNRESET)
1252 goto done;
1253 /* What error should we report if the URB completed normally? */
1254 }
1255 if (status != 0)
1256 ctx->status = status;
1257
1258 done:
1259 if (atomic_dec_and_test(&ctx->pending))
1260 complete(&ctx->complete);
1261}
1262
1263static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num,
1264 unsigned size)
1265{
1266 struct queued_ctx ctx;
1267 struct usb_device *udev = testdev_to_usbdev(dev);
1268 void *buf;
1269 dma_addr_t buf_dma;
1270 int i;
1271 int retval = -ENOMEM;
1272
1273 init_completion(&ctx.complete);
1274 atomic_set(&ctx.pending, 1); /* One more than the actual value */
1275 ctx.num = num;
1276 ctx.status = 0;
1277
1278 buf = usb_alloc_coherent(udev, size, GFP_KERNEL, &buf_dma);
1279 if (!buf)
1280 return retval;
1281 memset(buf, 0, size);
1282
1283 /* Allocate and init the urbs we'll queue */
1284 ctx.urbs = kcalloc(num, sizeof(struct urb *), GFP_KERNEL);
1285 if (!ctx.urbs)
1286 goto free_buf;
1287 for (i = 0; i < num; i++) {
1288 ctx.urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1289 if (!ctx.urbs[i])
1290 goto free_urbs;
1291 usb_fill_bulk_urb(ctx.urbs[i], udev, pipe, buf, size,
1292 unlink_queued_callback, &ctx);
1293 ctx.urbs[i]->transfer_dma = buf_dma;
1294 ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
Huang Rui43e5e632014-05-26 10:55:36 +08001295
1296 if (usb_pipeout(ctx.urbs[i]->pipe)) {
1297 simple_fill_buf(ctx.urbs[i]);
1298 ctx.urbs[i]->transfer_flags |= URB_ZERO_PACKET;
1299 }
Alan Stern869410f2011-04-14 11:21:04 -04001300 }
1301
1302 /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */
1303 for (i = 0; i < num; i++) {
1304 atomic_inc(&ctx.pending);
1305 retval = usb_submit_urb(ctx.urbs[i], GFP_KERNEL);
1306 if (retval != 0) {
1307 dev_err(&dev->intf->dev, "submit urbs[%d] fail %d\n",
1308 i, retval);
1309 atomic_dec(&ctx.pending);
1310 ctx.status = retval;
1311 break;
1312 }
1313 }
1314 if (i == num) {
1315 usb_unlink_urb(ctx.urbs[num - 4]);
1316 usb_unlink_urb(ctx.urbs[num - 2]);
1317 } else {
1318 while (--i >= 0)
1319 usb_unlink_urb(ctx.urbs[i]);
1320 }
1321
1322 if (atomic_dec_and_test(&ctx.pending)) /* The extra count */
1323 complete(&ctx.complete);
1324 wait_for_completion(&ctx.complete);
1325 retval = ctx.status;
1326
1327 free_urbs:
1328 for (i = 0; i < num; i++)
1329 usb_free_urb(ctx.urbs[i]);
1330 kfree(ctx.urbs);
1331 free_buf:
1332 usb_free_coherent(udev, size, buf, buf_dma);
1333 return retval;
1334}
1335
1336/*-------------------------------------------------------------------------*/
1337
David Brownell28ffd792008-04-25 18:51:10 -07001338static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
1340 int retval;
1341 u16 status;
1342
1343 /* shouldn't look or act halted */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001344 retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 if (retval < 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001346 ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n",
1347 ep, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 return retval;
1349 }
1350 if (status != 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001351 ERROR(tdev, "ep %02x bogus status: %04x != 0\n", ep, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 return -EINVAL;
1353 }
David Brownell28ffd792008-04-25 18:51:10 -07001354 retval = simple_io(tdev, urb, 1, 0, 0, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 if (retval != 0)
1356 return -EINVAL;
1357 return 0;
1358}
1359
David Brownell28ffd792008-04-25 18:51:10 -07001360static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
1362 int retval;
1363 u16 status;
1364
1365 /* should look and act halted */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001366 retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 if (retval < 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001368 ERROR(tdev, "ep %02x couldn't get halt status, %d\n",
1369 ep, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 return retval;
1371 }
Jan Andersson6ce45602008-01-08 16:39:49 +01001372 le16_to_cpus(&status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 if (status != 1) {
David Brownell28ffd792008-04-25 18:51:10 -07001374 ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 return -EINVAL;
1376 }
David Brownell28ffd792008-04-25 18:51:10 -07001377 retval = simple_io(tdev, urb, 1, 0, -EPIPE, __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 if (retval != -EPIPE)
1379 return -EINVAL;
David Brownell28ffd792008-04-25 18:51:10 -07001380 retval = simple_io(tdev, urb, 1, 0, -EPIPE, "verify_still_halted");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 if (retval != -EPIPE)
1382 return -EINVAL;
1383 return 0;
1384}
1385
David Brownell28ffd792008-04-25 18:51:10 -07001386static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
1388 int retval;
1389
1390 /* shouldn't look or act halted now */
David Brownell28ffd792008-04-25 18:51:10 -07001391 retval = verify_not_halted(tdev, ep, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 if (retval < 0)
1393 return retval;
1394
1395 /* set halt (protocol test only), verify it worked */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001396 retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT,
1398 USB_ENDPOINT_HALT, ep,
1399 NULL, 0, USB_CTRL_SET_TIMEOUT);
1400 if (retval < 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001401 ERROR(tdev, "ep %02x couldn't set halt, %d\n", ep, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 return retval;
1403 }
David Brownell28ffd792008-04-25 18:51:10 -07001404 retval = verify_halted(tdev, ep, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 if (retval < 0)
1406 return retval;
1407
1408 /* clear halt (tests API + protocol), verify it worked */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001409 retval = usb_clear_halt(urb->dev, urb->pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 if (retval < 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001411 ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 return retval;
1413 }
David Brownell28ffd792008-04-25 18:51:10 -07001414 retval = verify_not_halted(tdev, ep, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 if (retval < 0)
1416 return retval;
1417
1418 /* NOTE: could also verify SET_INTERFACE clear halts ... */
1419
1420 return 0;
1421}
1422
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001423static int halt_simple(struct usbtest_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
Paul Zimmerman0053c7e2012-04-16 14:19:07 -07001425 int ep;
1426 int retval = 0;
1427 struct urb *urb;
1428 struct usb_device *udev = testdev_to_usbdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Paul Zimmerman0053c7e2012-04-16 14:19:07 -07001430 if (udev->speed == USB_SPEED_SUPER)
1431 urb = simple_alloc_urb(udev, 0, 1024);
1432 else
1433 urb = simple_alloc_urb(udev, 0, 512);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 if (urb == NULL)
1435 return -ENOMEM;
1436
1437 if (dev->in_pipe) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001438 ep = usb_pipeendpoint(dev->in_pipe) | USB_DIR_IN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 urb->pipe = dev->in_pipe;
David Brownell28ffd792008-04-25 18:51:10 -07001440 retval = test_halt(dev, ep, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 if (retval < 0)
1442 goto done;
1443 }
1444
1445 if (dev->out_pipe) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001446 ep = usb_pipeendpoint(dev->out_pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 urb->pipe = dev->out_pipe;
David Brownell28ffd792008-04-25 18:51:10 -07001448 retval = test_halt(dev, ep, urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
1450done:
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001451 simple_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 return retval;
1453}
1454
1455/*-------------------------------------------------------------------------*/
1456
1457/* Control OUT tests use the vendor control requests from Intel's
1458 * USB 2.0 compliance test device: write a buffer, read it back.
1459 *
1460 * Intel's spec only _requires_ that it work for one packet, which
1461 * is pretty weak. Some HCDs place limits here; most devices will
1462 * need to be able to handle more than one OUT data packet. We'll
1463 * try whatever we're told to try.
1464 */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001465static int ctrl_out(struct usbtest_dev *dev,
Martin Fuzzey084fb202011-01-16 19:17:11 +01001466 unsigned count, unsigned length, unsigned vary, unsigned offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Orjan Fribergf54fa842006-08-08 23:31:40 -07001468 unsigned i, j, len;
1469 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 u8 *buf;
1471 char *what = "?";
1472 struct usb_device *udev;
Orjan Fribergf54fa842006-08-08 23:31:40 -07001473
David Brownellff7c79e2005-04-22 13:17:00 -07001474 if (length < 1 || length > 0xffff || vary >= length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 return -EINVAL;
1476
Martin Fuzzey084fb202011-01-16 19:17:11 +01001477 buf = kmalloc(length + offset, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 if (!buf)
1479 return -ENOMEM;
1480
Martin Fuzzey084fb202011-01-16 19:17:11 +01001481 buf += offset;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001482 udev = testdev_to_usbdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 len = length;
1484 retval = 0;
1485
1486 /* NOTE: hardware might well act differently if we pushed it
1487 * with lots back-to-back queued requests.
1488 */
1489 for (i = 0; i < count; i++) {
1490 /* write patterned data */
1491 for (j = 0; j < len; j++)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001492 buf[j] = i + j;
1493 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR,
1495 0, 0, buf, len, USB_CTRL_SET_TIMEOUT);
1496 if (retval != len) {
1497 what = "write";
David Brownellff7c79e2005-04-22 13:17:00 -07001498 if (retval >= 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001499 ERROR(dev, "ctrl_out, wlen %d (expected %d)\n",
David Brownellff7c79e2005-04-22 13:17:00 -07001500 retval, len);
1501 retval = -EBADMSG;
1502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 break;
1504 }
1505
1506 /* read it back -- assuming nothing intervened!! */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001507 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 0x5c, USB_DIR_IN|USB_TYPE_VENDOR,
1509 0, 0, buf, len, USB_CTRL_GET_TIMEOUT);
1510 if (retval != len) {
1511 what = "read";
David Brownellff7c79e2005-04-22 13:17:00 -07001512 if (retval >= 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001513 ERROR(dev, "ctrl_out, rlen %d (expected %d)\n",
David Brownellff7c79e2005-04-22 13:17:00 -07001514 retval, len);
1515 retval = -EBADMSG;
1516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 break;
1518 }
1519
1520 /* fail if we can't verify */
1521 for (j = 0; j < len; j++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001522 if (buf[j] != (u8) (i + j)) {
David Brownell28ffd792008-04-25 18:51:10 -07001523 ERROR(dev, "ctrl_out, byte %d is %d not %d\n",
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001524 j, buf[j], (u8) i + j);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 retval = -EBADMSG;
1526 break;
1527 }
1528 }
1529 if (retval < 0) {
1530 what = "verify";
1531 break;
1532 }
1533
1534 len += vary;
David Brownellff7c79e2005-04-22 13:17:00 -07001535
1536 /* [real world] the "zero bytes IN" case isn't really used.
Joe Perchesdc0d5c12007-12-17 11:40:18 -08001537 * hardware can easily trip up in this weird case, since its
David Brownellff7c79e2005-04-22 13:17:00 -07001538 * status stage is IN, not OUT like other ep0in transfers.
1539 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 if (len > length)
David Brownellff7c79e2005-04-22 13:17:00 -07001541 len = realworld ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 }
1543
1544 if (retval < 0)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001545 ERROR(dev, "ctrl_out %s failed, code %d, count %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 what, retval, i);
1547
Martin Fuzzey084fb202011-01-16 19:17:11 +01001548 kfree(buf - offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 return retval;
1550}
1551
1552/*-------------------------------------------------------------------------*/
1553
1554/* ISO tests ... mimics common usage
1555 * - buffer length is split into N packets (mostly maxpacket sized)
1556 * - multi-buffers according to sglen
1557 */
1558
1559struct iso_context {
1560 unsigned count;
1561 unsigned pending;
1562 spinlock_t lock;
1563 struct completion done;
Alan Stern9da21502006-05-22 16:47:13 -04001564 int submit_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 unsigned long errors;
Alan Stern9da21502006-05-22 16:47:13 -04001566 unsigned long packet_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 struct usbtest_dev *dev;
1568};
1569
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001570static void iso_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571{
1572 struct iso_context *ctx = urb->context;
1573
1574 spin_lock(&ctx->lock);
1575 ctx->count--;
1576
Alan Stern9da21502006-05-22 16:47:13 -04001577 ctx->packet_count += urb->number_of_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 if (urb->error_count > 0)
1579 ctx->errors += urb->error_count;
Alan Stern9da21502006-05-22 16:47:13 -04001580 else if (urb->status != 0)
1581 ctx->errors += urb->number_of_packets;
Martin Fuzzey40aed522010-10-01 00:20:48 +02001582 else if (urb->actual_length != urb->transfer_buffer_length)
1583 ctx->errors++;
Martin Fuzzey084fb202011-01-16 19:17:11 +01001584 else if (check_guard_bytes(ctx->dev, urb) != 0)
1585 ctx->errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
Alan Stern9da21502006-05-22 16:47:13 -04001587 if (urb->status == 0 && ctx->count > (ctx->pending - 1)
1588 && !ctx->submit_error) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001589 int status = usb_submit_urb(urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 switch (status) {
1591 case 0:
1592 goto done;
1593 default:
David Brownell28ffd792008-04-25 18:51:10 -07001594 dev_err(&ctx->dev->intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 "iso resubmit err %d\n",
1596 status);
1597 /* FALLTHROUGH */
1598 case -ENODEV: /* disconnected */
Alan Stern9da21502006-05-22 16:47:13 -04001599 case -ESHUTDOWN: /* endpoint disabled */
1600 ctx->submit_error = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 break;
1602 }
1603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
1605 ctx->pending--;
1606 if (ctx->pending == 0) {
1607 if (ctx->errors)
David Brownell28ffd792008-04-25 18:51:10 -07001608 dev_err(&ctx->dev->intf->dev,
Alan Stern9da21502006-05-22 16:47:13 -04001609 "iso test, %lu errors out of %lu\n",
1610 ctx->errors, ctx->packet_count);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001611 complete(&ctx->done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 }
1613done:
1614 spin_unlock(&ctx->lock);
1615}
1616
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001617static struct urb *iso_alloc_urb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 struct usb_device *udev,
1619 int pipe,
1620 struct usb_endpoint_descriptor *desc,
Martin Fuzzey084fb202011-01-16 19:17:11 +01001621 long bytes,
1622 unsigned offset
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623)
1624{
1625 struct urb *urb;
1626 unsigned i, maxp, packets;
1627
1628 if (bytes < 0 || !desc)
1629 return NULL;
Kuninori Morimoto29cc8892011-08-23 03:12:03 -07001630 maxp = 0x7ff & usb_endpoint_maxp(desc);
1631 maxp *= 1 + (0x3 & (usb_endpoint_maxp(desc) >> 11));
Julia Lawalldfa5ec72008-03-04 15:25:11 -08001632 packets = DIV_ROUND_UP(bytes, maxp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001634 urb = usb_alloc_urb(packets, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 if (!urb)
1636 return urb;
1637 urb->dev = udev;
1638 urb->pipe = pipe;
1639
1640 urb->number_of_packets = packets;
1641 urb->transfer_buffer_length = bytes;
Martin Fuzzey084fb202011-01-16 19:17:11 +01001642 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
1643 GFP_KERNEL,
1644 &urb->transfer_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 if (!urb->transfer_buffer) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001646 usb_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 return NULL;
1648 }
Martin Fuzzey084fb202011-01-16 19:17:11 +01001649 if (offset) {
1650 memset(urb->transfer_buffer, GUARD_BYTE, offset);
1651 urb->transfer_buffer += offset;
1652 urb->transfer_dma += offset;
1653 }
1654 /* For inbound transfers use guard byte so that test fails if
1655 data not correctly copied */
1656 memset(urb->transfer_buffer,
1657 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
1658 bytes);
1659
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 for (i = 0; i < packets; i++) {
1661 /* here, only the last packet will be short */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001662 urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 bytes -= urb->iso_frame_desc[i].length;
1664
1665 urb->iso_frame_desc[i].offset = maxp * i;
1666 }
1667
1668 urb->complete = iso_callback;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001669 /* urb->context = SET BY CALLER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 urb->interval = 1 << (desc->bInterval - 1);
1671 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
1672 return urb;
1673}
1674
1675static int
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001676test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
Martin Fuzzey084fb202011-01-16 19:17:11 +01001677 int pipe, struct usb_endpoint_descriptor *desc, unsigned offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
1679 struct iso_context context;
1680 struct usb_device *udev;
1681 unsigned i;
1682 unsigned long packets = 0;
Alan Stern9da21502006-05-22 16:47:13 -04001683 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 struct urb *urbs[10]; /* FIXME no limit */
1685
1686 if (param->sglen > 10)
1687 return -EDOM;
1688
Alan Stern9da21502006-05-22 16:47:13 -04001689 memset(&context, 0, sizeof context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 context.count = param->iterations * param->sglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 context.dev = dev;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001692 init_completion(&context.done);
1693 spin_lock_init(&context.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001695 memset(urbs, 0, sizeof urbs);
1696 udev = testdev_to_usbdev(dev);
David Brownell28ffd792008-04-25 18:51:10 -07001697 dev_info(&dev->intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 "... iso period %d %sframes, wMaxPacket %04x\n",
1699 1 << (desc->bInterval - 1),
1700 (udev->speed == USB_SPEED_HIGH) ? "micro" : "",
Kuninori Morimoto29cc8892011-08-23 03:12:03 -07001701 usb_endpoint_maxp(desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
1703 for (i = 0; i < param->sglen; i++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001704 urbs[i] = iso_alloc_urb(udev, pipe, desc,
Martin Fuzzey084fb202011-01-16 19:17:11 +01001705 param->length, offset);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001706 if (!urbs[i]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 status = -ENOMEM;
1708 goto fail;
1709 }
1710 packets += urbs[i]->number_of_packets;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001711 urbs[i]->context = &context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 }
1713 packets *= param->iterations;
David Brownell28ffd792008-04-25 18:51:10 -07001714 dev_info(&dev->intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 "... total %lu msec (%lu packets)\n",
1716 (packets * (1 << (desc->bInterval - 1)))
1717 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1),
1718 packets);
1719
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001720 spin_lock_irq(&context.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 for (i = 0; i < param->sglen; i++) {
Alan Stern9da21502006-05-22 16:47:13 -04001722 ++context.pending;
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001723 status = usb_submit_urb(urbs[i], GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 if (status < 0) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001725 ERROR(dev, "submit iso[%d], error %d\n", i, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 if (i == 0) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001727 spin_unlock_irq(&context.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 goto fail;
1729 }
1730
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001731 simple_free_urb(urbs[i]);
Ming Leie10e1be2010-08-02 22:09:01 +08001732 urbs[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 context.pending--;
Alan Stern9da21502006-05-22 16:47:13 -04001734 context.submit_error = 1;
1735 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 }
1737 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001738 spin_unlock_irq(&context.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001740 wait_for_completion(&context.done);
Alan Stern9da21502006-05-22 16:47:13 -04001741
Ming Leie10e1be2010-08-02 22:09:01 +08001742 for (i = 0; i < param->sglen; i++) {
1743 if (urbs[i])
1744 simple_free_urb(urbs[i]);
1745 }
Alan Stern9da21502006-05-22 16:47:13 -04001746 /*
1747 * Isochronous transfers are expected to fail sometimes. As an
1748 * arbitrary limit, we will report an error if any submissions
1749 * fail or if the transfer failure rate is > 10%.
1750 */
1751 if (status != 0)
1752 ;
1753 else if (context.submit_error)
1754 status = -EACCES;
1755 else if (context.errors > context.packet_count / 10)
1756 status = -EIO;
1757 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
1759fail:
1760 for (i = 0; i < param->sglen; i++) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001761 if (urbs[i])
1762 simple_free_urb(urbs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 }
1764 return status;
1765}
1766
Martin Fuzzey084fb202011-01-16 19:17:11 +01001767static int test_unaligned_bulk(
1768 struct usbtest_dev *tdev,
1769 int pipe,
1770 unsigned length,
1771 int iterations,
1772 unsigned transfer_flags,
1773 const char *label)
1774{
1775 int retval;
1776 struct urb *urb = usbtest_alloc_urb(
1777 testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1);
1778
1779 if (!urb)
1780 return -ENOMEM;
1781
1782 retval = simple_io(tdev, urb, iterations, 0, 0, label);
1783 simple_free_urb(urb);
1784 return retval;
1785}
1786
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787/*-------------------------------------------------------------------------*/
1788
1789/* We only have this one interface to user space, through usbfs.
1790 * User mode code can scan usbfs to find N different devices (maybe on
1791 * different busses) to use when testing, and allocate one thread per
1792 * test. So discovery is simplified, and we have no device naming issues.
1793 *
1794 * Don't use these only as stress/load tests. Use them along with with
1795 * other USB bus activity: plugging, unplugging, mousing, mp3 playback,
1796 * video capture, and so on. Run different tests at different times, in
1797 * different sequences. Nothing here should interact with other devices,
1798 * except indirectly by consuming USB bandwidth and CPU resources for test
1799 * threads and request completion. But the only way to know that for sure
1800 * is to test when HC queues are in use by many devices.
David Brownell28ffd792008-04-25 18:51:10 -07001801 *
1802 * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(),
1803 * it locks out usbcore in certain code paths. Notably, if you disconnect
1804 * the device-under-test, khubd will wait block forever waiting for the
1805 * ioctl to complete ... so that usb_disconnect() can abort the pending
1806 * urbs and then call usbtest_disconnect(). To abort a test, you're best
1807 * off just killing the userspace task and waiting for it to exit.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 */
1809
1810static int
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001811usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001813 struct usbtest_dev *dev = usb_get_intfdata(intf);
1814 struct usb_device *udev = testdev_to_usbdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 struct usbtest_param *param = buf;
1816 int retval = -EOPNOTSUPP;
1817 struct urb *urb;
1818 struct scatterlist *sg;
1819 struct usb_sg_request req;
1820 struct timeval start;
1821 unsigned i;
1822
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001823 /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
Vikram Pandita7f4e9852009-11-09 21:24:32 -06001825 pattern = mod_pattern;
1826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 if (code != USBTEST_REQUEST)
1828 return -EOPNOTSUPP;
1829
roel kluin8aafdf62008-10-21 00:36:44 -04001830 if (param->iterations <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 return -EINVAL;
1832
Matthias Kaehlcke1cfab022007-12-13 16:15:33 -08001833 if (mutex_lock_interruptible(&dev->lock))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 return -ERESTARTSYS;
1835
Alan Stern70a1c9e2008-03-06 17:00:58 -05001836 /* FIXME: What if a system sleep starts while a test is running? */
David Brownellff7c79e2005-04-22 13:17:00 -07001837
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 /* some devices, like ez-usb default devices, need a non-default
1839 * altsetting to have any active endpoints. some tests change
1840 * altsettings; force a default so most tests don't need to check.
1841 */
1842 if (dev->info->alt >= 0) {
David Brownell28ffd792008-04-25 18:51:10 -07001843 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
1845 if (intf->altsetting->desc.bInterfaceNumber) {
Matthias Kaehlcke1cfab022007-12-13 16:15:33 -08001846 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 return -ENODEV;
1848 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001849 res = set_altsetting(dev, dev->info->alt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 if (res) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001851 dev_err(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 "set altsetting to %d failed, %d\n",
1853 dev->info->alt, res);
Matthias Kaehlcke1cfab022007-12-13 16:15:33 -08001854 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 return res;
1856 }
1857 }
1858
1859 /*
1860 * Just a bunch of test cases that every HCD is expected to handle.
1861 *
1862 * Some may need specific firmware, though it'd be good to have
1863 * one firmware image to handle all the test cases.
1864 *
1865 * FIXME add more tests! cancel requests, verify the data, control
1866 * queueing, concurrent read+write threads, and so on.
1867 */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001868 do_gettimeofday(&start);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 switch (param->test_num) {
1870
1871 case 0:
David Brownell28ffd792008-04-25 18:51:10 -07001872 dev_info(&intf->dev, "TEST 0: NOP\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 retval = 0;
1874 break;
1875
1876 /* Simple non-queued bulk I/O tests */
1877 case 1:
1878 if (dev->out_pipe == 0)
1879 break;
David Brownell28ffd792008-04-25 18:51:10 -07001880 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 "TEST 1: write %d bytes %u times\n",
1882 param->length, param->iterations);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001883 urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 if (!urb) {
1885 retval = -ENOMEM;
1886 break;
1887 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001888 /* FIRMWARE: bulk sink (maybe accepts short writes) */
David Brownell28ffd792008-04-25 18:51:10 -07001889 retval = simple_io(dev, urb, param->iterations, 0, 0, "test1");
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001890 simple_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 break;
1892 case 2:
1893 if (dev->in_pipe == 0)
1894 break;
David Brownell28ffd792008-04-25 18:51:10 -07001895 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 "TEST 2: read %d bytes %u times\n",
1897 param->length, param->iterations);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001898 urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 if (!urb) {
1900 retval = -ENOMEM;
1901 break;
1902 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001903 /* FIRMWARE: bulk source (maybe generates short writes) */
David Brownell28ffd792008-04-25 18:51:10 -07001904 retval = simple_io(dev, urb, param->iterations, 0, 0, "test2");
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001905 simple_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 break;
1907 case 3:
1908 if (dev->out_pipe == 0 || param->vary == 0)
1909 break;
David Brownell28ffd792008-04-25 18:51:10 -07001910 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 "TEST 3: write/%d 0..%d bytes %u times\n",
1912 param->vary, param->length, param->iterations);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001913 urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 if (!urb) {
1915 retval = -ENOMEM;
1916 break;
1917 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001918 /* FIRMWARE: bulk sink (maybe accepts short writes) */
David Brownell28ffd792008-04-25 18:51:10 -07001919 retval = simple_io(dev, urb, param->iterations, param->vary,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 0, "test3");
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001921 simple_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 break;
1923 case 4:
1924 if (dev->in_pipe == 0 || param->vary == 0)
1925 break;
David Brownell28ffd792008-04-25 18:51:10 -07001926 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 "TEST 4: read/%d 0..%d bytes %u times\n",
1928 param->vary, param->length, param->iterations);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001929 urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 if (!urb) {
1931 retval = -ENOMEM;
1932 break;
1933 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001934 /* FIRMWARE: bulk source (maybe generates short writes) */
David Brownell28ffd792008-04-25 18:51:10 -07001935 retval = simple_io(dev, urb, param->iterations, param->vary,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 0, "test4");
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001937 simple_free_urb(urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 break;
1939
1940 /* Queued bulk I/O tests */
1941 case 5:
1942 if (dev->out_pipe == 0 || param->sglen == 0)
1943 break;
David Brownell28ffd792008-04-25 18:51:10 -07001944 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 "TEST 5: write %d sglists %d entries of %d bytes\n",
1946 param->iterations,
1947 param->sglen, param->length);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001948 sg = alloc_sglist(param->sglen, param->length, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 if (!sg) {
1950 retval = -ENOMEM;
1951 break;
1952 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001953 /* FIRMWARE: bulk sink (maybe accepts short writes) */
David Brownell28ffd792008-04-25 18:51:10 -07001954 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 &req, sg, param->sglen);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001956 free_sglist(sg, param->sglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 break;
1958
1959 case 6:
1960 if (dev->in_pipe == 0 || param->sglen == 0)
1961 break;
David Brownell28ffd792008-04-25 18:51:10 -07001962 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 "TEST 6: read %d sglists %d entries of %d bytes\n",
1964 param->iterations,
1965 param->sglen, param->length);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001966 sg = alloc_sglist(param->sglen, param->length, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 if (!sg) {
1968 retval = -ENOMEM;
1969 break;
1970 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001971 /* FIRMWARE: bulk source (maybe generates short writes) */
David Brownell28ffd792008-04-25 18:51:10 -07001972 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 &req, sg, param->sglen);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001974 free_sglist(sg, param->sglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 break;
1976 case 7:
1977 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0)
1978 break;
David Brownell28ffd792008-04-25 18:51:10 -07001979 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n",
1981 param->vary, param->iterations,
1982 param->sglen, param->length);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001983 sg = alloc_sglist(param->sglen, param->length, param->vary);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 if (!sg) {
1985 retval = -ENOMEM;
1986 break;
1987 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001988 /* FIRMWARE: bulk sink (maybe accepts short writes) */
David Brownell28ffd792008-04-25 18:51:10 -07001989 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 &req, sg, param->sglen);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02001991 free_sglist(sg, param->sglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 break;
1993 case 8:
1994 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0)
1995 break;
David Brownell28ffd792008-04-25 18:51:10 -07001996 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n",
1998 param->vary, param->iterations,
1999 param->sglen, param->length);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002000 sg = alloc_sglist(param->sglen, param->length, param->vary);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 if (!sg) {
2002 retval = -ENOMEM;
2003 break;
2004 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002005 /* FIRMWARE: bulk source (maybe generates short writes) */
David Brownell28ffd792008-04-25 18:51:10 -07002006 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 &req, sg, param->sglen);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002008 free_sglist(sg, param->sglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 break;
2010
2011 /* non-queued sanity tests for control (chapter 9 subset) */
2012 case 9:
2013 retval = 0;
David Brownell28ffd792008-04-25 18:51:10 -07002014 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 "TEST 9: ch9 (subset) control tests, %d times\n",
2016 param->iterations);
2017 for (i = param->iterations; retval == 0 && i--; /* NOP */)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002018 retval = ch9_postconfig(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 if (retval)
David Brownell28ffd792008-04-25 18:51:10 -07002020 dev_err(&intf->dev, "ch9 subset failed, "
2021 "iterations left %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 break;
2023
2024 /* queued control messaging */
2025 case 10:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 retval = 0;
David Brownell28ffd792008-04-25 18:51:10 -07002027 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 "TEST 10: queue %d control calls, %d times\n",
2029 param->sglen,
2030 param->iterations);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002031 retval = test_ctrl_queue(dev, param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 break;
2033
2034 /* simple non-queued unlinks (ring with one urb) */
2035 case 11:
2036 if (dev->in_pipe == 0 || !param->length)
2037 break;
2038 retval = 0;
David Brownell28ffd792008-04-25 18:51:10 -07002039 dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 param->iterations, param->length);
2041 for (i = param->iterations; retval == 0 && i--; /* NOP */)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002042 retval = unlink_simple(dev, dev->in_pipe,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 param->length);
2044 if (retval)
David Brownell28ffd792008-04-25 18:51:10 -07002045 dev_err(&intf->dev, "unlink reads failed %d, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 "iterations left %d\n", retval, i);
2047 break;
2048 case 12:
2049 if (dev->out_pipe == 0 || !param->length)
2050 break;
2051 retval = 0;
David Brownell28ffd792008-04-25 18:51:10 -07002052 dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 param->iterations, param->length);
2054 for (i = param->iterations; retval == 0 && i--; /* NOP */)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002055 retval = unlink_simple(dev, dev->out_pipe,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 param->length);
2057 if (retval)
David Brownell28ffd792008-04-25 18:51:10 -07002058 dev_err(&intf->dev, "unlink writes failed %d, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 "iterations left %d\n", retval, i);
2060 break;
2061
2062 /* ep halt tests */
2063 case 13:
2064 if (dev->out_pipe == 0 && dev->in_pipe == 0)
2065 break;
2066 retval = 0;
David Brownell28ffd792008-04-25 18:51:10 -07002067 dev_info(&intf->dev, "TEST 13: set/clear %d halts\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 param->iterations);
2069 for (i = param->iterations; retval == 0 && i--; /* NOP */)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002070 retval = halt_simple(dev);
David Brownell28ffd792008-04-25 18:51:10 -07002071
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 if (retval)
David Brownell28ffd792008-04-25 18:51:10 -07002073 ERROR(dev, "halts failed, iterations left %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 break;
2075
2076 /* control write tests */
2077 case 14:
2078 if (!dev->info->ctrl_out)
2079 break;
David Brownell28ffd792008-04-25 18:51:10 -07002080 dev_info(&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n",
David Brownellff7c79e2005-04-22 13:17:00 -07002081 param->iterations,
2082 realworld ? 1 : 0, param->length,
2083 param->vary);
David Brownell28ffd792008-04-25 18:51:10 -07002084 retval = ctrl_out(dev, param->iterations,
Martin Fuzzey084fb202011-01-16 19:17:11 +01002085 param->length, param->vary, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 break;
2087
2088 /* iso write tests */
2089 case 15:
2090 if (dev->out_iso_pipe == 0 || param->sglen == 0)
2091 break;
David Brownell28ffd792008-04-25 18:51:10 -07002092 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 "TEST 15: write %d iso, %d entries of %d bytes\n",
2094 param->iterations,
2095 param->sglen, param->length);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002096 /* FIRMWARE: iso sink */
2097 retval = test_iso_queue(dev, param,
Martin Fuzzey084fb202011-01-16 19:17:11 +01002098 dev->out_iso_pipe, dev->iso_out, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 break;
2100
2101 /* iso read tests */
2102 case 16:
2103 if (dev->in_iso_pipe == 0 || param->sglen == 0)
2104 break;
David Brownell28ffd792008-04-25 18:51:10 -07002105 dev_info(&intf->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 "TEST 16: read %d iso, %d entries of %d bytes\n",
2107 param->iterations,
2108 param->sglen, param->length);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002109 /* FIRMWARE: iso source */
2110 retval = test_iso_queue(dev, param,
Martin Fuzzey084fb202011-01-16 19:17:11 +01002111 dev->in_iso_pipe, dev->iso_in, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 break;
2113
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002114 /* FIXME scatterlist cancel (needs helper thread) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Martin Fuzzey084fb202011-01-16 19:17:11 +01002116 /* Tests for bulk I/O using DMA mapping by core and odd address */
2117 case 17:
2118 if (dev->out_pipe == 0)
2119 break;
2120 dev_info(&intf->dev,
2121 "TEST 17: write odd addr %d bytes %u times core map\n",
2122 param->length, param->iterations);
2123
2124 retval = test_unaligned_bulk(
2125 dev, dev->out_pipe,
2126 param->length, param->iterations,
2127 0, "test17");
2128 break;
2129
2130 case 18:
2131 if (dev->in_pipe == 0)
2132 break;
2133 dev_info(&intf->dev,
2134 "TEST 18: read odd addr %d bytes %u times core map\n",
2135 param->length, param->iterations);
2136
2137 retval = test_unaligned_bulk(
2138 dev, dev->in_pipe,
2139 param->length, param->iterations,
2140 0, "test18");
2141 break;
2142
2143 /* Tests for bulk I/O using premapped coherent buffer and odd address */
2144 case 19:
2145 if (dev->out_pipe == 0)
2146 break;
2147 dev_info(&intf->dev,
2148 "TEST 19: write odd addr %d bytes %u times premapped\n",
2149 param->length, param->iterations);
2150
2151 retval = test_unaligned_bulk(
2152 dev, dev->out_pipe,
2153 param->length, param->iterations,
2154 URB_NO_TRANSFER_DMA_MAP, "test19");
2155 break;
2156
2157 case 20:
2158 if (dev->in_pipe == 0)
2159 break;
2160 dev_info(&intf->dev,
2161 "TEST 20: read odd addr %d bytes %u times premapped\n",
2162 param->length, param->iterations);
2163
2164 retval = test_unaligned_bulk(
2165 dev, dev->in_pipe,
2166 param->length, param->iterations,
2167 URB_NO_TRANSFER_DMA_MAP, "test20");
2168 break;
2169
2170 /* control write tests with unaligned buffer */
2171 case 21:
2172 if (!dev->info->ctrl_out)
2173 break;
2174 dev_info(&intf->dev,
2175 "TEST 21: %d ep0out odd addr, %d..%d vary %d\n",
2176 param->iterations,
2177 realworld ? 1 : 0, param->length,
2178 param->vary);
2179 retval = ctrl_out(dev, param->iterations,
2180 param->length, param->vary, 1);
2181 break;
2182
2183 /* unaligned iso tests */
2184 case 22:
2185 if (dev->out_iso_pipe == 0 || param->sglen == 0)
2186 break;
2187 dev_info(&intf->dev,
2188 "TEST 22: write %d iso odd, %d entries of %d bytes\n",
2189 param->iterations,
2190 param->sglen, param->length);
2191 retval = test_iso_queue(dev, param,
2192 dev->out_iso_pipe, dev->iso_out, 1);
2193 break;
2194
2195 case 23:
2196 if (dev->in_iso_pipe == 0 || param->sglen == 0)
2197 break;
2198 dev_info(&intf->dev,
2199 "TEST 23: read %d iso odd, %d entries of %d bytes\n",
2200 param->iterations,
2201 param->sglen, param->length);
2202 retval = test_iso_queue(dev, param,
2203 dev->in_iso_pipe, dev->iso_in, 1);
2204 break;
2205
Alan Stern869410f2011-04-14 11:21:04 -04002206 /* unlink URBs from a bulk-OUT queue */
2207 case 24:
2208 if (dev->out_pipe == 0 || !param->length || param->sglen < 4)
2209 break;
2210 retval = 0;
2211 dev_info(&intf->dev, "TEST 17: unlink from %d queues of "
2212 "%d %d-byte writes\n",
2213 param->iterations, param->sglen, param->length);
2214 for (i = param->iterations; retval == 0 && i > 0; --i) {
2215 retval = unlink_queued(dev, dev->out_pipe,
2216 param->sglen, param->length);
2217 if (retval) {
2218 dev_err(&intf->dev,
2219 "unlink queued writes failed %d, "
2220 "iterations left %d\n", retval, i);
2221 break;
2222 }
2223 }
2224 break;
2225
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 }
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002227 do_gettimeofday(&param->duration);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 param->duration.tv_sec -= start.tv_sec;
2229 param->duration.tv_usec -= start.tv_usec;
2230 if (param->duration.tv_usec < 0) {
2231 param->duration.tv_usec += 1000 * 1000;
2232 param->duration.tv_sec -= 1;
2233 }
Matthias Kaehlcke1cfab022007-12-13 16:15:33 -08002234 mutex_unlock(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 return retval;
2236}
2237
2238/*-------------------------------------------------------------------------*/
2239
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002240static unsigned force_interrupt;
2241module_param(force_interrupt, uint, 0);
2242MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
2244#ifdef GENERIC
2245static unsigned short vendor;
2246module_param(vendor, ushort, 0);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002247MODULE_PARM_DESC(vendor, "vendor code (from usb-if)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249static unsigned short product;
2250module_param(product, ushort, 0);
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002251MODULE_PARM_DESC(product, "product code (from vendor)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252#endif
2253
2254static int
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002255usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
2257 struct usb_device *udev;
2258 struct usbtest_dev *dev;
2259 struct usbtest_info *info;
2260 char *rtest, *wtest;
2261 char *irtest, *iwtest;
2262
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002263 udev = interface_to_usbdev(intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
2265#ifdef GENERIC
2266 /* specify devices by module parameters? */
2267 if (id->match_flags == 0) {
2268 /* vendor match required, product match optional */
2269 if (!vendor || le16_to_cpu(udev->descriptor.idVendor) != (u16)vendor)
2270 return -ENODEV;
2271 if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product)
2272 return -ENODEV;
David Brownell28ffd792008-04-25 18:51:10 -07002273 dev_info(&intf->dev, "matched module params, "
2274 "vend=0x%04x prod=0x%04x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 le16_to_cpu(udev->descriptor.idVendor),
2276 le16_to_cpu(udev->descriptor.idProduct));
2277 }
2278#endif
2279
Christoph Lametere94b1762006-12-06 20:33:17 -08002280 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 if (!dev)
2282 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 info = (struct usbtest_info *) id->driver_info;
2284 dev->info = info;
Matthias Kaehlcke1cfab022007-12-13 16:15:33 -08002285 mutex_init(&dev->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
2287 dev->intf = intf;
2288
2289 /* cacheline-aligned scratch for i/o */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002290 dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL);
2291 if (dev->buf == NULL) {
2292 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 return -ENOMEM;
2294 }
2295
2296 /* NOTE this doesn't yet test the handful of difference that are
2297 * visible with high speed interrupts: bigger maxpacket (1K) and
2298 * "high bandwidth" modes (up to 3 packets/uframe).
2299 */
2300 rtest = wtest = "";
2301 irtest = iwtest = "";
2302 if (force_interrupt || udev->speed == USB_SPEED_LOW) {
2303 if (info->ep_in) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002304 dev->in_pipe = usb_rcvintpipe(udev, info->ep_in);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 rtest = " intr-in";
2306 }
2307 if (info->ep_out) {
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002308 dev->out_pipe = usb_sndintpipe(udev, info->ep_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 wtest = " intr-out";
2310 }
2311 } else {
2312 if (info->autoconf) {
2313 int status;
2314
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002315 status = get_endpoints(dev, intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 if (status < 0) {
Arjan van de Venb6c63932008-07-25 01:45:52 -07002317 WARNING(dev, "couldn't get endpoints, %d\n",
David Brownell28ffd792008-04-25 18:51:10 -07002318 status);
Julia Lawallf4a728d2012-03-25 21:08:32 +02002319 kfree(dev->buf);
2320 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 return status;
2322 }
2323 /* may find bulk or ISO pipes */
2324 } else {
2325 if (info->ep_in)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002326 dev->in_pipe = usb_rcvbulkpipe(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 info->ep_in);
2328 if (info->ep_out)
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002329 dev->out_pipe = usb_sndbulkpipe(udev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 info->ep_out);
2331 }
2332 if (dev->in_pipe)
2333 rtest = " bulk-in";
2334 if (dev->out_pipe)
2335 wtest = " bulk-out";
2336 if (dev->in_iso_pipe)
2337 irtest = " iso-in";
2338 if (dev->out_iso_pipe)
2339 iwtest = " iso-out";
2340 }
2341
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002342 usb_set_intfdata(intf, dev);
2343 dev_info(&intf->dev, "%s\n", info->name);
Michal Nazarewicze538dfd2011-08-30 17:11:19 +02002344 dev_info(&intf->dev, "%s {control%s%s%s%s%s} tests%s\n",
2345 usb_speed_string(udev->speed),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 info->ctrl_out ? " in/out" : "",
2347 rtest, wtest,
2348 irtest, iwtest,
2349 info->alt >= 0 ? " (+alt)" : "");
2350 return 0;
2351}
2352
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002353static int usbtest_suspend(struct usb_interface *intf, pm_message_t message)
David Brownellff7c79e2005-04-22 13:17:00 -07002354{
David Brownellff7c79e2005-04-22 13:17:00 -07002355 return 0;
2356}
2357
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002358static int usbtest_resume(struct usb_interface *intf)
David Brownellff7c79e2005-04-22 13:17:00 -07002359{
David Brownellff7c79e2005-04-22 13:17:00 -07002360 return 0;
2361}
2362
2363
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002364static void usbtest_disconnect(struct usb_interface *intf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365{
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002366 struct usbtest_dev *dev = usb_get_intfdata(intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002368 usb_set_intfdata(intf, NULL);
2369 dev_dbg(&intf->dev, "disconnect\n");
2370 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371}
2372
2373/* Basic testing only needs a device that can source or sink bulk traffic.
2374 * Any device can test control transfers (default with GENERIC binding).
2375 *
2376 * Several entries work with the default EP0 implementation that's built
2377 * into EZ-USB chips. There's a default vendor ID which can be overridden
2378 * by (very) small config EEPROMS, but otherwise all these devices act
2379 * identically until firmware is loaded: only EP0 works. It turns out
2380 * to be easy to make other endpoints work, without modifying that EP0
2381 * behavior. For now, we expect that kind of firmware.
2382 */
2383
2384/* an21xx or fx versions of ez-usb */
2385static struct usbtest_info ez1_info = {
2386 .name = "EZ-USB device",
2387 .ep_in = 2,
2388 .ep_out = 2,
2389 .alt = 1,
2390};
2391
2392/* fx2 version of ez-usb */
2393static struct usbtest_info ez2_info = {
2394 .name = "FX2 device",
2395 .ep_in = 6,
2396 .ep_out = 2,
2397 .alt = 1,
2398};
2399
2400/* ezusb family device with dedicated usb test firmware,
2401 */
2402static struct usbtest_info fw_info = {
2403 .name = "usb test device",
2404 .ep_in = 2,
2405 .ep_out = 2,
2406 .alt = 1,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002407 .autoconf = 1, /* iso and ctrl_out need autoconf */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 .ctrl_out = 1,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002409 .iso = 1, /* iso_ep's are #8 in/out */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410};
2411
2412/* peripheral running Linux and 'zero.c' test firmware, or
2413 * its user-mode cousin. different versions of this use
2414 * different hardware with the same vendor/product codes.
2415 * host side MUST rely on the endpoint descriptors.
2416 */
2417static struct usbtest_info gz_info = {
2418 .name = "Linux gadget zero",
2419 .autoconf = 1,
2420 .ctrl_out = 1,
2421 .alt = 0,
2422};
2423
2424static struct usbtest_info um_info = {
2425 .name = "Linux user mode test driver",
2426 .autoconf = 1,
2427 .alt = -1,
2428};
2429
2430static struct usbtest_info um2_info = {
2431 .name = "Linux user mode ISO test driver",
2432 .autoconf = 1,
2433 .iso = 1,
2434 .alt = -1,
2435};
2436
2437#ifdef IBOT2
2438/* this is a nice source of high speed bulk data;
2439 * uses an FX2, with firmware provided in the device
2440 */
2441static struct usbtest_info ibot2_info = {
2442 .name = "iBOT2 webcam",
2443 .ep_in = 2,
2444 .alt = -1,
2445};
2446#endif
2447
2448#ifdef GENERIC
2449/* we can use any device to test control traffic */
2450static struct usbtest_info generic_info = {
2451 .name = "Generic USB device",
2452 .alt = -1,
2453};
2454#endif
2455
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Németh Márton33b9e162010-01-10 15:34:45 +01002457static const struct usb_device_id id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 /*-------------------------------------------------------------*/
2460
2461 /* EZ-USB devices which download firmware to replace (or in our
2462 * case augment) the default device implementation.
2463 */
2464
2465 /* generic EZ-USB FX controller */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002466 { USB_DEVICE(0x0547, 0x2235),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 .driver_info = (unsigned long) &ez1_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002468 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469
2470 /* CY3671 development board with EZ-USB FX */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002471 { USB_DEVICE(0x0547, 0x0080),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 .driver_info = (unsigned long) &ez1_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002473 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
2475 /* generic EZ-USB FX2 controller (or development board) */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002476 { USB_DEVICE(0x04b4, 0x8613),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 .driver_info = (unsigned long) &ez2_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002478 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
2480 /* re-enumerated usb test device firmware */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002481 { USB_DEVICE(0xfff0, 0xfff0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 .driver_info = (unsigned long) &fw_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002483 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
2485 /* "Gadget Zero" firmware runs under Linux */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002486 { USB_DEVICE(0x0525, 0xa4a0),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 .driver_info = (unsigned long) &gz_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002488 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
2490 /* so does a user-mode variant */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002491 { USB_DEVICE(0x0525, 0xa4a4),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 .driver_info = (unsigned long) &um_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002493 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
2495 /* ... and a user-mode variant that talks iso */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002496 { USB_DEVICE(0x0525, 0xa4a3),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 .driver_info = (unsigned long) &um2_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002498 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499
2500#ifdef KEYSPAN_19Qi
2501 /* Keyspan 19qi uses an21xx (original EZ-USB) */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002502 /* this does not coexist with the real Keyspan 19qi driver! */
2503 { USB_DEVICE(0x06cd, 0x010b),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 .driver_info = (unsigned long) &ez1_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002505 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506#endif
2507
2508 /*-------------------------------------------------------------*/
2509
2510#ifdef IBOT2
2511 /* iBOT2 makes a nice source of high speed bulk-in data */
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002512 /* this does not coexist with a real iBOT2 driver! */
2513 { USB_DEVICE(0x0b62, 0x0059),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 .driver_info = (unsigned long) &ibot2_info,
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002515 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516#endif
2517
2518 /*-------------------------------------------------------------*/
2519
2520#ifdef GENERIC
2521 /* module params can specify devices to use for control tests */
2522 { .driver_info = (unsigned long) &generic_info, },
2523#endif
2524
2525 /*-------------------------------------------------------------*/
2526
2527 { }
2528};
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002529MODULE_DEVICE_TABLE(usb, id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
2531static struct usb_driver usbtest_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 .name = "usbtest",
2533 .id_table = id_table,
2534 .probe = usbtest_probe,
Andi Kleenc532b292010-06-01 23:04:41 +02002535 .unlocked_ioctl = usbtest_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 .disconnect = usbtest_disconnect,
David Brownellff7c79e2005-04-22 13:17:00 -07002537 .suspend = usbtest_suspend,
2538 .resume = usbtest_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539};
2540
2541/*-------------------------------------------------------------------------*/
2542
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002543static int __init usbtest_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544{
2545#ifdef GENERIC
2546 if (vendor)
David Brownell28ffd792008-04-25 18:51:10 -07002547 pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548#endif
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002549 return usb_register(&usbtest_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550}
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002551module_init(usbtest_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002553static void __exit usbtest_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002555 usb_deregister(&usbtest_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556}
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002557module_exit(usbtest_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
Martin Fuzzeyfabbf212010-10-01 00:20:42 +02002559MODULE_DESCRIPTION("USB Core/HCD Testing Driver");
2560MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561