aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/Kconfig8
-rw-r--r--drivers/usb/host/Makefile3
-rw-r--r--drivers/usb/host/ehci-exynos.c2
-rw-r--r--drivers/usb/host/ehci-hub.c2
-rw-r--r--drivers/usb/host/ehci-mem.c2
-rw-r--r--drivers/usb/host/ehci-msm.c2
-rw-r--r--drivers/usb/host/ehci-pci.c25
-rw-r--r--drivers/usb/host/ehci-spear.c2
-rw-r--r--drivers/usb/host/ehci-tegra.c67
-rw-r--r--drivers/usb/host/fhci-dbg.c8
-rw-r--r--drivers/usb/host/fotg210-hcd.c48
-rw-r--r--drivers/usb/host/max3421-hcd.c48
-rw-r--r--drivers/usb/host/ohci-dbg.c9
-rw-r--r--drivers/usb/host/ohci-exynos.c2
-rw-r--r--drivers/usb/host/ohci-hcd.c381
-rw-r--r--drivers/usb/host/ohci-hub.c11
-rw-r--r--drivers/usb/host/ohci-mem.c1
-rw-r--r--drivers/usb/host/ohci-q.c262
-rw-r--r--drivers/usb/host/ohci-spear.c2
-rw-r--r--drivers/usb/host/ohci.h23
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c48
-rw-r--r--drivers/usb/host/uhci-grlib.c31
-rw-r--r--drivers/usb/host/uhci-hcd.c2
-rw-r--r--drivers/usb/host/uhci-platform.c22
-rw-r--r--drivers/usb/host/xhci-pci.c17
-rw-r--r--drivers/usb/host/xhci-plat.c52
-rw-r--r--drivers/usb/host/xhci-rcar.c148
-rw-r--r--drivers/usb/host/xhci-rcar.h27
-rw-r--r--drivers/usb/host/xhci-ring.c108
-rw-r--r--drivers/usb/host/xhci.c163
-rw-r--r--drivers/usb/host/xhci.h2
31 files changed, 927 insertions, 601 deletions
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 03314f861bee..82800a775501 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -37,6 +37,14 @@ config USB_XHCI_MVEBU
37 Say 'Y' to enable the support for the xHCI host controller 37 Say 'Y' to enable the support for the xHCI host controller
38 found in Marvell Armada 375/38x ARM SOCs. 38 found in Marvell Armada 375/38x ARM SOCs.
39 39
40config USB_XHCI_RCAR
41 tristate "xHCI support for Renesas R-Car SoCs"
42 select USB_XHCI_PLATFORM
43 depends on ARCH_SHMOBILE || COMPILE_TEST
44 ---help---
45 Say 'Y' to enable the support for the xHCI host controller
46 found in Renesas R-Car ARM SoCs.
47
40endif # USB_XHCI_HCD 48endif # USB_XHCI_HCD
41 49
42config USB_EHCI_HCD 50config USB_EHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index af89a903d97e..144c038ef70f 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -22,6 +22,9 @@ ifneq ($(CONFIG_USB_XHCI_PLATFORM), )
22ifneq ($(CONFIG_USB_XHCI_MVEBU), ) 22ifneq ($(CONFIG_USB_XHCI_MVEBU), )
23 xhci-hcd-y += xhci-mvebu.o 23 xhci-hcd-y += xhci-mvebu.o
24endif 24endif
25ifneq ($(CONFIG_USB_XHCI_RCAR), )
26 xhci-hcd-y += xhci-rcar.o
27endif
25endif 28endif
26 29
27obj-$(CONFIG_USB_WHCI_HCD) += whci/ 30obj-$(CONFIG_USB_WHCI_HCD) += whci/
diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c
index d1c76216350f..cda0a2f5c467 100644
--- a/drivers/usb/host/ehci-exynos.c
+++ b/drivers/usb/host/ehci-exynos.c
@@ -88,7 +88,7 @@ static int exynos_ehci_get_phy(struct device *dev,
88 return -EINVAL; 88 return -EINVAL;
89 } 89 }
90 90
91 phy = devm_of_phy_get(dev, child, 0); 91 phy = devm_of_phy_get(dev, child, NULL);
92 of_node_put(child); 92 of_node_put(child);
93 if (IS_ERR(phy)) { 93 if (IS_ERR(phy)) {
94 ret = PTR_ERR(phy); 94 ret = PTR_ERR(phy);
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index cc305c71ac3d..6130b7574908 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -1230,7 +1230,7 @@ int ehci_hub_control(
1230 if (selector == EHSET_TEST_SINGLE_STEP_SET_FEATURE) { 1230 if (selector == EHSET_TEST_SINGLE_STEP_SET_FEATURE) {
1231 spin_unlock_irqrestore(&ehci->lock, flags); 1231 spin_unlock_irqrestore(&ehci->lock, flags);
1232 retval = ehset_single_step_set_feature(hcd, 1232 retval = ehset_single_step_set_feature(hcd,
1233 wIndex); 1233 wIndex + 1);
1234 spin_lock_irqsave(&ehci->lock, flags); 1234 spin_lock_irqsave(&ehci->lock, flags);
1235 break; 1235 break;
1236 } 1236 }
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index c0fb6a8ae6a3..b6205fac3567 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -209,7 +209,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
209 ehci->periodic = (__le32 *) 209 ehci->periodic = (__le32 *)
210 dma_alloc_coherent (ehci_to_hcd(ehci)->self.controller, 210 dma_alloc_coherent (ehci_to_hcd(ehci)->self.controller,
211 ehci->periodic_size * sizeof(__le32), 211 ehci->periodic_size * sizeof(__le32),
212 &ehci->periodic_dma, 0); 212 &ehci->periodic_dma, flags);
213 if (ehci->periodic == NULL) { 213 if (ehci->periodic == NULL) {
214 goto fail; 214 goto fail;
215 } 215 }
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 982c09bebe0f..934b39d5e44a 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -190,7 +190,7 @@ static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
190 .resume = ehci_msm_pm_resume, 190 .resume = ehci_msm_pm_resume,
191}; 191};
192 192
193static struct of_device_id msm_ehci_dt_match[] = { 193static const struct of_device_id msm_ehci_dt_match[] = {
194 { .compatible = "qcom,ehci-host", }, 194 { .compatible = "qcom,ehci-host", },
195 {} 195 {}
196}; 196};
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 3e86bf4371b3..ca7b964124af 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -35,6 +35,21 @@ static const char hcd_name[] = "ehci-pci";
35#define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70 35#define PCI_DEVICE_ID_INTEL_CE4100_USB 0x2e70
36 36
37/*-------------------------------------------------------------------------*/ 37/*-------------------------------------------------------------------------*/
38#define PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC 0x0939
39static inline bool is_intel_quark_x1000(struct pci_dev *pdev)
40{
41 return pdev->vendor == PCI_VENDOR_ID_INTEL &&
42 pdev->device == PCI_DEVICE_ID_INTEL_QUARK_X1000_SOC;
43}
44
45/*
46 * 0x84 is the offset of in/out threshold register,
47 * and it is the same offset as the register of 'hostpc'.
48 */
49#define intel_quark_x1000_insnreg01 hostpc
50
51/* Maximum usable threshold value is 0x7f dwords for both IN and OUT */
52#define INTEL_QUARK_X1000_EHCI_MAX_THRESHOLD 0x007f007f
38 53
39/* called after powerup, by probe or system-pm "wakeup" */ 54/* called after powerup, by probe or system-pm "wakeup" */
40static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) 55static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
@@ -50,6 +65,16 @@ static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
50 if (!retval) 65 if (!retval)
51 ehci_dbg(ehci, "MWI active\n"); 66 ehci_dbg(ehci, "MWI active\n");
52 67
68 /* Reset the threshold limit */
69 if (is_intel_quark_x1000(pdev)) {
70 /*
71 * For the Intel QUARK X1000, raise the I/O threshold to the
72 * maximum usable value in order to improve performance.
73 */
74 ehci_writel(ehci, INTEL_QUARK_X1000_EHCI_MAX_THRESHOLD,
75 ehci->regs->intel_quark_x1000_insnreg01);
76 }
77
53 return 0; 78 return 0;
54} 79}
55 80
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
index 1d59958ad0ce..1355ff0946b9 100644
--- a/drivers/usb/host/ehci-spear.c
+++ b/drivers/usb/host/ehci-spear.c
@@ -150,7 +150,7 @@ static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
150 return 0; 150 return 0;
151} 151}
152 152
153static struct of_device_id spear_ehci_id_table[] = { 153static const struct of_device_id spear_ehci_id_table[] = {
154 { .compatible = "st,spear600-ehci", }, 154 { .compatible = "st,spear600-ehci", },
155 { }, 155 { },
156}; 156};
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 6fdcb8ad2296..7aafb05e7a40 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -46,6 +46,7 @@
46#define DRV_NAME "tegra-ehci" 46#define DRV_NAME "tegra-ehci"
47 47
48static struct hc_driver __read_mostly tegra_ehci_hc_driver; 48static struct hc_driver __read_mostly tegra_ehci_hc_driver;
49static bool usb1_reset_attempted;
49 50
50struct tegra_ehci_soc_config { 51struct tegra_ehci_soc_config {
51 bool has_hostpc; 52 bool has_hostpc;
@@ -60,6 +61,61 @@ struct tegra_ehci_hcd {
60 enum tegra_usb_phy_port_speed port_speed; 61 enum tegra_usb_phy_port_speed port_speed;
61}; 62};
62 63
64/*
65 * The 1st USB controller contains some UTMI pad registers that are global for
66 * all the controllers on the chip. Those registers are also cleared when
67 * reset is asserted to the 1st controller. This means that the 1st controller
68 * can only be reset when no other controlled has finished probing. So we'll
69 * reset the 1st controller before doing any other setup on any of the
70 * controllers, and then never again.
71 *
72 * Since this is a PHY issue, the Tegra PHY driver should probably be doing
73 * the resetting of the USB controllers. But to keep compatibility with old
74 * device trees that don't have reset phandles in the PHYs, do it here.
75 * Those old DTs will be vulnerable to total USB breakage if the 1st EHCI
76 * device isn't the first one to finish probing, so warn them.
77 */
78static int tegra_reset_usb_controller(struct platform_device *pdev)
79{
80 struct device_node *phy_np;
81 struct usb_hcd *hcd = platform_get_drvdata(pdev);
82 struct tegra_ehci_hcd *tegra =
83 (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv;
84
85 phy_np = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0);
86 if (!phy_np)
87 return -ENOENT;
88
89 if (!usb1_reset_attempted) {
90 struct reset_control *usb1_reset;
91
92 usb1_reset = of_reset_control_get(phy_np, "usb");
93 if (IS_ERR(usb1_reset)) {
94 dev_warn(&pdev->dev,
95 "can't get utmi-pads reset from the PHY\n");
96 dev_warn(&pdev->dev,
97 "continuing, but please update your DT\n");
98 } else {
99 reset_control_assert(usb1_reset);
100 udelay(1);
101 reset_control_deassert(usb1_reset);
102 }
103
104 reset_control_put(usb1_reset);
105 usb1_reset_attempted = true;
106 }
107
108 if (!of_property_read_bool(phy_np, "nvidia,has-utmi-pad-registers")) {
109 reset_control_assert(tegra->rst);
110 udelay(1);
111 reset_control_deassert(tegra->rst);
112 }
113
114 of_node_put(phy_np);
115
116 return 0;
117}
118
63static int tegra_ehci_internal_port_reset( 119static int tegra_ehci_internal_port_reset(
64 struct ehci_hcd *ehci, 120 struct ehci_hcd *ehci,
65 u32 __iomem *portsc_reg 121 u32 __iomem *portsc_reg
@@ -326,7 +382,7 @@ static const struct tegra_ehci_soc_config tegra20_soc_config = {
326 .has_hostpc = false, 382 .has_hostpc = false,
327}; 383};
328 384
329static struct of_device_id tegra_ehci_of_match[] = { 385static const struct of_device_id tegra_ehci_of_match[] = {
330 { .compatible = "nvidia,tegra30-ehci", .data = &tegra30_soc_config }, 386 { .compatible = "nvidia,tegra30-ehci", .data = &tegra30_soc_config },
331 { .compatible = "nvidia,tegra20-ehci", .data = &tegra20_soc_config }, 387 { .compatible = "nvidia,tegra20-ehci", .data = &tegra20_soc_config },
332 { }, 388 { },
@@ -389,9 +445,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
389 if (err) 445 if (err)
390 goto cleanup_hcd_create; 446 goto cleanup_hcd_create;
391 447
392 reset_control_assert(tegra->rst); 448 err = tegra_reset_usb_controller(pdev);
393 udelay(1); 449 if (err)
394 reset_control_deassert(tegra->rst); 450 goto cleanup_clk_en;
395 451
396 u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0); 452 u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0);
397 if (IS_ERR(u_phy)) { 453 if (IS_ERR(u_phy)) {
@@ -479,10 +535,11 @@ static int tegra_ehci_remove(struct platform_device *pdev)
479 535
480 usb_phy_shutdown(hcd->phy); 536 usb_phy_shutdown(hcd->phy);
481 usb_remove_hcd(hcd); 537 usb_remove_hcd(hcd);
482 usb_put_hcd(hcd);
483 538
484 clk_disable_unprepare(tegra->clk); 539 clk_disable_unprepare(tegra->clk);
485 540
541 usb_put_hcd(hcd);
542
486 return 0; 543 return 0;
487} 544}
488 545
diff --git a/drivers/usb/host/fhci-dbg.c b/drivers/usb/host/fhci-dbg.c
index f238cb37305c..b58e7a60913a 100644
--- a/drivers/usb/host/fhci-dbg.c
+++ b/drivers/usb/host/fhci-dbg.c
@@ -129,11 +129,7 @@ void fhci_dfs_destroy(struct fhci_hcd *fhci)
129 if (!fhci->dfs_root) 129 if (!fhci->dfs_root)
130 return; 130 return;
131 131
132 if (fhci->dfs_irq_stat) 132 debugfs_remove(fhci->dfs_irq_stat);
133 debugfs_remove(fhci->dfs_irq_stat); 133 debugfs_remove(fhci->dfs_regs);
134
135 if (fhci->dfs_regs)
136 debugfs_remove(fhci->dfs_regs);
137
138 debugfs_remove(fhci->dfs_root); 134 debugfs_remove(fhci->dfs_root);
139} 135}
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
index 98a89d16cc3e..adcd2050dced 100644
--- a/drivers/usb/host/fotg210-hcd.c
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -5838,41 +5838,17 @@ static int fotg210_hcd_probe(struct platform_device *pdev)
5838 goto fail_create_hcd; 5838 goto fail_create_hcd;
5839 } 5839 }
5840 5840
5841 hcd->has_tt = 1;
5842
5841 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 5843 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
5842 if (!res) { 5844 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
5843 dev_err(dev, 5845 if (IS_ERR(hcd->regs)) {
5844 "Found HC with no register addr. Check %s setup!\n", 5846 retval = PTR_ERR(hcd->regs);
5845 dev_name(dev)); 5847 goto failed;
5846 retval = -ENODEV;
5847 goto fail_request_resource;
5848 } 5848 }
5849 5849
5850 hcd->rsrc_start = res->start; 5850 hcd->rsrc_start = res->start;
5851 hcd->rsrc_len = resource_size(res); 5851 hcd->rsrc_len = resource_size(res);
5852 hcd->has_tt = 1;
5853
5854 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
5855 fotg210_fotg210_hc_driver.description)) {
5856 dev_dbg(dev, "controller already in use\n");
5857 retval = -EBUSY;
5858 goto fail_request_resource;
5859 }
5860
5861 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
5862 if (!res) {
5863 dev_err(dev,
5864 "Found HC with no register addr. Check %s setup!\n",
5865 dev_name(dev));
5866 retval = -ENODEV;
5867 goto fail_request_resource;
5868 }
5869
5870 hcd->regs = ioremap_nocache(res->start, resource_size(res));
5871 if (hcd->regs == NULL) {
5872 dev_dbg(dev, "error mapping memory\n");
5873 retval = -EFAULT;
5874 goto fail_ioremap;
5875 }
5876 5852
5877 fotg210 = hcd_to_fotg210(hcd); 5853 fotg210 = hcd_to_fotg210(hcd);
5878 5854
@@ -5880,24 +5856,20 @@ static int fotg210_hcd_probe(struct platform_device *pdev)
5880 5856
5881 retval = fotg210_setup(hcd); 5857 retval = fotg210_setup(hcd);
5882 if (retval) 5858 if (retval)
5883 goto fail_add_hcd; 5859 goto failed;
5884 5860
5885 fotg210_init(fotg210); 5861 fotg210_init(fotg210);
5886 5862
5887 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 5863 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
5888 if (retval) { 5864 if (retval) {
5889 dev_err(dev, "failed to add hcd with err %d\n", retval); 5865 dev_err(dev, "failed to add hcd with err %d\n", retval);
5890 goto fail_add_hcd; 5866 goto failed;
5891 } 5867 }
5892 device_wakeup_enable(hcd->self.controller); 5868 device_wakeup_enable(hcd->self.controller);
5893 5869
5894 return retval; 5870 return retval;
5895 5871
5896fail_add_hcd: 5872failed:
5897 iounmap(hcd->regs);
5898fail_ioremap:
5899 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
5900fail_request_resource:
5901 usb_put_hcd(hcd); 5873 usb_put_hcd(hcd);
5902fail_create_hcd: 5874fail_create_hcd:
5903 dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval); 5875 dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval);
@@ -5918,8 +5890,6 @@ static int fotg210_hcd_remove(struct platform_device *pdev)
5918 return 0; 5890 return 0;
5919 5891
5920 usb_remove_hcd(hcd); 5892 usb_remove_hcd(hcd);
5921 iounmap(hcd->regs);
5922 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
5923 usb_put_hcd(hcd); 5893 usb_put_hcd(hcd);
5924 5894
5925 return 0; 5895 return 0;
diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
index 858efcfda50b..6234c75da33f 100644
--- a/drivers/usb/host/max3421-hcd.c
+++ b/drivers/usb/host/max3421-hcd.c
@@ -102,6 +102,15 @@ enum scheduling_pass {
102 SCHED_PASS_DONE 102 SCHED_PASS_DONE
103}; 103};
104 104
105/* Bit numbers for max3421_hcd->todo: */
106enum {
107 ENABLE_IRQ = 0,
108 RESET_HCD,
109 RESET_PORT,
110 CHECK_UNLINK,
111 IOPIN_UPDATE
112};
113
105struct max3421_dma_buf { 114struct max3421_dma_buf {
106 u8 data[2]; 115 u8 data[2];
107}; 116};
@@ -146,11 +155,7 @@ struct max3421_hcd {
146 u8 hien; 155 u8 hien;
147 u8 mode; 156 u8 mode;
148 u8 iopins[2]; 157 u8 iopins[2];
149 unsigned int do_enable_irq:1; 158 unsigned long todo;
150 unsigned int do_reset_hcd:1;
151 unsigned int do_reset_port:1;
152 unsigned int do_check_unlink:1;
153 unsigned int do_iopin_update:1;
154#ifdef DEBUG 159#ifdef DEBUG
155 unsigned long err_stat[16]; 160 unsigned long err_stat[16];
156#endif 161#endif
@@ -1165,10 +1170,8 @@ max3421_irq_handler(int irq, void *dev_id)
1165 if (max3421_hcd->spi_thread && 1170 if (max3421_hcd->spi_thread &&
1166 max3421_hcd->spi_thread->state != TASK_RUNNING) 1171 max3421_hcd->spi_thread->state != TASK_RUNNING)
1167 wake_up_process(max3421_hcd->spi_thread); 1172 wake_up_process(max3421_hcd->spi_thread);
1168 if (!max3421_hcd->do_enable_irq) { 1173 if (!test_and_set_bit(ENABLE_IRQ, &max3421_hcd->todo))
1169 max3421_hcd->do_enable_irq = 1;
1170 disable_irq_nosync(spi->irq); 1174 disable_irq_nosync(spi->irq);
1171 }
1172 return IRQ_HANDLED; 1175 return IRQ_HANDLED;
1173} 1176}
1174 1177
@@ -1423,10 +1426,8 @@ max3421_spi_thread(void *dev_id)
1423 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); 1426 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien);
1424 1427
1425 set_current_state(TASK_INTERRUPTIBLE); 1428 set_current_state(TASK_INTERRUPTIBLE);
1426 if (max3421_hcd->do_enable_irq) { 1429 if (test_and_clear_bit(ENABLE_IRQ, &max3421_hcd->todo))
1427 max3421_hcd->do_enable_irq = 0;
1428 enable_irq(spi->irq); 1430 enable_irq(spi->irq);
1429 }
1430 schedule(); 1431 schedule();
1431 __set_current_state(TASK_RUNNING); 1432 __set_current_state(TASK_RUNNING);
1432 } 1433 }
@@ -1440,23 +1441,18 @@ max3421_spi_thread(void *dev_id)
1440 else if (!max3421_hcd->curr_urb) 1441 else if (!max3421_hcd->curr_urb)
1441 i_worked |= max3421_select_and_start_urb(hcd); 1442 i_worked |= max3421_select_and_start_urb(hcd);
1442 1443
1443 if (max3421_hcd->do_reset_hcd) { 1444 if (test_and_clear_bit(RESET_HCD, &max3421_hcd->todo))
1444 /* reset the HCD: */ 1445 /* reset the HCD: */
1445 max3421_hcd->do_reset_hcd = 0;
1446 i_worked |= max3421_reset_hcd(hcd); 1446 i_worked |= max3421_reset_hcd(hcd);
1447 } 1447 if (test_and_clear_bit(RESET_PORT, &max3421_hcd->todo)) {
1448 if (max3421_hcd->do_reset_port) {
1449 /* perform a USB bus reset: */ 1448 /* perform a USB bus reset: */
1450 max3421_hcd->do_reset_port = 0;
1451 spi_wr8(hcd, MAX3421_REG_HCTL, 1449 spi_wr8(hcd, MAX3421_REG_HCTL,
1452 BIT(MAX3421_HCTL_BUSRST_BIT)); 1450 BIT(MAX3421_HCTL_BUSRST_BIT));
1453 i_worked = 1; 1451 i_worked = 1;
1454 } 1452 }
1455 if (max3421_hcd->do_check_unlink) { 1453 if (test_and_clear_bit(CHECK_UNLINK, &max3421_hcd->todo))
1456 max3421_hcd->do_check_unlink = 0;
1457 i_worked |= max3421_check_unlink(hcd); 1454 i_worked |= max3421_check_unlink(hcd);
1458 } 1455 if (test_and_clear_bit(IOPIN_UPDATE, &max3421_hcd->todo)) {
1459 if (max3421_hcd->do_iopin_update) {
1460 /* 1456 /*
1461 * IOPINS1/IOPINS2 do not auto-increment, so we can't 1457 * IOPINS1/IOPINS2 do not auto-increment, so we can't
1462 * use spi_wr_buf(). 1458 * use spi_wr_buf().
@@ -1469,7 +1465,6 @@ max3421_spi_thread(void *dev_id)
1469 spi_wr8(hcd, MAX3421_REG_IOPINS1 + i, val); 1465 spi_wr8(hcd, MAX3421_REG_IOPINS1 + i, val);
1470 max3421_hcd->iopins[i] = val; 1466 max3421_hcd->iopins[i] = val;
1471 } 1467 }
1472 max3421_hcd->do_iopin_update = 0;
1473 i_worked = 1; 1468 i_worked = 1;
1474 } 1469 }
1475 } 1470 }
@@ -1485,7 +1480,8 @@ max3421_reset_port(struct usb_hcd *hcd)
1485 1480
1486 max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE | 1481 max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE |
1487 USB_PORT_STAT_LOW_SPEED); 1482 USB_PORT_STAT_LOW_SPEED);
1488 max3421_hcd->do_reset_port = 1; 1483 max3421_hcd->port_status |= USB_PORT_STAT_RESET;
1484 set_bit(RESET_PORT, &max3421_hcd->todo);
1489 wake_up_process(max3421_hcd->spi_thread); 1485 wake_up_process(max3421_hcd->spi_thread);
1490 return 0; 1486 return 0;
1491} 1487}
@@ -1498,7 +1494,7 @@ max3421_reset(struct usb_hcd *hcd)
1498 hcd->self.sg_tablesize = 0; 1494 hcd->self.sg_tablesize = 0;
1499 hcd->speed = HCD_USB2; 1495 hcd->speed = HCD_USB2;
1500 hcd->self.root_hub->speed = USB_SPEED_FULL; 1496 hcd->self.root_hub->speed = USB_SPEED_FULL;
1501 max3421_hcd->do_reset_hcd = 1; 1497 set_bit(RESET_HCD, &max3421_hcd->todo);
1502 wake_up_process(max3421_hcd->spi_thread); 1498 wake_up_process(max3421_hcd->spi_thread);
1503 return 0; 1499 return 0;
1504} 1500}
@@ -1551,7 +1547,7 @@ max3421_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
1551 max3421_ep = urb->ep->hcpriv; 1547 max3421_ep = urb->ep->hcpriv;
1552 if (!max3421_ep) { 1548 if (!max3421_ep) {
1553 /* gets freed in max3421_endpoint_disable: */ 1549 /* gets freed in max3421_endpoint_disable: */
1554 max3421_ep = kzalloc(sizeof(struct max3421_ep), mem_flags); 1550 max3421_ep = kzalloc(sizeof(struct max3421_ep), GFP_ATOMIC);
1555 if (!max3421_ep) { 1551 if (!max3421_ep) {
1556 retval = -ENOMEM; 1552 retval = -ENOMEM;
1557 goto out; 1553 goto out;
@@ -1590,7 +1586,7 @@ max3421_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1590 */ 1586 */
1591 retval = usb_hcd_check_unlink_urb(hcd, urb, status); 1587 retval = usb_hcd_check_unlink_urb(hcd, urb, status);
1592 if (retval == 0) { 1588 if (retval == 0) {
1593 max3421_hcd->do_check_unlink = 1; 1589 set_bit(CHECK_UNLINK, &max3421_hcd->todo);
1594 wake_up_process(max3421_hcd->spi_thread); 1590 wake_up_process(max3421_hcd->spi_thread);
1595 } 1591 }
1596 spin_unlock_irqrestore(&max3421_hcd->lock, flags); 1592 spin_unlock_irqrestore(&max3421_hcd->lock, flags);
@@ -1690,7 +1686,7 @@ max3421_gpout_set_value(struct usb_hcd *hcd, u8 pin_number, u8 value)
1690 max3421_hcd->iopins[idx] |= mask; 1686 max3421_hcd->iopins[idx] |= mask;
1691 else 1687 else
1692 max3421_hcd->iopins[idx] &= ~mask; 1688 max3421_hcd->iopins[idx] &= ~mask;
1693 max3421_hcd->do_iopin_update = 1; 1689 set_bit(IOPIN_UPDATE, &max3421_hcd->todo);
1694 wake_up_process(max3421_hcd->spi_thread); 1690 wake_up_process(max3421_hcd->spi_thread);
1695} 1691}
1696 1692
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 45032e933e18..04f2186939d2 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -236,7 +236,7 @@ ohci_dump_roothub (
236 } 236 }
237} 237}
238 238
239static void ohci_dump (struct ohci_hcd *controller, int verbose) 239static void ohci_dump(struct ohci_hcd *controller)
240{ 240{
241 ohci_dbg (controller, "OHCI controller state\n"); 241 ohci_dbg (controller, "OHCI controller state\n");
242 242
@@ -464,15 +464,16 @@ show_list (struct ohci_hcd *ohci, char *buf, size_t count, struct ed *ed)
464static ssize_t fill_async_buffer(struct debug_buffer *buf) 464static ssize_t fill_async_buffer(struct debug_buffer *buf)
465{ 465{
466 struct ohci_hcd *ohci; 466 struct ohci_hcd *ohci;
467 size_t temp; 467 size_t temp, size;
468 unsigned long flags; 468 unsigned long flags;
469 469
470 ohci = buf->ohci; 470 ohci = buf->ohci;
471 size = PAGE_SIZE;
471 472
472 /* display control and bulk lists together, for simplicity */ 473 /* display control and bulk lists together, for simplicity */
473 spin_lock_irqsave (&ohci->lock, flags); 474 spin_lock_irqsave (&ohci->lock, flags);
474 temp = show_list(ohci, buf->page, buf->count, ohci->ed_controltail); 475 temp = show_list(ohci, buf->page, size, ohci->ed_controltail);
475 temp += show_list(ohci, buf->page + temp, buf->count - temp, 476 temp += show_list(ohci, buf->page + temp, size - temp,
476 ohci->ed_bulktail); 477 ohci->ed_bulktail);
477 spin_unlock_irqrestore (&ohci->lock, flags); 478 spin_unlock_irqrestore (&ohci->lock, flags);
478 479
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index 060a6a414750..a72ab8fe8cd3 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -87,7 +87,7 @@ static int exynos_ohci_get_phy(struct device *dev,
87 return -EINVAL; 87 return -EINVAL;
88 } 88 }
89 89
90 phy = devm_of_phy_get(dev, child, 0); 90 phy = devm_of_phy_get(dev, child, NULL);
91 of_node_put(child); 91 of_node_put(child);
92 if (IS_ERR(phy)) { 92 if (IS_ERR(phy)) {
93 ret = PTR_ERR(phy); 93 ret = PTR_ERR(phy);
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index f98d03f3144c..46987735a2e3 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -72,12 +72,14 @@
72static const char hcd_name [] = "ohci_hcd"; 72static const char hcd_name [] = "ohci_hcd";
73 73
74#define STATECHANGE_DELAY msecs_to_jiffies(300) 74#define STATECHANGE_DELAY msecs_to_jiffies(300)
75#define IO_WATCHDOG_DELAY msecs_to_jiffies(250)
75 76
76#include "ohci.h" 77#include "ohci.h"
77#include "pci-quirks.h" 78#include "pci-quirks.h"
78 79
79static void ohci_dump (struct ohci_hcd *ohci, int verbose); 80static void ohci_dump(struct ohci_hcd *ohci);
80static void ohci_stop (struct usb_hcd *hcd); 81static void ohci_stop(struct usb_hcd *hcd);
82static void io_watchdog_func(unsigned long _ohci);
81 83
82#include "ohci-hub.c" 84#include "ohci-hub.c"
83#include "ohci-dbg.c" 85#include "ohci-dbg.c"
@@ -109,6 +111,33 @@ MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
109 111
110/*-------------------------------------------------------------------------*/ 112/*-------------------------------------------------------------------------*/
111 113
114static int number_of_tds(struct urb *urb)
115{
116 int len, i, num, this_sg_len;
117 struct scatterlist *sg;
118
119 len = urb->transfer_buffer_length;
120 i = urb->num_mapped_sgs;
121
122 if (len > 0 && i > 0) { /* Scatter-gather transfer */
123 num = 0;
124 sg = urb->sg;
125 for (;;) {
126 this_sg_len = min_t(int, sg_dma_len(sg), len);
127 num += DIV_ROUND_UP(this_sg_len, 4096);
128 len -= this_sg_len;
129 if (--i <= 0 || len <= 0)
130 break;
131 sg = sg_next(sg);
132 }
133
134 } else { /* Non-SG transfer */
135 /* one TD for every 4096 Bytes (could be up to 8K) */
136 num = DIV_ROUND_UP(len, 4096);
137 }
138 return num;
139}
140
112/* 141/*
113 * queue up an urb for anything except the root hub 142 * queue up an urb for anything except the root hub
114 */ 143 */
@@ -142,12 +171,8 @@ static int ohci_urb_enqueue (
142 // case PIPE_INTERRUPT: 171 // case PIPE_INTERRUPT:
143 // case PIPE_BULK: 172 // case PIPE_BULK:
144 default: 173 default:
145 /* one TD for every 4096 Bytes (can be up to 8K) */ 174 size += number_of_tds(urb);
146 size += urb->transfer_buffer_length / 4096; 175 /* maybe a zero-length packet to wrap it up */
147 /* ... and for any remaining bytes ... */
148 if ((urb->transfer_buffer_length % 4096) != 0)
149 size++;
150 /* ... and maybe a zero length packet to wrap it up */
151 if (size == 0) 176 if (size == 0)
152 size++; 177 size++;
153 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0 178 else if ((urb->transfer_flags & URB_ZERO_PACKET) != 0
@@ -202,6 +227,16 @@ static int ohci_urb_enqueue (
202 usb_hcd_unlink_urb_from_ep(hcd, urb); 227 usb_hcd_unlink_urb_from_ep(hcd, urb);
203 goto fail; 228 goto fail;
204 } 229 }
230
231 /* Start up the I/O watchdog timer, if it's not running */
232 if (!timer_pending(&ohci->io_watchdog) &&
233 list_empty(&ohci->eds_in_use)) {
234 ohci->prev_frame_no = ohci_frame_no(ohci);
235 mod_timer(&ohci->io_watchdog,
236 jiffies + IO_WATCHDOG_DELAY);
237 }
238 list_add(&ed->in_use_list, &ohci->eds_in_use);
239
205 if (ed->type == PIPE_ISOCHRONOUS) { 240 if (ed->type == PIPE_ISOCHRONOUS) {
206 u16 frame = ohci_frame_no(ohci); 241 u16 frame = ohci_frame_no(ohci);
207 242
@@ -277,30 +312,24 @@ static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
277 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 312 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
278 unsigned long flags; 313 unsigned long flags;
279 int rc; 314 int rc;
315 urb_priv_t *urb_priv;
280 316
281 spin_lock_irqsave (&ohci->lock, flags); 317 spin_lock_irqsave (&ohci->lock, flags);
282 rc = usb_hcd_check_unlink_urb(hcd, urb, status); 318 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
283 if (rc) { 319 if (rc == 0) {
284 ; /* Do nothing */
285 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
286 urb_priv_t *urb_priv;
287 320
288 /* Unless an IRQ completed the unlink while it was being 321 /* Unless an IRQ completed the unlink while it was being
289 * handed to us, flag it for unlink and giveback, and force 322 * handed to us, flag it for unlink and giveback, and force
290 * some upcoming INTR_SF to call finish_unlinks() 323 * some upcoming INTR_SF to call finish_unlinks()
291 */ 324 */
292 urb_priv = urb->hcpriv; 325 urb_priv = urb->hcpriv;
293 if (urb_priv) { 326 if (urb_priv->ed->state == ED_OPER)
294 if (urb_priv->ed->state == ED_OPER) 327 start_ed_unlink(ohci, urb_priv->ed);
295 start_ed_unlink (ohci, urb_priv->ed); 328
329 if (ohci->rh_state != OHCI_RH_RUNNING) {
330 /* With HC dead, we can clean up right away */
331 ohci_work(ohci);
296 } 332 }
297 } else {
298 /*
299 * with HC dead, we won't respect hc queue pointers
300 * any more ... just clean up every urb's memory.
301 */
302 if (urb->hcpriv)
303 finish_urb(ohci, urb, status);
304 } 333 }
305 spin_unlock_irqrestore (&ohci->lock, flags); 334 spin_unlock_irqrestore (&ohci->lock, flags);
306 return rc; 335 return rc;
@@ -332,9 +361,7 @@ rescan:
332 if (ohci->rh_state != OHCI_RH_RUNNING) { 361 if (ohci->rh_state != OHCI_RH_RUNNING) {
333sanitize: 362sanitize:
334 ed->state = ED_IDLE; 363 ed->state = ED_IDLE;
335 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT) 364 ohci_work(ohci);
336 ohci->eds_scheduled--;
337 finish_unlinks (ohci, 0);
338 } 365 }
339 366
340 switch (ed->state) { 367 switch (ed->state) {
@@ -342,11 +369,6 @@ sanitize:
342 /* major IRQ delivery trouble loses INTR_SF too... */ 369 /* major IRQ delivery trouble loses INTR_SF too... */
343 if (limit-- == 0) { 370 if (limit-- == 0) {
344 ohci_warn(ohci, "ED unlink timeout\n"); 371 ohci_warn(ohci, "ED unlink timeout\n");
345 if (quirk_zfmicro(ohci)) {
346 ohci_warn(ohci, "Attempting ZF TD recovery\n");
347 ohci->ed_to_check = ed;
348 ohci->zf_delay = 2;
349 }
350 goto sanitize; 372 goto sanitize;
351 } 373 }
352 spin_unlock_irqrestore (&ohci->lock, flags); 374 spin_unlock_irqrestore (&ohci->lock, flags);
@@ -406,93 +428,7 @@ ohci_shutdown (struct usb_hcd *hcd)
406 udelay(10); 428 udelay(10);
407 429
408 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval); 430 ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval);
409} 431 ohci->rh_state = OHCI_RH_HALTED;
410
411static int check_ed(struct ohci_hcd *ohci, struct ed *ed)
412{
413 return (hc32_to_cpu(ohci, ed->hwINFO) & ED_IN) != 0
414 && (hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK)
415 == (hc32_to_cpu(ohci, ed->hwTailP) & TD_MASK)
416 && !list_empty(&ed->td_list);
417}
418
419/* ZF Micro watchdog timer callback. The ZF Micro chipset sometimes completes
420 * an interrupt TD but neglects to add it to the donelist. On systems with
421 * this chipset, we need to periodically check the state of the queues to look
422 * for such "lost" TDs.
423 */
424static void unlink_watchdog_func(unsigned long _ohci)
425{
426 unsigned long flags;
427 unsigned max;
428 unsigned seen_count = 0;
429 unsigned i;
430 struct ed **seen = NULL;
431 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
432
433 spin_lock_irqsave(&ohci->lock, flags);
434 max = ohci->eds_scheduled;
435 if (!max)
436 goto done;
437
438 if (ohci->ed_to_check)
439 goto out;
440
441 seen = kcalloc(max, sizeof *seen, GFP_ATOMIC);
442 if (!seen)
443 goto out;
444
445 for (i = 0; i < NUM_INTS; i++) {
446 struct ed *ed = ohci->periodic[i];
447
448 while (ed) {
449 unsigned temp;
450
451 /* scan this branch of the periodic schedule tree */
452 for (temp = 0; temp < seen_count; temp++) {
453 if (seen[temp] == ed) {
454 /* we've checked it and what's after */
455 ed = NULL;
456 break;
457 }
458 }
459 if (!ed)
460 break;
461 seen[seen_count++] = ed;
462 if (!check_ed(ohci, ed)) {
463 ed = ed->ed_next;
464 continue;
465 }
466
467 /* HC's TD list is empty, but HCD sees at least one
468 * TD that's not been sent through the donelist.
469 */
470 ohci->ed_to_check = ed;
471 ohci->zf_delay = 2;
472
473 /* The HC may wait until the next frame to report the
474 * TD as done through the donelist and INTR_WDH. (We
475 * just *assume* it's not a multi-TD interrupt URB;
476 * those could defer the IRQ more than one frame, using
477 * DI...) Check again after the next INTR_SF.
478 */
479 ohci_writel(ohci, OHCI_INTR_SF,
480 &ohci->regs->intrstatus);
481 ohci_writel(ohci, OHCI_INTR_SF,
482 &ohci->regs->intrenable);
483
484 /* flush those writes */
485 (void) ohci_readl(ohci, &ohci->regs->control);
486
487 goto out;
488 }
489 }
490out:
491 kfree(seen);
492 if (ohci->eds_scheduled)
493 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
494done:
495 spin_unlock_irqrestore(&ohci->lock, flags);
496} 432}
497 433
498/*-------------------------------------------------------------------------* 434/*-------------------------------------------------------------------------*
@@ -506,6 +442,9 @@ static int ohci_init (struct ohci_hcd *ohci)
506 int ret; 442 int ret;
507 struct usb_hcd *hcd = ohci_to_hcd(ohci); 443 struct usb_hcd *hcd = ohci_to_hcd(ohci);
508 444
445 /* Accept arbitrarily long scatter-gather lists */
446 hcd->self.sg_tablesize = ~0;
447
509 if (distrust_firmware) 448 if (distrust_firmware)
510 ohci->flags |= OHCI_QUIRK_HUB_POWER; 449 ohci->flags |= OHCI_QUIRK_HUB_POWER;
511 450
@@ -558,8 +497,12 @@ static int ohci_init (struct ohci_hcd *ohci)
558 if (ohci->hcca) 497 if (ohci->hcca)
559 return 0; 498 return 0;
560 499
500 setup_timer(&ohci->io_watchdog, io_watchdog_func,
501 (unsigned long) ohci);
502 set_timer_slack(&ohci->io_watchdog, msecs_to_jiffies(20));
503
561 ohci->hcca = dma_alloc_coherent (hcd->self.controller, 504 ohci->hcca = dma_alloc_coherent (hcd->self.controller,
562 sizeof *ohci->hcca, &ohci->hcca_dma, 0); 505 sizeof(*ohci->hcca), &ohci->hcca_dma, GFP_KERNEL);
563 if (!ohci->hcca) 506 if (!ohci->hcca)
564 return -ENOMEM; 507 return -ENOMEM;
565 508
@@ -735,16 +678,7 @@ retry:
735 // POTPGT delay is bits 24-31, in 2 ms units. 678 // POTPGT delay is bits 24-31, in 2 ms units.
736 mdelay ((val >> 23) & 0x1fe); 679 mdelay ((val >> 23) & 0x1fe);
737 680
738 if (quirk_zfmicro(ohci)) { 681 ohci_dump(ohci);
739 /* Create timer to watch for bad queue state on ZF Micro */
740 setup_timer(&ohci->unlink_watchdog, unlink_watchdog_func,
741 (unsigned long) ohci);
742
743 ohci->eds_scheduled = 0;
744 ohci->ed_to_check = NULL;
745 }
746
747 ohci_dump (ohci, 1);
748 682
749 return 0; 683 return 0;
750} 684}
@@ -777,6 +711,142 @@ static int ohci_start(struct usb_hcd *hcd)
777 711
778/*-------------------------------------------------------------------------*/ 712/*-------------------------------------------------------------------------*/
779 713
714/*
715 * Some OHCI controllers are known to lose track of completed TDs. They
716 * don't add the TDs to the hardware done queue, which means we never see
717 * them as being completed.
718 *
719 * This watchdog routine checks for such problems. Without some way to
720 * tell when those TDs have completed, we would never take their EDs off
721 * the unlink list. As a result, URBs could never be dequeued and
722 * endpoints could never be released.
723 */
724static void io_watchdog_func(unsigned long _ohci)
725{
726 struct ohci_hcd *ohci = (struct ohci_hcd *) _ohci;
727 bool takeback_all_pending = false;
728 u32 status;
729 u32 head;
730 struct ed *ed;
731 struct td *td, *td_start, *td_next;
732 unsigned frame_no;
733 unsigned long flags;
734
735 spin_lock_irqsave(&ohci->lock, flags);
736
737 /*
738 * One way to lose track of completed TDs is if the controller
739 * never writes back the done queue head. If it hasn't been
740 * written back since the last time this function ran and if it
741 * was non-empty at that time, something is badly wrong with the
742 * hardware.
743 */
744 status = ohci_readl(ohci, &ohci->regs->intrstatus);
745 if (!(status & OHCI_INTR_WDH) && ohci->wdh_cnt == ohci->prev_wdh_cnt) {
746 if (ohci->prev_donehead) {
747 ohci_err(ohci, "HcDoneHead not written back; disabled\n");
748 died:
749 usb_hc_died(ohci_to_hcd(ohci));
750 ohci_dump(ohci);
751 ohci_shutdown(ohci_to_hcd(ohci));
752 goto done;
753 } else {
754 /* No write back because the done queue was empty */
755 takeback_all_pending = true;
756 }
757 }
758
759 /* Check every ED which might have pending TDs */
760 list_for_each_entry(ed, &ohci->eds_in_use, in_use_list) {
761 if (ed->pending_td) {
762 if (takeback_all_pending ||
763 OKAY_TO_TAKEBACK(ohci, ed)) {
764 unsigned tmp = hc32_to_cpu(ohci, ed->hwINFO);
765
766 ohci_dbg(ohci, "takeback pending TD for dev %d ep 0x%x\n",
767 0x007f & tmp,
768 (0x000f & (tmp >> 7)) +
769 ((tmp & ED_IN) >> 5));
770 add_to_done_list(ohci, ed->pending_td);
771 }
772 }
773
774 /* Starting from the latest pending TD, */
775 td = ed->pending_td;
776
777 /* or the last TD on the done list, */
778 if (!td) {
779 list_for_each_entry(td_next, &ed->td_list, td_list) {
780 if (!td_next->next_dl_td)
781 break;
782 td = td_next;
783 }
784 }
785
786 /* find the last TD processed by the controller. */
787 head = hc32_to_cpu(ohci, ACCESS_ONCE(ed->hwHeadP)) & TD_MASK;
788 td_start = td;
789 td_next = list_prepare_entry(td, &ed->td_list, td_list);
790 list_for_each_entry_continue(td_next, &ed->td_list, td_list) {
791 if (head == (u32) td_next->td_dma)
792 break;
793 td = td_next; /* head pointer has passed this TD */
794 }
795 if (td != td_start) {
796 /*
797 * In case a WDH cycle is in progress, we will wait
798 * for the next two cycles to complete before assuming
799 * this TD will never get on the done queue.
800 */
801 ed->takeback_wdh_cnt = ohci->wdh_cnt + 2;
802 ed->pending_td = td;
803 }
804 }
805
806 ohci_work(ohci);
807
808 if (ohci->rh_state == OHCI_RH_RUNNING) {
809
810 /*
811 * Sometimes a controller just stops working. We can tell
812 * by checking that the frame counter has advanced since
813 * the last time we ran.
814 *
815 * But be careful: Some controllers violate the spec by
816 * stopping their frame counter when no ports are active.
817 */
818 frame_no = ohci_frame_no(ohci);
819 if (frame_no == ohci->prev_frame_no) {
820 int active_cnt = 0;
821 int i;
822 unsigned tmp;
823
824 for (i = 0; i < ohci->num_ports; ++i) {
825 tmp = roothub_portstatus(ohci, i);
826 /* Enabled and not suspended? */
827 if ((tmp & RH_PS_PES) && !(tmp & RH_PS_PSS))
828 ++active_cnt;
829 }
830
831 if (active_cnt > 0) {
832 ohci_err(ohci, "frame counter not updating; disabled\n");
833 goto died;
834 }
835 }
836 if (!list_empty(&ohci->eds_in_use)) {
837 ohci->prev_frame_no = frame_no;
838 ohci->prev_wdh_cnt = ohci->wdh_cnt;
839 ohci->prev_donehead = ohci_readl(ohci,
840 &ohci->regs->donehead);
841 mod_timer(&ohci->io_watchdog,
842 jiffies + IO_WATCHDOG_DELAY);
843 }
844 }
845
846 done:
847 spin_unlock_irqrestore(&ohci->lock, flags);
848}
849
780/* an interrupt happens */ 850/* an interrupt happens */
781 851
782static irqreturn_t ohci_irq (struct usb_hcd *hcd) 852static irqreturn_t ohci_irq (struct usb_hcd *hcd)
@@ -825,7 +895,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
825 usb_hc_died(hcd); 895 usb_hc_died(hcd);
826 } 896 }
827 897
828 ohci_dump (ohci, 1); 898 ohci_dump(ohci);
829 ohci_usb_reset (ohci); 899 ohci_usb_reset (ohci);
830 } 900 }
831 901
@@ -863,58 +933,30 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
863 usb_hcd_resume_root_hub(hcd); 933 usb_hcd_resume_root_hub(hcd);
864 } 934 }
865 935
866 if (ints & OHCI_INTR_WDH) { 936 spin_lock(&ohci->lock);
867 spin_lock (&ohci->lock); 937 if (ints & OHCI_INTR_WDH)
868 dl_done_list (ohci); 938 update_done_list(ohci);
869 spin_unlock (&ohci->lock);
870 }
871
872 if (quirk_zfmicro(ohci) && (ints & OHCI_INTR_SF)) {
873 spin_lock(&ohci->lock);
874 if (ohci->ed_to_check) {
875 struct ed *ed = ohci->ed_to_check;
876
877 if (check_ed(ohci, ed)) {
878 /* HC thinks the TD list is empty; HCD knows
879 * at least one TD is outstanding
880 */
881 if (--ohci->zf_delay == 0) {
882 struct td *td = list_entry(
883 ed->td_list.next,
884 struct td, td_list);
885 ohci_warn(ohci,
886 "Reclaiming orphan TD %p\n",
887 td);
888 takeback_td(ohci, td);
889 ohci->ed_to_check = NULL;
890 }
891 } else
892 ohci->ed_to_check = NULL;
893 }
894 spin_unlock(&ohci->lock);
895 }
896 939
897 /* could track INTR_SO to reduce available PCI/... bandwidth */ 940 /* could track INTR_SO to reduce available PCI/... bandwidth */
898 941
899 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled 942 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
900 * when there's still unlinking to be done (next frame). 943 * when there's still unlinking to be done (next frame).
901 */ 944 */
902 spin_lock (&ohci->lock); 945 ohci_work(ohci);
903 if (ohci->ed_rm_list) 946 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
904 finish_unlinks (ohci, ohci_frame_no(ohci));
905 if ((ints & OHCI_INTR_SF) != 0
906 && !ohci->ed_rm_list
907 && !ohci->ed_to_check
908 && ohci->rh_state == OHCI_RH_RUNNING) 947 && ohci->rh_state == OHCI_RH_RUNNING)
909 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable); 948 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
910 spin_unlock (&ohci->lock);
911 949
912 if (ohci->rh_state == OHCI_RH_RUNNING) { 950 if (ohci->rh_state == OHCI_RH_RUNNING) {
913 ohci_writel (ohci, ints, &regs->intrstatus); 951 ohci_writel (ohci, ints, &regs->intrstatus);
952 if (ints & OHCI_INTR_WDH)
953 ++ohci->wdh_cnt;
954
914 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable); 955 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
915 // flush those writes 956 // flush those writes
916 (void) ohci_readl (ohci, &ohci->regs->control); 957 (void) ohci_readl (ohci, &ohci->regs->control);
917 } 958 }
959 spin_unlock(&ohci->lock);
918 960
919 return IRQ_HANDLED; 961 return IRQ_HANDLED;
920} 962}
@@ -925,18 +967,17 @@ static void ohci_stop (struct usb_hcd *hcd)
925{ 967{
926 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 968 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
927 969
928 ohci_dump (ohci, 1); 970 ohci_dump(ohci);
929 971
930 if (quirk_nec(ohci)) 972 if (quirk_nec(ohci))
931 flush_work(&ohci->nec_work); 973 flush_work(&ohci->nec_work);
974 del_timer_sync(&ohci->io_watchdog);
932 975
933 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 976 ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
934 ohci_usb_reset(ohci); 977 ohci_usb_reset(ohci);
935 free_irq(hcd->irq, hcd); 978 free_irq(hcd->irq, hcd);
936 hcd->irq = 0; 979 hcd->irq = 0;
937 980
938 if (quirk_zfmicro(ohci))
939 del_timer(&ohci->unlink_watchdog);
940 if (quirk_amdiso(ohci)) 981 if (quirk_amdiso(ohci))
941 usb_amd_dev_put(); 982 usb_amd_dev_put();
942 983
@@ -993,7 +1034,7 @@ int ohci_restart(struct ohci_hcd *ohci)
993 if (!urb->unlinked) 1034 if (!urb->unlinked)
994 urb->unlinked = -ESHUTDOWN; 1035 urb->unlinked = -ESHUTDOWN;
995 } 1036 }
996 finish_unlinks (ohci, 0); 1037 ohci_work(ohci);
997 spin_unlock_irq(&ohci->lock); 1038 spin_unlock_irq(&ohci->lock);
998 1039
999 /* paranoia, in case that didn't work: */ 1040 /* paranoia, in case that didn't work: */
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index b4940de1eba3..17d32b0ea565 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -39,8 +39,8 @@
39#define OHCI_SCHED_ENABLES \ 39#define OHCI_SCHED_ENABLES \
40 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) 40 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
41 41
42static void dl_done_list (struct ohci_hcd *); 42static void update_done_list(struct ohci_hcd *);
43static void finish_unlinks (struct ohci_hcd *, u16); 43static void ohci_work(struct ohci_hcd *);
44 44
45#ifdef CONFIG_PM 45#ifdef CONFIG_PM
46static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop) 46static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop)
@@ -87,8 +87,8 @@ __acquires(ohci->lock)
87 msleep (8); 87 msleep (8);
88 spin_lock_irq (&ohci->lock); 88 spin_lock_irq (&ohci->lock);
89 } 89 }
90 dl_done_list (ohci); 90 update_done_list(ohci);
91 finish_unlinks (ohci, ohci_frame_no(ohci)); 91 ohci_work(ohci);
92 92
93 /* 93 /*
94 * Some controllers don't handle "global" suspend properly if 94 * Some controllers don't handle "global" suspend properly if
@@ -309,6 +309,9 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
309 else 309 else
310 rc = ohci_rh_suspend (ohci, 0); 310 rc = ohci_rh_suspend (ohci, 0);
311 spin_unlock_irq (&ohci->lock); 311 spin_unlock_irq (&ohci->lock);
312
313 if (rc == 0)
314 del_timer_sync(&ohci->io_watchdog);
312 return rc; 315 return rc;
313} 316}
314 317
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index 2f20d3dc895b..c9e315c6808a 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -28,6 +28,7 @@ static void ohci_hcd_init (struct ohci_hcd *ohci)
28 ohci->next_statechange = jiffies; 28 ohci->next_statechange = jiffies;
29 spin_lock_init (&ohci->lock); 29 spin_lock_init (&ohci->lock);
30 INIT_LIST_HEAD (&ohci->pending); 30 INIT_LIST_HEAD (&ohci->pending);
31 INIT_LIST_HEAD(&ohci->eds_in_use);
31} 32}
32 33
33/*-------------------------------------------------------------------------*/ 34/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index d4253e319428..1463c398d322 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -187,10 +187,6 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
187 ed->ed_prev = NULL; 187 ed->ed_prev = NULL;
188 ed->ed_next = NULL; 188 ed->ed_next = NULL;
189 ed->hwNextED = 0; 189 ed->hwNextED = 0;
190 if (quirk_zfmicro(ohci)
191 && (ed->type == PIPE_INTERRUPT)
192 && !(ohci->eds_scheduled++))
193 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
194 wmb (); 190 wmb ();
195 191
196 /* we care about rm_list when setting CLE/BLE in case the HC was at 192 /* we care about rm_list when setting CLE/BLE in case the HC was at
@@ -311,8 +307,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
311 * - ED_OPER: when there's any request queued, the ED gets rescheduled 307 * - ED_OPER: when there's any request queued, the ED gets rescheduled
312 * immediately. HC should be working on them. 308 * immediately. HC should be working on them.
313 * 309 *
314 * - ED_IDLE: when there's no TD queue. there's no reason for the HC 310 * - ED_IDLE: when there's no TD queue or the HC isn't running.
315 * to care about this ED; safe to disable the endpoint.
316 * 311 *
317 * When finish_unlinks() runs later, after SOF interrupt, it will often 312 * When finish_unlinks() runs later, after SOF interrupt, it will often
318 * complete one or more URB unlinks before making that state change. 313 * complete one or more URB unlinks before making that state change.
@@ -602,6 +597,8 @@ static void td_submit_urb (
602 u32 info = 0; 597 u32 info = 0;
603 int is_out = usb_pipeout (urb->pipe); 598 int is_out = usb_pipeout (urb->pipe);
604 int periodic = 0; 599 int periodic = 0;
600 int i, this_sg_len, n;
601 struct scatterlist *sg;
605 602
606 /* OHCI handles the bulk/interrupt data toggles itself. We just 603 /* OHCI handles the bulk/interrupt data toggles itself. We just
607 * use the device toggle bits for resetting, and rely on the fact 604 * use the device toggle bits for resetting, and rely on the fact
@@ -615,10 +612,24 @@ static void td_submit_urb (
615 612
616 list_add (&urb_priv->pending, &ohci->pending); 613 list_add (&urb_priv->pending, &ohci->pending);
617 614
618 if (data_len) 615 i = urb->num_mapped_sgs;
619 data = urb->transfer_dma; 616 if (data_len > 0 && i > 0) {
620 else 617 sg = urb->sg;
621 data = 0; 618 data = sg_dma_address(sg);
619
620 /*
621 * urb->transfer_buffer_length may be smaller than the
622 * size of the scatterlist (or vice versa)
623 */
624 this_sg_len = min_t(int, sg_dma_len(sg), data_len);
625 } else {
626 sg = NULL;
627 if (data_len)
628 data = urb->transfer_dma;
629 else
630 data = 0;
631 this_sg_len = data_len;
632 }
622 633
623 /* NOTE: TD_CC is set so we can tell which TDs the HC processed by 634 /* NOTE: TD_CC is set so we can tell which TDs the HC processed by
624 * using TD_CC_GET, as well as by seeing them on the done list. 635 * using TD_CC_GET, as well as by seeing them on the done list.
@@ -639,17 +650,29 @@ static void td_submit_urb (
639 ? TD_T_TOGGLE | TD_CC | TD_DP_OUT 650 ? TD_T_TOGGLE | TD_CC | TD_DP_OUT
640 : TD_T_TOGGLE | TD_CC | TD_DP_IN; 651 : TD_T_TOGGLE | TD_CC | TD_DP_IN;
641 /* TDs _could_ transfer up to 8K each */ 652 /* TDs _could_ transfer up to 8K each */
642 while (data_len > 4096) { 653 for (;;) {
643 td_fill (ohci, info, data, 4096, urb, cnt); 654 n = min(this_sg_len, 4096);
644 data += 4096; 655
645 data_len -= 4096; 656 /* maybe avoid ED halt on final TD short read */
657 if (n >= data_len || (i == 1 && n >= this_sg_len)) {
658 if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
659 info |= TD_R;
660 }
661 td_fill(ohci, info, data, n, urb, cnt);
662 this_sg_len -= n;
663 data_len -= n;
664 data += n;
646 cnt++; 665 cnt++;
666
667 if (this_sg_len <= 0) {
668 if (--i <= 0 || data_len <= 0)
669 break;
670 sg = sg_next(sg);
671 data = sg_dma_address(sg);
672 this_sg_len = min_t(int, sg_dma_len(sg),
673 data_len);
674 }
647 } 675 }
648 /* maybe avoid ED halt on final TD short read */
649 if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
650 info |= TD_R;
651 td_fill (ohci, info, data, data_len, urb, cnt);
652 cnt++;
653 if ((urb->transfer_flags & URB_ZERO_PACKET) 676 if ((urb->transfer_flags & URB_ZERO_PACKET)
654 && cnt < urb_priv->length) { 677 && cnt < urb_priv->length) {
655 td_fill (ohci, info, 0, 0, urb, cnt); 678 td_fill (ohci, info, 0, 0, urb, cnt);
@@ -869,13 +892,46 @@ static void ed_halted(struct ohci_hcd *ohci, struct td *td, int cc)
869 } 892 }
870} 893}
871 894
872/* replies to the request have to be on a FIFO basis so 895/* Add a TD to the done list */
873 * we unreverse the hc-reversed done-list 896static void add_to_done_list(struct ohci_hcd *ohci, struct td *td)
874 */ 897{
875static struct td *dl_reverse_done_list (struct ohci_hcd *ohci) 898 struct td *td2, *td_prev;
899 struct ed *ed;
900
901 if (td->next_dl_td)
902 return; /* Already on the list */
903
904 /* Add all the TDs going back until we reach one that's on the list */
905 ed = td->ed;
906 td2 = td_prev = td;
907 list_for_each_entry_continue_reverse(td2, &ed->td_list, td_list) {
908 if (td2->next_dl_td)
909 break;
910 td2->next_dl_td = td_prev;
911 td_prev = td2;
912 }
913
914 if (ohci->dl_end)
915 ohci->dl_end->next_dl_td = td_prev;
916 else
917 ohci->dl_start = td_prev;
918
919 /*
920 * Make td->next_dl_td point to td itself, to mark the fact
921 * that td is on the done list.
922 */
923 ohci->dl_end = td->next_dl_td = td;
924
925 /* Did we just add the latest pending TD? */
926 td2 = ed->pending_td;
927 if (td2 && td2->next_dl_td)
928 ed->pending_td = NULL;
929}
930
931/* Get the entries on the hardware done queue and put them on our list */
932static void update_done_list(struct ohci_hcd *ohci)
876{ 933{
877 u32 td_dma; 934 u32 td_dma;
878 struct td *td_rev = NULL;
879 struct td *td = NULL; 935 struct td *td = NULL;
880 936
881 td_dma = hc32_to_cpup (ohci, &ohci->hcca->done_head); 937 td_dma = hc32_to_cpup (ohci, &ohci->hcca->done_head);
@@ -883,7 +939,7 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
883 wmb(); 939 wmb();
884 940
885 /* get TD from hc's singly linked list, and 941 /* get TD from hc's singly linked list, and
886 * prepend to ours. ed->td_list changes later. 942 * add to ours. ed->td_list changes later.
887 */ 943 */
888 while (td_dma) { 944 while (td_dma) {
889 int cc; 945 int cc;
@@ -905,19 +961,17 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
905 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H))) 961 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
906 ed_halted(ohci, td, cc); 962 ed_halted(ohci, td, cc);
907 963
908 td->next_dl_td = td_rev;
909 td_rev = td;
910 td_dma = hc32_to_cpup (ohci, &td->hwNextTD); 964 td_dma = hc32_to_cpup (ohci, &td->hwNextTD);
965 add_to_done_list(ohci, td);
911 } 966 }
912 return td_rev;
913} 967}
914 968
915/*-------------------------------------------------------------------------*/ 969/*-------------------------------------------------------------------------*/
916 970
917/* there are some urbs/eds to unlink; called in_irq(), with HCD locked */ 971/* there are some urbs/eds to unlink; called in_irq(), with HCD locked */
918static void 972static void finish_unlinks(struct ohci_hcd *ohci)
919finish_unlinks (struct ohci_hcd *ohci, u16 tick)
920{ 973{
974 unsigned tick = ohci_frame_no(ohci);
921 struct ed *ed, **last; 975 struct ed *ed, **last;
922 976
923rescan_all: 977rescan_all:
@@ -926,41 +980,48 @@ rescan_all:
926 int completed, modified; 980 int completed, modified;
927 __hc32 *prev; 981 __hc32 *prev;
928 982
983 /* Is this ED already invisible to the hardware? */
984 if (ed->state == ED_IDLE)
985 goto ed_idle;
986
929 /* only take off EDs that the HC isn't using, accounting for 987 /* only take off EDs that the HC isn't using, accounting for
930 * frame counter wraps and EDs with partially retired TDs 988 * frame counter wraps and EDs with partially retired TDs
931 */ 989 */
932 if (likely(ohci->rh_state == OHCI_RH_RUNNING)) { 990 if (likely(ohci->rh_state == OHCI_RH_RUNNING) &&
933 if (tick_before (tick, ed->tick)) { 991 tick_before(tick, ed->tick)) {
934skip_ed: 992skip_ed:
935 last = &ed->ed_next; 993 last = &ed->ed_next;
936 continue; 994 continue;
937 } 995 }
996 if (!list_empty(&ed->td_list)) {
997 struct td *td;
998 u32 head;
938 999
939 if (!list_empty (&ed->td_list)) { 1000 td = list_first_entry(&ed->td_list, struct td, td_list);
940 struct td *td; 1001
941 u32 head; 1002 /* INTR_WDH may need to clean up first */
942 1003 head = hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK;
943 td = list_entry (ed->td_list.next, struct td, 1004 if (td->td_dma != head &&
944 td_list); 1005 ohci->rh_state == OHCI_RH_RUNNING)
945 head = hc32_to_cpu (ohci, ed->hwHeadP) & 1006 goto skip_ed;
946 TD_MASK; 1007
947 1008 /* Don't mess up anything already on the done list */
948 /* INTR_WDH may need to clean up first */ 1009 if (td->next_dl_td)
949 if (td->td_dma != head) { 1010 goto skip_ed;
950 if (ed == ohci->ed_to_check)
951 ohci->ed_to_check = NULL;
952 else
953 goto skip_ed;
954 }
955 }
956 } 1011 }
957 1012
1013 /* ED's now officially unlinked, hc doesn't see */
1014 ed->state = ED_IDLE;
1015 ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H);
1016 ed->hwNextED = 0;
1017 wmb();
1018 ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE);
1019ed_idle:
1020
958 /* reentrancy: if we drop the schedule lock, someone might 1021 /* reentrancy: if we drop the schedule lock, someone might
959 * have modified this list. normally it's just prepending 1022 * have modified this list. normally it's just prepending
960 * entries (which we'd ignore), but paranoia won't hurt. 1023 * entries (which we'd ignore), but paranoia won't hurt.
961 */ 1024 */
962 *last = ed->ed_next;
963 ed->ed_next = NULL;
964 modified = 0; 1025 modified = 0;
965 1026
966 /* unlink urbs as requested, but rescan the list after 1027 /* unlink urbs as requested, but rescan the list after
@@ -1018,19 +1079,21 @@ rescan_this:
1018 if (completed && !list_empty (&ed->td_list)) 1079 if (completed && !list_empty (&ed->td_list))
1019 goto rescan_this; 1080 goto rescan_this;
1020 1081
1021 /* ED's now officially unlinked, hc doesn't see */ 1082 /*
1022 ed->state = ED_IDLE; 1083 * If no TDs are queued, take ED off the ed_rm_list.
1023 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT) 1084 * Otherwise, if the HC is running, reschedule.
1024 ohci->eds_scheduled--; 1085 * If not, leave it on the list for further dequeues.
1025 ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H); 1086 */
1026 ed->hwNextED = 0; 1087 if (list_empty(&ed->td_list)) {
1027 wmb (); 1088 *last = ed->ed_next;
1028 ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE); 1089 ed->ed_next = NULL;
1029 1090 list_del(&ed->in_use_list);
1030 /* but if there's work queued, reschedule */ 1091 } else if (ohci->rh_state == OHCI_RH_RUNNING) {
1031 if (!list_empty (&ed->td_list)) { 1092 *last = ed->ed_next;
1032 if (ohci->rh_state == OHCI_RH_RUNNING) 1093 ed->ed_next = NULL;
1033 ed_schedule (ohci, ed); 1094 ed_schedule(ohci, ed);
1095 } else {
1096 last = &ed->ed_next;
1034 } 1097 }
1035 1098
1036 if (modified) 1099 if (modified)
@@ -1082,12 +1145,7 @@ rescan_this:
1082 1145
1083/*-------------------------------------------------------------------------*/ 1146/*-------------------------------------------------------------------------*/
1084 1147
1085/* 1148/* Take back a TD from the host controller */
1086 * Used to take back a TD from the host controller. This would normally be
1087 * called from within dl_done_list, however it may be called directly if the
1088 * HC no longer sees the TD and it has not appeared on the donelist (after
1089 * two frames). This bug has been observed on ZF Micro systems.
1090 */
1091static void takeback_td(struct ohci_hcd *ohci, struct td *td) 1149static void takeback_td(struct ohci_hcd *ohci, struct td *td)
1092{ 1150{
1093 struct urb *urb = td->urb; 1151 struct urb *urb = td->urb;
@@ -1134,37 +1192,43 @@ static void takeback_td(struct ohci_hcd *ohci, struct td *td)
1134 * 1192 *
1135 * This is the main path for handing urbs back to drivers. The only other 1193 * This is the main path for handing urbs back to drivers. The only other
1136 * normal path is finish_unlinks(), which unlinks URBs using ed_rm_list, 1194 * normal path is finish_unlinks(), which unlinks URBs using ed_rm_list,
1137 * instead of scanning the (re-reversed) donelist as this does. There's 1195 * instead of scanning the (re-reversed) donelist as this does.
1138 * an abnormal path too, handling a quirk in some Compaq silicon: URBs
1139 * with TDs that appear to be orphaned are directly reclaimed.
1140 */ 1196 */
1141static void 1197static void process_done_list(struct ohci_hcd *ohci)
1142dl_done_list (struct ohci_hcd *ohci)
1143{ 1198{
1144 struct td *td = dl_reverse_done_list (ohci); 1199 struct td *td;
1145 1200
1146 while (td) { 1201 while (ohci->dl_start) {
1147 struct td *td_next = td->next_dl_td; 1202 td = ohci->dl_start;
1148 struct ed *ed = td->ed; 1203 if (td == ohci->dl_end)
1204 ohci->dl_start = ohci->dl_end = NULL;
1205 else
1206 ohci->dl_start = td->next_dl_td;
1149 1207
1150 /* 1208 takeback_td(ohci, td);
1151 * Some OHCI controllers (NVIDIA for sure, maybe others) 1209 }
1152 * occasionally forget to add TDs to the done queue. Since 1210}
1153 * TDs for a given endpoint are always processed in order,
1154 * if we find a TD on the donelist then all of its
1155 * predecessors must be finished as well.
1156 */
1157 for (;;) {
1158 struct td *td2;
1159 1211
1160 td2 = list_first_entry(&ed->td_list, struct td, 1212/*
1161 td_list); 1213 * TD takeback and URB giveback must be single-threaded.
1162 if (td2 == td) 1214 * This routine takes care of it all.
1163 break; 1215 */
1164 takeback_td(ohci, td2); 1216static void ohci_work(struct ohci_hcd *ohci)
1165 } 1217{
1218 if (ohci->working) {
1219 ohci->restart_work = 1;
1220 return;
1221 }
1222 ohci->working = 1;
1166 1223
1167 takeback_td(ohci, td); 1224 restart:
1168 td = td_next; 1225 process_done_list(ohci);
1226 if (ohci->ed_rm_list)
1227 finish_unlinks(ohci);
1228
1229 if (ohci->restart_work) {
1230 ohci->restart_work = 0;
1231 goto restart;
1169 } 1232 }
1233 ohci->working = 0;
1170} 1234}
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c
index 8b29a0c04c23..8d5876692e7c 100644
--- a/drivers/usb/host/ohci-spear.c
+++ b/drivers/usb/host/ohci-spear.c
@@ -162,7 +162,7 @@ static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
162} 162}
163#endif 163#endif
164 164
165static struct of_device_id spear_ohci_id_table[] = { 165static const struct of_device_id spear_ohci_id_table[] = {
166 { .compatible = "st,spear600-ohci", }, 166 { .compatible = "st,spear600-ohci", },
167 { }, 167 { },
168}; 168};
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 05e02a709d4f..59f424567a8d 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -47,6 +47,7 @@ struct ed {
47 struct ed *ed_next; /* on schedule or rm_list */ 47 struct ed *ed_next; /* on schedule or rm_list */
48 struct ed *ed_prev; /* for non-interrupt EDs */ 48 struct ed *ed_prev; /* for non-interrupt EDs */
49 struct list_head td_list; /* "shadow list" of our TDs */ 49 struct list_head td_list; /* "shadow list" of our TDs */
50 struct list_head in_use_list;
50 51
51 /* create --> IDLE --> OPER --> ... --> IDLE --> destroy 52 /* create --> IDLE --> OPER --> ... --> IDLE --> destroy
52 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ... 53 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ...
@@ -66,6 +67,13 @@ struct ed {
66 67
67 /* HC may see EDs on rm_list until next frame (frame_no == tick) */ 68 /* HC may see EDs on rm_list until next frame (frame_no == tick) */
68 u16 tick; 69 u16 tick;
70
71 /* Detect TDs not added to the done queue */
72 unsigned takeback_wdh_cnt;
73 struct td *pending_td;
74#define OKAY_TO_TAKEBACK(ohci, ed) \
75 ((int) (ohci->wdh_cnt - ed->takeback_wdh_cnt) >= 0)
76
69} __attribute__ ((aligned(16))); 77} __attribute__ ((aligned(16)));
70 78
71#define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */ 79#define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */
@@ -380,7 +388,9 @@ struct ohci_hcd {
380 struct dma_pool *td_cache; 388 struct dma_pool *td_cache;
381 struct dma_pool *ed_cache; 389 struct dma_pool *ed_cache;
382 struct td *td_hash [TD_HASH_SIZE]; 390 struct td *td_hash [TD_HASH_SIZE];
391 struct td *dl_start, *dl_end; /* the done list */
383 struct list_head pending; 392 struct list_head pending;
393 struct list_head eds_in_use; /* all EDs with at least 1 TD */
384 394
385 /* 395 /*
386 * driver state 396 * driver state
@@ -392,6 +402,8 @@ struct ohci_hcd {
392 unsigned long next_statechange; /* suspend/resume */ 402 unsigned long next_statechange; /* suspend/resume */
393 u32 fminterval; /* saved register */ 403 u32 fminterval; /* saved register */
394 unsigned autostop:1; /* rh auto stopping/stopped */ 404 unsigned autostop:1; /* rh auto stopping/stopped */
405 unsigned working:1;
406 unsigned restart_work:1;
395 407
396 unsigned long flags; /* for HC bugs */ 408 unsigned long flags; /* for HC bugs */
397#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */ 409#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
@@ -409,13 +421,12 @@ struct ohci_hcd {
409 421
410 // there are also chip quirks/bugs in init logic 422 // there are also chip quirks/bugs in init logic
411 423
412 struct work_struct nec_work; /* Worker for NEC quirk */ 424 unsigned prev_frame_no;
425 unsigned wdh_cnt, prev_wdh_cnt;
426 u32 prev_donehead;
427 struct timer_list io_watchdog;
413 428
414 /* Needed for ZF Micro quirk */ 429 struct work_struct nec_work; /* Worker for NEC quirk */
415 struct timer_list unlink_watchdog;
416 unsigned eds_scheduled;
417 struct ed *ed_to_check;
418 unsigned zf_delay;
419 430
420 struct dentry *debug_dir; 431 struct dentry *debug_dir;
421 struct dentry *debug_async; 432 struct dentry *debug_async;
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index e07248b6ab67..da5fb0e3c363 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -3826,49 +3826,36 @@ static int oxu_drv_probe(struct platform_device *pdev)
3826 dev_dbg(&pdev->dev, "IRQ resource %d\n", irq); 3826 dev_dbg(&pdev->dev, "IRQ resource %d\n", irq);
3827 3827
3828 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 3828 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3829 if (!res) { 3829 base = devm_ioremap_resource(&pdev->dev, res);
3830 dev_err(&pdev->dev, "no registers address! Check %s setup!\n", 3830 if (IS_ERR(base)) {
3831 dev_name(&pdev->dev)); 3831 ret = PTR_ERR(base);
3832 return -ENODEV; 3832 goto error;
3833 } 3833 }
3834 memstart = res->start; 3834 memstart = res->start;
3835 memlen = resource_size(res); 3835 memlen = resource_size(res);
3836 dev_dbg(&pdev->dev, "MEM resource %lx-%lx\n", memstart, memlen);
3837 if (!request_mem_region(memstart, memlen,
3838 oxu_hc_driver.description)) {
3839 dev_dbg(&pdev->dev, "memory area already in use\n");
3840 return -EBUSY;
3841 }
3842 3836
3843 ret = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING); 3837 ret = irq_set_irq_type(irq, IRQF_TRIGGER_FALLING);
3844 if (ret) { 3838 if (ret) {
3845 dev_err(&pdev->dev, "error setting irq type\n"); 3839 dev_err(&pdev->dev, "error setting irq type\n");
3846 ret = -EFAULT; 3840 ret = -EFAULT;
3847 goto error_set_irq_type; 3841 goto error;
3848 }
3849
3850 base = ioremap(memstart, memlen);
3851 if (!base) {
3852 dev_dbg(&pdev->dev, "error mapping memory\n");
3853 ret = -EFAULT;
3854 goto error_ioremap;
3855 } 3842 }
3856 3843
3857 /* Allocate a driver data struct to hold useful info for both 3844 /* Allocate a driver data struct to hold useful info for both
3858 * SPH & OTG devices 3845 * SPH & OTG devices
3859 */ 3846 */
3860 info = kzalloc(sizeof(struct oxu_info), GFP_KERNEL); 3847 info = devm_kzalloc(&pdev->dev, sizeof(struct oxu_info), GFP_KERNEL);
3861 if (!info) { 3848 if (!info) {
3862 dev_dbg(&pdev->dev, "error allocating memory\n"); 3849 dev_dbg(&pdev->dev, "error allocating memory\n");
3863 ret = -EFAULT; 3850 ret = -EFAULT;
3864 goto error_alloc; 3851 goto error;
3865 } 3852 }
3866 platform_set_drvdata(pdev, info); 3853 platform_set_drvdata(pdev, info);
3867 3854
3868 ret = oxu_init(pdev, memstart, memlen, base, irq); 3855 ret = oxu_init(pdev, memstart, memlen, base, irq);
3869 if (ret < 0) { 3856 if (ret < 0) {
3870 dev_dbg(&pdev->dev, "cannot init USB devices\n"); 3857 dev_dbg(&pdev->dev, "cannot init USB devices\n");
3871 goto error_init; 3858 goto error;
3872 } 3859 }
3873 3860
3874 dev_info(&pdev->dev, "devices enabled and running\n"); 3861 dev_info(&pdev->dev, "devices enabled and running\n");
@@ -3876,16 +3863,7 @@ static int oxu_drv_probe(struct platform_device *pdev)
3876 3863
3877 return 0; 3864 return 0;
3878 3865
3879error_init: 3866error:
3880 kfree(info);
3881
3882error_alloc:
3883 iounmap(base);
3884
3885error_set_irq_type:
3886error_ioremap:
3887 release_mem_region(memstart, memlen);
3888
3889 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret); 3867 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), ret);
3890 return ret; 3868 return ret;
3891} 3869}
@@ -3899,18 +3877,10 @@ static void oxu_remove(struct platform_device *pdev, struct usb_hcd *hcd)
3899static int oxu_drv_remove(struct platform_device *pdev) 3877static int oxu_drv_remove(struct platform_device *pdev)
3900{ 3878{
3901 struct oxu_info *info = platform_get_drvdata(pdev); 3879 struct oxu_info *info = platform_get_drvdata(pdev);
3902 unsigned long memstart = info->hcd[0]->rsrc_start,
3903 memlen = info->hcd[0]->rsrc_len;
3904 void *base = info->hcd[0]->regs;
3905 3880
3906 oxu_remove(pdev, info->hcd[0]); 3881 oxu_remove(pdev, info->hcd[0]);
3907 oxu_remove(pdev, info->hcd[1]); 3882 oxu_remove(pdev, info->hcd[1]);
3908 3883
3909 iounmap(base);
3910 release_mem_region(memstart, memlen);
3911
3912 kfree(info);
3913
3914 return 0; 3884 return 0;
3915} 3885}
3916 3886
diff --git a/drivers/usb/host/uhci-grlib.c b/drivers/usb/host/uhci-grlib.c
index ab25dc397e8b..05f57ffdf9ab 100644
--- a/drivers/usb/host/uhci-grlib.c
+++ b/drivers/usb/host/uhci-grlib.c
@@ -17,6 +17,7 @@
17 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu 17 * (C) Copyright 2004-2007 Alan Stern, stern@rowland.harvard.edu
18 */ 18 */
19 19
20#include <linux/device.h>
20#include <linux/of_irq.h> 21#include <linux/of_irq.h>
21#include <linux/of_address.h> 22#include <linux/of_address.h>
22#include <linux/of_platform.h> 23#include <linux/of_platform.h>
@@ -113,24 +114,17 @@ static int uhci_hcd_grlib_probe(struct platform_device *op)
113 hcd->rsrc_start = res.start; 114 hcd->rsrc_start = res.start;
114 hcd->rsrc_len = resource_size(&res); 115 hcd->rsrc_len = resource_size(&res);
115 116
116 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
117 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
118 rv = -EBUSY;
119 goto err_rmr;
120 }
121
122 irq = irq_of_parse_and_map(dn, 0); 117 irq = irq_of_parse_and_map(dn, 0);
123 if (irq == NO_IRQ) { 118 if (irq == NO_IRQ) {
124 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__); 119 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
125 rv = -EBUSY; 120 rv = -EBUSY;
126 goto err_irq; 121 goto err_usb;
127 } 122 }
128 123
129 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 124 hcd->regs = devm_ioremap_resource(&op->dev, &res);
130 if (!hcd->regs) { 125 if (IS_ERR(hcd->regs)) {
131 printk(KERN_ERR "%s: ioremap failed\n", __FILE__); 126 rv = PTR_ERR(hcd->regs);
132 rv = -ENOMEM; 127 goto err_irq;
133 goto err_ioremap;
134 } 128 }
135 129
136 uhci = hcd_to_uhci(hcd); 130 uhci = hcd_to_uhci(hcd);
@@ -139,18 +133,14 @@ static int uhci_hcd_grlib_probe(struct platform_device *op)
139 133
140 rv = usb_add_hcd(hcd, irq, 0); 134 rv = usb_add_hcd(hcd, irq, 0);
141 if (rv) 135 if (rv)
142 goto err_uhci; 136 goto err_irq;
143 137
144 device_wakeup_enable(hcd->self.controller); 138 device_wakeup_enable(hcd->self.controller);
145 return 0; 139 return 0;
146 140
147err_uhci:
148 iounmap(hcd->regs);
149err_ioremap:
150 irq_dispose_mapping(irq);
151err_irq: 141err_irq:
152 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 142 irq_dispose_mapping(irq);
153err_rmr: 143err_usb:
154 usb_put_hcd(hcd); 144 usb_put_hcd(hcd);
155 145
156 return rv; 146 return rv;
@@ -164,10 +154,7 @@ static int uhci_hcd_grlib_remove(struct platform_device *op)
164 154
165 usb_remove_hcd(hcd); 155 usb_remove_hcd(hcd);
166 156
167 iounmap(hcd->regs);
168 irq_dispose_mapping(hcd->irq); 157 irq_dispose_mapping(hcd->irq);
169 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
170
171 usb_put_hcd(hcd); 158 usb_put_hcd(hcd);
172 159
173 return 0; 160 return 0;
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 27f35e8f161b..a7de8e8bb458 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -591,7 +591,7 @@ static int uhci_start(struct usb_hcd *hcd)
591 591
592 uhci->frame = dma_alloc_coherent(uhci_dev(uhci), 592 uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
593 UHCI_NUMFRAMES * sizeof(*uhci->frame), 593 UHCI_NUMFRAMES * sizeof(*uhci->frame),
594 &uhci->frame_dma_handle, 0); 594 &uhci->frame_dma_handle, GFP_KERNEL);
595 if (!uhci->frame) { 595 if (!uhci->frame) {
596 dev_err(uhci_dev(uhci), 596 dev_err(uhci_dev(uhci),
597 "unable to allocate consistent memory for frame list\n"); 597 "unable to allocate consistent memory for frame list\n");
diff --git a/drivers/usb/host/uhci-platform.c b/drivers/usb/host/uhci-platform.c
index 01833ab2b5c3..b987f1d10058 100644
--- a/drivers/usb/host/uhci-platform.c
+++ b/drivers/usb/host/uhci-platform.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/of.h> 10#include <linux/of.h>
11#include <linux/device.h>
11#include <linux/platform_device.h> 12#include <linux/platform_device.h>
12 13
13static int uhci_platform_init(struct usb_hcd *hcd) 14static int uhci_platform_init(struct usb_hcd *hcd)
@@ -88,33 +89,22 @@ static int uhci_hcd_platform_probe(struct platform_device *pdev)
88 hcd->rsrc_start = res->start; 89 hcd->rsrc_start = res->start;
89 hcd->rsrc_len = resource_size(res); 90 hcd->rsrc_len = resource_size(res);
90 91
91 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 92 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
92 pr_err("%s: request_mem_region failed\n", __func__); 93 if (IS_ERR(hcd->regs)) {
93 ret = -EBUSY; 94 ret = PTR_ERR(hcd->regs);
94 goto err_rmr; 95 goto err_rmr;
95 } 96 }
96
97 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
98 if (!hcd->regs) {
99 pr_err("%s: ioremap failed\n", __func__);
100 ret = -ENOMEM;
101 goto err_irq;
102 }
103 uhci = hcd_to_uhci(hcd); 97 uhci = hcd_to_uhci(hcd);
104 98
105 uhci->regs = hcd->regs; 99 uhci->regs = hcd->regs;
106 100
107 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED); 101 ret = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
108 if (ret) 102 if (ret)
109 goto err_uhci; 103 goto err_rmr;
110 104
111 device_wakeup_enable(hcd->self.controller); 105 device_wakeup_enable(hcd->self.controller);
112 return 0; 106 return 0;
113 107
114err_uhci:
115 iounmap(hcd->regs);
116err_irq:
117 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
118err_rmr: 108err_rmr:
119 usb_put_hcd(hcd); 109 usb_put_hcd(hcd);
120 110
@@ -126,8 +116,6 @@ static int uhci_hcd_platform_remove(struct platform_device *pdev)
126 struct usb_hcd *hcd = platform_get_drvdata(pdev); 116 struct usb_hcd *hcd = platform_get_drvdata(pdev);
127 117
128 usb_remove_hcd(hcd); 118 usb_remove_hcd(hcd);
129 iounmap(hcd->regs);
130 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
131 usb_put_hcd(hcd); 119 usb_put_hcd(hcd);
132 120
133 return 0; 121 return 0;
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index e20520f42753..c22a3e15a16e 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -33,7 +33,7 @@
33#define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400 33#define PCI_DEVICE_ID_FRESCO_LOGIC_FL1400 0x1400
34 34
35#define PCI_VENDOR_ID_ETRON 0x1b6f 35#define PCI_VENDOR_ID_ETRON 0x1b6f
36#define PCI_DEVICE_ID_ASROCK_P67 0x7023 36#define PCI_DEVICE_ID_EJ168 0x7023
37 37
38#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31 38#define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI 0x8c31
39#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 39#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
@@ -101,6 +101,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
101 /* AMD PLL quirk */ 101 /* AMD PLL quirk */
102 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) 102 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
103 xhci->quirks |= XHCI_AMD_PLL_FIX; 103 xhci->quirks |= XHCI_AMD_PLL_FIX;
104
105 if (pdev->vendor == PCI_VENDOR_ID_AMD)
106 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
107
104 if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 108 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
105 xhci->quirks |= XHCI_LPM_SUPPORT; 109 xhci->quirks |= XHCI_LPM_SUPPORT;
106 xhci->quirks |= XHCI_INTEL_HOST; 110 xhci->quirks |= XHCI_INTEL_HOST;
@@ -140,9 +144,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
140 xhci->quirks |= XHCI_SPURIOUS_REBOOT; 144 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
141 } 145 }
142 if (pdev->vendor == PCI_VENDOR_ID_ETRON && 146 if (pdev->vendor == PCI_VENDOR_ID_ETRON &&
143 pdev->device == PCI_DEVICE_ID_ASROCK_P67) { 147 pdev->device == PCI_DEVICE_ID_EJ168) {
144 xhci->quirks |= XHCI_RESET_ON_RESUME; 148 xhci->quirks |= XHCI_RESET_ON_RESUME;
145 xhci->quirks |= XHCI_TRUST_TX_LENGTH; 149 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
150 xhci->quirks |= XHCI_BROKEN_STREAMS;
146 } 151 }
147 if (pdev->vendor == PCI_VENDOR_ID_RENESAS && 152 if (pdev->vendor == PCI_VENDOR_ID_RENESAS &&
148 pdev->device == 0x0015) 153 pdev->device == 0x0015)
@@ -150,6 +155,11 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
150 if (pdev->vendor == PCI_VENDOR_ID_VIA) 155 if (pdev->vendor == PCI_VENDOR_ID_VIA)
151 xhci->quirks |= XHCI_RESET_ON_RESUME; 156 xhci->quirks |= XHCI_RESET_ON_RESUME;
152 157
158 /* See https://bugzilla.kernel.org/show_bug.cgi?id=79511 */
159 if (pdev->vendor == PCI_VENDOR_ID_VIA &&
160 pdev->device == 0x3432)
161 xhci->quirks |= XHCI_BROKEN_STREAMS;
162
153 if (xhci->quirks & XHCI_RESET_ON_RESUME) 163 if (xhci->quirks & XHCI_RESET_ON_RESUME)
154 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, 164 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
155 "QUIRK: Resetting on resume"); 165 "QUIRK: Resetting on resume");
@@ -230,7 +240,8 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
230 goto put_usb3_hcd; 240 goto put_usb3_hcd;
231 /* Roothub already marked as USB 3.0 speed */ 241 /* Roothub already marked as USB 3.0 speed */
232 242
233 if (HCC_MAX_PSA(xhci->hcc_params) >= 4) 243 if (!(xhci->quirks & XHCI_BROKEN_STREAMS) &&
244 HCC_MAX_PSA(xhci->hcc_params) >= 4)
234 xhci->shared_hcd->can_do_streams = 1; 245 xhci->shared_hcd->can_do_streams = 1;
235 246
236 /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */ 247 /* USB-2 and USB-3 roothubs initialized, allow runtime pm suspend */
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 29d8adb5c8d1..1a0cf9f31e43 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -17,9 +17,11 @@
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/usb/xhci_pdriver.h>
20 21
21#include "xhci.h" 22#include "xhci.h"
22#include "xhci-mvebu.h" 23#include "xhci-mvebu.h"
24#include "xhci-rcar.h"
23 25
24static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci) 26static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
25{ 27{
@@ -34,11 +36,27 @@ static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
34/* called during probe() after chip reset completes */ 36/* called during probe() after chip reset completes */
35static int xhci_plat_setup(struct usb_hcd *hcd) 37static int xhci_plat_setup(struct usb_hcd *hcd)
36{ 38{
39 struct device_node *of_node = hcd->self.controller->of_node;
40 int ret;
41
42 if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") ||
43 of_device_is_compatible(of_node, "renesas,xhci-r8a7791")) {
44 ret = xhci_rcar_init_quirk(hcd);
45 if (ret)
46 return ret;
47 }
48
37 return xhci_gen_setup(hcd, xhci_plat_quirks); 49 return xhci_gen_setup(hcd, xhci_plat_quirks);
38} 50}
39 51
40static int xhci_plat_start(struct usb_hcd *hcd) 52static int xhci_plat_start(struct usb_hcd *hcd)
41{ 53{
54 struct device_node *of_node = hcd->self.controller->of_node;
55
56 if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") ||
57 of_device_is_compatible(of_node, "renesas,xhci-r8a7791"))
58 xhci_rcar_start(hcd);
59
42 return xhci_run(hcd); 60 return xhci_run(hcd);
43} 61}
44 62
@@ -90,10 +108,15 @@ static const struct hc_driver xhci_plat_xhci_driver = {
90 .hub_status_data = xhci_hub_status_data, 108 .hub_status_data = xhci_hub_status_data,
91 .bus_suspend = xhci_bus_suspend, 109 .bus_suspend = xhci_bus_suspend,
92 .bus_resume = xhci_bus_resume, 110 .bus_resume = xhci_bus_resume,
111
112 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
113 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
93}; 114};
94 115
95static int xhci_plat_probe(struct platform_device *pdev) 116static int xhci_plat_probe(struct platform_device *pdev)
96{ 117{
118 struct device_node *node = pdev->dev.of_node;
119 struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev);
97 const struct hc_driver *driver; 120 const struct hc_driver *driver;
98 struct xhci_hcd *xhci; 121 struct xhci_hcd *xhci;
99 struct resource *res; 122 struct resource *res;
@@ -140,20 +163,12 @@ static int xhci_plat_probe(struct platform_device *pdev)
140 hcd->rsrc_start = res->start; 163 hcd->rsrc_start = res->start;
141 hcd->rsrc_len = resource_size(res); 164 hcd->rsrc_len = resource_size(res);
142 165
143 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, 166 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
144 driver->description)) { 167 if (IS_ERR(hcd->regs)) {
145 dev_dbg(&pdev->dev, "controller already in use\n"); 168 ret = PTR_ERR(hcd->regs);
146 ret = -EBUSY;
147 goto put_hcd; 169 goto put_hcd;
148 } 170 }
149 171
150 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
151 if (!hcd->regs) {
152 dev_dbg(&pdev->dev, "error mapping memory\n");
153 ret = -EFAULT;
154 goto release_mem_region;
155 }
156
157 /* 172 /*
158 * Not all platforms have a clk so it is not an error if the 173 * Not all platforms have a clk so it is not an error if the
159 * clock does not exists. 174 * clock does not exists.
@@ -162,7 +177,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
162 if (!IS_ERR(clk)) { 177 if (!IS_ERR(clk)) {
163 ret = clk_prepare_enable(clk); 178 ret = clk_prepare_enable(clk);
164 if (ret) 179 if (ret)
165 goto unmap_registers; 180 goto put_hcd;
166 } 181 }
167 182
168 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 183 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
@@ -182,6 +197,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
182 goto dealloc_usb2_hcd; 197 goto dealloc_usb2_hcd;
183 } 198 }
184 199
200 if ((node && of_property_read_bool(node, "usb3-lpm-capable")) ||
201 (pdata && pdata->usb3_lpm_capable))
202 xhci->quirks |= XHCI_LPM_SUPPORT;
185 /* 203 /*
186 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset) 204 * Set the xHCI pointer before xhci_plat_setup() (aka hcd_driver.reset)
187 * is called by usb_add_hcd(). 205 * is called by usb_add_hcd().
@@ -207,12 +225,6 @@ disable_clk:
207 if (!IS_ERR(clk)) 225 if (!IS_ERR(clk))
208 clk_disable_unprepare(clk); 226 clk_disable_unprepare(clk);
209 227
210unmap_registers:
211 iounmap(hcd->regs);
212
213release_mem_region:
214 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
215
216put_hcd: 228put_hcd:
217 usb_put_hcd(hcd); 229 usb_put_hcd(hcd);
218 230
@@ -231,8 +243,6 @@ static int xhci_plat_remove(struct platform_device *dev)
231 usb_remove_hcd(hcd); 243 usb_remove_hcd(hcd);
232 if (!IS_ERR(clk)) 244 if (!IS_ERR(clk))
233 clk_disable_unprepare(clk); 245 clk_disable_unprepare(clk);
234 iounmap(hcd->regs);
235 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
236 usb_put_hcd(hcd); 246 usb_put_hcd(hcd);
237 kfree(xhci); 247 kfree(xhci);
238 248
@@ -270,6 +280,8 @@ static const struct of_device_id usb_xhci_of_match[] = {
270 { .compatible = "xhci-platform" }, 280 { .compatible = "xhci-platform" },
271 { .compatible = "marvell,armada-375-xhci"}, 281 { .compatible = "marvell,armada-375-xhci"},
272 { .compatible = "marvell,armada-380-xhci"}, 282 { .compatible = "marvell,armada-380-xhci"},
283 { .compatible = "renesas,xhci-r8a7790"},
284 { .compatible = "renesas,xhci-r8a7791"},
273 { }, 285 { },
274}; 286};
275MODULE_DEVICE_TABLE(of, usb_xhci_of_match); 287MODULE_DEVICE_TABLE(of, usb_xhci_of_match);
diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
new file mode 100644
index 000000000000..ff0d1b44ea58
--- /dev/null
+++ b/drivers/usb/host/xhci-rcar.c
@@ -0,0 +1,148 @@
1/*
2 * xHCI host controller driver for R-Car SoCs
3 *
4 * Copyright (C) 2014 Renesas Electronics Corporation
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/firmware.h>
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/usb/phy.h>
15
16#include "xhci.h"
17#include "xhci-rcar.h"
18
19#define FIRMWARE_NAME "r8a779x_usb3_v1.dlmem"
20MODULE_FIRMWARE(FIRMWARE_NAME);
21
22/*** Register Offset ***/
23#define RCAR_USB3_INT_ENA 0x224 /* Interrupt Enable */
24#define RCAR_USB3_DL_CTRL 0x250 /* FW Download Control & Status */
25#define RCAR_USB3_FW_DATA0 0x258 /* FW Data0 */
26
27#define RCAR_USB3_LCLK 0xa44 /* LCLK Select */
28#define RCAR_USB3_CONF1 0xa48 /* USB3.0 Configuration1 */
29#define RCAR_USB3_CONF2 0xa5c /* USB3.0 Configuration2 */
30#define RCAR_USB3_CONF3 0xaa8 /* USB3.0 Configuration3 */
31#define RCAR_USB3_RX_POL 0xab0 /* USB3.0 RX Polarity */
32#define RCAR_USB3_TX_POL 0xab8 /* USB3.0 TX Polarity */
33
34/*** Register Settings ***/
35/* Interrupt Enable */
36#define RCAR_USB3_INT_XHC_ENA 0x00000001
37#define RCAR_USB3_INT_PME_ENA 0x00000002
38#define RCAR_USB3_INT_HSE_ENA 0x00000004
39#define RCAR_USB3_INT_ENA_VAL (RCAR_USB3_INT_XHC_ENA | \
40 RCAR_USB3_INT_PME_ENA | RCAR_USB3_INT_HSE_ENA)
41
42/* FW Download Control & Status */
43#define RCAR_USB3_DL_CTRL_ENABLE 0x00000001
44#define RCAR_USB3_DL_CTRL_FW_SUCCESS 0x00000010
45#define RCAR_USB3_DL_CTRL_FW_SET_DATA0 0x00000100
46
47/* LCLK Select */
48#define RCAR_USB3_LCLK_ENA_VAL 0x01030001
49
50/* USB3.0 Configuration */
51#define RCAR_USB3_CONF1_VAL 0x00030204
52#define RCAR_USB3_CONF2_VAL 0x00030300
53#define RCAR_USB3_CONF3_VAL 0x13802007
54
55/* USB3.0 Polarity */
56#define RCAR_USB3_RX_POL_VAL BIT(21)
57#define RCAR_USB3_TX_POL_VAL BIT(4)
58
59void xhci_rcar_start(struct usb_hcd *hcd)
60{
61 u32 temp;
62
63 if (hcd->regs != NULL) {
64 /* Interrupt Enable */
65 temp = readl(hcd->regs + RCAR_USB3_INT_ENA);
66 temp |= RCAR_USB3_INT_ENA_VAL;
67 writel(temp, hcd->regs + RCAR_USB3_INT_ENA);
68 /* LCLK Select */
69 writel(RCAR_USB3_LCLK_ENA_VAL, hcd->regs + RCAR_USB3_LCLK);
70 /* USB3.0 Configuration */
71 writel(RCAR_USB3_CONF1_VAL, hcd->regs + RCAR_USB3_CONF1);
72 writel(RCAR_USB3_CONF2_VAL, hcd->regs + RCAR_USB3_CONF2);
73 writel(RCAR_USB3_CONF3_VAL, hcd->regs + RCAR_USB3_CONF3);
74 /* USB3.0 Polarity */
75 writel(RCAR_USB3_RX_POL_VAL, hcd->regs + RCAR_USB3_RX_POL);
76 writel(RCAR_USB3_TX_POL_VAL, hcd->regs + RCAR_USB3_TX_POL);
77 }
78}
79
80static int xhci_rcar_download_firmware(struct device *dev, void __iomem *regs)
81{
82 const struct firmware *fw;
83 int retval, index, j, time;
84 int timeout = 10000;
85 u32 data, val, temp;
86
87 /* request R-Car USB3.0 firmware */
88 retval = request_firmware(&fw, FIRMWARE_NAME, dev);
89 if (retval)
90 return retval;
91
92 /* download R-Car USB3.0 firmware */
93 temp = readl(regs + RCAR_USB3_DL_CTRL);
94 temp |= RCAR_USB3_DL_CTRL_ENABLE;
95 writel(temp, regs + RCAR_USB3_DL_CTRL);
96
97 for (index = 0; index < fw->size; index += 4) {
98 /* to avoid reading beyond the end of the buffer */
99 for (data = 0, j = 3; j >= 0; j--) {
100 if ((j + index) < fw->size)
101 data |= fw->data[index + j] << (8 * j);
102 }
103 writel(data, regs + RCAR_USB3_FW_DATA0);
104 temp = readl(regs + RCAR_USB3_DL_CTRL);
105 temp |= RCAR_USB3_DL_CTRL_FW_SET_DATA0;
106 writel(temp, regs + RCAR_USB3_DL_CTRL);
107
108 for (time = 0; time < timeout; time++) {
109 val = readl(regs + RCAR_USB3_DL_CTRL);
110 if ((val & RCAR_USB3_DL_CTRL_FW_SET_DATA0) == 0)
111 break;
112 udelay(1);
113 }
114 if (time == timeout) {
115 retval = -ETIMEDOUT;
116 break;
117 }
118 }
119
120 temp = readl(regs + RCAR_USB3_DL_CTRL);
121 temp &= ~RCAR_USB3_DL_CTRL_ENABLE;
122 writel(temp, regs + RCAR_USB3_DL_CTRL);
123
124 for (time = 0; time < timeout; time++) {
125 val = readl(regs + RCAR_USB3_DL_CTRL);
126 if (val & RCAR_USB3_DL_CTRL_FW_SUCCESS) {
127 retval = 0;
128 break;
129 }
130 udelay(1);
131 }
132 if (time == timeout)
133 retval = -ETIMEDOUT;
134
135 release_firmware(fw);
136
137 return retval;
138}
139
140/* This function needs to initialize a "phy" of usb before */
141int xhci_rcar_init_quirk(struct usb_hcd *hcd)
142{
143 /* If hcd->regs is NULL, we don't just call the following function */
144 if (!hcd->regs)
145 return 0;
146
147 return xhci_rcar_download_firmware(hcd->self.controller, hcd->regs);
148}
diff --git a/drivers/usb/host/xhci-rcar.h b/drivers/usb/host/xhci-rcar.h
new file mode 100644
index 000000000000..58501256715d
--- /dev/null
+++ b/drivers/usb/host/xhci-rcar.h
@@ -0,0 +1,27 @@
1/*
2 * drivers/usb/host/xhci-rcar.h
3 *
4 * Copyright (C) 2014 Renesas Electronics Corporation
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 */
10
11#ifndef _XHCI_RCAR_H
12#define _XHCI_RCAR_H
13
14#if IS_ENABLED(CONFIG_USB_XHCI_RCAR)
15void xhci_rcar_start(struct usb_hcd *hcd);
16int xhci_rcar_init_quirk(struct usb_hcd *hcd);
17#else
18static inline void xhci_rcar_start(struct usb_hcd *hcd)
19{
20}
21
22static inline int xhci_rcar_init_quirk(struct usb_hcd *hcd)
23{
24 return 0;
25}
26#endif
27#endif /* _XHCI_RCAR_H */
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 749fc68eb5c1..abed30b82905 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -364,32 +364,6 @@ static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci,
364 } 364 }
365} 365}
366 366
367/*
368 * Find the segment that trb is in. Start searching in start_seg.
369 * If we must move past a segment that has a link TRB with a toggle cycle state
370 * bit set, then we will toggle the value pointed at by cycle_state.
371 */
372static struct xhci_segment *find_trb_seg(
373 struct xhci_segment *start_seg,
374 union xhci_trb *trb, int *cycle_state)
375{
376 struct xhci_segment *cur_seg = start_seg;
377 struct xhci_generic_trb *generic_trb;
378
379 while (cur_seg->trbs > trb ||
380 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
381 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic;
382 if (generic_trb->field[3] & cpu_to_le32(LINK_TOGGLE))
383 *cycle_state ^= 0x1;
384 cur_seg = cur_seg->next;
385 if (cur_seg == start_seg)
386 /* Looped over the entire list. Oops! */
387 return NULL;
388 }
389 return cur_seg;
390}
391
392
393static struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, 367static struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
394 unsigned int slot_id, unsigned int ep_index, 368 unsigned int slot_id, unsigned int ep_index,
395 unsigned int stream_id) 369 unsigned int stream_id)
@@ -459,9 +433,12 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
459 struct xhci_virt_device *dev = xhci->devs[slot_id]; 433 struct xhci_virt_device *dev = xhci->devs[slot_id];
460 struct xhci_virt_ep *ep = &dev->eps[ep_index]; 434 struct xhci_virt_ep *ep = &dev->eps[ep_index];
461 struct xhci_ring *ep_ring; 435 struct xhci_ring *ep_ring;
462 struct xhci_generic_trb *trb; 436 struct xhci_segment *new_seg;
437 union xhci_trb *new_deq;
463 dma_addr_t addr; 438 dma_addr_t addr;
464 u64 hw_dequeue; 439 u64 hw_dequeue;
440 bool cycle_found = false;
441 bool td_last_trb_found = false;
465 442
466 ep_ring = xhci_triad_to_transfer_ring(xhci, slot_id, 443 ep_ring = xhci_triad_to_transfer_ring(xhci, slot_id,
467 ep_index, stream_id); 444 ep_index, stream_id);
@@ -486,45 +463,45 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
486 hw_dequeue = le64_to_cpu(ep_ctx->deq); 463 hw_dequeue = le64_to_cpu(ep_ctx->deq);
487 } 464 }
488 465
489 /* Find virtual address and segment of hardware dequeue pointer */ 466 new_seg = ep_ring->deq_seg;
490 state->new_deq_seg = ep_ring->deq_seg; 467 new_deq = ep_ring->dequeue;
491 state->new_deq_ptr = ep_ring->dequeue; 468 state->new_cycle_state = hw_dequeue & 0x1;
492 while (xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr) 469
493 != (dma_addr_t)(hw_dequeue & ~0xf)) {
494 next_trb(xhci, ep_ring, &state->new_deq_seg,
495 &state->new_deq_ptr);
496 if (state->new_deq_ptr == ep_ring->dequeue) {
497 WARN_ON(1);
498 return;
499 }
500 }
501 /* 470 /*
502 * Find cycle state for last_trb, starting at old cycle state of 471 * We want to find the pointer, segment and cycle state of the new trb
503 * hw_dequeue. If there is only one segment ring, find_trb_seg() will 472 * (the one after current TD's last_trb). We know the cycle state at
504 * return immediately and cannot toggle the cycle state if this search 473 * hw_dequeue, so walk the ring until both hw_dequeue and last_trb are
505 * wraps around, so add one more toggle manually in that case. 474 * found.
506 */ 475 */
507 state->new_cycle_state = hw_dequeue & 0x1; 476 do {
508 if (ep_ring->first_seg == ep_ring->first_seg->next && 477 if (!cycle_found && xhci_trb_virt_to_dma(new_seg, new_deq)
509 cur_td->last_trb < state->new_deq_ptr) 478 == (dma_addr_t)(hw_dequeue & ~0xf)) {
510 state->new_cycle_state ^= 0x1; 479 cycle_found = true;
480 if (td_last_trb_found)
481 break;
482 }
483 if (new_deq == cur_td->last_trb)
484 td_last_trb_found = true;
511 485
512 state->new_deq_ptr = cur_td->last_trb; 486 if (cycle_found &&
513 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, 487 TRB_TYPE_LINK_LE32(new_deq->generic.field[3]) &&
514 "Finding segment containing last TRB in TD."); 488 new_deq->generic.field[3] & cpu_to_le32(LINK_TOGGLE))
515 state->new_deq_seg = find_trb_seg(state->new_deq_seg, 489 state->new_cycle_state ^= 0x1;
516 state->new_deq_ptr, &state->new_cycle_state);
517 if (!state->new_deq_seg) {
518 WARN_ON(1);
519 return;
520 }
521 490
522 /* Increment to find next TRB after last_trb. Cycle if appropriate. */ 491 next_trb(xhci, ep_ring, &new_seg, &new_deq);
523 trb = &state->new_deq_ptr->generic; 492
524 if (TRB_TYPE_LINK_LE32(trb->field[3]) && 493 /* Search wrapped around, bail out */
525 (trb->field[3] & cpu_to_le32(LINK_TOGGLE))) 494 if (new_deq == ep->ring->dequeue) {
526 state->new_cycle_state ^= 0x1; 495 xhci_err(xhci, "Error: Failed finding new dequeue state\n");
527 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); 496 state->new_deq_seg = NULL;
497 state->new_deq_ptr = NULL;
498 return;
499 }
500
501 } while (!cycle_found || !td_last_trb_found);
502
503 state->new_deq_seg = new_seg;
504 state->new_deq_ptr = new_deq;
528 505
529 /* Don't update the ring cycle state for the producer (us). */ 506 /* Don't update the ring cycle state for the producer (us). */
530 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb, 507 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
@@ -1118,6 +1095,10 @@ static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id,
1118 if (xhci->quirks & XHCI_RESET_EP_QUIRK) { 1095 if (xhci->quirks & XHCI_RESET_EP_QUIRK) {
1119 struct xhci_command *command; 1096 struct xhci_command *command;
1120 command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); 1097 command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC);
1098 if (!command) {
1099 xhci_warn(xhci, "WARN Cannot submit cfg ep: ENOMEM\n");
1100 return;
1101 }
1121 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, 1102 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
1122 "Queueing configure endpoint command"); 1103 "Queueing configure endpoint command");
1123 xhci_queue_configure_endpoint(xhci, command, 1104 xhci_queue_configure_endpoint(xhci, command,
@@ -2483,7 +2464,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
2483 * last TRB of the previous TD. The command completion handle 2464 * last TRB of the previous TD. The command completion handle
2484 * will take care the rest. 2465 * will take care the rest.
2485 */ 2466 */
2486 if (!event_seg && trb_comp_code == COMP_STOP_INVAL) { 2467 if (!event_seg && (trb_comp_code == COMP_STOP ||
2468 trb_comp_code == COMP_STOP_INVAL)) {
2487 ret = 0; 2469 ret = 0;
2488 goto cleanup; 2470 goto cleanup;
2489 } 2471 }
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 7436d5f5e67a..c020b094fe7d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1553,6 +1553,10 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1553 */ 1553 */
1554 if (!(ep->ep_state & EP_HALT_PENDING)) { 1554 if (!(ep->ep_state & EP_HALT_PENDING)) {
1555 command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC); 1555 command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC);
1556 if (!command) {
1557 ret = -ENOMEM;
1558 goto done;
1559 }
1556 ep->ep_state |= EP_HALT_PENDING; 1560 ep->ep_state |= EP_HALT_PENDING;
1557 ep->stop_cmds_pending++; 1561 ep->stop_cmds_pending++;
1558 ep->stop_cmd_timer.expires = jiffies + 1562 ep->stop_cmd_timer.expires = jiffies +
@@ -1586,12 +1590,10 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1586 struct xhci_hcd *xhci; 1590 struct xhci_hcd *xhci;
1587 struct xhci_container_ctx *in_ctx, *out_ctx; 1591 struct xhci_container_ctx *in_ctx, *out_ctx;
1588 struct xhci_input_control_ctx *ctrl_ctx; 1592 struct xhci_input_control_ctx *ctrl_ctx;
1589 struct xhci_slot_ctx *slot_ctx;
1590 unsigned int last_ctx;
1591 unsigned int ep_index; 1593 unsigned int ep_index;
1592 struct xhci_ep_ctx *ep_ctx; 1594 struct xhci_ep_ctx *ep_ctx;
1593 u32 drop_flag; 1595 u32 drop_flag;
1594 u32 new_add_flags, new_drop_flags, new_slot_info; 1596 u32 new_add_flags, new_drop_flags;
1595 int ret; 1597 int ret;
1596 1598
1597 ret = xhci_check_args(hcd, udev, ep, 1, true, __func__); 1599 ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
@@ -1638,24 +1640,13 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1638 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag); 1640 ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag);
1639 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags); 1641 new_add_flags = le32_to_cpu(ctrl_ctx->add_flags);
1640 1642
1641 last_ctx = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags));
1642 slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
1643 /* Update the last valid endpoint context, if we deleted the last one */
1644 if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) >
1645 LAST_CTX(last_ctx)) {
1646 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
1647 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx));
1648 }
1649 new_slot_info = le32_to_cpu(slot_ctx->dev_info);
1650
1651 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); 1643 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep);
1652 1644
1653 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n", 1645 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n",
1654 (unsigned int) ep->desc.bEndpointAddress, 1646 (unsigned int) ep->desc.bEndpointAddress,
1655 udev->slot_id, 1647 udev->slot_id,
1656 (unsigned int) new_drop_flags, 1648 (unsigned int) new_drop_flags,
1657 (unsigned int) new_add_flags, 1649 (unsigned int) new_add_flags);
1658 (unsigned int) new_slot_info);
1659 return 0; 1650 return 0;
1660} 1651}
1661 1652
@@ -1678,11 +1669,9 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1678 struct xhci_hcd *xhci; 1669 struct xhci_hcd *xhci;
1679 struct xhci_container_ctx *in_ctx, *out_ctx; 1670 struct xhci_container_ctx *in_ctx, *out_ctx;
1680 unsigned int ep_index; 1671 unsigned int ep_index;
1681 struct xhci_slot_ctx *slot_ctx;
1682 struct xhci_input_control_ctx *ctrl_ctx; 1672 struct xhci_input_control_ctx *ctrl_ctx;
1683 u32 added_ctxs; 1673 u32 added_ctxs;
1684 unsigned int last_ctx; 1674 u32 new_add_flags, new_drop_flags;
1685 u32 new_add_flags, new_drop_flags, new_slot_info;
1686 struct xhci_virt_device *virt_dev; 1675 struct xhci_virt_device *virt_dev;
1687 int ret = 0; 1676 int ret = 0;
1688 1677
@@ -1697,7 +1686,6 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1697 return -ENODEV; 1686 return -ENODEV;
1698 1687
1699 added_ctxs = xhci_get_endpoint_flag(&ep->desc); 1688 added_ctxs = xhci_get_endpoint_flag(&ep->desc);
1700 last_ctx = xhci_last_valid_endpoint(added_ctxs);
1701 if (added_ctxs == SLOT_FLAG || added_ctxs == EP0_FLAG) { 1689 if (added_ctxs == SLOT_FLAG || added_ctxs == EP0_FLAG) {
1702 /* FIXME when we have to issue an evaluate endpoint command to 1690 /* FIXME when we have to issue an evaluate endpoint command to
1703 * deal with ep0 max packet size changing once we get the 1691 * deal with ep0 max packet size changing once we get the
@@ -1763,24 +1751,14 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
1763 */ 1751 */
1764 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags); 1752 new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags);
1765 1753
1766 slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
1767 /* Update the last valid endpoint context, if we just added one past */
1768 if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) <
1769 LAST_CTX(last_ctx)) {
1770 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
1771 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx));
1772 }
1773 new_slot_info = le32_to_cpu(slot_ctx->dev_info);
1774
1775 /* Store the usb_device pointer for later use */ 1754 /* Store the usb_device pointer for later use */
1776 ep->hcpriv = udev; 1755 ep->hcpriv = udev;
1777 1756
1778 xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x, new slot info = %#x\n", 1757 xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n",
1779 (unsigned int) ep->desc.bEndpointAddress, 1758 (unsigned int) ep->desc.bEndpointAddress,
1780 udev->slot_id, 1759 udev->slot_id,
1781 (unsigned int) new_drop_flags, 1760 (unsigned int) new_drop_flags,
1782 (unsigned int) new_add_flags, 1761 (unsigned int) new_add_flags);
1783 (unsigned int) new_slot_info);
1784 return 0; 1762 return 0;
1785} 1763}
1786 1764
@@ -1830,15 +1808,15 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1830 ret = -ETIME; 1808 ret = -ETIME;
1831 break; 1809 break;
1832 case COMP_ENOMEM: 1810 case COMP_ENOMEM:
1833 dev_warn(&udev->dev, "Not enough host controller resources " 1811 dev_warn(&udev->dev,
1834 "for new device state.\n"); 1812 "Not enough host controller resources for new device state.\n");
1835 ret = -ENOMEM; 1813 ret = -ENOMEM;
1836 /* FIXME: can we allocate more resources for the HC? */ 1814 /* FIXME: can we allocate more resources for the HC? */
1837 break; 1815 break;
1838 case COMP_BW_ERR: 1816 case COMP_BW_ERR:
1839 case COMP_2ND_BW_ERR: 1817 case COMP_2ND_BW_ERR:
1840 dev_warn(&udev->dev, "Not enough bandwidth " 1818 dev_warn(&udev->dev,
1841 "for new device state.\n"); 1819 "Not enough bandwidth for new device state.\n");
1842 ret = -ENOSPC; 1820 ret = -ENOSPC;
1843 /* FIXME: can we go back to the old state? */ 1821 /* FIXME: can we go back to the old state? */
1844 break; 1822 break;
@@ -1850,8 +1828,8 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1850 ret = -EINVAL; 1828 ret = -EINVAL;
1851 break; 1829 break;
1852 case COMP_DEV_ERR: 1830 case COMP_DEV_ERR:
1853 dev_warn(&udev->dev, "ERROR: Incompatible device for endpoint " 1831 dev_warn(&udev->dev,
1854 "configure command.\n"); 1832 "ERROR: Incompatible device for endpoint configure command.\n");
1855 ret = -ENODEV; 1833 ret = -ENODEV;
1856 break; 1834 break;
1857 case COMP_SUCCESS: 1835 case COMP_SUCCESS:
@@ -1860,8 +1838,8 @@ static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1860 ret = 0; 1838 ret = 0;
1861 break; 1839 break;
1862 default: 1840 default:
1863 xhci_err(xhci, "ERROR: unexpected command completion " 1841 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n",
1864 "code 0x%x.\n", *cmd_status); 1842 *cmd_status);
1865 ret = -EINVAL; 1843 ret = -EINVAL;
1866 break; 1844 break;
1867 } 1845 }
@@ -1881,24 +1859,24 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
1881 ret = -ETIME; 1859 ret = -ETIME;
1882 break; 1860 break;
1883 case COMP_EINVAL: 1861 case COMP_EINVAL:
1884 dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate " 1862 dev_warn(&udev->dev,
1885 "context command.\n"); 1863 "WARN: xHCI driver setup invalid evaluate context command.\n");
1886 ret = -EINVAL; 1864 ret = -EINVAL;
1887 break; 1865 break;
1888 case COMP_EBADSLT: 1866 case COMP_EBADSLT:
1889 dev_warn(&udev->dev, "WARN: slot not enabled for" 1867 dev_warn(&udev->dev,
1890 "evaluate context command.\n"); 1868 "WARN: slot not enabled for evaluate context command.\n");
1891 ret = -EINVAL; 1869 ret = -EINVAL;
1892 break; 1870 break;
1893 case COMP_CTX_STATE: 1871 case COMP_CTX_STATE:
1894 dev_warn(&udev->dev, "WARN: invalid context state for " 1872 dev_warn(&udev->dev,
1895 "evaluate context command.\n"); 1873 "WARN: invalid context state for evaluate context command.\n");
1896 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1); 1874 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1);
1897 ret = -EINVAL; 1875 ret = -EINVAL;
1898 break; 1876 break;
1899 case COMP_DEV_ERR: 1877 case COMP_DEV_ERR:
1900 dev_warn(&udev->dev, "ERROR: Incompatible device for evaluate " 1878 dev_warn(&udev->dev,
1901 "context command.\n"); 1879 "ERROR: Incompatible device for evaluate context command.\n");
1902 ret = -ENODEV; 1880 ret = -ENODEV;
1903 break; 1881 break;
1904 case COMP_MEL_ERR: 1882 case COMP_MEL_ERR:
@@ -1912,8 +1890,8 @@ static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
1912 ret = 0; 1890 ret = 0;
1913 break; 1891 break;
1914 default: 1892 default:
1915 xhci_err(xhci, "ERROR: unexpected command completion " 1893 xhci_err(xhci, "ERROR: unexpected command completion code 0x%x.\n",
1916 "code 0x%x.\n", *cmd_status); 1894 *cmd_status);
1917 ret = -EINVAL; 1895 ret = -EINVAL;
1918 break; 1896 break;
1919 } 1897 }
@@ -2750,8 +2728,19 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
2750 ret = 0; 2728 ret = 0;
2751 goto command_cleanup; 2729 goto command_cleanup;
2752 } 2730 }
2753 xhci_dbg(xhci, "New Input Control Context:\n"); 2731 /* Fix up Context Entries field. Minimum value is EP0 == BIT(1). */
2754 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); 2732 slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
2733 for (i = 31; i >= 1; i--) {
2734 __le32 le32 = cpu_to_le32(BIT(i));
2735
2736 if ((virt_dev->eps[i-1].ring && !(ctrl_ctx->drop_flags & le32))
2737 || (ctrl_ctx->add_flags & le32) || i == 1) {
2738 slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
2739 slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(i));
2740 break;
2741 }
2742 }
2743 xhci_dbg(xhci, "New Input Control Context:\n");
2755 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2744 xhci_dbg_ctx(xhci, virt_dev->in_ctx,
2756 LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info))); 2745 LAST_CTX_TO_EP_NUM(le32_to_cpu(slot_ctx->dev_info)));
2757 2746
@@ -2891,6 +2880,9 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
2891 ep_index, ep->stopped_stream, ep->stopped_td, 2880 ep_index, ep->stopped_stream, ep->stopped_td,
2892 &deq_state); 2881 &deq_state);
2893 2882
2883 if (!deq_state.new_deq_ptr || !deq_state.new_deq_seg)
2884 return;
2885
2894 /* HW with the reset endpoint quirk will use the saved dequeue state to 2886 /* HW with the reset endpoint quirk will use the saved dequeue state to
2895 * issue a configure endpoint command later. 2887 * issue a configure endpoint command later.
2896 */ 2888 */
@@ -3163,7 +3155,8 @@ int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
3163 num_streams); 3155 num_streams);
3164 3156
3165 /* MaxPSASize value 0 (2 streams) means streams are not supported */ 3157 /* MaxPSASize value 0 (2 streams) means streams are not supported */
3166 if (HCC_MAX_PSA(xhci->hcc_params) < 4) { 3158 if ((xhci->quirks & XHCI_BROKEN_STREAMS) ||
3159 HCC_MAX_PSA(xhci->hcc_params) < 4) {
3167 xhci_dbg(xhci, "xHCI controller does not support streams.\n"); 3160 xhci_dbg(xhci, "xHCI controller does not support streams.\n");
3168 return -ENOSYS; 3161 return -ENOSYS;
3169 } 3162 }
@@ -4303,8 +4296,7 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev,
4303 return USB3_LPM_DISABLED; 4296 return USB3_LPM_DISABLED;
4304} 4297}
4305 4298
4306/* Returns the hub-encoded U1 timeout value. 4299/* The U1 timeout should be the maximum of the following values:
4307 * The U1 timeout should be the maximum of the following values:
4308 * - For control endpoints, U1 system exit latency (SEL) * 3 4300 * - For control endpoints, U1 system exit latency (SEL) * 3
4309 * - For bulk endpoints, U1 SEL * 5 4301 * - For bulk endpoints, U1 SEL * 5
4310 * - For interrupt endpoints: 4302 * - For interrupt endpoints:
@@ -4312,7 +4304,8 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev,
4312 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2) 4304 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
4313 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2) 4305 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
4314 */ 4306 */
4315static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev, 4307static unsigned long long xhci_calculate_intel_u1_timeout(
4308 struct usb_device *udev,
4316 struct usb_endpoint_descriptor *desc) 4309 struct usb_endpoint_descriptor *desc)
4317{ 4310{
4318 unsigned long long timeout_ns; 4311 unsigned long long timeout_ns;
@@ -4344,11 +4337,28 @@ static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev,
4344 return 0; 4337 return 0;
4345 } 4338 }
4346 4339
4347 /* The U1 timeout is encoded in 1us intervals. */ 4340 return timeout_ns;
4348 timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000); 4341}
4349 /* Don't return a timeout of zero, because that's USB3_LPM_DISABLED. */ 4342
4343/* Returns the hub-encoded U1 timeout value. */
4344static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci,
4345 struct usb_device *udev,
4346 struct usb_endpoint_descriptor *desc)
4347{
4348 unsigned long long timeout_ns;
4349
4350 if (xhci->quirks & XHCI_INTEL_HOST)
4351 timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc);
4352 else
4353 timeout_ns = udev->u1_params.sel;
4354
4355 /* The U1 timeout is encoded in 1us intervals.
4356 * Don't return a timeout of zero, because that's USB3_LPM_DISABLED.
4357 */
4350 if (timeout_ns == USB3_LPM_DISABLED) 4358 if (timeout_ns == USB3_LPM_DISABLED)
4351 timeout_ns++; 4359 timeout_ns = 1;
4360 else
4361 timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000);
4352 4362
4353 /* If the necessary timeout value is bigger than what we can set in the 4363 /* If the necessary timeout value is bigger than what we can set in the
4354 * USB 3.0 hub, we have to disable hub-initiated U1. 4364 * USB 3.0 hub, we have to disable hub-initiated U1.
@@ -4360,14 +4370,14 @@ static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev,
4360 return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U1); 4370 return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U1);
4361} 4371}
4362 4372
4363/* Returns the hub-encoded U2 timeout value. 4373/* The U2 timeout should be the maximum of:
4364 * The U2 timeout should be the maximum of:
4365 * - 10 ms (to avoid the bandwidth impact on the scheduler) 4374 * - 10 ms (to avoid the bandwidth impact on the scheduler)
4366 * - largest bInterval of any active periodic endpoint (to avoid going 4375 * - largest bInterval of any active periodic endpoint (to avoid going
4367 * into lower power link states between intervals). 4376 * into lower power link states between intervals).
4368 * - the U2 Exit Latency of the device 4377 * - the U2 Exit Latency of the device
4369 */ 4378 */
4370static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev, 4379static unsigned long long xhci_calculate_intel_u2_timeout(
4380 struct usb_device *udev,
4371 struct usb_endpoint_descriptor *desc) 4381 struct usb_endpoint_descriptor *desc)
4372{ 4382{
4373 unsigned long long timeout_ns; 4383 unsigned long long timeout_ns;
@@ -4383,6 +4393,21 @@ static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev,
4383 if (u2_del_ns > timeout_ns) 4393 if (u2_del_ns > timeout_ns)
4384 timeout_ns = u2_del_ns; 4394 timeout_ns = u2_del_ns;
4385 4395
4396 return timeout_ns;
4397}
4398
4399/* Returns the hub-encoded U2 timeout value. */
4400static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci,
4401 struct usb_device *udev,
4402 struct usb_endpoint_descriptor *desc)
4403{
4404 unsigned long long timeout_ns;
4405
4406 if (xhci->quirks & XHCI_INTEL_HOST)
4407 timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc);
4408 else
4409 timeout_ns = udev->u2_params.sel;
4410
4386 /* The U2 timeout is encoded in 256us intervals */ 4411 /* The U2 timeout is encoded in 256us intervals */
4387 timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000); 4412 timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000);
4388 /* If the necessary timeout value is bigger than what we can set in the 4413 /* If the necessary timeout value is bigger than what we can set in the
@@ -4401,13 +4426,10 @@ static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci,
4401 enum usb3_link_state state, 4426 enum usb3_link_state state,
4402 u16 *timeout) 4427 u16 *timeout)
4403{ 4428{
4404 if (state == USB3_LPM_U1) { 4429 if (state == USB3_LPM_U1)
4405 if (xhci->quirks & XHCI_INTEL_HOST) 4430 return xhci_calculate_u1_timeout(xhci, udev, desc);
4406 return xhci_calculate_intel_u1_timeout(udev, desc); 4431 else if (state == USB3_LPM_U2)
4407 } else { 4432 return xhci_calculate_u2_timeout(xhci, udev, desc);
4408 if (xhci->quirks & XHCI_INTEL_HOST)
4409 return xhci_calculate_intel_u2_timeout(udev, desc);
4410 }
4411 4433
4412 return USB3_LPM_DISABLED; 4434 return USB3_LPM_DISABLED;
4413} 4435}
@@ -4484,7 +4506,8 @@ static int xhci_check_tier_policy(struct xhci_hcd *xhci,
4484{ 4506{
4485 if (xhci->quirks & XHCI_INTEL_HOST) 4507 if (xhci->quirks & XHCI_INTEL_HOST)
4486 return xhci_check_intel_tier_policy(udev, state); 4508 return xhci_check_intel_tier_policy(udev, state);
4487 return -EINVAL; 4509 else
4510 return 0;
4488} 4511}
4489 4512
4490/* Returns the U1 or U2 timeout that should be enabled. 4513/* Returns the U1 or U2 timeout that should be enabled.
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 9ffecd56600d..dace5152e179 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1558,6 +1558,8 @@ struct xhci_hcd {
1558#define XHCI_PLAT (1 << 16) 1558#define XHCI_PLAT (1 << 16)
1559#define XHCI_SLOW_SUSPEND (1 << 17) 1559#define XHCI_SLOW_SUSPEND (1 << 17)
1560#define XHCI_SPURIOUS_WAKEUP (1 << 18) 1560#define XHCI_SPURIOUS_WAKEUP (1 << 18)
1561/* For controllers with a broken beyond repair streams implementation */
1562#define XHCI_BROKEN_STREAMS (1 << 19)
1561 unsigned int num_active_eps; 1563 unsigned int num_active_eps;
1562 unsigned int limit_active_eps; 1564 unsigned int limit_active_eps;
1563 /* There are two roothubs to keep track of bus suspend info for */ 1565 /* There are two roothubs to keep track of bus suspend info for */