Deleted Added
full compact
usb_request.c (187173) usb_request.c (188411)
1/* $FreeBSD: head/sys/dev/usb2/core/usb2_request.c 187173 2009-01-13 19:03:12Z thompsa $ */
1/* $FreeBSD: head/sys/dev/usb2/core/usb2_request.c 188411 2009-02-09 21:56:33Z thompsa $ */
2/*-
3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 356 unchanged lines hidden (view full) ---

366
367 temp = usb2_ss_delay;
368 if (temp > 5000) {
369 temp = 5000;
370 }
371 if (temp > 0) {
372 usb2_pause_mtx(
373 xfer->xroot->xfer_mtx,
2/*-
3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

--- 356 unchanged lines hidden (view full) ---

366
367 temp = usb2_ss_delay;
368 if (temp > 5000) {
369 temp = 5000;
370 }
371 if (temp > 0) {
372 usb2_pause_mtx(
373 xfer->xroot->xfer_mtx,
374 temp);
374 USB_MS_TO_TICKS(temp));
375 }
376#endif
377 xfer->flags.manual_status = 0;
378 } else {
379 break;
380 }
381 }
382 xfer->nframes = 1;

--- 89 unchanged lines hidden (view full) ---

472
473 if (mtx) {
474 mtx_lock(mtx);
475 }
476 return ((usb2_error_t)err);
477}
478
479/*------------------------------------------------------------------------*
375 }
376#endif
377 xfer->flags.manual_status = 0;
378 } else {
379 break;
380 }
381 }
382 xfer->nframes = 1;

--- 89 unchanged lines hidden (view full) ---

472
473 if (mtx) {
474 mtx_lock(mtx);
475 }
476 return ((usb2_error_t)err);
477}
478
479/*------------------------------------------------------------------------*
480 * usb2_do_request_proc - factored out code
481 *
482 * This function is factored out code. It does basically the same like
483 * usb2_do_request_flags, except it will check the status of the
484 * passed process argument before doing the USB request. If the
485 * process is draining the USB_ERR_IOERROR code will be returned. It
486 * is assumed that the mutex associated with the process is locked
487 * when calling this function.
488 *------------------------------------------------------------------------*/
489usb2_error_t
490usb2_do_request_proc(struct usb2_device *udev, struct usb2_process *pproc,
491 struct usb2_device_request *req, void *data, uint32_t flags,
492 uint16_t *actlen, uint32_t timeout)
493{
494 usb2_error_t err;
495 uint16_t len;
496
497 /* get request data length */
498 len = UGETW(req->wLength);
499
500 /* check if the device is being detached */
501 if (usb2_proc_is_gone(pproc)) {
502 err = USB_ERR_IOERROR;
503 goto done;
504 }
505
506 /* forward the USB request */
507 err = usb2_do_request_flags(udev, pproc->up_mtx,
508 req, data, flags, actlen, timeout);
509
510done:
511 /* on failure we zero the data */
512 /* on short packet we zero the unused data */
513 if ((len != 0) && (req->bmRequestType & UE_DIR_IN)) {
514 if (err)
515 memset(data, 0, len);
516 else if (actlen && *actlen != len)
517 memset(((uint8_t *)data) + *actlen, 0, len - *actlen);
518 }
519 return (err);
520}
521
522/*------------------------------------------------------------------------*
480 * usb2_req_reset_port
481 *
482 * This function will instruct an USB HUB to perform a reset sequence
483 * on the specified port number.
484 *
485 * Returns:
486 * 0: Success. The USB device should now be at address zero.
487 * Else: Failure. No USB device is present and the USB port should be

--- 27 unchanged lines hidden (view full) ---

515 if (pr_recovery_delay > 1000) {
516 pr_recovery_delay = 1000;
517 }
518#endif
519 n = 0;
520 while (1) {
521#if USB_DEBUG
522 /* wait for the device to recover from reset */
523 * usb2_req_reset_port
524 *
525 * This function will instruct an USB HUB to perform a reset sequence
526 * on the specified port number.
527 *
528 * Returns:
529 * 0: Success. The USB device should now be at address zero.
530 * Else: Failure. No USB device is present and the USB port should be

--- 27 unchanged lines hidden (view full) ---

558 if (pr_recovery_delay > 1000) {
559 pr_recovery_delay = 1000;
560 }
561#endif
562 n = 0;
563 while (1) {
564#if USB_DEBUG
565 /* wait for the device to recover from reset */
523 usb2_pause_mtx(mtx, pr_poll_delay);
566 usb2_pause_mtx(mtx, USB_MS_TO_TICKS(pr_poll_delay));
524 n += pr_poll_delay;
525#else
526 /* wait for the device to recover from reset */
567 n += pr_poll_delay;
568#else
569 /* wait for the device to recover from reset */
527 usb2_pause_mtx(mtx, USB_PORT_RESET_DELAY);
570 usb2_pause_mtx(mtx, USB_MS_TO_TICKS(USB_PORT_RESET_DELAY));
528 n += USB_PORT_RESET_DELAY;
529#endif
530 err = usb2_req_get_port_status(udev, mtx, &ps, port);
531 if (err) {
532 goto done;
533 }
534 /* if the device disappeared, just give up */
535 if (!(UGETW(ps.wPortStatus) & UPS_CURRENT_CONNECT_STATUS)) {

--- 18 unchanged lines hidden (view full) ---

554 }
555 /* check for timeout */
556 if (n == 0) {
557 err = USB_ERR_TIMEOUT;
558 goto done;
559 }
560#if USB_DEBUG
561 /* wait for the device to recover from reset */
571 n += USB_PORT_RESET_DELAY;
572#endif
573 err = usb2_req_get_port_status(udev, mtx, &ps, port);
574 if (err) {
575 goto done;
576 }
577 /* if the device disappeared, just give up */
578 if (!(UGETW(ps.wPortStatus) & UPS_CURRENT_CONNECT_STATUS)) {

--- 18 unchanged lines hidden (view full) ---

597 }
598 /* check for timeout */
599 if (n == 0) {
600 err = USB_ERR_TIMEOUT;
601 goto done;
602 }
603#if USB_DEBUG
604 /* wait for the device to recover from reset */
562 usb2_pause_mtx(mtx, pr_recovery_delay);
605 usb2_pause_mtx(mtx, USB_MS_TO_TICKS(pr_recovery_delay));
563#else
564 /* wait for the device to recover from reset */
606#else
607 /* wait for the device to recover from reset */
565 usb2_pause_mtx(mtx, USB_PORT_RESET_RECOVERY);
608 usb2_pause_mtx(mtx, USB_MS_TO_TICKS(USB_PORT_RESET_RECOVERY));
566#endif
567
568done:
569 DPRINTFN(2, "port %d reset returning error=%s\n",
570 port, usb2_errstr(err));
571 return (err);
572}
573

--- 45 unchanged lines hidden (view full) ---

619 desc, 0, NULL, 1000);
620
621 if (err) {
622 if (!retries) {
623 goto done;
624 }
625 retries--;
626
609#endif
610
611done:
612 DPRINTFN(2, "port %d reset returning error=%s\n",
613 port, usb2_errstr(err));
614 return (err);
615}
616

--- 45 unchanged lines hidden (view full) ---

662 desc, 0, NULL, 1000);
663
664 if (err) {
665 if (!retries) {
666 goto done;
667 }
668 retries--;
669
627 usb2_pause_mtx(mtx, 200);
670 usb2_pause_mtx(mtx, hz / 5);
628
629 continue;
630 }
631 buf = desc;
632
633 if (min_len == max_len) {
634
635 /* enforce correct type and length */

--- 728 unchanged lines hidden (view full) ---

1364 /* XXX ignore any errors! */
1365 DPRINTFN(0, "addr=%d, set address failed! (ignored)\n",
1366 old_addr);
1367 }
1368 /* restore device address */
1369 udev->address = old_addr;
1370
1371 /* allow device time to set new address */
671
672 continue;
673 }
674 buf = desc;
675
676 if (min_len == max_len) {
677
678 /* enforce correct type and length */

--- 728 unchanged lines hidden (view full) ---

1407 /* XXX ignore any errors! */
1408 DPRINTFN(0, "addr=%d, set address failed! (ignored)\n",
1409 old_addr);
1410 }
1411 /* restore device address */
1412 udev->address = old_addr;
1413
1414 /* allow device time to set new address */
1372 usb2_pause_mtx(mtx, USB_SET_ADDRESS_SETTLE);
1415 usb2_pause_mtx(mtx, USB_MS_TO_TICKS(USB_SET_ADDRESS_SETTLE));
1373
1374 /* get the device descriptor */
1375 err = usb2_req_get_desc(udev, mtx, &udev->ddesc,
1376 USB_MAX_IPACKET, USB_MAX_IPACKET, 0, UDESC_DEVICE, 0, 0);
1377 if (err) {
1378 DPRINTFN(0, "getting device descriptor "
1379 "at addr %d failed!\n", udev->address);
1380 goto done;
1381 }
1382 /* get the full device descriptor */
1383 err = usb2_req_get_device_desc(udev, mtx, &udev->ddesc);
1384 if (err) {
1385 DPRINTFN(0, "addr=%d, getting device "
1386 "descriptor failed!\n", old_addr);
1387 goto done;
1388 }
1389done:
1390 if (err && do_retry) {
1391 /* give the USB firmware some time to load */
1416
1417 /* get the device descriptor */
1418 err = usb2_req_get_desc(udev, mtx, &udev->ddesc,
1419 USB_MAX_IPACKET, USB_MAX_IPACKET, 0, UDESC_DEVICE, 0, 0);
1420 if (err) {
1421 DPRINTFN(0, "getting device descriptor "
1422 "at addr %d failed!\n", udev->address);
1423 goto done;
1424 }
1425 /* get the full device descriptor */
1426 err = usb2_req_get_device_desc(udev, mtx, &udev->ddesc);
1427 if (err) {
1428 DPRINTFN(0, "addr=%d, getting device "
1429 "descriptor failed!\n", old_addr);
1430 goto done;
1431 }
1432done:
1433 if (err && do_retry) {
1434 /* give the USB firmware some time to load */
1392 usb2_pause_mtx(mtx, 500);
1435 usb2_pause_mtx(mtx, hz / 2);
1393 /* no more retries after this retry */
1394 do_retry = 0;
1395 /* try again */
1396 goto retry;
1397 }
1398 /* restore address */
1399 udev->address = old_addr;
1400 return (err);

--- 43 unchanged lines hidden ---
1436 /* no more retries after this retry */
1437 do_retry = 0;
1438 /* try again */
1439 goto retry;
1440 }
1441 /* restore address */
1442 udev->address = old_addr;
1443 return (err);

--- 43 unchanged lines hidden ---