aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/misc/usbtest.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/usb/misc/usbtest.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'drivers/usb/misc/usbtest.c')
-rw-r--r--drivers/usb/misc/usbtest.c1014
1 files changed, 671 insertions, 343 deletions
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index eef370eb7a54..bb10846affc3 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -13,17 +13,16 @@
13 13
14/*-------------------------------------------------------------------------*/ 14/*-------------------------------------------------------------------------*/
15 15
16// FIXME make these public somewhere; usbdevfs.h? 16/* FIXME make these public somewhere; usbdevfs.h? */
17//
18struct usbtest_param { 17struct usbtest_param {
19 // inputs 18 /* inputs */
20 unsigned test_num; /* 0..(TEST_CASES-1) */ 19 unsigned test_num; /* 0..(TEST_CASES-1) */
21 unsigned iterations; 20 unsigned iterations;
22 unsigned length; 21 unsigned length;
23 unsigned vary; 22 unsigned vary;
24 unsigned sglen; 23 unsigned sglen;
25 24
26 // outputs 25 /* outputs */
27 struct timeval duration; 26 struct timeval duration;
28}; 27};
29#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param) 28#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
@@ -45,9 +44,9 @@ struct usbtest_info {
45 const char *name; 44 const char *name;
46 u8 ep_in; /* bulk/intr source */ 45 u8 ep_in; /* bulk/intr source */
47 u8 ep_out; /* bulk/intr sink */ 46 u8 ep_out; /* bulk/intr sink */
48 unsigned autoconf : 1; 47 unsigned autoconf:1;
49 unsigned ctrl_out : 1; 48 unsigned ctrl_out:1;
50 unsigned iso : 1; /* try iso in/out */ 49 unsigned iso:1; /* try iso in/out */
51 int alt; 50 int alt;
52}; 51};
53 52
@@ -71,9 +70,9 @@ struct usbtest_dev {
71 u8 *buf; 70 u8 *buf;
72}; 71};
73 72
74static struct usb_device *testdev_to_usbdev (struct usbtest_dev *test) 73static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
75{ 74{
76 return interface_to_usbdev (test->intf); 75 return interface_to_usbdev(test->intf);
77} 76}
78 77
79/* set up all urbs so they can be used with either bulk or interrupt */ 78/* set up all urbs so they can be used with either bulk or interrupt */
@@ -84,10 +83,12 @@ static struct usb_device *testdev_to_usbdev (struct usbtest_dev *test)
84#define WARNING(tdev, fmt, args...) \ 83#define WARNING(tdev, fmt, args...) \
85 dev_warn(&(tdev)->intf->dev , fmt , ## args) 84 dev_warn(&(tdev)->intf->dev , fmt , ## args)
86 85
86#define GUARD_BYTE 0xA5
87
87/*-------------------------------------------------------------------------*/ 88/*-------------------------------------------------------------------------*/
88 89
89static int 90static int
90get_endpoints (struct usbtest_dev *dev, struct usb_interface *intf) 91get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
91{ 92{
92 int tmp; 93 int tmp;
93 struct usb_host_interface *alt; 94 struct usb_host_interface *alt;
@@ -103,7 +104,7 @@ get_endpoints (struct usbtest_dev *dev, struct usb_interface *intf)
103 alt = intf->altsetting + tmp; 104 alt = intf->altsetting + tmp;
104 105
105 /* take the first altsetting with in-bulk + out-bulk; 106 /* take the first altsetting with in-bulk + out-bulk;
106 * ignore other endpoints and altsetttings. 107 * ignore other endpoints and altsettings.
107 */ 108 */
108 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { 109 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
109 struct usb_host_endpoint *e; 110 struct usb_host_endpoint *e;
@@ -115,7 +116,7 @@ get_endpoints (struct usbtest_dev *dev, struct usb_interface *intf)
115 case USB_ENDPOINT_XFER_ISOC: 116 case USB_ENDPOINT_XFER_ISOC:
116 if (dev->info->iso) 117 if (dev->info->iso)
117 goto try_iso; 118 goto try_iso;
118 // FALLTHROUGH 119 /* FALLTHROUGH */
119 default: 120 default:
120 continue; 121 continue;
121 } 122 }
@@ -142,9 +143,9 @@ try_iso:
142 return -EINVAL; 143 return -EINVAL;
143 144
144found: 145found:
145 udev = testdev_to_usbdev (dev); 146 udev = testdev_to_usbdev(dev);
146 if (alt->desc.bAlternateSetting != 0) { 147 if (alt->desc.bAlternateSetting != 0) {
147 tmp = usb_set_interface (udev, 148 tmp = usb_set_interface(udev,
148 alt->desc.bInterfaceNumber, 149 alt->desc.bInterfaceNumber,
149 alt->desc.bAlternateSetting); 150 alt->desc.bAlternateSetting);
150 if (tmp < 0) 151 if (tmp < 0)
@@ -152,21 +153,21 @@ found:
152 } 153 }
153 154
154 if (in) { 155 if (in) {
155 dev->in_pipe = usb_rcvbulkpipe (udev, 156 dev->in_pipe = usb_rcvbulkpipe(udev,
156 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 157 in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
157 dev->out_pipe = usb_sndbulkpipe (udev, 158 dev->out_pipe = usb_sndbulkpipe(udev,
158 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 159 out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
159 } 160 }
160 if (iso_in) { 161 if (iso_in) {
161 dev->iso_in = &iso_in->desc; 162 dev->iso_in = &iso_in->desc;
162 dev->in_iso_pipe = usb_rcvisocpipe (udev, 163 dev->in_iso_pipe = usb_rcvisocpipe(udev,
163 iso_in->desc.bEndpointAddress 164 iso_in->desc.bEndpointAddress
164 & USB_ENDPOINT_NUMBER_MASK); 165 & USB_ENDPOINT_NUMBER_MASK);
165 } 166 }
166 167
167 if (iso_out) { 168 if (iso_out) {
168 dev->iso_out = &iso_out->desc; 169 dev->iso_out = &iso_out->desc;
169 dev->out_iso_pipe = usb_sndisocpipe (udev, 170 dev->out_iso_pipe = usb_sndisocpipe(udev,
170 iso_out->desc.bEndpointAddress 171 iso_out->desc.bEndpointAddress
171 & USB_ENDPOINT_NUMBER_MASK); 172 & USB_ENDPOINT_NUMBER_MASK);
172 } 173 }
@@ -182,45 +183,73 @@ found:
182 * them with non-zero test data (or test for it) when appropriate. 183 * them with non-zero test data (or test for it) when appropriate.
183 */ 184 */
184 185
185static void simple_callback (struct urb *urb) 186static void simple_callback(struct urb *urb)
186{ 187{
187 complete(urb->context); 188 complete(urb->context);
188} 189}
189 190
190static struct urb *simple_alloc_urb ( 191static struct urb *usbtest_alloc_urb(
191 struct usb_device *udev, 192 struct usb_device *udev,
192 int pipe, 193 int pipe,
193 unsigned long bytes 194 unsigned long bytes,
194) 195 unsigned transfer_flags,
196 unsigned offset)
195{ 197{
196 struct urb *urb; 198 struct urb *urb;
197 199
198 urb = usb_alloc_urb (0, GFP_KERNEL); 200 urb = usb_alloc_urb(0, GFP_KERNEL);
199 if (!urb) 201 if (!urb)
200 return urb; 202 return urb;
201 usb_fill_bulk_urb (urb, udev, pipe, NULL, bytes, simple_callback, NULL); 203 usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, NULL);
202 urb->interval = (udev->speed == USB_SPEED_HIGH) 204 urb->interval = (udev->speed == USB_SPEED_HIGH)
203 ? (INTERRUPT_RATE << 3) 205 ? (INTERRUPT_RATE << 3)
204 : INTERRUPT_RATE; 206 : INTERRUPT_RATE;
205 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 207 urb->transfer_flags = transfer_flags;
206 if (usb_pipein (pipe)) 208 if (usb_pipein(pipe))
207 urb->transfer_flags |= URB_SHORT_NOT_OK; 209 urb->transfer_flags |= URB_SHORT_NOT_OK;
208 urb->transfer_buffer = usb_alloc_coherent (udev, bytes, GFP_KERNEL, 210
209 &urb->transfer_dma); 211 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
212 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
213 GFP_KERNEL, &urb->transfer_dma);
214 else
215 urb->transfer_buffer = kmalloc(bytes + offset, GFP_KERNEL);
216
210 if (!urb->transfer_buffer) { 217 if (!urb->transfer_buffer) {
211 usb_free_urb (urb); 218 usb_free_urb(urb);
212 urb = NULL; 219 return NULL;
213 } else 220 }
214 memset (urb->transfer_buffer, 0, bytes); 221
222 /* To test unaligned transfers add an offset and fill the
223 unused memory with a guard value */
224 if (offset) {
225 memset(urb->transfer_buffer, GUARD_BYTE, offset);
226 urb->transfer_buffer += offset;
227 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
228 urb->transfer_dma += offset;
229 }
230
231 /* For inbound transfers use guard byte so that test fails if
232 data not correctly copied */
233 memset(urb->transfer_buffer,
234 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
235 bytes);
215 return urb; 236 return urb;
216} 237}
217 238
218static unsigned pattern = 0; 239static struct urb *simple_alloc_urb(
240 struct usb_device *udev,
241 int pipe,
242 unsigned long bytes)
243{
244 return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0);
245}
246
247static unsigned pattern;
219static unsigned mod_pattern; 248static unsigned mod_pattern;
220module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR); 249module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR);
221MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)"); 250MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)");
222 251
223static inline void simple_fill_buf (struct urb *urb) 252static inline void simple_fill_buf(struct urb *urb)
224{ 253{
225 unsigned i; 254 unsigned i;
226 u8 *buf = urb->transfer_buffer; 255 u8 *buf = urb->transfer_buffer;
@@ -228,9 +257,9 @@ static inline void simple_fill_buf (struct urb *urb)
228 257
229 switch (pattern) { 258 switch (pattern) {
230 default: 259 default:
231 // FALLTHROUGH 260 /* FALLTHROUGH */
232 case 0: 261 case 0:
233 memset (buf, 0, len); 262 memset(buf, 0, len);
234 break; 263 break;
235 case 1: /* mod63 */ 264 case 1: /* mod63 */
236 for (i = 0; i < len; i++) 265 for (i = 0; i < len; i++)
@@ -239,13 +268,38 @@ static inline void simple_fill_buf (struct urb *urb)
239 } 268 }
240} 269}
241 270
242static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb) 271static inline unsigned long buffer_offset(void *buf)
272{
273 return (unsigned long)buf & (ARCH_KMALLOC_MINALIGN - 1);
274}
275
276static int check_guard_bytes(struct usbtest_dev *tdev, struct urb *urb)
277{
278 u8 *buf = urb->transfer_buffer;
279 u8 *guard = buf - buffer_offset(buf);
280 unsigned i;
281
282 for (i = 0; guard < buf; i++, guard++) {
283 if (*guard != GUARD_BYTE) {
284 ERROR(tdev, "guard byte[%d] %d (not %d)\n",
285 i, *guard, GUARD_BYTE);
286 return -EINVAL;
287 }
288 }
289 return 0;
290}
291
292static int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
243{ 293{
244 unsigned i; 294 unsigned i;
245 u8 expected; 295 u8 expected;
246 u8 *buf = urb->transfer_buffer; 296 u8 *buf = urb->transfer_buffer;
247 unsigned len = urb->actual_length; 297 unsigned len = urb->actual_length;
248 298
299 int ret = check_guard_bytes(tdev, urb);
300 if (ret)
301 return ret;
302
249 for (i = 0; i < len; i++, buf++) { 303 for (i = 0; i < len; i++, buf++) {
250 switch (pattern) { 304 switch (pattern) {
251 /* all-zeroes has no synchronization issues */ 305 /* all-zeroes has no synchronization issues */
@@ -273,14 +327,22 @@ static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
273 return 0; 327 return 0;
274} 328}
275 329
276static void simple_free_urb (struct urb *urb) 330static void simple_free_urb(struct urb *urb)
277{ 331{
278 usb_free_coherent(urb->dev, urb->transfer_buffer_length, 332 unsigned long offset = buffer_offset(urb->transfer_buffer);
279 urb->transfer_buffer, urb->transfer_dma); 333
280 usb_free_urb (urb); 334 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
335 usb_free_coherent(
336 urb->dev,
337 urb->transfer_buffer_length + offset,
338 urb->transfer_buffer - offset,
339 urb->transfer_dma - offset);
340 else
341 kfree(urb->transfer_buffer - offset);
342 usb_free_urb(urb);
281} 343}
282 344
283static int simple_io ( 345static int simple_io(
284 struct usbtest_dev *tdev, 346 struct usbtest_dev *tdev,
285 struct urb *urb, 347 struct urb *urb,
286 int iterations, 348 int iterations,
@@ -296,17 +358,18 @@ static int simple_io (
296 358
297 urb->context = &completion; 359 urb->context = &completion;
298 while (retval == 0 && iterations-- > 0) { 360 while (retval == 0 && iterations-- > 0) {
299 init_completion (&completion); 361 init_completion(&completion);
300 if (usb_pipeout (urb->pipe)) 362 if (usb_pipeout(urb->pipe))
301 simple_fill_buf (urb); 363 simple_fill_buf(urb);
302 if ((retval = usb_submit_urb (urb, GFP_KERNEL)) != 0) 364 retval = usb_submit_urb(urb, GFP_KERNEL);
365 if (retval != 0)
303 break; 366 break;
304 367
305 /* NOTE: no timeouts; can't be broken out of by interrupt */ 368 /* NOTE: no timeouts; can't be broken out of by interrupt */
306 wait_for_completion (&completion); 369 wait_for_completion(&completion);
307 retval = urb->status; 370 retval = urb->status;
308 urb->dev = udev; 371 urb->dev = udev;
309 if (retval == 0 && usb_pipein (urb->pipe)) 372 if (retval == 0 && usb_pipein(urb->pipe))
310 retval = simple_check_buf(tdev, urb); 373 retval = simple_check_buf(tdev, urb);
311 374
312 if (vary) { 375 if (vary) {
@@ -337,7 +400,7 @@ static int simple_io (
337 * Yes, this also tests the scatterlist primitives. 400 * Yes, this also tests the scatterlist primitives.
338 */ 401 */
339 402
340static void free_sglist (struct scatterlist *sg, int nents) 403static void free_sglist(struct scatterlist *sg, int nents)
341{ 404{
342 unsigned i; 405 unsigned i;
343 406
@@ -346,19 +409,19 @@ static void free_sglist (struct scatterlist *sg, int nents)
346 for (i = 0; i < nents; i++) { 409 for (i = 0; i < nents; i++) {
347 if (!sg_page(&sg[i])) 410 if (!sg_page(&sg[i]))
348 continue; 411 continue;
349 kfree (sg_virt(&sg[i])); 412 kfree(sg_virt(&sg[i]));
350 } 413 }
351 kfree (sg); 414 kfree(sg);
352} 415}
353 416
354static struct scatterlist * 417static struct scatterlist *
355alloc_sglist (int nents, int max, int vary) 418alloc_sglist(int nents, int max, int vary)
356{ 419{
357 struct scatterlist *sg; 420 struct scatterlist *sg;
358 unsigned i; 421 unsigned i;
359 unsigned size = max; 422 unsigned size = max;
360 423
361 sg = kmalloc (nents * sizeof *sg, GFP_KERNEL); 424 sg = kmalloc(nents * sizeof *sg, GFP_KERNEL);
362 if (!sg) 425 if (!sg)
363 return NULL; 426 return NULL;
364 sg_init_table(sg, nents); 427 sg_init_table(sg, nents);
@@ -367,9 +430,9 @@ alloc_sglist (int nents, int max, int vary)
367 char *buf; 430 char *buf;
368 unsigned j; 431 unsigned j;
369 432
370 buf = kzalloc (size, GFP_KERNEL); 433 buf = kzalloc(size, GFP_KERNEL);
371 if (!buf) { 434 if (!buf) {
372 free_sglist (sg, i); 435 free_sglist(sg, i);
373 return NULL; 436 return NULL;
374 } 437 }
375 438
@@ -397,7 +460,7 @@ alloc_sglist (int nents, int max, int vary)
397 return sg; 460 return sg;
398} 461}
399 462
400static int perform_sglist ( 463static int perform_sglist(
401 struct usbtest_dev *tdev, 464 struct usbtest_dev *tdev,
402 unsigned iterations, 465 unsigned iterations,
403 int pipe, 466 int pipe,
@@ -410,7 +473,7 @@ static int perform_sglist (
410 int retval = 0; 473 int retval = 0;
411 474
412 while (retval == 0 && iterations-- > 0) { 475 while (retval == 0 && iterations-- > 0) {
413 retval = usb_sg_init (req, udev, pipe, 476 retval = usb_sg_init(req, udev, pipe,
414 (udev->speed == USB_SPEED_HIGH) 477 (udev->speed == USB_SPEED_HIGH)
415 ? (INTERRUPT_RATE << 3) 478 ? (INTERRUPT_RATE << 3)
416 : INTERRUPT_RATE, 479 : INTERRUPT_RATE,
@@ -418,7 +481,7 @@ static int perform_sglist (
418 481
419 if (retval) 482 if (retval)
420 break; 483 break;
421 usb_sg_wait (req); 484 usb_sg_wait(req);
422 retval = req->status; 485 retval = req->status;
423 486
424 /* FIXME check resulting data pattern */ 487 /* FIXME check resulting data pattern */
@@ -426,9 +489,9 @@ static int perform_sglist (
426 /* FIXME if endpoint halted, clear halt (and log) */ 489 /* FIXME if endpoint halted, clear halt (and log) */
427 } 490 }
428 491
429 // FIXME for unlink or fault handling tests, don't report 492 /* FIXME for unlink or fault handling tests, don't report
430 // failure if retval is as we expected ... 493 * failure if retval is as we expected ...
431 494 */
432 if (retval) 495 if (retval)
433 ERROR(tdev, "perform_sglist failed, " 496 ERROR(tdev, "perform_sglist failed, "
434 "iterations left %d, status %d\n", 497 "iterations left %d, status %d\n",
@@ -452,31 +515,31 @@ static int perform_sglist (
452 */ 515 */
453 516
454static unsigned realworld = 1; 517static unsigned realworld = 1;
455module_param (realworld, uint, 0); 518module_param(realworld, uint, 0);
456MODULE_PARM_DESC (realworld, "clear to demand stricter spec compliance"); 519MODULE_PARM_DESC(realworld, "clear to demand stricter spec compliance");
457 520
458static int get_altsetting (struct usbtest_dev *dev) 521static int get_altsetting(struct usbtest_dev *dev)
459{ 522{
460 struct usb_interface *iface = dev->intf; 523 struct usb_interface *iface = dev->intf;
461 struct usb_device *udev = interface_to_usbdev (iface); 524 struct usb_device *udev = interface_to_usbdev(iface);
462 int retval; 525 int retval;
463 526
464 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev, 0), 527 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
465 USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE, 528 USB_REQ_GET_INTERFACE, USB_DIR_IN|USB_RECIP_INTERFACE,
466 0, iface->altsetting [0].desc.bInterfaceNumber, 529 0, iface->altsetting[0].desc.bInterfaceNumber,
467 dev->buf, 1, USB_CTRL_GET_TIMEOUT); 530 dev->buf, 1, USB_CTRL_GET_TIMEOUT);
468 switch (retval) { 531 switch (retval) {
469 case 1: 532 case 1:
470 return dev->buf [0]; 533 return dev->buf[0];
471 case 0: 534 case 0:
472 retval = -ERANGE; 535 retval = -ERANGE;
473 // FALLTHROUGH 536 /* FALLTHROUGH */
474 default: 537 default:
475 return retval; 538 return retval;
476 } 539 }
477} 540}
478 541
479static int set_altsetting (struct usbtest_dev *dev, int alternate) 542static int set_altsetting(struct usbtest_dev *dev, int alternate)
480{ 543{
481 struct usb_interface *iface = dev->intf; 544 struct usb_interface *iface = dev->intf;
482 struct usb_device *udev; 545 struct usb_device *udev;
@@ -484,9 +547,9 @@ static int set_altsetting (struct usbtest_dev *dev, int alternate)
484 if (alternate < 0 || alternate >= 256) 547 if (alternate < 0 || alternate >= 256)
485 return -EINVAL; 548 return -EINVAL;
486 549
487 udev = interface_to_usbdev (iface); 550 udev = interface_to_usbdev(iface);
488 return usb_set_interface (udev, 551 return usb_set_interface(udev,
489 iface->altsetting [0].desc.bInterfaceNumber, 552 iface->altsetting[0].desc.bInterfaceNumber,
490 alternate); 553 alternate);
491} 554}
492 555
@@ -519,9 +582,9 @@ static int is_good_config(struct usbtest_dev *tdev, int len)
519 return 0; 582 return 0;
520 } 583 }
521 584
522 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */ 585 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */
523 return 1; 586 return 1;
524 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */ 587 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */
525 return 1; 588 return 1;
526 ERROR(tdev, "bogus config descriptor read size\n"); 589 ERROR(tdev, "bogus config descriptor read size\n");
527 return 0; 590 return 0;
@@ -542,10 +605,10 @@ static int is_good_config(struct usbtest_dev *tdev, int len)
542 * to see if usbcore, hcd, and device all behave right. such testing would 605 * to see if usbcore, hcd, and device all behave right. such testing would
543 * involve varied read sizes and other operation sequences. 606 * involve varied read sizes and other operation sequences.
544 */ 607 */
545static int ch9_postconfig (struct usbtest_dev *dev) 608static int ch9_postconfig(struct usbtest_dev *dev)
546{ 609{
547 struct usb_interface *iface = dev->intf; 610 struct usb_interface *iface = dev->intf;
548 struct usb_device *udev = interface_to_usbdev (iface); 611 struct usb_device *udev = interface_to_usbdev(iface);
549 int i, alt, retval; 612 int i, alt, retval;
550 613
551 /* [9.2.3] if there's more than one altsetting, we need to be able to 614 /* [9.2.3] if there's more than one altsetting, we need to be able to
@@ -554,7 +617,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
554 for (i = 0; i < iface->num_altsetting; i++) { 617 for (i = 0; i < iface->num_altsetting; i++) {
555 618
556 /* 9.2.3 constrains the range here */ 619 /* 9.2.3 constrains the range here */
557 alt = iface->altsetting [i].desc.bAlternateSetting; 620 alt = iface->altsetting[i].desc.bAlternateSetting;
558 if (alt < 0 || alt >= iface->num_altsetting) { 621 if (alt < 0 || alt >= iface->num_altsetting) {
559 dev_err(&iface->dev, 622 dev_err(&iface->dev,
560 "invalid alt [%d].bAltSetting = %d\n", 623 "invalid alt [%d].bAltSetting = %d\n",
@@ -566,7 +629,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
566 continue; 629 continue;
567 630
568 /* [9.4.10] set_interface */ 631 /* [9.4.10] set_interface */
569 retval = set_altsetting (dev, alt); 632 retval = set_altsetting(dev, alt);
570 if (retval) { 633 if (retval) {
571 dev_err(&iface->dev, "can't set_interface = %d, %d\n", 634 dev_err(&iface->dev, "can't set_interface = %d, %d\n",
572 alt, retval); 635 alt, retval);
@@ -574,7 +637,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
574 } 637 }
575 638
576 /* [9.4.4] get_interface always works */ 639 /* [9.4.4] get_interface always works */
577 retval = get_altsetting (dev); 640 retval = get_altsetting(dev);
578 if (retval != alt) { 641 if (retval != alt) {
579 dev_err(&iface->dev, "get alt should be %d, was %d\n", 642 dev_err(&iface->dev, "get alt should be %d, was %d\n",
580 alt, retval); 643 alt, retval);
@@ -591,11 +654,11 @@ static int ch9_postconfig (struct usbtest_dev *dev)
591 * ... although some cheap devices (like one TI Hub I've got) 654 * ... although some cheap devices (like one TI Hub I've got)
592 * won't return config descriptors except before set_config. 655 * won't return config descriptors except before set_config.
593 */ 656 */
594 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev, 0), 657 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
595 USB_REQ_GET_CONFIGURATION, 658 USB_REQ_GET_CONFIGURATION,
596 USB_DIR_IN | USB_RECIP_DEVICE, 659 USB_DIR_IN | USB_RECIP_DEVICE,
597 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); 660 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
598 if (retval != 1 || dev->buf [0] != expected) { 661 if (retval != 1 || dev->buf[0] != expected) {
599 dev_err(&iface->dev, "get config --> %d %d (1 %d)\n", 662 dev_err(&iface->dev, "get config --> %d %d (1 %d)\n",
600 retval, dev->buf[0], expected); 663 retval, dev->buf[0], expected);
601 return (retval < 0) ? retval : -EDOM; 664 return (retval < 0) ? retval : -EDOM;
@@ -603,7 +666,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
603 } 666 }
604 667
605 /* there's always [9.4.3] a device descriptor [9.6.1] */ 668 /* there's always [9.4.3] a device descriptor [9.6.1] */
606 retval = usb_get_descriptor (udev, USB_DT_DEVICE, 0, 669 retval = usb_get_descriptor(udev, USB_DT_DEVICE, 0,
607 dev->buf, sizeof udev->descriptor); 670 dev->buf, sizeof udev->descriptor);
608 if (retval != sizeof udev->descriptor) { 671 if (retval != sizeof udev->descriptor) {
609 dev_err(&iface->dev, "dev descriptor --> %d\n", retval); 672 dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
@@ -612,7 +675,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
612 675
613 /* there's always [9.4.3] at least one config descriptor [9.6.3] */ 676 /* there's always [9.4.3] at least one config descriptor [9.6.3] */
614 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 677 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
615 retval = usb_get_descriptor (udev, USB_DT_CONFIG, i, 678 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i,
616 dev->buf, TBUF_SIZE); 679 dev->buf, TBUF_SIZE);
617 if (!is_good_config(dev, retval)) { 680 if (!is_good_config(dev, retval)) {
618 dev_err(&iface->dev, 681 dev_err(&iface->dev,
@@ -621,18 +684,19 @@ static int ch9_postconfig (struct usbtest_dev *dev)
621 return (retval < 0) ? retval : -EDOM; 684 return (retval < 0) ? retval : -EDOM;
622 } 685 }
623 686
624 // FIXME cross-checking udev->config[i] to make sure usbcore 687 /* FIXME cross-checking udev->config[i] to make sure usbcore
625 // parsed it right (etc) would be good testing paranoia 688 * parsed it right (etc) would be good testing paranoia
689 */
626 } 690 }
627 691
628 /* and sometimes [9.2.6.6] speed dependent descriptors */ 692 /* and sometimes [9.2.6.6] speed dependent descriptors */
629 if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) { 693 if (le16_to_cpu(udev->descriptor.bcdUSB) == 0x0200) {
630 struct usb_qualifier_descriptor *d = NULL; 694 struct usb_qualifier_descriptor *d = NULL;
631 695
632 /* device qualifier [9.6.2] */ 696 /* device qualifier [9.6.2] */
633 retval = usb_get_descriptor (udev, 697 retval = usb_get_descriptor(udev,
634 USB_DT_DEVICE_QUALIFIER, 0, dev->buf, 698 USB_DT_DEVICE_QUALIFIER, 0, dev->buf,
635 sizeof (struct usb_qualifier_descriptor)); 699 sizeof(struct usb_qualifier_descriptor));
636 if (retval == -EPIPE) { 700 if (retval == -EPIPE) {
637 if (udev->speed == USB_SPEED_HIGH) { 701 if (udev->speed == USB_SPEED_HIGH) {
638 dev_err(&iface->dev, 702 dev_err(&iface->dev,
@@ -641,7 +705,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
641 return (retval < 0) ? retval : -EDOM; 705 return (retval < 0) ? retval : -EDOM;
642 } 706 }
643 /* usb2.0 but not high-speed capable; fine */ 707 /* usb2.0 but not high-speed capable; fine */
644 } else if (retval != sizeof (struct usb_qualifier_descriptor)) { 708 } else if (retval != sizeof(struct usb_qualifier_descriptor)) {
645 dev_err(&iface->dev, "dev qualifier --> %d\n", retval); 709 dev_err(&iface->dev, "dev qualifier --> %d\n", retval);
646 return (retval < 0) ? retval : -EDOM; 710 return (retval < 0) ? retval : -EDOM;
647 } else 711 } else
@@ -651,7 +715,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
651 if (d) { 715 if (d) {
652 unsigned max = d->bNumConfigurations; 716 unsigned max = d->bNumConfigurations;
653 for (i = 0; i < max; i++) { 717 for (i = 0; i < max; i++) {
654 retval = usb_get_descriptor (udev, 718 retval = usb_get_descriptor(udev,
655 USB_DT_OTHER_SPEED_CONFIG, i, 719 USB_DT_OTHER_SPEED_CONFIG, i,
656 dev->buf, TBUF_SIZE); 720 dev->buf, TBUF_SIZE);
657 if (!is_good_config(dev, retval)) { 721 if (!is_good_config(dev, retval)) {
@@ -663,25 +727,26 @@ static int ch9_postconfig (struct usbtest_dev *dev)
663 } 727 }
664 } 728 }
665 } 729 }
666 // FIXME fetch strings from at least the device descriptor 730 /* FIXME fetch strings from at least the device descriptor */
667 731
668 /* [9.4.5] get_status always works */ 732 /* [9.4.5] get_status always works */
669 retval = usb_get_status (udev, USB_RECIP_DEVICE, 0, dev->buf); 733 retval = usb_get_status(udev, USB_RECIP_DEVICE, 0, dev->buf);
670 if (retval != 2) { 734 if (retval != 2) {
671 dev_err(&iface->dev, "get dev status --> %d\n", retval); 735 dev_err(&iface->dev, "get dev status --> %d\n", retval);
672 return (retval < 0) ? retval : -EDOM; 736 return (retval < 0) ? retval : -EDOM;
673 } 737 }
674 738
675 // FIXME configuration.bmAttributes says if we could try to set/clear 739 /* FIXME configuration.bmAttributes says if we could try to set/clear
676 // the device's remote wakeup feature ... if we can, test that here 740 * the device's remote wakeup feature ... if we can, test that here
741 */
677 742
678 retval = usb_get_status (udev, USB_RECIP_INTERFACE, 743 retval = usb_get_status(udev, USB_RECIP_INTERFACE,
679 iface->altsetting [0].desc.bInterfaceNumber, dev->buf); 744 iface->altsetting[0].desc.bInterfaceNumber, dev->buf);
680 if (retval != 2) { 745 if (retval != 2) {
681 dev_err(&iface->dev, "get interface status --> %d\n", retval); 746 dev_err(&iface->dev, "get interface status --> %d\n", retval);
682 return (retval < 0) ? retval : -EDOM; 747 return (retval < 0) ? retval : -EDOM;
683 } 748 }
684 // FIXME get status for each endpoint in the interface 749 /* FIXME get status for each endpoint in the interface */
685 750
686 return 0; 751 return 0;
687} 752}
@@ -717,7 +782,7 @@ struct subcase {
717 int expected; 782 int expected;
718}; 783};
719 784
720static void ctrl_complete (struct urb *urb) 785static void ctrl_complete(struct urb *urb)
721{ 786{
722 struct ctrl_ctx *ctx = urb->context; 787 struct ctrl_ctx *ctx = urb->context;
723 struct usb_ctrlrequest *reqp; 788 struct usb_ctrlrequest *reqp;
@@ -725,9 +790,9 @@ static void ctrl_complete (struct urb *urb)
725 int status = urb->status; 790 int status = urb->status;
726 791
727 reqp = (struct usb_ctrlrequest *)urb->setup_packet; 792 reqp = (struct usb_ctrlrequest *)urb->setup_packet;
728 subcase = container_of (reqp, struct subcase, setup); 793 subcase = container_of(reqp, struct subcase, setup);
729 794
730 spin_lock (&ctx->lock); 795 spin_lock(&ctx->lock);
731 ctx->count--; 796 ctx->count--;
732 ctx->pending--; 797 ctx->pending--;
733 798
@@ -787,14 +852,14 @@ error:
787 852
788 /* unlink whatever's still pending */ 853 /* unlink whatever's still pending */
789 for (i = 1; i < ctx->param->sglen; i++) { 854 for (i = 1; i < ctx->param->sglen; i++) {
790 struct urb *u = ctx->urb [ 855 struct urb *u = ctx->urb[
791 (i + subcase->number) 856 (i + subcase->number)
792 % ctx->param->sglen]; 857 % ctx->param->sglen];
793 858
794 if (u == urb || !u->dev) 859 if (u == urb || !u->dev)
795 continue; 860 continue;
796 spin_unlock(&ctx->lock); 861 spin_unlock(&ctx->lock);
797 status = usb_unlink_urb (u); 862 status = usb_unlink_urb(u);
798 spin_lock(&ctx->lock); 863 spin_lock(&ctx->lock);
799 switch (status) { 864 switch (status) {
800 case -EINPROGRESS: 865 case -EINPROGRESS:
@@ -812,7 +877,8 @@ error:
812 877
813 /* resubmit if we need to, else mark this as done */ 878 /* resubmit if we need to, else mark this as done */
814 if ((status == 0) && (ctx->pending < ctx->count)) { 879 if ((status == 0) && (ctx->pending < ctx->count)) {
815 if ((status = usb_submit_urb (urb, GFP_ATOMIC)) != 0) { 880 status = usb_submit_urb(urb, GFP_ATOMIC);
881 if (status != 0) {
816 ERROR(ctx->dev, 882 ERROR(ctx->dev,
817 "can't resubmit ctrl %02x.%02x, err %d\n", 883 "can't resubmit ctrl %02x.%02x, err %d\n",
818 reqp->bRequestType, reqp->bRequest, status); 884 reqp->bRequestType, reqp->bRequest, status);
@@ -824,21 +890,21 @@ error:
824 890
825 /* signal completion when nothing's queued */ 891 /* signal completion when nothing's queued */
826 if (ctx->pending == 0) 892 if (ctx->pending == 0)
827 complete (&ctx->complete); 893 complete(&ctx->complete);
828 spin_unlock (&ctx->lock); 894 spin_unlock(&ctx->lock);
829} 895}
830 896
831static int 897static int
832test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param) 898test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param)
833{ 899{
834 struct usb_device *udev = testdev_to_usbdev (dev); 900 struct usb_device *udev = testdev_to_usbdev(dev);
835 struct urb **urb; 901 struct urb **urb;
836 struct ctrl_ctx context; 902 struct ctrl_ctx context;
837 int i; 903 int i;
838 904
839 spin_lock_init (&context.lock); 905 spin_lock_init(&context.lock);
840 context.dev = dev; 906 context.dev = dev;
841 init_completion (&context.complete); 907 init_completion(&context.complete);
842 context.count = param->sglen * param->iterations; 908 context.count = param->sglen * param->iterations;
843 context.pending = 0; 909 context.pending = 0;
844 context.status = -ENOMEM; 910 context.status = -ENOMEM;
@@ -853,7 +919,7 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
853 if (!urb) 919 if (!urb)
854 return -ENOMEM; 920 return -ENOMEM;
855 for (i = 0; i < param->sglen; i++) { 921 for (i = 0; i < param->sglen; i++) {
856 int pipe = usb_rcvctrlpipe (udev, 0); 922 int pipe = usb_rcvctrlpipe(udev, 0);
857 unsigned len; 923 unsigned len;
858 struct urb *u; 924 struct urb *u;
859 struct usb_ctrlrequest req; 925 struct usb_ctrlrequest req;
@@ -869,104 +935,110 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
869 * device, but some are chosen to trigger protocol stalls 935 * device, but some are chosen to trigger protocol stalls
870 * or short reads. 936 * or short reads.
871 */ 937 */
872 memset (&req, 0, sizeof req); 938 memset(&req, 0, sizeof req);
873 req.bRequest = USB_REQ_GET_DESCRIPTOR; 939 req.bRequest = USB_REQ_GET_DESCRIPTOR;
874 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 940 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
875 941
876 switch (i % NUM_SUBCASES) { 942 switch (i % NUM_SUBCASES) {
877 case 0: // get device descriptor 943 case 0: /* get device descriptor */
878 req.wValue = cpu_to_le16 (USB_DT_DEVICE << 8); 944 req.wValue = cpu_to_le16(USB_DT_DEVICE << 8);
879 len = sizeof (struct usb_device_descriptor); 945 len = sizeof(struct usb_device_descriptor);
880 break; 946 break;
881 case 1: // get first config descriptor (only) 947 case 1: /* get first config descriptor (only) */
882 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 948 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
883 len = sizeof (struct usb_config_descriptor); 949 len = sizeof(struct usb_config_descriptor);
884 break; 950 break;
885 case 2: // get altsetting (OFTEN STALLS) 951 case 2: /* get altsetting (OFTEN STALLS) */
886 req.bRequest = USB_REQ_GET_INTERFACE; 952 req.bRequest = USB_REQ_GET_INTERFACE;
887 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; 953 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
888 // index = 0 means first interface 954 /* index = 0 means first interface */
889 len = 1; 955 len = 1;
890 expected = EPIPE; 956 expected = EPIPE;
891 break; 957 break;
892 case 3: // get interface status 958 case 3: /* get interface status */
893 req.bRequest = USB_REQ_GET_STATUS; 959 req.bRequest = USB_REQ_GET_STATUS;
894 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE; 960 req.bRequestType = USB_DIR_IN|USB_RECIP_INTERFACE;
895 // interface 0 961 /* interface 0 */
896 len = 2; 962 len = 2;
897 break; 963 break;
898 case 4: // get device status 964 case 4: /* get device status */
899 req.bRequest = USB_REQ_GET_STATUS; 965 req.bRequest = USB_REQ_GET_STATUS;
900 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE; 966 req.bRequestType = USB_DIR_IN|USB_RECIP_DEVICE;
901 len = 2; 967 len = 2;
902 break; 968 break;
903 case 5: // get device qualifier (MAY STALL) 969 case 5: /* get device qualifier (MAY STALL) */
904 req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8); 970 req.wValue = cpu_to_le16 (USB_DT_DEVICE_QUALIFIER << 8);
905 len = sizeof (struct usb_qualifier_descriptor); 971 len = sizeof(struct usb_qualifier_descriptor);
906 if (udev->speed != USB_SPEED_HIGH) 972 if (udev->speed != USB_SPEED_HIGH)
907 expected = EPIPE; 973 expected = EPIPE;
908 break; 974 break;
909 case 6: // get first config descriptor, plus interface 975 case 6: /* get first config descriptor, plus interface */
910 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 976 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
911 len = sizeof (struct usb_config_descriptor); 977 len = sizeof(struct usb_config_descriptor);
912 len += sizeof (struct usb_interface_descriptor); 978 len += sizeof(struct usb_interface_descriptor);
913 break; 979 break;
914 case 7: // get interface descriptor (ALWAYS STALLS) 980 case 7: /* get interface descriptor (ALWAYS STALLS) */
915 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8); 981 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8);
916 // interface == 0 982 /* interface == 0 */
917 len = sizeof (struct usb_interface_descriptor); 983 len = sizeof(struct usb_interface_descriptor);
918 expected = -EPIPE; 984 expected = -EPIPE;
919 break; 985 break;
920 // NOTE: two consecutive stalls in the queue here. 986 /* NOTE: two consecutive stalls in the queue here.
921 // that tests fault recovery a bit more aggressively. 987 * that tests fault recovery a bit more aggressively. */
922 case 8: // clear endpoint halt (MAY STALL) 988 case 8: /* clear endpoint halt (MAY STALL) */
923 req.bRequest = USB_REQ_CLEAR_FEATURE; 989 req.bRequest = USB_REQ_CLEAR_FEATURE;
924 req.bRequestType = USB_RECIP_ENDPOINT; 990 req.bRequestType = USB_RECIP_ENDPOINT;
925 // wValue 0 == ep halt 991 /* wValue 0 == ep halt */
926 // wIndex 0 == ep0 (shouldn't halt!) 992 /* wIndex 0 == ep0 (shouldn't halt!) */
927 len = 0; 993 len = 0;
928 pipe = usb_sndctrlpipe (udev, 0); 994 pipe = usb_sndctrlpipe(udev, 0);
929 expected = EPIPE; 995 expected = EPIPE;
930 break; 996 break;
931 case 9: // get endpoint status 997 case 9: /* get endpoint status */
932 req.bRequest = USB_REQ_GET_STATUS; 998 req.bRequest = USB_REQ_GET_STATUS;
933 req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT; 999 req.bRequestType = USB_DIR_IN|USB_RECIP_ENDPOINT;
934 // endpoint 0 1000 /* endpoint 0 */
935 len = 2; 1001 len = 2;
936 break; 1002 break;
937 case 10: // trigger short read (EREMOTEIO) 1003 case 10: /* trigger short read (EREMOTEIO) */
938 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 1004 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
939 len = 1024; 1005 len = 1024;
940 expected = -EREMOTEIO; 1006 expected = -EREMOTEIO;
941 break; 1007 break;
942 // NOTE: two consecutive _different_ faults in the queue. 1008 /* NOTE: two consecutive _different_ faults in the queue. */
943 case 11: // get endpoint descriptor (ALWAYS STALLS) 1009 case 11: /* get endpoint descriptor (ALWAYS STALLS) */
944 req.wValue = cpu_to_le16 (USB_DT_ENDPOINT << 8); 1010 req.wValue = cpu_to_le16(USB_DT_ENDPOINT << 8);
945 // endpoint == 0 1011 /* endpoint == 0 */
946 len = sizeof (struct usb_interface_descriptor); 1012 len = sizeof(struct usb_interface_descriptor);
947 expected = EPIPE; 1013 expected = EPIPE;
948 break; 1014 break;
949 // NOTE: sometimes even a third fault in the queue! 1015 /* NOTE: sometimes even a third fault in the queue! */
950 case 12: // get string 0 descriptor (MAY STALL) 1016 case 12: /* get string 0 descriptor (MAY STALL) */
951 req.wValue = cpu_to_le16 (USB_DT_STRING << 8); 1017 req.wValue = cpu_to_le16(USB_DT_STRING << 8);
952 // string == 0, for language IDs 1018 /* string == 0, for language IDs */
953 len = sizeof (struct usb_interface_descriptor); 1019 len = sizeof(struct usb_interface_descriptor);
954 // may succeed when > 4 languages 1020 /* may succeed when > 4 languages */
955 expected = EREMOTEIO; // or EPIPE, if no strings 1021 expected = EREMOTEIO; /* or EPIPE, if no strings */
956 break; 1022 break;
957 case 13: // short read, resembling case 10 1023 case 13: /* short read, resembling case 10 */
958 req.wValue = cpu_to_le16 ((USB_DT_CONFIG << 8) | 0); 1024 req.wValue = cpu_to_le16((USB_DT_CONFIG << 8) | 0);
959 // last data packet "should" be DATA1, not DATA0 1025 /* last data packet "should" be DATA1, not DATA0 */
960 len = 1024 - udev->descriptor.bMaxPacketSize0; 1026 len = 1024 - udev->descriptor.bMaxPacketSize0;
961 expected = -EREMOTEIO; 1027 expected = -EREMOTEIO;
962 break; 1028 break;
963 case 14: // short read; try to fill the last packet 1029 case 14: /* short read; try to fill the last packet */
964 req.wValue = cpu_to_le16 ((USB_DT_DEVICE << 8) | 0); 1030 req.wValue = cpu_to_le16((USB_DT_DEVICE << 8) | 0);
965 /* device descriptor size == 18 bytes */ 1031 /* device descriptor size == 18 bytes */
966 len = udev->descriptor.bMaxPacketSize0; 1032 len = udev->descriptor.bMaxPacketSize0;
1033 if (udev->speed == USB_SPEED_SUPER)
1034 len = 512;
967 switch (len) { 1035 switch (len) {
968 case 8: len = 24; break; 1036 case 8:
969 case 16: len = 32; break; 1037 len = 24;
1038 break;
1039 case 16:
1040 len = 32;
1041 break;
970 } 1042 }
971 expected = -EREMOTEIO; 1043 expected = -EREMOTEIO;
972 break; 1044 break;
@@ -975,8 +1047,8 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
975 context.status = -EINVAL; 1047 context.status = -EINVAL;
976 goto cleanup; 1048 goto cleanup;
977 } 1049 }
978 req.wLength = cpu_to_le16 (len); 1050 req.wLength = cpu_to_le16(len);
979 urb [i] = u = simple_alloc_urb (udev, pipe, len); 1051 urb[i] = u = simple_alloc_urb(udev, pipe, len);
980 if (!u) 1052 if (!u)
981 goto cleanup; 1053 goto cleanup;
982 1054
@@ -994,9 +1066,9 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
994 1066
995 /* queue the urbs */ 1067 /* queue the urbs */
996 context.urb = urb; 1068 context.urb = urb;
997 spin_lock_irq (&context.lock); 1069 spin_lock_irq(&context.lock);
998 for (i = 0; i < param->sglen; i++) { 1070 for (i = 0; i < param->sglen; i++) {
999 context.status = usb_submit_urb (urb [i], GFP_ATOMIC); 1071 context.status = usb_submit_urb(urb[i], GFP_ATOMIC);
1000 if (context.status != 0) { 1072 if (context.status != 0) {
1001 ERROR(dev, "can't submit urb[%d], status %d\n", 1073 ERROR(dev, "can't submit urb[%d], status %d\n",
1002 i, context.status); 1074 i, context.status);
@@ -1005,23 +1077,23 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
1005 } 1077 }
1006 context.pending++; 1078 context.pending++;
1007 } 1079 }
1008 spin_unlock_irq (&context.lock); 1080 spin_unlock_irq(&context.lock);
1009 1081
1010 /* FIXME set timer and time out; provide a disconnect hook */ 1082 /* FIXME set timer and time out; provide a disconnect hook */
1011 1083
1012 /* wait for the last one to complete */ 1084 /* wait for the last one to complete */
1013 if (context.pending > 0) 1085 if (context.pending > 0)
1014 wait_for_completion (&context.complete); 1086 wait_for_completion(&context.complete);
1015 1087
1016cleanup: 1088cleanup:
1017 for (i = 0; i < param->sglen; i++) { 1089 for (i = 0; i < param->sglen; i++) {
1018 if (!urb [i]) 1090 if (!urb[i])
1019 continue; 1091 continue;
1020 urb [i]->dev = udev; 1092 urb[i]->dev = udev;
1021 kfree(urb[i]->setup_packet); 1093 kfree(urb[i]->setup_packet);
1022 simple_free_urb (urb [i]); 1094 simple_free_urb(urb[i]);
1023 } 1095 }
1024 kfree (urb); 1096 kfree(urb);
1025 return context.status; 1097 return context.status;
1026} 1098}
1027#undef NUM_SUBCASES 1099#undef NUM_SUBCASES
@@ -1029,27 +1101,27 @@ cleanup:
1029 1101
1030/*-------------------------------------------------------------------------*/ 1102/*-------------------------------------------------------------------------*/
1031 1103
1032static void unlink1_callback (struct urb *urb) 1104static void unlink1_callback(struct urb *urb)
1033{ 1105{
1034 int status = urb->status; 1106 int status = urb->status;
1035 1107
1036 // we "know" -EPIPE (stall) never happens 1108 /* we "know" -EPIPE (stall) never happens */
1037 if (!status) 1109 if (!status)
1038 status = usb_submit_urb (urb, GFP_ATOMIC); 1110 status = usb_submit_urb(urb, GFP_ATOMIC);
1039 if (status) { 1111 if (status) {
1040 urb->status = status; 1112 urb->status = status;
1041 complete(urb->context); 1113 complete(urb->context);
1042 } 1114 }
1043} 1115}
1044 1116
1045static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async) 1117static int unlink1(struct usbtest_dev *dev, int pipe, int size, int async)
1046{ 1118{
1047 struct urb *urb; 1119 struct urb *urb;
1048 struct completion completion; 1120 struct completion completion;
1049 int retval = 0; 1121 int retval = 0;
1050 1122
1051 init_completion (&completion); 1123 init_completion(&completion);
1052 urb = simple_alloc_urb (testdev_to_usbdev (dev), pipe, size); 1124 urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size);
1053 if (!urb) 1125 if (!urb)
1054 return -ENOMEM; 1126 return -ENOMEM;
1055 urb->context = &completion; 1127 urb->context = &completion;
@@ -1061,7 +1133,8 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1061 * FIXME want additional tests for when endpoint is STALLing 1133 * FIXME want additional tests for when endpoint is STALLing
1062 * due to errors, or is just NAKing requests. 1134 * due to errors, or is just NAKing requests.
1063 */ 1135 */
1064 if ((retval = usb_submit_urb (urb, GFP_KERNEL)) != 0) { 1136 retval = usb_submit_urb(urb, GFP_KERNEL);
1137 if (retval != 0) {
1065 dev_err(&dev->intf->dev, "submit fail %d\n", retval); 1138 dev_err(&dev->intf->dev, "submit fail %d\n", retval);
1066 return retval; 1139 return retval;
1067 } 1140 }
@@ -1069,7 +1142,7 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1069 /* unlinking that should always work. variable delay tests more 1142 /* unlinking that should always work. variable delay tests more
1070 * hcd states and code paths, even with little other system load. 1143 * hcd states and code paths, even with little other system load.
1071 */ 1144 */
1072 msleep (jiffies % (2 * INTERRUPT_RATE)); 1145 msleep(jiffies % (2 * INTERRUPT_RATE));
1073 if (async) { 1146 if (async) {
1074 while (!completion_done(&completion)) { 1147 while (!completion_done(&completion)) {
1075 retval = usb_unlink_urb(urb); 1148 retval = usb_unlink_urb(urb);
@@ -1098,11 +1171,11 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1098 break; 1171 break;
1099 } 1172 }
1100 } else 1173 } else
1101 usb_kill_urb (urb); 1174 usb_kill_urb(urb);
1102 1175
1103 wait_for_completion (&completion); 1176 wait_for_completion(&completion);
1104 retval = urb->status; 1177 retval = urb->status;
1105 simple_free_urb (urb); 1178 simple_free_urb(urb);
1106 1179
1107 if (async) 1180 if (async)
1108 return (retval == -ECONNRESET) ? 0 : retval - 1000; 1181 return (retval == -ECONNRESET) ? 0 : retval - 1000;
@@ -1111,14 +1184,112 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1111 0 : retval - 2000; 1184 0 : retval - 2000;
1112} 1185}
1113 1186
1114static int unlink_simple (struct usbtest_dev *dev, int pipe, int len) 1187static int unlink_simple(struct usbtest_dev *dev, int pipe, int len)
1115{ 1188{
1116 int retval = 0; 1189 int retval = 0;
1117 1190
1118 /* test sync and async paths */ 1191 /* test sync and async paths */
1119 retval = unlink1 (dev, pipe, len, 1); 1192 retval = unlink1(dev, pipe, len, 1);
1120 if (!retval) 1193 if (!retval)
1121 retval = unlink1 (dev, pipe, len, 0); 1194 retval = unlink1(dev, pipe, len, 0);
1195 return retval;
1196}
1197
1198/*-------------------------------------------------------------------------*/
1199
1200struct queued_ctx {
1201 struct completion complete;
1202 atomic_t pending;
1203 unsigned num;
1204 int status;
1205 struct urb **urbs;
1206};
1207
1208static void unlink_queued_callback(struct urb *urb)
1209{
1210 int status = urb->status;
1211 struct queued_ctx *ctx = urb->context;
1212
1213 if (ctx->status)
1214 goto done;
1215 if (urb == ctx->urbs[ctx->num - 4] || urb == ctx->urbs[ctx->num - 2]) {
1216 if (status == -ECONNRESET)
1217 goto done;
1218 /* What error should we report if the URB completed normally? */
1219 }
1220 if (status != 0)
1221 ctx->status = status;
1222
1223 done:
1224 if (atomic_dec_and_test(&ctx->pending))
1225 complete(&ctx->complete);
1226}
1227
1228static int unlink_queued(struct usbtest_dev *dev, int pipe, unsigned num,
1229 unsigned size)
1230{
1231 struct queued_ctx ctx;
1232 struct usb_device *udev = testdev_to_usbdev(dev);
1233 void *buf;
1234 dma_addr_t buf_dma;
1235 int i;
1236 int retval = -ENOMEM;
1237
1238 init_completion(&ctx.complete);
1239 atomic_set(&ctx.pending, 1); /* One more than the actual value */
1240 ctx.num = num;
1241 ctx.status = 0;
1242
1243 buf = usb_alloc_coherent(udev, size, GFP_KERNEL, &buf_dma);
1244 if (!buf)
1245 return retval;
1246 memset(buf, 0, size);
1247
1248 /* Allocate and init the urbs we'll queue */
1249 ctx.urbs = kcalloc(num, sizeof(struct urb *), GFP_KERNEL);
1250 if (!ctx.urbs)
1251 goto free_buf;
1252 for (i = 0; i < num; i++) {
1253 ctx.urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1254 if (!ctx.urbs[i])
1255 goto free_urbs;
1256 usb_fill_bulk_urb(ctx.urbs[i], udev, pipe, buf, size,
1257 unlink_queued_callback, &ctx);
1258 ctx.urbs[i]->transfer_dma = buf_dma;
1259 ctx.urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1260 }
1261
1262 /* Submit all the URBs and then unlink URBs num - 4 and num - 2. */
1263 for (i = 0; i < num; i++) {
1264 atomic_inc(&ctx.pending);
1265 retval = usb_submit_urb(ctx.urbs[i], GFP_KERNEL);
1266 if (retval != 0) {
1267 dev_err(&dev->intf->dev, "submit urbs[%d] fail %d\n",
1268 i, retval);
1269 atomic_dec(&ctx.pending);
1270 ctx.status = retval;
1271 break;
1272 }
1273 }
1274 if (i == num) {
1275 usb_unlink_urb(ctx.urbs[num - 4]);
1276 usb_unlink_urb(ctx.urbs[num - 2]);
1277 } else {
1278 while (--i >= 0)
1279 usb_unlink_urb(ctx.urbs[i]);
1280 }
1281
1282 if (atomic_dec_and_test(&ctx.pending)) /* The extra count */
1283 complete(&ctx.complete);
1284 wait_for_completion(&ctx.complete);
1285 retval = ctx.status;
1286
1287 free_urbs:
1288 for (i = 0; i < num; i++)
1289 usb_free_urb(ctx.urbs[i]);
1290 kfree(ctx.urbs);
1291 free_buf:
1292 usb_free_coherent(udev, size, buf, buf_dma);
1122 return retval; 1293 return retval;
1123} 1294}
1124 1295
@@ -1130,7 +1301,7 @@ static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1130 u16 status; 1301 u16 status;
1131 1302
1132 /* shouldn't look or act halted */ 1303 /* shouldn't look or act halted */
1133 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status); 1304 retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
1134 if (retval < 0) { 1305 if (retval < 0) {
1135 ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n", 1306 ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n",
1136 ep, retval); 1307 ep, retval);
@@ -1152,7 +1323,7 @@ static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1152 u16 status; 1323 u16 status;
1153 1324
1154 /* should look and act halted */ 1325 /* should look and act halted */
1155 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status); 1326 retval = usb_get_status(urb->dev, USB_RECIP_ENDPOINT, ep, &status);
1156 if (retval < 0) { 1327 if (retval < 0) {
1157 ERROR(tdev, "ep %02x couldn't get halt status, %d\n", 1328 ERROR(tdev, "ep %02x couldn't get halt status, %d\n",
1158 ep, retval); 1329 ep, retval);
@@ -1182,7 +1353,7 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
1182 return retval; 1353 return retval;
1183 1354
1184 /* set halt (protocol test only), verify it worked */ 1355 /* set halt (protocol test only), verify it worked */
1185 retval = usb_control_msg (urb->dev, usb_sndctrlpipe (urb->dev, 0), 1356 retval = usb_control_msg(urb->dev, usb_sndctrlpipe(urb->dev, 0),
1186 USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT, 1357 USB_REQ_SET_FEATURE, USB_RECIP_ENDPOINT,
1187 USB_ENDPOINT_HALT, ep, 1358 USB_ENDPOINT_HALT, ep,
1188 NULL, 0, USB_CTRL_SET_TIMEOUT); 1359 NULL, 0, USB_CTRL_SET_TIMEOUT);
@@ -1195,7 +1366,7 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
1195 return retval; 1366 return retval;
1196 1367
1197 /* clear halt (tests API + protocol), verify it worked */ 1368 /* clear halt (tests API + protocol), verify it worked */
1198 retval = usb_clear_halt (urb->dev, urb->pipe); 1369 retval = usb_clear_halt(urb->dev, urb->pipe);
1199 if (retval < 0) { 1370 if (retval < 0) {
1200 ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval); 1371 ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval);
1201 return retval; 1372 return retval;
@@ -1209,18 +1380,18 @@ static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
1209 return 0; 1380 return 0;
1210} 1381}
1211 1382
1212static int halt_simple (struct usbtest_dev *dev) 1383static int halt_simple(struct usbtest_dev *dev)
1213{ 1384{
1214 int ep; 1385 int ep;
1215 int retval = 0; 1386 int retval = 0;
1216 struct urb *urb; 1387 struct urb *urb;
1217 1388
1218 urb = simple_alloc_urb (testdev_to_usbdev (dev), 0, 512); 1389 urb = simple_alloc_urb(testdev_to_usbdev(dev), 0, 512);
1219 if (urb == NULL) 1390 if (urb == NULL)
1220 return -ENOMEM; 1391 return -ENOMEM;
1221 1392
1222 if (dev->in_pipe) { 1393 if (dev->in_pipe) {
1223 ep = usb_pipeendpoint (dev->in_pipe) | USB_DIR_IN; 1394 ep = usb_pipeendpoint(dev->in_pipe) | USB_DIR_IN;
1224 urb->pipe = dev->in_pipe; 1395 urb->pipe = dev->in_pipe;
1225 retval = test_halt(dev, ep, urb); 1396 retval = test_halt(dev, ep, urb);
1226 if (retval < 0) 1397 if (retval < 0)
@@ -1228,12 +1399,12 @@ static int halt_simple (struct usbtest_dev *dev)
1228 } 1399 }
1229 1400
1230 if (dev->out_pipe) { 1401 if (dev->out_pipe) {
1231 ep = usb_pipeendpoint (dev->out_pipe); 1402 ep = usb_pipeendpoint(dev->out_pipe);
1232 urb->pipe = dev->out_pipe; 1403 urb->pipe = dev->out_pipe;
1233 retval = test_halt(dev, ep, urb); 1404 retval = test_halt(dev, ep, urb);
1234 } 1405 }
1235done: 1406done:
1236 simple_free_urb (urb); 1407 simple_free_urb(urb);
1237 return retval; 1408 return retval;
1238} 1409}
1239 1410
@@ -1247,8 +1418,8 @@ done:
1247 * need to be able to handle more than one OUT data packet. We'll 1418 * need to be able to handle more than one OUT data packet. We'll
1248 * try whatever we're told to try. 1419 * try whatever we're told to try.
1249 */ 1420 */
1250static int ctrl_out (struct usbtest_dev *dev, 1421static int ctrl_out(struct usbtest_dev *dev,
1251 unsigned count, unsigned length, unsigned vary) 1422 unsigned count, unsigned length, unsigned vary, unsigned offset)
1252{ 1423{
1253 unsigned i, j, len; 1424 unsigned i, j, len;
1254 int retval; 1425 int retval;
@@ -1259,11 +1430,12 @@ static int ctrl_out (struct usbtest_dev *dev,
1259 if (length < 1 || length > 0xffff || vary >= length) 1430 if (length < 1 || length > 0xffff || vary >= length)
1260 return -EINVAL; 1431 return -EINVAL;
1261 1432
1262 buf = kmalloc(length, GFP_KERNEL); 1433 buf = kmalloc(length + offset, GFP_KERNEL);
1263 if (!buf) 1434 if (!buf)
1264 return -ENOMEM; 1435 return -ENOMEM;
1265 1436
1266 udev = testdev_to_usbdev (dev); 1437 buf += offset;
1438 udev = testdev_to_usbdev(dev);
1267 len = length; 1439 len = length;
1268 retval = 0; 1440 retval = 0;
1269 1441
@@ -1273,8 +1445,8 @@ static int ctrl_out (struct usbtest_dev *dev,
1273 for (i = 0; i < count; i++) { 1445 for (i = 0; i < count; i++) {
1274 /* write patterned data */ 1446 /* write patterned data */
1275 for (j = 0; j < len; j++) 1447 for (j = 0; j < len; j++)
1276 buf [j] = i + j; 1448 buf[j] = i + j;
1277 retval = usb_control_msg (udev, usb_sndctrlpipe (udev,0), 1449 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1278 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR, 1450 0x5b, USB_DIR_OUT|USB_TYPE_VENDOR,
1279 0, 0, buf, len, USB_CTRL_SET_TIMEOUT); 1451 0, 0, buf, len, USB_CTRL_SET_TIMEOUT);
1280 if (retval != len) { 1452 if (retval != len) {
@@ -1288,7 +1460,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1288 } 1460 }
1289 1461
1290 /* read it back -- assuming nothing intervened!! */ 1462 /* read it back -- assuming nothing intervened!! */
1291 retval = usb_control_msg (udev, usb_rcvctrlpipe (udev,0), 1463 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
1292 0x5c, USB_DIR_IN|USB_TYPE_VENDOR, 1464 0x5c, USB_DIR_IN|USB_TYPE_VENDOR,
1293 0, 0, buf, len, USB_CTRL_GET_TIMEOUT); 1465 0, 0, buf, len, USB_CTRL_GET_TIMEOUT);
1294 if (retval != len) { 1466 if (retval != len) {
@@ -1303,9 +1475,9 @@ static int ctrl_out (struct usbtest_dev *dev,
1303 1475
1304 /* fail if we can't verify */ 1476 /* fail if we can't verify */
1305 for (j = 0; j < len; j++) { 1477 for (j = 0; j < len; j++) {
1306 if (buf [j] != (u8) (i + j)) { 1478 if (buf[j] != (u8) (i + j)) {
1307 ERROR(dev, "ctrl_out, byte %d is %d not %d\n", 1479 ERROR(dev, "ctrl_out, byte %d is %d not %d\n",
1308 j, buf [j], (u8) i + j); 1480 j, buf[j], (u8) i + j);
1309 retval = -EBADMSG; 1481 retval = -EBADMSG;
1310 break; 1482 break;
1311 } 1483 }
@@ -1326,10 +1498,10 @@ static int ctrl_out (struct usbtest_dev *dev,
1326 } 1498 }
1327 1499
1328 if (retval < 0) 1500 if (retval < 0)
1329 ERROR (dev, "ctrl_out %s failed, code %d, count %d\n", 1501 ERROR(dev, "ctrl_out %s failed, code %d, count %d\n",
1330 what, retval, i); 1502 what, retval, i);
1331 1503
1332 kfree (buf); 1504 kfree(buf - offset);
1333 return retval; 1505 return retval;
1334} 1506}
1335 1507
@@ -1351,7 +1523,7 @@ struct iso_context {
1351 struct usbtest_dev *dev; 1523 struct usbtest_dev *dev;
1352}; 1524};
1353 1525
1354static void iso_callback (struct urb *urb) 1526static void iso_callback(struct urb *urb)
1355{ 1527{
1356 struct iso_context *ctx = urb->context; 1528 struct iso_context *ctx = urb->context;
1357 1529
@@ -1363,10 +1535,14 @@ static void iso_callback (struct urb *urb)
1363 ctx->errors += urb->error_count; 1535 ctx->errors += urb->error_count;
1364 else if (urb->status != 0) 1536 else if (urb->status != 0)
1365 ctx->errors += urb->number_of_packets; 1537 ctx->errors += urb->number_of_packets;
1538 else if (urb->actual_length != urb->transfer_buffer_length)
1539 ctx->errors++;
1540 else if (check_guard_bytes(ctx->dev, urb) != 0)
1541 ctx->errors++;
1366 1542
1367 if (urb->status == 0 && ctx->count > (ctx->pending - 1) 1543 if (urb->status == 0 && ctx->count > (ctx->pending - 1)
1368 && !ctx->submit_error) { 1544 && !ctx->submit_error) {
1369 int status = usb_submit_urb (urb, GFP_ATOMIC); 1545 int status = usb_submit_urb(urb, GFP_ATOMIC);
1370 switch (status) { 1546 switch (status) {
1371 case 0: 1547 case 0:
1372 goto done; 1548 goto done;
@@ -1388,17 +1564,18 @@ static void iso_callback (struct urb *urb)
1388 dev_err(&ctx->dev->intf->dev, 1564 dev_err(&ctx->dev->intf->dev,
1389 "iso test, %lu errors out of %lu\n", 1565 "iso test, %lu errors out of %lu\n",
1390 ctx->errors, ctx->packet_count); 1566 ctx->errors, ctx->packet_count);
1391 complete (&ctx->done); 1567 complete(&ctx->done);
1392 } 1568 }
1393done: 1569done:
1394 spin_unlock(&ctx->lock); 1570 spin_unlock(&ctx->lock);
1395} 1571}
1396 1572
1397static struct urb *iso_alloc_urb ( 1573static struct urb *iso_alloc_urb(
1398 struct usb_device *udev, 1574 struct usb_device *udev,
1399 int pipe, 1575 int pipe,
1400 struct usb_endpoint_descriptor *desc, 1576 struct usb_endpoint_descriptor *desc,
1401 long bytes 1577 long bytes,
1578 unsigned offset
1402) 1579)
1403{ 1580{
1404 struct urb *urb; 1581 struct urb *urb;
@@ -1410,7 +1587,7 @@ static struct urb *iso_alloc_urb (
1410 maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11)); 1587 maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11));
1411 packets = DIV_ROUND_UP(bytes, maxp); 1588 packets = DIV_ROUND_UP(bytes, maxp);
1412 1589
1413 urb = usb_alloc_urb (packets, GFP_KERNEL); 1590 urb = usb_alloc_urb(packets, GFP_KERNEL);
1414 if (!urb) 1591 if (!urb)
1415 return urb; 1592 return urb;
1416 urb->dev = udev; 1593 urb->dev = udev;
@@ -1418,31 +1595,42 @@ static struct urb *iso_alloc_urb (
1418 1595
1419 urb->number_of_packets = packets; 1596 urb->number_of_packets = packets;
1420 urb->transfer_buffer_length = bytes; 1597 urb->transfer_buffer_length = bytes;
1421 urb->transfer_buffer = usb_alloc_coherent (udev, bytes, GFP_KERNEL, 1598 urb->transfer_buffer = usb_alloc_coherent(udev, bytes + offset,
1422 &urb->transfer_dma); 1599 GFP_KERNEL,
1600 &urb->transfer_dma);
1423 if (!urb->transfer_buffer) { 1601 if (!urb->transfer_buffer) {
1424 usb_free_urb (urb); 1602 usb_free_urb(urb);
1425 return NULL; 1603 return NULL;
1426 } 1604 }
1427 memset (urb->transfer_buffer, 0, bytes); 1605 if (offset) {
1606 memset(urb->transfer_buffer, GUARD_BYTE, offset);
1607 urb->transfer_buffer += offset;
1608 urb->transfer_dma += offset;
1609 }
1610 /* For inbound transfers use guard byte so that test fails if
1611 data not correctly copied */
1612 memset(urb->transfer_buffer,
1613 usb_pipein(urb->pipe) ? GUARD_BYTE : 0,
1614 bytes);
1615
1428 for (i = 0; i < packets; i++) { 1616 for (i = 0; i < packets; i++) {
1429 /* here, only the last packet will be short */ 1617 /* here, only the last packet will be short */
1430 urb->iso_frame_desc[i].length = min ((unsigned) bytes, maxp); 1618 urb->iso_frame_desc[i].length = min((unsigned) bytes, maxp);
1431 bytes -= urb->iso_frame_desc[i].length; 1619 bytes -= urb->iso_frame_desc[i].length;
1432 1620
1433 urb->iso_frame_desc[i].offset = maxp * i; 1621 urb->iso_frame_desc[i].offset = maxp * i;
1434 } 1622 }
1435 1623
1436 urb->complete = iso_callback; 1624 urb->complete = iso_callback;
1437 // urb->context = SET BY CALLER 1625 /* urb->context = SET BY CALLER */
1438 urb->interval = 1 << (desc->bInterval - 1); 1626 urb->interval = 1 << (desc->bInterval - 1);
1439 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1627 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
1440 return urb; 1628 return urb;
1441} 1629}
1442 1630
1443static int 1631static int
1444test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param, 1632test_iso_queue(struct usbtest_dev *dev, struct usbtest_param *param,
1445 int pipe, struct usb_endpoint_descriptor *desc) 1633 int pipe, struct usb_endpoint_descriptor *desc, unsigned offset)
1446{ 1634{
1447 struct iso_context context; 1635 struct iso_context context;
1448 struct usb_device *udev; 1636 struct usb_device *udev;
@@ -1457,11 +1645,11 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1457 memset(&context, 0, sizeof context); 1645 memset(&context, 0, sizeof context);
1458 context.count = param->iterations * param->sglen; 1646 context.count = param->iterations * param->sglen;
1459 context.dev = dev; 1647 context.dev = dev;
1460 init_completion (&context.done); 1648 init_completion(&context.done);
1461 spin_lock_init (&context.lock); 1649 spin_lock_init(&context.lock);
1462 1650
1463 memset (urbs, 0, sizeof urbs); 1651 memset(urbs, 0, sizeof urbs);
1464 udev = testdev_to_usbdev (dev); 1652 udev = testdev_to_usbdev(dev);
1465 dev_info(&dev->intf->dev, 1653 dev_info(&dev->intf->dev,
1466 "... iso period %d %sframes, wMaxPacket %04x\n", 1654 "... iso period %d %sframes, wMaxPacket %04x\n",
1467 1 << (desc->bInterval - 1), 1655 1 << (desc->bInterval - 1),
@@ -1469,14 +1657,14 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1469 le16_to_cpu(desc->wMaxPacketSize)); 1657 le16_to_cpu(desc->wMaxPacketSize));
1470 1658
1471 for (i = 0; i < param->sglen; i++) { 1659 for (i = 0; i < param->sglen; i++) {
1472 urbs [i] = iso_alloc_urb (udev, pipe, desc, 1660 urbs[i] = iso_alloc_urb(udev, pipe, desc,
1473 param->length); 1661 param->length, offset);
1474 if (!urbs [i]) { 1662 if (!urbs[i]) {
1475 status = -ENOMEM; 1663 status = -ENOMEM;
1476 goto fail; 1664 goto fail;
1477 } 1665 }
1478 packets += urbs[i]->number_of_packets; 1666 packets += urbs[i]->number_of_packets;
1479 urbs [i]->context = &context; 1667 urbs[i]->context = &context;
1480 } 1668 }
1481 packets *= param->iterations; 1669 packets *= param->iterations;
1482 dev_info(&dev->intf->dev, 1670 dev_info(&dev->intf->dev,
@@ -1485,27 +1673,27 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1485 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1), 1673 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1),
1486 packets); 1674 packets);
1487 1675
1488 spin_lock_irq (&context.lock); 1676 spin_lock_irq(&context.lock);
1489 for (i = 0; i < param->sglen; i++) { 1677 for (i = 0; i < param->sglen; i++) {
1490 ++context.pending; 1678 ++context.pending;
1491 status = usb_submit_urb (urbs [i], GFP_ATOMIC); 1679 status = usb_submit_urb(urbs[i], GFP_ATOMIC);
1492 if (status < 0) { 1680 if (status < 0) {
1493 ERROR (dev, "submit iso[%d], error %d\n", i, status); 1681 ERROR(dev, "submit iso[%d], error %d\n", i, status);
1494 if (i == 0) { 1682 if (i == 0) {
1495 spin_unlock_irq (&context.lock); 1683 spin_unlock_irq(&context.lock);
1496 goto fail; 1684 goto fail;
1497 } 1685 }
1498 1686
1499 simple_free_urb (urbs [i]); 1687 simple_free_urb(urbs[i]);
1500 urbs[i] = NULL; 1688 urbs[i] = NULL;
1501 context.pending--; 1689 context.pending--;
1502 context.submit_error = 1; 1690 context.submit_error = 1;
1503 break; 1691 break;
1504 } 1692 }
1505 } 1693 }
1506 spin_unlock_irq (&context.lock); 1694 spin_unlock_irq(&context.lock);
1507 1695
1508 wait_for_completion (&context.done); 1696 wait_for_completion(&context.done);
1509 1697
1510 for (i = 0; i < param->sglen; i++) { 1698 for (i = 0; i < param->sglen; i++) {
1511 if (urbs[i]) 1699 if (urbs[i])
@@ -1526,12 +1714,32 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1526 1714
1527fail: 1715fail:
1528 for (i = 0; i < param->sglen; i++) { 1716 for (i = 0; i < param->sglen; i++) {
1529 if (urbs [i]) 1717 if (urbs[i])
1530 simple_free_urb (urbs [i]); 1718 simple_free_urb(urbs[i]);
1531 } 1719 }
1532 return status; 1720 return status;
1533} 1721}
1534 1722
1723static int test_unaligned_bulk(
1724 struct usbtest_dev *tdev,
1725 int pipe,
1726 unsigned length,
1727 int iterations,
1728 unsigned transfer_flags,
1729 const char *label)
1730{
1731 int retval;
1732 struct urb *urb = usbtest_alloc_urb(
1733 testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1);
1734
1735 if (!urb)
1736 return -ENOMEM;
1737
1738 retval = simple_io(tdev, urb, iterations, 0, 0, label);
1739 simple_free_urb(urb);
1740 return retval;
1741}
1742
1535/*-------------------------------------------------------------------------*/ 1743/*-------------------------------------------------------------------------*/
1536 1744
1537/* We only have this one interface to user space, through usbfs. 1745/* We only have this one interface to user space, through usbfs.
@@ -1557,10 +1765,10 @@ fail:
1557 1765
1558/* No BKL needed */ 1766/* No BKL needed */
1559static int 1767static int
1560usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) 1768usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf)
1561{ 1769{
1562 struct usbtest_dev *dev = usb_get_intfdata (intf); 1770 struct usbtest_dev *dev = usb_get_intfdata(intf);
1563 struct usb_device *udev = testdev_to_usbdev (dev); 1771 struct usb_device *udev = testdev_to_usbdev(dev);
1564 struct usbtest_param *param = buf; 1772 struct usbtest_param *param = buf;
1565 int retval = -EOPNOTSUPP; 1773 int retval = -EOPNOTSUPP;
1566 struct urb *urb; 1774 struct urb *urb;
@@ -1569,7 +1777,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1569 struct timeval start; 1777 struct timeval start;
1570 unsigned i; 1778 unsigned i;
1571 1779
1572 // FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. 1780 /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */
1573 1781
1574 pattern = mod_pattern; 1782 pattern = mod_pattern;
1575 1783
@@ -1595,9 +1803,9 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1595 mutex_unlock(&dev->lock); 1803 mutex_unlock(&dev->lock);
1596 return -ENODEV; 1804 return -ENODEV;
1597 } 1805 }
1598 res = set_altsetting (dev, dev->info->alt); 1806 res = set_altsetting(dev, dev->info->alt);
1599 if (res) { 1807 if (res) {
1600 dev_err (&intf->dev, 1808 dev_err(&intf->dev,
1601 "set altsetting to %d failed, %d\n", 1809 "set altsetting to %d failed, %d\n",
1602 dev->info->alt, res); 1810 dev->info->alt, res);
1603 mutex_unlock(&dev->lock); 1811 mutex_unlock(&dev->lock);
@@ -1614,7 +1822,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1614 * FIXME add more tests! cancel requests, verify the data, control 1822 * FIXME add more tests! cancel requests, verify the data, control
1615 * queueing, concurrent read+write threads, and so on. 1823 * queueing, concurrent read+write threads, and so on.
1616 */ 1824 */
1617 do_gettimeofday (&start); 1825 do_gettimeofday(&start);
1618 switch (param->test_num) { 1826 switch (param->test_num) {
1619 1827
1620 case 0: 1828 case 0:
@@ -1629,14 +1837,14 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1629 dev_info(&intf->dev, 1837 dev_info(&intf->dev,
1630 "TEST 1: write %d bytes %u times\n", 1838 "TEST 1: write %d bytes %u times\n",
1631 param->length, param->iterations); 1839 param->length, param->iterations);
1632 urb = simple_alloc_urb (udev, dev->out_pipe, param->length); 1840 urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
1633 if (!urb) { 1841 if (!urb) {
1634 retval = -ENOMEM; 1842 retval = -ENOMEM;
1635 break; 1843 break;
1636 } 1844 }
1637 // FIRMWARE: bulk sink (maybe accepts short writes) 1845 /* FIRMWARE: bulk sink (maybe accepts short writes) */
1638 retval = simple_io(dev, urb, param->iterations, 0, 0, "test1"); 1846 retval = simple_io(dev, urb, param->iterations, 0, 0, "test1");
1639 simple_free_urb (urb); 1847 simple_free_urb(urb);
1640 break; 1848 break;
1641 case 2: 1849 case 2:
1642 if (dev->in_pipe == 0) 1850 if (dev->in_pipe == 0)
@@ -1644,14 +1852,14 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1644 dev_info(&intf->dev, 1852 dev_info(&intf->dev,
1645 "TEST 2: read %d bytes %u times\n", 1853 "TEST 2: read %d bytes %u times\n",
1646 param->length, param->iterations); 1854 param->length, param->iterations);
1647 urb = simple_alloc_urb (udev, dev->in_pipe, param->length); 1855 urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
1648 if (!urb) { 1856 if (!urb) {
1649 retval = -ENOMEM; 1857 retval = -ENOMEM;
1650 break; 1858 break;
1651 } 1859 }
1652 // FIRMWARE: bulk source (maybe generates short writes) 1860 /* FIRMWARE: bulk source (maybe generates short writes) */
1653 retval = simple_io(dev, urb, param->iterations, 0, 0, "test2"); 1861 retval = simple_io(dev, urb, param->iterations, 0, 0, "test2");
1654 simple_free_urb (urb); 1862 simple_free_urb(urb);
1655 break; 1863 break;
1656 case 3: 1864 case 3:
1657 if (dev->out_pipe == 0 || param->vary == 0) 1865 if (dev->out_pipe == 0 || param->vary == 0)
@@ -1659,15 +1867,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1659 dev_info(&intf->dev, 1867 dev_info(&intf->dev,
1660 "TEST 3: write/%d 0..%d bytes %u times\n", 1868 "TEST 3: write/%d 0..%d bytes %u times\n",
1661 param->vary, param->length, param->iterations); 1869 param->vary, param->length, param->iterations);
1662 urb = simple_alloc_urb (udev, dev->out_pipe, param->length); 1870 urb = simple_alloc_urb(udev, dev->out_pipe, param->length);
1663 if (!urb) { 1871 if (!urb) {
1664 retval = -ENOMEM; 1872 retval = -ENOMEM;
1665 break; 1873 break;
1666 } 1874 }
1667 // FIRMWARE: bulk sink (maybe accepts short writes) 1875 /* FIRMWARE: bulk sink (maybe accepts short writes) */
1668 retval = simple_io(dev, urb, param->iterations, param->vary, 1876 retval = simple_io(dev, urb, param->iterations, param->vary,
1669 0, "test3"); 1877 0, "test3");
1670 simple_free_urb (urb); 1878 simple_free_urb(urb);
1671 break; 1879 break;
1672 case 4: 1880 case 4:
1673 if (dev->in_pipe == 0 || param->vary == 0) 1881 if (dev->in_pipe == 0 || param->vary == 0)
@@ -1675,15 +1883,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1675 dev_info(&intf->dev, 1883 dev_info(&intf->dev,
1676 "TEST 4: read/%d 0..%d bytes %u times\n", 1884 "TEST 4: read/%d 0..%d bytes %u times\n",
1677 param->vary, param->length, param->iterations); 1885 param->vary, param->length, param->iterations);
1678 urb = simple_alloc_urb (udev, dev->in_pipe, param->length); 1886 urb = simple_alloc_urb(udev, dev->in_pipe, param->length);
1679 if (!urb) { 1887 if (!urb) {
1680 retval = -ENOMEM; 1888 retval = -ENOMEM;
1681 break; 1889 break;
1682 } 1890 }
1683 // FIRMWARE: bulk source (maybe generates short writes) 1891 /* FIRMWARE: bulk source (maybe generates short writes) */
1684 retval = simple_io(dev, urb, param->iterations, param->vary, 1892 retval = simple_io(dev, urb, param->iterations, param->vary,
1685 0, "test4"); 1893 0, "test4");
1686 simple_free_urb (urb); 1894 simple_free_urb(urb);
1687 break; 1895 break;
1688 1896
1689 /* Queued bulk I/O tests */ 1897 /* Queued bulk I/O tests */
@@ -1694,15 +1902,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1694 "TEST 5: write %d sglists %d entries of %d bytes\n", 1902 "TEST 5: write %d sglists %d entries of %d bytes\n",
1695 param->iterations, 1903 param->iterations,
1696 param->sglen, param->length); 1904 param->sglen, param->length);
1697 sg = alloc_sglist (param->sglen, param->length, 0); 1905 sg = alloc_sglist(param->sglen, param->length, 0);
1698 if (!sg) { 1906 if (!sg) {
1699 retval = -ENOMEM; 1907 retval = -ENOMEM;
1700 break; 1908 break;
1701 } 1909 }
1702 // FIRMWARE: bulk sink (maybe accepts short writes) 1910 /* FIRMWARE: bulk sink (maybe accepts short writes) */
1703 retval = perform_sglist(dev, param->iterations, dev->out_pipe, 1911 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
1704 &req, sg, param->sglen); 1912 &req, sg, param->sglen);
1705 free_sglist (sg, param->sglen); 1913 free_sglist(sg, param->sglen);
1706 break; 1914 break;
1707 1915
1708 case 6: 1916 case 6:
@@ -1712,15 +1920,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1712 "TEST 6: read %d sglists %d entries of %d bytes\n", 1920 "TEST 6: read %d sglists %d entries of %d bytes\n",
1713 param->iterations, 1921 param->iterations,
1714 param->sglen, param->length); 1922 param->sglen, param->length);
1715 sg = alloc_sglist (param->sglen, param->length, 0); 1923 sg = alloc_sglist(param->sglen, param->length, 0);
1716 if (!sg) { 1924 if (!sg) {
1717 retval = -ENOMEM; 1925 retval = -ENOMEM;
1718 break; 1926 break;
1719 } 1927 }
1720 // FIRMWARE: bulk source (maybe generates short writes) 1928 /* FIRMWARE: bulk source (maybe generates short writes) */
1721 retval = perform_sglist(dev, param->iterations, dev->in_pipe, 1929 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
1722 &req, sg, param->sglen); 1930 &req, sg, param->sglen);
1723 free_sglist (sg, param->sglen); 1931 free_sglist(sg, param->sglen);
1724 break; 1932 break;
1725 case 7: 1933 case 7:
1726 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0) 1934 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0)
@@ -1729,15 +1937,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1729 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n", 1937 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n",
1730 param->vary, param->iterations, 1938 param->vary, param->iterations,
1731 param->sglen, param->length); 1939 param->sglen, param->length);
1732 sg = alloc_sglist (param->sglen, param->length, param->vary); 1940 sg = alloc_sglist(param->sglen, param->length, param->vary);
1733 if (!sg) { 1941 if (!sg) {
1734 retval = -ENOMEM; 1942 retval = -ENOMEM;
1735 break; 1943 break;
1736 } 1944 }
1737 // FIRMWARE: bulk sink (maybe accepts short writes) 1945 /* FIRMWARE: bulk sink (maybe accepts short writes) */
1738 retval = perform_sglist(dev, param->iterations, dev->out_pipe, 1946 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
1739 &req, sg, param->sglen); 1947 &req, sg, param->sglen);
1740 free_sglist (sg, param->sglen); 1948 free_sglist(sg, param->sglen);
1741 break; 1949 break;
1742 case 8: 1950 case 8:
1743 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0) 1951 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0)
@@ -1746,15 +1954,15 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1746 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n", 1954 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n",
1747 param->vary, param->iterations, 1955 param->vary, param->iterations,
1748 param->sglen, param->length); 1956 param->sglen, param->length);
1749 sg = alloc_sglist (param->sglen, param->length, param->vary); 1957 sg = alloc_sglist(param->sglen, param->length, param->vary);
1750 if (!sg) { 1958 if (!sg) {
1751 retval = -ENOMEM; 1959 retval = -ENOMEM;
1752 break; 1960 break;
1753 } 1961 }
1754 // FIRMWARE: bulk source (maybe generates short writes) 1962 /* FIRMWARE: bulk source (maybe generates short writes) */
1755 retval = perform_sglist(dev, param->iterations, dev->in_pipe, 1963 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
1756 &req, sg, param->sglen); 1964 &req, sg, param->sglen);
1757 free_sglist (sg, param->sglen); 1965 free_sglist(sg, param->sglen);
1758 break; 1966 break;
1759 1967
1760 /* non-queued sanity tests for control (chapter 9 subset) */ 1968 /* non-queued sanity tests for control (chapter 9 subset) */
@@ -1764,7 +1972,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1764 "TEST 9: ch9 (subset) control tests, %d times\n", 1972 "TEST 9: ch9 (subset) control tests, %d times\n",
1765 param->iterations); 1973 param->iterations);
1766 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1974 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1767 retval = ch9_postconfig (dev); 1975 retval = ch9_postconfig(dev);
1768 if (retval) 1976 if (retval)
1769 dev_err(&intf->dev, "ch9 subset failed, " 1977 dev_err(&intf->dev, "ch9 subset failed, "
1770 "iterations left %d\n", i); 1978 "iterations left %d\n", i);
@@ -1779,7 +1987,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1779 "TEST 10: queue %d control calls, %d times\n", 1987 "TEST 10: queue %d control calls, %d times\n",
1780 param->sglen, 1988 param->sglen,
1781 param->iterations); 1989 param->iterations);
1782 retval = test_ctrl_queue (dev, param); 1990 retval = test_ctrl_queue(dev, param);
1783 break; 1991 break;
1784 1992
1785 /* simple non-queued unlinks (ring with one urb) */ 1993 /* simple non-queued unlinks (ring with one urb) */
@@ -1790,7 +1998,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1790 dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n", 1998 dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n",
1791 param->iterations, param->length); 1999 param->iterations, param->length);
1792 for (i = param->iterations; retval == 0 && i--; /* NOP */) 2000 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1793 retval = unlink_simple (dev, dev->in_pipe, 2001 retval = unlink_simple(dev, dev->in_pipe,
1794 param->length); 2002 param->length);
1795 if (retval) 2003 if (retval)
1796 dev_err(&intf->dev, "unlink reads failed %d, " 2004 dev_err(&intf->dev, "unlink reads failed %d, "
@@ -1803,7 +2011,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1803 dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n", 2011 dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n",
1804 param->iterations, param->length); 2012 param->iterations, param->length);
1805 for (i = param->iterations; retval == 0 && i--; /* NOP */) 2013 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1806 retval = unlink_simple (dev, dev->out_pipe, 2014 retval = unlink_simple(dev, dev->out_pipe,
1807 param->length); 2015 param->length);
1808 if (retval) 2016 if (retval)
1809 dev_err(&intf->dev, "unlink writes failed %d, " 2017 dev_err(&intf->dev, "unlink writes failed %d, "
@@ -1818,7 +2026,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1818 dev_info(&intf->dev, "TEST 13: set/clear %d halts\n", 2026 dev_info(&intf->dev, "TEST 13: set/clear %d halts\n",
1819 param->iterations); 2027 param->iterations);
1820 for (i = param->iterations; retval == 0 && i--; /* NOP */) 2028 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1821 retval = halt_simple (dev); 2029 retval = halt_simple(dev);
1822 2030
1823 if (retval) 2031 if (retval)
1824 ERROR(dev, "halts failed, iterations left %d\n", i); 2032 ERROR(dev, "halts failed, iterations left %d\n", i);
@@ -1833,7 +2041,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1833 realworld ? 1 : 0, param->length, 2041 realworld ? 1 : 0, param->length,
1834 param->vary); 2042 param->vary);
1835 retval = ctrl_out(dev, param->iterations, 2043 retval = ctrl_out(dev, param->iterations,
1836 param->length, param->vary); 2044 param->length, param->vary, 0);
1837 break; 2045 break;
1838 2046
1839 /* iso write tests */ 2047 /* iso write tests */
@@ -1844,9 +2052,9 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1844 "TEST 15: write %d iso, %d entries of %d bytes\n", 2052 "TEST 15: write %d iso, %d entries of %d bytes\n",
1845 param->iterations, 2053 param->iterations,
1846 param->sglen, param->length); 2054 param->sglen, param->length);
1847 // FIRMWARE: iso sink 2055 /* FIRMWARE: iso sink */
1848 retval = test_iso_queue (dev, param, 2056 retval = test_iso_queue(dev, param,
1849 dev->out_iso_pipe, dev->iso_out); 2057 dev->out_iso_pipe, dev->iso_out, 0);
1850 break; 2058 break;
1851 2059
1852 /* iso read tests */ 2060 /* iso read tests */
@@ -1857,17 +2065,125 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1857 "TEST 16: read %d iso, %d entries of %d bytes\n", 2065 "TEST 16: read %d iso, %d entries of %d bytes\n",
1858 param->iterations, 2066 param->iterations,
1859 param->sglen, param->length); 2067 param->sglen, param->length);
1860 // FIRMWARE: iso source 2068 /* FIRMWARE: iso source */
1861 retval = test_iso_queue (dev, param, 2069 retval = test_iso_queue(dev, param,
1862 dev->in_iso_pipe, dev->iso_in); 2070 dev->in_iso_pipe, dev->iso_in, 0);
2071 break;
2072
2073 /* FIXME scatterlist cancel (needs helper thread) */
2074
2075 /* Tests for bulk I/O using DMA mapping by core and odd address */
2076 case 17:
2077 if (dev->out_pipe == 0)
2078 break;
2079 dev_info(&intf->dev,
2080 "TEST 17: write odd addr %d bytes %u times core map\n",
2081 param->length, param->iterations);
2082
2083 retval = test_unaligned_bulk(
2084 dev, dev->out_pipe,
2085 param->length, param->iterations,
2086 0, "test17");
2087 break;
2088
2089 case 18:
2090 if (dev->in_pipe == 0)
2091 break;
2092 dev_info(&intf->dev,
2093 "TEST 18: read odd addr %d bytes %u times core map\n",
2094 param->length, param->iterations);
2095
2096 retval = test_unaligned_bulk(
2097 dev, dev->in_pipe,
2098 param->length, param->iterations,
2099 0, "test18");
2100 break;
2101
2102 /* Tests for bulk I/O using premapped coherent buffer and odd address */
2103 case 19:
2104 if (dev->out_pipe == 0)
2105 break;
2106 dev_info(&intf->dev,
2107 "TEST 19: write odd addr %d bytes %u times premapped\n",
2108 param->length, param->iterations);
2109
2110 retval = test_unaligned_bulk(
2111 dev, dev->out_pipe,
2112 param->length, param->iterations,
2113 URB_NO_TRANSFER_DMA_MAP, "test19");
2114 break;
2115
2116 case 20:
2117 if (dev->in_pipe == 0)
2118 break;
2119 dev_info(&intf->dev,
2120 "TEST 20: read odd addr %d bytes %u times premapped\n",
2121 param->length, param->iterations);
2122
2123 retval = test_unaligned_bulk(
2124 dev, dev->in_pipe,
2125 param->length, param->iterations,
2126 URB_NO_TRANSFER_DMA_MAP, "test20");
2127 break;
2128
2129 /* control write tests with unaligned buffer */
2130 case 21:
2131 if (!dev->info->ctrl_out)
2132 break;
2133 dev_info(&intf->dev,
2134 "TEST 21: %d ep0out odd addr, %d..%d vary %d\n",
2135 param->iterations,
2136 realworld ? 1 : 0, param->length,
2137 param->vary);
2138 retval = ctrl_out(dev, param->iterations,
2139 param->length, param->vary, 1);
2140 break;
2141
2142 /* unaligned iso tests */
2143 case 22:
2144 if (dev->out_iso_pipe == 0 || param->sglen == 0)
2145 break;
2146 dev_info(&intf->dev,
2147 "TEST 22: write %d iso odd, %d entries of %d bytes\n",
2148 param->iterations,
2149 param->sglen, param->length);
2150 retval = test_iso_queue(dev, param,
2151 dev->out_iso_pipe, dev->iso_out, 1);
1863 break; 2152 break;
1864 2153
1865 // FIXME unlink from queue (ring with N urbs) 2154 case 23:
2155 if (dev->in_iso_pipe == 0 || param->sglen == 0)
2156 break;
2157 dev_info(&intf->dev,
2158 "TEST 23: read %d iso odd, %d entries of %d bytes\n",
2159 param->iterations,
2160 param->sglen, param->length);
2161 retval = test_iso_queue(dev, param,
2162 dev->in_iso_pipe, dev->iso_in, 1);
2163 break;
1866 2164
1867 // FIXME scatterlist cancel (needs helper thread) 2165 /* unlink URBs from a bulk-OUT queue */
2166 case 24:
2167 if (dev->out_pipe == 0 || !param->length || param->sglen < 4)
2168 break;
2169 retval = 0;
2170 dev_info(&intf->dev, "TEST 17: unlink from %d queues of "
2171 "%d %d-byte writes\n",
2172 param->iterations, param->sglen, param->length);
2173 for (i = param->iterations; retval == 0 && i > 0; --i) {
2174 retval = unlink_queued(dev, dev->out_pipe,
2175 param->sglen, param->length);
2176 if (retval) {
2177 dev_err(&intf->dev,
2178 "unlink queued writes failed %d, "
2179 "iterations left %d\n", retval, i);
2180 break;
2181 }
2182 }
2183 break;
1868 2184
1869 } 2185 }
1870 do_gettimeofday (&param->duration); 2186 do_gettimeofday(&param->duration);
1871 param->duration.tv_sec -= start.tv_sec; 2187 param->duration.tv_sec -= start.tv_sec;
1872 param->duration.tv_usec -= start.tv_usec; 2188 param->duration.tv_usec -= start.tv_usec;
1873 if (param->duration.tv_usec < 0) { 2189 if (param->duration.tv_usec < 0) {
@@ -1880,22 +2196,22 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1880 2196
1881/*-------------------------------------------------------------------------*/ 2197/*-------------------------------------------------------------------------*/
1882 2198
1883static unsigned force_interrupt = 0; 2199static unsigned force_interrupt;
1884module_param (force_interrupt, uint, 0); 2200module_param(force_interrupt, uint, 0);
1885MODULE_PARM_DESC (force_interrupt, "0 = test default; else interrupt"); 2201MODULE_PARM_DESC(force_interrupt, "0 = test default; else interrupt");
1886 2202
1887#ifdef GENERIC 2203#ifdef GENERIC
1888static unsigned short vendor; 2204static unsigned short vendor;
1889module_param(vendor, ushort, 0); 2205module_param(vendor, ushort, 0);
1890MODULE_PARM_DESC (vendor, "vendor code (from usb-if)"); 2206MODULE_PARM_DESC(vendor, "vendor code (from usb-if)");
1891 2207
1892static unsigned short product; 2208static unsigned short product;
1893module_param(product, ushort, 0); 2209module_param(product, ushort, 0);
1894MODULE_PARM_DESC (product, "product code (from vendor)"); 2210MODULE_PARM_DESC(product, "product code (from vendor)");
1895#endif 2211#endif
1896 2212
1897static int 2213static int
1898usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id) 2214usbtest_probe(struct usb_interface *intf, const struct usb_device_id *id)
1899{ 2215{
1900 struct usb_device *udev; 2216 struct usb_device *udev;
1901 struct usbtest_dev *dev; 2217 struct usbtest_dev *dev;
@@ -1903,7 +2219,7 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1903 char *rtest, *wtest; 2219 char *rtest, *wtest;
1904 char *irtest, *iwtest; 2220 char *irtest, *iwtest;
1905 2221
1906 udev = interface_to_usbdev (intf); 2222 udev = interface_to_usbdev(intf);
1907 2223
1908#ifdef GENERIC 2224#ifdef GENERIC
1909 /* specify devices by module parameters? */ 2225 /* specify devices by module parameters? */
@@ -1930,8 +2246,9 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1930 dev->intf = intf; 2246 dev->intf = intf;
1931 2247
1932 /* cacheline-aligned scratch for i/o */ 2248 /* cacheline-aligned scratch for i/o */
1933 if ((dev->buf = kmalloc (TBUF_SIZE, GFP_KERNEL)) == NULL) { 2249 dev->buf = kmalloc(TBUF_SIZE, GFP_KERNEL);
1934 kfree (dev); 2250 if (dev->buf == NULL) {
2251 kfree(dev);
1935 return -ENOMEM; 2252 return -ENOMEM;
1936 } 2253 }
1937 2254
@@ -1943,18 +2260,18 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1943 irtest = iwtest = ""; 2260 irtest = iwtest = "";
1944 if (force_interrupt || udev->speed == USB_SPEED_LOW) { 2261 if (force_interrupt || udev->speed == USB_SPEED_LOW) {
1945 if (info->ep_in) { 2262 if (info->ep_in) {
1946 dev->in_pipe = usb_rcvintpipe (udev, info->ep_in); 2263 dev->in_pipe = usb_rcvintpipe(udev, info->ep_in);
1947 rtest = " intr-in"; 2264 rtest = " intr-in";
1948 } 2265 }
1949 if (info->ep_out) { 2266 if (info->ep_out) {
1950 dev->out_pipe = usb_sndintpipe (udev, info->ep_out); 2267 dev->out_pipe = usb_sndintpipe(udev, info->ep_out);
1951 wtest = " intr-out"; 2268 wtest = " intr-out";
1952 } 2269 }
1953 } else { 2270 } else {
1954 if (info->autoconf) { 2271 if (info->autoconf) {
1955 int status; 2272 int status;
1956 2273
1957 status = get_endpoints (dev, intf); 2274 status = get_endpoints(dev, intf);
1958 if (status < 0) { 2275 if (status < 0) {
1959 WARNING(dev, "couldn't get endpoints, %d\n", 2276 WARNING(dev, "couldn't get endpoints, %d\n",
1960 status); 2277 status);
@@ -1963,10 +2280,10 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1963 /* may find bulk or ISO pipes */ 2280 /* may find bulk or ISO pipes */
1964 } else { 2281 } else {
1965 if (info->ep_in) 2282 if (info->ep_in)
1966 dev->in_pipe = usb_rcvbulkpipe (udev, 2283 dev->in_pipe = usb_rcvbulkpipe(udev,
1967 info->ep_in); 2284 info->ep_in);
1968 if (info->ep_out) 2285 if (info->ep_out)
1969 dev->out_pipe = usb_sndbulkpipe (udev, 2286 dev->out_pipe = usb_sndbulkpipe(udev,
1970 info->ep_out); 2287 info->ep_out);
1971 } 2288 }
1972 if (dev->in_pipe) 2289 if (dev->in_pipe)
@@ -1979,15 +2296,26 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1979 iwtest = " iso-out"; 2296 iwtest = " iso-out";
1980 } 2297 }
1981 2298
1982 usb_set_intfdata (intf, dev); 2299 usb_set_intfdata(intf, dev);
1983 dev_info (&intf->dev, "%s\n", info->name); 2300 dev_info(&intf->dev, "%s\n", info->name);
1984 dev_info (&intf->dev, "%s speed {control%s%s%s%s%s} tests%s\n", 2301 dev_info(&intf->dev, "%s speed {control%s%s%s%s%s} tests%s\n",
1985 ({ char *tmp; 2302 ({ char *tmp;
1986 switch (udev->speed) { 2303 switch (udev->speed) {
1987 case USB_SPEED_LOW: tmp = "low"; break; 2304 case USB_SPEED_LOW:
1988 case USB_SPEED_FULL: tmp = "full"; break; 2305 tmp = "low";
1989 case USB_SPEED_HIGH: tmp = "high"; break; 2306 break;
1990 default: tmp = "unknown"; break; 2307 case USB_SPEED_FULL:
2308 tmp = "full";
2309 break;
2310 case USB_SPEED_HIGH:
2311 tmp = "high";
2312 break;
2313 case USB_SPEED_SUPER:
2314 tmp = "super";
2315 break;
2316 default:
2317 tmp = "unknown";
2318 break;
1991 }; tmp; }), 2319 }; tmp; }),
1992 info->ctrl_out ? " in/out" : "", 2320 info->ctrl_out ? " in/out" : "",
1993 rtest, wtest, 2321 rtest, wtest,
@@ -1996,24 +2324,24 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1996 return 0; 2324 return 0;
1997} 2325}
1998 2326
1999static int usbtest_suspend (struct usb_interface *intf, pm_message_t message) 2327static int usbtest_suspend(struct usb_interface *intf, pm_message_t message)
2000{ 2328{
2001 return 0; 2329 return 0;
2002} 2330}
2003 2331
2004static int usbtest_resume (struct usb_interface *intf) 2332static int usbtest_resume(struct usb_interface *intf)
2005{ 2333{
2006 return 0; 2334 return 0;
2007} 2335}
2008 2336
2009 2337
2010static void usbtest_disconnect (struct usb_interface *intf) 2338static void usbtest_disconnect(struct usb_interface *intf)
2011{ 2339{
2012 struct usbtest_dev *dev = usb_get_intfdata (intf); 2340 struct usbtest_dev *dev = usb_get_intfdata(intf);
2013 2341
2014 usb_set_intfdata (intf, NULL); 2342 usb_set_intfdata(intf, NULL);
2015 dev_dbg (&intf->dev, "disconnect\n"); 2343 dev_dbg(&intf->dev, "disconnect\n");
2016 kfree (dev); 2344 kfree(dev);
2017} 2345}
2018 2346
2019/* Basic testing only needs a device that can source or sink bulk traffic. 2347/* Basic testing only needs a device that can source or sink bulk traffic.
@@ -2050,9 +2378,9 @@ static struct usbtest_info fw_info = {
2050 .ep_in = 2, 2378 .ep_in = 2,
2051 .ep_out = 2, 2379 .ep_out = 2,
2052 .alt = 1, 2380 .alt = 1,
2053 .autoconf = 1, // iso and ctrl_out need autoconf 2381 .autoconf = 1, /* iso and ctrl_out need autoconf */
2054 .ctrl_out = 1, 2382 .ctrl_out = 1,
2055 .iso = 1, // iso_ep's are #8 in/out 2383 .iso = 1, /* iso_ep's are #8 in/out */
2056}; 2384};
2057 2385
2058/* peripheral running Linux and 'zero.c' test firmware, or 2386/* peripheral running Linux and 'zero.c' test firmware, or
@@ -2109,56 +2437,56 @@ static const struct usb_device_id id_table[] = {
2109 */ 2437 */
2110 2438
2111 /* generic EZ-USB FX controller */ 2439 /* generic EZ-USB FX controller */
2112 { USB_DEVICE (0x0547, 0x2235), 2440 { USB_DEVICE(0x0547, 0x2235),
2113 .driver_info = (unsigned long) &ez1_info, 2441 .driver_info = (unsigned long) &ez1_info,
2114 }, 2442 },
2115 2443
2116 /* CY3671 development board with EZ-USB FX */ 2444 /* CY3671 development board with EZ-USB FX */
2117 { USB_DEVICE (0x0547, 0x0080), 2445 { USB_DEVICE(0x0547, 0x0080),
2118 .driver_info = (unsigned long) &ez1_info, 2446 .driver_info = (unsigned long) &ez1_info,
2119 }, 2447 },
2120 2448
2121 /* generic EZ-USB FX2 controller (or development board) */ 2449 /* generic EZ-USB FX2 controller (or development board) */
2122 { USB_DEVICE (0x04b4, 0x8613), 2450 { USB_DEVICE(0x04b4, 0x8613),
2123 .driver_info = (unsigned long) &ez2_info, 2451 .driver_info = (unsigned long) &ez2_info,
2124 }, 2452 },
2125 2453
2126 /* re-enumerated usb test device firmware */ 2454 /* re-enumerated usb test device firmware */
2127 { USB_DEVICE (0xfff0, 0xfff0), 2455 { USB_DEVICE(0xfff0, 0xfff0),
2128 .driver_info = (unsigned long) &fw_info, 2456 .driver_info = (unsigned long) &fw_info,
2129 }, 2457 },
2130 2458
2131 /* "Gadget Zero" firmware runs under Linux */ 2459 /* "Gadget Zero" firmware runs under Linux */
2132 { USB_DEVICE (0x0525, 0xa4a0), 2460 { USB_DEVICE(0x0525, 0xa4a0),
2133 .driver_info = (unsigned long) &gz_info, 2461 .driver_info = (unsigned long) &gz_info,
2134 }, 2462 },
2135 2463
2136 /* so does a user-mode variant */ 2464 /* so does a user-mode variant */
2137 { USB_DEVICE (0x0525, 0xa4a4), 2465 { USB_DEVICE(0x0525, 0xa4a4),
2138 .driver_info = (unsigned long) &um_info, 2466 .driver_info = (unsigned long) &um_info,
2139 }, 2467 },
2140 2468
2141 /* ... and a user-mode variant that talks iso */ 2469 /* ... and a user-mode variant that talks iso */
2142 { USB_DEVICE (0x0525, 0xa4a3), 2470 { USB_DEVICE(0x0525, 0xa4a3),
2143 .driver_info = (unsigned long) &um2_info, 2471 .driver_info = (unsigned long) &um2_info,
2144 }, 2472 },
2145 2473
2146#ifdef KEYSPAN_19Qi 2474#ifdef KEYSPAN_19Qi
2147 /* Keyspan 19qi uses an21xx (original EZ-USB) */ 2475 /* Keyspan 19qi uses an21xx (original EZ-USB) */
2148 // this does not coexist with the real Keyspan 19qi driver! 2476 /* this does not coexist with the real Keyspan 19qi driver! */
2149 { USB_DEVICE (0x06cd, 0x010b), 2477 { USB_DEVICE(0x06cd, 0x010b),
2150 .driver_info = (unsigned long) &ez1_info, 2478 .driver_info = (unsigned long) &ez1_info,
2151 }, 2479 },
2152#endif 2480#endif
2153 2481
2154 /*-------------------------------------------------------------*/ 2482 /*-------------------------------------------------------------*/
2155 2483
2156#ifdef IBOT2 2484#ifdef IBOT2
2157 /* iBOT2 makes a nice source of high speed bulk-in data */ 2485 /* iBOT2 makes a nice source of high speed bulk-in data */
2158 // this does not coexist with a real iBOT2 driver! 2486 /* this does not coexist with a real iBOT2 driver! */
2159 { USB_DEVICE (0x0b62, 0x0059), 2487 { USB_DEVICE(0x0b62, 0x0059),
2160 .driver_info = (unsigned long) &ibot2_info, 2488 .driver_info = (unsigned long) &ibot2_info,
2161 }, 2489 },
2162#endif 2490#endif
2163 2491
2164 /*-------------------------------------------------------------*/ 2492 /*-------------------------------------------------------------*/
@@ -2172,7 +2500,7 @@ static const struct usb_device_id id_table[] = {
2172 2500
2173 { } 2501 { }
2174}; 2502};
2175MODULE_DEVICE_TABLE (usb, id_table); 2503MODULE_DEVICE_TABLE(usb, id_table);
2176 2504
2177static struct usb_driver usbtest_driver = { 2505static struct usb_driver usbtest_driver = {
2178 .name = "usbtest", 2506 .name = "usbtest",
@@ -2186,22 +2514,22 @@ static struct usb_driver usbtest_driver = {
2186 2514
2187/*-------------------------------------------------------------------------*/ 2515/*-------------------------------------------------------------------------*/
2188 2516
2189static int __init usbtest_init (void) 2517static int __init usbtest_init(void)
2190{ 2518{
2191#ifdef GENERIC 2519#ifdef GENERIC
2192 if (vendor) 2520 if (vendor)
2193 pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product); 2521 pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product);
2194#endif 2522#endif
2195 return usb_register (&usbtest_driver); 2523 return usb_register(&usbtest_driver);
2196} 2524}
2197module_init (usbtest_init); 2525module_init(usbtest_init);
2198 2526
2199static void __exit usbtest_exit (void) 2527static void __exit usbtest_exit(void)
2200{ 2528{
2201 usb_deregister (&usbtest_driver); 2529 usb_deregister(&usbtest_driver);
2202} 2530}
2203module_exit (usbtest_exit); 2531module_exit(usbtest_exit);
2204 2532
2205MODULE_DESCRIPTION ("USB Core/HCD Testing Driver"); 2533MODULE_DESCRIPTION("USB Core/HCD Testing Driver");
2206MODULE_LICENSE ("GPL"); 2534MODULE_LICENSE("GPL");
2207 2535