aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ehci-sched.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2012-07-11 11:22:05 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-16 19:53:16 -0400
commit3ca9aebac2ebb8f56d2d097636b8c568320a9f87 (patch)
treead4382a904320043a32e8b18263bc22215ce5cee /drivers/usb/host/ehci-sched.c
parentd58b4bcc6df8046cf9c3c59f9ff84d2cd86b93eb (diff)
USB: EHCI: use hrtimer for the periodic schedule
This patch (as1573) adds hrtimer support for managing ehci-hcd's periodic schedule. There are two issues to deal with. First, the schedule's state (on or off) must not be changed until the hardware status has caught up with the current command. This is handled by an hrtimer event that polls at 1-ms intervals to see when the Periodic Schedule Status (PSS) flag matches the Periodic Schedule Enable (PSE) value. Second, the schedule should not be turned off as soon as it becomes empty. Turning the schedule on and off takes time, so we want to wait until the schedule has been empty for a suitable period before turning it off. This is handled by an hrtimer event that gets set to expire 10 ms after the periodic schedule becomes empty. The existing code polls (for up to 1125 us and with interrupts disabled!) to check the status, and doesn't implement a delay before turning off the schedule. Furthermore, if the polling fails then the driver decides that the controller has died. This has caused problems for several people; some controllers can take 10 ms or more to turn off their periodic schedules. This patch fixes these issues. It also makes the "broken_periodic" workaround unnecessary; there is no longer any danger of turning off the periodic schedule after it has been on for less than 1 ms. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/host/ehci-sched.c')
-rw-r--r--drivers/usb/host/ehci-sched.c69
1 files changed, 15 insertions, 54 deletions
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 3429b8a33c58..f5c15880c65a 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -481,67 +481,26 @@ static int tt_no_collision (
481 481
482static int enable_periodic (struct ehci_hcd *ehci) 482static int enable_periodic (struct ehci_hcd *ehci)
483{ 483{
484 int status; 484 if (ehci->periodic_count++)
485
486 if (ehci->periodic_sched++)
487 return 0; 485 return 0;
488 486
489 /* did clearing PSE did take effect yet? 487 /* Stop waiting to turn off the periodic schedule */
490 * takes effect only at frame boundaries... 488 ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_DISABLE_PERIODIC);
491 */
492 status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
493 STS_PSS, 0, 9 * 125);
494 if (status) {
495 usb_hc_died(ehci_to_hcd(ehci));
496 return status;
497 }
498
499 ehci->command |= CMD_PSE;
500 ehci_writel(ehci, ehci->command, &ehci->regs->command);
501 /* posted write ... PSS happens later */
502 489
503 /* make sure ehci_work scans these */ 490 /* Don't start the schedule until PSS is 0 */
504 ehci->next_uframe = ehci_read_frame_index(ehci) 491 ehci_poll_PSS(ehci);
505 % (ehci->periodic_size << 3);
506 if (unlikely(ehci->broken_periodic))
507 ehci->last_periodic_enable = ktime_get_real();
508 return 0; 492 return 0;
509} 493}
510 494
511static int disable_periodic (struct ehci_hcd *ehci) 495static int disable_periodic (struct ehci_hcd *ehci)
512{ 496{
513 int status; 497 if (--ehci->periodic_count)
514
515 if (--ehci->periodic_sched)
516 return 0; 498 return 0;
517 499
518 if (unlikely(ehci->broken_periodic)) { 500 ehci->next_uframe = -1; /* the periodic schedule is empty */
519 /* delay experimentally determined */
520 ktime_t safe = ktime_add_us(ehci->last_periodic_enable, 1000);
521 ktime_t now = ktime_get_real();
522 s64 delay = ktime_us_delta(safe, now);
523
524 if (unlikely(delay > 0))
525 udelay(delay);
526 }
527
528 /* did setting PSE not take effect yet?
529 * takes effect only at frame boundaries...
530 */
531 status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
532 STS_PSS, STS_PSS, 9 * 125);
533 if (status) {
534 usb_hc_died(ehci_to_hcd(ehci));
535 return status;
536 }
537
538 ehci->command &= ~CMD_PSE;
539 ehci_writel(ehci, ehci->command, &ehci->regs->command);
540 /* posted write ... */
541
542 free_cached_lists(ehci);
543 501
544 ehci->next_uframe = -1; 502 /* Don't turn off the schedule until PSS is 1 */
503 ehci_poll_PSS(ehci);
545 return 0; 504 return 0;
546} 505}
547 506
@@ -650,8 +609,7 @@ static int qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
650 qh->qh_state = QH_STATE_UNLINK; 609 qh->qh_state = QH_STATE_UNLINK;
651 qh->qh_next.ptr = NULL; 610 qh->qh_next.ptr = NULL;
652 611
653 /* maybe turn off periodic schedule */ 612 return 0;
654 return disable_periodic(ehci);
655} 613}
656 614
657static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) 615static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
@@ -706,6 +664,9 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
706 ehci_err(ehci, "can't reschedule qh %p, err %d\n", 664 ehci_err(ehci, "can't reschedule qh %p, err %d\n",
707 qh, rc); 665 qh, rc);
708 } 666 }
667
668 /* maybe turn off periodic schedule */
669 disable_periodic(ehci);
709} 670}
710 671
711/*-------------------------------------------------------------------------*/ 672/*-------------------------------------------------------------------------*/
@@ -2447,7 +2408,7 @@ restart:
2447 2408
2448 /* assume completion callbacks modify the queue */ 2409 /* assume completion callbacks modify the queue */
2449 if (unlikely (modified)) { 2410 if (unlikely (modified)) {
2450 if (likely(ehci->periodic_sched > 0)) 2411 if (likely(ehci->periodic_count > 0))
2451 goto restart; 2412 goto restart;
2452 /* short-circuit this scan */ 2413 /* short-circuit this scan */
2453 now_uframe = clock; 2414 now_uframe = clock;
@@ -2476,7 +2437,7 @@ restart:
2476 unsigned now; 2437 unsigned now;
2477 2438
2478 if (ehci->rh_state < EHCI_RH_RUNNING 2439 if (ehci->rh_state < EHCI_RH_RUNNING
2479 || ehci->periodic_sched == 0) 2440 || ehci->periodic_count == 0)
2480 break; 2441 break;
2481 ehci->next_uframe = now_uframe; 2442 ehci->next_uframe = now_uframe;
2482 now = ehci_read_frame_index(ehci) & (mod - 1); 2443 now = ehci_read_frame_index(ehci) & (mod - 1);