aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/uhci-hcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host/uhci-hcd.c')
-rw-r--r--drivers/usb/host/uhci-hcd.c139
1 files changed, 70 insertions, 69 deletions
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index d225e11f4055..7b48567622ef 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -13,7 +13,7 @@
13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface 13 * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). 14 * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) 15 * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
16 * (C) Copyright 2004-2005 Alan Stern, stern@rowland.harvard.edu 16 * (C) Copyright 2004-2006 Alan Stern, stern@rowland.harvard.edu
17 * 17 *
18 * Intel documents this fairly well, and as far as I know there 18 * Intel documents this fairly well, and as far as I know there
19 * are no royalties or anything like that, but even so there are 19 * are no royalties or anything like that, but even so there are
@@ -31,7 +31,6 @@
31#include <linux/ioport.h> 31#include <linux/ioport.h>
32#include <linux/sched.h> 32#include <linux/sched.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/smp_lock.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
36#include <linux/unistd.h> 35#include <linux/unistd.h>
37#include <linux/interrupt.h> 36#include <linux/interrupt.h>
@@ -88,15 +87,6 @@ static void suspend_rh(struct uhci_hcd *uhci, enum uhci_rh_state new_state);
88static void wakeup_rh(struct uhci_hcd *uhci); 87static void wakeup_rh(struct uhci_hcd *uhci);
89static void uhci_get_current_frame_number(struct uhci_hcd *uhci); 88static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
90 89
91/* If a transfer is still active after this much time, turn off FSBR */
92#define IDLE_TIMEOUT msecs_to_jiffies(50)
93#define FSBR_DELAY msecs_to_jiffies(50)
94
95/* When we timeout an idle transfer for FSBR, we'll switch it over to */
96/* depth first traversal. We'll do it in groups of this number of TDs */
97/* to make sure it doesn't hog all of the bandwidth */
98#define DEPTH_INTERVAL 5
99
100#include "uhci-debug.c" 90#include "uhci-debug.c"
101#include "uhci-q.c" 91#include "uhci-q.c"
102#include "uhci-hub.c" 92#include "uhci-hub.c"
@@ -120,22 +110,29 @@ static void finish_reset(struct uhci_hcd *uhci)
120 uhci->is_stopped = UHCI_IS_STOPPED; 110 uhci->is_stopped = UHCI_IS_STOPPED;
121 uhci_to_hcd(uhci)->state = HC_STATE_HALT; 111 uhci_to_hcd(uhci)->state = HC_STATE_HALT;
122 uhci_to_hcd(uhci)->poll_rh = 0; 112 uhci_to_hcd(uhci)->poll_rh = 0;
113
114 uhci->dead = 0; /* Full reset resurrects the controller */
123} 115}
124 116
125/* 117/*
126 * Last rites for a defunct/nonfunctional controller 118 * Last rites for a defunct/nonfunctional controller
127 * or one we don't want to use any more. 119 * or one we don't want to use any more.
128 */ 120 */
129static void hc_died(struct uhci_hcd *uhci) 121static void uhci_hc_died(struct uhci_hcd *uhci)
130{ 122{
123 uhci_get_current_frame_number(uhci);
131 uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr); 124 uhci_reset_hc(to_pci_dev(uhci_dev(uhci)), uhci->io_addr);
132 finish_reset(uhci); 125 finish_reset(uhci);
133 uhci->hc_inaccessible = 1; 126 uhci->dead = 1;
127
128 /* The current frame may already be partway finished */
129 ++uhci->frame_number;
134} 130}
135 131
136/* 132/*
137 * Initialize a controller that was newly discovered or has just been 133 * Initialize a controller that was newly discovered or has lost power
138 * resumed. In either case we can't be sure of its previous state. 134 * or otherwise been reset while it was suspended. In none of these cases
135 * can we be sure of its previous state.
139 */ 136 */
140static void check_and_reset_hc(struct uhci_hcd *uhci) 137static void check_and_reset_hc(struct uhci_hcd *uhci)
141{ 138{
@@ -155,7 +152,8 @@ static void configure_hc(struct uhci_hcd *uhci)
155 outl(uhci->frame_dma_handle, uhci->io_addr + USBFLBASEADD); 152 outl(uhci->frame_dma_handle, uhci->io_addr + USBFLBASEADD);
156 153
157 /* Set the current frame number */ 154 /* Set the current frame number */
158 outw(uhci->frame_number, uhci->io_addr + USBFRNUM); 155 outw(uhci->frame_number & UHCI_MAX_SOF_NUMBER,
156 uhci->io_addr + USBFRNUM);
159 157
160 /* Mark controller as not halted before we enable interrupts */ 158 /* Mark controller as not halted before we enable interrupts */
161 uhci_to_hcd(uhci)->state = HC_STATE_SUSPENDED; 159 uhci_to_hcd(uhci)->state = HC_STATE_SUSPENDED;
@@ -207,7 +205,8 @@ __acquires(uhci->lock)
207 int int_enable; 205 int int_enable;
208 206
209 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED); 207 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
210 dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__, 208 dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev,
209 "%s%s\n", __FUNCTION__,
211 (auto_stop ? " (auto-stop)" : "")); 210 (auto_stop ? " (auto-stop)" : ""));
212 211
213 /* If we get a suspend request when we're already auto-stopped 212 /* If we get a suspend request when we're already auto-stopped
@@ -241,27 +240,27 @@ __acquires(uhci->lock)
241 spin_unlock_irq(&uhci->lock); 240 spin_unlock_irq(&uhci->lock);
242 msleep(1); 241 msleep(1);
243 spin_lock_irq(&uhci->lock); 242 spin_lock_irq(&uhci->lock);
244 if (uhci->hc_inaccessible) /* Died */ 243 if (uhci->dead)
245 return; 244 return;
246 } 245 }
247 if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH)) 246 if (!(inw(uhci->io_addr + USBSTS) & USBSTS_HCH))
248 dev_warn(uhci_dev(uhci), "Controller not stopped yet!\n"); 247 dev_warn(&uhci_to_hcd(uhci)->self.root_hub->dev,
248 "Controller not stopped yet!\n");
249 249
250 uhci_get_current_frame_number(uhci); 250 uhci_get_current_frame_number(uhci);
251 smp_wmb();
252 251
253 uhci->rh_state = new_state; 252 uhci->rh_state = new_state;
254 uhci->is_stopped = UHCI_IS_STOPPED; 253 uhci->is_stopped = UHCI_IS_STOPPED;
255 uhci_to_hcd(uhci)->poll_rh = !int_enable; 254 uhci_to_hcd(uhci)->poll_rh = !int_enable;
256 255
257 uhci_scan_schedule(uhci, NULL); 256 uhci_scan_schedule(uhci, NULL);
257 uhci_fsbr_off(uhci);
258} 258}
259 259
260static void start_rh(struct uhci_hcd *uhci) 260static void start_rh(struct uhci_hcd *uhci)
261{ 261{
262 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING; 262 uhci_to_hcd(uhci)->state = HC_STATE_RUNNING;
263 uhci->is_stopped = 0; 263 uhci->is_stopped = 0;
264 smp_wmb();
265 264
266 /* Mark it configured and running with a 64-byte max packet. 265 /* Mark it configured and running with a 64-byte max packet.
267 * All interrupts are enabled, even though RESUME won't do anything. 266 * All interrupts are enabled, even though RESUME won't do anything.
@@ -278,7 +277,8 @@ static void wakeup_rh(struct uhci_hcd *uhci)
278__releases(uhci->lock) 277__releases(uhci->lock)
279__acquires(uhci->lock) 278__acquires(uhci->lock)
280{ 279{
281 dev_dbg(uhci_dev(uhci), "%s%s\n", __FUNCTION__, 280 dev_dbg(&uhci_to_hcd(uhci)->self.root_hub->dev,
281 "%s%s\n", __FUNCTION__,
282 uhci->rh_state == UHCI_RH_AUTO_STOPPED ? 282 uhci->rh_state == UHCI_RH_AUTO_STOPPED ?
283 " (auto-start)" : ""); 283 " (auto-start)" : "");
284 284
@@ -293,7 +293,7 @@ __acquires(uhci->lock)
293 spin_unlock_irq(&uhci->lock); 293 spin_unlock_irq(&uhci->lock);
294 msleep(20); 294 msleep(20);
295 spin_lock_irq(&uhci->lock); 295 spin_lock_irq(&uhci->lock);
296 if (uhci->hc_inaccessible) /* Died */ 296 if (uhci->dead)
297 return; 297 return;
298 298
299 /* End Global Resume and wait for EOP to be sent */ 299 /* End Global Resume and wait for EOP to be sent */
@@ -345,7 +345,7 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs)
345 errbuf, ERRBUF_LEN); 345 errbuf, ERRBUF_LEN);
346 lprintk(errbuf); 346 lprintk(errbuf);
347 } 347 }
348 hc_died(uhci); 348 uhci_hc_died(uhci);
349 349
350 /* Force a callback in case there are 350 /* Force a callback in case there are
351 * pending unlinks */ 351 * pending unlinks */
@@ -368,12 +368,21 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs)
368 368
369/* 369/*
370 * Store the current frame number in uhci->frame_number if the controller 370 * Store the current frame number in uhci->frame_number if the controller
371 * is runnning 371 * is runnning. Expand from 11 bits (of which we use only 10) to a
372 * full-sized integer.
373 *
374 * Like many other parts of the driver, this code relies on being polled
375 * more than once per second as long as the controller is running.
372 */ 376 */
373static void uhci_get_current_frame_number(struct uhci_hcd *uhci) 377static void uhci_get_current_frame_number(struct uhci_hcd *uhci)
374{ 378{
375 if (!uhci->is_stopped) 379 if (!uhci->is_stopped) {
376 uhci->frame_number = inw(uhci->io_addr + USBFRNUM); 380 unsigned delta;
381
382 delta = (inw(uhci->io_addr + USBFRNUM) - uhci->frame_number) &
383 (UHCI_NUMFRAMES - 1);
384 uhci->frame_number += delta;
385 }
377} 386}
378 387
379/* 388/*
@@ -407,7 +416,7 @@ static void release_uhci(struct uhci_hcd *uhci)
407 uhci->frame, uhci->frame_dma_handle); 416 uhci->frame, uhci->frame_dma_handle);
408} 417}
409 418
410static int uhci_reset(struct usb_hcd *hcd) 419static int uhci_init(struct usb_hcd *hcd)
411{ 420{
412 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 421 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
413 unsigned io_size = (unsigned) hcd->rsrc_len; 422 unsigned io_size = (unsigned) hcd->rsrc_len;
@@ -459,7 +468,7 @@ static void uhci_shutdown(struct pci_dev *pdev)
459{ 468{
460 struct usb_hcd *hcd = (struct usb_hcd *) pci_get_drvdata(pdev); 469 struct usb_hcd *hcd = (struct usb_hcd *) pci_get_drvdata(pdev);
461 470
462 hc_died(hcd_to_uhci(hcd)); 471 uhci_hc_died(hcd_to_uhci(hcd));
463} 472}
464 473
465/* 474/*
@@ -487,14 +496,10 @@ static int uhci_start(struct usb_hcd *hcd)
487 496
488 hcd->uses_new_polling = 1; 497 hcd->uses_new_polling = 1;
489 498
490 uhci->fsbr = 0;
491 uhci->fsbrtimeout = 0;
492
493 spin_lock_init(&uhci->lock); 499 spin_lock_init(&uhci->lock);
494 500 setup_timer(&uhci->fsbr_timer, uhci_fsbr_timeout,
495 INIT_LIST_HEAD(&uhci->td_remove_list); 501 (unsigned long) uhci);
496 INIT_LIST_HEAD(&uhci->idle_qh_list); 502 INIT_LIST_HEAD(&uhci->idle_qh_list);
497
498 init_waitqueue_head(&uhci->waitqh); 503 init_waitqueue_head(&uhci->waitqh);
499 504
500 if (DEBUG_CONFIGURED) { 505 if (DEBUG_CONFIGURED) {
@@ -665,11 +670,12 @@ static void uhci_stop(struct usb_hcd *hcd)
665 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 670 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
666 671
667 spin_lock_irq(&uhci->lock); 672 spin_lock_irq(&uhci->lock);
668 if (!uhci->hc_inaccessible) 673 if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && !uhci->dead)
669 hc_died(uhci); 674 uhci_hc_died(uhci);
670 uhci_scan_schedule(uhci, NULL); 675 uhci_scan_schedule(uhci, NULL);
671 spin_unlock_irq(&uhci->lock); 676 spin_unlock_irq(&uhci->lock);
672 677
678 del_timer_sync(&uhci->fsbr_timer);
673 release_uhci(uhci); 679 release_uhci(uhci);
674} 680}
675 681
@@ -677,12 +683,15 @@ static void uhci_stop(struct usb_hcd *hcd)
677static int uhci_rh_suspend(struct usb_hcd *hcd) 683static int uhci_rh_suspend(struct usb_hcd *hcd)
678{ 684{
679 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 685 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
686 int rc = 0;
680 687
681 spin_lock_irq(&uhci->lock); 688 spin_lock_irq(&uhci->lock);
682 if (!uhci->hc_inaccessible) /* Not dead */ 689 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
690 rc = -ESHUTDOWN;
691 else if (!uhci->dead)
683 suspend_rh(uhci, UHCI_RH_SUSPENDED); 692 suspend_rh(uhci, UHCI_RH_SUSPENDED);
684 spin_unlock_irq(&uhci->lock); 693 spin_unlock_irq(&uhci->lock);
685 return 0; 694 return rc;
686} 695}
687 696
688static int uhci_rh_resume(struct usb_hcd *hcd) 697static int uhci_rh_resume(struct usb_hcd *hcd)
@@ -691,13 +700,10 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
691 int rc = 0; 700 int rc = 0;
692 701
693 spin_lock_irq(&uhci->lock); 702 spin_lock_irq(&uhci->lock);
694 if (uhci->hc_inaccessible) { 703 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
695 if (uhci->rh_state == UHCI_RH_SUSPENDED) { 704 dev_warn(&hcd->self.root_hub->dev, "HC isn't running!\n");
696 dev_warn(uhci_dev(uhci), "HC isn't running!\n"); 705 rc = -ESHUTDOWN;
697 rc = -ENODEV; 706 } else if (!uhci->dead)
698 }
699 /* Otherwise the HC is dead */
700 } else
701 wakeup_rh(uhci); 707 wakeup_rh(uhci);
702 spin_unlock_irq(&uhci->lock); 708 spin_unlock_irq(&uhci->lock);
703 return rc; 709 return rc;
@@ -711,8 +717,8 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message)
711 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 717 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__);
712 718
713 spin_lock_irq(&uhci->lock); 719 spin_lock_irq(&uhci->lock);
714 if (uhci->hc_inaccessible) /* Dead or already suspended */ 720 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead)
715 goto done; 721 goto done_okay; /* Already suspended or dead */
716 722
717 if (uhci->rh_state > UHCI_RH_SUSPENDED) { 723 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
718 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n"); 724 dev_warn(uhci_dev(uhci), "Root hub isn't suspended!\n");
@@ -725,12 +731,12 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message)
725 */ 731 */
726 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); 732 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0);
727 mb(); 733 mb();
728 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
729 uhci->hc_inaccessible = 1;
730 hcd->poll_rh = 0; 734 hcd->poll_rh = 0;
731 735
732 /* FIXME: Enable non-PME# remote wakeup? */ 736 /* FIXME: Enable non-PME# remote wakeup? */
733 737
738done_okay:
739 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
734done: 740done:
735 spin_unlock_irq(&uhci->lock); 741 spin_unlock_irq(&uhci->lock);
736 return rc; 742 return rc;
@@ -743,24 +749,22 @@ static int uhci_resume(struct usb_hcd *hcd)
743 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__); 749 dev_dbg(uhci_dev(uhci), "%s\n", __FUNCTION__);
744 750
745 /* Since we aren't in D3 any more, it's safe to set this flag 751 /* Since we aren't in D3 any more, it's safe to set this flag
746 * even if the controller was dead. It might not even be dead 752 * even if the controller was dead.
747 * any more, if the firmware or quirks code has reset it.
748 */ 753 */
749 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 754 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
750 mb(); 755 mb();
751 756
752 if (uhci->rh_state == UHCI_RH_RESET) /* Dead */
753 return 0;
754 spin_lock_irq(&uhci->lock); 757 spin_lock_irq(&uhci->lock);
755 758
756 /* FIXME: Disable non-PME# remote wakeup? */ 759 /* FIXME: Disable non-PME# remote wakeup? */
757 760
758 uhci->hc_inaccessible = 0; 761 /* The firmware or a boot kernel may have changed the controller
759 762 * settings during a system wakeup. Check it and reconfigure
760 /* The BIOS may have changed the controller settings during a 763 * to avoid problems.
761 * system wakeup. Check it and reconfigure to avoid problems.
762 */ 764 */
763 check_and_reset_hc(uhci); 765 check_and_reset_hc(uhci);
766
767 /* If the controller was dead before, it's back alive now */
764 configure_hc(uhci); 768 configure_hc(uhci);
765 769
766 if (uhci->rh_state == UHCI_RH_RESET) { 770 if (uhci->rh_state == UHCI_RH_RESET) {
@@ -810,18 +814,15 @@ done:
810static int uhci_hcd_get_frame_number(struct usb_hcd *hcd) 814static int uhci_hcd_get_frame_number(struct usb_hcd *hcd)
811{ 815{
812 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 816 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
813 unsigned long flags; 817 unsigned frame_number;
814 int is_stopped; 818 unsigned delta;
815 int frame_number;
816 819
817 /* Minimize latency by avoiding the spinlock */ 820 /* Minimize latency by avoiding the spinlock */
818 local_irq_save(flags); 821 frame_number = uhci->frame_number;
819 is_stopped = uhci->is_stopped; 822 barrier();
820 smp_rmb(); 823 delta = (inw(uhci->io_addr + USBFRNUM) - frame_number) &
821 frame_number = (is_stopped ? uhci->frame_number : 824 (UHCI_NUMFRAMES - 1);
822 inw(uhci->io_addr + USBFRNUM)); 825 return frame_number + delta;
823 local_irq_restore(flags);
824 return frame_number;
825} 826}
826 827
827static const char hcd_name[] = "uhci_hcd"; 828static const char hcd_name[] = "uhci_hcd";
@@ -836,7 +837,7 @@ static const struct hc_driver uhci_driver = {
836 .flags = HCD_USB11, 837 .flags = HCD_USB11,
837 838
838 /* Basic lifecycle operations */ 839 /* Basic lifecycle operations */
839 .reset = uhci_reset, 840 .reset = uhci_init,
840 .start = uhci_start, 841 .start = uhci_start,
841#ifdef CONFIG_PM 842#ifdef CONFIG_PM
842 .suspend = uhci_suspend, 843 .suspend = uhci_suspend,