aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/Kconfig11
-rw-r--r--drivers/usb/host/ehci-au1xxx.c2
-rw-r--r--drivers/usb/host/ehci-dbg.c196
-rw-r--r--drivers/usb/host/ehci-fsl.c3
-rw-r--r--drivers/usb/host/ehci-hcd.c49
-rw-r--r--drivers/usb/host/ehci-hub.c25
-rw-r--r--drivers/usb/host/ehci-lpm.c83
-rw-r--r--drivers/usb/host/ehci-omap.c36
-rw-r--r--drivers/usb/host/ehci-pci.c26
-rw-r--r--drivers/usb/host/ehci-q.c3
-rw-r--r--drivers/usb/host/ehci-sched.c182
-rw-r--r--drivers/usb/host/ehci.h18
-rw-r--r--drivers/usb/host/hwa-hc.c4
-rw-r--r--drivers/usb/host/imx21-hcd.c2
-rw-r--r--drivers/usb/host/isp1362.h24
-rw-r--r--drivers/usb/host/isp1760-hcd.c3
-rw-r--r--drivers/usb/host/ohci-dbg.c4
-rw-r--r--drivers/usb/host/ohci-hcd.c6
-rw-r--r--drivers/usb/host/ohci-hub.c23
-rw-r--r--drivers/usb/host/ohci-pci.c2
-rw-r--r--drivers/usb/host/ohci-ssb.c52
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c7
-rw-r--r--drivers/usb/host/sl811-hcd.c5
-rw-r--r--drivers/usb/host/uhci-debug.c23
-rw-r--r--drivers/usb/host/uhci-hcd.c87
-rw-r--r--drivers/usb/host/uhci-hcd.h7
-rw-r--r--drivers/usb/host/uhci-hub.c6
-rw-r--r--drivers/usb/host/uhci-q.c4
-rw-r--r--drivers/usb/host/whci/hcd.c2
-rw-r--r--drivers/usb/host/whci/qset.c2
-rw-r--r--drivers/usb/host/xhci-mem.c101
-rw-r--r--drivers/usb/host/xhci-pci.c9
-rw-r--r--drivers/usb/host/xhci-ring.c1332
-rw-r--r--drivers/usb/host/xhci.c344
-rw-r--r--drivers/usb/host/xhci.h30
35 files changed, 1887 insertions, 826 deletions
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f865be2276d4..2d926cec0725 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -72,8 +72,9 @@ config USB_EHCI_ROOT_HUB_TT
72 from ARC, and has since changed hands a few times. 72 from ARC, and has since changed hands a few times.
73 73
74config USB_EHCI_TT_NEWSCHED 74config USB_EHCI_TT_NEWSCHED
75 bool "Improved Transaction Translator scheduling (EXPERIMENTAL)" 75 bool "Improved Transaction Translator scheduling"
76 depends on USB_EHCI_HCD && EXPERIMENTAL 76 depends on USB_EHCI_HCD
77 default y
77 ---help--- 78 ---help---
78 This changes the periodic scheduling code to fill more of the low 79 This changes the periodic scheduling code to fill more of the low
79 and full speed bandwidth available from the Transaction Translator 80 and full speed bandwidth available from the Transaction Translator
@@ -84,9 +85,11 @@ config USB_EHCI_TT_NEWSCHED
84 If you have multiple periodic low/fullspeed devices connected to a 85 If you have multiple periodic low/fullspeed devices connected to a
85 highspeed USB hub which is connected to a highspeed USB Host 86 highspeed USB hub which is connected to a highspeed USB Host
86 Controller, and some of those devices will not work correctly 87 Controller, and some of those devices will not work correctly
87 (possibly due to "ENOSPC" or "-28" errors), say Y. 88 (possibly due to "ENOSPC" or "-28" errors), say Y. Conversely, if
89 you have only one such device and it doesn't work, you could try
90 saying N.
88 91
89 If unsure, say N. 92 If unsure, say Y.
90 93
91config USB_EHCI_BIG_ENDIAN_MMIO 94config USB_EHCI_BIG_ENDIAN_MMIO
92 bool 95 bool
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index faa61748db70..2baf8a849086 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -228,7 +228,7 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
228 * the root hub is either suspended or stopped. 228 * the root hub is either suspended or stopped.
229 */ 229 */
230 spin_lock_irqsave(&ehci->lock, flags); 230 spin_lock_irqsave(&ehci->lock, flags);
231 ehci_prepare_ports_for_controller_suspend(ehci); 231 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
232 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 232 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
233 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 233 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
234 234
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 874d2000bf92..76b7fd2d838a 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -98,13 +98,18 @@ static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
98 HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); 98 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
99 } else { 99 } else {
100 ehci_dbg (ehci, 100 ehci_dbg (ehci,
101 "%s hcc_params %04x thresh %d uframes %s%s%s\n", 101 "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
102 label, 102 label,
103 params, 103 params,
104 HCC_ISOC_THRES(params), 104 HCC_ISOC_THRES(params),
105 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", 105 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
106 HCC_CANPARK(params) ? " park" : "", 106 HCC_CANPARK(params) ? " park" : "",
107 HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); 107 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "",
108 HCC_LPM(params) ? " LPM" : "",
109 HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "",
110 HCC_HW_PREFETCH(params) ? " hw prefetch" : "",
111 HCC_32FRAME_PERIODIC_LIST(params) ?
112 " 32 peridic list" : "");
108 } 113 }
109} 114}
110#else 115#else
@@ -191,8 +196,9 @@ static int __maybe_unused
191dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) 196dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
192{ 197{
193 return scnprintf (buf, len, 198 return scnprintf (buf, len,
194 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s", 199 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
195 label, label [0] ? " " : "", status, 200 label, label [0] ? " " : "", status,
201 (status & STS_PPCE_MASK) ? " PPCE" : "",
196 (status & STS_ASS) ? " Async" : "", 202 (status & STS_ASS) ? " Async" : "",
197 (status & STS_PSS) ? " Periodic" : "", 203 (status & STS_PSS) ? " Periodic" : "",
198 (status & STS_RECL) ? " Recl" : "", 204 (status & STS_RECL) ? " Recl" : "",
@@ -210,8 +216,9 @@ static int __maybe_unused
210dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) 216dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
211{ 217{
212 return scnprintf (buf, len, 218 return scnprintf (buf, len,
213 "%s%sintrenable %02x%s%s%s%s%s%s", 219 "%s%sintrenable %02x%s%s%s%s%s%s%s",
214 label, label [0] ? " " : "", enable, 220 label, label [0] ? " " : "", enable,
221 (enable & STS_PPCE_MASK) ? " PPCE" : "",
215 (enable & STS_IAA) ? " IAA" : "", 222 (enable & STS_IAA) ? " IAA" : "",
216 (enable & STS_FATAL) ? " FATAL" : "", 223 (enable & STS_FATAL) ? " FATAL" : "",
217 (enable & STS_FLR) ? " FLR" : "", 224 (enable & STS_FLR) ? " FLR" : "",
@@ -228,9 +235,15 @@ static int
228dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) 235dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
229{ 236{
230 return scnprintf (buf, len, 237 return scnprintf (buf, len,
231 "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s", 238 "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
239 "period=%s%s %s",
232 label, label [0] ? " " : "", command, 240 label, label [0] ? " " : "", command,
233 (command & CMD_PARK) ? "park" : "(park)", 241 (command & CMD_HIRD) ? " HIRD" : "",
242 (command & CMD_PPCEE) ? " PPCEE" : "",
243 (command & CMD_FSP) ? " FSP" : "",
244 (command & CMD_ASPE) ? " ASPE" : "",
245 (command & CMD_PSPE) ? " PSPE" : "",
246 (command & CMD_PARK) ? " park" : "(park)",
234 CMD_PARK_CNT (command), 247 CMD_PARK_CNT (command),
235 (command >> 16) & 0x3f, 248 (command >> 16) & 0x3f,
236 (command & CMD_LRESET) ? " LReset" : "", 249 (command & CMD_LRESET) ? " LReset" : "",
@@ -257,11 +270,22 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
257 } 270 }
258 271
259 return scnprintf (buf, len, 272 return scnprintf (buf, len,
260 "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s", 273 "%s%sport:%d status %06x %d %s%s%s%s%s%s "
274 "sig=%s%s%s%s%s%s%s%s%s%s%s",
261 label, label [0] ? " " : "", port, status, 275 label, label [0] ? " " : "", port, status,
276 status>>25,/*device address */
277 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ACK ?
278 " ACK" : "",
279 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ?
280 " NYET" : "",
281 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ?
282 " STALL" : "",
283 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ?
284 " ERR" : "",
262 (status & PORT_POWER) ? " POWER" : "", 285 (status & PORT_POWER) ? " POWER" : "",
263 (status & PORT_OWNER) ? " OWNER" : "", 286 (status & PORT_OWNER) ? " OWNER" : "",
264 sig, 287 sig,
288 (status & PORT_LPM) ? " LPM" : "",
265 (status & PORT_RESET) ? " RESET" : "", 289 (status & PORT_RESET) ? " RESET" : "",
266 (status & PORT_SUSPEND) ? " SUSPEND" : "", 290 (status & PORT_SUSPEND) ? " SUSPEND" : "",
267 (status & PORT_RESUME) ? " RESUME" : "", 291 (status & PORT_RESUME) ? " RESUME" : "",
@@ -330,6 +354,13 @@ static int debug_async_open(struct inode *, struct file *);
330static int debug_periodic_open(struct inode *, struct file *); 354static int debug_periodic_open(struct inode *, struct file *);
331static int debug_registers_open(struct inode *, struct file *); 355static int debug_registers_open(struct inode *, struct file *);
332static int debug_async_open(struct inode *, struct file *); 356static int debug_async_open(struct inode *, struct file *);
357static int debug_lpm_open(struct inode *, struct file *);
358static ssize_t debug_lpm_read(struct file *file, char __user *user_buf,
359 size_t count, loff_t *ppos);
360static ssize_t debug_lpm_write(struct file *file, const char __user *buffer,
361 size_t count, loff_t *ppos);
362static int debug_lpm_close(struct inode *inode, struct file *file);
363
333static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); 364static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
334static int debug_close(struct inode *, struct file *); 365static int debug_close(struct inode *, struct file *);
335 366
@@ -351,6 +382,13 @@ static const struct file_operations debug_registers_fops = {
351 .read = debug_output, 382 .read = debug_output,
352 .release = debug_close, 383 .release = debug_close,
353}; 384};
385static const struct file_operations debug_lpm_fops = {
386 .owner = THIS_MODULE,
387 .open = debug_lpm_open,
388 .read = debug_lpm_read,
389 .write = debug_lpm_write,
390 .release = debug_lpm_close,
391};
354 392
355static struct dentry *ehci_debug_root; 393static struct dentry *ehci_debug_root;
356 394
@@ -674,7 +712,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
674 712
675 spin_lock_irqsave (&ehci->lock, flags); 713 spin_lock_irqsave (&ehci->lock, flags);
676 714
677 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 715 if (!HCD_HW_ACCESSIBLE(hcd)) {
678 size = scnprintf (next, size, 716 size = scnprintf (next, size,
679 "bus %s, device %s\n" 717 "bus %s, device %s\n"
680 "%s\n" 718 "%s\n"
@@ -917,51 +955,127 @@ static int debug_registers_open(struct inode *inode, struct file *file)
917 return file->private_data ? 0 : -ENOMEM; 955 return file->private_data ? 0 : -ENOMEM;
918} 956}
919 957
958static int debug_lpm_open(struct inode *inode, struct file *file)
959{
960 file->private_data = inode->i_private;
961 return 0;
962}
963
964static int debug_lpm_close(struct inode *inode, struct file *file)
965{
966 return 0;
967}
968
969static ssize_t debug_lpm_read(struct file *file, char __user *user_buf,
970 size_t count, loff_t *ppos)
971{
972 /* TODO: show lpm stats */
973 return 0;
974}
975
976static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf,
977 size_t count, loff_t *ppos)
978{
979 struct usb_hcd *hcd;
980 struct ehci_hcd *ehci;
981 char buf[50];
982 size_t len;
983 u32 temp;
984 unsigned long port;
985 u32 __iomem *portsc ;
986 u32 params;
987
988 hcd = bus_to_hcd(file->private_data);
989 ehci = hcd_to_ehci(hcd);
990
991 len = min(count, sizeof(buf) - 1);
992 if (copy_from_user(buf, user_buf, len))
993 return -EFAULT;
994 buf[len] = '\0';
995 if (len > 0 && buf[len - 1] == '\n')
996 buf[len - 1] = '\0';
997
998 if (strncmp(buf, "enable", 5) == 0) {
999 if (strict_strtoul(buf + 7, 10, &port))
1000 return -EINVAL;
1001 params = ehci_readl(ehci, &ehci->caps->hcs_params);
1002 if (port > HCS_N_PORTS(params)) {
1003 ehci_dbg(ehci, "ERR: LPM on bad port %lu\n", port);
1004 return -ENODEV;
1005 }
1006 portsc = &ehci->regs->port_status[port-1];
1007 temp = ehci_readl(ehci, portsc);
1008 if (!(temp & PORT_DEV_ADDR)) {
1009 ehci_dbg(ehci, "LPM: no device attached\n");
1010 return -ENODEV;
1011 }
1012 temp |= PORT_LPM;
1013 ehci_writel(ehci, temp, portsc);
1014 printk(KERN_INFO "force enable LPM for port %lu\n", port);
1015 } else if (strncmp(buf, "hird=", 5) == 0) {
1016 unsigned long hird;
1017 if (strict_strtoul(buf + 5, 16, &hird))
1018 return -EINVAL;
1019 printk(KERN_INFO "setting hird %s %lu\n", buf + 6, hird);
1020 temp = ehci_readl(ehci, &ehci->regs->command);
1021 temp &= ~CMD_HIRD;
1022 temp |= hird << 24;
1023 ehci_writel(ehci, temp, &ehci->regs->command);
1024 } else if (strncmp(buf, "disable", 7) == 0) {
1025 if (strict_strtoul(buf + 8, 10, &port))
1026 return -EINVAL;
1027 params = ehci_readl(ehci, &ehci->caps->hcs_params);
1028 if (port > HCS_N_PORTS(params)) {
1029 ehci_dbg(ehci, "ERR: LPM off bad port %lu\n", port);
1030 return -ENODEV;
1031 }
1032 portsc = &ehci->regs->port_status[port-1];
1033 temp = ehci_readl(ehci, portsc);
1034 if (!(temp & PORT_DEV_ADDR)) {
1035 ehci_dbg(ehci, "ERR: no device attached\n");
1036 return -ENODEV;
1037 }
1038 temp &= ~PORT_LPM;
1039 ehci_writel(ehci, temp, portsc);
1040 printk(KERN_INFO "disabled LPM for port %lu\n", port);
1041 } else
1042 return -EOPNOTSUPP;
1043 return count;
1044}
1045
920static inline void create_debug_files (struct ehci_hcd *ehci) 1046static inline void create_debug_files (struct ehci_hcd *ehci)
921{ 1047{
922 struct usb_bus *bus = &ehci_to_hcd(ehci)->self; 1048 struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
923 1049
924 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root); 1050 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
925 if (!ehci->debug_dir) 1051 if (!ehci->debug_dir)
926 goto dir_error; 1052 return;
927 1053
928 ehci->debug_async = debugfs_create_file("async", S_IRUGO, 1054 if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
929 ehci->debug_dir, bus, 1055 &debug_async_fops))
930 &debug_async_fops); 1056 goto file_error;
931 if (!ehci->debug_async) 1057
932 goto async_error; 1058 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
933 1059 &debug_periodic_fops))
934 ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO, 1060 goto file_error;
935 ehci->debug_dir, bus, 1061
936 &debug_periodic_fops); 1062 if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus,
937 if (!ehci->debug_periodic) 1063 &debug_registers_fops))
938 goto periodic_error; 1064 goto file_error;
939 1065
940 ehci->debug_registers = debugfs_create_file("registers", S_IRUGO, 1066 if (!debugfs_create_file("lpm", S_IRUGO|S_IWUGO, ehci->debug_dir, bus,
941 ehci->debug_dir, bus, 1067 &debug_lpm_fops))
942 &debug_registers_fops); 1068 goto file_error;
943 if (!ehci->debug_registers) 1069
944 goto registers_error;
945 return; 1070 return;
946 1071
947registers_error: 1072file_error:
948 debugfs_remove(ehci->debug_periodic); 1073 debugfs_remove_recursive(ehci->debug_dir);
949periodic_error:
950 debugfs_remove(ehci->debug_async);
951async_error:
952 debugfs_remove(ehci->debug_dir);
953dir_error:
954 ehci->debug_periodic = NULL;
955 ehci->debug_async = NULL;
956 ehci->debug_dir = NULL;
957} 1074}
958 1075
959static inline void remove_debug_files (struct ehci_hcd *ehci) 1076static inline void remove_debug_files (struct ehci_hcd *ehci)
960{ 1077{
961 debugfs_remove(ehci->debug_registers); 1078 debugfs_remove_recursive(ehci->debug_dir);
962 debugfs_remove(ehci->debug_periodic);
963 debugfs_remove(ehci->debug_async);
964 debugfs_remove(ehci->debug_dir);
965} 1079}
966 1080
967#endif /* STUB_DEBUG_FILES */ 1081#endif /* STUB_DEBUG_FILES */
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 5cd967d28938..a416421abfa2 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -313,7 +313,8 @@ static int ehci_fsl_drv_suspend(struct device *dev)
313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); 313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
314 void __iomem *non_ehci = hcd->regs; 314 void __iomem *non_ehci = hcd->regs;
315 315
316 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd)); 316 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
317 device_may_wakeup(dev));
317 if (!fsl_deep_sleep()) 318 if (!fsl_deep_sleep())
318 return 0; 319 return 0;
319 320
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 6fcffe15a005..ac0f7a4b0341 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -36,6 +36,7 @@
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/debugfs.h> 37#include <linux/debugfs.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/uaccess.h>
39 40
40#include <asm/byteorder.h> 41#include <asm/byteorder.h>
41#include <asm/io.h> 42#include <asm/io.h>
@@ -78,7 +79,13 @@ static const char hcd_name [] = "ehci_hcd";
78#define EHCI_TUNE_RL_TT 0 79#define EHCI_TUNE_RL_TT 0
79#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ 80#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
80#define EHCI_TUNE_MULT_TT 1 81#define EHCI_TUNE_MULT_TT 1
81#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ 82/*
83 * Some drivers think it's safe to schedule isochronous transfers more than
84 * 256 ms into the future (partly as a result of an old bug in the scheduling
85 * code). In an attempt to avoid trouble, we will use a minimum scheduling
86 * length of 512 frames instead of 256.
87 */
88#define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
82 89
83#define EHCI_IAA_MSECS 10 /* arbitrary */ 90#define EHCI_IAA_MSECS 10 /* arbitrary */
84#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ 91#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
@@ -100,6 +107,11 @@ static int ignore_oc = 0;
100module_param (ignore_oc, bool, S_IRUGO); 107module_param (ignore_oc, bool, S_IRUGO);
101MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications"); 108MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
102 109
110/* for link power management(LPM) feature */
111static unsigned int hird;
112module_param(hird, int, S_IRUGO);
113MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n");
114
103#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 115#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
104 116
105/*-------------------------------------------------------------------------*/ 117/*-------------------------------------------------------------------------*/
@@ -304,6 +316,7 @@ static void end_unlink_async(struct ehci_hcd *ehci);
304static void ehci_work(struct ehci_hcd *ehci); 316static void ehci_work(struct ehci_hcd *ehci);
305 317
306#include "ehci-hub.c" 318#include "ehci-hub.c"
319#include "ehci-lpm.c"
307#include "ehci-mem.c" 320#include "ehci-mem.c"
308#include "ehci-q.c" 321#include "ehci-q.c"
309#include "ehci-sched.c" 322#include "ehci-sched.c"
@@ -577,6 +590,11 @@ static int ehci_init(struct usb_hcd *hcd)
577 if (log2_irq_thresh < 0 || log2_irq_thresh > 6) 590 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
578 log2_irq_thresh = 0; 591 log2_irq_thresh = 0;
579 temp = 1 << (16 + log2_irq_thresh); 592 temp = 1 << (16 + log2_irq_thresh);
593 if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
594 ehci->has_ppcd = 1;
595 ehci_dbg(ehci, "enable per-port change event\n");
596 temp |= CMD_PPCEE;
597 }
580 if (HCC_CANPARK(hcc_params)) { 598 if (HCC_CANPARK(hcc_params)) {
581 /* HW default park == 3, on hardware that supports it (like 599 /* HW default park == 3, on hardware that supports it (like
582 * NVidia and ALI silicon), maximizes throughput on the async 600 * NVidia and ALI silicon), maximizes throughput on the async
@@ -603,10 +621,22 @@ static int ehci_init(struct usb_hcd *hcd)
603 default: BUG(); 621 default: BUG();
604 } 622 }
605 } 623 }
624 if (HCC_LPM(hcc_params)) {
625 /* support link power management EHCI 1.1 addendum */
626 ehci_dbg(ehci, "support lpm\n");
627 ehci->has_lpm = 1;
628 if (hird > 0xf) {
629 ehci_dbg(ehci, "hird %d invalid, use default 0",
630 hird);
631 hird = 0;
632 }
633 temp |= hird << 24;
634 }
606 ehci->command = temp; 635 ehci->command = temp;
607 636
608 /* Accept arbitrarily long scatter-gather lists */ 637 /* Accept arbitrarily long scatter-gather lists */
609 hcd->self.sg_tablesize = ~0; 638 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
639 hcd->self.sg_tablesize = ~0;
610 return 0; 640 return 0;
611} 641}
612 642
@@ -619,7 +649,6 @@ static int ehci_run (struct usb_hcd *hcd)
619 u32 hcc_params; 649 u32 hcc_params;
620 650
621 hcd->uses_new_polling = 1; 651 hcd->uses_new_polling = 1;
622 hcd->poll_rh = 0;
623 652
624 /* EHCI spec section 4.1 */ 653 /* EHCI spec section 4.1 */
625 if ((retval = ehci_reset(ehci)) != 0) { 654 if ((retval = ehci_reset(ehci)) != 0) {
@@ -764,6 +793,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
764 /* remote wakeup [4.3.1] */ 793 /* remote wakeup [4.3.1] */
765 if (status & STS_PCD) { 794 if (status & STS_PCD) {
766 unsigned i = HCS_N_PORTS (ehci->hcs_params); 795 unsigned i = HCS_N_PORTS (ehci->hcs_params);
796 u32 ppcd = 0;
767 797
768 /* kick root hub later */ 798 /* kick root hub later */
769 pcd_status = status; 799 pcd_status = status;
@@ -772,9 +802,18 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
772 if (!(cmd & CMD_RUN)) 802 if (!(cmd & CMD_RUN))
773 usb_hcd_resume_root_hub(hcd); 803 usb_hcd_resume_root_hub(hcd);
774 804
805 /* get per-port change detect bits */
806 if (ehci->has_ppcd)
807 ppcd = status >> 16;
808
775 while (i--) { 809 while (i--) {
776 int pstatus = ehci_readl(ehci, 810 int pstatus;
777 &ehci->regs->port_status [i]); 811
812 /* leverage per-port change bits feature */
813 if (ehci->has_ppcd && !(ppcd & (1 << i)))
814 continue;
815 pstatus = ehci_readl(ehci,
816 &ehci->regs->port_status[i]);
778 817
779 if (pstatus & PORT_OWNER) 818 if (pstatus & PORT_OWNER)
780 continue; 819 continue;
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index e7d3d8def282..796ea0c8900f 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -107,7 +107,7 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
107} 107}
108 108
109static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 109static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
110 bool suspending) 110 bool suspending, bool do_wakeup)
111{ 111{
112 int port; 112 int port;
113 u32 temp; 113 u32 temp;
@@ -117,8 +117,7 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
117 * when the controller is suspended or resumed. In all other 117 * when the controller is suspended or resumed. In all other
118 * cases they don't need to be changed. 118 * cases they don't need to be changed.
119 */ 119 */
120 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || 120 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
121 device_may_wakeup(ehci_to_hcd(ehci)->self.controller))
122 return; 121 return;
123 122
124 /* clear phy low-power mode before changing wakeup flags */ 123 /* clear phy low-power mode before changing wakeup flags */
@@ -167,6 +166,10 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
167 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg); 166 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
168 } 167 }
169 } 168 }
169
170 /* Does the root hub have a port wakeup pending? */
171 if (!suspending && (ehci_readl(ehci, &ehci->regs->status) & STS_PCD))
172 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
170} 173}
171 174
172static int ehci_bus_suspend (struct usb_hcd *hcd) 175static int ehci_bus_suspend (struct usb_hcd *hcd)
@@ -316,7 +319,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
316 if (time_before (jiffies, ehci->next_statechange)) 319 if (time_before (jiffies, ehci->next_statechange))
317 msleep(5); 320 msleep(5);
318 spin_lock_irq (&ehci->lock); 321 spin_lock_irq (&ehci->lock);
319 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 322 if (!HCD_HW_ACCESSIBLE(hcd)) {
320 spin_unlock_irq(&ehci->lock); 323 spin_unlock_irq(&ehci->lock);
321 return -ESHUTDOWN; 324 return -ESHUTDOWN;
322 } 325 }
@@ -603,6 +606,7 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
603 u32 mask; 606 u32 mask;
604 int ports, i, retval = 1; 607 int ports, i, retval = 1;
605 unsigned long flags; 608 unsigned long flags;
609 u32 ppcd = 0;
606 610
607 /* if !USB_SUSPEND, root hub timers won't get shut down ... */ 611 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
608 if (!HC_IS_RUNNING(hcd->state)) 612 if (!HC_IS_RUNNING(hcd->state))
@@ -632,7 +636,15 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
632 636
633 /* port N changes (bit N)? */ 637 /* port N changes (bit N)? */
634 spin_lock_irqsave (&ehci->lock, flags); 638 spin_lock_irqsave (&ehci->lock, flags);
639
640 /* get per-port change detect bits */
641 if (ehci->has_ppcd)
642 ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16;
643
635 for (i = 0; i < ports; i++) { 644 for (i = 0; i < ports; i++) {
645 /* leverage per-port change bits feature */
646 if (ehci->has_ppcd && !(ppcd & (1 << i)))
647 continue;
636 temp = ehci_readl(ehci, &ehci->regs->port_status [i]); 648 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
637 649
638 /* 650 /*
@@ -790,6 +802,11 @@ static int ehci_hub_control (
790 status_reg); 802 status_reg);
791 break; 803 break;
792 case USB_PORT_FEAT_C_CONNECTION: 804 case USB_PORT_FEAT_C_CONNECTION:
805 if (ehci->has_lpm) {
806 /* clear PORTSC bits on disconnect */
807 temp &= ~PORT_LPM;
808 temp &= ~PORT_DEV_ADDR;
809 }
793 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC, 810 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC,
794 status_reg); 811 status_reg);
795 break; 812 break;
diff --git a/drivers/usb/host/ehci-lpm.c b/drivers/usb/host/ehci-lpm.c
new file mode 100644
index 000000000000..b4d4d63c13ed
--- /dev/null
+++ b/drivers/usb/host/ehci-lpm.c
@@ -0,0 +1,83 @@
1/* ehci-lpm.c EHCI HCD LPM support code
2 * Copyright (c) 2008 - 2010, Intel Corporation.
3 * Author: Jacob Pan <jacob.jun.pan@intel.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/
18
19/* this file is part of ehci-hcd.c */
20static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num)
21{
22 u32 __iomem portsc;
23
24 ehci_dbg(ehci, "set dev address %d for port %d\n", dev_addr, port_num);
25 if (port_num > HCS_N_PORTS(ehci->hcs_params)) {
26 ehci_dbg(ehci, "invalid port number %d\n", port_num);
27 return -ENODEV;
28 }
29 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_num-1]);
30 portsc &= ~PORT_DEV_ADDR;
31 portsc |= dev_addr<<25;
32 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_num-1]);
33 return 0;
34}
35
36/*
37 * this function is used to check if the device support LPM
38 * if yes, mark the PORTSC register with PORT_LPM bit
39 */
40static int ehci_lpm_check(struct ehci_hcd *ehci, int port)
41{
42 u32 __iomem *portsc ;
43 u32 val32;
44 int retval;
45
46 portsc = &ehci->regs->port_status[port-1];
47 val32 = ehci_readl(ehci, portsc);
48 if (!(val32 & PORT_DEV_ADDR)) {
49 ehci_dbg(ehci, "LPM: no device attached\n");
50 return -ENODEV;
51 }
52 val32 |= PORT_LPM;
53 ehci_writel(ehci, val32, portsc);
54 msleep(5);
55 val32 |= PORT_SUSPEND;
56 ehci_dbg(ehci, "Sending LPM 0x%08x to port %d\n", val32, port);
57 ehci_writel(ehci, val32, portsc);
58 /* wait for ACK */
59 msleep(10);
60 retval = handshake(ehci, &ehci->regs->port_status[port-1], PORT_SSTS,
61 PORTSC_SUSPEND_STS_ACK, 125);
62 dbg_port(ehci, "LPM", port, val32);
63 if (retval != -ETIMEDOUT) {
64 ehci_dbg(ehci, "LPM: device ACK for LPM\n");
65 val32 |= PORT_LPM;
66 /*
67 * now device should be in L1 sleep, let's wake up the device
68 * so that we can complete enumeration.
69 */
70 ehci_writel(ehci, val32, portsc);
71 msleep(10);
72 val32 |= PORT_RESUME;
73 ehci_writel(ehci, val32, portsc);
74 } else {
75 ehci_dbg(ehci, "LPM: device does not ACK, disable LPM %d\n",
76 retval);
77 val32 &= ~PORT_LPM;
78 retval = -ETIMEDOUT;
79 ehci_writel(ehci, val32, portsc);
80 }
81
82 return retval;
83}
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 5450e628157f..116ae280053a 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -38,6 +38,7 @@
38#include <linux/gpio.h> 38#include <linux/gpio.h>
39#include <linux/regulator/consumer.h> 39#include <linux/regulator/consumer.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/usb/ulpi.h>
41#include <plat/usb.h> 42#include <plat/usb.h>
42 43
43/* 44/*
@@ -236,6 +237,35 @@ static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask)
236 237
237/*-------------------------------------------------------------------------*/ 238/*-------------------------------------------------------------------------*/
238 239
240static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
241{
242 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
243 unsigned reg = 0;
244
245 reg = ULPI_FUNC_CTRL_RESET
246 /* FUNCTION_CTRL_SET register */
247 | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
248 /* Write */
249 | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
250 /* PORTn */
251 | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
252 /* start ULPI access*/
253 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
254
255 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg);
256
257 /* Wait for ULPI access completion */
258 while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI)
259 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
260 cpu_relax();
261
262 if (time_after(jiffies, timeout)) {
263 dev_dbg(omap->dev, "phy reset operation timed out\n");
264 break;
265 }
266 }
267}
268
239/* omap_start_ehc 269/* omap_start_ehc
240 * - Start the TI USBHOST controller 270 * - Start the TI USBHOST controller
241 */ 271 */
@@ -425,6 +455,12 @@ static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
425 gpio_set_value(omap->reset_gpio_port[1], 1); 455 gpio_set_value(omap->reset_gpio_port[1], 1);
426 } 456 }
427 457
458 /* Soft reset the PHY using PHY reset command over ULPI */
459 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
460 omap_ehci_soft_phy_reset(omap, 0);
461 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
462 omap_ehci_soft_phy_reset(omap, 1);
463
428 return 0; 464 return 0;
429 465
430err_sys_status: 466err_sys_status:
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index d43d176161aa..58b72d741d93 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -114,6 +114,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
114 break; 114 break;
115 case PCI_VENDOR_ID_INTEL: 115 case PCI_VENDOR_ID_INTEL:
116 ehci->need_io_watchdog = 0; 116 ehci->need_io_watchdog = 0;
117 ehci->fs_i_thresh = 1;
117 if (pdev->device == 0x27cc) { 118 if (pdev->device == 0x27cc) {
118 ehci->broken_periodic = 1; 119 ehci->broken_periodic = 1;
119 ehci_info(ehci, "using broken periodic workaround\n"); 120 ehci_info(ehci, "using broken periodic workaround\n");
@@ -277,7 +278,7 @@ done:
277 * Also they depend on separate root hub suspend/resume. 278 * Also they depend on separate root hub suspend/resume.
278 */ 279 */
279 280
280static int ehci_pci_suspend(struct usb_hcd *hcd) 281static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
281{ 282{
282 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 283 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
283 unsigned long flags; 284 unsigned long flags;
@@ -291,7 +292,7 @@ static int ehci_pci_suspend(struct usb_hcd *hcd)
291 * the root hub is either suspended or stopped. 292 * the root hub is either suspended or stopped.
292 */ 293 */
293 spin_lock_irqsave (&ehci->lock, flags); 294 spin_lock_irqsave (&ehci->lock, flags);
294 ehci_prepare_ports_for_controller_suspend(ehci); 295 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
295 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 296 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
296 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 297 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
297 298
@@ -361,6 +362,22 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
361} 362}
362#endif 363#endif
363 364
365static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
366{
367 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
368 int rc = 0;
369
370 if (!udev->parent) /* udev is root hub itself, impossible */
371 rc = -1;
372 /* we only support lpm device connected to root hub yet */
373 if (ehci->has_lpm && !udev->parent->parent) {
374 rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
375 if (!rc)
376 rc = ehci_lpm_check(ehci, udev->portnum);
377 }
378 return rc;
379}
380
364static const struct hc_driver ehci_pci_hc_driver = { 381static const struct hc_driver ehci_pci_hc_driver = {
365 .description = hcd_name, 382 .description = hcd_name,
366 .product_desc = "EHCI Host Controller", 383 .product_desc = "EHCI Host Controller",
@@ -407,6 +424,11 @@ static const struct hc_driver ehci_pci_hc_driver = {
407 .relinquish_port = ehci_relinquish_port, 424 .relinquish_port = ehci_relinquish_port,
408 .port_handed_over = ehci_port_handed_over, 425 .port_handed_over = ehci_port_handed_over,
409 426
427 /*
428 * call back when device connected and addressed
429 */
430 .update_device = ehci_update_device,
431
410 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 432 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
411}; 433};
412 434
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 11a79c4f4a9d..233c288e3f93 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1126,8 +1126,7 @@ submit_async (
1126#endif 1126#endif
1127 1127
1128 spin_lock_irqsave (&ehci->lock, flags); 1128 spin_lock_irqsave (&ehci->lock, flags);
1129 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1129 if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
1130 &ehci_to_hcd(ehci)->flags))) {
1131 rc = -ESHUTDOWN; 1130 rc = -ESHUTDOWN;
1132 goto done; 1131 goto done;
1133 } 1132 }
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 805ec633a652..a92526d6e5ae 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -880,8 +880,7 @@ static int intr_submit (
880 880
881 spin_lock_irqsave (&ehci->lock, flags); 881 spin_lock_irqsave (&ehci->lock, flags);
882 882
883 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 883 if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
884 &ehci_to_hcd(ehci)->flags))) {
885 status = -ESHUTDOWN; 884 status = -ESHUTDOWN;
886 goto done_not_linked; 885 goto done_not_linked;
887 } 886 }
@@ -1075,15 +1074,6 @@ iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream)
1075 if (stream->ep) 1074 if (stream->ep)
1076 stream->ep->hcpriv = NULL; 1075 stream->ep->hcpriv = NULL;
1077 1076
1078 if (stream->rescheduled) {
1079 ehci_info (ehci, "ep%d%s-iso rescheduled "
1080 "%lu times in %lu seconds\n",
1081 stream->bEndpointAddress, is_in ? "in" : "out",
1082 stream->rescheduled,
1083 ((jiffies - stream->start)/HZ)
1084 );
1085 }
1086
1087 kfree(stream); 1077 kfree(stream);
1088 } 1078 }
1089} 1079}
@@ -1396,30 +1386,25 @@ iso_stream_schedule (
1396 struct ehci_iso_stream *stream 1386 struct ehci_iso_stream *stream
1397) 1387)
1398{ 1388{
1399 u32 now, next, start, period; 1389 u32 now, next, start, period, span;
1400 int status; 1390 int status;
1401 unsigned mod = ehci->periodic_size << 3; 1391 unsigned mod = ehci->periodic_size << 3;
1402 struct ehci_iso_sched *sched = urb->hcpriv; 1392 struct ehci_iso_sched *sched = urb->hcpriv;
1403 struct pci_dev *pdev;
1404 1393
1405 if (sched->span > (mod - SCHEDULE_SLOP)) { 1394 period = urb->interval;
1406 ehci_dbg (ehci, "iso request %p too long\n", urb); 1395 span = sched->span;
1407 status = -EFBIG; 1396 if (!stream->highspeed) {
1408 goto fail; 1397 period <<= 3;
1398 span <<= 3;
1409 } 1399 }
1410 1400
1411 if ((stream->depth + sched->span) > mod) { 1401 if (span > mod - SCHEDULE_SLOP) {
1412 ehci_dbg (ehci, "request %p would overflow (%d+%d>%d)\n", 1402 ehci_dbg (ehci, "iso request %p too long\n", urb);
1413 urb, stream->depth, sched->span, mod);
1414 status = -EFBIG; 1403 status = -EFBIG;
1415 goto fail; 1404 goto fail;
1416 } 1405 }
1417 1406
1418 period = urb->interval; 1407 now = ehci_readl(ehci, &ehci->regs->frame_index) & (mod - 1);
1419 if (!stream->highspeed)
1420 period <<= 3;
1421
1422 now = ehci_readl(ehci, &ehci->regs->frame_index) % mod;
1423 1408
1424 /* Typical case: reuse current schedule, stream is still active. 1409 /* Typical case: reuse current schedule, stream is still active.
1425 * Hopefully there are no gaps from the host falling behind 1410 * Hopefully there are no gaps from the host falling behind
@@ -1427,34 +1412,35 @@ iso_stream_schedule (
1427 * slot in the schedule, implicitly assuming URB_ISO_ASAP. 1412 * slot in the schedule, implicitly assuming URB_ISO_ASAP.
1428 */ 1413 */
1429 if (likely (!list_empty (&stream->td_list))) { 1414 if (likely (!list_empty (&stream->td_list))) {
1430 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); 1415 u32 excess;
1431 start = stream->next_uframe;
1432 1416
1433 /* For high speed devices, allow scheduling within the 1417 /* For high speed devices, allow scheduling within the
1434 * isochronous scheduling threshold. For full speed devices, 1418 * isochronous scheduling threshold. For full speed devices
1435 * don't. (Work around for Intel ICH9 bug.) 1419 * and Intel PCI-based controllers, don't (work around for
1420 * Intel ICH9 bug).
1436 */ 1421 */
1437 if (!stream->highspeed && 1422 if (!stream->highspeed && ehci->fs_i_thresh)
1438 pdev->vendor == PCI_VENDOR_ID_INTEL)
1439 next = now + ehci->i_thresh; 1423 next = now + ehci->i_thresh;
1440 else 1424 else
1441 next = now; 1425 next = now;
1442 1426
1443 /* Fell behind (by up to twice the slop amount)? */ 1427 /* Fell behind (by up to twice the slop amount)?
1444 if (((start - next) & (mod - 1)) >= 1428 * We decide based on the time of the last currently-scheduled
1445 mod - 2 * SCHEDULE_SLOP) 1429 * slot, not the time of the next available slot.
1446 start += period * DIV_ROUND_UP( 1430 */
1447 (next - start) & (mod - 1), 1431 excess = (stream->next_uframe - period - next) & (mod - 1);
1448 period); 1432 if (excess >= mod - 2 * SCHEDULE_SLOP)
1449 1433 start = next + excess - mod + period *
1450 /* Tried to schedule too far into the future? */ 1434 DIV_ROUND_UP(mod - excess, period);
1451 if (unlikely(((start - now) & (mod - 1)) + sched->span 1435 else
1452 >= mod - 2 * SCHEDULE_SLOP)) { 1436 start = next + excess + period;
1437 if (start - now >= mod) {
1438 ehci_dbg(ehci, "request %p would overflow (%d+%d >= %d)\n",
1439 urb, start - now - period, period,
1440 mod);
1453 status = -EFBIG; 1441 status = -EFBIG;
1454 goto fail; 1442 goto fail;
1455 } 1443 }
1456 stream->next_uframe = start;
1457 goto ready;
1458 } 1444 }
1459 1445
1460 /* need to schedule; when's the next (u)frame we could start? 1446 /* need to schedule; when's the next (u)frame we could start?
@@ -1463,51 +1449,60 @@ iso_stream_schedule (
1463 * can also help high bandwidth if the dma and irq loads don't 1449 * can also help high bandwidth if the dma and irq loads don't
1464 * jump until after the queue is primed. 1450 * jump until after the queue is primed.
1465 */ 1451 */
1466 start = SCHEDULE_SLOP + (now & ~0x07); 1452 else {
1467 start %= mod; 1453 start = SCHEDULE_SLOP + (now & ~0x07);
1468 stream->next_uframe = start; 1454
1469 1455 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */
1470 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ 1456
1471 1457 /* find a uframe slot with enough bandwidth */
1472 /* find a uframe slot with enough bandwidth */ 1458 next = start + period;
1473 for (; start < (stream->next_uframe + period); start++) { 1459 for (; start < next; start++) {
1474 int enough_space; 1460
1475 1461 /* check schedule: enough space? */
1476 /* check schedule: enough space? */ 1462 if (stream->highspeed) {
1477 if (stream->highspeed) 1463 if (itd_slot_ok(ehci, mod, start,
1478 enough_space = itd_slot_ok (ehci, mod, start, 1464 stream->usecs, period))
1479 stream->usecs, period); 1465 break;
1480 else { 1466 } else {
1481 if ((start % 8) >= 6) 1467 if ((start % 8) >= 6)
1482 continue; 1468 continue;
1483 enough_space = sitd_slot_ok (ehci, mod, stream, 1469 if (sitd_slot_ok(ehci, mod, stream,
1484 start, sched, period); 1470 start, sched, period))
1471 break;
1472 }
1485 } 1473 }
1486 1474
1487 /* schedule it here if there's enough bandwidth */ 1475 /* no room in the schedule */
1488 if (enough_space) { 1476 if (start == next) {
1489 stream->next_uframe = start % mod; 1477 ehci_dbg(ehci, "iso resched full %p (now %d max %d)\n",
1490 goto ready; 1478 urb, now, now + mod);
1479 status = -ENOSPC;
1480 goto fail;
1491 } 1481 }
1492 } 1482 }
1493 1483
1494 /* no room in the schedule */ 1484 /* Tried to schedule too far into the future? */
1495 ehci_dbg (ehci, "iso %ssched full %p (now %d max %d)\n", 1485 if (unlikely(start - now + span - period
1496 list_empty (&stream->td_list) ? "" : "re", 1486 >= mod - 2 * SCHEDULE_SLOP)) {
1497 urb, now, now + mod); 1487 ehci_dbg(ehci, "request %p would overflow (%d+%d >= %d)\n",
1498 status = -ENOSPC; 1488 urb, start - now, span - period,
1489 mod - 2 * SCHEDULE_SLOP);
1490 status = -EFBIG;
1491 goto fail;
1492 }
1499 1493
1500fail: 1494 stream->next_uframe = start & (mod - 1);
1501 iso_sched_free (stream, sched);
1502 urb->hcpriv = NULL;
1503 return status;
1504 1495
1505ready:
1506 /* report high speed start in uframes; full speed, in frames */ 1496 /* report high speed start in uframes; full speed, in frames */
1507 urb->start_frame = stream->next_uframe; 1497 urb->start_frame = stream->next_uframe;
1508 if (!stream->highspeed) 1498 if (!stream->highspeed)
1509 urb->start_frame >>= 3; 1499 urb->start_frame >>= 3;
1510 return 0; 1500 return 0;
1501
1502 fail:
1503 iso_sched_free(stream, sched);
1504 urb->hcpriv = NULL;
1505 return status;
1511} 1506}
1512 1507
1513/*-------------------------------------------------------------------------*/ 1508/*-------------------------------------------------------------------------*/
@@ -1602,7 +1597,7 @@ itd_link_urb (
1602 struct ehci_iso_sched *iso_sched = urb->hcpriv; 1597 struct ehci_iso_sched *iso_sched = urb->hcpriv;
1603 struct ehci_itd *itd; 1598 struct ehci_itd *itd;
1604 1599
1605 next_uframe = stream->next_uframe % mod; 1600 next_uframe = stream->next_uframe & (mod - 1);
1606 1601
1607 if (unlikely (list_empty(&stream->td_list))) { 1602 if (unlikely (list_empty(&stream->td_list))) {
1608 ehci_to_hcd(ehci)->self.bandwidth_allocated 1603 ehci_to_hcd(ehci)->self.bandwidth_allocated
@@ -1613,7 +1608,6 @@ itd_link_urb (
1613 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 1608 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
1614 urb->interval, 1609 urb->interval,
1615 next_uframe >> 3, next_uframe & 0x7); 1610 next_uframe >> 3, next_uframe & 0x7);
1616 stream->start = jiffies;
1617 } 1611 }
1618 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 1612 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
1619 1613
@@ -1639,14 +1633,13 @@ itd_link_urb (
1639 itd_patch(ehci, itd, iso_sched, packet, uframe); 1633 itd_patch(ehci, itd, iso_sched, packet, uframe);
1640 1634
1641 next_uframe += stream->interval; 1635 next_uframe += stream->interval;
1642 stream->depth += stream->interval; 1636 next_uframe &= mod - 1;
1643 next_uframe %= mod;
1644 packet++; 1637 packet++;
1645 1638
1646 /* link completed itds into the schedule */ 1639 /* link completed itds into the schedule */
1647 if (((next_uframe >> 3) != frame) 1640 if (((next_uframe >> 3) != frame)
1648 || packet == urb->number_of_packets) { 1641 || packet == urb->number_of_packets) {
1649 itd_link (ehci, frame % ehci->periodic_size, itd); 1642 itd_link(ehci, frame & (ehci->periodic_size - 1), itd);
1650 itd = NULL; 1643 itd = NULL;
1651 } 1644 }
1652 } 1645 }
@@ -1695,7 +1688,6 @@ itd_complete (
1695 1688
1696 t = hc32_to_cpup(ehci, &itd->hw_transaction [uframe]); 1689 t = hc32_to_cpup(ehci, &itd->hw_transaction [uframe]);
1697 itd->hw_transaction [uframe] = 0; 1690 itd->hw_transaction [uframe] = 0;
1698 stream->depth -= stream->interval;
1699 1691
1700 /* report transfer status */ 1692 /* report transfer status */
1701 if (unlikely (t & ISO_ERRS)) { 1693 if (unlikely (t & ISO_ERRS)) {
@@ -1815,8 +1807,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1815 1807
1816 /* schedule ... need to lock */ 1808 /* schedule ... need to lock */
1817 spin_lock_irqsave (&ehci->lock, flags); 1809 spin_lock_irqsave (&ehci->lock, flags);
1818 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1810 if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
1819 &ehci_to_hcd(ehci)->flags))) {
1820 status = -ESHUTDOWN; 1811 status = -ESHUTDOWN;
1821 goto done_not_linked; 1812 goto done_not_linked;
1822 } 1813 }
@@ -2024,9 +2015,8 @@ sitd_link_urb (
2024 "sched devp %s ep%d%s-iso [%d] %dms/%04x\n", 2015 "sched devp %s ep%d%s-iso [%d] %dms/%04x\n",
2025 urb->dev->devpath, stream->bEndpointAddress & 0x0f, 2016 urb->dev->devpath, stream->bEndpointAddress & 0x0f,
2026 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 2017 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
2027 (next_uframe >> 3) % ehci->periodic_size, 2018 (next_uframe >> 3) & (ehci->periodic_size - 1),
2028 stream->interval, hc32_to_cpu(ehci, stream->splits)); 2019 stream->interval, hc32_to_cpu(ehci, stream->splits));
2029 stream->start = jiffies;
2030 } 2020 }
2031 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 2021 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
2032 2022
@@ -2047,13 +2037,12 @@ sitd_link_urb (
2047 sitd->urb = urb; 2037 sitd->urb = urb;
2048 2038
2049 sitd_patch(ehci, stream, sitd, sched, packet); 2039 sitd_patch(ehci, stream, sitd, sched, packet);
2050 sitd_link (ehci, (next_uframe >> 3) % ehci->periodic_size, 2040 sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1),
2051 sitd); 2041 sitd);
2052 2042
2053 next_uframe += stream->interval << 3; 2043 next_uframe += stream->interval << 3;
2054 stream->depth += stream->interval << 3;
2055 } 2044 }
2056 stream->next_uframe = next_uframe % mod; 2045 stream->next_uframe = next_uframe & (mod - 1);
2057 2046
2058 /* don't need that schedule data any more */ 2047 /* don't need that schedule data any more */
2059 iso_sched_free (stream, sched); 2048 iso_sched_free (stream, sched);
@@ -2111,7 +2100,6 @@ sitd_complete (
2111 desc->actual_length = desc->length - SITD_LENGTH(t); 2100 desc->actual_length = desc->length - SITD_LENGTH(t);
2112 urb->actual_length += desc->actual_length; 2101 urb->actual_length += desc->actual_length;
2113 } 2102 }
2114 stream->depth -= stream->interval << 3;
2115 2103
2116 /* handle completion now? */ 2104 /* handle completion now? */
2117 if ((urb_index + 1) != urb->number_of_packets) 2105 if ((urb_index + 1) != urb->number_of_packets)
@@ -2201,8 +2189,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2201 2189
2202 /* schedule ... need to lock */ 2190 /* schedule ... need to lock */
2203 spin_lock_irqsave (&ehci->lock, flags); 2191 spin_lock_irqsave (&ehci->lock, flags);
2204 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 2192 if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
2205 &ehci_to_hcd(ehci)->flags))) {
2206 status = -ESHUTDOWN; 2193 status = -ESHUTDOWN;
2207 goto done_not_linked; 2194 goto done_not_linked;
2208 } 2195 }
@@ -2263,7 +2250,7 @@ scan_periodic (struct ehci_hcd *ehci)
2263 now_uframe = ehci->next_uframe; 2250 now_uframe = ehci->next_uframe;
2264 if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { 2251 if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
2265 clock = ehci_readl(ehci, &ehci->regs->frame_index); 2252 clock = ehci_readl(ehci, &ehci->regs->frame_index);
2266 clock_frame = (clock >> 3) % ehci->periodic_size; 2253 clock_frame = (clock >> 3) & (ehci->periodic_size - 1);
2267 } else { 2254 } else {
2268 clock = now_uframe + mod - 1; 2255 clock = now_uframe + mod - 1;
2269 clock_frame = -1; 2256 clock_frame = -1;
@@ -2272,7 +2259,7 @@ scan_periodic (struct ehci_hcd *ehci)
2272 free_cached_lists(ehci); 2259 free_cached_lists(ehci);
2273 ehci->clock_frame = clock_frame; 2260 ehci->clock_frame = clock_frame;
2274 } 2261 }
2275 clock %= mod; 2262 clock &= mod - 1;
2276 clock_frame = clock >> 3; 2263 clock_frame = clock >> 3;
2277 2264
2278 for (;;) { 2265 for (;;) {
@@ -2361,7 +2348,7 @@ restart:
2361 * frame is current. 2348 * frame is current.
2362 */ 2349 */
2363 if (((frame == clock_frame) || 2350 if (((frame == clock_frame) ||
2364 (((frame + 1) % ehci->periodic_size) 2351 (((frame + 1) & (ehci->periodic_size - 1))
2365 == clock_frame)) 2352 == clock_frame))
2366 && live 2353 && live
2367 && (q.sitd->hw_results & 2354 && (q.sitd->hw_results &
@@ -2428,7 +2415,8 @@ restart:
2428 || ehci->periodic_sched == 0) 2415 || ehci->periodic_sched == 0)
2429 break; 2416 break;
2430 ehci->next_uframe = now_uframe; 2417 ehci->next_uframe = now_uframe;
2431 now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; 2418 now = ehci_readl(ehci, &ehci->regs->frame_index) &
2419 (mod - 1);
2432 if (now_uframe == now) 2420 if (now_uframe == now)
2433 break; 2421 break;
2434 2422
@@ -2441,7 +2429,7 @@ restart:
2441 } 2429 }
2442 } else { 2430 } else {
2443 now_uframe++; 2431 now_uframe++;
2444 now_uframe %= mod; 2432 now_uframe &= mod - 1;
2445 } 2433 }
2446 } 2434 }
2447} 2435}
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 650a687f2854..bde823f704e9 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -130,6 +130,7 @@ struct ehci_hcd { /* one per controller */
130 unsigned has_amcc_usb23:1; 130 unsigned has_amcc_usb23:1;
131 unsigned need_io_watchdog:1; 131 unsigned need_io_watchdog:1;
132 unsigned broken_periodic:1; 132 unsigned broken_periodic:1;
133 unsigned fs_i_thresh:1; /* Intel iso scheduling */
133 134
134 /* required for usb32 quirk */ 135 /* required for usb32 quirk */
135 #define OHCI_CTRL_HCFS (3 << 6) 136 #define OHCI_CTRL_HCFS (3 << 6)
@@ -140,7 +141,8 @@ struct ehci_hcd { /* one per controller */
140 #define OHCI_HCCTRL_LEN 0x4 141 #define OHCI_HCCTRL_LEN 0x4
141 __hc32 *ohci_hcctrl_reg; 142 __hc32 *ohci_hcctrl_reg;
142 unsigned has_hostpc:1; 143 unsigned has_hostpc:1;
143 144 unsigned has_lpm:1; /* support link power management */
145 unsigned has_ppcd:1; /* support per-port change bits */
144 u8 sbrn; /* packed release number */ 146 u8 sbrn; /* packed release number */
145 147
146 /* irq statistics */ 148 /* irq statistics */
@@ -154,9 +156,6 @@ struct ehci_hcd { /* one per controller */
154 /* debug files */ 156 /* debug files */
155#ifdef DEBUG 157#ifdef DEBUG
156 struct dentry *debug_dir; 158 struct dentry *debug_dir;
157 struct dentry *debug_async;
158 struct dentry *debug_periodic;
159 struct dentry *debug_registers;
160#endif 159#endif
161}; 160};
162 161
@@ -401,15 +400,12 @@ struct ehci_iso_stream {
401 u32 refcount; 400 u32 refcount;
402 u8 bEndpointAddress; 401 u8 bEndpointAddress;
403 u8 highspeed; 402 u8 highspeed;
404 u16 depth; /* depth in uframes */
405 struct list_head td_list; /* queued itds/sitds */ 403 struct list_head td_list; /* queued itds/sitds */
406 struct list_head free_list; /* list of unused itds/sitds */ 404 struct list_head free_list; /* list of unused itds/sitds */
407 struct usb_device *udev; 405 struct usb_device *udev;
408 struct usb_host_endpoint *ep; 406 struct usb_host_endpoint *ep;
409 407
410 /* output of (re)scheduling */ 408 /* output of (re)scheduling */
411 unsigned long start; /* jiffies */
412 unsigned long rescheduled;
413 int next_uframe; 409 int next_uframe;
414 __hc32 splits; 410 __hc32 splits;
415 411
@@ -538,11 +534,11 @@ struct ehci_fstn {
538 534
539/* Prepare the PORTSC wakeup flags during controller suspend/resume */ 535/* Prepare the PORTSC wakeup flags during controller suspend/resume */
540 536
541#define ehci_prepare_ports_for_controller_suspend(ehci) \ 537#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \
542 ehci_adjust_port_wakeup_flags(ehci, true); 538 ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup);
543 539
544#define ehci_prepare_ports_for_controller_resume(ehci) \ 540#define ehci_prepare_ports_for_controller_resume(ehci) \
545 ehci_adjust_port_wakeup_flags(ehci, false); 541 ehci_adjust_port_wakeup_flags(ehci, false, false);
546 542
547/*-------------------------------------------------------------------------*/ 543/*-------------------------------------------------------------------------*/
548 544
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 35742f8c7cda..9bfac657572e 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -159,7 +159,7 @@ static int hwahc_op_start(struct usb_hcd *usb_hcd)
159 goto error_set_cluster_id; 159 goto error_set_cluster_id;
160 160
161 usb_hcd->uses_new_polling = 1; 161 usb_hcd->uses_new_polling = 1;
162 usb_hcd->poll_rh = 1; 162 set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
163 usb_hcd->state = HC_STATE_RUNNING; 163 usb_hcd->state = HC_STATE_RUNNING;
164 result = 0; 164 result = 0;
165out: 165out:
@@ -776,7 +776,7 @@ static int hwahc_probe(struct usb_interface *usb_iface,
776 goto error_alloc; 776 goto error_alloc;
777 } 777 }
778 usb_hcd->wireless = 1; 778 usb_hcd->wireless = 1;
779 usb_hcd->flags |= HCD_FLAG_SAW_IRQ; 779 set_bit(HCD_FLAG_SAW_IRQ, &usb_hcd->flags);
780 wusbhc = usb_hcd_to_wusbhc(usb_hcd); 780 wusbhc = usb_hcd_to_wusbhc(usb_hcd);
781 hwahc = container_of(wusbhc, struct hwahc, wusbhc); 781 hwahc = container_of(wusbhc, struct hwahc, wusbhc);
782 hwahc_init(hwahc); 782 hwahc_init(hwahc);
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index caf116c09376..d0abb9b0e673 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -1521,7 +1521,7 @@ static int imx21_hc_reset(struct usb_hcd *hcd)
1521 return -ETIMEDOUT; 1521 return -ETIMEDOUT;
1522 } 1522 }
1523 spin_unlock_irq(&imx21->lock); 1523 spin_unlock_irq(&imx21->lock);
1524 schedule_timeout(1); 1524 schedule_timeout_uninterruptible(1);
1525 spin_lock_irq(&imx21->lock); 1525 spin_lock_irq(&imx21->lock);
1526 } 1526 }
1527 spin_unlock_irqrestore(&imx21->lock, flags); 1527 spin_unlock_irqrestore(&imx21->lock, flags);
diff --git a/drivers/usb/host/isp1362.h b/drivers/usb/host/isp1362.h
index d995351f9bed..0f97820e65be 100644
--- a/drivers/usb/host/isp1362.h
+++ b/drivers/usb/host/isp1362.h
@@ -8,29 +8,7 @@
8/* 8/*
9 * Platform specific compile time options 9 * Platform specific compile time options
10 */ 10 */
11#if defined(CONFIG_ARCH_KARO) 11#if defined(CONFIG_BLACKFIN)
12#include <asm/arch/hardware.h>
13#include <asm/arch/pxa-regs.h>
14#include <asm/arch/karo.h>
15
16#define USE_32BIT 1
17
18
19/* These options are mutually eclusive */
20#define USE_PLATFORM_DELAY 1
21#define USE_NDELAY 0
22/*
23 * MAX_ROOT_PORTS: Number of downstream ports
24 *
25 * The chip has two USB ports, one of which can be configured as
26 * an USB device port, so the value of this constant is implementation
27 * specific.
28 */
29#define MAX_ROOT_PORTS 2
30#define DUMMY_DELAY_ACCESS do {} while (0)
31
32/* insert platform specific definitions for other machines here */
33#elif defined(CONFIG_BLACKFIN)
34 12
35#include <linux/io.h> 13#include <linux/io.h>
36#define USE_32BIT 0 14#define USE_32BIT 0
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index dbcafa29c775..d1a3dfc9a408 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -482,7 +482,6 @@ static int isp1760_run(struct usb_hcd *hcd)
482 u32 chipid; 482 u32 chipid;
483 483
484 hcd->uses_new_polling = 1; 484 hcd->uses_new_polling = 1;
485 hcd->poll_rh = 0;
486 485
487 hcd->state = HC_STATE_RUNNING; 486 hcd->state = HC_STATE_RUNNING;
488 isp1760_enable_interrupts(hcd); 487 isp1760_enable_interrupts(hcd);
@@ -1450,7 +1449,7 @@ static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb,
1450 epnum = urb->ep->desc.bEndpointAddress; 1449 epnum = urb->ep->desc.bEndpointAddress;
1451 1450
1452 spin_lock_irqsave(&priv->lock, flags); 1451 spin_lock_irqsave(&priv->lock, flags);
1453 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &priv_to_hcd(priv)->flags)) { 1452 if (!HCD_HW_ACCESSIBLE(priv_to_hcd(priv))) {
1454 rc = -ESHUTDOWN; 1453 rc = -ESHUTDOWN;
1455 goto done; 1454 goto done;
1456 } 1455 }
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 8ad2441b0284..36abd2baa3ea 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -645,7 +645,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
645 hcd->product_desc, 645 hcd->product_desc,
646 hcd_name); 646 hcd_name);
647 647
648 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 648 if (!HCD_HW_ACCESSIBLE(hcd)) {
649 size -= scnprintf (next, size, 649 size -= scnprintf (next, size,
650 "SUSPENDED (no register access)\n"); 650 "SUSPENDED (no register access)\n");
651 goto done; 651 goto done;
@@ -687,7 +687,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
687 next += temp; 687 next += temp;
688 688
689 temp = scnprintf (next, size, "hub poll timer %s\n", 689 temp = scnprintf (next, size, "hub poll timer %s\n",
690 ohci_to_hcd(ohci)->poll_rh ? "ON" : "off"); 690 HCD_POLL_RH(ohci_to_hcd(ohci)) ? "ON" : "off");
691 size -= temp; 691 size -= temp;
692 next += temp; 692 next += temp;
693 693
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 3ceb097e165a..15ae39d6cc24 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -212,7 +212,7 @@ static int ohci_urb_enqueue (
212 spin_lock_irqsave (&ohci->lock, flags); 212 spin_lock_irqsave (&ohci->lock, flags);
213 213
214 /* don't submit to a dead HC */ 214 /* don't submit to a dead HC */
215 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 215 if (!HCD_HW_ACCESSIBLE(hcd)) {
216 retval = -ENODEV; 216 retval = -ENODEV;
217 goto fail; 217 goto fail;
218 } 218 }
@@ -684,7 +684,7 @@ retry:
684 } 684 }
685 685
686 /* use rhsc irqs after khubd is fully initialized */ 686 /* use rhsc irqs after khubd is fully initialized */
687 hcd->poll_rh = 1; 687 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
688 hcd->uses_new_polling = 1; 688 hcd->uses_new_polling = 1;
689 689
690 /* start controller operations */ 690 /* start controller operations */
@@ -821,7 +821,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
821 else if (ints & OHCI_INTR_RD) { 821 else if (ints & OHCI_INTR_RD) {
822 ohci_vdbg(ohci, "resume detect\n"); 822 ohci_vdbg(ohci, "resume detect\n");
823 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus); 823 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
824 hcd->poll_rh = 1; 824 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
825 if (ohci->autostop) { 825 if (ohci->autostop) {
826 spin_lock (&ohci->lock); 826 spin_lock (&ohci->lock);
827 ohci_rh_resume (ohci); 827 ohci_rh_resume (ohci);
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 65cac8cc8921..cddcda95b579 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -284,7 +284,7 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
284 284
285 spin_lock_irq (&ohci->lock); 285 spin_lock_irq (&ohci->lock);
286 286
287 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 287 if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
288 rc = -ESHUTDOWN; 288 rc = -ESHUTDOWN;
289 else 289 else
290 rc = ohci_rh_suspend (ohci, 0); 290 rc = ohci_rh_suspend (ohci, 0);
@@ -302,7 +302,7 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
302 302
303 spin_lock_irq (&ohci->lock); 303 spin_lock_irq (&ohci->lock);
304 304
305 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 305 if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
306 rc = -ESHUTDOWN; 306 rc = -ESHUTDOWN;
307 else 307 else
308 rc = ohci_rh_resume (ohci); 308 rc = ohci_rh_resume (ohci);
@@ -355,6 +355,11 @@ static void ohci_finish_controller_resume(struct usb_hcd *hcd)
355 ohci_readl(ohci, &ohci->regs->intrenable); 355 ohci_readl(ohci, &ohci->regs->intrenable);
356 msleep(20); 356 msleep(20);
357 } 357 }
358
359 /* Does the root hub have a port wakeup pending? */
360 if (ohci_readl(ohci, &ohci->regs->intrstatus) &
361 (OHCI_INTR_RD | OHCI_INTR_RHSC))
362 usb_hcd_resume_root_hub(hcd);
358} 363}
359 364
360/* Carry out polling-, autostop-, and autoresume-related state changes */ 365/* Carry out polling-, autostop-, and autoresume-related state changes */
@@ -364,7 +369,7 @@ static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
364 int poll_rh = 1; 369 int poll_rh = 1;
365 int rhsc_enable; 370 int rhsc_enable;
366 371
367 /* Some broken controllers never turn off RHCS in the interrupt 372 /* Some broken controllers never turn off RHSC in the interrupt
368 * status register. For their sake we won't re-enable RHSC 373 * status register. For their sake we won't re-enable RHSC
369 * interrupts if the interrupt bit is already active. 374 * interrupts if the interrupt bit is already active.
370 */ 375 */
@@ -489,7 +494,7 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
489 unsigned long flags; 494 unsigned long flags;
490 495
491 spin_lock_irqsave (&ohci->lock, flags); 496 spin_lock_irqsave (&ohci->lock, flags);
492 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 497 if (!HCD_HW_ACCESSIBLE(hcd))
493 goto done; 498 goto done;
494 499
495 /* undocumented erratum seen on at least rev D */ 500 /* undocumented erratum seen on at least rev D */
@@ -533,8 +538,12 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
533 } 538 }
534 } 539 }
535 540
536 hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed, 541 if (ohci_root_hub_state_changes(ohci, changed,
537 any_connected, rhsc_status); 542 any_connected, rhsc_status))
543 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
544 else
545 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
546
538 547
539done: 548done:
540 spin_unlock_irqrestore (&ohci->lock, flags); 549 spin_unlock_irqrestore (&ohci->lock, flags);
@@ -701,7 +710,7 @@ static int ohci_hub_control (
701 u32 temp; 710 u32 temp;
702 int retval = 0; 711 int retval = 0;
703 712
704 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 713 if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
705 return -ESHUTDOWN; 714 return -ESHUTDOWN;
706 715
707 switch (typeReq) { 716 switch (typeReq) {
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index b8a1148f248e..6bdc8b25a6a1 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -392,7 +392,7 @@ static int __devinit ohci_pci_start (struct usb_hcd *hcd)
392 392
393#ifdef CONFIG_PM 393#ifdef CONFIG_PM
394 394
395static int ohci_pci_suspend(struct usb_hcd *hcd) 395static int ohci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
396{ 396{
397 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 397 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
398 unsigned long flags; 398 unsigned long flags;
diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
index 23fd6a886bdd..48ee6943bf35 100644
--- a/drivers/usb/host/ohci-ssb.c
+++ b/drivers/usb/host/ohci-ssb.c
@@ -93,8 +93,11 @@ static void ssb_ohci_detach(struct ssb_device *dev)
93{ 93{
94 struct usb_hcd *hcd = ssb_get_drvdata(dev); 94 struct usb_hcd *hcd = ssb_get_drvdata(dev);
95 95
96 if (hcd->driver->shutdown)
97 hcd->driver->shutdown(hcd);
96 usb_remove_hcd(hcd); 98 usb_remove_hcd(hcd);
97 iounmap(hcd->regs); 99 iounmap(hcd->regs);
100 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
98 usb_put_hcd(hcd); 101 usb_put_hcd(hcd);
99 ssb_device_disable(dev, 0); 102 ssb_device_disable(dev, 0);
100} 103}
@@ -106,10 +109,52 @@ static int ssb_ohci_attach(struct ssb_device *dev)
106 int err = -ENOMEM; 109 int err = -ENOMEM;
107 u32 tmp, flags = 0; 110 u32 tmp, flags = 0;
108 111
109 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) 112 if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
110 flags |= SSB_OHCI_TMSLOW_HOSTMODE; 113 dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
114 return -EOPNOTSUPP;
111 115
112 ssb_device_enable(dev, flags); 116 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) {
117 /* Put the device into host-mode. */
118 flags |= SSB_OHCI_TMSLOW_HOSTMODE;
119 ssb_device_enable(dev, flags);
120 } else if (dev->id.coreid == SSB_DEV_USB20_HOST) {
121 /*
122 * USB 2.0 special considerations:
123 *
124 * In addition to the standard SSB reset sequence, the Host
125 * Control Register must be programmed to bring the USB core
126 * and various phy components out of reset.
127 */
128 ssb_device_enable(dev, 0);
129 ssb_write32(dev, 0x200, 0x7ff);
130
131 /* Change Flush control reg */
132 tmp = ssb_read32(dev, 0x400);
133 tmp &= ~8;
134 ssb_write32(dev, 0x400, tmp);
135 tmp = ssb_read32(dev, 0x400);
136
137 /* Change Shim control reg */
138 tmp = ssb_read32(dev, 0x304);
139 tmp &= ~0x100;
140 ssb_write32(dev, 0x304, tmp);
141 tmp = ssb_read32(dev, 0x304);
142
143 udelay(1);
144
145 /* Work around for 5354 failures */
146 if (dev->id.revision == 2 && dev->bus->chip_id == 0x5354) {
147 /* Change syn01 reg */
148 tmp = 0x00fe00fe;
149 ssb_write32(dev, 0x894, tmp);
150
151 /* Change syn03 reg */
152 tmp = ssb_read32(dev, 0x89c);
153 tmp |= 0x1;
154 ssb_write32(dev, 0x89c, tmp);
155 }
156 } else
157 ssb_device_enable(dev, 0);
113 158
114 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev, 159 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
115 dev_name(dev->dev)); 160 dev_name(dev->dev));
@@ -200,6 +245,7 @@ static int ssb_ohci_resume(struct ssb_device *dev)
200static const struct ssb_device_id ssb_ohci_table[] = { 245static const struct ssb_device_id ssb_ohci_table[] = {
201 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV), 246 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
202 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV), 247 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
248 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB20_HOST, SSB_ANY_REV),
203 SSB_DEVTABLE_END 249 SSB_DEVTABLE_END
204}; 250};
205MODULE_DEVICE_TABLE(ssb, ssb_ohci_table); 251MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index de9e1c35da45..8026dc85996c 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -1633,8 +1633,7 @@ static int submit_async(struct oxu_hcd *oxu, struct urb *urb,
1633#endif 1633#endif
1634 1634
1635 spin_lock_irqsave(&oxu->lock, flags); 1635 spin_lock_irqsave(&oxu->lock, flags);
1636 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1636 if (unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) {
1637 &oxu_to_hcd(oxu)->flags))) {
1638 rc = -ESHUTDOWN; 1637 rc = -ESHUTDOWN;
1639 goto done; 1638 goto done;
1640 } 1639 }
@@ -2201,8 +2200,7 @@ static int intr_submit(struct oxu_hcd *oxu, struct urb *urb,
2201 2200
2202 spin_lock_irqsave(&oxu->lock, flags); 2201 spin_lock_irqsave(&oxu->lock, flags);
2203 2202
2204 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 2203 if (unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) {
2205 &oxu_to_hcd(oxu)->flags))) {
2206 status = -ESHUTDOWN; 2204 status = -ESHUTDOWN;
2207 goto done; 2205 goto done;
2208 } 2206 }
@@ -2707,7 +2705,6 @@ static int oxu_run(struct usb_hcd *hcd)
2707 u32 temp, hcc_params; 2705 u32 temp, hcc_params;
2708 2706
2709 hcd->uses_new_polling = 1; 2707 hcd->uses_new_polling = 1;
2710 hcd->poll_rh = 0;
2711 2708
2712 /* EHCI spec section 4.1 */ 2709 /* EHCI spec section 4.1 */
2713 retval = ehci_reset(oxu); 2710 retval = ehci_reset(oxu);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index bcf9f0e809de..990f06b89eaa 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -813,8 +813,11 @@ static int sl811h_urb_enqueue(
813#endif 813#endif
814 814
815 /* avoid all allocations within spinlocks */ 815 /* avoid all allocations within spinlocks */
816 if (!hep->hcpriv) 816 if (!hep->hcpriv) {
817 ep = kzalloc(sizeof *ep, mem_flags); 817 ep = kzalloc(sizeof *ep, mem_flags);
818 if (ep == NULL)
819 return -ENOMEM;
820 }
818 821
819 spin_lock_irqsave(&sl811->lock, flags); 822 spin_lock_irqsave(&sl811->lock, flags);
820 823
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 98cf0b26b968..6e7fb5f38db6 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -17,7 +17,6 @@
17 17
18#include "uhci-hcd.h" 18#include "uhci-hcd.h"
19 19
20#define uhci_debug_operations (* (const struct file_operations *) NULL)
21static struct dentry *uhci_debugfs_root; 20static struct dentry *uhci_debugfs_root;
22 21
23#ifdef DEBUG 22#ifdef DEBUG
@@ -495,18 +494,16 @@ static int uhci_debug_open(struct inode *inode, struct file *file)
495{ 494{
496 struct uhci_hcd *uhci = inode->i_private; 495 struct uhci_hcd *uhci = inode->i_private;
497 struct uhci_debug *up; 496 struct uhci_debug *up;
498 int ret = -ENOMEM;
499 unsigned long flags; 497 unsigned long flags;
500 498
501 lock_kernel();
502 up = kmalloc(sizeof(*up), GFP_KERNEL); 499 up = kmalloc(sizeof(*up), GFP_KERNEL);
503 if (!up) 500 if (!up)
504 goto out; 501 return -ENOMEM;
505 502
506 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL); 503 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
507 if (!up->data) { 504 if (!up->data) {
508 kfree(up); 505 kfree(up);
509 goto out; 506 return -ENOMEM;
510 } 507 }
511 508
512 up->size = 0; 509 up->size = 0;
@@ -517,10 +514,7 @@ static int uhci_debug_open(struct inode *inode, struct file *file)
517 514
518 file->private_data = up; 515 file->private_data = up;
519 516
520 ret = 0; 517 return 0;
521out:
522 unlock_kernel();
523 return ret;
524} 518}
525 519
526static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence) 520static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
@@ -528,9 +522,9 @@ static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
528 struct uhci_debug *up; 522 struct uhci_debug *up;
529 loff_t new = -1; 523 loff_t new = -1;
530 524
531 lock_kernel();
532 up = file->private_data; 525 up = file->private_data;
533 526
527 /* XXX: atomic 64bit seek access, but that needs to be fixed in the VFS */
534 switch (whence) { 528 switch (whence) {
535 case 0: 529 case 0:
536 new = off; 530 new = off;
@@ -539,11 +533,10 @@ static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
539 new = file->f_pos + off; 533 new = file->f_pos + off;
540 break; 534 break;
541 } 535 }
542 if (new < 0 || new > up->size) { 536
543 unlock_kernel(); 537 if (new < 0 || new > up->size)
544 return -EINVAL; 538 return -EINVAL;
545 } 539
546 unlock_kernel();
547 return (file->f_pos = new); 540 return (file->f_pos = new);
548} 541}
549 542
@@ -564,7 +557,6 @@ static int uhci_debug_release(struct inode *inode, struct file *file)
564 return 0; 557 return 0;
565} 558}
566 559
567#undef uhci_debug_operations
568static const struct file_operations uhci_debug_operations = { 560static const struct file_operations uhci_debug_operations = {
569 .owner = THIS_MODULE, 561 .owner = THIS_MODULE,
570 .open = uhci_debug_open, 562 .open = uhci_debug_open,
@@ -572,6 +564,7 @@ static const struct file_operations uhci_debug_operations = {
572 .read = uhci_debug_read, 564 .read = uhci_debug_read,
573 .release = uhci_debug_release, 565 .release = uhci_debug_release,
574}; 566};
567#define UHCI_DEBUG_OPS
575 568
576#endif /* CONFIG_DEBUG_FS */ 569#endif /* CONFIG_DEBUG_FS */
577 570
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 6637e52736dd..f52d04db28f4 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -140,7 +140,7 @@ static void finish_reset(struct uhci_hcd *uhci)
140 uhci->rh_state = UHCI_RH_RESET; 140 uhci->rh_state = UHCI_RH_RESET;
141 uhci->is_stopped = UHCI_IS_STOPPED; 141 uhci->is_stopped = UHCI_IS_STOPPED;
142 uhci_to_hcd(uhci)->state = HC_STATE_HALT; 142 uhci_to_hcd(uhci)->state = HC_STATE_HALT;
143 uhci_to_hcd(uhci)->poll_rh = 0; 143 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
144 144
145 uhci->dead = 0; /* Full reset resurrects the controller */ 145 uhci->dead = 0; /* Full reset resurrects the controller */
146} 146}
@@ -176,6 +176,8 @@ static void check_and_reset_hc(struct uhci_hcd *uhci)
176 */ 176 */
177static void configure_hc(struct uhci_hcd *uhci) 177static void configure_hc(struct uhci_hcd *uhci)
178{ 178{
179 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
180
179 /* Set the frame length to the default: 1 ms exactly */ 181 /* Set the frame length to the default: 1 ms exactly */
180 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF); 182 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF);
181 183
@@ -191,8 +193,11 @@ static void configure_hc(struct uhci_hcd *uhci)
191 mb(); 193 mb();
192 194
193 /* Enable PIRQ */ 195 /* Enable PIRQ */
194 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 196 pci_write_config_word(pdev, USBLEGSUP, USBLEGSUP_DEFAULT);
195 USBLEGSUP_DEFAULT); 197
198 /* Disable platform-specific non-PME# wakeup */
199 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
200 pci_write_config_byte(pdev, USBRES_INTEL, 0);
196} 201}
197 202
198 203
@@ -344,7 +349,10 @@ __acquires(uhci->lock)
344 /* If interrupts don't work and remote wakeup is enabled then 349 /* If interrupts don't work and remote wakeup is enabled then
345 * the suspended root hub needs to be polled. 350 * the suspended root hub needs to be polled.
346 */ 351 */
347 uhci_to_hcd(uhci)->poll_rh = (!int_enable && wakeup_enable); 352 if (!int_enable && wakeup_enable)
353 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
354 else
355 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
348 356
349 uhci_scan_schedule(uhci); 357 uhci_scan_schedule(uhci);
350 uhci_fsbr_off(uhci); 358 uhci_fsbr_off(uhci);
@@ -363,7 +371,7 @@ static void start_rh(struct uhci_hcd *uhci)
363 uhci->io_addr + USBINTR); 371 uhci->io_addr + USBINTR);
364 mb(); 372 mb();
365 uhci->rh_state = UHCI_RH_RUNNING; 373 uhci->rh_state = UHCI_RH_RUNNING;
366 uhci_to_hcd(uhci)->poll_rh = 1; 374 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
367} 375}
368 376
369static void wakeup_rh(struct uhci_hcd *uhci) 377static void wakeup_rh(struct uhci_hcd *uhci)
@@ -589,7 +597,7 @@ static int uhci_start(struct usb_hcd *hcd)
589 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 597 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
590 int retval = -EBUSY; 598 int retval = -EBUSY;
591 int i; 599 int i;
592 struct dentry *dentry; 600 struct dentry __maybe_unused *dentry;
593 601
594 hcd->uses_new_polling = 1; 602 hcd->uses_new_polling = 1;
595 603
@@ -599,18 +607,16 @@ static int uhci_start(struct usb_hcd *hcd)
599 INIT_LIST_HEAD(&uhci->idle_qh_list); 607 INIT_LIST_HEAD(&uhci->idle_qh_list);
600 init_waitqueue_head(&uhci->waitqh); 608 init_waitqueue_head(&uhci->waitqh);
601 609
602 if (DEBUG_CONFIGURED) { 610#ifdef UHCI_DEBUG_OPS
603 dentry = debugfs_create_file(hcd->self.bus_name, 611 dentry = debugfs_create_file(hcd->self.bus_name,
604 S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, 612 S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root,
605 uhci, &uhci_debug_operations); 613 uhci, &uhci_debug_operations);
606 if (!dentry) { 614 if (!dentry) {
607 dev_err(uhci_dev(uhci), "couldn't create uhci " 615 dev_err(uhci_dev(uhci), "couldn't create uhci debugfs entry\n");
608 "debugfs entry\n"); 616 return -ENOMEM;
609 retval = -ENOMEM;
610 goto err_create_debug_entry;
611 }
612 uhci->dentry = dentry;
613 } 617 }
618 uhci->dentry = dentry;
619#endif
614 620
615 uhci->frame = dma_alloc_coherent(uhci_dev(uhci), 621 uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
616 UHCI_NUMFRAMES * sizeof(*uhci->frame), 622 UHCI_NUMFRAMES * sizeof(*uhci->frame),
@@ -691,7 +697,9 @@ static int uhci_start(struct usb_hcd *hcd)
691 697
692 configure_hc(uhci); 698 configure_hc(uhci);
693 uhci->is_initialized = 1; 699 uhci->is_initialized = 1;
700 spin_lock_irq(&uhci->lock);
694 start_rh(uhci); 701 start_rh(uhci);
702 spin_unlock_irq(&uhci->lock);
695 return 0; 703 return 0;
696 704
697/* 705/*
@@ -722,7 +730,6 @@ err_alloc_frame_cpu:
722err_alloc_frame: 730err_alloc_frame:
723 debugfs_remove(uhci->dentry); 731 debugfs_remove(uhci->dentry);
724 732
725err_create_debug_entry:
726 return retval; 733 return retval;
727} 734}
728 735
@@ -731,7 +738,7 @@ static void uhci_stop(struct usb_hcd *hcd)
731 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 738 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
732 739
733 spin_lock_irq(&uhci->lock); 740 spin_lock_irq(&uhci->lock);
734 if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && !uhci->dead) 741 if (HCD_HW_ACCESSIBLE(hcd) && !uhci->dead)
735 uhci_hc_died(uhci); 742 uhci_hc_died(uhci);
736 uhci_scan_schedule(uhci); 743 uhci_scan_schedule(uhci);
737 spin_unlock_irq(&uhci->lock); 744 spin_unlock_irq(&uhci->lock);
@@ -748,7 +755,7 @@ static int uhci_rh_suspend(struct usb_hcd *hcd)
748 int rc = 0; 755 int rc = 0;
749 756
750 spin_lock_irq(&uhci->lock); 757 spin_lock_irq(&uhci->lock);
751 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 758 if (!HCD_HW_ACCESSIBLE(hcd))
752 rc = -ESHUTDOWN; 759 rc = -ESHUTDOWN;
753 else if (uhci->dead) 760 else if (uhci->dead)
754 ; /* Dead controllers tell no tales */ 761 ; /* Dead controllers tell no tales */
@@ -775,7 +782,7 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
775 int rc = 0; 782 int rc = 0;
776 783
777 spin_lock_irq(&uhci->lock); 784 spin_lock_irq(&uhci->lock);
778 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 785 if (!HCD_HW_ACCESSIBLE(hcd))
779 rc = -ESHUTDOWN; 786 rc = -ESHUTDOWN;
780 else if (!uhci->dead) 787 else if (!uhci->dead)
781 wakeup_rh(uhci); 788 wakeup_rh(uhci);
@@ -783,15 +790,16 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
783 return rc; 790 return rc;
784} 791}
785 792
786static int uhci_pci_suspend(struct usb_hcd *hcd) 793static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
787{ 794{
788 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 795 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
796 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
789 int rc = 0; 797 int rc = 0;
790 798
791 dev_dbg(uhci_dev(uhci), "%s\n", __func__); 799 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
792 800
793 spin_lock_irq(&uhci->lock); 801 spin_lock_irq(&uhci->lock);
794 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 802 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
795 goto done_okay; /* Already suspended or dead */ 803 goto done_okay; /* Already suspended or dead */
796 804
797 if (uhci->rh_state > UHCI_RH_SUSPENDED) { 805 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
@@ -803,11 +811,15 @@ static int uhci_pci_suspend(struct usb_hcd *hcd)
803 /* All PCI host controllers are required to disable IRQ generation 811 /* All PCI host controllers are required to disable IRQ generation
804 * at the source, so we must turn off PIRQ. 812 * at the source, so we must turn off PIRQ.
805 */ 813 */
806 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); 814 pci_write_config_word(pdev, USBLEGSUP, 0);
807 mb(); 815 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
808 hcd->poll_rh = 0; 816
809 817 /* Enable platform-specific non-PME# wakeup */
810 /* FIXME: Enable non-PME# remote wakeup? */ 818 if (do_wakeup) {
819 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
820 pci_write_config_byte(pdev, USBRES_INTEL,
821 USBPORT1EN | USBPORT2EN);
822 }
811 823
812done_okay: 824done_okay:
813 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 825 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
@@ -826,7 +838,6 @@ static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
826 * even if the controller was dead. 838 * even if the controller was dead.
827 */ 839 */
828 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 840 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
829 mb();
830 841
831 spin_lock_irq(&uhci->lock); 842 spin_lock_irq(&uhci->lock);
832 843
@@ -834,8 +845,6 @@ static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
834 if (hibernated) 845 if (hibernated)
835 uhci_hc_died(uhci); 846 uhci_hc_died(uhci);
836 847
837 /* FIXME: Disable non-PME# remote wakeup? */
838
839 /* The firmware or a boot kernel may have changed the controller 848 /* The firmware or a boot kernel may have changed the controller
840 * settings during a system wakeup. Check it and reconfigure 849 * settings during a system wakeup. Check it and reconfigure
841 * to avoid problems. 850 * to avoid problems.
@@ -845,22 +854,20 @@ static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
845 /* If the controller was dead before, it's back alive now */ 854 /* If the controller was dead before, it's back alive now */
846 configure_hc(uhci); 855 configure_hc(uhci);
847 856
848 if (uhci->rh_state == UHCI_RH_RESET) { 857 /* Tell the core if the controller had to be reset */
849 858 if (uhci->rh_state == UHCI_RH_RESET)
850 /* The controller had to be reset */
851 usb_root_hub_lost_power(hcd->self.root_hub); 859 usb_root_hub_lost_power(hcd->self.root_hub);
852 suspend_rh(uhci, UHCI_RH_SUSPENDED);
853 }
854 860
855 spin_unlock_irq(&uhci->lock); 861 spin_unlock_irq(&uhci->lock);
856 862
857 /* If interrupts don't work and remote wakeup is enabled then 863 /* If interrupts don't work and remote wakeup is enabled then
858 * the suspended root hub needs to be polled. 864 * the suspended root hub needs to be polled.
859 */ 865 */
860 if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup) { 866 if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup)
861 hcd->poll_rh = 1; 867 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
862 usb_hcd_poll_rh_status(hcd); 868
863 } 869 /* Does the root hub have a port wakeup pending? */
870 usb_hcd_poll_rh_status(hcd);
864 return 0; 871 return 0;
865} 872}
866#endif 873#endif
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 26bd1b2bcbfc..49bf2790f9c2 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -67,12 +67,17 @@
67#define USBPORTSC_RES3 0x4000 /* reserved, write zeroes */ 67#define USBPORTSC_RES3 0x4000 /* reserved, write zeroes */
68#define USBPORTSC_RES4 0x8000 /* reserved, write zeroes */ 68#define USBPORTSC_RES4 0x8000 /* reserved, write zeroes */
69 69
70/* Legacy support register */ 70/* PCI legacy support register */
71#define USBLEGSUP 0xc0 71#define USBLEGSUP 0xc0
72#define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */ 72#define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */
73#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */ 73#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */
74#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */ 74#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */
75 75
76/* PCI Intel-specific resume-enable register */
77#define USBRES_INTEL 0xc4
78#define USBPORT1EN 0x01
79#define USBPORT2EN 0x02
80
76#define UHCI_PTR_BITS cpu_to_le32(0x000F) 81#define UHCI_PTR_BITS cpu_to_le32(0x000F)
77#define UHCI_PTR_TERM cpu_to_le32(0x0001) 82#define UHCI_PTR_TERM cpu_to_le32(0x0001)
78#define UHCI_PTR_QH cpu_to_le32(0x0002) 83#define UHCI_PTR_QH cpu_to_le32(0x0002)
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 8270055848ca..6d59c0f77f25 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -190,7 +190,7 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
190 spin_lock_irqsave(&uhci->lock, flags); 190 spin_lock_irqsave(&uhci->lock, flags);
191 191
192 uhci_scan_schedule(uhci); 192 uhci_scan_schedule(uhci);
193 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 193 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
194 goto done; 194 goto done;
195 uhci_check_ports(uhci); 195 uhci_check_ports(uhci);
196 196
@@ -200,7 +200,7 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
200 case UHCI_RH_SUSPENDING: 200 case UHCI_RH_SUSPENDING:
201 case UHCI_RH_SUSPENDED: 201 case UHCI_RH_SUSPENDED:
202 /* if port change, ask to be resumed */ 202 /* if port change, ask to be resumed */
203 if (status) 203 if (status || uhci->resuming_ports)
204 usb_hcd_resume_root_hub(hcd); 204 usb_hcd_resume_root_hub(hcd);
205 break; 205 break;
206 206
@@ -246,7 +246,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
246 u16 wPortChange, wPortStatus; 246 u16 wPortChange, wPortStatus;
247 unsigned long flags; 247 unsigned long flags;
248 248
249 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 249 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
250 return -ETIMEDOUT; 250 return -ETIMEDOUT;
251 251
252 spin_lock_irqsave(&uhci->lock, flags); 252 spin_lock_irqsave(&uhci->lock, flags);
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index acd582c02802..d3ade4018487 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -565,7 +565,7 @@ static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
565 qh->unlink_frame = uhci->frame_number; 565 qh->unlink_frame = uhci->frame_number;
566 566
567 /* Force an interrupt so we know when the QH is fully unlinked */ 567 /* Force an interrupt so we know when the QH is fully unlinked */
568 if (list_empty(&uhci->skel_unlink_qh->node)) 568 if (list_empty(&uhci->skel_unlink_qh->node) || uhci->is_stopped)
569 uhci_set_next_interrupt(uhci); 569 uhci_set_next_interrupt(uhci);
570 570
571 /* Move the QH from its old list to the end of the unlinking list */ 571 /* Move the QH from its old list to the end of the unlinking list */
@@ -1667,7 +1667,7 @@ static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh)
1667 qh->advance_jiffies = jiffies; 1667 qh->advance_jiffies = jiffies;
1668 goto done; 1668 goto done;
1669 } 1669 }
1670 ret = 0; 1670 ret = uhci->is_stopped;
1671 } 1671 }
1672 1672
1673 /* The queue hasn't advanced; check for timeout */ 1673 /* The queue hasn't advanced; check for timeout */
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index e0d3401285c8..72b6892fda67 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -68,7 +68,7 @@ static int whc_start(struct usb_hcd *usb_hcd)
68 whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN); 68 whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN);
69 69
70 usb_hcd->uses_new_polling = 1; 70 usb_hcd->uses_new_polling = 1;
71 usb_hcd->poll_rh = 1; 71 set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
72 usb_hcd->state = HC_STATE_RUNNING; 72 usb_hcd->state = HC_STATE_RUNNING;
73 73
74out: 74out:
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index ab5a14fbfeeb..dc0ab8382f5d 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -475,7 +475,7 @@ static int qset_add_urb_sg(struct whc *whc, struct whc_qset *qset, struct urb *u
475 || (prev_end & (WHCI_PAGE_SIZE-1)) 475 || (prev_end & (WHCI_PAGE_SIZE-1))
476 || (dma_addr & (WHCI_PAGE_SIZE-1)) 476 || (dma_addr & (WHCI_PAGE_SIZE-1))
477 || std->len + WHCI_PAGE_SIZE > QTD_MAX_XFER_SIZE) { 477 || std->len + WHCI_PAGE_SIZE > QTD_MAX_XFER_SIZE) {
478 if (std->len % qset->max_packet != 0) 478 if (std && std->len % qset->max_packet != 0)
479 return -EINVAL; 479 return -EINVAL;
480 std = qset_new_std(whc, qset, urb, mem_flags); 480 std = qset_new_std(whc, qset, urb, mem_flags);
481 if (std == NULL) { 481 if (std == NULL) {
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 2eb658d26394..4e51343ddffc 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -391,49 +391,6 @@ struct xhci_ring *xhci_stream_id_to_ring(
391 return ep->stream_info->stream_rings[stream_id]; 391 return ep->stream_info->stream_rings[stream_id];
392} 392}
393 393
394struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
395 unsigned int slot_id, unsigned int ep_index,
396 unsigned int stream_id)
397{
398 struct xhci_virt_ep *ep;
399
400 ep = &xhci->devs[slot_id]->eps[ep_index];
401 /* Common case: no streams */
402 if (!(ep->ep_state & EP_HAS_STREAMS))
403 return ep->ring;
404
405 if (stream_id == 0) {
406 xhci_warn(xhci,
407 "WARN: Slot ID %u, ep index %u has streams, "
408 "but URB has no stream ID.\n",
409 slot_id, ep_index);
410 return NULL;
411 }
412
413 if (stream_id < ep->stream_info->num_streams)
414 return ep->stream_info->stream_rings[stream_id];
415
416 xhci_warn(xhci,
417 "WARN: Slot ID %u, ep index %u has "
418 "stream IDs 1 to %u allocated, "
419 "but stream ID %u is requested.\n",
420 slot_id, ep_index,
421 ep->stream_info->num_streams - 1,
422 stream_id);
423 return NULL;
424}
425
426/* Get the right ring for the given URB.
427 * If the endpoint supports streams, boundary check the URB's stream ID.
428 * If the endpoint doesn't support streams, return the singular endpoint ring.
429 */
430struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
431 struct urb *urb)
432{
433 return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id,
434 xhci_get_endpoint_index(&urb->ep->desc), urb->stream_id);
435}
436
437#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 394#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
438static int xhci_test_radix_tree(struct xhci_hcd *xhci, 395static int xhci_test_radix_tree(struct xhci_hcd *xhci,
439 unsigned int num_streams, 396 unsigned int num_streams,
@@ -1112,8 +1069,18 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1112 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); 1069 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
1113 1070
1114 /* Set up the endpoint ring */ 1071 /* Set up the endpoint ring */
1115 virt_dev->eps[ep_index].new_ring = 1072 /*
1116 xhci_ring_alloc(xhci, 1, true, mem_flags); 1073 * Isochronous endpoint ring needs bigger size because one isoc URB
1074 * carries multiple packets and it will insert multiple tds to the
1075 * ring.
1076 * This should be replaced with dynamic ring resizing in the future.
1077 */
1078 if (usb_endpoint_xfer_isoc(&ep->desc))
1079 virt_dev->eps[ep_index].new_ring =
1080 xhci_ring_alloc(xhci, 8, true, mem_flags);
1081 else
1082 virt_dev->eps[ep_index].new_ring =
1083 xhci_ring_alloc(xhci, 1, true, mem_flags);
1117 if (!virt_dev->eps[ep_index].new_ring) { 1084 if (!virt_dev->eps[ep_index].new_ring) {
1118 /* Attempt to use the ring cache */ 1085 /* Attempt to use the ring cache */
1119 if (virt_dev->num_rings_cached == 0) 1086 if (virt_dev->num_rings_cached == 0)
@@ -1124,6 +1091,7 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1124 virt_dev->num_rings_cached--; 1091 virt_dev->num_rings_cached--;
1125 xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring); 1092 xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring);
1126 } 1093 }
1094 virt_dev->eps[ep_index].skip = false;
1127 ep_ring = virt_dev->eps[ep_index].new_ring; 1095 ep_ring = virt_dev->eps[ep_index].new_ring;
1128 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; 1096 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state;
1129 1097
@@ -1389,6 +1357,22 @@ struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1389 return command; 1357 return command;
1390} 1358}
1391 1359
1360void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv)
1361{
1362 int last;
1363
1364 if (!urb_priv)
1365 return;
1366
1367 last = urb_priv->length - 1;
1368 if (last >= 0) {
1369 int i;
1370 for (i = 0; i <= last; i++)
1371 kfree(urb_priv->td[i]);
1372 }
1373 kfree(urb_priv);
1374}
1375
1392void xhci_free_command(struct xhci_hcd *xhci, 1376void xhci_free_command(struct xhci_hcd *xhci,
1393 struct xhci_command *command) 1377 struct xhci_command *command)
1394{ 1378{
@@ -1588,7 +1572,7 @@ static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
1588 unsigned int num_tests; 1572 unsigned int num_tests;
1589 int i, ret; 1573 int i, ret;
1590 1574
1591 num_tests = sizeof(simple_test_vector) / sizeof(simple_test_vector[0]); 1575 num_tests = ARRAY_SIZE(simple_test_vector);
1592 for (i = 0; i < num_tests; i++) { 1576 for (i = 0; i < num_tests; i++) {
1593 ret = xhci_test_trb_in_td(xhci, 1577 ret = xhci_test_trb_in_td(xhci,
1594 xhci->event_ring->first_seg, 1578 xhci->event_ring->first_seg,
@@ -1601,7 +1585,7 @@ static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
1601 return ret; 1585 return ret;
1602 } 1586 }
1603 1587
1604 num_tests = sizeof(complex_test_vector) / sizeof(complex_test_vector[0]); 1588 num_tests = ARRAY_SIZE(complex_test_vector);
1605 for (i = 0; i < num_tests; i++) { 1589 for (i = 0; i < num_tests; i++) {
1606 ret = xhci_test_trb_in_td(xhci, 1590 ret = xhci_test_trb_in_td(xhci,
1607 complex_test_vector[i].input_seg, 1591 complex_test_vector[i].input_seg,
@@ -1617,6 +1601,29 @@ static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
1617 return 0; 1601 return 0;
1618} 1602}
1619 1603
1604static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
1605{
1606 u64 temp;
1607 dma_addr_t deq;
1608
1609 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
1610 xhci->event_ring->dequeue);
1611 if (deq == 0 && !in_interrupt())
1612 xhci_warn(xhci, "WARN something wrong with SW event ring "
1613 "dequeue ptr.\n");
1614 /* Update HC event ring dequeue pointer */
1615 temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
1616 temp &= ERST_PTR_MASK;
1617 /* Don't clear the EHB bit (which is RW1C) because
1618 * there might be more events to service.
1619 */
1620 temp &= ~ERST_EHB;
1621 xhci_dbg(xhci, "// Write event ring dequeue pointer, "
1622 "preserving EHB bit\n");
1623 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
1624 &xhci->ir_set->erst_dequeue);
1625}
1626
1620 1627
1621int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) 1628int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1622{ 1629{
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 11482b6b9381..f7efe025beda 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -53,6 +53,7 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
53 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 53 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
55 int retval; 55 int retval;
56 u32 temp;
56 57
57 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; 58 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2;
58 59
@@ -93,6 +94,14 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
93 return retval; 94 return retval;
94 xhci_dbg(xhci, "Reset complete\n"); 95 xhci_dbg(xhci, "Reset complete\n");
95 96
97 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
98 if (HCC_64BIT_ADDR(temp)) {
99 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
100 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64));
101 } else {
102 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
103 }
104
96 xhci_dbg(xhci, "Calling HCD init\n"); 105 xhci_dbg(xhci, "Calling HCD init\n");
97 /* Initialize HCD and host controller data structures. */ 106 /* Initialize HCD and host controller data structures. */
98 retval = xhci_init(hcd); 107 retval = xhci_init(hcd);
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index bfc99a939455..bc3f4f427065 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -301,28 +301,6 @@ static int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring,
301 return 1; 301 return 1;
302} 302}
303 303
304void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
305{
306 u64 temp;
307 dma_addr_t deq;
308
309 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
310 xhci->event_ring->dequeue);
311 if (deq == 0 && !in_interrupt())
312 xhci_warn(xhci, "WARN something wrong with SW event ring "
313 "dequeue ptr.\n");
314 /* Update HC event ring dequeue pointer */
315 temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
316 temp &= ERST_PTR_MASK;
317 /* Don't clear the EHB bit (which is RW1C) because
318 * there might be more events to service.
319 */
320 temp &= ~ERST_EHB;
321 xhci_dbg(xhci, "// Write event ring dequeue pointer, preserving EHB bit\n");
322 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
323 &xhci->ir_set->erst_dequeue);
324}
325
326/* Ring the host controller doorbell after placing a command on the ring */ 304/* Ring the host controller doorbell after placing a command on the ring */
327void xhci_ring_cmd_db(struct xhci_hcd *xhci) 305void xhci_ring_cmd_db(struct xhci_hcd *xhci)
328{ 306{
@@ -359,11 +337,6 @@ static void ring_ep_doorbell(struct xhci_hcd *xhci,
359 field = xhci_readl(xhci, db_addr) & DB_MASK; 337 field = xhci_readl(xhci, db_addr) & DB_MASK;
360 field |= EPI_TO_DB(ep_index) | STREAM_ID_TO_DB(stream_id); 338 field |= EPI_TO_DB(ep_index) | STREAM_ID_TO_DB(stream_id);
361 xhci_writel(xhci, field, db_addr); 339 xhci_writel(xhci, field, db_addr);
362 /* Flush PCI posted writes - FIXME Matthew Wilcox says this
363 * isn't time-critical and we shouldn't make the CPU wait for
364 * the flush.
365 */
366 xhci_readl(xhci, db_addr);
367 } 340 }
368} 341}
369 342
@@ -419,6 +392,50 @@ static struct xhci_segment *find_trb_seg(
419 return cur_seg; 392 return cur_seg;
420} 393}
421 394
395
396static struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
397 unsigned int slot_id, unsigned int ep_index,
398 unsigned int stream_id)
399{
400 struct xhci_virt_ep *ep;
401
402 ep = &xhci->devs[slot_id]->eps[ep_index];
403 /* Common case: no streams */
404 if (!(ep->ep_state & EP_HAS_STREAMS))
405 return ep->ring;
406
407 if (stream_id == 0) {
408 xhci_warn(xhci,
409 "WARN: Slot ID %u, ep index %u has streams, "
410 "but URB has no stream ID.\n",
411 slot_id, ep_index);
412 return NULL;
413 }
414
415 if (stream_id < ep->stream_info->num_streams)
416 return ep->stream_info->stream_rings[stream_id];
417
418 xhci_warn(xhci,
419 "WARN: Slot ID %u, ep index %u has "
420 "stream IDs 1 to %u allocated, "
421 "but stream ID %u is requested.\n",
422 slot_id, ep_index,
423 ep->stream_info->num_streams - 1,
424 stream_id);
425 return NULL;
426}
427
428/* Get the right ring for the given URB.
429 * If the endpoint supports streams, boundary check the URB's stream ID.
430 * If the endpoint doesn't support streams, return the singular endpoint ring.
431 */
432static struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
433 struct urb *urb)
434{
435 return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id,
436 xhci_get_endpoint_index(&urb->ep->desc), urb->stream_id);
437}
438
422/* 439/*
423 * Move the xHC's endpoint ring dequeue pointer past cur_td. 440 * Move the xHC's endpoint ring dequeue pointer past cur_td.
424 * Record the new state of the xHC's endpoint ring dequeue segment, 441 * Record the new state of the xHC's endpoint ring dequeue segment,
@@ -578,16 +595,24 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
578 struct xhci_td *cur_td, int status, char *adjective) 595 struct xhci_td *cur_td, int status, char *adjective)
579{ 596{
580 struct usb_hcd *hcd = xhci_to_hcd(xhci); 597 struct usb_hcd *hcd = xhci_to_hcd(xhci);
598 struct urb *urb;
599 struct urb_priv *urb_priv;
581 600
582 cur_td->urb->hcpriv = NULL; 601 urb = cur_td->urb;
583 usb_hcd_unlink_urb_from_ep(hcd, cur_td->urb); 602 urb_priv = urb->hcpriv;
584 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, cur_td->urb); 603 urb_priv->td_cnt++;
585 604
586 spin_unlock(&xhci->lock); 605 /* Only giveback urb when this is the last td in urb */
587 usb_hcd_giveback_urb(hcd, cur_td->urb, status); 606 if (urb_priv->td_cnt == urb_priv->length) {
588 kfree(cur_td); 607 usb_hcd_unlink_urb_from_ep(hcd, urb);
589 spin_lock(&xhci->lock); 608 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, urb);
590 xhci_dbg(xhci, "%s URB given back\n", adjective); 609
610 spin_unlock(&xhci->lock);
611 usb_hcd_giveback_urb(hcd, urb, status);
612 xhci_urb_free_priv(xhci, urb_priv);
613 spin_lock(&xhci->lock);
614 xhci_dbg(xhci, "%s URB given back\n", adjective);
615 }
591} 616}
592 617
593/* 618/*
@@ -1132,7 +1157,6 @@ static void handle_port_status(struct xhci_hcd *xhci,
1132 1157
1133 /* Update event ring dequeue pointer before dropping the lock */ 1158 /* Update event ring dequeue pointer before dropping the lock */
1134 inc_deq(xhci, xhci->event_ring, true); 1159 inc_deq(xhci, xhci->event_ring, true);
1135 xhci_set_hc_event_deq(xhci);
1136 1160
1137 spin_unlock(&xhci->lock); 1161 spin_unlock(&xhci->lock);
1138 /* Pass this up to the core */ 1162 /* Pass this up to the core */
@@ -1258,6 +1282,421 @@ int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code)
1258} 1282}
1259 1283
1260/* 1284/*
1285 * Finish the td processing, remove the td from td list;
1286 * Return 1 if the urb can be given back.
1287 */
1288static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td,
1289 union xhci_trb *event_trb, struct xhci_transfer_event *event,
1290 struct xhci_virt_ep *ep, int *status, bool skip)
1291{
1292 struct xhci_virt_device *xdev;
1293 struct xhci_ring *ep_ring;
1294 unsigned int slot_id;
1295 int ep_index;
1296 struct urb *urb = NULL;
1297 struct xhci_ep_ctx *ep_ctx;
1298 int ret = 0;
1299 struct urb_priv *urb_priv;
1300 u32 trb_comp_code;
1301
1302 slot_id = TRB_TO_SLOT_ID(event->flags);
1303 xdev = xhci->devs[slot_id];
1304 ep_index = TRB_TO_EP_ID(event->flags) - 1;
1305 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1306 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1307 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1308
1309 if (skip)
1310 goto td_cleanup;
1311
1312 if (trb_comp_code == COMP_STOP_INVAL ||
1313 trb_comp_code == COMP_STOP) {
1314 /* The Endpoint Stop Command completion will take care of any
1315 * stopped TDs. A stopped TD may be restarted, so don't update
1316 * the ring dequeue pointer or take this TD off any lists yet.
1317 */
1318 ep->stopped_td = td;
1319 ep->stopped_trb = event_trb;
1320 return 0;
1321 } else {
1322 if (trb_comp_code == COMP_STALL) {
1323 /* The transfer is completed from the driver's
1324 * perspective, but we need to issue a set dequeue
1325 * command for this stalled endpoint to move the dequeue
1326 * pointer past the TD. We can't do that here because
1327 * the halt condition must be cleared first. Let the
1328 * USB class driver clear the stall later.
1329 */
1330 ep->stopped_td = td;
1331 ep->stopped_trb = event_trb;
1332 ep->stopped_stream = ep_ring->stream_id;
1333 } else if (xhci_requires_manual_halt_cleanup(xhci,
1334 ep_ctx, trb_comp_code)) {
1335 /* Other types of errors halt the endpoint, but the
1336 * class driver doesn't call usb_reset_endpoint() unless
1337 * the error is -EPIPE. Clear the halted status in the
1338 * xHCI hardware manually.
1339 */
1340 xhci_cleanup_halted_endpoint(xhci,
1341 slot_id, ep_index, ep_ring->stream_id,
1342 td, event_trb);
1343 } else {
1344 /* Update ring dequeue pointer */
1345 while (ep_ring->dequeue != td->last_trb)
1346 inc_deq(xhci, ep_ring, false);
1347 inc_deq(xhci, ep_ring, false);
1348 }
1349
1350td_cleanup:
1351 /* Clean up the endpoint's TD list */
1352 urb = td->urb;
1353 urb_priv = urb->hcpriv;
1354
1355 /* Do one last check of the actual transfer length.
1356 * If the host controller said we transferred more data than
1357 * the buffer length, urb->actual_length will be a very big
1358 * number (since it's unsigned). Play it safe and say we didn't
1359 * transfer anything.
1360 */
1361 if (urb->actual_length > urb->transfer_buffer_length) {
1362 xhci_warn(xhci, "URB transfer length is wrong, "
1363 "xHC issue? req. len = %u, "
1364 "act. len = %u\n",
1365 urb->transfer_buffer_length,
1366 urb->actual_length);
1367 urb->actual_length = 0;
1368 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1369 *status = -EREMOTEIO;
1370 else
1371 *status = 0;
1372 }
1373 list_del(&td->td_list);
1374 /* Was this TD slated to be cancelled but completed anyway? */
1375 if (!list_empty(&td->cancelled_td_list))
1376 list_del(&td->cancelled_td_list);
1377
1378 urb_priv->td_cnt++;
1379 /* Giveback the urb when all the tds are completed */
1380 if (urb_priv->td_cnt == urb_priv->length)
1381 ret = 1;
1382 }
1383
1384 return ret;
1385}
1386
1387/*
1388 * Process control tds, update urb status and actual_length.
1389 */
1390static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1391 union xhci_trb *event_trb, struct xhci_transfer_event *event,
1392 struct xhci_virt_ep *ep, int *status)
1393{
1394 struct xhci_virt_device *xdev;
1395 struct xhci_ring *ep_ring;
1396 unsigned int slot_id;
1397 int ep_index;
1398 struct xhci_ep_ctx *ep_ctx;
1399 u32 trb_comp_code;
1400
1401 slot_id = TRB_TO_SLOT_ID(event->flags);
1402 xdev = xhci->devs[slot_id];
1403 ep_index = TRB_TO_EP_ID(event->flags) - 1;
1404 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1405 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1406 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1407
1408 xhci_debug_trb(xhci, xhci->event_ring->dequeue);
1409 switch (trb_comp_code) {
1410 case COMP_SUCCESS:
1411 if (event_trb == ep_ring->dequeue) {
1412 xhci_warn(xhci, "WARN: Success on ctrl setup TRB "
1413 "without IOC set??\n");
1414 *status = -ESHUTDOWN;
1415 } else if (event_trb != td->last_trb) {
1416 xhci_warn(xhci, "WARN: Success on ctrl data TRB "
1417 "without IOC set??\n");
1418 *status = -ESHUTDOWN;
1419 } else {
1420 xhci_dbg(xhci, "Successful control transfer!\n");
1421 *status = 0;
1422 }
1423 break;
1424 case COMP_SHORT_TX:
1425 xhci_warn(xhci, "WARN: short transfer on control ep\n");
1426 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1427 *status = -EREMOTEIO;
1428 else
1429 *status = 0;
1430 break;
1431 default:
1432 if (!xhci_requires_manual_halt_cleanup(xhci,
1433 ep_ctx, trb_comp_code))
1434 break;
1435 xhci_dbg(xhci, "TRB error code %u, "
1436 "halted endpoint index = %u\n",
1437 trb_comp_code, ep_index);
1438 /* else fall through */
1439 case COMP_STALL:
1440 /* Did we transfer part of the data (middle) phase? */
1441 if (event_trb != ep_ring->dequeue &&
1442 event_trb != td->last_trb)
1443 td->urb->actual_length =
1444 td->urb->transfer_buffer_length
1445 - TRB_LEN(event->transfer_len);
1446 else
1447 td->urb->actual_length = 0;
1448
1449 xhci_cleanup_halted_endpoint(xhci,
1450 slot_id, ep_index, 0, td, event_trb);
1451 return finish_td(xhci, td, event_trb, event, ep, status, true);
1452 }
1453 /*
1454 * Did we transfer any data, despite the errors that might have
1455 * happened? I.e. did we get past the setup stage?
1456 */
1457 if (event_trb != ep_ring->dequeue) {
1458 /* The event was for the status stage */
1459 if (event_trb == td->last_trb) {
1460 if (td->urb->actual_length != 0) {
1461 /* Don't overwrite a previously set error code
1462 */
1463 if ((*status == -EINPROGRESS || *status == 0) &&
1464 (td->urb->transfer_flags
1465 & URB_SHORT_NOT_OK))
1466 /* Did we already see a short data
1467 * stage? */
1468 *status = -EREMOTEIO;
1469 } else {
1470 td->urb->actual_length =
1471 td->urb->transfer_buffer_length;
1472 }
1473 } else {
1474 /* Maybe the event was for the data stage? */
1475 if (trb_comp_code != COMP_STOP_INVAL) {
1476 /* We didn't stop on a link TRB in the middle */
1477 td->urb->actual_length =
1478 td->urb->transfer_buffer_length -
1479 TRB_LEN(event->transfer_len);
1480 xhci_dbg(xhci, "Waiting for status "
1481 "stage event\n");
1482 return 0;
1483 }
1484 }
1485 }
1486
1487 return finish_td(xhci, td, event_trb, event, ep, status, false);
1488}
1489
1490/*
1491 * Process isochronous tds, update urb packet status and actual_length.
1492 */
1493static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1494 union xhci_trb *event_trb, struct xhci_transfer_event *event,
1495 struct xhci_virt_ep *ep, int *status)
1496{
1497 struct xhci_ring *ep_ring;
1498 struct urb_priv *urb_priv;
1499 int idx;
1500 int len = 0;
1501 int skip_td = 0;
1502 union xhci_trb *cur_trb;
1503 struct xhci_segment *cur_seg;
1504 u32 trb_comp_code;
1505
1506 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1507 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1508 urb_priv = td->urb->hcpriv;
1509 idx = urb_priv->td_cnt;
1510
1511 if (ep->skip) {
1512 /* The transfer is partly done */
1513 *status = -EXDEV;
1514 td->urb->iso_frame_desc[idx].status = -EXDEV;
1515 } else {
1516 /* handle completion code */
1517 switch (trb_comp_code) {
1518 case COMP_SUCCESS:
1519 td->urb->iso_frame_desc[idx].status = 0;
1520 xhci_dbg(xhci, "Successful isoc transfer!\n");
1521 break;
1522 case COMP_SHORT_TX:
1523 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1524 td->urb->iso_frame_desc[idx].status =
1525 -EREMOTEIO;
1526 else
1527 td->urb->iso_frame_desc[idx].status = 0;
1528 break;
1529 case COMP_BW_OVER:
1530 td->urb->iso_frame_desc[idx].status = -ECOMM;
1531 skip_td = 1;
1532 break;
1533 case COMP_BUFF_OVER:
1534 case COMP_BABBLE:
1535 td->urb->iso_frame_desc[idx].status = -EOVERFLOW;
1536 skip_td = 1;
1537 break;
1538 case COMP_STALL:
1539 td->urb->iso_frame_desc[idx].status = -EPROTO;
1540 skip_td = 1;
1541 break;
1542 case COMP_STOP:
1543 case COMP_STOP_INVAL:
1544 break;
1545 default:
1546 td->urb->iso_frame_desc[idx].status = -1;
1547 break;
1548 }
1549 }
1550
1551 /* calc actual length */
1552 if (ep->skip) {
1553 td->urb->iso_frame_desc[idx].actual_length = 0;
1554 return finish_td(xhci, td, event_trb, event, ep, status, true);
1555 }
1556
1557 if (trb_comp_code == COMP_SUCCESS || skip_td == 1) {
1558 td->urb->iso_frame_desc[idx].actual_length =
1559 td->urb->iso_frame_desc[idx].length;
1560 td->urb->actual_length +=
1561 td->urb->iso_frame_desc[idx].length;
1562 } else {
1563 for (cur_trb = ep_ring->dequeue,
1564 cur_seg = ep_ring->deq_seg; cur_trb != event_trb;
1565 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1566 if ((cur_trb->generic.field[3] &
1567 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1568 (cur_trb->generic.field[3] &
1569 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1570 len +=
1571 TRB_LEN(cur_trb->generic.field[2]);
1572 }
1573 len += TRB_LEN(cur_trb->generic.field[2]) -
1574 TRB_LEN(event->transfer_len);
1575
1576 if (trb_comp_code != COMP_STOP_INVAL) {
1577 td->urb->iso_frame_desc[idx].actual_length = len;
1578 td->urb->actual_length += len;
1579 }
1580 }
1581
1582 if ((idx == urb_priv->length - 1) && *status == -EINPROGRESS)
1583 *status = 0;
1584
1585 return finish_td(xhci, td, event_trb, event, ep, status, false);
1586}
1587
1588/*
1589 * Process bulk and interrupt tds, update urb status and actual_length.
1590 */
1591static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1592 union xhci_trb *event_trb, struct xhci_transfer_event *event,
1593 struct xhci_virt_ep *ep, int *status)
1594{
1595 struct xhci_ring *ep_ring;
1596 union xhci_trb *cur_trb;
1597 struct xhci_segment *cur_seg;
1598 u32 trb_comp_code;
1599
1600 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1601 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1602
1603 switch (trb_comp_code) {
1604 case COMP_SUCCESS:
1605 /* Double check that the HW transferred everything. */
1606 if (event_trb != td->last_trb) {
1607 xhci_warn(xhci, "WARN Successful completion "
1608 "on short TX\n");
1609 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1610 *status = -EREMOTEIO;
1611 else
1612 *status = 0;
1613 } else {
1614 if (usb_endpoint_xfer_bulk(&td->urb->ep->desc))
1615 xhci_dbg(xhci, "Successful bulk "
1616 "transfer!\n");
1617 else
1618 xhci_dbg(xhci, "Successful interrupt "
1619 "transfer!\n");
1620 *status = 0;
1621 }
1622 break;
1623 case COMP_SHORT_TX:
1624 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1625 *status = -EREMOTEIO;
1626 else
1627 *status = 0;
1628 break;
1629 default:
1630 /* Others already handled above */
1631 break;
1632 }
1633 dev_dbg(&td->urb->dev->dev,
1634 "ep %#x - asked for %d bytes, "
1635 "%d bytes untransferred\n",
1636 td->urb->ep->desc.bEndpointAddress,
1637 td->urb->transfer_buffer_length,
1638 TRB_LEN(event->transfer_len));
1639 /* Fast path - was this the last TRB in the TD for this URB? */
1640 if (event_trb == td->last_trb) {
1641 if (TRB_LEN(event->transfer_len) != 0) {
1642 td->urb->actual_length =
1643 td->urb->transfer_buffer_length -
1644 TRB_LEN(event->transfer_len);
1645 if (td->urb->transfer_buffer_length <
1646 td->urb->actual_length) {
1647 xhci_warn(xhci, "HC gave bad length "
1648 "of %d bytes left\n",
1649 TRB_LEN(event->transfer_len));
1650 td->urb->actual_length = 0;
1651 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1652 *status = -EREMOTEIO;
1653 else
1654 *status = 0;
1655 }
1656 /* Don't overwrite a previously set error code */
1657 if (*status == -EINPROGRESS) {
1658 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1659 *status = -EREMOTEIO;
1660 else
1661 *status = 0;
1662 }
1663 } else {
1664 td->urb->actual_length =
1665 td->urb->transfer_buffer_length;
1666 /* Ignore a short packet completion if the
1667 * untransferred length was zero.
1668 */
1669 if (*status == -EREMOTEIO)
1670 *status = 0;
1671 }
1672 } else {
1673 /* Slow path - walk the list, starting from the dequeue
1674 * pointer, to get the actual length transferred.
1675 */
1676 td->urb->actual_length = 0;
1677 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg;
1678 cur_trb != event_trb;
1679 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1680 if ((cur_trb->generic.field[3] &
1681 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1682 (cur_trb->generic.field[3] &
1683 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1684 td->urb->actual_length +=
1685 TRB_LEN(cur_trb->generic.field[2]);
1686 }
1687 /* If the ring didn't stop on a Link or No-op TRB, add
1688 * in the actual bytes transferred from the Normal TRB
1689 */
1690 if (trb_comp_code != COMP_STOP_INVAL)
1691 td->urb->actual_length +=
1692 TRB_LEN(cur_trb->generic.field[2]) -
1693 TRB_LEN(event->transfer_len);
1694 }
1695
1696 return finish_td(xhci, td, event_trb, event, ep, status, false);
1697}
1698
1699/*
1261 * If this function returns an error condition, it means it got a Transfer 1700 * If this function returns an error condition, it means it got a Transfer
1262 * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address. 1701 * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address.
1263 * At this point, the host controller is probably hosed and should be reset. 1702 * At this point, the host controller is probably hosed and should be reset.
@@ -1276,10 +1715,11 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1276 union xhci_trb *event_trb; 1715 union xhci_trb *event_trb;
1277 struct urb *urb = NULL; 1716 struct urb *urb = NULL;
1278 int status = -EINPROGRESS; 1717 int status = -EINPROGRESS;
1718 struct urb_priv *urb_priv;
1279 struct xhci_ep_ctx *ep_ctx; 1719 struct xhci_ep_ctx *ep_ctx;
1280 u32 trb_comp_code; 1720 u32 trb_comp_code;
1721 int ret = 0;
1281 1722
1282 xhci_dbg(xhci, "In %s\n", __func__);
1283 slot_id = TRB_TO_SLOT_ID(event->flags); 1723 slot_id = TRB_TO_SLOT_ID(event->flags);
1284 xdev = xhci->devs[slot_id]; 1724 xdev = xhci->devs[slot_id];
1285 if (!xdev) { 1725 if (!xdev) {
@@ -1293,51 +1733,16 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1293 ep = &xdev->eps[ep_index]; 1733 ep = &xdev->eps[ep_index];
1294 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1734 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1295 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1735 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1296 if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { 1736 if (!ep_ring ||
1737 (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) {
1297 xhci_err(xhci, "ERROR Transfer event for disabled endpoint " 1738 xhci_err(xhci, "ERROR Transfer event for disabled endpoint "
1298 "or incorrect stream ring\n"); 1739 "or incorrect stream ring\n");
1299 return -ENODEV; 1740 return -ENODEV;
1300 } 1741 }
1301 1742
1302 event_dma = event->buffer; 1743 event_dma = event->buffer;
1303 /* This TRB should be in the TD at the head of this ring's TD list */
1304 xhci_dbg(xhci, "%s - checking for list empty\n", __func__);
1305 if (list_empty(&ep_ring->td_list)) {
1306 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d with no TDs queued?\n",
1307 TRB_TO_SLOT_ID(event->flags), ep_index);
1308 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
1309 (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10);
1310 xhci_print_trb_offsets(xhci, (union xhci_trb *) event);
1311 urb = NULL;
1312 goto cleanup;
1313 }
1314 xhci_dbg(xhci, "%s - getting list entry\n", __func__);
1315 td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list);
1316
1317 /* Is this a TRB in the currently executing TD? */
1318 xhci_dbg(xhci, "%s - looking for TD\n", __func__);
1319 event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue,
1320 td->last_trb, event_dma);
1321 xhci_dbg(xhci, "%s - found event_seg = %p\n", __func__, event_seg);
1322 if (!event_seg) {
1323 /* HC is busted, give up! */
1324 xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not part of current TD\n");
1325 return -ESHUTDOWN;
1326 }
1327 event_trb = &event_seg->trbs[(event_dma - event_seg->dma) / sizeof(*event_trb)];
1328 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
1329 (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10);
1330 xhci_dbg(xhci, "Offset 0x00 (buffer lo) = 0x%x\n",
1331 lower_32_bits(event->buffer));
1332 xhci_dbg(xhci, "Offset 0x04 (buffer hi) = 0x%x\n",
1333 upper_32_bits(event->buffer));
1334 xhci_dbg(xhci, "Offset 0x08 (transfer length) = 0x%x\n",
1335 (unsigned int) event->transfer_len);
1336 xhci_dbg(xhci, "Offset 0x0C (flags) = 0x%x\n",
1337 (unsigned int) event->flags);
1338
1339 /* Look for common error cases */
1340 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1744 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1745 /* Look for common error cases */
1341 switch (trb_comp_code) { 1746 switch (trb_comp_code) {
1342 /* Skip codes that require special handling depending on 1747 /* Skip codes that require special handling depending on
1343 * transfer type 1748 * transfer type
@@ -1373,278 +1778,156 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1373 xhci_warn(xhci, "WARN: HC couldn't access mem fast enough\n"); 1778 xhci_warn(xhci, "WARN: HC couldn't access mem fast enough\n");
1374 status = -ENOSR; 1779 status = -ENOSR;
1375 break; 1780 break;
1781 case COMP_BW_OVER:
1782 xhci_warn(xhci, "WARN: bandwidth overrun event on endpoint\n");
1783 break;
1784 case COMP_BUFF_OVER:
1785 xhci_warn(xhci, "WARN: buffer overrun event on endpoint\n");
1786 break;
1787 case COMP_UNDERRUN:
1788 /*
1789 * When the Isoch ring is empty, the xHC will generate
1790 * a Ring Overrun Event for IN Isoch endpoint or Ring
1791 * Underrun Event for OUT Isoch endpoint.
1792 */
1793 xhci_dbg(xhci, "underrun event on endpoint\n");
1794 if (!list_empty(&ep_ring->td_list))
1795 xhci_dbg(xhci, "Underrun Event for slot %d ep %d "
1796 "still with TDs queued?\n",
1797 TRB_TO_SLOT_ID(event->flags), ep_index);
1798 goto cleanup;
1799 case COMP_OVERRUN:
1800 xhci_dbg(xhci, "overrun event on endpoint\n");
1801 if (!list_empty(&ep_ring->td_list))
1802 xhci_dbg(xhci, "Overrun Event for slot %d ep %d "
1803 "still with TDs queued?\n",
1804 TRB_TO_SLOT_ID(event->flags), ep_index);
1805 goto cleanup;
1806 case COMP_MISSED_INT:
1807 /*
1808 * When encounter missed service error, one or more isoc tds
1809 * may be missed by xHC.
1810 * Set skip flag of the ep_ring; Complete the missed tds as
1811 * short transfer when process the ep_ring next time.
1812 */
1813 ep->skip = true;
1814 xhci_dbg(xhci, "Miss service interval error, set skip flag\n");
1815 goto cleanup;
1376 default: 1816 default:
1377 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) { 1817 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) {
1378 status = 0; 1818 status = 0;
1379 break; 1819 break;
1380 } 1820 }
1381 xhci_warn(xhci, "ERROR Unknown event condition, HC probably busted\n"); 1821 xhci_warn(xhci, "ERROR Unknown event condition, HC probably "
1382 urb = NULL; 1822 "busted\n");
1383 goto cleanup; 1823 goto cleanup;
1384 } 1824 }
1385 /* Now update the urb's actual_length and give back to the core */
1386 /* Was this a control transfer? */
1387 if (usb_endpoint_xfer_control(&td->urb->ep->desc)) {
1388 xhci_debug_trb(xhci, xhci->event_ring->dequeue);
1389 switch (trb_comp_code) {
1390 case COMP_SUCCESS:
1391 if (event_trb == ep_ring->dequeue) {
1392 xhci_warn(xhci, "WARN: Success on ctrl setup TRB without IOC set??\n");
1393 status = -ESHUTDOWN;
1394 } else if (event_trb != td->last_trb) {
1395 xhci_warn(xhci, "WARN: Success on ctrl data TRB without IOC set??\n");
1396 status = -ESHUTDOWN;
1397 } else {
1398 xhci_dbg(xhci, "Successful control transfer!\n");
1399 status = 0;
1400 }
1401 break;
1402 case COMP_SHORT_TX:
1403 xhci_warn(xhci, "WARN: short transfer on control ep\n");
1404 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1405 status = -EREMOTEIO;
1406 else
1407 status = 0;
1408 break;
1409 1825
1410 default: 1826 do {
1411 if (!xhci_requires_manual_halt_cleanup(xhci, 1827 /* This TRB should be in the TD at the head of this ring's
1412 ep_ctx, trb_comp_code)) 1828 * TD list.
1413 break;
1414 xhci_dbg(xhci, "TRB error code %u, "
1415 "halted endpoint index = %u\n",
1416 trb_comp_code, ep_index);
1417 /* else fall through */
1418 case COMP_STALL:
1419 /* Did we transfer part of the data (middle) phase? */
1420 if (event_trb != ep_ring->dequeue &&
1421 event_trb != td->last_trb)
1422 td->urb->actual_length =
1423 td->urb->transfer_buffer_length
1424 - TRB_LEN(event->transfer_len);
1425 else
1426 td->urb->actual_length = 0;
1427
1428 xhci_cleanup_halted_endpoint(xhci,
1429 slot_id, ep_index, 0, td, event_trb);
1430 goto td_cleanup;
1431 }
1432 /*
1433 * Did we transfer any data, despite the errors that might have
1434 * happened? I.e. did we get past the setup stage?
1435 */ 1829 */
1436 if (event_trb != ep_ring->dequeue) { 1830 if (list_empty(&ep_ring->td_list)) {
1437 /* The event was for the status stage */ 1831 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d "
1438 if (event_trb == td->last_trb) { 1832 "with no TDs queued?\n",
1439 if (td->urb->actual_length != 0) { 1833 TRB_TO_SLOT_ID(event->flags), ep_index);
1440 /* Don't overwrite a previously set error code */ 1834 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
1441 if ((status == -EINPROGRESS || 1835 (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10);
1442 status == 0) && 1836 xhci_print_trb_offsets(xhci, (union xhci_trb *) event);
1443 (td->urb->transfer_flags 1837 if (ep->skip) {
1444 & URB_SHORT_NOT_OK)) 1838 ep->skip = false;
1445 /* Did we already see a short data stage? */ 1839 xhci_dbg(xhci, "td_list is empty while skip "
1446 status = -EREMOTEIO; 1840 "flag set. Clear skip flag.\n");
1447 } else {
1448 td->urb->actual_length =
1449 td->urb->transfer_buffer_length;
1450 }
1451 } else {
1452 /* Maybe the event was for the data stage? */
1453 if (trb_comp_code != COMP_STOP_INVAL) {
1454 /* We didn't stop on a link TRB in the middle */
1455 td->urb->actual_length =
1456 td->urb->transfer_buffer_length -
1457 TRB_LEN(event->transfer_len);
1458 xhci_dbg(xhci, "Waiting for status stage event\n");
1459 urb = NULL;
1460 goto cleanup;
1461 }
1462 } 1841 }
1842 ret = 0;
1843 goto cleanup;
1463 } 1844 }
1464 } else { 1845
1465 switch (trb_comp_code) { 1846 td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list);
1466 case COMP_SUCCESS: 1847 /* Is this a TRB in the currently executing TD? */
1467 /* Double check that the HW transferred everything. */ 1848 event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue,
1468 if (event_trb != td->last_trb) { 1849 td->last_trb, event_dma);
1469 xhci_warn(xhci, "WARN Successful completion " 1850 if (event_seg && ep->skip) {
1470 "on short TX\n"); 1851 xhci_dbg(xhci, "Found td. Clear skip flag.\n");
1471 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1852 ep->skip = false;
1472 status = -EREMOTEIO; 1853 }
1473 else 1854 if (!event_seg &&
1474 status = 0; 1855 (!ep->skip || !usb_endpoint_xfer_isoc(&td->urb->ep->desc))) {
1475 } else { 1856 /* HC is busted, give up! */
1476 if (usb_endpoint_xfer_bulk(&td->urb->ep->desc)) 1857 xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not "
1477 xhci_dbg(xhci, "Successful bulk " 1858 "part of current TD\n");
1478 "transfer!\n"); 1859 return -ESHUTDOWN;
1479 else
1480 xhci_dbg(xhci, "Successful interrupt "
1481 "transfer!\n");
1482 status = 0;
1483 }
1484 break;
1485 case COMP_SHORT_TX:
1486 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1487 status = -EREMOTEIO;
1488 else
1489 status = 0;
1490 break;
1491 default:
1492 /* Others already handled above */
1493 break;
1494 } 1860 }
1495 dev_dbg(&td->urb->dev->dev,
1496 "ep %#x - asked for %d bytes, "
1497 "%d bytes untransferred\n",
1498 td->urb->ep->desc.bEndpointAddress,
1499 td->urb->transfer_buffer_length,
1500 TRB_LEN(event->transfer_len));
1501 /* Fast path - was this the last TRB in the TD for this URB? */
1502 if (event_trb == td->last_trb) {
1503 if (TRB_LEN(event->transfer_len) != 0) {
1504 td->urb->actual_length =
1505 td->urb->transfer_buffer_length -
1506 TRB_LEN(event->transfer_len);
1507 if (td->urb->transfer_buffer_length <
1508 td->urb->actual_length) {
1509 xhci_warn(xhci, "HC gave bad length "
1510 "of %d bytes left\n",
1511 TRB_LEN(event->transfer_len));
1512 td->urb->actual_length = 0;
1513 if (td->urb->transfer_flags &
1514 URB_SHORT_NOT_OK)
1515 status = -EREMOTEIO;
1516 else
1517 status = 0;
1518 }
1519 /* Don't overwrite a previously set error code */
1520 if (status == -EINPROGRESS) {
1521 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1522 status = -EREMOTEIO;
1523 else
1524 status = 0;
1525 }
1526 } else {
1527 td->urb->actual_length = td->urb->transfer_buffer_length;
1528 /* Ignore a short packet completion if the
1529 * untransferred length was zero.
1530 */
1531 if (status == -EREMOTEIO)
1532 status = 0;
1533 }
1534 } else {
1535 /* Slow path - walk the list, starting from the dequeue
1536 * pointer, to get the actual length transferred.
1537 */
1538 union xhci_trb *cur_trb;
1539 struct xhci_segment *cur_seg;
1540 1861
1541 td->urb->actual_length = 0; 1862 if (event_seg) {
1542 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg; 1863 event_trb = &event_seg->trbs[(event_dma -
1543 cur_trb != event_trb; 1864 event_seg->dma) / sizeof(*event_trb)];
1544 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1865 /*
1545 if ((cur_trb->generic.field[3] & 1866 * No-op TRB should not trigger interrupts.
1546 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1867 * If event_trb is a no-op TRB, it means the
1547 (cur_trb->generic.field[3] & 1868 * corresponding TD has been cancelled. Just ignore
1548 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK)) 1869 * the TD.
1549 td->urb->actual_length +=
1550 TRB_LEN(cur_trb->generic.field[2]);
1551 }
1552 /* If the ring didn't stop on a Link or No-op TRB, add
1553 * in the actual bytes transferred from the Normal TRB
1554 */ 1870 */
1555 if (trb_comp_code != COMP_STOP_INVAL) 1871 if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK)
1556 td->urb->actual_length += 1872 == TRB_TYPE(TRB_TR_NOOP)) {
1557 TRB_LEN(cur_trb->generic.field[2]) - 1873 xhci_dbg(xhci, "event_trb is a no-op TRB. "
1558 TRB_LEN(event->transfer_len); 1874 "Skip it\n");
1875 goto cleanup;
1876 }
1559 } 1877 }
1560 } 1878
1561 if (trb_comp_code == COMP_STOP_INVAL || 1879 /* Now update the urb's actual_length and give back to
1562 trb_comp_code == COMP_STOP) { 1880 * the core
1563 /* The Endpoint Stop Command completion will take care of any
1564 * stopped TDs. A stopped TD may be restarted, so don't update
1565 * the ring dequeue pointer or take this TD off any lists yet.
1566 */ 1881 */
1567 ep->stopped_td = td; 1882 if (usb_endpoint_xfer_control(&td->urb->ep->desc))
1568 ep->stopped_trb = event_trb; 1883 ret = process_ctrl_td(xhci, td, event_trb, event, ep,
1569 } else { 1884 &status);
1570 if (trb_comp_code == COMP_STALL) { 1885 else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc))
1571 /* The transfer is completed from the driver's 1886 ret = process_isoc_td(xhci, td, event_trb, event, ep,
1572 * perspective, but we need to issue a set dequeue 1887 &status);
1573 * command for this stalled endpoint to move the dequeue 1888 else
1574 * pointer past the TD. We can't do that here because 1889 ret = process_bulk_intr_td(xhci, td, event_trb, event,
1575 * the halt condition must be cleared first. Let the 1890 ep, &status);
1576 * USB class driver clear the stall later.
1577 */
1578 ep->stopped_td = td;
1579 ep->stopped_trb = event_trb;
1580 ep->stopped_stream = ep_ring->stream_id;
1581 } else if (xhci_requires_manual_halt_cleanup(xhci,
1582 ep_ctx, trb_comp_code)) {
1583 /* Other types of errors halt the endpoint, but the
1584 * class driver doesn't call usb_reset_endpoint() unless
1585 * the error is -EPIPE. Clear the halted status in the
1586 * xHCI hardware manually.
1587 */
1588 xhci_cleanup_halted_endpoint(xhci,
1589 slot_id, ep_index, ep_ring->stream_id, td, event_trb);
1590 } else {
1591 /* Update ring dequeue pointer */
1592 while (ep_ring->dequeue != td->last_trb)
1593 inc_deq(xhci, ep_ring, false);
1594 inc_deq(xhci, ep_ring, false);
1595 }
1596 1891
1597td_cleanup: 1892cleanup:
1598 /* Clean up the endpoint's TD list */ 1893 /*
1599 urb = td->urb; 1894 * Do not update event ring dequeue pointer if ep->skip is set.
1600 /* Do one last check of the actual transfer length. 1895 * Will roll back to continue process missed tds.
1601 * If the host controller said we transferred more data than
1602 * the buffer length, urb->actual_length will be a very big
1603 * number (since it's unsigned). Play it safe and say we didn't
1604 * transfer anything.
1605 */ 1896 */
1606 if (urb->actual_length > urb->transfer_buffer_length) { 1897 if (trb_comp_code == COMP_MISSED_INT || !ep->skip) {
1607 xhci_warn(xhci, "URB transfer length is wrong, " 1898 inc_deq(xhci, xhci->event_ring, true);
1608 "xHC issue? req. len = %u, "
1609 "act. len = %u\n",
1610 urb->transfer_buffer_length,
1611 urb->actual_length);
1612 urb->actual_length = 0;
1613 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1614 status = -EREMOTEIO;
1615 else
1616 status = 0;
1617 } 1899 }
1618 list_del(&td->td_list);
1619 /* Was this TD slated to be cancelled but completed anyway? */
1620 if (!list_empty(&td->cancelled_td_list))
1621 list_del(&td->cancelled_td_list);
1622 1900
1623 /* Leave the TD around for the reset endpoint function to use 1901 if (ret) {
1624 * (but only if it's not a control endpoint, since we already 1902 urb = td->urb;
1625 * queued the Set TR dequeue pointer command for stalled 1903 urb_priv = urb->hcpriv;
1626 * control endpoints). 1904 /* Leave the TD around for the reset endpoint function
1627 */ 1905 * to use(but only if it's not a control endpoint,
1628 if (usb_endpoint_xfer_control(&urb->ep->desc) || 1906 * since we already queued the Set TR dequeue pointer
1629 (trb_comp_code != COMP_STALL && 1907 * command for stalled control endpoints).
1630 trb_comp_code != COMP_BABBLE)) { 1908 */
1631 kfree(td); 1909 if (usb_endpoint_xfer_control(&urb->ep->desc) ||
1910 (trb_comp_code != COMP_STALL &&
1911 trb_comp_code != COMP_BABBLE))
1912 xhci_urb_free_priv(xhci, urb_priv);
1913
1914 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb);
1915 xhci_dbg(xhci, "Giveback URB %p, len = %d, "
1916 "status = %d\n",
1917 urb, urb->actual_length, status);
1918 spin_unlock(&xhci->lock);
1919 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status);
1920 spin_lock(&xhci->lock);
1632 } 1921 }
1633 urb->hcpriv = NULL;
1634 }
1635cleanup:
1636 inc_deq(xhci, xhci->event_ring, true);
1637 xhci_set_hc_event_deq(xhci);
1638 1922
1639 /* FIXME for multi-TD URBs (who have buffers bigger than 64MB) */ 1923 /*
1640 if (urb) { 1924 * If ep->skip is set, it means there are missed tds on the
1641 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); 1925 * endpoint ring need to take care of.
1642 xhci_dbg(xhci, "Giveback URB %p, len = %d, status = %d\n", 1926 * Process them as short transfer until reach the td pointed by
1643 urb, urb->actual_length, status); 1927 * the event.
1644 spin_unlock(&xhci->lock); 1928 */
1645 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); 1929 } while (ep->skip && trb_comp_code != COMP_MISSED_INT);
1646 spin_lock(&xhci->lock); 1930
1647 }
1648 return 0; 1931 return 0;
1649} 1932}
1650 1933
@@ -1652,7 +1935,7 @@ cleanup:
1652 * This function handles all OS-owned events on the event ring. It may drop 1935 * This function handles all OS-owned events on the event ring. It may drop
1653 * xhci->lock between event processing (e.g. to pass up port status changes). 1936 * xhci->lock between event processing (e.g. to pass up port status changes).
1654 */ 1937 */
1655void xhci_handle_event(struct xhci_hcd *xhci) 1938static void xhci_handle_event(struct xhci_hcd *xhci)
1656{ 1939{
1657 union xhci_trb *event; 1940 union xhci_trb *event;
1658 int update_ptrs = 1; 1941 int update_ptrs = 1;
@@ -1710,15 +1993,130 @@ void xhci_handle_event(struct xhci_hcd *xhci)
1710 return; 1993 return;
1711 } 1994 }
1712 1995
1713 if (update_ptrs) { 1996 if (update_ptrs)
1714 /* Update SW and HC event ring dequeue pointer */ 1997 /* Update SW event ring dequeue pointer */
1715 inc_deq(xhci, xhci->event_ring, true); 1998 inc_deq(xhci, xhci->event_ring, true);
1716 xhci_set_hc_event_deq(xhci); 1999
1717 }
1718 /* Are there more items on the event ring? */ 2000 /* Are there more items on the event ring? */
1719 xhci_handle_event(xhci); 2001 xhci_handle_event(xhci);
1720} 2002}
1721 2003
2004/*
2005 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
2006 * we might get bad data out of the event ring. Section 4.10.2.7 has a list of
2007 * indicators of an event TRB error, but we check the status *first* to be safe.
2008 */
2009irqreturn_t xhci_irq(struct usb_hcd *hcd)
2010{
2011 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
2012 u32 status;
2013 union xhci_trb *trb;
2014 u64 temp_64;
2015 union xhci_trb *event_ring_deq;
2016 dma_addr_t deq;
2017
2018 spin_lock(&xhci->lock);
2019 trb = xhci->event_ring->dequeue;
2020 /* Check if the xHC generated the interrupt, or the irq is shared */
2021 status = xhci_readl(xhci, &xhci->op_regs->status);
2022 if (status == 0xffffffff)
2023 goto hw_died;
2024
2025 if (!(status & STS_EINT)) {
2026 spin_unlock(&xhci->lock);
2027 xhci_warn(xhci, "Spurious interrupt.\n");
2028 return IRQ_NONE;
2029 }
2030 xhci_dbg(xhci, "op reg status = %08x\n", status);
2031 xhci_dbg(xhci, "Event ring dequeue ptr:\n");
2032 xhci_dbg(xhci, "@%llx %08x %08x %08x %08x\n",
2033 (unsigned long long)
2034 xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, trb),
2035 lower_32_bits(trb->link.segment_ptr),
2036 upper_32_bits(trb->link.segment_ptr),
2037 (unsigned int) trb->link.intr_target,
2038 (unsigned int) trb->link.control);
2039
2040 if (status & STS_FATAL) {
2041 xhci_warn(xhci, "WARNING: Host System Error\n");
2042 xhci_halt(xhci);
2043hw_died:
2044 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
2045 spin_unlock(&xhci->lock);
2046 return -ESHUTDOWN;
2047 }
2048
2049 /*
2050 * Clear the op reg interrupt status first,
2051 * so we can receive interrupts from other MSI-X interrupters.
2052 * Write 1 to clear the interrupt status.
2053 */
2054 status |= STS_EINT;
2055 xhci_writel(xhci, status, &xhci->op_regs->status);
2056 /* FIXME when MSI-X is supported and there are multiple vectors */
2057 /* Clear the MSI-X event interrupt status */
2058
2059 if (hcd->irq != -1) {
2060 u32 irq_pending;
2061 /* Acknowledge the PCI interrupt */
2062 irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending);
2063 irq_pending |= 0x3;
2064 xhci_writel(xhci, irq_pending, &xhci->ir_set->irq_pending);
2065 }
2066
2067 if (xhci->xhc_state & XHCI_STATE_DYING) {
2068 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. "
2069 "Shouldn't IRQs be disabled?\n");
2070 /* Clear the event handler busy flag (RW1C);
2071 * the event ring should be empty.
2072 */
2073 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2074 xhci_write_64(xhci, temp_64 | ERST_EHB,
2075 &xhci->ir_set->erst_dequeue);
2076 spin_unlock(&xhci->lock);
2077
2078 return IRQ_HANDLED;
2079 }
2080
2081 event_ring_deq = xhci->event_ring->dequeue;
2082 /* FIXME this should be a delayed service routine
2083 * that clears the EHB.
2084 */
2085 xhci_handle_event(xhci);
2086
2087 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2088 /* If necessary, update the HW's version of the event ring deq ptr. */
2089 if (event_ring_deq != xhci->event_ring->dequeue) {
2090 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
2091 xhci->event_ring->dequeue);
2092 if (deq == 0)
2093 xhci_warn(xhci, "WARN something wrong with SW event "
2094 "ring dequeue ptr.\n");
2095 /* Update HC event ring dequeue pointer */
2096 temp_64 &= ERST_PTR_MASK;
2097 temp_64 |= ((u64) deq & (u64) ~ERST_PTR_MASK);
2098 }
2099
2100 /* Clear the event handler busy flag (RW1C); event ring is empty. */
2101 temp_64 |= ERST_EHB;
2102 xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue);
2103
2104 spin_unlock(&xhci->lock);
2105
2106 return IRQ_HANDLED;
2107}
2108
2109irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd)
2110{
2111 irqreturn_t ret;
2112
2113 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
2114
2115 ret = xhci_irq(hcd);
2116
2117 return ret;
2118}
2119
1722/**** Endpoint Ring Operations ****/ 2120/**** Endpoint Ring Operations ****/
1723 2121
1724/* 2122/*
@@ -1827,10 +2225,12 @@ static int prepare_transfer(struct xhci_hcd *xhci,
1827 unsigned int stream_id, 2225 unsigned int stream_id,
1828 unsigned int num_trbs, 2226 unsigned int num_trbs,
1829 struct urb *urb, 2227 struct urb *urb,
1830 struct xhci_td **td, 2228 unsigned int td_index,
1831 gfp_t mem_flags) 2229 gfp_t mem_flags)
1832{ 2230{
1833 int ret; 2231 int ret;
2232 struct urb_priv *urb_priv;
2233 struct xhci_td *td;
1834 struct xhci_ring *ep_ring; 2234 struct xhci_ring *ep_ring;
1835 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 2235 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1836 2236
@@ -1846,24 +2246,29 @@ static int prepare_transfer(struct xhci_hcd *xhci,
1846 num_trbs, mem_flags); 2246 num_trbs, mem_flags);
1847 if (ret) 2247 if (ret)
1848 return ret; 2248 return ret;
1849 *td = kzalloc(sizeof(struct xhci_td), mem_flags);
1850 if (!*td)
1851 return -ENOMEM;
1852 INIT_LIST_HEAD(&(*td)->td_list);
1853 INIT_LIST_HEAD(&(*td)->cancelled_td_list);
1854 2249
1855 ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb); 2250 urb_priv = urb->hcpriv;
1856 if (unlikely(ret)) { 2251 td = urb_priv->td[td_index];
1857 kfree(*td); 2252
1858 return ret; 2253 INIT_LIST_HEAD(&td->td_list);
2254 INIT_LIST_HEAD(&td->cancelled_td_list);
2255
2256 if (td_index == 0) {
2257 ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb);
2258 if (unlikely(ret)) {
2259 xhci_urb_free_priv(xhci, urb_priv);
2260 urb->hcpriv = NULL;
2261 return ret;
2262 }
1859 } 2263 }
1860 2264
1861 (*td)->urb = urb; 2265 td->urb = urb;
1862 urb->hcpriv = (void *) (*td);
1863 /* Add this TD to the tail of the endpoint ring's TD list */ 2266 /* Add this TD to the tail of the endpoint ring's TD list */
1864 list_add_tail(&(*td)->td_list, &ep_ring->td_list); 2267 list_add_tail(&td->td_list, &ep_ring->td_list);
1865 (*td)->start_seg = ep_ring->enq_seg; 2268 td->start_seg = ep_ring->enq_seg;
1866 (*td)->first_trb = ep_ring->enqueue; 2269 td->first_trb = ep_ring->enqueue;
2270
2271 urb_priv->td[td_index] = td;
1867 2272
1868 return 0; 2273 return 0;
1869} 2274}
@@ -2002,6 +2407,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2002{ 2407{
2003 struct xhci_ring *ep_ring; 2408 struct xhci_ring *ep_ring;
2004 unsigned int num_trbs; 2409 unsigned int num_trbs;
2410 struct urb_priv *urb_priv;
2005 struct xhci_td *td; 2411 struct xhci_td *td;
2006 struct scatterlist *sg; 2412 struct scatterlist *sg;
2007 int num_sgs; 2413 int num_sgs;
@@ -2022,9 +2428,13 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2022 2428
2023 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], 2429 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id],
2024 ep_index, urb->stream_id, 2430 ep_index, urb->stream_id,
2025 num_trbs, urb, &td, mem_flags); 2431 num_trbs, urb, 0, mem_flags);
2026 if (trb_buff_len < 0) 2432 if (trb_buff_len < 0)
2027 return trb_buff_len; 2433 return trb_buff_len;
2434
2435 urb_priv = urb->hcpriv;
2436 td = urb_priv->td[0];
2437
2028 /* 2438 /*
2029 * Don't give the first TRB to the hardware (by toggling the cycle bit) 2439 * Don't give the first TRB to the hardware (by toggling the cycle bit)
2030 * until we've finished creating all the other TRBs. The ring's cycle 2440 * until we've finished creating all the other TRBs. The ring's cycle
@@ -2145,6 +2555,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2145 struct urb *urb, int slot_id, unsigned int ep_index) 2555 struct urb *urb, int slot_id, unsigned int ep_index)
2146{ 2556{
2147 struct xhci_ring *ep_ring; 2557 struct xhci_ring *ep_ring;
2558 struct urb_priv *urb_priv;
2148 struct xhci_td *td; 2559 struct xhci_td *td;
2149 int num_trbs; 2560 int num_trbs;
2150 struct xhci_generic_trb *start_trb; 2561 struct xhci_generic_trb *start_trb;
@@ -2190,10 +2601,13 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2190 2601
2191 ret = prepare_transfer(xhci, xhci->devs[slot_id], 2602 ret = prepare_transfer(xhci, xhci->devs[slot_id],
2192 ep_index, urb->stream_id, 2603 ep_index, urb->stream_id,
2193 num_trbs, urb, &td, mem_flags); 2604 num_trbs, urb, 0, mem_flags);
2194 if (ret < 0) 2605 if (ret < 0)
2195 return ret; 2606 return ret;
2196 2607
2608 urb_priv = urb->hcpriv;
2609 td = urb_priv->td[0];
2610
2197 /* 2611 /*
2198 * Don't give the first TRB to the hardware (by toggling the cycle bit) 2612 * Don't give the first TRB to the hardware (by toggling the cycle bit)
2199 * until we've finished creating all the other TRBs. The ring's cycle 2613 * until we've finished creating all the other TRBs. The ring's cycle
@@ -2279,6 +2693,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2279 struct xhci_generic_trb *start_trb; 2693 struct xhci_generic_trb *start_trb;
2280 int start_cycle; 2694 int start_cycle;
2281 u32 field, length_field; 2695 u32 field, length_field;
2696 struct urb_priv *urb_priv;
2282 struct xhci_td *td; 2697 struct xhci_td *td;
2283 2698
2284 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); 2699 ep_ring = xhci_urb_to_transfer_ring(xhci, urb);
@@ -2306,10 +2721,13 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2306 num_trbs++; 2721 num_trbs++;
2307 ret = prepare_transfer(xhci, xhci->devs[slot_id], 2722 ret = prepare_transfer(xhci, xhci->devs[slot_id],
2308 ep_index, urb->stream_id, 2723 ep_index, urb->stream_id,
2309 num_trbs, urb, &td, mem_flags); 2724 num_trbs, urb, 0, mem_flags);
2310 if (ret < 0) 2725 if (ret < 0)
2311 return ret; 2726 return ret;
2312 2727
2728 urb_priv = urb->hcpriv;
2729 td = urb_priv->td[0];
2730
2313 /* 2731 /*
2314 * Don't give the first TRB to the hardware (by toggling the cycle bit) 2732 * Don't give the first TRB to the hardware (by toggling the cycle bit)
2315 * until we've finished creating all the other TRBs. The ring's cycle 2733 * until we've finished creating all the other TRBs. The ring's cycle
@@ -2366,6 +2784,224 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2366 return 0; 2784 return 0;
2367} 2785}
2368 2786
2787static int count_isoc_trbs_needed(struct xhci_hcd *xhci,
2788 struct urb *urb, int i)
2789{
2790 int num_trbs = 0;
2791 u64 addr, td_len, running_total;
2792
2793 addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset);
2794 td_len = urb->iso_frame_desc[i].length;
2795
2796 running_total = TRB_MAX_BUFF_SIZE -
2797 (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1));
2798 if (running_total != 0)
2799 num_trbs++;
2800
2801 while (running_total < td_len) {
2802 num_trbs++;
2803 running_total += TRB_MAX_BUFF_SIZE;
2804 }
2805
2806 return num_trbs;
2807}
2808
2809/* This is for isoc transfer */
2810static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2811 struct urb *urb, int slot_id, unsigned int ep_index)
2812{
2813 struct xhci_ring *ep_ring;
2814 struct urb_priv *urb_priv;
2815 struct xhci_td *td;
2816 int num_tds, trbs_per_td;
2817 struct xhci_generic_trb *start_trb;
2818 bool first_trb;
2819 int start_cycle;
2820 u32 field, length_field;
2821 int running_total, trb_buff_len, td_len, td_remain_len, ret;
2822 u64 start_addr, addr;
2823 int i, j;
2824
2825 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
2826
2827 num_tds = urb->number_of_packets;
2828 if (num_tds < 1) {
2829 xhci_dbg(xhci, "Isoc URB with zero packets?\n");
2830 return -EINVAL;
2831 }
2832
2833 if (!in_interrupt())
2834 dev_dbg(&urb->dev->dev, "ep %#x - urb len = %#x (%d),"
2835 " addr = %#llx, num_tds = %d\n",
2836 urb->ep->desc.bEndpointAddress,
2837 urb->transfer_buffer_length,
2838 urb->transfer_buffer_length,
2839 (unsigned long long)urb->transfer_dma,
2840 num_tds);
2841
2842 start_addr = (u64) urb->transfer_dma;
2843 start_trb = &ep_ring->enqueue->generic;
2844 start_cycle = ep_ring->cycle_state;
2845
2846 /* Queue the first TRB, even if it's zero-length */
2847 for (i = 0; i < num_tds; i++) {
2848 first_trb = true;
2849
2850 running_total = 0;
2851 addr = start_addr + urb->iso_frame_desc[i].offset;
2852 td_len = urb->iso_frame_desc[i].length;
2853 td_remain_len = td_len;
2854
2855 trbs_per_td = count_isoc_trbs_needed(xhci, urb, i);
2856
2857 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index,
2858 urb->stream_id, trbs_per_td, urb, i, mem_flags);
2859 if (ret < 0)
2860 return ret;
2861
2862 urb_priv = urb->hcpriv;
2863 td = urb_priv->td[i];
2864
2865 for (j = 0; j < trbs_per_td; j++) {
2866 u32 remainder = 0;
2867 field = 0;
2868
2869 if (first_trb) {
2870 /* Queue the isoc TRB */
2871 field |= TRB_TYPE(TRB_ISOC);
2872 /* Assume URB_ISO_ASAP is set */
2873 field |= TRB_SIA;
2874 if (i > 0)
2875 field |= ep_ring->cycle_state;
2876 first_trb = false;
2877 } else {
2878 /* Queue other normal TRBs */
2879 field |= TRB_TYPE(TRB_NORMAL);
2880 field |= ep_ring->cycle_state;
2881 }
2882
2883 /* Chain all the TRBs together; clear the chain bit in
2884 * the last TRB to indicate it's the last TRB in the
2885 * chain.
2886 */
2887 if (j < trbs_per_td - 1) {
2888 field |= TRB_CHAIN;
2889 } else {
2890 td->last_trb = ep_ring->enqueue;
2891 field |= TRB_IOC;
2892 }
2893
2894 /* Calculate TRB length */
2895 trb_buff_len = TRB_MAX_BUFF_SIZE -
2896 (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1));
2897 if (trb_buff_len > td_remain_len)
2898 trb_buff_len = td_remain_len;
2899
2900 remainder = xhci_td_remainder(td_len - running_total);
2901 length_field = TRB_LEN(trb_buff_len) |
2902 remainder |
2903 TRB_INTR_TARGET(0);
2904 queue_trb(xhci, ep_ring, false, false,
2905 lower_32_bits(addr),
2906 upper_32_bits(addr),
2907 length_field,
2908 /* We always want to know if the TRB was short,
2909 * or we won't get an event when it completes.
2910 * (Unless we use event data TRBs, which are a
2911 * waste of space and HC resources.)
2912 */
2913 field | TRB_ISP);
2914 running_total += trb_buff_len;
2915
2916 addr += trb_buff_len;
2917 td_remain_len -= trb_buff_len;
2918 }
2919
2920 /* Check TD length */
2921 if (running_total != td_len) {
2922 xhci_err(xhci, "ISOC TD length unmatch\n");
2923 return -EINVAL;
2924 }
2925 }
2926
2927 wmb();
2928 start_trb->field[3] |= start_cycle;
2929
2930 ring_ep_doorbell(xhci, slot_id, ep_index, urb->stream_id);
2931 return 0;
2932}
2933
2934/*
2935 * Check transfer ring to guarantee there is enough room for the urb.
2936 * Update ISO URB start_frame and interval.
2937 * Update interval as xhci_queue_intr_tx does. Just use xhci frame_index to
2938 * update the urb->start_frame by now.
2939 * Always assume URB_ISO_ASAP set, and NEVER use urb->start_frame as input.
2940 */
2941int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
2942 struct urb *urb, int slot_id, unsigned int ep_index)
2943{
2944 struct xhci_virt_device *xdev;
2945 struct xhci_ring *ep_ring;
2946 struct xhci_ep_ctx *ep_ctx;
2947 int start_frame;
2948 int xhci_interval;
2949 int ep_interval;
2950 int num_tds, num_trbs, i;
2951 int ret;
2952
2953 xdev = xhci->devs[slot_id];
2954 ep_ring = xdev->eps[ep_index].ring;
2955 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
2956
2957 num_trbs = 0;
2958 num_tds = urb->number_of_packets;
2959 for (i = 0; i < num_tds; i++)
2960 num_trbs += count_isoc_trbs_needed(xhci, urb, i);
2961
2962 /* Check the ring to guarantee there is enough room for the whole urb.
2963 * Do not insert any td of the urb to the ring if the check failed.
2964 */
2965 ret = prepare_ring(xhci, ep_ring, ep_ctx->ep_info & EP_STATE_MASK,
2966 num_trbs, mem_flags);
2967 if (ret)
2968 return ret;
2969
2970 start_frame = xhci_readl(xhci, &xhci->run_regs->microframe_index);
2971 start_frame &= 0x3fff;
2972
2973 urb->start_frame = start_frame;
2974 if (urb->dev->speed == USB_SPEED_LOW ||
2975 urb->dev->speed == USB_SPEED_FULL)
2976 urb->start_frame >>= 3;
2977
2978 xhci_interval = EP_INTERVAL_TO_UFRAMES(ep_ctx->ep_info);
2979 ep_interval = urb->interval;
2980 /* Convert to microframes */
2981 if (urb->dev->speed == USB_SPEED_LOW ||
2982 urb->dev->speed == USB_SPEED_FULL)
2983 ep_interval *= 8;
2984 /* FIXME change this to a warning and a suggestion to use the new API
2985 * to set the polling interval (once the API is added).
2986 */
2987 if (xhci_interval != ep_interval) {
2988 if (!printk_ratelimit())
2989 dev_dbg(&urb->dev->dev, "Driver uses different interval"
2990 " (%d microframe%s) than xHCI "
2991 "(%d microframe%s)\n",
2992 ep_interval,
2993 ep_interval == 1 ? "" : "s",
2994 xhci_interval,
2995 xhci_interval == 1 ? "" : "s");
2996 urb->interval = xhci_interval;
2997 /* Convert back to frames for LS/FS devices */
2998 if (urb->dev->speed == USB_SPEED_LOW ||
2999 urb->dev->speed == USB_SPEED_FULL)
3000 urb->interval /= 8;
3001 }
3002 return xhci_queue_isoc_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index);
3003}
3004
2369/**** Command Ring Operations ****/ 3005/**** Command Ring Operations ****/
2370 3006
2371/* Generic function for queueing a command TRB on the command ring. 3007/* Generic function for queueing a command TRB on the command ring.
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 3998f72cd0c4..d5c550ea3e68 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -20,6 +20,7 @@
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#include <linux/pci.h>
23#include <linux/irq.h> 24#include <linux/irq.h>
24#include <linux/log2.h> 25#include <linux/log2.h>
25#include <linux/module.h> 26#include <linux/module.h>
@@ -171,22 +172,84 @@ int xhci_reset(struct xhci_hcd *xhci)
171 return handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000); 172 return handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000);
172} 173}
173 174
175/*
176 * Free IRQs
177 * free all IRQs request
178 */
179static void xhci_free_irq(struct xhci_hcd *xhci)
180{
181 int i;
182 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
174 183
175#if 0 184 /* return if using legacy interrupt */
176/* Set up MSI-X table for entry 0 (may claim other entries later) */ 185 if (xhci_to_hcd(xhci)->irq >= 0)
177static int xhci_setup_msix(struct xhci_hcd *xhci) 186 return;
187
188 if (xhci->msix_entries) {
189 for (i = 0; i < xhci->msix_count; i++)
190 if (xhci->msix_entries[i].vector)
191 free_irq(xhci->msix_entries[i].vector,
192 xhci_to_hcd(xhci));
193 } else if (pdev->irq >= 0)
194 free_irq(pdev->irq, xhci_to_hcd(xhci));
195
196 return;
197}
198
199/*
200 * Set up MSI
201 */
202static int xhci_setup_msi(struct xhci_hcd *xhci)
178{ 203{
179 int ret; 204 int ret;
205 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
206
207 ret = pci_enable_msi(pdev);
208 if (ret) {
209 xhci_err(xhci, "failed to allocate MSI entry\n");
210 return ret;
211 }
212
213 ret = request_irq(pdev->irq, (irq_handler_t)xhci_msi_irq,
214 0, "xhci_hcd", xhci_to_hcd(xhci));
215 if (ret) {
216 xhci_err(xhci, "disable MSI interrupt\n");
217 pci_disable_msi(pdev);
218 }
219
220 return ret;
221}
222
223/*
224 * Set up MSI-X
225 */
226static int xhci_setup_msix(struct xhci_hcd *xhci)
227{
228 int i, ret = 0;
180 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 229 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
181 230
182 xhci->msix_count = 0; 231 /*
183 /* XXX: did I do this right? ixgbe does kcalloc for more than one */ 232 * calculate number of msi-x vectors supported.
184 xhci->msix_entries = kmalloc(sizeof(struct msix_entry), GFP_KERNEL); 233 * - HCS_MAX_INTRS: the max number of interrupts the host can handle,
234 * with max number of interrupters based on the xhci HCSPARAMS1.
235 * - num_online_cpus: maximum msi-x vectors per CPUs core.
236 * Add additional 1 vector to ensure always available interrupt.
237 */
238 xhci->msix_count = min(num_online_cpus() + 1,
239 HCS_MAX_INTRS(xhci->hcs_params1));
240
241 xhci->msix_entries =
242 kmalloc((sizeof(struct msix_entry))*xhci->msix_count,
243 GFP_KERNEL);
185 if (!xhci->msix_entries) { 244 if (!xhci->msix_entries) {
186 xhci_err(xhci, "Failed to allocate MSI-X entries\n"); 245 xhci_err(xhci, "Failed to allocate MSI-X entries\n");
187 return -ENOMEM; 246 return -ENOMEM;
188 } 247 }
189 xhci->msix_entries[0].entry = 0; 248
249 for (i = 0; i < xhci->msix_count; i++) {
250 xhci->msix_entries[i].entry = i;
251 xhci->msix_entries[i].vector = 0;
252 }
190 253
191 ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count); 254 ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count);
192 if (ret) { 255 if (ret) {
@@ -194,20 +257,19 @@ static int xhci_setup_msix(struct xhci_hcd *xhci)
194 goto free_entries; 257 goto free_entries;
195 } 258 }
196 259
197 /* 260 for (i = 0; i < xhci->msix_count; i++) {
198 * Pass the xhci pointer value as the request_irq "cookie". 261 ret = request_irq(xhci->msix_entries[i].vector,
199 * If more irqs are added, this will need to be unique for each one. 262 (irq_handler_t)xhci_msi_irq,
200 */ 263 0, "xhci_hcd", xhci_to_hcd(xhci));
201 ret = request_irq(xhci->msix_entries[0].vector, &xhci_irq, 0, 264 if (ret)
202 "xHCI", xhci_to_hcd(xhci)); 265 goto disable_msix;
203 if (ret) {
204 xhci_err(xhci, "Failed to allocate MSI-X interrupt\n");
205 goto disable_msix;
206 } 266 }
207 xhci_dbg(xhci, "Finished setting up MSI-X\n"); 267
208 return 0; 268 return ret;
209 269
210disable_msix: 270disable_msix:
271 xhci_err(xhci, "disable MSI-X interrupt\n");
272 xhci_free_irq(xhci);
211 pci_disable_msix(pdev); 273 pci_disable_msix(pdev);
212free_entries: 274free_entries:
213 kfree(xhci->msix_entries); 275 kfree(xhci->msix_entries);
@@ -215,21 +277,23 @@ free_entries:
215 return ret; 277 return ret;
216} 278}
217 279
218/* XXX: code duplication; can xhci_setup_msix call this? */
219/* Free any IRQs and disable MSI-X */ 280/* Free any IRQs and disable MSI-X */
220static void xhci_cleanup_msix(struct xhci_hcd *xhci) 281static void xhci_cleanup_msix(struct xhci_hcd *xhci)
221{ 282{
222 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 283 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
223 if (!xhci->msix_entries)
224 return;
225 284
226 free_irq(xhci->msix_entries[0].vector, xhci); 285 xhci_free_irq(xhci);
227 pci_disable_msix(pdev); 286
228 kfree(xhci->msix_entries); 287 if (xhci->msix_entries) {
229 xhci->msix_entries = NULL; 288 pci_disable_msix(pdev);
230 xhci_dbg(xhci, "Finished cleaning up MSI-X\n"); 289 kfree(xhci->msix_entries);
290 xhci->msix_entries = NULL;
291 } else {
292 pci_disable_msi(pdev);
293 }
294
295 return;
231} 296}
232#endif
233 297
234/* 298/*
235 * Initialize memory for HCD and xHC (one-time init). 299 * Initialize memory for HCD and xHC (one-time init).
@@ -257,100 +321,8 @@ int xhci_init(struct usb_hcd *hcd)
257 return retval; 321 return retval;
258} 322}
259 323
260/*
261 * Called in interrupt context when there might be work
262 * queued on the event ring
263 *
264 * xhci->lock must be held by caller.
265 */
266static void xhci_work(struct xhci_hcd *xhci)
267{
268 u32 temp;
269 u64 temp_64;
270
271 /*
272 * Clear the op reg interrupt status first,
273 * so we can receive interrupts from other MSI-X interrupters.
274 * Write 1 to clear the interrupt status.
275 */
276 temp = xhci_readl(xhci, &xhci->op_regs->status);
277 temp |= STS_EINT;
278 xhci_writel(xhci, temp, &xhci->op_regs->status);
279 /* FIXME when MSI-X is supported and there are multiple vectors */
280 /* Clear the MSI-X event interrupt status */
281
282 /* Acknowledge the interrupt */
283 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
284 temp |= 0x3;
285 xhci_writel(xhci, temp, &xhci->ir_set->irq_pending);
286 /* Flush posted writes */
287 xhci_readl(xhci, &xhci->ir_set->irq_pending);
288
289 if (xhci->xhc_state & XHCI_STATE_DYING)
290 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. "
291 "Shouldn't IRQs be disabled?\n");
292 else
293 /* FIXME this should be a delayed service routine
294 * that clears the EHB.
295 */
296 xhci_handle_event(xhci);
297
298 /* Clear the event handler busy flag (RW1C); the event ring should be empty. */
299 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
300 xhci_write_64(xhci, temp_64 | ERST_EHB, &xhci->ir_set->erst_dequeue);
301 /* Flush posted writes -- FIXME is this necessary? */
302 xhci_readl(xhci, &xhci->ir_set->irq_pending);
303}
304
305/*-------------------------------------------------------------------------*/ 324/*-------------------------------------------------------------------------*/
306 325
307/*
308 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
309 * we might get bad data out of the event ring. Section 4.10.2.7 has a list of
310 * indicators of an event TRB error, but we check the status *first* to be safe.
311 */
312irqreturn_t xhci_irq(struct usb_hcd *hcd)
313{
314 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
315 u32 temp, temp2;
316 union xhci_trb *trb;
317
318 spin_lock(&xhci->lock);
319 trb = xhci->event_ring->dequeue;
320 /* Check if the xHC generated the interrupt, or the irq is shared */
321 temp = xhci_readl(xhci, &xhci->op_regs->status);
322 temp2 = xhci_readl(xhci, &xhci->ir_set->irq_pending);
323 if (temp == 0xffffffff && temp2 == 0xffffffff)
324 goto hw_died;
325
326 if (!(temp & STS_EINT) && !ER_IRQ_PENDING(temp2)) {
327 spin_unlock(&xhci->lock);
328 return IRQ_NONE;
329 }
330 xhci_dbg(xhci, "op reg status = %08x\n", temp);
331 xhci_dbg(xhci, "ir set irq_pending = %08x\n", temp2);
332 xhci_dbg(xhci, "Event ring dequeue ptr:\n");
333 xhci_dbg(xhci, "@%llx %08x %08x %08x %08x\n",
334 (unsigned long long)xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, trb),
335 lower_32_bits(trb->link.segment_ptr),
336 upper_32_bits(trb->link.segment_ptr),
337 (unsigned int) trb->link.intr_target,
338 (unsigned int) trb->link.control);
339
340 if (temp & STS_FATAL) {
341 xhci_warn(xhci, "WARNING: Host System Error\n");
342 xhci_halt(xhci);
343hw_died:
344 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
345 spin_unlock(&xhci->lock);
346 return -ESHUTDOWN;
347 }
348
349 xhci_work(xhci);
350 spin_unlock(&xhci->lock);
351
352 return IRQ_HANDLED;
353}
354 326
355#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 327#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
356void xhci_event_ring_work(unsigned long arg) 328void xhci_event_ring_work(unsigned long arg)
@@ -423,21 +395,36 @@ int xhci_run(struct usb_hcd *hcd)
423{ 395{
424 u32 temp; 396 u32 temp;
425 u64 temp_64; 397 u64 temp_64;
398 u32 ret;
426 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 399 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
400 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
427 void (*doorbell)(struct xhci_hcd *) = NULL; 401 void (*doorbell)(struct xhci_hcd *) = NULL;
428 402
429 hcd->uses_new_polling = 1; 403 hcd->uses_new_polling = 1;
430 hcd->poll_rh = 0;
431 404
432 xhci_dbg(xhci, "xhci_run\n"); 405 xhci_dbg(xhci, "xhci_run\n");
433#if 0 /* FIXME: MSI not setup yet */ 406 /* unregister the legacy interrupt */
434 /* Do this at the very last minute */ 407 if (hcd->irq)
408 free_irq(hcd->irq, hcd);
409 hcd->irq = -1;
410
435 ret = xhci_setup_msix(xhci); 411 ret = xhci_setup_msix(xhci);
436 if (!ret) 412 if (ret)
437 return ret; 413 /* fall back to msi*/
414 ret = xhci_setup_msi(xhci);
415
416 if (ret) {
417 /* fall back to legacy interrupt*/
418 ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED,
419 hcd->irq_descr, hcd);
420 if (ret) {
421 xhci_err(xhci, "request interrupt %d failed\n",
422 pdev->irq);
423 return ret;
424 }
425 hcd->irq = pdev->irq;
426 }
438 427
439 return -ENOSYS;
440#endif
441#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 428#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
442 init_timer(&xhci->event_ring_timer); 429 init_timer(&xhci->event_ring_timer);
443 xhci->event_ring_timer.data = (unsigned long) xhci; 430 xhci->event_ring_timer.data = (unsigned long) xhci;
@@ -495,7 +482,6 @@ int xhci_run(struct usb_hcd *hcd)
495 return -ENODEV; 482 return -ENODEV;
496 } 483 }
497 484
498 xhci_dbg(xhci, "// @%p = 0x%x\n", &xhci->op_regs->command, temp);
499 if (doorbell) 485 if (doorbell)
500 (*doorbell)(xhci); 486 (*doorbell)(xhci);
501 if (xhci->quirks & XHCI_NEC_HOST) 487 if (xhci->quirks & XHCI_NEC_HOST)
@@ -522,11 +508,9 @@ void xhci_stop(struct usb_hcd *hcd)
522 spin_lock_irq(&xhci->lock); 508 spin_lock_irq(&xhci->lock);
523 xhci_halt(xhci); 509 xhci_halt(xhci);
524 xhci_reset(xhci); 510 xhci_reset(xhci);
511 xhci_cleanup_msix(xhci);
525 spin_unlock_irq(&xhci->lock); 512 spin_unlock_irq(&xhci->lock);
526 513
527#if 0 /* No MSI yet */
528 xhci_cleanup_msix(xhci);
529#endif
530#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 514#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
531 /* Tell the event ring poll function not to reschedule */ 515 /* Tell the event ring poll function not to reschedule */
532 xhci->zombie = 1; 516 xhci->zombie = 1;
@@ -560,11 +544,8 @@ void xhci_shutdown(struct usb_hcd *hcd)
560 544
561 spin_lock_irq(&xhci->lock); 545 spin_lock_irq(&xhci->lock);
562 xhci_halt(xhci); 546 xhci_halt(xhci);
563 spin_unlock_irq(&xhci->lock);
564
565#if 0
566 xhci_cleanup_msix(xhci); 547 xhci_cleanup_msix(xhci);
567#endif 548 spin_unlock_irq(&xhci->lock);
568 549
569 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n", 550 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n",
570 xhci_readl(xhci, &xhci->op_regs->status)); 551 xhci_readl(xhci, &xhci->op_regs->status));
@@ -720,7 +701,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
720 unsigned long flags; 701 unsigned long flags;
721 int ret = 0; 702 int ret = 0;
722 unsigned int slot_id, ep_index; 703 unsigned int slot_id, ep_index;
723 704 struct urb_priv *urb_priv;
705 int size, i;
724 706
725 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0) 707 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0)
726 return -EINVAL; 708 return -EINVAL;
@@ -734,12 +716,36 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
734 ret = -EINVAL; 716 ret = -EINVAL;
735 goto exit; 717 goto exit;
736 } 718 }
737 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 719 if (!HCD_HW_ACCESSIBLE(hcd)) {
738 if (!in_interrupt()) 720 if (!in_interrupt())
739 xhci_dbg(xhci, "urb submitted during PCI suspend\n"); 721 xhci_dbg(xhci, "urb submitted during PCI suspend\n");
740 ret = -ESHUTDOWN; 722 ret = -ESHUTDOWN;
741 goto exit; 723 goto exit;
742 } 724 }
725
726 if (usb_endpoint_xfer_isoc(&urb->ep->desc))
727 size = urb->number_of_packets;
728 else
729 size = 1;
730
731 urb_priv = kzalloc(sizeof(struct urb_priv) +
732 size * sizeof(struct xhci_td *), mem_flags);
733 if (!urb_priv)
734 return -ENOMEM;
735
736 for (i = 0; i < size; i++) {
737 urb_priv->td[i] = kzalloc(sizeof(struct xhci_td), mem_flags);
738 if (!urb_priv->td[i]) {
739 urb_priv->length = i;
740 xhci_urb_free_priv(xhci, urb_priv);
741 return -ENOMEM;
742 }
743 }
744
745 urb_priv->length = size;
746 urb_priv->td_cnt = 0;
747 urb->hcpriv = urb_priv;
748
743 if (usb_endpoint_xfer_control(&urb->ep->desc)) { 749 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
744 /* Check to see if the max packet size for the default control 750 /* Check to see if the max packet size for the default control
745 * endpoint changed during FS device enumeration 751 * endpoint changed during FS device enumeration
@@ -788,11 +794,18 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
788 slot_id, ep_index); 794 slot_id, ep_index);
789 spin_unlock_irqrestore(&xhci->lock, flags); 795 spin_unlock_irqrestore(&xhci->lock, flags);
790 } else { 796 } else {
791 ret = -EINVAL; 797 spin_lock_irqsave(&xhci->lock, flags);
798 if (xhci->xhc_state & XHCI_STATE_DYING)
799 goto dying;
800 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb,
801 slot_id, ep_index);
802 spin_unlock_irqrestore(&xhci->lock, flags);
792 } 803 }
793exit: 804exit:
794 return ret; 805 return ret;
795dying: 806dying:
807 xhci_urb_free_priv(xhci, urb_priv);
808 urb->hcpriv = NULL;
796 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for " 809 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for "
797 "non-responsive xHCI host.\n", 810 "non-responsive xHCI host.\n",
798 urb->ep->desc.bEndpointAddress, urb); 811 urb->ep->desc.bEndpointAddress, urb);
@@ -800,6 +813,47 @@ dying:
800 return -ESHUTDOWN; 813 return -ESHUTDOWN;
801} 814}
802 815
816/* Get the right ring for the given URB.
817 * If the endpoint supports streams, boundary check the URB's stream ID.
818 * If the endpoint doesn't support streams, return the singular endpoint ring.
819 */
820static struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
821 struct urb *urb)
822{
823 unsigned int slot_id;
824 unsigned int ep_index;
825 unsigned int stream_id;
826 struct xhci_virt_ep *ep;
827
828 slot_id = urb->dev->slot_id;
829 ep_index = xhci_get_endpoint_index(&urb->ep->desc);
830 stream_id = urb->stream_id;
831 ep = &xhci->devs[slot_id]->eps[ep_index];
832 /* Common case: no streams */
833 if (!(ep->ep_state & EP_HAS_STREAMS))
834 return ep->ring;
835
836 if (stream_id == 0) {
837 xhci_warn(xhci,
838 "WARN: Slot ID %u, ep index %u has streams, "
839 "but URB has no stream ID.\n",
840 slot_id, ep_index);
841 return NULL;
842 }
843
844 if (stream_id < ep->stream_info->num_streams)
845 return ep->stream_info->stream_rings[stream_id];
846
847 xhci_warn(xhci,
848 "WARN: Slot ID %u, ep index %u has "
849 "stream IDs 1 to %u allocated, "
850 "but stream ID %u is requested.\n",
851 slot_id, ep_index,
852 ep->stream_info->num_streams - 1,
853 stream_id);
854 return NULL;
855}
856
803/* 857/*
804 * Remove the URB's TD from the endpoint ring. This may cause the HC to stop 858 * Remove the URB's TD from the endpoint ring. This may cause the HC to stop
805 * USB transfers, potentially stopping in the middle of a TRB buffer. The HC 859 * USB transfers, potentially stopping in the middle of a TRB buffer. The HC
@@ -834,9 +888,10 @@ dying:
834int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 888int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
835{ 889{
836 unsigned long flags; 890 unsigned long flags;
837 int ret; 891 int ret, i;
838 u32 temp; 892 u32 temp;
839 struct xhci_hcd *xhci; 893 struct xhci_hcd *xhci;
894 struct urb_priv *urb_priv;
840 struct xhci_td *td; 895 struct xhci_td *td;
841 unsigned int ep_index; 896 unsigned int ep_index;
842 struct xhci_ring *ep_ring; 897 struct xhci_ring *ep_ring;
@@ -851,12 +906,12 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
851 temp = xhci_readl(xhci, &xhci->op_regs->status); 906 temp = xhci_readl(xhci, &xhci->op_regs->status);
852 if (temp == 0xffffffff) { 907 if (temp == 0xffffffff) {
853 xhci_dbg(xhci, "HW died, freeing TD.\n"); 908 xhci_dbg(xhci, "HW died, freeing TD.\n");
854 td = (struct xhci_td *) urb->hcpriv; 909 urb_priv = urb->hcpriv;
855 910
856 usb_hcd_unlink_urb_from_ep(hcd, urb); 911 usb_hcd_unlink_urb_from_ep(hcd, urb);
857 spin_unlock_irqrestore(&xhci->lock, flags); 912 spin_unlock_irqrestore(&xhci->lock, flags);
858 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN); 913 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN);
859 kfree(td); 914 xhci_urb_free_priv(xhci, urb_priv);
860 return ret; 915 return ret;
861 } 916 }
862 if (xhci->xhc_state & XHCI_STATE_DYING) { 917 if (xhci->xhc_state & XHCI_STATE_DYING) {
@@ -884,9 +939,14 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
884 939
885 xhci_dbg(xhci, "Endpoint ring:\n"); 940 xhci_dbg(xhci, "Endpoint ring:\n");
886 xhci_debug_ring(xhci, ep_ring); 941 xhci_debug_ring(xhci, ep_ring);
887 td = (struct xhci_td *) urb->hcpriv;
888 942
889 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); 943 urb_priv = urb->hcpriv;
944
945 for (i = urb_priv->td_cnt; i < urb_priv->length; i++) {
946 td = urb_priv->td[i];
947 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list);
948 }
949
890 /* Queue a stop endpoint command, but only if this is 950 /* Queue a stop endpoint command, but only if this is
891 * the first cancellation to be handled. 951 * the first cancellation to be handled.
892 */ 952 */
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 6c7e3430ec93..34a60d9f056a 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -720,6 +720,14 @@ struct xhci_virt_ep {
720 struct timer_list stop_cmd_timer; 720 struct timer_list stop_cmd_timer;
721 int stop_cmds_pending; 721 int stop_cmds_pending;
722 struct xhci_hcd *xhci; 722 struct xhci_hcd *xhci;
723 /*
724 * Sometimes the xHC can not process isochronous endpoint ring quickly
725 * enough, and it will miss some isoc tds on the ring and generate
726 * a Missed Service Error Event.
727 * Set skip flag when receive a Missed Service Error Event and
728 * process the missed tds on the endpoint ring.
729 */
730 bool skip;
723}; 731};
724 732
725struct xhci_virt_device { 733struct xhci_virt_device {
@@ -911,6 +919,9 @@ struct xhci_event_cmd {
911/* Control transfer TRB specific fields */ 919/* Control transfer TRB specific fields */
912#define TRB_DIR_IN (1<<16) 920#define TRB_DIR_IN (1<<16)
913 921
922/* Isochronous TRB specific fields */
923#define TRB_SIA (1<<31)
924
914struct xhci_generic_trb { 925struct xhci_generic_trb {
915 u32 field[4]; 926 u32 field[4];
916}; 927};
@@ -1082,6 +1093,12 @@ struct xhci_scratchpad {
1082 dma_addr_t *sp_dma_buffers; 1093 dma_addr_t *sp_dma_buffers;
1083}; 1094};
1084 1095
1096struct urb_priv {
1097 int length;
1098 int td_cnt;
1099 struct xhci_td *td[0];
1100};
1101
1085/* 1102/*
1086 * Each segment table entry is 4*32bits long. 1K seems like an ok size: 1103 * Each segment table entry is 4*32bits long. 1K seems like an ok size:
1087 * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table, 1104 * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
@@ -1130,7 +1147,7 @@ struct xhci_hcd {
1130 int page_size; 1147 int page_size;
1131 /* Valid values are 12 to 20, inclusive */ 1148 /* Valid values are 12 to 20, inclusive */
1132 int page_shift; 1149 int page_shift;
1133 /* only one MSI vector for now, but might need more later */ 1150 /* msi-x vectors */
1134 int msix_count; 1151 int msix_count;
1135 struct msix_entry *msix_entries; 1152 struct msix_entry *msix_entries;
1136 /* data structures */ 1153 /* data structures */
@@ -1327,11 +1344,6 @@ void xhci_setup_no_streams_ep_input_ctx(struct xhci_hcd *xhci,
1327struct xhci_ring *xhci_dma_to_transfer_ring( 1344struct xhci_ring *xhci_dma_to_transfer_ring(
1328 struct xhci_virt_ep *ep, 1345 struct xhci_virt_ep *ep,
1329 u64 address); 1346 u64 address);
1330struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
1331 struct urb *urb);
1332struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
1333 unsigned int slot_id, unsigned int ep_index,
1334 unsigned int stream_id);
1335struct xhci_ring *xhci_stream_id_to_ring( 1347struct xhci_ring *xhci_stream_id_to_ring(
1336 struct xhci_virt_device *dev, 1348 struct xhci_virt_device *dev,
1337 unsigned int ep_index, 1349 unsigned int ep_index,
@@ -1339,6 +1351,7 @@ struct xhci_ring *xhci_stream_id_to_ring(
1339struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, 1351struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1340 bool allocate_in_ctx, bool allocate_completion, 1352 bool allocate_in_ctx, bool allocate_completion,
1341 gfp_t mem_flags); 1353 gfp_t mem_flags);
1354void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv);
1342void xhci_free_command(struct xhci_hcd *xhci, 1355void xhci_free_command(struct xhci_hcd *xhci,
1343 struct xhci_command *command); 1356 struct xhci_command *command);
1344 1357
@@ -1358,6 +1371,7 @@ void xhci_stop(struct usb_hcd *hcd);
1358void xhci_shutdown(struct usb_hcd *hcd); 1371void xhci_shutdown(struct usb_hcd *hcd);
1359int xhci_get_frame(struct usb_hcd *hcd); 1372int xhci_get_frame(struct usb_hcd *hcd);
1360irqreturn_t xhci_irq(struct usb_hcd *hcd); 1373irqreturn_t xhci_irq(struct usb_hcd *hcd);
1374irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd);
1361int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); 1375int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
1362void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); 1376void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
1363int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, 1377int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
@@ -1386,8 +1400,6 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1386int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); 1400int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
1387void xhci_ring_cmd_db(struct xhci_hcd *xhci); 1401void xhci_ring_cmd_db(struct xhci_hcd *xhci);
1388void *xhci_setup_one_noop(struct xhci_hcd *xhci); 1402void *xhci_setup_one_noop(struct xhci_hcd *xhci);
1389void xhci_handle_event(struct xhci_hcd *xhci);
1390void xhci_set_hc_event_deq(struct xhci_hcd *xhci);
1391int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); 1403int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
1392int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1404int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1393 u32 slot_id); 1405 u32 slot_id);
@@ -1401,6 +1413,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1401 int slot_id, unsigned int ep_index); 1413 int slot_id, unsigned int ep_index);
1402int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, 1414int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1403 int slot_id, unsigned int ep_index); 1415 int slot_id, unsigned int ep_index);
1416int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
1417 struct urb *urb, int slot_id, unsigned int ep_index);
1404int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1418int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1405 u32 slot_id, bool command_must_succeed); 1419 u32 slot_id, bool command_must_succeed);
1406int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1420int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,