aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Senna Tschudin <peter.senna@gmail.com>2015-10-12 17:22:32 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-10-17 02:46:22 -0400
commit259127ba78d0f25c82a13e594f322b5016f40b62 (patch)
tree84798f41fb898360af75263569242720afe1093d
parent34e51ba6b65b5db4e35426759b1fbdf608545238 (diff)
usb/host/fotg210: Fix coding style issues
This patch fix coding style issues reported by checkpatch that do not change semantics of the code. Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/host/fotg210-hcd.c1710
-rw-r--r--drivers/usb/host/fotg210.h36
2 files changed, 769 insertions, 977 deletions
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
index dea513ebf7f9..714fe845dd1b 100644
--- a/drivers/usb/host/fotg210-hcd.c
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -1,5 +1,4 @@
1/* 1/* Faraday FOTG210 EHCI-like driver
2 * Faraday FOTG210 EHCI-like driver
3 * 2 *
4 * Copyright (c) 2013 Faraday Technology Corporation 3 * Copyright (c) 2013 Faraday Technology Corporation
5 * 4 *
@@ -50,32 +49,29 @@
50#include <asm/irq.h> 49#include <asm/irq.h>
51#include <asm/unaligned.h> 50#include <asm/unaligned.h>
52 51
53/*-------------------------------------------------------------------------*/
54#define DRIVER_AUTHOR "Yuan-Hsin Chen" 52#define DRIVER_AUTHOR "Yuan-Hsin Chen"
55#define DRIVER_DESC "FOTG210 Host Controller (EHCI) Driver" 53#define DRIVER_DESC "FOTG210 Host Controller (EHCI) Driver"
56 54static const char hcd_name[] = "fotg210_hcd";
57static const char hcd_name[] = "fotg210_hcd";
58 55
59#undef FOTG210_URB_TRACE 56#undef FOTG210_URB_TRACE
60
61#define FOTG210_STATS 57#define FOTG210_STATS
62 58
63/* magic numbers that can affect system performance */ 59/* magic numbers that can affect system performance */
64#define FOTG210_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */ 60#define FOTG210_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
65#define FOTG210_TUNE_RL_HS 4 /* nak throttle; see 4.9 */ 61#define FOTG210_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
66#define FOTG210_TUNE_RL_TT 0 62#define FOTG210_TUNE_RL_TT 0
67#define FOTG210_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ 63#define FOTG210_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
68#define FOTG210_TUNE_MULT_TT 1 64#define FOTG210_TUNE_MULT_TT 1
69/* 65
70 * Some drivers think it's safe to schedule isochronous transfers more than 66/* Some drivers think it's safe to schedule isochronous transfers more than 256
71 * 256 ms into the future (partly as a result of an old bug in the scheduling 67 * ms into the future (partly as a result of an old bug in the scheduling
72 * code). In an attempt to avoid trouble, we will use a minimum scheduling 68 * code). In an attempt to avoid trouble, we will use a minimum scheduling
73 * length of 512 frames instead of 256. 69 * length of 512 frames instead of 256.
74 */ 70 */
75#define FOTG210_TUNE_FLS 1 /* (medium) 512-frame schedule */ 71#define FOTG210_TUNE_FLS 1 /* (medium) 512-frame schedule */
76 72
77/* Initial IRQ latency: faster than hw default */ 73/* Initial IRQ latency: faster than hw default */
78static int log2_irq_thresh; /* 0 to 6 */ 74static int log2_irq_thresh; /* 0 to 6 */
79module_param(log2_irq_thresh, int, S_IRUGO); 75module_param(log2_irq_thresh, int, S_IRUGO);
80MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes"); 76MODULE_PARM_DESC(log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");
81 77
@@ -89,66 +85,57 @@ static unsigned int hird;
89module_param(hird, int, S_IRUGO); 85module_param(hird, int, S_IRUGO);
90MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us"); 86MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us");
91 87
92#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 88#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
93 89
94#include "fotg210.h" 90#include "fotg210.h"
95 91
96/*-------------------------------------------------------------------------*/
97
98#define fotg210_dbg(fotg210, fmt, args...) \ 92#define fotg210_dbg(fotg210, fmt, args...) \
99 dev_dbg(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args) 93 dev_dbg(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
100#define fotg210_err(fotg210, fmt, args...) \ 94#define fotg210_err(fotg210, fmt, args...) \
101 dev_err(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args) 95 dev_err(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
102#define fotg210_info(fotg210, fmt, args...) \ 96#define fotg210_info(fotg210, fmt, args...) \
103 dev_info(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args) 97 dev_info(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
104#define fotg210_warn(fotg210, fmt, args...) \ 98#define fotg210_warn(fotg210, fmt, args...) \
105 dev_warn(fotg210_to_hcd(fotg210)->self.controller , fmt , ## args) 99 dev_warn(fotg210_to_hcd(fotg210)->self.controller, fmt, ## args)
106 100
107/* check the values in the HCSPARAMS register 101/* check the values in the HCSPARAMS register (host controller _Structural_
108 * (host controller _Structural_ parameters) 102 * parameters) see EHCI spec, Table 2-4 for each value
109 * see EHCI spec, Table 2-4 for each value
110 */ 103 */
111static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label) 104static void dbg_hcs_params(struct fotg210_hcd *fotg210, char *label)
112{ 105{
113 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params); 106 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcs_params);
114 107
115 fotg210_dbg(fotg210, 108 fotg210_dbg(fotg210, "%s hcs_params 0x%x ports=%d\n", label, params,
116 "%s hcs_params 0x%x ports=%d\n", 109 HCS_N_PORTS(params));
117 label, params,
118 HCS_N_PORTS(params)
119 );
120} 110}
121 111
122/* check the values in the HCCPARAMS register 112/* check the values in the HCCPARAMS register (host controller _Capability_
123 * (host controller _Capability_ parameters) 113 * parameters) see EHCI Spec, Table 2-5 for each value
124 * see EHCI Spec, Table 2-5 for each value 114 */
125 * */
126static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label) 115static void dbg_hcc_params(struct fotg210_hcd *fotg210, char *label)
127{ 116{
128 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params); 117 u32 params = fotg210_readl(fotg210, &fotg210->caps->hcc_params);
129 118
130 fotg210_dbg(fotg210, 119 fotg210_dbg(fotg210, "%s hcc_params %04x uframes %s%s\n", label,
131 "%s hcc_params %04x uframes %s%s\n", 120 params,
132 label, 121 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
133 params, 122 HCC_CANPARK(params) ? " park" : "");
134 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
135 HCC_CANPARK(params) ? " park" : "");
136} 123}
137 124
138static void __maybe_unused 125static void __maybe_unused
139dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd) 126dbg_qtd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd)
140{ 127{
141 fotg210_dbg(fotg210, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd, 128 fotg210_dbg(fotg210, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
142 hc32_to_cpup(fotg210, &qtd->hw_next), 129 hc32_to_cpup(fotg210, &qtd->hw_next),
143 hc32_to_cpup(fotg210, &qtd->hw_alt_next), 130 hc32_to_cpup(fotg210, &qtd->hw_alt_next),
144 hc32_to_cpup(fotg210, &qtd->hw_token), 131 hc32_to_cpup(fotg210, &qtd->hw_token),
145 hc32_to_cpup(fotg210, &qtd->hw_buf[0])); 132 hc32_to_cpup(fotg210, &qtd->hw_buf[0]));
146 if (qtd->hw_buf[1]) 133 if (qtd->hw_buf[1])
147 fotg210_dbg(fotg210, " p1=%08x p2=%08x p3=%08x p4=%08x\n", 134 fotg210_dbg(fotg210, " p1=%08x p2=%08x p3=%08x p4=%08x\n",
148 hc32_to_cpup(fotg210, &qtd->hw_buf[1]), 135 hc32_to_cpup(fotg210, &qtd->hw_buf[1]),
149 hc32_to_cpup(fotg210, &qtd->hw_buf[2]), 136 hc32_to_cpup(fotg210, &qtd->hw_buf[2]),
150 hc32_to_cpup(fotg210, &qtd->hw_buf[3]), 137 hc32_to_cpup(fotg210, &qtd->hw_buf[3]),
151 hc32_to_cpup(fotg210, &qtd->hw_buf[4])); 138 hc32_to_cpup(fotg210, &qtd->hw_buf[4]));
152} 139}
153 140
154static void __maybe_unused 141static void __maybe_unused
@@ -156,101 +143,100 @@ dbg_qh(const char *label, struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
156{ 143{
157 struct fotg210_qh_hw *hw = qh->hw; 144 struct fotg210_qh_hw *hw = qh->hw;
158 145
159 fotg210_dbg(fotg210, "%s qh %p n%08x info %x %x qtd %x\n", label, 146 fotg210_dbg(fotg210, "%s qh %p n%08x info %x %x qtd %x\n", label, qh,
160 qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current); 147 hw->hw_next, hw->hw_info1, hw->hw_info2,
148 hw->hw_current);
149
161 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next); 150 dbg_qtd("overlay", fotg210, (struct fotg210_qtd *) &hw->hw_qtd_next);
162} 151}
163 152
164static void __maybe_unused 153static void __maybe_unused
165dbg_itd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_itd *itd) 154dbg_itd(const char *label, struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
166{ 155{
167 fotg210_dbg(fotg210, "%s[%d] itd %p, next %08x, urb %p\n", 156 fotg210_dbg(fotg210, "%s[%d] itd %p, next %08x, urb %p\n", label,
168 label, itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next), 157 itd->frame, itd, hc32_to_cpu(fotg210, itd->hw_next),
169 itd->urb); 158 itd->urb);
159
170 fotg210_dbg(fotg210, 160 fotg210_dbg(fotg210,
171 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n", 161 " trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
172 hc32_to_cpu(fotg210, itd->hw_transaction[0]), 162 hc32_to_cpu(fotg210, itd->hw_transaction[0]),
173 hc32_to_cpu(fotg210, itd->hw_transaction[1]), 163 hc32_to_cpu(fotg210, itd->hw_transaction[1]),
174 hc32_to_cpu(fotg210, itd->hw_transaction[2]), 164 hc32_to_cpu(fotg210, itd->hw_transaction[2]),
175 hc32_to_cpu(fotg210, itd->hw_transaction[3]), 165 hc32_to_cpu(fotg210, itd->hw_transaction[3]),
176 hc32_to_cpu(fotg210, itd->hw_transaction[4]), 166 hc32_to_cpu(fotg210, itd->hw_transaction[4]),
177 hc32_to_cpu(fotg210, itd->hw_transaction[5]), 167 hc32_to_cpu(fotg210, itd->hw_transaction[5]),
178 hc32_to_cpu(fotg210, itd->hw_transaction[6]), 168 hc32_to_cpu(fotg210, itd->hw_transaction[6]),
179 hc32_to_cpu(fotg210, itd->hw_transaction[7])); 169 hc32_to_cpu(fotg210, itd->hw_transaction[7]));
170
180 fotg210_dbg(fotg210, 171 fotg210_dbg(fotg210,
181 " buf: %08x %08x %08x %08x %08x %08x %08x\n", 172 " buf: %08x %08x %08x %08x %08x %08x %08x\n",
182 hc32_to_cpu(fotg210, itd->hw_bufp[0]), 173 hc32_to_cpu(fotg210, itd->hw_bufp[0]),
183 hc32_to_cpu(fotg210, itd->hw_bufp[1]), 174 hc32_to_cpu(fotg210, itd->hw_bufp[1]),
184 hc32_to_cpu(fotg210, itd->hw_bufp[2]), 175 hc32_to_cpu(fotg210, itd->hw_bufp[2]),
185 hc32_to_cpu(fotg210, itd->hw_bufp[3]), 176 hc32_to_cpu(fotg210, itd->hw_bufp[3]),
186 hc32_to_cpu(fotg210, itd->hw_bufp[4]), 177 hc32_to_cpu(fotg210, itd->hw_bufp[4]),
187 hc32_to_cpu(fotg210, itd->hw_bufp[5]), 178 hc32_to_cpu(fotg210, itd->hw_bufp[5]),
188 hc32_to_cpu(fotg210, itd->hw_bufp[6])); 179 hc32_to_cpu(fotg210, itd->hw_bufp[6]));
180
189 fotg210_dbg(fotg210, " index: %d %d %d %d %d %d %d %d\n", 181 fotg210_dbg(fotg210, " index: %d %d %d %d %d %d %d %d\n",
190 itd->index[0], itd->index[1], itd->index[2], 182 itd->index[0], itd->index[1], itd->index[2],
191 itd->index[3], itd->index[4], itd->index[5], 183 itd->index[3], itd->index[4], itd->index[5],
192 itd->index[6], itd->index[7]); 184 itd->index[6], itd->index[7]);
193} 185}
194 186
195static int __maybe_unused 187static int __maybe_unused
196dbg_status_buf(char *buf, unsigned len, const char *label, u32 status) 188dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
197{ 189{
198 return scnprintf(buf, len, 190 return scnprintf(buf, len, "%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", 191 label, label[0] ? " " : "", status,
200 label, label[0] ? " " : "", status, 192 (status & STS_ASS) ? " Async" : "",
201 (status & STS_ASS) ? " Async" : "", 193 (status & STS_PSS) ? " Periodic" : "",
202 (status & STS_PSS) ? " Periodic" : "", 194 (status & STS_RECL) ? " Recl" : "",
203 (status & STS_RECL) ? " Recl" : "", 195 (status & STS_HALT) ? " Halt" : "",
204 (status & STS_HALT) ? " Halt" : "", 196 (status & STS_IAA) ? " IAA" : "",
205 (status & STS_IAA) ? " IAA" : "", 197 (status & STS_FATAL) ? " FATAL" : "",
206 (status & STS_FATAL) ? " FATAL" : "", 198 (status & STS_FLR) ? " FLR" : "",
207 (status & STS_FLR) ? " FLR" : "", 199 (status & STS_PCD) ? " PCD" : "",
208 (status & STS_PCD) ? " PCD" : "", 200 (status & STS_ERR) ? " ERR" : "",
209 (status & STS_ERR) ? " ERR" : "", 201 (status & STS_INT) ? " INT" : "");
210 (status & STS_INT) ? " INT" : ""
211 );
212} 202}
213 203
214static int __maybe_unused 204static int __maybe_unused
215dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable) 205dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
216{ 206{
217 return scnprintf(buf, len, 207 return scnprintf(buf, len, "%s%sintrenable %02x%s%s%s%s%s%s",
218 "%s%sintrenable %02x%s%s%s%s%s%s", 208 label, label[0] ? " " : "", enable,
219 label, label[0] ? " " : "", enable, 209 (enable & STS_IAA) ? " IAA" : "",
220 (enable & STS_IAA) ? " IAA" : "", 210 (enable & STS_FATAL) ? " FATAL" : "",
221 (enable & STS_FATAL) ? " FATAL" : "", 211 (enable & STS_FLR) ? " FLR" : "",
222 (enable & STS_FLR) ? " FLR" : "", 212 (enable & STS_PCD) ? " PCD" : "",
223 (enable & STS_PCD) ? " PCD" : "", 213 (enable & STS_ERR) ? " ERR" : "",
224 (enable & STS_ERR) ? " ERR" : "", 214 (enable & STS_INT) ? " INT" : "");
225 (enable & STS_INT) ? " INT" : ""
226 );
227} 215}
228 216
229static const char *const fls_strings[] = { "1024", "512", "256", "??" }; 217static const char *const fls_strings[] = { "1024", "512", "256", "??" };
230 218
231static int 219static int dbg_command_buf(char *buf, unsigned len, const char *label,
232dbg_command_buf(char *buf, unsigned len, const char *label, u32 command) 220 u32 command)
233{ 221{
234 return scnprintf(buf, len, 222 return scnprintf(buf, len,
235 "%s%scommand %07x %s=%d ithresh=%d%s%s%s " 223 "%s%scommand %07x %s=%d ithresh=%d%s%s%s period=%s%s %s",
236 "period=%s%s %s", 224 label, label[0] ? " " : "", command,
237 label, label[0] ? " " : "", command, 225 (command & CMD_PARK) ? " park" : "(park)",
238 (command & CMD_PARK) ? " park" : "(park)", 226 CMD_PARK_CNT(command),
239 CMD_PARK_CNT(command), 227 (command >> 16) & 0x3f,
240 (command >> 16) & 0x3f, 228 (command & CMD_IAAD) ? " IAAD" : "",
241 (command & CMD_IAAD) ? " IAAD" : "", 229 (command & CMD_ASE) ? " Async" : "",
242 (command & CMD_ASE) ? " Async" : "", 230 (command & CMD_PSE) ? " Periodic" : "",
243 (command & CMD_PSE) ? " Periodic" : "", 231 fls_strings[(command >> 2) & 0x3],
244 fls_strings[(command >> 2) & 0x3], 232 (command & CMD_RESET) ? " Reset" : "",
245 (command & CMD_RESET) ? " Reset" : "", 233 (command & CMD_RUN) ? "RUN" : "HALT");
246 (command & CMD_RUN) ? "RUN" : "HALT" 234}
247 ); 235
248} 236static char *dbg_port_buf(char *buf, unsigned len, const char *label, int port,
249 237 u32 status)
250static char 238{
251*dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status) 239 char *sig;
252{
253 char *sig;
254 240
255 /* signaling state */ 241 /* signaling state */
256 switch (status & (3 << 10)) { 242 switch (status & (3 << 10)) {
@@ -268,44 +254,41 @@ static char
268 break; 254 break;
269 } 255 }
270 256
271 scnprintf(buf, len, 257 scnprintf(buf, len, "%s%sport:%d status %06x %d sig=%s%s%s%s%s%s%s%s",
272 "%s%sport:%d status %06x %d " 258 label, label[0] ? " " : "", port, status,
273 "sig=%s%s%s%s%s%s%s%s", 259 status >> 25, /*device address */
274 label, label[0] ? " " : "", port, status, 260 sig,
275 status>>25,/*device address */ 261 (status & PORT_RESET) ? " RESET" : "",
276 sig, 262 (status & PORT_SUSPEND) ? " SUSPEND" : "",
277 (status & PORT_RESET) ? " RESET" : "", 263 (status & PORT_RESUME) ? " RESUME" : "",
278 (status & PORT_SUSPEND) ? " SUSPEND" : "", 264 (status & PORT_PEC) ? " PEC" : "",
279 (status & PORT_RESUME) ? " RESUME" : "", 265 (status & PORT_PE) ? " PE" : "",
280 (status & PORT_PEC) ? " PEC" : "", 266 (status & PORT_CSC) ? " CSC" : "",
281 (status & PORT_PE) ? " PE" : "", 267 (status & PORT_CONNECT) ? " CONNECT" : "");
282 (status & PORT_CSC) ? " CSC" : "", 268
283 (status & PORT_CONNECT) ? " CONNECT" : "");
284 return buf; 269 return buf;
285} 270}
286 271
287/* functions have the "wrong" filename when they're output... */ 272/* functions have the "wrong" filename when they're output... */
288#define dbg_status(fotg210, label, status) { \ 273#define dbg_status(fotg210, label, status) { \
289 char _buf[80]; \ 274 char _buf[80]; \
290 dbg_status_buf(_buf, sizeof(_buf), label, status); \ 275 dbg_status_buf(_buf, sizeof(_buf), label, status); \
291 fotg210_dbg(fotg210, "%s\n", _buf); \ 276 fotg210_dbg(fotg210, "%s\n", _buf); \
292} 277}
293 278
294#define dbg_cmd(fotg210, label, command) { \ 279#define dbg_cmd(fotg210, label, command) { \
295 char _buf[80]; \ 280 char _buf[80]; \
296 dbg_command_buf(_buf, sizeof(_buf), label, command); \ 281 dbg_command_buf(_buf, sizeof(_buf), label, command); \
297 fotg210_dbg(fotg210, "%s\n", _buf); \ 282 fotg210_dbg(fotg210, "%s\n", _buf); \
298} 283}
299 284
300#define dbg_port(fotg210, label, port, status) { \ 285#define dbg_port(fotg210, label, port, status) { \
301 char _buf[80]; \ 286 char _buf[80]; \
302 fotg210_dbg(fotg210, "%s\n", dbg_port_buf(_buf, sizeof(_buf), label, port, status) ); \ 287 fotg210_dbg(fotg210, "%s\n", \
288 dbg_port_buf(_buf, sizeof(_buf), label, port, status));\
303} 289}
304 290
305/*-------------------------------------------------------------------------*/
306
307/* troubleshooting help: expose state in debugfs */ 291/* troubleshooting help: expose state in debugfs */
308
309static int debug_async_open(struct inode *, struct file *); 292static int debug_async_open(struct inode *, struct file *);
310static int debug_periodic_open(struct inode *, struct file *); 293static int debug_periodic_open(struct inode *, struct file *);
311static int debug_registers_open(struct inode *, struct file *); 294static int debug_registers_open(struct inode *, struct file *);
@@ -373,33 +356,29 @@ static inline char token_mark(struct fotg210_hcd *fotg210, __hc32 token)
373 return '/'; 356 return '/';
374} 357}
375 358
376static void qh_lines( 359static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
377 struct fotg210_hcd *fotg210, 360 char **nextp, unsigned *sizep)
378 struct fotg210_qh *qh, 361{
379 char **nextp, 362 u32 scratch;
380 unsigned *sizep 363 u32 hw_curr;
381) 364 struct fotg210_qtd *td;
382{ 365 unsigned temp;
383 u32 scratch; 366 unsigned size = *sizep;
384 u32 hw_curr; 367 char *next = *nextp;
385 struct fotg210_qtd *td; 368 char mark;
386 unsigned temp; 369 __le32 list_end = FOTG210_LIST_END(fotg210);
387 unsigned size = *sizep; 370 struct fotg210_qh_hw *hw = qh->hw;
388 char *next = *nextp; 371
389 char mark; 372 if (hw->hw_qtd_next == list_end) /* NEC does this */
390 __le32 list_end = FOTG210_LIST_END(fotg210);
391 struct fotg210_qh_hw *hw = qh->hw;
392
393 if (hw->hw_qtd_next == list_end) /* NEC does this */
394 mark = '@'; 373 mark = '@';
395 else 374 else
396 mark = token_mark(fotg210, hw->hw_token); 375 mark = token_mark(fotg210, hw->hw_token);
397 if (mark == '/') { /* qh_alt_next controls qh advance? */ 376 if (mark == '/') { /* qh_alt_next controls qh advance? */
398 if ((hw->hw_alt_next & QTD_MASK(fotg210)) 377 if ((hw->hw_alt_next & QTD_MASK(fotg210)) ==
399 == fotg210->async->hw->hw_alt_next) 378 fotg210->async->hw->hw_alt_next)
400 mark = '#'; /* blocked */ 379 mark = '#'; /* blocked */
401 else if (hw->hw_alt_next == list_end) 380 else if (hw->hw_alt_next == list_end)
402 mark = '.'; /* use hw_qtd_next */ 381 mark = '.'; /* use hw_qtd_next */
403 /* else alt_next points to some other qtd */ 382 /* else alt_next points to some other qtd */
404 } 383 }
405 scratch = hc32_to_cpup(fotg210, &hw->hw_info1); 384 scratch = hc32_to_cpup(fotg210, &hw->hw_info1);
@@ -462,6 +441,7 @@ static void qh_lines(
462 temp = snprintf(next, size, "\n"); 441 temp = snprintf(next, size, "\n");
463 if (size < temp) 442 if (size < temp)
464 temp = size; 443 temp = size;
444
465 size -= temp; 445 size -= temp;
466 next += temp; 446 next += temp;
467 447
@@ -472,12 +452,12 @@ done:
472 452
473static ssize_t fill_async_buffer(struct debug_buffer *buf) 453static ssize_t fill_async_buffer(struct debug_buffer *buf)
474{ 454{
475 struct usb_hcd *hcd; 455 struct usb_hcd *hcd;
476 struct fotg210_hcd *fotg210; 456 struct fotg210_hcd *fotg210;
477 unsigned long flags; 457 unsigned long flags;
478 unsigned temp, size; 458 unsigned temp, size;
479 char *next; 459 char *next;
480 struct fotg210_qh *qh; 460 struct fotg210_qh *qh;
481 461
482 hcd = bus_to_hcd(buf->bus); 462 hcd = bus_to_hcd(buf->bus);
483 fotg210 = hcd_to_fotg210(hcd); 463 fotg210 = hcd_to_fotg210(hcd);
@@ -492,7 +472,7 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
492 */ 472 */
493 spin_lock_irqsave(&fotg210->lock, flags); 473 spin_lock_irqsave(&fotg210->lock, flags);
494 for (qh = fotg210->async->qh_next.qh; size > 0 && qh; 474 for (qh = fotg210->async->qh_next.qh; size > 0 && qh;
495 qh = qh->qh_next.qh) 475 qh = qh->qh_next.qh)
496 qh_lines(fotg210, qh, &next, &size); 476 qh_lines(fotg210, qh, &next, &size);
497 if (fotg210->async_unlink && size > 0) { 477 if (fotg210->async_unlink && size > 0) {
498 temp = scnprintf(next, size, "\nunlink =\n"); 478 temp = scnprintf(next, size, "\nunlink =\n");
@@ -511,18 +491,19 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
511#define DBG_SCHED_LIMIT 64 491#define DBG_SCHED_LIMIT 64
512static ssize_t fill_periodic_buffer(struct debug_buffer *buf) 492static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
513{ 493{
514 struct usb_hcd *hcd; 494 struct usb_hcd *hcd;
515 struct fotg210_hcd *fotg210; 495 struct fotg210_hcd *fotg210;
516 unsigned long flags; 496 unsigned long flags;
517 union fotg210_shadow p, *seen; 497 union fotg210_shadow p, *seen;
518 unsigned temp, size, seen_count; 498 unsigned temp, size, seen_count;
519 char *next; 499 char *next;
520 unsigned i; 500 unsigned i;
521 __hc32 tag; 501 __hc32 tag;
522 502
523 seen = kmalloc(DBG_SCHED_LIMIT * sizeof(*seen), GFP_ATOMIC); 503 seen = kmalloc(DBG_SCHED_LIMIT * sizeof(*seen), GFP_ATOMIC);
524 if (!seen) 504 if (!seen)
525 return 0; 505 return 0;
506
526 seen_count = 0; 507 seen_count = 0;
527 508
528 hcd = bus_to_hcd(buf->bus); 509 hcd = bus_to_hcd(buf->bus);
@@ -542,6 +523,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
542 p = fotg210->pshadow[i]; 523 p = fotg210->pshadow[i];
543 if (likely(!p.ptr)) 524 if (likely(!p.ptr))
544 continue; 525 continue;
526
545 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]); 527 tag = Q_NEXT_TYPE(fotg210, fotg210->periodic[i]);
546 528
547 temp = scnprintf(next, size, "%4d: ", i); 529 temp = scnprintf(next, size, "%4d: ", i);
@@ -569,7 +551,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
569 continue; 551 continue;
570 if (p.qh->qh_next.ptr) { 552 if (p.qh->qh_next.ptr) {
571 temp = scnprintf(next, size, 553 temp = scnprintf(next, size,
572 " ..."); 554 " ...");
573 size -= temp; 555 size -= temp;
574 next += temp; 556 next += temp;
575 } 557 }
@@ -577,10 +559,10 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
577 } 559 }
578 /* show more info the first time around */ 560 /* show more info the first time around */
579 if (temp == seen_count) { 561 if (temp == seen_count) {
580 u32 scratch = hc32_to_cpup(fotg210, 562 u32 scratch = hc32_to_cpup(fotg210,
581 &hw->hw_info1); 563 &hw->hw_info1);
582 struct fotg210_qtd *qtd; 564 struct fotg210_qtd *qtd;
583 char *type = ""; 565 char *type = "";
584 566
585 /* count tds, get ep direction */ 567 /* count tds, get ep direction */
586 temp = 0; 568 temp = 0;
@@ -601,8 +583,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
601 } 583 }
602 584
603 temp = scnprintf(next, size, 585 temp = scnprintf(next, size,
604 "(%c%d ep%d%s " 586 "(%c%d ep%d%s [%d/%d] q%d p%d)",
605 "[%d/%d] q%d p%d)",
606 speed_char(scratch), 587 speed_char(scratch),
607 scratch & 0x007f, 588 scratch & 0x007f,
608 (scratch >> 8) & 0x000f, type, 589 (scratch >> 8) & 0x000f, type,
@@ -619,14 +600,14 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
619 break; 600 break;
620 case Q_TYPE_FSTN: 601 case Q_TYPE_FSTN:
621 temp = scnprintf(next, size, 602 temp = scnprintf(next, size,
622 " fstn-%8x/%p", p.fstn->hw_prev, 603 " fstn-%8x/%p",
623 p.fstn); 604 p.fstn->hw_prev, p.fstn);
624 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next); 605 tag = Q_NEXT_TYPE(fotg210, p.fstn->hw_next);
625 p = p.fstn->fstn_next; 606 p = p.fstn->fstn_next;
626 break; 607 break;
627 case Q_TYPE_ITD: 608 case Q_TYPE_ITD:
628 temp = scnprintf(next, size, 609 temp = scnprintf(next, size,
629 " itd/%p", p.itd); 610 " itd/%p", p.itd);
630 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next); 611 tag = Q_NEXT_TYPE(fotg210, p.itd->hw_next);
631 p = p.itd->itd_next; 612 p = p.itd->itd_next;
632 break; 613 break;
@@ -663,13 +644,13 @@ static const char *rh_state_string(struct fotg210_hcd *fotg210)
663 644
664static ssize_t fill_registers_buffer(struct debug_buffer *buf) 645static ssize_t fill_registers_buffer(struct debug_buffer *buf)
665{ 646{
666 struct usb_hcd *hcd; 647 struct usb_hcd *hcd;
667 struct fotg210_hcd *fotg210; 648 struct fotg210_hcd *fotg210;
668 unsigned long flags; 649 unsigned long flags;
669 unsigned temp, size, i; 650 unsigned temp, size, i;
670 char *next, scratch[80]; 651 char *next, scratch[80];
671 static const char fmt[] = "%*s\n"; 652 static const char fmt[] = "%*s\n";
672 static const char label[] = ""; 653 static const char label[] = "";
673 654
674 hcd = bus_to_hcd(buf->bus); 655 hcd = bus_to_hcd(buf->bus);
675 fotg210 = hcd_to_fotg210(hcd); 656 fotg210 = hcd_to_fotg210(hcd);
@@ -680,26 +661,26 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
680 661
681 if (!HCD_HW_ACCESSIBLE(hcd)) { 662 if (!HCD_HW_ACCESSIBLE(hcd)) {
682 size = scnprintf(next, size, 663 size = scnprintf(next, size,
683 "bus %s, device %s\n" 664 "bus %s, device %s\n"
684 "%s\n" 665 "%s\n"
685 "SUSPENDED(no register access)\n", 666 "SUSPENDED(no register access)\n",
686 hcd->self.controller->bus->name, 667 hcd->self.controller->bus->name,
687 dev_name(hcd->self.controller), 668 dev_name(hcd->self.controller),
688 hcd->product_desc); 669 hcd->product_desc);
689 goto done; 670 goto done;
690 } 671 }
691 672
692 /* Capability Registers */ 673 /* Capability Registers */
693 i = HC_VERSION(fotg210, fotg210_readl(fotg210, 674 i = HC_VERSION(fotg210, fotg210_readl(fotg210,
694 &fotg210->caps->hc_capbase)); 675 &fotg210->caps->hc_capbase));
695 temp = scnprintf(next, size, 676 temp = scnprintf(next, size,
696 "bus %s, device %s\n" 677 "bus %s, device %s\n"
697 "%s\n" 678 "%s\n"
698 "EHCI %x.%02x, rh state %s\n", 679 "EHCI %x.%02x, rh state %s\n",
699 hcd->self.controller->bus->name, 680 hcd->self.controller->bus->name,
700 dev_name(hcd->self.controller), 681 dev_name(hcd->self.controller),
701 hcd->product_desc, 682 hcd->product_desc,
702 i >> 8, i & 0x0ff, rh_state_string(fotg210)); 683 i >> 8, i & 0x0ff, rh_state_string(fotg210));
703 size -= temp; 684 size -= temp;
704 next += temp; 685 next += temp;
705 686
@@ -747,14 +728,14 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
747 728
748#ifdef FOTG210_STATS 729#ifdef FOTG210_STATS
749 temp = scnprintf(next, size, 730 temp = scnprintf(next, size,
750 "irq normal %ld err %ld iaa %ld(lost %ld)\n", 731 "irq normal %ld err %ld iaa %ld(lost %ld)\n",
751 fotg210->stats.normal, fotg210->stats.error, fotg210->stats.iaa, 732 fotg210->stats.normal, fotg210->stats.error,
752 fotg210->stats.lost_iaa); 733 fotg210->stats.iaa, fotg210->stats.lost_iaa);
753 size -= temp; 734 size -= temp;
754 next += temp; 735 next += temp;
755 736
756 temp = scnprintf(next, size, "complete %ld unlink %ld\n", 737 temp = scnprintf(next, size, "complete %ld unlink %ld\n",
757 fotg210->stats.complete, fotg210->stats.unlink); 738 fotg210->stats.complete, fotg210->stats.unlink);
758 size -= temp; 739 size -= temp;
759 next += temp; 740 next += temp;
760#endif 741#endif
@@ -765,8 +746,8 @@ done:
765 return buf->alloc_size - size; 746 return buf->alloc_size - size;
766} 747}
767 748
768static struct debug_buffer *alloc_buffer(struct usb_bus *bus, 749static struct debug_buffer
769 ssize_t (*fill_func)(struct debug_buffer *)) 750*alloc_buffer(struct usb_bus *bus, ssize_t (*fill_func)(struct debug_buffer *))
770{ 751{
771 struct debug_buffer *buf; 752 struct debug_buffer *buf;
772 753
@@ -806,7 +787,7 @@ out:
806} 787}
807 788
808static ssize_t debug_output(struct file *file, char __user *user_buf, 789static ssize_t debug_output(struct file *file, char __user *user_buf,
809 size_t len, loff_t *offset) 790 size_t len, loff_t *offset)
810{ 791{
811 struct debug_buffer *buf = file->private_data; 792 struct debug_buffer *buf = file->private_data;
812 int ret = 0; 793 int ret = 0;
@@ -822,7 +803,7 @@ static ssize_t debug_output(struct file *file, char __user *user_buf,
822 mutex_unlock(&buf->mutex); 803 mutex_unlock(&buf->mutex);
823 804
824 ret = simple_read_from_buffer(user_buf, len, offset, 805 ret = simple_read_from_buffer(user_buf, len, offset,
825 buf->output_buf, buf->count); 806 buf->output_buf, buf->count);
826 807
827out: 808out:
828 return ret; 809 return ret;
@@ -850,6 +831,7 @@ static int debug_async_open(struct inode *inode, struct file *file)
850static int debug_periodic_open(struct inode *inode, struct file *file) 831static int debug_periodic_open(struct inode *inode, struct file *file)
851{ 832{
852 struct debug_buffer *buf; 833 struct debug_buffer *buf;
834
853 buf = alloc_buffer(inode->i_private, fill_periodic_buffer); 835 buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
854 if (!buf) 836 if (!buf)
855 return -ENOMEM; 837 return -ENOMEM;
@@ -862,7 +844,7 @@ static int debug_periodic_open(struct inode *inode, struct file *file)
862static int debug_registers_open(struct inode *inode, struct file *file) 844static int debug_registers_open(struct inode *inode, struct file *file)
863{ 845{
864 file->private_data = alloc_buffer(inode->i_private, 846 file->private_data = alloc_buffer(inode->i_private,
865 fill_registers_buffer); 847 fill_registers_buffer);
866 848
867 return file->private_data ? 0 : -ENOMEM; 849 return file->private_data ? 0 : -ENOMEM;
868} 850}
@@ -872,20 +854,20 @@ static inline void create_debug_files(struct fotg210_hcd *fotg210)
872 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self; 854 struct usb_bus *bus = &fotg210_to_hcd(fotg210)->self;
873 855
874 fotg210->debug_dir = debugfs_create_dir(bus->bus_name, 856 fotg210->debug_dir = debugfs_create_dir(bus->bus_name,
875 fotg210_debug_root); 857 fotg210_debug_root);
876 if (!fotg210->debug_dir) 858 if (!fotg210->debug_dir)
877 return; 859 return;
878 860
879 if (!debugfs_create_file("async", S_IRUGO, fotg210->debug_dir, bus, 861 if (!debugfs_create_file("async", S_IRUGO, fotg210->debug_dir, bus,
880 &debug_async_fops)) 862 &debug_async_fops))
881 goto file_error; 863 goto file_error;
882 864
883 if (!debugfs_create_file("periodic", S_IRUGO, fotg210->debug_dir, bus, 865 if (!debugfs_create_file("periodic", S_IRUGO, fotg210->debug_dir, bus,
884 &debug_periodic_fops)) 866 &debug_periodic_fops))
885 goto file_error; 867 goto file_error;
886 868
887 if (!debugfs_create_file("registers", S_IRUGO, fotg210->debug_dir, bus, 869 if (!debugfs_create_file("registers", S_IRUGO, fotg210->debug_dir, bus,
888 &debug_registers_fops)) 870 &debug_registers_fops))
889 goto file_error; 871 goto file_error;
890 872
891 return; 873 return;
@@ -899,10 +881,7 @@ static inline void remove_debug_files(struct fotg210_hcd *fotg210)
899 debugfs_remove_recursive(fotg210->debug_dir); 881 debugfs_remove_recursive(fotg210->debug_dir);
900} 882}
901 883
902/*-------------------------------------------------------------------------*/ 884/* handshake - spin reading hc until handshake completes or fails
903
904/*
905 * handshake - spin reading hc until handshake completes or fails
906 * @ptr: address of hc register to be read 885 * @ptr: address of hc register to be read
907 * @mask: bits to look at in result of read 886 * @mask: bits to look at in result of read
908 * @done: value of those bits when handshake succeeds 887 * @done: value of those bits when handshake succeeds
@@ -919,9 +898,9 @@ static inline void remove_debug_files(struct fotg210_hcd *fotg210)
919 * bridge shutdown: shutting down the bridge before the devices using it. 898 * bridge shutdown: shutting down the bridge before the devices using it.
920 */ 899 */
921static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr, 900static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr,
922 u32 mask, u32 done, int usec) 901 u32 mask, u32 done, int usec)
923{ 902{
924 u32 result; 903 u32 result;
925 904
926 do { 905 do {
927 result = fotg210_readl(fotg210, ptr); 906 result = fotg210_readl(fotg210, ptr);
@@ -936,13 +915,12 @@ static int handshake(struct fotg210_hcd *fotg210, void __iomem *ptr,
936 return -ETIMEDOUT; 915 return -ETIMEDOUT;
937} 916}
938 917
939/* 918/* Force HC to halt state from unknown (EHCI spec section 2.3).
940 * Force HC to halt state from unknown (EHCI spec section 2.3).
941 * Must be called with interrupts enabled and the lock not held. 919 * Must be called with interrupts enabled and the lock not held.
942 */ 920 */
943static int fotg210_halt(struct fotg210_hcd *fotg210) 921static int fotg210_halt(struct fotg210_hcd *fotg210)
944{ 922{
945 u32 temp; 923 u32 temp;
946 924
947 spin_lock_irq(&fotg210->lock); 925 spin_lock_irq(&fotg210->lock);
948 926
@@ -962,20 +940,20 @@ static int fotg210_halt(struct fotg210_hcd *fotg210)
962 synchronize_irq(fotg210_to_hcd(fotg210)->irq); 940 synchronize_irq(fotg210_to_hcd(fotg210)->irq);
963 941
964 return handshake(fotg210, &fotg210->regs->status, 942 return handshake(fotg210, &fotg210->regs->status,
965 STS_HALT, STS_HALT, 16 * 125); 943 STS_HALT, STS_HALT, 16 * 125);
966} 944}
967 945
968/* 946/* Reset a non-running (STS_HALT == 1) controller.
969 * Reset a non-running (STS_HALT == 1) controller.
970 * Must be called with interrupts enabled and the lock not held. 947 * Must be called with interrupts enabled and the lock not held.
971 */ 948 */
972static int fotg210_reset(struct fotg210_hcd *fotg210) 949static int fotg210_reset(struct fotg210_hcd *fotg210)
973{ 950{
974 int retval; 951 int retval;
975 u32 command = fotg210_readl(fotg210, &fotg210->regs->command); 952 u32 command = fotg210_readl(fotg210, &fotg210->regs->command);
976 953
977 /* If the EHCI debug controller is active, special care must be 954 /* If the EHCI debug controller is active, special care must be
978 * taken before and after a host controller reset */ 955 * taken before and after a host controller reset
956 */
979 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210))) 957 if (fotg210->debug && !dbgp_reset_prep(fotg210_to_hcd(fotg210)))
980 fotg210->debug = NULL; 958 fotg210->debug = NULL;
981 959
@@ -985,7 +963,7 @@ static int fotg210_reset(struct fotg210_hcd *fotg210)
985 fotg210->rh_state = FOTG210_RH_HALTED; 963 fotg210->rh_state = FOTG210_RH_HALTED;
986 fotg210->next_statechange = jiffies; 964 fotg210->next_statechange = jiffies;
987 retval = handshake(fotg210, &fotg210->regs->command, 965 retval = handshake(fotg210, &fotg210->regs->command,
988 CMD_RESET, 0, 250 * 1000); 966 CMD_RESET, 0, 250 * 1000);
989 967
990 if (retval) 968 if (retval)
991 return retval; 969 return retval;
@@ -998,13 +976,12 @@ static int fotg210_reset(struct fotg210_hcd *fotg210)
998 return retval; 976 return retval;
999} 977}
1000 978
1001/* 979/* Idle the controller (turn off the schedules).
1002 * Idle the controller (turn off the schedules).
1003 * Must be called with interrupts enabled and the lock not held. 980 * Must be called with interrupts enabled and the lock not held.
1004 */ 981 */
1005static void fotg210_quiesce(struct fotg210_hcd *fotg210) 982static void fotg210_quiesce(struct fotg210_hcd *fotg210)
1006{ 983{
1007 u32 temp; 984 u32 temp;
1008 985
1009 if (fotg210->rh_state != FOTG210_RH_RUNNING) 986 if (fotg210->rh_state != FOTG210_RH_RUNNING)
1010 return; 987 return;
@@ -1012,7 +989,7 @@ static void fotg210_quiesce(struct fotg210_hcd *fotg210)
1012 /* wait for any schedule enables/disables to take effect */ 989 /* wait for any schedule enables/disables to take effect */
1013 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS); 990 temp = (fotg210->command << 10) & (STS_ASS | STS_PSS);
1014 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp, 991 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, temp,
1015 16 * 125); 992 16 * 125);
1016 993
1017 /* then disable anything that's still active */ 994 /* then disable anything that's still active */
1018 spin_lock_irq(&fotg210->lock); 995 spin_lock_irq(&fotg210->lock);
@@ -1022,11 +999,9 @@ static void fotg210_quiesce(struct fotg210_hcd *fotg210)
1022 999
1023 /* hardware can take 16 microframes to turn off ... */ 1000 /* hardware can take 16 microframes to turn off ... */
1024 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0, 1001 handshake(fotg210, &fotg210->regs->status, STS_ASS | STS_PSS, 0,
1025 16 * 125); 1002 16 * 125);
1026} 1003}
1027 1004
1028/*-------------------------------------------------------------------------*/
1029
1030static void end_unlink_async(struct fotg210_hcd *fotg210); 1005static void end_unlink_async(struct fotg210_hcd *fotg210);
1031static void unlink_empty_async(struct fotg210_hcd *fotg210); 1006static void unlink_empty_async(struct fotg210_hcd *fotg210);
1032static void fotg210_work(struct fotg210_hcd *fotg210); 1007static void fotg210_work(struct fotg210_hcd *fotg210);
@@ -1034,8 +1009,6 @@ static void start_unlink_intr(struct fotg210_hcd *fotg210,
1034 struct fotg210_qh *qh); 1009 struct fotg210_qh *qh);
1035static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh); 1010static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
1036 1011
1037/*-------------------------------------------------------------------------*/
1038
1039/* Set a bit in the USBCMD register */ 1012/* Set a bit in the USBCMD register */
1040static void fotg210_set_command_bit(struct fotg210_hcd *fotg210, u32 bit) 1013static void fotg210_set_command_bit(struct fotg210_hcd *fotg210, u32 bit)
1041{ 1014{
@@ -1056,10 +1029,7 @@ static void fotg210_clear_command_bit(struct fotg210_hcd *fotg210, u32 bit)
1056 fotg210_readl(fotg210, &fotg210->regs->command); 1029 fotg210_readl(fotg210, &fotg210->regs->command);
1057} 1030}
1058 1031
1059/*-------------------------------------------------------------------------*/ 1032/* EHCI timer support... Now using hrtimers.
1060
1061/*
1062 * EHCI timer support... Now using hrtimers.
1063 * 1033 *
1064 * Lots of different events are triggered from fotg210->hrtimer. Whenever 1034 * Lots of different events are triggered from fotg210->hrtimer. Whenever
1065 * the timer routine runs, it checks each possible event; events that are 1035 * the timer routine runs, it checks each possible event; events that are
@@ -1081,8 +1051,7 @@ static void fotg210_clear_command_bit(struct fotg210_hcd *fotg210, u32 bit)
1081 * allow for an expiration range of 1 ms. 1051 * allow for an expiration range of 1 ms.
1082 */ 1052 */
1083 1053
1084/* 1054/* Delay lengths for the hrtimer event types.
1085 * Delay lengths for the hrtimer event types.
1086 * Keep this list sorted by delay length, in the same order as 1055 * Keep this list sorted by delay length, in the same order as
1087 * the event types indexed by enum fotg210_hrtimer_event in fotg210.h. 1056 * the event types indexed by enum fotg210_hrtimer_event in fotg210.h.
1088 */ 1057 */
@@ -1103,7 +1072,7 @@ static unsigned event_delays_ns[] = {
1103static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event, 1072static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event,
1104 bool resched) 1073 bool resched)
1105{ 1074{
1106 ktime_t *timeout = &fotg210->hr_timeouts[event]; 1075 ktime_t *timeout = &fotg210->hr_timeouts[event];
1107 1076
1108 if (resched) 1077 if (resched)
1109 *timeout = ktime_add(ktime_get(), 1078 *timeout = ktime_add(ktime_get(),
@@ -1122,7 +1091,7 @@ static void fotg210_enable_event(struct fotg210_hcd *fotg210, unsigned event,
1122/* Poll the STS_ASS status bit; see when it agrees with CMD_ASE */ 1091/* Poll the STS_ASS status bit; see when it agrees with CMD_ASE */
1123static void fotg210_poll_ASS(struct fotg210_hcd *fotg210) 1092static void fotg210_poll_ASS(struct fotg210_hcd *fotg210)
1124{ 1093{
1125 unsigned actual, want; 1094 unsigned actual, want;
1126 1095
1127 /* Don't enable anything if the controller isn't running (e.g., died) */ 1096 /* Don't enable anything if the controller isn't running (e.g., died) */
1128 if (fotg210->rh_state != FOTG210_RH_RUNNING) 1097 if (fotg210->rh_state != FOTG210_RH_RUNNING)
@@ -1136,7 +1105,7 @@ static void fotg210_poll_ASS(struct fotg210_hcd *fotg210)
1136 /* Poll again later, but give up after about 20 ms */ 1105 /* Poll again later, but give up after about 20 ms */
1137 if (fotg210->ASS_poll_count++ < 20) { 1106 if (fotg210->ASS_poll_count++ < 20) {
1138 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_ASS, 1107 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_ASS,
1139 true); 1108 true);
1140 return; 1109 return;
1141 } 1110 }
1142 fotg210_dbg(fotg210, "Waited too long for the async schedule status (%x/%x), giving up\n", 1111 fotg210_dbg(fotg210, "Waited too long for the async schedule status (%x/%x), giving up\n",
@@ -1154,8 +1123,8 @@ static void fotg210_poll_ASS(struct fotg210_hcd *fotg210)
1154 1123
1155 /* Turn off the schedule after a while */ 1124 /* Turn off the schedule after a while */
1156 fotg210_enable_event(fotg210, 1125 fotg210_enable_event(fotg210,
1157 FOTG210_HRTIMER_DISABLE_ASYNC, 1126 FOTG210_HRTIMER_DISABLE_ASYNC,
1158 true); 1127 true);
1159 } 1128 }
1160 } 1129 }
1161} 1130}
@@ -1170,7 +1139,7 @@ static void fotg210_disable_ASE(struct fotg210_hcd *fotg210)
1170/* Poll the STS_PSS status bit; see when it agrees with CMD_PSE */ 1139/* Poll the STS_PSS status bit; see when it agrees with CMD_PSE */
1171static void fotg210_poll_PSS(struct fotg210_hcd *fotg210) 1140static void fotg210_poll_PSS(struct fotg210_hcd *fotg210)
1172{ 1141{
1173 unsigned actual, want; 1142 unsigned actual, want;
1174 1143
1175 /* Don't do anything if the controller isn't running (e.g., died) */ 1144 /* Don't do anything if the controller isn't running (e.g., died) */
1176 if (fotg210->rh_state != FOTG210_RH_RUNNING) 1145 if (fotg210->rh_state != FOTG210_RH_RUNNING)
@@ -1184,7 +1153,7 @@ static void fotg210_poll_PSS(struct fotg210_hcd *fotg210)
1184 /* Poll again later, but give up after about 20 ms */ 1153 /* Poll again later, but give up after about 20 ms */
1185 if (fotg210->PSS_poll_count++ < 20) { 1154 if (fotg210->PSS_poll_count++ < 20) {
1186 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_PSS, 1155 fotg210_enable_event(fotg210, FOTG210_HRTIMER_POLL_PSS,
1187 true); 1156 true);
1188 return; 1157 return;
1189 } 1158 }
1190 fotg210_dbg(fotg210, "Waited too long for the periodic schedule status (%x/%x), giving up\n", 1159 fotg210_dbg(fotg210, "Waited too long for the periodic schedule status (%x/%x), giving up\n",
@@ -1202,8 +1171,8 @@ static void fotg210_poll_PSS(struct fotg210_hcd *fotg210)
1202 1171
1203 /* Turn off the schedule after a while */ 1172 /* Turn off the schedule after a while */
1204 fotg210_enable_event(fotg210, 1173 fotg210_enable_event(fotg210,
1205 FOTG210_HRTIMER_DISABLE_PERIODIC, 1174 FOTG210_HRTIMER_DISABLE_PERIODIC,
1206 true); 1175 true);
1207 } 1176 }
1208 } 1177 }
1209} 1178}
@@ -1224,7 +1193,7 @@ static void fotg210_handle_controller_death(struct fotg210_hcd *fotg210)
1224 if (fotg210->died_poll_count++ < 5) { 1193 if (fotg210->died_poll_count++ < 5) {
1225 /* Try again later */ 1194 /* Try again later */
1226 fotg210_enable_event(fotg210, 1195 fotg210_enable_event(fotg210,
1227 FOTG210_HRTIMER_POLL_DEAD, true); 1196 FOTG210_HRTIMER_POLL_DEAD, true);
1228 return; 1197 return;
1229 } 1198 }
1230 fotg210_warn(fotg210, "Waited too long for the controller to stop, giving up\n"); 1199 fotg210_warn(fotg210, "Waited too long for the controller to stop, giving up\n");
@@ -1243,7 +1212,7 @@ static void fotg210_handle_controller_death(struct fotg210_hcd *fotg210)
1243/* Handle unlinked interrupt QHs once they are gone from the hardware */ 1212/* Handle unlinked interrupt QHs once they are gone from the hardware */
1244static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210) 1213static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210)
1245{ 1214{
1246 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING); 1215 bool stopped = (fotg210->rh_state < FOTG210_RH_RUNNING);
1247 1216
1248 /* 1217 /*
1249 * Process all the QHs on the intr_unlink list that were added 1218 * Process all the QHs on the intr_unlink list that were added
@@ -1254,7 +1223,7 @@ static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210)
1254 */ 1223 */
1255 fotg210->intr_unlinking = true; 1224 fotg210->intr_unlinking = true;
1256 while (fotg210->intr_unlink) { 1225 while (fotg210->intr_unlink) {
1257 struct fotg210_qh *qh = fotg210->intr_unlink; 1226 struct fotg210_qh *qh = fotg210->intr_unlink;
1258 1227
1259 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle) 1228 if (!stopped && qh->unlink_cycle == fotg210->intr_unlink_cycle)
1260 break; 1229 break;
@@ -1266,7 +1235,7 @@ static void fotg210_handle_intr_unlinks(struct fotg210_hcd *fotg210)
1266 /* Handle remaining entries later */ 1235 /* Handle remaining entries later */
1267 if (fotg210->intr_unlink) { 1236 if (fotg210->intr_unlink) {
1268 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR, 1237 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR,
1269 true); 1238 true);
1270 ++fotg210->intr_unlink_cycle; 1239 ++fotg210->intr_unlink_cycle;
1271 } 1240 }
1272 fotg210->intr_unlinking = false; 1241 fotg210->intr_unlinking = false;
@@ -1288,7 +1257,7 @@ static void start_free_itds(struct fotg210_hcd *fotg210)
1288/* Wait for controller to stop using old iTDs and siTDs */ 1257/* Wait for controller to stop using old iTDs and siTDs */
1289static void end_free_itds(struct fotg210_hcd *fotg210) 1258static void end_free_itds(struct fotg210_hcd *fotg210)
1290{ 1259{
1291 struct fotg210_itd *itd, *n; 1260 struct fotg210_itd *itd, *n;
1292 1261
1293 if (fotg210->rh_state < FOTG210_RH_RUNNING) 1262 if (fotg210->rh_state < FOTG210_RH_RUNNING)
1294 fotg210->last_itd_to_free = NULL; 1263 fotg210->last_itd_to_free = NULL;
@@ -1339,7 +1308,7 @@ static void fotg210_iaa_watchdog(struct fotg210_hcd *fotg210)
1339 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) { 1308 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
1340 COUNT(fotg210->stats.lost_iaa); 1309 COUNT(fotg210->stats.lost_iaa);
1341 fotg210_writel(fotg210, STS_IAA, 1310 fotg210_writel(fotg210, STS_IAA,
1342 &fotg210->regs->status); 1311 &fotg210->regs->status);
1343 } 1312 }
1344 1313
1345 fotg210_dbg(fotg210, "IAA watchdog: status %x cmd %x\n", 1314 fotg210_dbg(fotg210, "IAA watchdog: status %x cmd %x\n",
@@ -1355,7 +1324,7 @@ static void turn_on_io_watchdog(struct fotg210_hcd *fotg210)
1355 /* Not needed if the controller isn't running or it's already enabled */ 1324 /* Not needed if the controller isn't running or it's already enabled */
1356 if (fotg210->rh_state != FOTG210_RH_RUNNING || 1325 if (fotg210->rh_state != FOTG210_RH_RUNNING ||
1357 (fotg210->enabled_hrtimer_events & 1326 (fotg210->enabled_hrtimer_events &
1358 BIT(FOTG210_HRTIMER_IO_WATCHDOG))) 1327 BIT(FOTG210_HRTIMER_IO_WATCHDOG)))
1359 return; 1328 return;
1360 1329
1361 /* 1330 /*
@@ -1365,12 +1334,11 @@ static void turn_on_io_watchdog(struct fotg210_hcd *fotg210)
1365 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog && 1334 if (fotg210->isoc_count > 0 || (fotg210->need_io_watchdog &&
1366 fotg210->async_count + fotg210->intr_count > 0)) 1335 fotg210->async_count + fotg210->intr_count > 0))
1367 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IO_WATCHDOG, 1336 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IO_WATCHDOG,
1368 true); 1337 true);
1369} 1338}
1370 1339
1371 1340
1372/* 1341/* Handler functions for the hrtimer event types.
1373 * Handler functions for the hrtimer event types.
1374 * Keep this array in the same order as the event types indexed by 1342 * Keep this array in the same order as the event types indexed by
1375 * enum fotg210_hrtimer_event in fotg210.h. 1343 * enum fotg210_hrtimer_event in fotg210.h.
1376 */ 1344 */
@@ -1391,10 +1359,10 @@ static enum hrtimer_restart fotg210_hrtimer_func(struct hrtimer *t)
1391{ 1359{
1392 struct fotg210_hcd *fotg210 = 1360 struct fotg210_hcd *fotg210 =
1393 container_of(t, struct fotg210_hcd, hrtimer); 1361 container_of(t, struct fotg210_hcd, hrtimer);
1394 ktime_t now; 1362 ktime_t now;
1395 unsigned long events; 1363 unsigned long events;
1396 unsigned long flags; 1364 unsigned long flags;
1397 unsigned e; 1365 unsigned e;
1398 1366
1399 spin_lock_irqsave(&fotg210->lock, flags); 1367 spin_lock_irqsave(&fotg210->lock, flags);
1400 1368
@@ -1418,19 +1386,12 @@ static enum hrtimer_restart fotg210_hrtimer_func(struct hrtimer *t)
1418 return HRTIMER_NORESTART; 1386 return HRTIMER_NORESTART;
1419} 1387}
1420 1388
1421/*-------------------------------------------------------------------------*/ 1389#define fotg210_bus_suspend NULL
1422 1390#define fotg210_bus_resume NULL
1423#define fotg210_bus_suspend NULL
1424#define fotg210_bus_resume NULL
1425
1426/*-------------------------------------------------------------------------*/
1427 1391
1428static int check_reset_complete( 1392static int check_reset_complete(struct fotg210_hcd *fotg210, int index,
1429 struct fotg210_hcd *fotg210, 1393 u32 __iomem *status_reg, int port_status)
1430 int index, 1394{
1431 u32 __iomem *status_reg,
1432 int port_status
1433) {
1434 if (!(port_status & PORT_CONNECT)) 1395 if (!(port_status & PORT_CONNECT))
1435 return port_status; 1396 return port_status;
1436 1397
@@ -1438,30 +1399,27 @@ static int check_reset_complete(
1438 if (!(port_status & PORT_PE)) { 1399 if (!(port_status & PORT_PE)) {
1439 /* with integrated TT, there's nobody to hand it to! */ 1400 /* with integrated TT, there's nobody to hand it to! */
1440 fotg210_dbg(fotg210, 1401 fotg210_dbg(fotg210,
1441 "Failed to enable port %d on root hub TT\n", 1402 "Failed to enable port %d on root hub TT\n",
1442 index+1); 1403 index + 1);
1443 return port_status; 1404 return port_status;
1444 } else { 1405 } else {
1445 fotg210_dbg(fotg210, "port %d reset complete, port enabled\n", 1406 fotg210_dbg(fotg210, "port %d reset complete, port enabled\n",
1446 index + 1); 1407 index + 1);
1447 } 1408 }
1448 1409
1449 return port_status; 1410 return port_status;
1450} 1411}
1451 1412
1452/*-------------------------------------------------------------------------*/
1453
1454 1413
1455/* build "status change" packet (one or two bytes) from HC registers */ 1414/* build "status change" packet (one or two bytes) from HC registers */
1456 1415
1457static int 1416static int fotg210_hub_status_data(struct usb_hcd *hcd, char *buf)
1458fotg210_hub_status_data(struct usb_hcd *hcd, char *buf)
1459{ 1417{
1460 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 1418 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1461 u32 temp, status; 1419 u32 temp, status;
1462 u32 mask; 1420 u32 mask;
1463 int retval = 1; 1421 int retval = 1;
1464 unsigned long flags; 1422 unsigned long flags;
1465 1423
1466 /* init status to no-changes */ 1424 /* init status to no-changes */
1467 buf[0] = 0; 1425 buf[0] = 0;
@@ -1488,9 +1446,9 @@ fotg210_hub_status_data(struct usb_hcd *hcd, char *buf)
1488 * controller by the user. 1446 * controller by the user.
1489 */ 1447 */
1490 1448
1491 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) 1449 if ((temp & mask) != 0 || test_bit(0, &fotg210->port_c_suspend) ||
1492 || (fotg210->reset_done[0] && time_after_eq( 1450 (fotg210->reset_done[0] &&
1493 jiffies, fotg210->reset_done[0]))) { 1451 time_after_eq(jiffies, fotg210->reset_done[0]))) {
1494 buf[0] |= 1 << 1; 1452 buf[0] |= 1 << 1;
1495 status = STS_PCD; 1453 status = STS_PCD;
1496 } 1454 }
@@ -1499,15 +1457,11 @@ fotg210_hub_status_data(struct usb_hcd *hcd, char *buf)
1499 return status ? retval : 0; 1457 return status ? retval : 0;
1500} 1458}
1501 1459
1502/*-------------------------------------------------------------------------*/ 1460static void fotg210_hub_descriptor(struct fotg210_hcd *fotg210,
1503 1461 struct usb_hub_descriptor *desc)
1504static void 1462{
1505fotg210_hub_descriptor( 1463 int ports = HCS_N_PORTS(fotg210->hcs_params);
1506 struct fotg210_hcd *fotg210, 1464 u16 temp;
1507 struct usb_hub_descriptor *desc
1508) {
1509 int ports = HCS_N_PORTS(fotg210->hcs_params);
1510 u16 temp;
1511 1465
1512 desc->bDescriptorType = USB_DT_HUB; 1466 desc->bDescriptorType = USB_DT_HUB;
1513 desc->bPwrOn2PwrGood = 10; /* fotg210 1.0, 2.3.9 says 20ms max */ 1467 desc->bPwrOn2PwrGood = 10; /* fotg210 1.0, 2.3.9 says 20ms max */
@@ -1526,23 +1480,16 @@ fotg210_hub_descriptor(
1526 desc->wHubCharacteristics = cpu_to_le16(temp); 1480 desc->wHubCharacteristics = cpu_to_le16(temp);
1527} 1481}
1528 1482
1529/*-------------------------------------------------------------------------*/ 1483static int fotg210_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1530 1484 u16 wIndex, char *buf, u16 wLength)
1531static int fotg210_hub_control( 1485{
1532 struct usb_hcd *hcd, 1486 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1533 u16 typeReq, 1487 int ports = HCS_N_PORTS(fotg210->hcs_params);
1534 u16 wValue, 1488 u32 __iomem *status_reg = &fotg210->regs->port_status;
1535 u16 wIndex, 1489 u32 temp, temp1, status;
1536 char *buf, 1490 unsigned long flags;
1537 u16 wLength 1491 int retval = 0;
1538) { 1492 unsigned selector;
1539 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
1540 int ports = HCS_N_PORTS(fotg210->hcs_params);
1541 u32 __iomem *status_reg = &fotg210->regs->port_status;
1542 u32 temp, temp1, status;
1543 unsigned long flags;
1544 int retval = 0;
1545 unsigned selector;
1546 1493
1547 /* 1494 /*
1548 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR. 1495 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
@@ -1605,7 +1552,7 @@ static int fotg210_hub_control(
1605 break; 1552 break;
1606 case USB_PORT_FEAT_C_OVER_CURRENT: 1553 case USB_PORT_FEAT_C_OVER_CURRENT:
1607 fotg210_writel(fotg210, temp | OTGISR_OVC, 1554 fotg210_writel(fotg210, temp | OTGISR_OVC,
1608 &fotg210->regs->otgisr); 1555 &fotg210->regs->otgisr);
1609 break; 1556 break;
1610 case USB_PORT_FEAT_C_RESET: 1557 case USB_PORT_FEAT_C_RESET:
1611 /* GetPortStatus clears reset */ 1558 /* GetPortStatus clears reset */
@@ -1617,7 +1564,7 @@ static int fotg210_hub_control(
1617 break; 1564 break;
1618 case GetHubDescriptor: 1565 case GetHubDescriptor:
1619 fotg210_hub_descriptor(fotg210, (struct usb_hub_descriptor *) 1566 fotg210_hub_descriptor(fotg210, (struct usb_hub_descriptor *)
1620 buf); 1567 buf);
1621 break; 1568 break;
1622 case GetHubStatus: 1569 case GetHubStatus:
1623 /* no hub-wide feature/status flags */ 1570 /* no hub-wide feature/status flags */
@@ -1663,16 +1610,16 @@ static int fotg210_hub_control(
1663 1610
1664 /* stop resume signaling */ 1611 /* stop resume signaling */
1665 temp = fotg210_readl(fotg210, status_reg); 1612 temp = fotg210_readl(fotg210, status_reg);
1666 fotg210_writel(fotg210, 1613 fotg210_writel(fotg210, temp &
1667 temp & ~(PORT_RWC_BITS | PORT_RESUME), 1614 ~(PORT_RWC_BITS | PORT_RESUME),
1668 status_reg); 1615 status_reg);
1669 clear_bit(wIndex, &fotg210->resuming_ports); 1616 clear_bit(wIndex, &fotg210->resuming_ports);
1670 retval = handshake(fotg210, status_reg, 1617 retval = handshake(fotg210, status_reg,
1671 PORT_RESUME, 0, 2000 /* 2msec */); 1618 PORT_RESUME, 0, 2000);/* 2ms */
1672 if (retval != 0) { 1619 if (retval != 0) {
1673 fotg210_err(fotg210, 1620 fotg210_err(fotg210,
1674 "port %d resume error %d\n", 1621 "port %d resume error %d\n",
1675 wIndex + 1, retval); 1622 wIndex + 1, retval);
1676 goto error; 1623 goto error;
1677 } 1624 }
1678 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); 1625 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
@@ -1680,17 +1627,16 @@ static int fotg210_hub_control(
1680 } 1627 }
1681 1628
1682 /* whoever resets must GetPortStatus to complete it!! */ 1629 /* whoever resets must GetPortStatus to complete it!! */
1683 if ((temp & PORT_RESET) 1630 if ((temp & PORT_RESET) && time_after_eq(jiffies,
1684 && time_after_eq(jiffies, 1631 fotg210->reset_done[wIndex])) {
1685 fotg210->reset_done[wIndex])) {
1686 status |= USB_PORT_STAT_C_RESET << 16; 1632 status |= USB_PORT_STAT_C_RESET << 16;
1687 fotg210->reset_done[wIndex] = 0; 1633 fotg210->reset_done[wIndex] = 0;
1688 clear_bit(wIndex, &fotg210->resuming_ports); 1634 clear_bit(wIndex, &fotg210->resuming_ports);
1689 1635
1690 /* force reset to complete */ 1636 /* force reset to complete */
1691 fotg210_writel(fotg210, 1637 fotg210_writel(fotg210,
1692 temp & ~(PORT_RWC_BITS | PORT_RESET), 1638 temp & ~(PORT_RWC_BITS | PORT_RESET),
1693 status_reg); 1639 status_reg);
1694 /* REVISIT: some hardware needs 550+ usec to clear 1640 /* REVISIT: some hardware needs 550+ usec to clear
1695 * this bit; seems too long to spin routinely... 1641 * this bit; seems too long to spin routinely...
1696 */ 1642 */
@@ -1698,7 +1644,7 @@ static int fotg210_hub_control(
1698 PORT_RESET, 0, 1000); 1644 PORT_RESET, 0, 1000);
1699 if (retval != 0) { 1645 if (retval != 0) {
1700 fotg210_err(fotg210, "port %d reset error %d\n", 1646 fotg210_err(fotg210, "port %d reset error %d\n",
1701 wIndex + 1, retval); 1647 wIndex + 1, retval);
1702 goto error; 1648 goto error;
1703 } 1649 }
1704 1650
@@ -1718,7 +1664,7 @@ static int fotg210_hub_control(
1718 temp &= ~PORT_RWC_BITS; 1664 temp &= ~PORT_RWC_BITS;
1719 fotg210_writel(fotg210, temp, status_reg); 1665 fotg210_writel(fotg210, temp, status_reg);
1720 fotg210_dbg(fotg210, "port %d --> companion\n", 1666 fotg210_dbg(fotg210, "port %d --> companion\n",
1721 wIndex + 1); 1667 wIndex + 1);
1722 temp = fotg210_readl(fotg210, status_reg); 1668 temp = fotg210_readl(fotg210, status_reg);
1723 } 1669 }
1724 1670
@@ -1788,7 +1734,7 @@ static int fotg210_hub_control(
1788 * mode if we have hostpc feature 1734 * mode if we have hostpc feature
1789 */ 1735 */
1790 fotg210_writel(fotg210, temp | PORT_SUSPEND, 1736 fotg210_writel(fotg210, temp | PORT_SUSPEND,
1791 status_reg); 1737 status_reg);
1792 set_bit(wIndex, &fotg210->suspended_ports); 1738 set_bit(wIndex, &fotg210->suspended_ports);
1793 break; 1739 break;
1794 case USB_PORT_FEAT_RESET: 1740 case USB_PORT_FEAT_RESET:
@@ -1866,9 +1812,8 @@ static int __maybe_unused fotg210_port_handed_over(struct usb_hcd *hcd,
1866{ 1812{
1867 return 0; 1813 return 0;
1868} 1814}
1869/*-------------------------------------------------------------------------*/ 1815
1870/* 1816/* There's basically three types of memory:
1871 * There's basically three types of memory:
1872 * - data used only by the HCD ... kmalloc is fine 1817 * - data used only by the HCD ... kmalloc is fine
1873 * - async and periodic schedules, shared by HC and HCD ... these 1818 * - async and periodic schedules, shared by HC and HCD ... these
1874 * need to use dma_pool or dma_alloc_coherent 1819 * need to use dma_pool or dma_alloc_coherent
@@ -1878,12 +1823,9 @@ static int __maybe_unused fotg210_port_handed_over(struct usb_hcd *hcd,
1878 * No memory seen by this driver is pageable. 1823 * No memory seen by this driver is pageable.
1879 */ 1824 */
1880 1825
1881/*-------------------------------------------------------------------------*/
1882
1883/* Allocate the key transfer structures from the previously allocated pool */ 1826/* Allocate the key transfer structures from the previously allocated pool */
1884
1885static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210, 1827static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210,
1886 struct fotg210_qtd *qtd, dma_addr_t dma) 1828 struct fotg210_qtd *qtd, dma_addr_t dma)
1887{ 1829{
1888 memset(qtd, 0, sizeof(*qtd)); 1830 memset(qtd, 0, sizeof(*qtd));
1889 qtd->qtd_dma = dma; 1831 qtd->qtd_dma = dma;
@@ -1894,10 +1836,10 @@ static inline void fotg210_qtd_init(struct fotg210_hcd *fotg210,
1894} 1836}
1895 1837
1896static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210, 1838static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210,
1897 gfp_t flags) 1839 gfp_t flags)
1898{ 1840{
1899 struct fotg210_qtd *qtd; 1841 struct fotg210_qtd *qtd;
1900 dma_addr_t dma; 1842 dma_addr_t dma;
1901 1843
1902 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma); 1844 qtd = dma_pool_alloc(fotg210->qtd_pool, flags, &dma);
1903 if (qtd != NULL) 1845 if (qtd != NULL)
@@ -1907,7 +1849,7 @@ static struct fotg210_qtd *fotg210_qtd_alloc(struct fotg210_hcd *fotg210,
1907} 1849}
1908 1850
1909static inline void fotg210_qtd_free(struct fotg210_hcd *fotg210, 1851static inline void fotg210_qtd_free(struct fotg210_hcd *fotg210,
1910 struct fotg210_qtd *qtd) 1852 struct fotg210_qtd *qtd)
1911{ 1853{
1912 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma); 1854 dma_pool_free(fotg210->qtd_pool, qtd, qtd->qtd_dma);
1913} 1855}
@@ -1927,10 +1869,10 @@ static void qh_destroy(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
1927} 1869}
1928 1870
1929static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210, 1871static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210,
1930 gfp_t flags) 1872 gfp_t flags)
1931{ 1873{
1932 struct fotg210_qh *qh; 1874 struct fotg210_qh *qh;
1933 dma_addr_t dma; 1875 dma_addr_t dma;
1934 1876
1935 qh = kzalloc(sizeof(*qh), GFP_ATOMIC); 1877 qh = kzalloc(sizeof(*qh), GFP_ATOMIC);
1936 if (!qh) 1878 if (!qh)
@@ -1958,8 +1900,6 @@ fail:
1958 return NULL; 1900 return NULL;
1959} 1901}
1960 1902
1961/*-------------------------------------------------------------------------*/
1962
1963/* The queue heads and transfer descriptors are managed from pools tied 1903/* The queue heads and transfer descriptors are managed from pools tied
1964 * to each of the "per device" structures. 1904 * to each of the "per device" structures.
1965 * This is the initialisation and cleanup code. 1905 * This is the initialisation and cleanup code.
@@ -1987,8 +1927,8 @@ static void fotg210_mem_cleanup(struct fotg210_hcd *fotg210)
1987 1927
1988 if (fotg210->periodic) 1928 if (fotg210->periodic)
1989 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller, 1929 dma_free_coherent(fotg210_to_hcd(fotg210)->self.controller,
1990 fotg210->periodic_size * sizeof(u32), 1930 fotg210->periodic_size * sizeof(u32),
1991 fotg210->periodic, fotg210->periodic_dma); 1931 fotg210->periodic, fotg210->periodic_dma);
1992 fotg210->periodic = NULL; 1932 fotg210->periodic = NULL;
1993 1933
1994 /* shadow periodic table */ 1934 /* shadow periodic table */
@@ -2035,8 +1975,8 @@ static int fotg210_mem_init(struct fotg210_hcd *fotg210, gfp_t flags)
2035 /* Hardware periodic table */ 1975 /* Hardware periodic table */
2036 fotg210->periodic = (__le32 *) 1976 fotg210->periodic = (__le32 *)
2037 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller, 1977 dma_alloc_coherent(fotg210_to_hcd(fotg210)->self.controller,
2038 fotg210->periodic_size * sizeof(__le32), 1978 fotg210->periodic_size * sizeof(__le32),
2039 &fotg210->periodic_dma, 0); 1979 &fotg210->periodic_dma, 0);
2040 if (fotg210->periodic == NULL) 1980 if (fotg210->periodic == NULL)
2041 goto fail; 1981 goto fail;
2042 1982
@@ -2045,7 +1985,7 @@ static int fotg210_mem_init(struct fotg210_hcd *fotg210, gfp_t flags)
2045 1985
2046 /* software shadow of hardware table */ 1986 /* software shadow of hardware table */
2047 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *), 1987 fotg210->pshadow = kcalloc(fotg210->periodic_size, sizeof(void *),
2048 flags); 1988 flags);
2049 if (fotg210->pshadow != NULL) 1989 if (fotg210->pshadow != NULL)
2050 return 0; 1990 return 0;
2051 1991
@@ -2054,9 +1994,7 @@ fail:
2054 fotg210_mem_cleanup(fotg210); 1994 fotg210_mem_cleanup(fotg210);
2055 return -ENOMEM; 1995 return -ENOMEM;
2056} 1996}
2057/*-------------------------------------------------------------------------*/ 1997/* EHCI hardware queue manipulation ... the core. QH/QTD manipulation.
2058/*
2059 * EHCI hardware queue manipulation ... the core. QH/QTD manipulation.
2060 * 1998 *
2061 * Control, bulk, and interrupt traffic all use "qh" lists. They list "qtd" 1999 * Control, bulk, and interrupt traffic all use "qh" lists. They list "qtd"
2062 * entries describing USB transactions, max 16-20kB/entry (with 4kB-aligned 2000 * entries describing USB transactions, max 16-20kB/entry (with 4kB-aligned
@@ -2073,16 +2011,12 @@ fail:
2073 * buffer low/full speed data so the host collects it at high speed. 2011 * buffer low/full speed data so the host collects it at high speed.
2074 */ 2012 */
2075 2013
2076/*-------------------------------------------------------------------------*/
2077
2078/* fill a qtd, returning how much of the buffer we were able to queue up */ 2014/* fill a qtd, returning how much of the buffer we were able to queue up */
2079 2015static int qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd,
2080static int 2016 dma_addr_t buf, size_t len, int token, int maxpacket)
2081qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd, dma_addr_t buf,
2082 size_t len, int token, int maxpacket)
2083{ 2017{
2084 int i, count; 2018 int i, count;
2085 u64 addr = buf; 2019 u64 addr = buf;
2086 2020
2087 /* one buffer entry per 4K ... first might be short or unaligned */ 2021 /* one buffer entry per 4K ... first might be short or unaligned */
2088 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr); 2022 qtd->hw_buf[0] = cpu_to_hc32(fotg210, (u32)addr);
@@ -2117,11 +2051,8 @@ qtd_fill(struct fotg210_hcd *fotg210, struct fotg210_qtd *qtd, dma_addr_t buf,
2117 return count; 2051 return count;
2118} 2052}
2119 2053
2120/*-------------------------------------------------------------------------*/ 2054static inline void qh_update(struct fotg210_hcd *fotg210,
2121 2055 struct fotg210_qh *qh, struct fotg210_qtd *qtd)
2122static inline void
2123qh_update(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
2124 struct fotg210_qtd *qtd)
2125{ 2056{
2126 struct fotg210_qh_hw *hw = qh->hw; 2057 struct fotg210_qh_hw *hw = qh->hw;
2127 2058
@@ -2137,7 +2068,7 @@ qh_update(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
2137 * ever clear it. 2068 * ever clear it.
2138 */ 2069 */
2139 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) { 2070 if (!(hw->hw_info1 & cpu_to_hc32(fotg210, QH_TOGGLE_CTL))) {
2140 unsigned is_out, epnum; 2071 unsigned is_out, epnum;
2141 2072
2142 is_out = qh->is_out; 2073 is_out = qh->is_out;
2143 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f; 2074 epnum = (hc32_to_cpup(fotg210, &hw->hw_info1) >> 8) & 0x0f;
@@ -2154,8 +2085,7 @@ qh_update(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
2154 * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault 2085 * overlay, so qh->hw_token wrongly becomes inactive/halted), only fault
2155 * recovery (including urb dequeue) would need software changes to a QH... 2086 * recovery (including urb dequeue) would need software changes to a QH...
2156 */ 2087 */
2157static void 2088static void qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2158qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2159{ 2089{
2160 struct fotg210_qtd *qtd; 2090 struct fotg210_qtd *qtd;
2161 2091
@@ -2181,16 +2111,14 @@ qh_refresh(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2181 qh_update(fotg210, qh, qtd); 2111 qh_update(fotg210, qh, qtd);
2182} 2112}
2183 2113
2184/*-------------------------------------------------------------------------*/
2185
2186static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh); 2114static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2187 2115
2188static void fotg210_clear_tt_buffer_complete(struct usb_hcd *hcd, 2116static void fotg210_clear_tt_buffer_complete(struct usb_hcd *hcd,
2189 struct usb_host_endpoint *ep) 2117 struct usb_host_endpoint *ep)
2190{ 2118{
2191 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 2119 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
2192 struct fotg210_qh *qh = ep->hcpriv; 2120 struct fotg210_qh *qh = ep->hcpriv;
2193 unsigned long flags; 2121 unsigned long flags;
2194 2122
2195 spin_lock_irqsave(&fotg210->lock, flags); 2123 spin_lock_irqsave(&fotg210->lock, flags);
2196 qh->clearing_tt = 0; 2124 qh->clearing_tt = 0;
@@ -2201,8 +2129,7 @@ static void fotg210_clear_tt_buffer_complete(struct usb_hcd *hcd,
2201} 2129}
2202 2130
2203static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210, 2131static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210,
2204 struct fotg210_qh *qh, 2132 struct fotg210_qh *qh, struct urb *urb, u32 token)
2205 struct urb *urb, u32 token)
2206{ 2133{
2207 2134
2208 /* If an async split transaction gets an error or is unlinked, 2135 /* If an async split transaction gets an error or is unlinked,
@@ -2213,27 +2140,24 @@ static void fotg210_clear_tt_buffer(struct fotg210_hcd *fotg210,
2213 */ 2140 */
2214 if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) { 2141 if (urb->dev->tt && !usb_pipeint(urb->pipe) && !qh->clearing_tt) {
2215 struct usb_device *tt = urb->dev->tt->hub; 2142 struct usb_device *tt = urb->dev->tt->hub;
2143
2216 dev_dbg(&tt->dev, 2144 dev_dbg(&tt->dev,
2217 "clear tt buffer port %d, a%d ep%d t%08x\n", 2145 "clear tt buffer port %d, a%d ep%d t%08x\n",
2218 urb->dev->ttport, urb->dev->devnum, 2146 urb->dev->ttport, urb->dev->devnum,
2219 usb_pipeendpoint(urb->pipe), token); 2147 usb_pipeendpoint(urb->pipe), token);
2220 2148
2221 if (urb->dev->tt->hub != 2149 if (urb->dev->tt->hub !=
2222 fotg210_to_hcd(fotg210)->self.root_hub) { 2150 fotg210_to_hcd(fotg210)->self.root_hub) {
2223 if (usb_hub_clear_tt_buffer(urb) == 0) 2151 if (usb_hub_clear_tt_buffer(urb) == 0)
2224 qh->clearing_tt = 1; 2152 qh->clearing_tt = 1;
2225 } 2153 }
2226 } 2154 }
2227} 2155}
2228 2156
2229static int qtd_copy_status( 2157static int qtd_copy_status(struct fotg210_hcd *fotg210, struct urb *urb,
2230 struct fotg210_hcd *fotg210, 2158 size_t length, u32 token)
2231 struct urb *urb,
2232 size_t length,
2233 u32 token
2234)
2235{ 2159{
2236 int status = -EINPROGRESS; 2160 int status = -EINPROGRESS;
2237 2161
2238 /* count IN/OUT bytes, not SETUP (even short packets) */ 2162 /* count IN/OUT bytes, not SETUP (even short packets) */
2239 if (likely(QTD_PID(token) != 2)) 2163 if (likely(QTD_PID(token) != 2))
@@ -2270,32 +2194,32 @@ static int qtd_copy_status(
2270 } else if (token & QTD_STS_XACT) { 2194 } else if (token & QTD_STS_XACT) {
2271 /* timeout, bad CRC, wrong PID, etc */ 2195 /* timeout, bad CRC, wrong PID, etc */
2272 fotg210_dbg(fotg210, "devpath %s ep%d%s 3strikes\n", 2196 fotg210_dbg(fotg210, "devpath %s ep%d%s 3strikes\n",
2273 urb->dev->devpath, 2197 urb->dev->devpath,
2274 usb_pipeendpoint(urb->pipe), 2198 usb_pipeendpoint(urb->pipe),
2275 usb_pipein(urb->pipe) ? "in" : "out"); 2199 usb_pipein(urb->pipe) ? "in" : "out");
2276 status = -EPROTO; 2200 status = -EPROTO;
2277 } else { /* unknown */ 2201 } else { /* unknown */
2278 status = -EPROTO; 2202 status = -EPROTO;
2279 } 2203 }
2280 2204
2281 fotg210_dbg(fotg210, 2205 fotg210_dbg(fotg210,
2282 "dev%d ep%d%s qtd token %08x --> status %d\n", 2206 "dev%d ep%d%s qtd token %08x --> status %d\n",
2283 usb_pipedevice(urb->pipe), 2207 usb_pipedevice(urb->pipe),
2284 usb_pipeendpoint(urb->pipe), 2208 usb_pipeendpoint(urb->pipe),
2285 usb_pipein(urb->pipe) ? "in" : "out", 2209 usb_pipein(urb->pipe) ? "in" : "out",
2286 token, status); 2210 token, status);
2287 } 2211 }
2288 2212
2289 return status; 2213 return status;
2290} 2214}
2291 2215
2292static void 2216static void fotg210_urb_done(struct fotg210_hcd *fotg210, struct urb *urb,
2293fotg210_urb_done(struct fotg210_hcd *fotg210, struct urb *urb, int status) 2217 int status)
2294__releases(fotg210->lock) 2218__releases(fotg210->lock)
2295__acquires(fotg210->lock) 2219__acquires(fotg210->lock)
2296{ 2220{
2297 if (likely(urb->hcpriv != NULL)) { 2221 if (likely(urb->hcpriv != NULL)) {
2298 struct fotg210_qh *qh = (struct fotg210_qh *) urb->hcpriv; 2222 struct fotg210_qh *qh = (struct fotg210_qh *) urb->hcpriv;
2299 2223
2300 /* S-mask in a QH means it's an interrupt urb */ 2224 /* S-mask in a QH means it's an interrupt urb */
2301 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) { 2225 if ((qh->hw->hw_info2 & cpu_to_hc32(fotg210, QH_SMASK)) != 0) {
@@ -2316,12 +2240,12 @@ __acquires(fotg210->lock)
2316 2240
2317#ifdef FOTG210_URB_TRACE 2241#ifdef FOTG210_URB_TRACE
2318 fotg210_dbg(fotg210, 2242 fotg210_dbg(fotg210,
2319 "%s %s urb %p ep%d%s status %d len %d/%d\n", 2243 "%s %s urb %p ep%d%s status %d len %d/%d\n",
2320 __func__, urb->dev->devpath, urb, 2244 __func__, urb->dev->devpath, urb,
2321 usb_pipeendpoint(urb->pipe), 2245 usb_pipeendpoint(urb->pipe),
2322 usb_pipein(urb->pipe) ? "in" : "out", 2246 usb_pipein(urb->pipe) ? "in" : "out",
2323 status, 2247 status,
2324 urb->actual_length, urb->transfer_buffer_length); 2248 urb->actual_length, urb->transfer_buffer_length);
2325#endif 2249#endif
2326 2250
2327 /* complete() can reenter this HCD */ 2251 /* complete() can reenter this HCD */
@@ -2333,21 +2257,20 @@ __acquires(fotg210->lock)
2333 2257
2334static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh); 2258static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh);
2335 2259
2336/* 2260/* Process and free completed qtds for a qh, returning URBs to drivers.
2337 * Process and free completed qtds for a qh, returning URBs to drivers.
2338 * Chases up to qh->hw_current. Returns number of completions called, 2261 * Chases up to qh->hw_current. Returns number of completions called,
2339 * indicating how much "real" work we did. 2262 * indicating how much "real" work we did.
2340 */ 2263 */
2341static unsigned 2264static unsigned qh_completions(struct fotg210_hcd *fotg210,
2342qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) 2265 struct fotg210_qh *qh)
2343{ 2266{
2344 struct fotg210_qtd *last, *end = qh->dummy; 2267 struct fotg210_qtd *last, *end = qh->dummy;
2345 struct list_head *entry, *tmp; 2268 struct list_head *entry, *tmp;
2346 int last_status; 2269 int last_status;
2347 int stopped; 2270 int stopped;
2348 unsigned count = 0; 2271 unsigned count = 0;
2349 u8 state; 2272 u8 state;
2350 struct fotg210_qh_hw *hw = qh->hw; 2273 struct fotg210_qh_hw *hw = qh->hw;
2351 2274
2352 if (unlikely(list_empty(&qh->qtd_list))) 2275 if (unlikely(list_empty(&qh->qtd_list)))
2353 return count; 2276 return count;
@@ -2366,7 +2289,7 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2366 qh->qh_state = QH_STATE_COMPLETING; 2289 qh->qh_state = QH_STATE_COMPLETING;
2367 stopped = (state == QH_STATE_IDLE); 2290 stopped = (state == QH_STATE_IDLE);
2368 2291
2369 rescan: 2292rescan:
2370 last = NULL; 2293 last = NULL;
2371 last_status = -EINPROGRESS; 2294 last_status = -EINPROGRESS;
2372 qh->needs_rescan = 0; 2295 qh->needs_rescan = 0;
@@ -2377,9 +2300,9 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2377 * if queue is stopped, handles unlinks. 2300 * if queue is stopped, handles unlinks.
2378 */ 2301 */
2379 list_for_each_safe(entry, tmp, &qh->qtd_list) { 2302 list_for_each_safe(entry, tmp, &qh->qtd_list) {
2380 struct fotg210_qtd *qtd; 2303 struct fotg210_qtd *qtd;
2381 struct urb *urb; 2304 struct urb *urb;
2382 u32 token = 0; 2305 u32 token = 0;
2383 2306
2384 qtd = list_entry(entry, struct fotg210_qtd, qtd_list); 2307 qtd = list_entry(entry, struct fotg210_qtd, qtd_list);
2385 urb = qtd->urb; 2308 urb = qtd->urb;
@@ -2388,7 +2311,7 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2388 if (last) { 2311 if (last) {
2389 if (likely(last->urb != urb)) { 2312 if (likely(last->urb != urb)) {
2390 fotg210_urb_done(fotg210, last->urb, 2313 fotg210_urb_done(fotg210, last->urb,
2391 last_status); 2314 last_status);
2392 count++; 2315 count++;
2393 last_status = -EINPROGRESS; 2316 last_status = -EINPROGRESS;
2394 } 2317 }
@@ -2405,20 +2328,17 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2405 token = hc32_to_cpu(fotg210, qtd->hw_token); 2328 token = hc32_to_cpu(fotg210, qtd->hw_token);
2406 2329
2407 /* always clean up qtds the hc de-activated */ 2330 /* always clean up qtds the hc de-activated */
2408 retry_xacterr: 2331retry_xacterr:
2409 if ((token & QTD_STS_ACTIVE) == 0) { 2332 if ((token & QTD_STS_ACTIVE) == 0) {
2410 2333
2411 /* Report Data Buffer Error: non-fatal but useful */ 2334 /* Report Data Buffer Error: non-fatal but useful */
2412 if (token & QTD_STS_DBE) 2335 if (token & QTD_STS_DBE)
2413 fotg210_dbg(fotg210, 2336 fotg210_dbg(fotg210,
2414 "detected DataBufferErr for urb %p ep%d%s len %d, qtd %p [qh %p]\n", 2337 "detected DataBufferErr for urb %p ep%d%s len %d, qtd %p [qh %p]\n",
2415 urb, 2338 urb, usb_endpoint_num(&urb->ep->desc),
2416 usb_endpoint_num(&urb->ep->desc),
2417 usb_endpoint_dir_in(&urb->ep->desc) 2339 usb_endpoint_dir_in(&urb->ep->desc)
2418 ? "in" : "out", 2340 ? "in" : "out",
2419 urb->transfer_buffer_length, 2341 urb->transfer_buffer_length, qtd, qh);
2420 qtd,
2421 qh);
2422 2342
2423 /* on STALL, error, and short reads this urb must 2343 /* on STALL, error, and short reads this urb must
2424 * complete and all its qtds must be recycled. 2344 * complete and all its qtds must be recycled.
@@ -2429,12 +2349,14 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2429 * reach the software xacterr limit 2349 * reach the software xacterr limit
2430 */ 2350 */
2431 if ((token & QTD_STS_XACT) && 2351 if ((token & QTD_STS_XACT) &&
2432 QTD_CERR(token) == 0 && 2352 QTD_CERR(token) == 0 &&
2433 ++qh->xacterrs < QH_XACTERR_MAX && 2353 ++qh->xacterrs < QH_XACTERR_MAX &&
2434 !urb->unlinked) { 2354 !urb->unlinked) {
2435 fotg210_dbg(fotg210, 2355 fotg210_dbg(fotg210,
2436 "detected XactErr len %zu/%zu retry %d\n", 2356 "detected XactErr len %zu/%zu retry %d\n",
2437 qtd->length - QTD_LENGTH(token), qtd->length, qh->xacterrs); 2357 qtd->length - QTD_LENGTH(token),
2358 qtd->length,
2359 qh->xacterrs);
2438 2360
2439 /* reset the token in the qtd and the 2361 /* reset the token in the qtd and the
2440 * qh overlay (which still contains 2362 * qh overlay (which still contains
@@ -2462,9 +2384,9 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2462 * URB_SHORT_NOT_OK was set so the driver submitting 2384 * URB_SHORT_NOT_OK was set so the driver submitting
2463 * the urbs could clean it up. 2385 * the urbs could clean it up.
2464 */ 2386 */
2465 } else if (IS_SHORT_READ(token) 2387 } else if (IS_SHORT_READ(token) &&
2466 && !(qtd->hw_alt_next 2388 !(qtd->hw_alt_next &
2467 & FOTG210_LIST_END(fotg210))) { 2389 FOTG210_LIST_END(fotg210))) {
2468 stopped = 1; 2390 stopped = 1;
2469 } 2391 }
2470 2392
@@ -2488,9 +2410,9 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2488 continue; 2410 continue;
2489 2411
2490 /* qh unlinked; token in overlay may be most current */ 2412 /* qh unlinked; token in overlay may be most current */
2491 if (state == QH_STATE_IDLE 2413 if (state == QH_STATE_IDLE &&
2492 && cpu_to_hc32(fotg210, qtd->qtd_dma) 2414 cpu_to_hc32(fotg210, qtd->qtd_dma)
2493 == hw->hw_current) { 2415 == hw->hw_current) {
2494 token = hc32_to_cpu(fotg210, hw->hw_token); 2416 token = hc32_to_cpu(fotg210, hw->hw_token);
2495 2417
2496 /* An unlink may leave an incomplete 2418 /* An unlink may leave an incomplete
@@ -2498,7 +2420,7 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2498 * We have to clear it. 2420 * We have to clear it.
2499 */ 2421 */
2500 fotg210_clear_tt_buffer(fotg210, qh, urb, 2422 fotg210_clear_tt_buffer(fotg210, qh, urb,
2501 token); 2423 token);
2502 } 2424 }
2503 } 2425 }
2504 2426
@@ -2512,9 +2434,9 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2512 if (last_status == -EINPROGRESS) { 2434 if (last_status == -EINPROGRESS) {
2513 last_status = qtd_copy_status(fotg210, urb, 2435 last_status = qtd_copy_status(fotg210, urb,
2514 qtd->length, token); 2436 qtd->length, token);
2515 if (last_status == -EREMOTEIO 2437 if (last_status == -EREMOTEIO &&
2516 && (qtd->hw_alt_next 2438 (qtd->hw_alt_next &
2517 & FOTG210_LIST_END(fotg210))) 2439 FOTG210_LIST_END(fotg210)))
2518 last_status = -EINPROGRESS; 2440 last_status = -EINPROGRESS;
2519 2441
2520 /* As part of low/full-speed endpoint-halt processing 2442 /* As part of low/full-speed endpoint-halt processing
@@ -2533,7 +2455,7 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2533 */ 2455 */
2534 if (last_status != -EPIPE) 2456 if (last_status != -EPIPE)
2535 fotg210_clear_tt_buffer(fotg210, qh, 2457 fotg210_clear_tt_buffer(fotg210, qh,
2536 urb, token); 2458 urb, token);
2537 } 2459 }
2538 } 2460 }
2539 2461
@@ -2611,26 +2533,21 @@ qh_completions(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
2611 return count; 2533 return count;
2612} 2534}
2613 2535
2614/*-------------------------------------------------------------------------*/
2615
2616/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */ 2536/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
2617#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03)) 2537#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
2618/* ... and packet size, for any kind of endpoint descriptor */ 2538/* ... and packet size, for any kind of endpoint descriptor */
2619#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff) 2539#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
2620 2540
2621/* 2541/* reverse of qh_urb_transaction: free a list of TDs.
2622 * reverse of qh_urb_transaction: free a list of TDs.
2623 * used for cleanup after errors, before HC sees an URB's TDs. 2542 * used for cleanup after errors, before HC sees an URB's TDs.
2624 */ 2543 */
2625static void qtd_list_free( 2544static void qtd_list_free(struct fotg210_hcd *fotg210, struct urb *urb,
2626 struct fotg210_hcd *fotg210, 2545 struct list_head *qtd_list)
2627 struct urb *urb, 2546{
2628 struct list_head *qtd_list 2547 struct list_head *entry, *temp;
2629) {
2630 struct list_head *entry, *temp;
2631 2548
2632 list_for_each_safe(entry, temp, qtd_list) { 2549 list_for_each_safe(entry, temp, qtd_list) {
2633 struct fotg210_qtd *qtd; 2550 struct fotg210_qtd *qtd;
2634 2551
2635 qtd = list_entry(entry, struct fotg210_qtd, qtd_list); 2552 qtd = list_entry(entry, struct fotg210_qtd, qtd_list);
2636 list_del(&qtd->qtd_list); 2553 list_del(&qtd->qtd_list);
@@ -2638,23 +2555,18 @@ static void qtd_list_free(
2638 } 2555 }
2639} 2556}
2640 2557
2641/* 2558/* create a list of filled qtds for this URB; won't link into qh.
2642 * create a list of filled qtds for this URB; won't link into qh.
2643 */ 2559 */
2644static struct list_head * 2560static struct list_head *qh_urb_transaction(struct fotg210_hcd *fotg210,
2645qh_urb_transaction( 2561 struct urb *urb, struct list_head *head, gfp_t flags)
2646 struct fotg210_hcd *fotg210, 2562{
2647 struct urb *urb, 2563 struct fotg210_qtd *qtd, *qtd_prev;
2648 struct list_head *head, 2564 dma_addr_t buf;
2649 gfp_t flags 2565 int len, this_sg_len, maxpacket;
2650) { 2566 int is_input;
2651 struct fotg210_qtd *qtd, *qtd_prev; 2567 u32 token;
2652 dma_addr_t buf; 2568 int i;
2653 int len, this_sg_len, maxpacket; 2569 struct scatterlist *sg;
2654 int is_input;
2655 u32 token;
2656 int i;
2657 struct scatterlist *sg;
2658 2570
2659 /* 2571 /*
2660 * URBs map to sequences of QTDs: one logical transaction 2572 * URBs map to sequences of QTDs: one logical transaction
@@ -2764,8 +2676,8 @@ qh_urb_transaction(
2764 * have the alt_next mechanism keep the queue running after the 2676 * have the alt_next mechanism keep the queue running after the
2765 * last data qtd (the only one, for control and most other cases). 2677 * last data qtd (the only one, for control and most other cases).
2766 */ 2678 */
2767 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 2679 if (likely((urb->transfer_flags & URB_SHORT_NOT_OK) == 0 ||
2768 || usb_pipecontrol(urb->pipe))) 2680 usb_pipecontrol(urb->pipe)))
2769 qtd->hw_alt_next = FOTG210_LIST_END(fotg210); 2681 qtd->hw_alt_next = FOTG210_LIST_END(fotg210);
2770 2682
2771 /* 2683 /*
@@ -2774,7 +2686,7 @@ qh_urb_transaction(
2774 * (zero length). 2686 * (zero length).
2775 */ 2687 */
2776 if (likely(urb->transfer_buffer_length != 0)) { 2688 if (likely(urb->transfer_buffer_length != 0)) {
2777 int one_more = 0; 2689 int one_more = 0;
2778 2690
2779 if (usb_pipecontrol(urb->pipe)) { 2691 if (usb_pipecontrol(urb->pipe)) {
2780 one_more = 1; 2692 one_more = 1;
@@ -2809,9 +2721,7 @@ cleanup:
2809 return NULL; 2721 return NULL;
2810} 2722}
2811 2723
2812/*-------------------------------------------------------------------------*/ 2724/* Would be best to create all qh's from config descriptors,
2813/*
2814 * Would be best to create all qh's from config descriptors,
2815 * when each interface/altsetting is established. Unlink 2725 * when each interface/altsetting is established. Unlink
2816 * any previous qh and cancel its urbs first; endpoints are 2726 * any previous qh and cancel its urbs first; endpoints are
2817 * implicitly reset then (data toggle too). 2727 * implicitly reset then (data toggle too).
@@ -2819,26 +2729,22 @@ cleanup:
2819*/ 2729*/
2820 2730
2821 2731
2822/* 2732/* Each QH holds a qtd list; a QH is used for everything except iso.
2823 * Each QH holds a qtd list; a QH is used for everything except iso.
2824 * 2733 *
2825 * For interrupt urbs, the scheduler must set the microframe scheduling 2734 * For interrupt urbs, the scheduler must set the microframe scheduling
2826 * mask(s) each time the QH gets scheduled. For highspeed, that's 2735 * mask(s) each time the QH gets scheduled. For highspeed, that's
2827 * just one microframe in the s-mask. For split interrupt transactions 2736 * just one microframe in the s-mask. For split interrupt transactions
2828 * there are additional complications: c-mask, maybe FSTNs. 2737 * there are additional complications: c-mask, maybe FSTNs.
2829 */ 2738 */
2830static struct fotg210_qh * 2739static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb,
2831qh_make( 2740 gfp_t flags)
2832 struct fotg210_hcd *fotg210, 2741{
2833 struct urb *urb, 2742 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags);
2834 gfp_t flags 2743 u32 info1 = 0, info2 = 0;
2835) { 2744 int is_input, type;
2836 struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags); 2745 int maxp = 0;
2837 u32 info1 = 0, info2 = 0; 2746 struct usb_tt *tt = urb->dev->tt;
2838 int is_input, type; 2747 struct fotg210_qh_hw *hw;
2839 int maxp = 0;
2840 struct usb_tt *tt = urb->dev->tt;
2841 struct fotg210_qh_hw *hw;
2842 2748
2843 if (!qh) 2749 if (!qh)
2844 return qh; 2750 return qh;
@@ -2858,7 +2764,7 @@ qh_make(
2858 */ 2764 */
2859 if (max_packet(maxp) > 1024) { 2765 if (max_packet(maxp) > 1024) {
2860 fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", 2766 fotg210_dbg(fotg210, "bogus qh maxpacket %d\n",
2861 max_packet(maxp)); 2767 max_packet(maxp));
2862 goto done; 2768 goto done;
2863 } 2769 }
2864 2770
@@ -2892,7 +2798,7 @@ qh_make(
2892 urb->interval = qh->period << 3; 2798 urb->interval = qh->period << 3;
2893 } 2799 }
2894 } else { 2800 } else {
2895 int think_time; 2801 int think_time;
2896 2802
2897 /* gap is f(FS/LS transfer times) */ 2803 /* gap is f(FS/LS transfer times) */
2898 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed, 2804 qh->gap_uf = 1 + usb_calc_bus_time(urb->dev->speed,
@@ -2982,7 +2888,7 @@ qh_make(
2982 break; 2888 break;
2983 default: 2889 default:
2984 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev, 2890 fotg210_dbg(fotg210, "bogus dev %p speed %d\n", urb->dev,
2985 urb->dev->speed); 2891 urb->dev->speed);
2986done: 2892done:
2987 qh_destroy(fotg210, qh); 2893 qh_destroy(fotg210, qh);
2988 return NULL; 2894 return NULL;
@@ -3001,8 +2907,6 @@ done:
3001 return qh; 2907 return qh;
3002} 2908}
3003 2909
3004/*-------------------------------------------------------------------------*/
3005
3006static void enable_async(struct fotg210_hcd *fotg210) 2910static void enable_async(struct fotg210_hcd *fotg210)
3007{ 2911{
3008 if (fotg210->async_count++) 2912 if (fotg210->async_count++)
@@ -3032,8 +2936,8 @@ static void disable_async(struct fotg210_hcd *fotg210)
3032 2936
3033static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) 2937static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3034{ 2938{
3035 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma); 2939 __hc32 dma = QH_NEXT(fotg210, qh->qh_dma);
3036 struct fotg210_qh *head; 2940 struct fotg210_qh *head;
3037 2941
3038 /* Don't link a QH if there's a Clear-TT-Buffer pending */ 2942 /* Don't link a QH if there's a Clear-TT-Buffer pending */
3039 if (unlikely(qh->clearing_tt)) 2943 if (unlikely(qh->clearing_tt))
@@ -3060,24 +2964,17 @@ static void qh_link_async(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3060 enable_async(fotg210); 2964 enable_async(fotg210);
3061} 2965}
3062 2966
3063/*-------------------------------------------------------------------------*/ 2967/* For control/bulk/interrupt, return QH with these TDs appended.
3064
3065/*
3066 * For control/bulk/interrupt, return QH with these TDs appended.
3067 * Allocates and initializes the QH if necessary. 2968 * Allocates and initializes the QH if necessary.
3068 * Returns null if it can't allocate a QH it needs to. 2969 * Returns null if it can't allocate a QH it needs to.
3069 * If the QH has TDs (urbs) already, that's great. 2970 * If the QH has TDs (urbs) already, that's great.
3070 */ 2971 */
3071static struct fotg210_qh *qh_append_tds( 2972static struct fotg210_qh *qh_append_tds(struct fotg210_hcd *fotg210,
3072 struct fotg210_hcd *fotg210, 2973 struct urb *urb, struct list_head *qtd_list,
3073 struct urb *urb, 2974 int epnum, void **ptr)
3074 struct list_head *qtd_list,
3075 int epnum,
3076 void **ptr
3077)
3078{ 2975{
3079 struct fotg210_qh *qh = NULL; 2976 struct fotg210_qh *qh = NULL;
3080 __hc32 qh_addr_mask = cpu_to_hc32(fotg210, 0x7f); 2977 __hc32 qh_addr_mask = cpu_to_hc32(fotg210, 0x7f);
3081 2978
3082 qh = (struct fotg210_qh *) *ptr; 2979 qh = (struct fotg210_qh *) *ptr;
3083 if (unlikely(qh == NULL)) { 2980 if (unlikely(qh == NULL)) {
@@ -3086,7 +2983,7 @@ static struct fotg210_qh *qh_append_tds(
3086 *ptr = qh; 2983 *ptr = qh;
3087 } 2984 }
3088 if (likely(qh != NULL)) { 2985 if (likely(qh != NULL)) {
3089 struct fotg210_qtd *qtd; 2986 struct fotg210_qtd *qtd;
3090 2987
3091 if (unlikely(list_empty(qtd_list))) 2988 if (unlikely(list_empty(qtd_list)))
3092 qtd = NULL; 2989 qtd = NULL;
@@ -3105,9 +3002,9 @@ static struct fotg210_qh *qh_append_tds(
3105 * only hc or qh_refresh() ever modify the overlay. 3002 * only hc or qh_refresh() ever modify the overlay.
3106 */ 3003 */
3107 if (likely(qtd != NULL)) { 3004 if (likely(qtd != NULL)) {
3108 struct fotg210_qtd *dummy; 3005 struct fotg210_qtd *dummy;
3109 dma_addr_t dma; 3006 dma_addr_t dma;
3110 __hc32 token; 3007 __hc32 token;
3111 3008
3112 /* to avoid racing the HC, use the dummy td instead of 3009 /* to avoid racing the HC, use the dummy td instead of
3113 * the first td of our list (becomes new dummy). both 3010 * the first td of our list (becomes new dummy). both
@@ -3146,32 +3043,28 @@ static struct fotg210_qh *qh_append_tds(
3146 return qh; 3043 return qh;
3147} 3044}
3148 3045
3149/*-------------------------------------------------------------------------*/ 3046static int submit_async(struct fotg210_hcd *fotg210, struct urb *urb,
3150 3047 struct list_head *qtd_list, gfp_t mem_flags)
3151static int 3048{
3152submit_async( 3049 int epnum;
3153 struct fotg210_hcd *fotg210, 3050 unsigned long flags;
3154 struct urb *urb, 3051 struct fotg210_qh *qh = NULL;
3155 struct list_head *qtd_list, 3052 int rc;
3156 gfp_t mem_flags
3157) {
3158 int epnum;
3159 unsigned long flags;
3160 struct fotg210_qh *qh = NULL;
3161 int rc;
3162 3053
3163 epnum = urb->ep->desc.bEndpointAddress; 3054 epnum = urb->ep->desc.bEndpointAddress;
3164 3055
3165#ifdef FOTG210_URB_TRACE 3056#ifdef FOTG210_URB_TRACE
3166 { 3057 {
3167 struct fotg210_qtd *qtd; 3058 struct fotg210_qtd *qtd;
3059
3168 qtd = list_entry(qtd_list->next, struct fotg210_qtd, qtd_list); 3060 qtd = list_entry(qtd_list->next, struct fotg210_qtd, qtd_list);
3169 fotg210_dbg(fotg210, 3061 fotg210_dbg(fotg210,
3170 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n", 3062 "%s %s urb %p ep%d%s len %d, qtd %p [qh %p]\n",
3171 __func__, urb->dev->devpath, urb, 3063 __func__, urb->dev->devpath, urb,
3172 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", 3064 epnum & 0x0f, (epnum & USB_DIR_IN)
3173 urb->transfer_buffer_length, 3065 ? "in" : "out",
3174 qtd, urb->ep->hcpriv); 3066 urb->transfer_buffer_length,
3067 qtd, urb->ep->hcpriv);
3175 } 3068 }
3176#endif 3069#endif
3177 3070
@@ -3196,19 +3089,17 @@ submit_async(
3196 */ 3089 */
3197 if (likely(qh->qh_state == QH_STATE_IDLE)) 3090 if (likely(qh->qh_state == QH_STATE_IDLE))
3198 qh_link_async(fotg210, qh); 3091 qh_link_async(fotg210, qh);
3199 done: 3092done:
3200 spin_unlock_irqrestore(&fotg210->lock, flags); 3093 spin_unlock_irqrestore(&fotg210->lock, flags);
3201 if (unlikely(qh == NULL)) 3094 if (unlikely(qh == NULL))
3202 qtd_list_free(fotg210, urb, qtd_list); 3095 qtd_list_free(fotg210, urb, qtd_list);
3203 return rc; 3096 return rc;
3204} 3097}
3205 3098
3206/*-------------------------------------------------------------------------*/
3207
3208static void single_unlink_async(struct fotg210_hcd *fotg210, 3099static void single_unlink_async(struct fotg210_hcd *fotg210,
3209 struct fotg210_qh *qh) 3100 struct fotg210_qh *qh)
3210{ 3101{
3211 struct fotg210_qh *prev; 3102 struct fotg210_qh *prev;
3212 3103
3213 /* Add to the end of the list of QHs waiting for the next IAAD */ 3104 /* Add to the end of the list of QHs waiting for the next IAAD */
3214 qh->qh_state = QH_STATE_UNLINK; 3105 qh->qh_state = QH_STATE_UNLINK;
@@ -3256,7 +3147,7 @@ static void start_iaa_cycle(struct fotg210_hcd *fotg210, bool nested)
3256 &fotg210->regs->command); 3147 &fotg210->regs->command);
3257 fotg210_readl(fotg210, &fotg210->regs->command); 3148 fotg210_readl(fotg210, &fotg210->regs->command);
3258 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IAA_WATCHDOG, 3149 fotg210_enable_event(fotg210, FOTG210_HRTIMER_IAA_WATCHDOG,
3259 true); 3150 true);
3260 } 3151 }
3261} 3152}
3262 3153
@@ -3264,10 +3155,10 @@ static void start_iaa_cycle(struct fotg210_hcd *fotg210, bool nested)
3264 3155
3265static void end_unlink_async(struct fotg210_hcd *fotg210) 3156static void end_unlink_async(struct fotg210_hcd *fotg210)
3266{ 3157{
3267 struct fotg210_qh *qh; 3158 struct fotg210_qh *qh;
3268 3159
3269 /* Process the idle QHs */ 3160 /* Process the idle QHs */
3270 restart: 3161restart:
3271 fotg210->async_unlinking = true; 3162 fotg210->async_unlinking = true;
3272 while (fotg210->async_iaa) { 3163 while (fotg210->async_iaa) {
3273 qh = fotg210->async_iaa; 3164 qh = fotg210->async_iaa;
@@ -3322,7 +3213,7 @@ static void unlink_empty_async(struct fotg210_hcd *fotg210)
3322 /* QHs that haven't been empty for long enough will be handled later */ 3213 /* QHs that haven't been empty for long enough will be handled later */
3323 if (check_unlinks_later) { 3214 if (check_unlinks_later) {
3324 fotg210_enable_event(fotg210, FOTG210_HRTIMER_ASYNC_UNLINKS, 3215 fotg210_enable_event(fotg210, FOTG210_HRTIMER_ASYNC_UNLINKS,
3325 true); 3216 true);
3326 ++fotg210->async_unlink_cycle; 3217 ++fotg210->async_unlink_cycle;
3327 } 3218 }
3328} 3219}
@@ -3331,7 +3222,7 @@ static void unlink_empty_async(struct fotg210_hcd *fotg210)
3331/* caller must own fotg210->lock */ 3222/* caller must own fotg210->lock */
3332 3223
3333static void start_unlink_async(struct fotg210_hcd *fotg210, 3224static void start_unlink_async(struct fotg210_hcd *fotg210,
3334 struct fotg210_qh *qh) 3225 struct fotg210_qh *qh)
3335{ 3226{
3336 /* 3227 /*
3337 * If the QH isn't linked then there's nothing we can do 3228 * If the QH isn't linked then there's nothing we can do
@@ -3348,18 +3239,16 @@ static void start_unlink_async(struct fotg210_hcd *fotg210,
3348 start_iaa_cycle(fotg210, false); 3239 start_iaa_cycle(fotg210, false);
3349} 3240}
3350 3241
3351/*-------------------------------------------------------------------------*/
3352
3353static void scan_async(struct fotg210_hcd *fotg210) 3242static void scan_async(struct fotg210_hcd *fotg210)
3354{ 3243{
3355 struct fotg210_qh *qh; 3244 struct fotg210_qh *qh;
3356 bool check_unlinks_later = false; 3245 bool check_unlinks_later = false;
3357 3246
3358 fotg210->qh_scan_next = fotg210->async->qh_next.qh; 3247 fotg210->qh_scan_next = fotg210->async->qh_next.qh;
3359 while (fotg210->qh_scan_next) { 3248 while (fotg210->qh_scan_next) {
3360 qh = fotg210->qh_scan_next; 3249 qh = fotg210->qh_scan_next;
3361 fotg210->qh_scan_next = qh->qh_next.qh; 3250 fotg210->qh_scan_next = qh->qh_next.qh;
3362 rescan: 3251rescan:
3363 /* clean any finished work for this qh */ 3252 /* clean any finished work for this qh */
3364 if (!list_empty(&qh->qtd_list)) { 3253 if (!list_empty(&qh->qtd_list)) {
3365 int temp; 3254 int temp;
@@ -3391,15 +3280,13 @@ static void scan_async(struct fotg210_hcd *fotg210)
3391 */ 3280 */
3392 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING && 3281 if (check_unlinks_later && fotg210->rh_state == FOTG210_RH_RUNNING &&
3393 !(fotg210->enabled_hrtimer_events & 3282 !(fotg210->enabled_hrtimer_events &
3394 BIT(FOTG210_HRTIMER_ASYNC_UNLINKS))) { 3283 BIT(FOTG210_HRTIMER_ASYNC_UNLINKS))) {
3395 fotg210_enable_event(fotg210, 3284 fotg210_enable_event(fotg210,
3396 FOTG210_HRTIMER_ASYNC_UNLINKS, true); 3285 FOTG210_HRTIMER_ASYNC_UNLINKS, true);
3397 ++fotg210->async_unlink_cycle; 3286 ++fotg210->async_unlink_cycle;
3398 } 3287 }
3399} 3288}
3400/*-------------------------------------------------------------------------*/ 3289/* EHCI scheduled transaction support: interrupt, iso, split iso
3401/*
3402 * EHCI scheduled transaction support: interrupt, iso, split iso
3403 * These are called "periodic" transactions in the EHCI spec. 3290 * These are called "periodic" transactions in the EHCI spec.
3404 * 3291 *
3405 * Note that for interrupt transfers, the QH/QTD manipulation is shared 3292 * Note that for interrupt transfers, the QH/QTD manipulation is shared
@@ -3410,19 +3297,14 @@ static void scan_async(struct fotg210_hcd *fotg210)
3410 * It keeps track of every ITD (or SITD) that's linked, and holds enough 3297 * It keeps track of every ITD (or SITD) that's linked, and holds enough
3411 * pre-calculated schedule data to make appending to the queue be quick. 3298 * pre-calculated schedule data to make appending to the queue be quick.
3412 */ 3299 */
3413
3414static int fotg210_get_frame(struct usb_hcd *hcd); 3300static int fotg210_get_frame(struct usb_hcd *hcd);
3415 3301
3416/*-------------------------------------------------------------------------*/ 3302/* periodic_next_shadow - return "next" pointer on shadow list
3417
3418/*
3419 * periodic_next_shadow - return "next" pointer on shadow list
3420 * @periodic: host pointer to qh/itd 3303 * @periodic: host pointer to qh/itd
3421 * @tag: hardware tag for type of this record 3304 * @tag: hardware tag for type of this record
3422 */ 3305 */
3423static union fotg210_shadow * 3306static union fotg210_shadow *periodic_next_shadow(struct fotg210_hcd *fotg210,
3424periodic_next_shadow(struct fotg210_hcd *fotg210, 3307 union fotg210_shadow *periodic, __hc32 tag)
3425 union fotg210_shadow *periodic, __hc32 tag)
3426{ 3308{
3427 switch (hc32_to_cpu(fotg210, tag)) { 3309 switch (hc32_to_cpu(fotg210, tag)) {
3428 case Q_TYPE_QH: 3310 case Q_TYPE_QH:
@@ -3434,9 +3316,8 @@ periodic_next_shadow(struct fotg210_hcd *fotg210,
3434 } 3316 }
3435} 3317}
3436 3318
3437static __hc32 * 3319static __hc32 *shadow_next_periodic(struct fotg210_hcd *fotg210,
3438shadow_next_periodic(struct fotg210_hcd *fotg210, 3320 union fotg210_shadow *periodic, __hc32 tag)
3439 union fotg210_shadow *periodic, __hc32 tag)
3440{ 3321{
3441 switch (hc32_to_cpu(fotg210, tag)) { 3322 switch (hc32_to_cpu(fotg210, tag)) {
3442 /* our fotg210_shadow.qh is actually software part */ 3323 /* our fotg210_shadow.qh is actually software part */
@@ -3450,11 +3331,11 @@ shadow_next_periodic(struct fotg210_hcd *fotg210,
3450 3331
3451/* caller must hold fotg210->lock */ 3332/* caller must hold fotg210->lock */
3452static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame, 3333static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame,
3453 void *ptr) 3334 void *ptr)
3454{ 3335{
3455 union fotg210_shadow *prev_p = &fotg210->pshadow[frame]; 3336 union fotg210_shadow *prev_p = &fotg210->pshadow[frame];
3456 __hc32 *hw_p = &fotg210->periodic[frame]; 3337 __hc32 *hw_p = &fotg210->periodic[frame];
3457 union fotg210_shadow here = *prev_p; 3338 union fotg210_shadow here = *prev_p;
3458 3339
3459 /* find predecessor of "ptr"; hw and shadow lists are in sync */ 3340 /* find predecessor of "ptr"; hw and shadow lists are in sync */
3460 while (here.ptr && here.ptr != ptr) { 3341 while (here.ptr && here.ptr != ptr) {
@@ -3475,17 +3356,17 @@ static void periodic_unlink(struct fotg210_hcd *fotg210, unsigned frame,
3475 Q_NEXT_TYPE(fotg210, *hw_p)); 3356 Q_NEXT_TYPE(fotg210, *hw_p));
3476 3357
3477 *hw_p = *shadow_next_periodic(fotg210, &here, 3358 *hw_p = *shadow_next_periodic(fotg210, &here,
3478 Q_NEXT_TYPE(fotg210, *hw_p)); 3359 Q_NEXT_TYPE(fotg210, *hw_p));
3479} 3360}
3480 3361
3481/* how many of the uframe's 125 usecs are allocated? */ 3362/* how many of the uframe's 125 usecs are allocated? */
3482static unsigned short 3363static unsigned short periodic_usecs(struct fotg210_hcd *fotg210,
3483periodic_usecs(struct fotg210_hcd *fotg210, unsigned frame, unsigned uframe) 3364 unsigned frame, unsigned uframe)
3484{ 3365{
3485 __hc32 *hw_p = &fotg210->periodic[frame]; 3366 __hc32 *hw_p = &fotg210->periodic[frame];
3486 union fotg210_shadow *q = &fotg210->pshadow[frame]; 3367 union fotg210_shadow *q = &fotg210->pshadow[frame];
3487 unsigned usecs = 0; 3368 unsigned usecs = 0;
3488 struct fotg210_qh_hw *hw; 3369 struct fotg210_qh_hw *hw;
3489 3370
3490 while (q->ptr) { 3371 while (q->ptr) {
3491 switch (hc32_to_cpu(fotg210, Q_NEXT_TYPE(fotg210, *hw_p))) { 3372 switch (hc32_to_cpu(fotg210, Q_NEXT_TYPE(fotg210, *hw_p))) {
@@ -3522,12 +3403,10 @@ periodic_usecs(struct fotg210_hcd *fotg210, unsigned frame, unsigned uframe)
3522 } 3403 }
3523 if (usecs > fotg210->uframe_periodic_max) 3404 if (usecs > fotg210->uframe_periodic_max)
3524 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n", 3405 fotg210_err(fotg210, "uframe %d sched overrun: %d usecs\n",
3525 frame * 8 + uframe, usecs); 3406 frame * 8 + uframe, usecs);
3526 return usecs; 3407 return usecs;
3527} 3408}
3528 3409
3529/*-------------------------------------------------------------------------*/
3530
3531static int same_tt(struct usb_device *dev1, struct usb_device *dev2) 3410static int same_tt(struct usb_device *dev1, struct usb_device *dev2)
3532{ 3411{
3533 if (!dev1->tt || !dev2->tt) 3412 if (!dev1->tt || !dev2->tt)
@@ -3544,13 +3423,8 @@ static int same_tt(struct usb_device *dev1, struct usb_device *dev2)
3544 * for a periodic transfer starting at the specified frame, using 3423 * for a periodic transfer starting at the specified frame, using
3545 * all the uframes in the mask. 3424 * all the uframes in the mask.
3546 */ 3425 */
3547static int tt_no_collision( 3426static int tt_no_collision(struct fotg210_hcd *fotg210, unsigned period,
3548 struct fotg210_hcd *fotg210, 3427 struct usb_device *dev, unsigned frame, u32 uf_mask)
3549 unsigned period,
3550 struct usb_device *dev,
3551 unsigned frame,
3552 u32 uf_mask
3553)
3554{ 3428{
3555 if (period == 0) /* error */ 3429 if (period == 0) /* error */
3556 return 0; 3430 return 0;
@@ -3560,9 +3434,9 @@ static int tt_no_collision(
3560 * calling convention doesn't make that distinction. 3434 * calling convention doesn't make that distinction.
3561 */ 3435 */
3562 for (; frame < fotg210->periodic_size; frame += period) { 3436 for (; frame < fotg210->periodic_size; frame += period) {
3563 union fotg210_shadow here; 3437 union fotg210_shadow here;
3564 __hc32 type; 3438 __hc32 type;
3565 struct fotg210_qh_hw *hw; 3439 struct fotg210_qh_hw *hw;
3566 3440
3567 here = fotg210->pshadow[frame]; 3441 here = fotg210->pshadow[frame];
3568 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]); 3442 type = Q_NEXT_TYPE(fotg210, fotg210->periodic[frame]);
@@ -3575,7 +3449,7 @@ static int tt_no_collision(
3575 case Q_TYPE_QH: 3449 case Q_TYPE_QH:
3576 hw = here.qh->hw; 3450 hw = here.qh->hw;
3577 if (same_tt(dev, here.qh->dev)) { 3451 if (same_tt(dev, here.qh->dev)) {
3578 u32 mask; 3452 u32 mask;
3579 3453
3580 mask = hc32_to_cpu(fotg210, 3454 mask = hc32_to_cpu(fotg210,
3581 hw->hw_info2); 3455 hw->hw_info2);
@@ -3590,8 +3464,8 @@ static int tt_no_collision(
3590 /* case Q_TYPE_FSTN: */ 3464 /* case Q_TYPE_FSTN: */
3591 default: 3465 default:
3592 fotg210_dbg(fotg210, 3466 fotg210_dbg(fotg210,
3593 "periodic frame %d bogus type %d\n", 3467 "periodic frame %d bogus type %d\n",
3594 frame, type); 3468 frame, type);
3595 } 3469 }
3596 3470
3597 /* collision or error */ 3471 /* collision or error */
@@ -3603,8 +3477,6 @@ static int tt_no_collision(
3603 return 1; 3477 return 1;
3604} 3478}
3605 3479
3606/*-------------------------------------------------------------------------*/
3607
3608static void enable_periodic(struct fotg210_hcd *fotg210) 3480static void enable_periodic(struct fotg210_hcd *fotg210)
3609{ 3481{
3610 if (fotg210->periodic_count++) 3482 if (fotg210->periodic_count++)
@@ -3628,8 +3500,6 @@ static void disable_periodic(struct fotg210_hcd *fotg210)
3628 fotg210_poll_PSS(fotg210); 3500 fotg210_poll_PSS(fotg210);
3629} 3501}
3630 3502
3631/*-------------------------------------------------------------------------*/
3632
3633/* periodic schedule slots have iso tds (normal or split) first, then a 3503/* periodic schedule slots have iso tds (normal or split) first, then a
3634 * sparse tree for active interrupt transfers. 3504 * sparse tree for active interrupt transfers.
3635 * 3505 *
@@ -3638,24 +3508,24 @@ static void disable_periodic(struct fotg210_hcd *fotg210)
3638 */ 3508 */
3639static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) 3509static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3640{ 3510{
3641 unsigned i; 3511 unsigned i;
3642 unsigned period = qh->period; 3512 unsigned period = qh->period;
3643 3513
3644 dev_dbg(&qh->dev->dev, 3514 dev_dbg(&qh->dev->dev,
3645 "link qh%d-%04x/%p start %d [%d/%d us]\n", 3515 "link qh%d-%04x/%p start %d [%d/%d us]\n", period,
3646 period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) 3516 hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3647 & (QH_CMASK | QH_SMASK), 3517 (QH_CMASK | QH_SMASK), qh, qh->start, qh->usecs,
3648 qh, qh->start, qh->usecs, qh->c_usecs); 3518 qh->c_usecs);
3649 3519
3650 /* high bandwidth, or otherwise every microframe */ 3520 /* high bandwidth, or otherwise every microframe */
3651 if (period == 0) 3521 if (period == 0)
3652 period = 1; 3522 period = 1;
3653 3523
3654 for (i = qh->start; i < fotg210->periodic_size; i += period) { 3524 for (i = qh->start; i < fotg210->periodic_size; i += period) {
3655 union fotg210_shadow *prev = &fotg210->pshadow[i]; 3525 union fotg210_shadow *prev = &fotg210->pshadow[i];
3656 __hc32 *hw_p = &fotg210->periodic[i]; 3526 __hc32 *hw_p = &fotg210->periodic[i];
3657 union fotg210_shadow here = *prev; 3527 union fotg210_shadow here = *prev;
3658 __hc32 type = 0; 3528 __hc32 type = 0;
3659 3529
3660 /* skip the iso nodes at list head */ 3530 /* skip the iso nodes at list head */
3661 while (here.ptr) { 3531 while (here.ptr) {
@@ -3703,10 +3573,10 @@ static void qh_link_periodic(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3703} 3573}
3704 3574
3705static void qh_unlink_periodic(struct fotg210_hcd *fotg210, 3575static void qh_unlink_periodic(struct fotg210_hcd *fotg210,
3706 struct fotg210_qh *qh) 3576 struct fotg210_qh *qh)
3707{ 3577{
3708 unsigned i; 3578 unsigned i;
3709 unsigned period; 3579 unsigned period;
3710 3580
3711 /* 3581 /*
3712 * If qh is for a low/full-speed device, simply unlinking it 3582 * If qh is for a low/full-speed device, simply unlinking it
@@ -3737,10 +3607,10 @@ static void qh_unlink_periodic(struct fotg210_hcd *fotg210,
3737 : (qh->usecs * 8); 3607 : (qh->usecs * 8);
3738 3608
3739 dev_dbg(&qh->dev->dev, 3609 dev_dbg(&qh->dev->dev,
3740 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", 3610 "unlink qh%d-%04x/%p start %d [%d/%d us]\n",
3741 qh->period, 3611 qh->period, hc32_to_cpup(fotg210, &qh->hw->hw_info2) &
3742 hc32_to_cpup(fotg210, &qh->hw->hw_info2) & 3612 (QH_CMASK | QH_SMASK), qh, qh->start, qh->usecs,
3743 (QH_CMASK | QH_SMASK), qh, qh->start, qh->usecs, qh->c_usecs); 3613 qh->c_usecs);
3744 3614
3745 /* qh->qh_next still "live" to HC */ 3615 /* qh->qh_next still "live" to HC */
3746 qh->qh_state = QH_STATE_UNLINK; 3616 qh->qh_state = QH_STATE_UNLINK;
@@ -3753,7 +3623,7 @@ static void qh_unlink_periodic(struct fotg210_hcd *fotg210,
3753} 3623}
3754 3624
3755static void start_unlink_intr(struct fotg210_hcd *fotg210, 3625static void start_unlink_intr(struct fotg210_hcd *fotg210,
3756 struct fotg210_qh *qh) 3626 struct fotg210_qh *qh)
3757{ 3627{
3758 /* If the QH isn't linked then there's nothing we can do 3628 /* If the QH isn't linked then there's nothing we can do
3759 * unless we were called during a giveback, in which case 3629 * unless we were called during a giveback, in which case
@@ -3790,15 +3660,15 @@ static void start_unlink_intr(struct fotg210_hcd *fotg210,
3790 fotg210_handle_intr_unlinks(fotg210); 3660 fotg210_handle_intr_unlinks(fotg210);
3791 else if (fotg210->intr_unlink == qh) { 3661 else if (fotg210->intr_unlink == qh) {
3792 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR, 3662 fotg210_enable_event(fotg210, FOTG210_HRTIMER_UNLINK_INTR,
3793 true); 3663 true);
3794 ++fotg210->intr_unlink_cycle; 3664 ++fotg210->intr_unlink_cycle;
3795 } 3665 }
3796} 3666}
3797 3667
3798static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) 3668static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3799{ 3669{
3800 struct fotg210_qh_hw *hw = qh->hw; 3670 struct fotg210_qh_hw *hw = qh->hw;
3801 int rc; 3671 int rc;
3802 3672
3803 qh->qh_state = QH_STATE_IDLE; 3673 qh->qh_state = QH_STATE_IDLE;
3804 hw->hw_next = FOTG210_LIST_END(fotg210); 3674 hw->hw_next = FOTG210_LIST_END(fotg210);
@@ -3807,7 +3677,7 @@ static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3807 3677
3808 /* reschedule QH iff another request is queued */ 3678 /* reschedule QH iff another request is queued */
3809 if (!list_empty(&qh->qtd_list) && 3679 if (!list_empty(&qh->qtd_list) &&
3810 fotg210->rh_state == FOTG210_RH_RUNNING) { 3680 fotg210->rh_state == FOTG210_RH_RUNNING) {
3811 rc = qh_schedule(fotg210, qh); 3681 rc = qh_schedule(fotg210, qh);
3812 3682
3813 /* An error here likely indicates handshake failure 3683 /* An error here likely indicates handshake failure
@@ -3826,16 +3696,10 @@ static void end_unlink_intr(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3826 disable_periodic(fotg210); 3696 disable_periodic(fotg210);
3827} 3697}
3828 3698
3829/*-------------------------------------------------------------------------*/ 3699static int check_period(struct fotg210_hcd *fotg210, unsigned frame,
3830 3700 unsigned uframe, unsigned period, unsigned usecs)
3831static int check_period( 3701{
3832 struct fotg210_hcd *fotg210, 3702 int claimed;
3833 unsigned frame,
3834 unsigned uframe,
3835 unsigned period,
3836 unsigned usecs
3837) {
3838 int claimed;
3839 3703
3840 /* complete split running into next frame? 3704 /* complete split running into next frame?
3841 * given FSTN support, we could sometimes check... 3705 * given FSTN support, we could sometimes check...
@@ -3853,7 +3717,7 @@ static int check_period(
3853 do { 3717 do {
3854 for (uframe = 0; uframe < 7; uframe++) { 3718 for (uframe = 0; uframe < 7; uframe++) {
3855 claimed = periodic_usecs(fotg210, frame, 3719 claimed = periodic_usecs(fotg210, frame,
3856 uframe); 3720 uframe);
3857 if (claimed > usecs) 3721 if (claimed > usecs)
3858 return 0; 3722 return 0;
3859 } 3723 }
@@ -3872,16 +3736,11 @@ static int check_period(
3872 return 1; 3736 return 1;
3873} 3737}
3874 3738
3875static int check_intr_schedule( 3739static int check_intr_schedule(struct fotg210_hcd *fotg210, unsigned frame,
3876 struct fotg210_hcd *fotg210, 3740 unsigned uframe, const struct fotg210_qh *qh, __hc32 *c_maskp)
3877 unsigned frame,
3878 unsigned uframe,
3879 const struct fotg210_qh *qh,
3880 __hc32 *c_maskp
3881)
3882{ 3741{
3883 int retval = -ENOSPC; 3742 int retval = -ENOSPC;
3884 u8 mask = 0; 3743 u8 mask = 0;
3885 3744
3886 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */ 3745 if (qh->c_usecs && uframe >= 6) /* FSTN territory? */
3887 goto done; 3746 goto done;
@@ -3907,10 +3766,10 @@ static int check_intr_schedule(
3907 mask |= 1 << uframe; 3766 mask |= 1 << uframe;
3908 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) { 3767 if (tt_no_collision(fotg210, qh->period, qh->dev, frame, mask)) {
3909 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1, 3768 if (!check_period(fotg210, frame, uframe + qh->gap_uf + 1,
3910 qh->period, qh->c_usecs)) 3769 qh->period, qh->c_usecs))
3911 goto done; 3770 goto done;
3912 if (!check_period(fotg210, frame, uframe + qh->gap_uf, 3771 if (!check_period(fotg210, frame, uframe + qh->gap_uf,
3913 qh->period, qh->c_usecs)) 3772 qh->period, qh->c_usecs))
3914 goto done; 3773 goto done;
3915 retval = 0; 3774 retval = 0;
3916 } 3775 }
@@ -3923,11 +3782,11 @@ done:
3923 */ 3782 */
3924static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh) 3783static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3925{ 3784{
3926 int status; 3785 int status;
3927 unsigned uframe; 3786 unsigned uframe;
3928 __hc32 c_mask; 3787 __hc32 c_mask;
3929 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ 3788 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
3930 struct fotg210_qh_hw *hw = qh->hw; 3789 struct fotg210_qh_hw *hw = qh->hw;
3931 3790
3932 qh_refresh(fotg210, qh); 3791 qh_refresh(fotg210, qh);
3933 hw->hw_next = FOTG210_LIST_END(fotg210); 3792 hw->hw_next = FOTG210_LIST_END(fotg210);
@@ -3950,7 +3809,7 @@ static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3950 if (status) { 3809 if (status) {
3951 /* "normal" case, uframing flexible except with splits */ 3810 /* "normal" case, uframing flexible except with splits */
3952 if (qh->period) { 3811 if (qh->period) {
3953 int i; 3812 int i;
3954 3813
3955 for (i = qh->period; status && i > 0; --i) { 3814 for (i = qh->period; status && i > 0; --i) {
3956 frame = ++fotg210->random_frame % qh->period; 3815 frame = ++fotg210->random_frame % qh->period;
@@ -3967,7 +3826,7 @@ static int qh_schedule(struct fotg210_hcd *fotg210, struct fotg210_qh *qh)
3967 } else { 3826 } else {
3968 frame = 0; 3827 frame = 0;
3969 status = check_intr_schedule(fotg210, 0, 0, qh, 3828 status = check_intr_schedule(fotg210, 0, 0, qh,
3970 &c_mask); 3829 &c_mask);
3971 } 3830 }
3972 if (status) 3831 if (status)
3973 goto done; 3832 goto done;
@@ -3988,17 +3847,14 @@ done:
3988 return status; 3847 return status;
3989} 3848}
3990 3849
3991static int intr_submit( 3850static int intr_submit(struct fotg210_hcd *fotg210, struct urb *urb,
3992 struct fotg210_hcd *fotg210, 3851 struct list_head *qtd_list, gfp_t mem_flags)
3993 struct urb *urb, 3852{
3994 struct list_head *qtd_list, 3853 unsigned epnum;
3995 gfp_t mem_flags 3854 unsigned long flags;
3996) { 3855 struct fotg210_qh *qh;
3997 unsigned epnum; 3856 int status;
3998 unsigned long flags; 3857 struct list_head empty;
3999 struct fotg210_qh *qh;
4000 int status;
4001 struct list_head empty;
4002 3858
4003 /* get endpoint and transfer/schedule data */ 3859 /* get endpoint and transfer/schedule data */
4004 epnum = urb->ep->desc.bEndpointAddress; 3860 epnum = urb->ep->desc.bEndpointAddress;
@@ -4046,11 +3902,11 @@ done_not_linked:
4046 3902
4047static void scan_intr(struct fotg210_hcd *fotg210) 3903static void scan_intr(struct fotg210_hcd *fotg210)
4048{ 3904{
4049 struct fotg210_qh *qh; 3905 struct fotg210_qh *qh;
4050 3906
4051 list_for_each_entry_safe(qh, fotg210->qh_scan_next, 3907 list_for_each_entry_safe(qh, fotg210->qh_scan_next,
4052 &fotg210->intr_qh_list, intr_node) { 3908 &fotg210->intr_qh_list, intr_node) {
4053 rescan: 3909rescan:
4054 /* clean any finished work for this qh */ 3910 /* clean any finished work for this qh */
4055 if (!list_empty(&qh->qtd_list)) { 3911 if (!list_empty(&qh->qtd_list)) {
4056 int temp; 3912 int temp;
@@ -4065,7 +3921,7 @@ static void scan_intr(struct fotg210_hcd *fotg210)
4065 temp = qh_completions(fotg210, qh); 3921 temp = qh_completions(fotg210, qh);
4066 if (unlikely(qh->needs_rescan || 3922 if (unlikely(qh->needs_rescan ||
4067 (list_empty(&qh->qtd_list) && 3923 (list_empty(&qh->qtd_list) &&
4068 qh->qh_state == QH_STATE_LINKED))) 3924 qh->qh_state == QH_STATE_LINKED)))
4069 start_unlink_intr(fotg210, qh); 3925 start_unlink_intr(fotg210, qh);
4070 else if (temp != 0) 3926 else if (temp != 0)
4071 goto rescan; 3927 goto rescan;
@@ -4073,12 +3929,9 @@ static void scan_intr(struct fotg210_hcd *fotg210)
4073 } 3929 }
4074} 3930}
4075 3931
4076/*-------------------------------------------------------------------------*/
4077
4078/* fotg210_iso_stream ops work with both ITD and SITD */ 3932/* fotg210_iso_stream ops work with both ITD and SITD */
4079 3933
4080static struct fotg210_iso_stream * 3934static struct fotg210_iso_stream *iso_stream_alloc(gfp_t mem_flags)
4081iso_stream_alloc(gfp_t mem_flags)
4082{ 3935{
4083 struct fotg210_iso_stream *stream; 3936 struct fotg210_iso_stream *stream;
4084 3937
@@ -4091,20 +3944,15 @@ iso_stream_alloc(gfp_t mem_flags)
4091 return stream; 3944 return stream;
4092} 3945}
4093 3946
4094static void 3947static void iso_stream_init(struct fotg210_hcd *fotg210,
4095iso_stream_init( 3948 struct fotg210_iso_stream *stream, struct usb_device *dev,
4096 struct fotg210_hcd *fotg210, 3949 int pipe, unsigned interval)
4097 struct fotg210_iso_stream *stream,
4098 struct usb_device *dev,
4099 int pipe,
4100 unsigned interval
4101)
4102{ 3950{
4103 u32 buf1; 3951 u32 buf1;
4104 unsigned epnum, maxp; 3952 unsigned epnum, maxp;
4105 int is_input; 3953 int is_input;
4106 long bandwidth; 3954 long bandwidth;
4107 unsigned multi; 3955 unsigned multi;
4108 3956
4109 /* 3957 /*
4110 * this might be a "high bandwidth" highspeed endpoint, 3958 * this might be a "high bandwidth" highspeed endpoint,
@@ -4149,13 +3997,13 @@ iso_stream_init(
4149 stream->maxp = maxp; 3997 stream->maxp = maxp;
4150} 3998}
4151 3999
4152static struct fotg210_iso_stream * 4000static struct fotg210_iso_stream *iso_stream_find(struct fotg210_hcd *fotg210,
4153iso_stream_find(struct fotg210_hcd *fotg210, struct urb *urb) 4001 struct urb *urb)
4154{ 4002{
4155 unsigned epnum; 4003 unsigned epnum;
4156 struct fotg210_iso_stream *stream; 4004 struct fotg210_iso_stream *stream;
4157 struct usb_host_endpoint *ep; 4005 struct usb_host_endpoint *ep;
4158 unsigned long flags; 4006 unsigned long flags;
4159 4007
4160 epnum = usb_pipeendpoint(urb->pipe); 4008 epnum = usb_pipeendpoint(urb->pipe);
4161 if (usb_pipein(urb->pipe)) 4009 if (usb_pipein(urb->pipe))
@@ -4178,8 +4026,8 @@ iso_stream_find(struct fotg210_hcd *fotg210, struct urb *urb)
4178 /* if dev->ep[epnum] is a QH, hw is set */ 4026 /* if dev->ep[epnum] is a QH, hw is set */
4179 } else if (unlikely(stream->hw != NULL)) { 4027 } else if (unlikely(stream->hw != NULL)) {
4180 fotg210_dbg(fotg210, "dev %s ep%d%s, not iso??\n", 4028 fotg210_dbg(fotg210, "dev %s ep%d%s, not iso??\n",
4181 urb->dev->devpath, epnum, 4029 urb->dev->devpath, epnum,
4182 usb_pipein(urb->pipe) ? "in" : "out"); 4030 usb_pipein(urb->pipe) ? "in" : "out");
4183 stream = NULL; 4031 stream = NULL;
4184 } 4032 }
4185 4033
@@ -4187,15 +4035,13 @@ iso_stream_find(struct fotg210_hcd *fotg210, struct urb *urb)
4187 return stream; 4035 return stream;
4188} 4036}
4189 4037
4190/*-------------------------------------------------------------------------*/
4191
4192/* fotg210_iso_sched ops can be ITD-only or SITD-only */ 4038/* fotg210_iso_sched ops can be ITD-only or SITD-only */
4193 4039
4194static struct fotg210_iso_sched * 4040static struct fotg210_iso_sched *iso_sched_alloc(unsigned packets,
4195iso_sched_alloc(unsigned packets, gfp_t mem_flags) 4041 gfp_t mem_flags)
4196{ 4042{
4197 struct fotg210_iso_sched *iso_sched; 4043 struct fotg210_iso_sched *iso_sched;
4198 int size = sizeof(*iso_sched); 4044 int size = sizeof(*iso_sched);
4199 4045
4200 size += packets * sizeof(struct fotg210_iso_packet); 4046 size += packets * sizeof(struct fotg210_iso_packet);
4201 iso_sched = kzalloc(size, mem_flags); 4047 iso_sched = kzalloc(size, mem_flags);
@@ -4205,16 +4051,12 @@ iso_sched_alloc(unsigned packets, gfp_t mem_flags)
4205 return iso_sched; 4051 return iso_sched;
4206} 4052}
4207 4053
4208static inline void 4054static inline void itd_sched_init(struct fotg210_hcd *fotg210,
4209itd_sched_init( 4055 struct fotg210_iso_sched *iso_sched,
4210 struct fotg210_hcd *fotg210, 4056 struct fotg210_iso_stream *stream, struct urb *urb)
4211 struct fotg210_iso_sched *iso_sched,
4212 struct fotg210_iso_stream *stream,
4213 struct urb *urb
4214)
4215{ 4057{
4216 unsigned i; 4058 unsigned i;
4217 dma_addr_t dma = urb->transfer_dma; 4059 dma_addr_t dma = urb->transfer_dma;
4218 4060
4219 /* how many uframes are needed for these transfers */ 4061 /* how many uframes are needed for these transfers */
4220 iso_sched->span = urb->number_of_packets * stream->interval; 4062 iso_sched->span = urb->number_of_packets * stream->interval;
@@ -4223,10 +4065,10 @@ itd_sched_init(
4223 * when we fit new itds into the schedule. 4065 * when we fit new itds into the schedule.
4224 */ 4066 */
4225 for (i = 0; i < urb->number_of_packets; i++) { 4067 for (i = 0; i < urb->number_of_packets; i++) {
4226 struct fotg210_iso_packet *uframe = &iso_sched->packet[i]; 4068 struct fotg210_iso_packet *uframe = &iso_sched->packet[i];
4227 unsigned length; 4069 unsigned length;
4228 dma_addr_t buf; 4070 dma_addr_t buf;
4229 u32 trans; 4071 u32 trans;
4230 4072
4231 length = urb->iso_frame_desc[i].length; 4073 length = urb->iso_frame_desc[i].length;
4232 buf = dma + urb->iso_frame_desc[i].offset; 4074 buf = dma + urb->iso_frame_desc[i].offset;
@@ -4247,11 +4089,8 @@ itd_sched_init(
4247 } 4089 }
4248} 4090}
4249 4091
4250static void 4092static void iso_sched_free(struct fotg210_iso_stream *stream,
4251iso_sched_free( 4093 struct fotg210_iso_sched *iso_sched)
4252 struct fotg210_iso_stream *stream,
4253 struct fotg210_iso_sched *iso_sched
4254)
4255{ 4094{
4256 if (!iso_sched) 4095 if (!iso_sched)
4257 return; 4096 return;
@@ -4260,20 +4099,15 @@ iso_sched_free(
4260 kfree(iso_sched); 4099 kfree(iso_sched);
4261} 4100}
4262 4101
4263static int 4102static int itd_urb_transaction(struct fotg210_iso_stream *stream,
4264itd_urb_transaction( 4103 struct fotg210_hcd *fotg210, struct urb *urb, gfp_t mem_flags)
4265 struct fotg210_iso_stream *stream,
4266 struct fotg210_hcd *fotg210,
4267 struct urb *urb,
4268 gfp_t mem_flags
4269)
4270{ 4104{
4271 struct fotg210_itd *itd; 4105 struct fotg210_itd *itd;
4272 dma_addr_t itd_dma; 4106 dma_addr_t itd_dma;
4273 int i; 4107 int i;
4274 unsigned num_itds; 4108 unsigned num_itds;
4275 struct fotg210_iso_sched *sched; 4109 struct fotg210_iso_sched *sched;
4276 unsigned long flags; 4110 unsigned long flags;
4277 4111
4278 sched = iso_sched_alloc(urb->number_of_packets, mem_flags); 4112 sched = iso_sched_alloc(urb->number_of_packets, mem_flags);
4279 if (unlikely(sched == NULL)) 4113 if (unlikely(sched == NULL))
@@ -4302,7 +4136,7 @@ itd_urb_transaction(
4302 list_del(&itd->itd_list); 4136 list_del(&itd->itd_list);
4303 itd_dma = itd->itd_dma; 4137 itd_dma = itd->itd_dma;
4304 } else { 4138 } else {
4305 alloc_itd: 4139alloc_itd:
4306 spin_unlock_irqrestore(&fotg210->lock, flags); 4140 spin_unlock_irqrestore(&fotg210->lock, flags);
4307 itd = dma_pool_alloc(fotg210->itd_pool, mem_flags, 4141 itd = dma_pool_alloc(fotg210->itd_pool, mem_flags,
4308 &itd_dma); 4142 &itd_dma);
@@ -4326,16 +4160,8 @@ itd_urb_transaction(
4326 return 0; 4160 return 0;
4327} 4161}
4328 4162
4329/*-------------------------------------------------------------------------*/ 4163static inline int itd_slot_ok(struct fotg210_hcd *fotg210, u32 mod, u32 uframe,
4330 4164 u8 usecs, u32 period)
4331static inline int
4332itd_slot_ok(
4333 struct fotg210_hcd *fotg210,
4334 u32 mod,
4335 u32 uframe,
4336 u8 usecs,
4337 u32 period
4338)
4339{ 4165{
4340 uframe %= period; 4166 uframe %= period;
4341 do { 4167 do {
@@ -4350,8 +4176,7 @@ itd_slot_ok(
4350 return 1; 4176 return 1;
4351} 4177}
4352 4178
4353/* 4179/* This scheduler plans almost as far into the future as it has actual
4354 * This scheduler plans almost as far into the future as it has actual
4355 * periodic schedule slots. (Affected by TUNE_FLS, which defaults to 4180 * periodic schedule slots. (Affected by TUNE_FLS, which defaults to
4356 * "as small as possible" to be cache-friendlier.) That limits the size 4181 * "as small as possible" to be cache-friendlier.) That limits the size
4357 * transfers you can stream reliably; avoid more than 64 msec per urb. 4182 * transfers you can stream reliably; avoid more than 64 msec per urb.
@@ -4361,19 +4186,15 @@ itd_slot_ok(
4361 * given FOTG210_TUNE_FLS and the slop). Or, write a smarter scheduler! 4186 * given FOTG210_TUNE_FLS and the slop). Or, write a smarter scheduler!
4362 */ 4187 */
4363 4188
4364#define SCHEDULE_SLOP 80 /* microframes */ 4189#define SCHEDULE_SLOP 80 /* microframes */
4365 4190
4366static int 4191static int iso_stream_schedule(struct fotg210_hcd *fotg210, struct urb *urb,
4367iso_stream_schedule( 4192 struct fotg210_iso_stream *stream)
4368 struct fotg210_hcd *fotg210,
4369 struct urb *urb,
4370 struct fotg210_iso_stream *stream
4371)
4372{ 4193{
4373 u32 now, next, start, period, span; 4194 u32 now, next, start, period, span;
4374 int status; 4195 int status;
4375 unsigned mod = fotg210->periodic_size << 3; 4196 unsigned mod = fotg210->periodic_size << 3;
4376 struct fotg210_iso_sched *sched = urb->hcpriv; 4197 struct fotg210_iso_sched *sched = urb->hcpriv;
4377 4198
4378 period = urb->interval; 4199 period = urb->interval;
4379 span = sched->span; 4200 span = sched->span;
@@ -4392,7 +4213,7 @@ iso_stream_schedule(
4392 * slot in the schedule, implicitly assuming URB_ISO_ASAP. 4213 * slot in the schedule, implicitly assuming URB_ISO_ASAP.
4393 */ 4214 */
4394 if (likely(!list_empty(&stream->td_list))) { 4215 if (likely(!list_empty(&stream->td_list))) {
4395 u32 excess; 4216 u32 excess;
4396 4217
4397 /* For high speed devices, allow scheduling within the 4218 /* For high speed devices, allow scheduling within the
4398 * isochronous scheduling threshold. For full speed devices 4219 * isochronous scheduling threshold. For full speed devices
@@ -4431,6 +4252,7 @@ iso_stream_schedule(
4431 */ 4252 */
4432 else { 4253 else {
4433 int done = 0; 4254 int done = 0;
4255
4434 start = SCHEDULE_SLOP + (now & ~0x07); 4256 start = SCHEDULE_SLOP + (now & ~0x07);
4435 4257
4436 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ 4258 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */
@@ -4453,15 +4275,15 @@ iso_stream_schedule(
4453 /* no room in the schedule */ 4275 /* no room in the schedule */
4454 if (!done) { 4276 if (!done) {
4455 fotg210_dbg(fotg210, "iso resched full %p (now %d max %d)\n", 4277 fotg210_dbg(fotg210, "iso resched full %p (now %d max %d)\n",
4456 urb, now, now + mod); 4278 urb, now, now + mod);
4457 status = -ENOSPC; 4279 status = -ENOSPC;
4458 goto fail; 4280 goto fail;
4459 } 4281 }
4460 } 4282 }
4461 4283
4462 /* Tried to schedule too far into the future? */ 4284 /* Tried to schedule too far into the future? */
4463 if (unlikely(start - now + span - period 4285 if (unlikely(start - now + span - period >=
4464 >= mod - 2 * SCHEDULE_SLOP)) { 4286 mod - 2 * SCHEDULE_SLOP)) {
4465 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n", 4287 fotg210_dbg(fotg210, "request %p would overflow (%d+%d >= %d)\n",
4466 urb, start - now, span - period, 4288 urb, start - now, span - period,
4467 mod - 2 * SCHEDULE_SLOP); 4289 mod - 2 * SCHEDULE_SLOP);
@@ -4481,17 +4303,14 @@ iso_stream_schedule(
4481 fotg210->next_frame = now >> 3; 4303 fotg210->next_frame = now >> 3;
4482 return 0; 4304 return 0;
4483 4305
4484 fail: 4306fail:
4485 iso_sched_free(stream, sched); 4307 iso_sched_free(stream, sched);
4486 urb->hcpriv = NULL; 4308 urb->hcpriv = NULL;
4487 return status; 4309 return status;
4488} 4310}
4489 4311
4490/*-------------------------------------------------------------------------*/ 4312static inline void itd_init(struct fotg210_hcd *fotg210,
4491 4313 struct fotg210_iso_stream *stream, struct fotg210_itd *itd)
4492static inline void
4493itd_init(struct fotg210_hcd *fotg210, struct fotg210_iso_stream *stream,
4494 struct fotg210_itd *itd)
4495{ 4314{
4496 int i; 4315 int i;
4497 4316
@@ -4507,17 +4326,12 @@ itd_init(struct fotg210_hcd *fotg210, struct fotg210_iso_stream *stream,
4507 /* All other fields are filled when scheduling */ 4326 /* All other fields are filled when scheduling */
4508} 4327}
4509 4328
4510static inline void 4329static inline void itd_patch(struct fotg210_hcd *fotg210,
4511itd_patch( 4330 struct fotg210_itd *itd, struct fotg210_iso_sched *iso_sched,
4512 struct fotg210_hcd *fotg210, 4331 unsigned index, u16 uframe)
4513 struct fotg210_itd *itd,
4514 struct fotg210_iso_sched *iso_sched,
4515 unsigned index,
4516 u16 uframe
4517)
4518{ 4332{
4519 struct fotg210_iso_packet *uf = &iso_sched->packet[index]; 4333 struct fotg210_iso_packet *uf = &iso_sched->packet[index];
4520 unsigned pg = itd->pg; 4334 unsigned pg = itd->pg;
4521 4335
4522 uframe &= 0x07; 4336 uframe &= 0x07;
4523 itd->index[uframe] = index; 4337 itd->index[uframe] = index;
@@ -4529,7 +4343,7 @@ itd_patch(
4529 4343
4530 /* iso_frame_desc[].offset must be strictly increasing */ 4344 /* iso_frame_desc[].offset must be strictly increasing */
4531 if (unlikely(uf->cross)) { 4345 if (unlikely(uf->cross)) {
4532 u64 bufp = uf->bufp + 4096; 4346 u64 bufp = uf->bufp + 4096;
4533 4347
4534 itd->pg = ++pg; 4348 itd->pg = ++pg;
4535 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0); 4349 itd->hw_bufp[pg] |= cpu_to_hc32(fotg210, bufp & ~(u32)0);
@@ -4537,13 +4351,13 @@ itd_patch(
4537 } 4351 }
4538} 4352}
4539 4353
4540static inline void 4354static inline void itd_link(struct fotg210_hcd *fotg210, unsigned frame,
4541itd_link(struct fotg210_hcd *fotg210, unsigned frame, struct fotg210_itd *itd) 4355 struct fotg210_itd *itd)
4542{ 4356{
4543 union fotg210_shadow *prev = &fotg210->pshadow[frame]; 4357 union fotg210_shadow *prev = &fotg210->pshadow[frame];
4544 __hc32 *hw_p = &fotg210->periodic[frame]; 4358 __hc32 *hw_p = &fotg210->periodic[frame];
4545 union fotg210_shadow here = *prev; 4359 union fotg210_shadow here = *prev;
4546 __hc32 type = 0; 4360 __hc32 type = 0;
4547 4361
4548 /* skip any iso nodes which might belong to previous microframes */ 4362 /* skip any iso nodes which might belong to previous microframes */
4549 while (here.ptr) { 4363 while (here.ptr) {
@@ -4564,17 +4378,13 @@ itd_link(struct fotg210_hcd *fotg210, unsigned frame, struct fotg210_itd *itd)
4564} 4378}
4565 4379
4566/* fit urb's itds into the selected schedule slot; activate as needed */ 4380/* fit urb's itds into the selected schedule slot; activate as needed */
4567static void itd_link_urb( 4381static void itd_link_urb(struct fotg210_hcd *fotg210, struct urb *urb,
4568 struct fotg210_hcd *fotg210, 4382 unsigned mod, struct fotg210_iso_stream *stream)
4569 struct urb *urb, 4383{
4570 unsigned mod, 4384 int packet;
4571 struct fotg210_iso_stream *stream 4385 unsigned next_uframe, uframe, frame;
4572) 4386 struct fotg210_iso_sched *iso_sched = urb->hcpriv;
4573{ 4387 struct fotg210_itd *itd;
4574 int packet;
4575 unsigned next_uframe, uframe, frame;
4576 struct fotg210_iso_sched *iso_sched = urb->hcpriv;
4577 struct fotg210_itd *itd;
4578 4388
4579 next_uframe = stream->next_uframe & (mod - 1); 4389 next_uframe = stream->next_uframe & (mod - 1);
4580 4390
@@ -4617,7 +4427,7 @@ static void itd_link_urb(
4617 if (((next_uframe >> 3) != frame) 4427 if (((next_uframe >> 3) != frame)
4618 || packet == urb->number_of_packets) { 4428 || packet == urb->number_of_packets) {
4619 itd_link(fotg210, frame & (fotg210->periodic_size - 1), 4429 itd_link(fotg210, frame & (fotg210->periodic_size - 1),
4620 itd); 4430 itd);
4621 itd = NULL; 4431 itd = NULL;
4622 } 4432 }
4623 } 4433 }
@@ -4631,8 +4441,8 @@ static void itd_link_urb(
4631 enable_periodic(fotg210); 4441 enable_periodic(fotg210);
4632} 4442}
4633 4443
4634#define ISO_ERRS (FOTG210_ISOC_BUF_ERR | FOTG210_ISOC_BABBLE |\ 4444#define ISO_ERRS (FOTG210_ISOC_BUF_ERR | FOTG210_ISOC_BABBLE |\
4635 FOTG210_ISOC_XACTERR) 4445 FOTG210_ISOC_XACTERR)
4636 4446
4637/* Process and recycle a completed ITD. Return true iff its urb completed, 4447/* Process and recycle a completed ITD. Return true iff its urb completed,
4638 * and hence its completion callback probably added things to the hardware 4448 * and hence its completion callback probably added things to the hardware
@@ -4646,14 +4456,14 @@ static void itd_link_urb(
4646 */ 4456 */
4647static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd) 4457static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
4648{ 4458{
4649 struct urb *urb = itd->urb; 4459 struct urb *urb = itd->urb;
4650 struct usb_iso_packet_descriptor *desc; 4460 struct usb_iso_packet_descriptor *desc;
4651 u32 t; 4461 u32 t;
4652 unsigned uframe; 4462 unsigned uframe;
4653 int urb_index = -1; 4463 int urb_index = -1;
4654 struct fotg210_iso_stream *stream = itd->stream; 4464 struct fotg210_iso_stream *stream = itd->stream;
4655 struct usb_device *dev; 4465 struct usb_device *dev;
4656 bool retval = false; 4466 bool retval = false;
4657 4467
4658 /* for each uframe with a packet */ 4468 /* for each uframe with a packet */
4659 for (uframe = 0; uframe < 8; uframe++) { 4469 for (uframe = 0; uframe < 8; uframe++) {
@@ -4698,8 +4508,8 @@ static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
4698 goto done; 4508 goto done;
4699 4509
4700 /* ASSERT: it's really the last itd for this urb 4510 /* ASSERT: it's really the last itd for this urb
4701 list_for_each_entry (itd, &stream->td_list, itd_list) 4511 * list_for_each_entry (itd, &stream->td_list, itd_list)
4702 BUG_ON (itd->urb == urb); 4512 * BUG_ON (itd->urb == urb);
4703 */ 4513 */
4704 4514
4705 /* give urb back to the driver; completion often (re)submits */ 4515 /* give urb back to the driver; completion often (re)submits */
@@ -4736,14 +4546,12 @@ done:
4736 return retval; 4546 return retval;
4737} 4547}
4738 4548
4739/*-------------------------------------------------------------------------*/
4740
4741static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb, 4549static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb,
4742 gfp_t mem_flags) 4550 gfp_t mem_flags)
4743{ 4551{
4744 int status = -EINVAL; 4552 int status = -EINVAL;
4745 unsigned long flags; 4553 unsigned long flags;
4746 struct fotg210_iso_stream *stream; 4554 struct fotg210_iso_stream *stream;
4747 4555
4748 /* Get iso_stream head */ 4556 /* Get iso_stream head */
4749 stream = iso_stream_find(fotg210, urb); 4557 stream = iso_stream_find(fotg210, urb);
@@ -4752,22 +4560,22 @@ static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb,
4752 return -ENOMEM; 4560 return -ENOMEM;
4753 } 4561 }
4754 if (unlikely(urb->interval != stream->interval && 4562 if (unlikely(urb->interval != stream->interval &&
4755 fotg210_port_speed(fotg210, 0) == 4563 fotg210_port_speed(fotg210, 0) ==
4756 USB_PORT_STAT_HIGH_SPEED)) { 4564 USB_PORT_STAT_HIGH_SPEED)) {
4757 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n", 4565 fotg210_dbg(fotg210, "can't change iso interval %d --> %d\n",
4758 stream->interval, urb->interval); 4566 stream->interval, urb->interval);
4759 goto done; 4567 goto done;
4760 } 4568 }
4761 4569
4762#ifdef FOTG210_URB_TRACE 4570#ifdef FOTG210_URB_TRACE
4763 fotg210_dbg(fotg210, 4571 fotg210_dbg(fotg210,
4764 "%s %s urb %p ep%d%s len %d, %d pkts %d uframes[%p]\n", 4572 "%s %s urb %p ep%d%s len %d, %d pkts %d uframes[%p]\n",
4765 __func__, urb->dev->devpath, urb, 4573 __func__, urb->dev->devpath, urb,
4766 usb_pipeendpoint(urb->pipe), 4574 usb_pipeendpoint(urb->pipe),
4767 usb_pipein(urb->pipe) ? "in" : "out", 4575 usb_pipein(urb->pipe) ? "in" : "out",
4768 urb->transfer_buffer_length, 4576 urb->transfer_buffer_length,
4769 urb->number_of_packets, urb->interval, 4577 urb->number_of_packets, urb->interval,
4770 stream); 4578 stream);
4771#endif 4579#endif
4772 4580
4773 /* allocate ITDs w/o locking anything */ 4581 /* allocate ITDs w/o locking anything */
@@ -4791,9 +4599,9 @@ static int itd_submit(struct fotg210_hcd *fotg210, struct urb *urb,
4791 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream); 4599 itd_link_urb(fotg210, urb, fotg210->periodic_size << 3, stream);
4792 else 4600 else
4793 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb); 4601 usb_hcd_unlink_urb_from_ep(fotg210_to_hcd(fotg210), urb);
4794 done_not_linked: 4602done_not_linked:
4795 spin_unlock_irqrestore(&fotg210->lock, flags); 4603 spin_unlock_irqrestore(&fotg210->lock, flags);
4796 done: 4604done:
4797 return status; 4605 return status;
4798} 4606}
4799 4607
@@ -4872,7 +4680,7 @@ restart:
4872 break; 4680 break;
4873 default: 4681 default:
4874 fotg210_dbg(fotg210, "corrupt type %d frame %d shadow %p\n", 4682 fotg210_dbg(fotg210, "corrupt type %d frame %d shadow %p\n",
4875 type, frame, q.ptr); 4683 type, frame, q.ptr);
4876 /* FALL THROUGH */ 4684 /* FALL THROUGH */
4877 case Q_TYPE_QH: 4685 case Q_TYPE_QH:
4878 case Q_TYPE_FSTN: 4686 case Q_TYPE_FSTN:
@@ -4893,16 +4701,14 @@ restart:
4893 } 4701 }
4894 fotg210->next_frame = now_frame; 4702 fotg210->next_frame = now_frame;
4895} 4703}
4896/*-------------------------------------------------------------------------*/ 4704
4897/* 4705/* Display / Set uframe_periodic_max
4898 * Display / Set uframe_periodic_max
4899 */ 4706 */
4900static ssize_t show_uframe_periodic_max(struct device *dev, 4707static ssize_t show_uframe_periodic_max(struct device *dev,
4901 struct device_attribute *attr, 4708 struct device_attribute *attr, char *buf)
4902 char *buf)
4903{ 4709{
4904 struct fotg210_hcd *fotg210; 4710 struct fotg210_hcd *fotg210;
4905 int n; 4711 int n;
4906 4712
4907 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev))); 4713 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev)));
4908 n = scnprintf(buf, PAGE_SIZE, "%d\n", fotg210->uframe_periodic_max); 4714 n = scnprintf(buf, PAGE_SIZE, "%d\n", fotg210->uframe_periodic_max);
@@ -4911,15 +4717,14 @@ static ssize_t show_uframe_periodic_max(struct device *dev,
4911 4717
4912 4718
4913static ssize_t store_uframe_periodic_max(struct device *dev, 4719static ssize_t store_uframe_periodic_max(struct device *dev,
4914 struct device_attribute *attr, 4720 struct device_attribute *attr, const char *buf, size_t count)
4915 const char *buf, size_t count)
4916{ 4721{
4917 struct fotg210_hcd *fotg210; 4722 struct fotg210_hcd *fotg210;
4918 unsigned uframe_periodic_max; 4723 unsigned uframe_periodic_max;
4919 unsigned frame, uframe; 4724 unsigned frame, uframe;
4920 unsigned short allocated_max; 4725 unsigned short allocated_max;
4921 unsigned long flags; 4726 unsigned long flags;
4922 ssize_t ret; 4727 ssize_t ret;
4923 4728
4924 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev))); 4729 fotg210 = hcd_to_fotg210(bus_to_hcd(dev_get_drvdata(dev)));
4925 if (kstrtouint(buf, 0, &uframe_periodic_max) < 0) 4730 if (kstrtouint(buf, 0, &uframe_periodic_max) < 0)
@@ -4927,7 +4732,7 @@ static ssize_t store_uframe_periodic_max(struct device *dev,
4927 4732
4928 if (uframe_periodic_max < 100 || uframe_periodic_max >= 125) { 4733 if (uframe_periodic_max < 100 || uframe_periodic_max >= 125) {
4929 fotg210_info(fotg210, "rejecting invalid request for uframe_periodic_max=%u\n", 4734 fotg210_info(fotg210, "rejecting invalid request for uframe_periodic_max=%u\n",
4930 uframe_periodic_max); 4735 uframe_periodic_max);
4931 return -EINVAL; 4736 return -EINVAL;
4932 } 4737 }
4933 4738
@@ -4950,22 +4755,22 @@ static ssize_t store_uframe_periodic_max(struct device *dev,
4950 for (frame = 0; frame < fotg210->periodic_size; ++frame) 4755 for (frame = 0; frame < fotg210->periodic_size; ++frame)
4951 for (uframe = 0; uframe < 7; ++uframe) 4756 for (uframe = 0; uframe < 7; ++uframe)
4952 allocated_max = max(allocated_max, 4757 allocated_max = max(allocated_max,
4953 periodic_usecs(fotg210, frame, uframe)); 4758 periodic_usecs(fotg210, frame,
4759 uframe));
4954 4760
4955 if (allocated_max > uframe_periodic_max) { 4761 if (allocated_max > uframe_periodic_max) {
4956 fotg210_info(fotg210, 4762 fotg210_info(fotg210,
4957 "cannot decrease uframe_periodic_max because " 4763 "cannot decrease uframe_periodic_max because periodic bandwidth is already allocated (%u > %u)\n",
4958 "periodic bandwidth is already allocated " 4764 allocated_max, uframe_periodic_max);
4959 "(%u > %u)\n",
4960 allocated_max, uframe_periodic_max);
4961 goto out_unlock; 4765 goto out_unlock;
4962 } 4766 }
4963 } 4767 }
4964 4768
4965 /* increasing is always ok */ 4769 /* increasing is always ok */
4966 4770
4967 fotg210_info(fotg210, "setting max periodic bandwidth to %u%% (== %u usec/uframe)\n", 4771 fotg210_info(fotg210,
4968 100 * uframe_periodic_max/125, uframe_periodic_max); 4772 "setting max periodic bandwidth to %u%% (== %u usec/uframe)\n",
4773 100 * uframe_periodic_max/125, uframe_periodic_max);
4969 4774
4970 if (uframe_periodic_max != 100) 4775 if (uframe_periodic_max != 100)
4971 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n"); 4776 fotg210_warn(fotg210, "max periodic bandwidth set is non-standard\n");
@@ -4983,8 +4788,8 @@ static DEVICE_ATTR(uframe_periodic_max, 0644, show_uframe_periodic_max,
4983 4788
4984static inline int create_sysfs_files(struct fotg210_hcd *fotg210) 4789static inline int create_sysfs_files(struct fotg210_hcd *fotg210)
4985{ 4790{
4986 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; 4791 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
4987 int i = 0; 4792 int i = 0;
4988 4793
4989 if (i) 4794 if (i)
4990 goto out; 4795 goto out;
@@ -4996,12 +4801,10 @@ out:
4996 4801
4997static inline void remove_sysfs_files(struct fotg210_hcd *fotg210) 4802static inline void remove_sysfs_files(struct fotg210_hcd *fotg210)
4998{ 4803{
4999 struct device *controller = fotg210_to_hcd(fotg210)->self.controller; 4804 struct device *controller = fotg210_to_hcd(fotg210)->self.controller;
5000 4805
5001 device_remove_file(controller, &dev_attr_uframe_periodic_max); 4806 device_remove_file(controller, &dev_attr_uframe_periodic_max);
5002} 4807}
5003/*-------------------------------------------------------------------------*/
5004
5005/* On some systems, leaving remote wakeup enabled prevents system shutdown. 4808/* On some systems, leaving remote wakeup enabled prevents system shutdown.
5006 * The firmware seems to think that powering off is a wakeup event! 4809 * The firmware seems to think that powering off is a wakeup event!
5007 * This routine turns off remote wakeup and everything else, on all ports. 4810 * This routine turns off remote wakeup and everything else, on all ports.
@@ -5013,8 +4816,7 @@ static void fotg210_turn_off_all_ports(struct fotg210_hcd *fotg210)
5013 fotg210_writel(fotg210, PORT_RWC_BITS, status_reg); 4816 fotg210_writel(fotg210, PORT_RWC_BITS, status_reg);
5014} 4817}
5015 4818
5016/* 4819/* Halt HC, turn off all ports, and let the BIOS use the companion controllers.
5017 * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
5018 * Must be called with interrupts enabled and the lock not held. 4820 * Must be called with interrupts enabled and the lock not held.
5019 */ 4821 */
5020static void fotg210_silence_controller(struct fotg210_hcd *fotg210) 4822static void fotg210_silence_controller(struct fotg210_hcd *fotg210)
@@ -5033,7 +4835,7 @@ static void fotg210_silence_controller(struct fotg210_hcd *fotg210)
5033 */ 4835 */
5034static void fotg210_shutdown(struct usb_hcd *hcd) 4836static void fotg210_shutdown(struct usb_hcd *hcd)
5035{ 4837{
5036 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 4838 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5037 4839
5038 spin_lock_irq(&fotg210->lock); 4840 spin_lock_irq(&fotg210->lock);
5039 fotg210->shutdown = true; 4841 fotg210->shutdown = true;
@@ -5046,10 +4848,7 @@ static void fotg210_shutdown(struct usb_hcd *hcd)
5046 hrtimer_cancel(&fotg210->hrtimer); 4848 hrtimer_cancel(&fotg210->hrtimer);
5047} 4849}
5048 4850
5049/*-------------------------------------------------------------------------*/ 4851/* fotg210_work is called from some interrupts, timers, and so on.
5050
5051/*
5052 * fotg210_work is called from some interrupts, timers, and so on.
5053 * it calls driver completion functions, after dropping fotg210->lock. 4852 * it calls driver completion functions, after dropping fotg210->lock.
5054 */ 4853 */
5055static void fotg210_work(struct fotg210_hcd *fotg210) 4854static void fotg210_work(struct fotg210_hcd *fotg210)
@@ -5064,7 +4863,7 @@ static void fotg210_work(struct fotg210_hcd *fotg210)
5064 } 4863 }
5065 fotg210->scanning = true; 4864 fotg210->scanning = true;
5066 4865
5067 rescan: 4866rescan:
5068 fotg210->need_rescan = false; 4867 fotg210->need_rescan = false;
5069 if (fotg210->async_count) 4868 if (fotg210->async_count)
5070 scan_async(fotg210); 4869 scan_async(fotg210);
@@ -5083,12 +4882,11 @@ static void fotg210_work(struct fotg210_hcd *fotg210)
5083 turn_on_io_watchdog(fotg210); 4882 turn_on_io_watchdog(fotg210);
5084} 4883}
5085 4884
5086/* 4885/* Called when the fotg210_hcd module is removed.
5087 * Called when the fotg210_hcd module is removed.
5088 */ 4886 */
5089static void fotg210_stop(struct usb_hcd *hcd) 4887static void fotg210_stop(struct usb_hcd *hcd)
5090{ 4888{
5091 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 4889 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5092 4890
5093 fotg210_dbg(fotg210, "stop\n"); 4891 fotg210_dbg(fotg210, "stop\n");
5094 4892
@@ -5112,26 +4910,26 @@ static void fotg210_stop(struct usb_hcd *hcd)
5112 spin_unlock_irq(&fotg210->lock); 4910 spin_unlock_irq(&fotg210->lock);
5113 fotg210_mem_cleanup(fotg210); 4911 fotg210_mem_cleanup(fotg210);
5114 4912
5115#ifdef FOTG210_STATS 4913#ifdef FOTG210_STATS
5116 fotg210_dbg(fotg210, "irq normal %ld err %ld iaa %ld (lost %ld)\n", 4914 fotg210_dbg(fotg210, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
5117 fotg210->stats.normal, fotg210->stats.error, fotg210->stats.iaa, 4915 fotg210->stats.normal, fotg210->stats.error,
5118 fotg210->stats.lost_iaa); 4916 fotg210->stats.iaa, fotg210->stats.lost_iaa);
5119 fotg210_dbg(fotg210, "complete %ld unlink %ld\n", 4917 fotg210_dbg(fotg210, "complete %ld unlink %ld\n",
5120 fotg210->stats.complete, fotg210->stats.unlink); 4918 fotg210->stats.complete, fotg210->stats.unlink);
5121#endif 4919#endif
5122 4920
5123 dbg_status(fotg210, "fotg210_stop completed", 4921 dbg_status(fotg210, "fotg210_stop completed",
5124 fotg210_readl(fotg210, &fotg210->regs->status)); 4922 fotg210_readl(fotg210, &fotg210->regs->status));
5125} 4923}
5126 4924
5127/* one-time init, only for memory state */ 4925/* one-time init, only for memory state */
5128static int hcd_fotg210_init(struct usb_hcd *hcd) 4926static int hcd_fotg210_init(struct usb_hcd *hcd)
5129{ 4927{
5130 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 4928 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5131 u32 temp; 4929 u32 temp;
5132 int retval; 4930 int retval;
5133 u32 hcc_params; 4931 u32 hcc_params;
5134 struct fotg210_qh_hw *hw; 4932 struct fotg210_qh_hw *hw;
5135 4933
5136 spin_lock_init(&fotg210->lock); 4934 spin_lock_init(&fotg210->lock);
5137 4935
@@ -5234,18 +5032,18 @@ static int hcd_fotg210_init(struct usb_hcd *hcd)
5234/* start HC running; it's halted, hcd_fotg210_init() has been run (once) */ 5032/* start HC running; it's halted, hcd_fotg210_init() has been run (once) */
5235static int fotg210_run(struct usb_hcd *hcd) 5033static int fotg210_run(struct usb_hcd *hcd)
5236{ 5034{
5237 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 5035 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5238 u32 temp; 5036 u32 temp;
5239 u32 hcc_params; 5037 u32 hcc_params;
5240 5038
5241 hcd->uses_new_polling = 1; 5039 hcd->uses_new_polling = 1;
5242 5040
5243 /* EHCI spec section 4.1 */ 5041 /* EHCI spec section 4.1 */
5244 5042
5245 fotg210_writel(fotg210, fotg210->periodic_dma, 5043 fotg210_writel(fotg210, fotg210->periodic_dma,
5246 &fotg210->regs->frame_list); 5044 &fotg210->regs->frame_list);
5247 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma, 5045 fotg210_writel(fotg210, (u32)fotg210->async->qh_dma,
5248 &fotg210->regs->async_next); 5046 &fotg210->regs->async_next);
5249 5047
5250 /* 5048 /*
5251 * hcc_params controls whether fotg210->regs->segment must (!!!) 5049 * hcc_params controls whether fotg210->regs->segment must (!!!)
@@ -5293,14 +5091,14 @@ static int fotg210_run(struct usb_hcd *hcd)
5293 fotg210->last_periodic_enable = ktime_get_real(); 5091 fotg210->last_periodic_enable = ktime_get_real();
5294 5092
5295 temp = HC_VERSION(fotg210, 5093 temp = HC_VERSION(fotg210,
5296 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); 5094 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5297 fotg210_info(fotg210, 5095 fotg210_info(fotg210,
5298 "USB %x.%x started, EHCI %x.%02x\n", 5096 "USB %x.%x started, EHCI %x.%02x\n",
5299 ((fotg210->sbrn & 0xf0)>>4), (fotg210->sbrn & 0x0f), 5097 ((fotg210->sbrn & 0xf0) >> 4), (fotg210->sbrn & 0x0f),
5300 temp >> 8, temp & 0xff); 5098 temp >> 8, temp & 0xff);
5301 5099
5302 fotg210_writel(fotg210, INTR_MASK, 5100 fotg210_writel(fotg210, INTR_MASK,
5303 &fotg210->regs->intr_enable); /* Turn On Interrupts */ 5101 &fotg210->regs->intr_enable); /* Turn On Interrupts */
5304 5102
5305 /* GRR this is run-once init(), being done every time the HC starts. 5103 /* GRR this is run-once init(), being done every time the HC starts.
5306 * So long as they're part of class devices, we can't do it init() 5104 * So long as they're part of class devices, we can't do it init()
@@ -5318,14 +5116,14 @@ static int fotg210_setup(struct usb_hcd *hcd)
5318 int retval; 5116 int retval;
5319 5117
5320 fotg210->regs = (void __iomem *)fotg210->caps + 5118 fotg210->regs = (void __iomem *)fotg210->caps +
5321 HC_LENGTH(fotg210, 5119 HC_LENGTH(fotg210,
5322 fotg210_readl(fotg210, &fotg210->caps->hc_capbase)); 5120 fotg210_readl(fotg210, &fotg210->caps->hc_capbase));
5323 dbg_hcs_params(fotg210, "reset"); 5121 dbg_hcs_params(fotg210, "reset");
5324 dbg_hcc_params(fotg210, "reset"); 5122 dbg_hcc_params(fotg210, "reset");
5325 5123
5326 /* cache this readonly data; minimize chip reads */ 5124 /* cache this readonly data; minimize chip reads */
5327 fotg210->hcs_params = fotg210_readl(fotg210, 5125 fotg210->hcs_params = fotg210_readl(fotg210,
5328 &fotg210->caps->hcs_params); 5126 &fotg210->caps->hcs_params);
5329 5127
5330 fotg210->sbrn = HCD_USB2; 5128 fotg210->sbrn = HCD_USB2;
5331 5129
@@ -5343,13 +5141,11 @@ static int fotg210_setup(struct usb_hcd *hcd)
5343 return 0; 5141 return 0;
5344} 5142}
5345 5143
5346/*-------------------------------------------------------------------------*/
5347
5348static irqreturn_t fotg210_irq(struct usb_hcd *hcd) 5144static irqreturn_t fotg210_irq(struct usb_hcd *hcd)
5349{ 5145{
5350 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 5146 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5351 u32 status, masked_status, pcd_status = 0, cmd; 5147 u32 status, masked_status, pcd_status = 0, cmd;
5352 int bh; 5148 int bh;
5353 5149
5354 spin_lock(&fotg210->lock); 5150 spin_lock(&fotg210->lock);
5355 5151
@@ -5369,7 +5165,7 @@ static irqreturn_t fotg210_irq(struct usb_hcd *hcd)
5369 5165
5370 /* Shared IRQ? */ 5166 /* Shared IRQ? */
5371 if (!masked_status || 5167 if (!masked_status ||
5372 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) { 5168 unlikely(fotg210->rh_state == FOTG210_RH_HALTED)) {
5373 spin_unlock(&fotg210->lock); 5169 spin_unlock(&fotg210->lock);
5374 return IRQ_NONE; 5170 return IRQ_NONE;
5375 } 5171 }
@@ -5436,7 +5232,7 @@ static irqreturn_t fotg210_irq(struct usb_hcd *hcd)
5436 5232
5437 if (test_bit(0, &fotg210->suspended_ports) && 5233 if (test_bit(0, &fotg210->suspended_ports) &&
5438 ((pstatus & PORT_RESUME) || 5234 ((pstatus & PORT_RESUME) ||
5439 !(pstatus & PORT_SUSPEND)) && 5235 !(pstatus & PORT_SUSPEND)) &&
5440 (pstatus & PORT_PE) && 5236 (pstatus & PORT_PE) &&
5441 fotg210->reset_done[0] == 0) { 5237 fotg210->reset_done[0] == 0) {
5442 5238
@@ -5465,7 +5261,7 @@ dead:
5465 fotg210->rh_state = FOTG210_RH_STOPPING; 5261 fotg210->rh_state = FOTG210_RH_STOPPING;
5466 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE); 5262 fotg210->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
5467 fotg210_writel(fotg210, fotg210->command, 5263 fotg210_writel(fotg210, fotg210->command,
5468 &fotg210->regs->command); 5264 &fotg210->regs->command);
5469 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable); 5265 fotg210_writel(fotg210, 0, &fotg210->regs->intr_enable);
5470 fotg210_handle_controller_death(fotg210); 5266 fotg210_handle_controller_death(fotg210);
5471 5267
@@ -5481,10 +5277,7 @@ dead:
5481 return IRQ_HANDLED; 5277 return IRQ_HANDLED;
5482} 5278}
5483 5279
5484/*-------------------------------------------------------------------------*/ 5280/* non-error returns are a promise to giveback() the urb later
5485
5486/*
5487 * non-error returns are a promise to giveback() the urb later
5488 * we drop ownership so next owner (or urb unlink) can get it 5281 * we drop ownership so next owner (or urb unlink) can get it
5489 * 5282 *
5490 * urb + dev is in hcd.self.controller.urb_list 5283 * urb + dev is in hcd.self.controller.urb_list
@@ -5495,13 +5288,11 @@ dead:
5495 * NOTE: control, bulk, and interrupt share the same code to append TDs 5288 * NOTE: control, bulk, and interrupt share the same code to append TDs
5496 * to a (possibly active) QH, and the same QH scanning code. 5289 * to a (possibly active) QH, and the same QH scanning code.
5497 */ 5290 */
5498static int fotg210_urb_enqueue( 5291static int fotg210_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
5499 struct usb_hcd *hcd, 5292 gfp_t mem_flags)
5500 struct urb *urb, 5293{
5501 gfp_t mem_flags 5294 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5502) { 5295 struct list_head qtd_list;
5503 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5504 struct list_head qtd_list;
5505 5296
5506 INIT_LIST_HEAD(&qtd_list); 5297 INIT_LIST_HEAD(&qtd_list);
5507 5298
@@ -5535,10 +5326,10 @@ static int fotg210_urb_enqueue(
5535 5326
5536static int fotg210_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 5327static int fotg210_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
5537{ 5328{
5538 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 5329 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5539 struct fotg210_qh *qh; 5330 struct fotg210_qh *qh;
5540 unsigned long flags; 5331 unsigned long flags;
5541 int rc; 5332 int rc;
5542 5333
5543 spin_lock_irqsave(&fotg210->lock, flags); 5334 spin_lock_irqsave(&fotg210->lock, flags);
5544 rc = usb_hcd_check_unlink_urb(hcd, urb, status); 5335 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
@@ -5599,16 +5390,14 @@ done:
5599 return rc; 5390 return rc;
5600} 5391}
5601 5392
5602/*-------------------------------------------------------------------------*/
5603
5604/* bulk qh holds the data toggle */ 5393/* bulk qh holds the data toggle */
5605 5394
5606static void 5395static void fotg210_endpoint_disable(struct usb_hcd *hcd,
5607fotg210_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep) 5396 struct usb_host_endpoint *ep)
5608{ 5397{
5609 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 5398 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5610 unsigned long flags; 5399 unsigned long flags;
5611 struct fotg210_qh *qh, *tmp; 5400 struct fotg210_qh *qh, *tmp;
5612 5401
5613 /* ASSERT: any requests/urbs are being unlinked */ 5402 /* ASSERT: any requests/urbs are being unlinked */
5614 /* ASSERT: nobody can be submitting urbs for this any more */ 5403 /* ASSERT: nobody can be submitting urbs for this any more */
@@ -5623,7 +5412,7 @@ rescan:
5623 * accelerate iso completions ... so spin a while. 5412 * accelerate iso completions ... so spin a while.
5624 */ 5413 */
5625 if (qh->hw == NULL) { 5414 if (qh->hw == NULL) {
5626 struct fotg210_iso_stream *stream = ep->hcpriv; 5415 struct fotg210_iso_stream *stream = ep->hcpriv;
5627 5416
5628 if (!list_empty(&stream->td_list)) 5417 if (!list_empty(&stream->td_list))
5629 goto idle_timeout; 5418 goto idle_timeout;
@@ -5667,24 +5456,24 @@ idle_timeout:
5667 * that's not our job. just leak this memory. 5456 * that's not our job. just leak this memory.
5668 */ 5457 */
5669 fotg210_err(fotg210, "qh %p (#%02x) state %d%s\n", 5458 fotg210_err(fotg210, "qh %p (#%02x) state %d%s\n",
5670 qh, ep->desc.bEndpointAddress, qh->qh_state, 5459 qh, ep->desc.bEndpointAddress, qh->qh_state,
5671 list_empty(&qh->qtd_list) ? "" : "(has tds)"); 5460 list_empty(&qh->qtd_list) ? "" : "(has tds)");
5672 break; 5461 break;
5673 } 5462 }
5674 done: 5463done:
5675 ep->hcpriv = NULL; 5464 ep->hcpriv = NULL;
5676 spin_unlock_irqrestore(&fotg210->lock, flags); 5465 spin_unlock_irqrestore(&fotg210->lock, flags);
5677} 5466}
5678 5467
5679static void 5468static void fotg210_endpoint_reset(struct usb_hcd *hcd,
5680fotg210_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep) 5469 struct usb_host_endpoint *ep)
5681{ 5470{
5682 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 5471 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5683 struct fotg210_qh *qh; 5472 struct fotg210_qh *qh;
5684 int eptype = usb_endpoint_type(&ep->desc); 5473 int eptype = usb_endpoint_type(&ep->desc);
5685 int epnum = usb_endpoint_num(&ep->desc); 5474 int epnum = usb_endpoint_num(&ep->desc);
5686 int is_out = usb_endpoint_dir_out(&ep->desc); 5475 int is_out = usb_endpoint_dir_out(&ep->desc);
5687 unsigned long flags; 5476 unsigned long flags;
5688 5477
5689 if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT) 5478 if (eptype != USB_ENDPOINT_XFER_BULK && eptype != USB_ENDPOINT_XFER_INT)
5690 return; 5479 return;
@@ -5719,15 +5508,13 @@ fotg210_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
5719 5508
5720static int fotg210_get_frame(struct usb_hcd *hcd) 5509static int fotg210_get_frame(struct usb_hcd *hcd)
5721{ 5510{
5722 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd); 5511 struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
5512
5723 return (fotg210_read_frame_index(fotg210) >> 3) % 5513 return (fotg210_read_frame_index(fotg210) >> 3) %
5724 fotg210->periodic_size; 5514 fotg210->periodic_size;
5725} 5515}
5726 5516
5727/*-------------------------------------------------------------------------*/ 5517/* The EHCI in ChipIdea HDRC cannot be a separate module or device,
5728
5729/*
5730 * The EHCI in ChipIdea HDRC cannot be a separate module or device,
5731 * because its registers (and irq) are shared between host/gadget/otg 5518 * because its registers (and irq) are shared between host/gadget/otg
5732 * functions and in order to facilitate role switching we cannot 5519 * functions and in order to facilitate role switching we cannot
5733 * give the fotg210 driver exclusive access to those. 5520 * give the fotg210 driver exclusive access to those.
@@ -5787,7 +5574,7 @@ static void fotg210_init(struct fotg210_hcd *fotg210)
5787 u32 value; 5574 u32 value;
5788 5575
5789 iowrite32(GMIR_MDEV_INT | GMIR_MOTG_INT | GMIR_INT_POLARITY, 5576 iowrite32(GMIR_MDEV_INT | GMIR_MOTG_INT | GMIR_INT_POLARITY,
5790 &fotg210->regs->gmir); 5577 &fotg210->regs->gmir);
5791 5578
5792 value = ioread32(&fotg210->regs->otgcsr); 5579 value = ioread32(&fotg210->regs->otgcsr);
5793 value &= ~OTGCSR_A_BUS_DROP; 5580 value &= ~OTGCSR_A_BUS_DROP;
@@ -5804,12 +5591,12 @@ static void fotg210_init(struct fotg210_hcd *fotg210)
5804 */ 5591 */
5805static int fotg210_hcd_probe(struct platform_device *pdev) 5592static int fotg210_hcd_probe(struct platform_device *pdev)
5806{ 5593{
5807 struct device *dev = &pdev->dev; 5594 struct device *dev = &pdev->dev;
5808 struct usb_hcd *hcd; 5595 struct usb_hcd *hcd;
5809 struct resource *res; 5596 struct resource *res;
5810 int irq; 5597 int irq;
5811 int retval = -ENODEV; 5598 int retval = -ENODEV;
5812 struct fotg210_hcd *fotg210; 5599 struct fotg210_hcd *fotg210;
5813 5600
5814 if (usb_disabled()) 5601 if (usb_disabled())
5815 return -ENODEV; 5602 return -ENODEV;
@@ -5818,9 +5605,8 @@ static int fotg210_hcd_probe(struct platform_device *pdev)
5818 5605
5819 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 5606 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
5820 if (!res) { 5607 if (!res) {
5821 dev_err(dev, 5608 dev_err(dev, "Found HC with no IRQ. Check %s setup!\n",
5822 "Found HC with no IRQ. Check %s setup!\n", 5609 dev_name(dev));
5823 dev_name(dev));
5824 return -ENODEV; 5610 return -ENODEV;
5825 } 5611 }
5826 5612
@@ -5879,8 +5665,8 @@ fail_create_hcd:
5879 */ 5665 */
5880static int fotg210_hcd_remove(struct platform_device *pdev) 5666static int fotg210_hcd_remove(struct platform_device *pdev)
5881{ 5667{
5882 struct device *dev = &pdev->dev; 5668 struct device *dev = &pdev->dev;
5883 struct usb_hcd *hcd = dev_get_drvdata(dev); 5669 struct usb_hcd *hcd = dev_get_drvdata(dev);
5884 5670
5885 if (!hcd) 5671 if (!hcd)
5886 return 0; 5672 return 0;
@@ -5913,9 +5699,9 @@ static int __init fotg210_hcd_init(void)
5913 pr_warn(KERN_WARNING "Warning! fotg210_hcd should always be loaded before uhci_hcd and ohci_hcd, not after\n"); 5699 pr_warn(KERN_WARNING "Warning! fotg210_hcd should always be loaded before uhci_hcd and ohci_hcd, not after\n");
5914 5700
5915 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd\n", 5701 pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd\n",
5916 hcd_name, 5702 hcd_name, sizeof(struct fotg210_qh),
5917 sizeof(struct fotg210_qh), sizeof(struct fotg210_qtd), 5703 sizeof(struct fotg210_qtd),
5918 sizeof(struct fotg210_itd)); 5704 sizeof(struct fotg210_itd));
5919 5705
5920 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root); 5706 fotg210_debug_root = debugfs_create_dir("fotg210", usb_debug_root);
5921 if (!fotg210_debug_root) { 5707 if (!fotg210_debug_root) {
diff --git a/drivers/usb/host/fotg210.h b/drivers/usb/host/fotg210.h
index 3bad17859cd7..b5cfa7aeb277 100644
--- a/drivers/usb/host/fotg210.h
+++ b/drivers/usb/host/fotg210.h
@@ -137,19 +137,25 @@ struct fotg210_hcd { /* one per controller */
137 /* per root hub port */ 137 /* per root hub port */
138 unsigned long reset_done[FOTG210_MAX_ROOT_PORTS]; 138 unsigned long reset_done[FOTG210_MAX_ROOT_PORTS];
139 139
140 /* bit vectors (one bit per port) */ 140 /* bit vectors (one bit per port)
141 unsigned long bus_suspended; /* which ports were 141 * which ports were already suspended at the start of a bus suspend
142 already suspended at the start of a bus suspend */ 142 */
143 unsigned long companion_ports; /* which ports are 143 unsigned long bus_suspended;
144 dedicated to the companion controller */ 144
145 unsigned long owned_ports; /* which ports are 145 /* which ports are edicated to the companion controller */
146 owned by the companion during a bus suspend */ 146 unsigned long companion_ports;
147 unsigned long port_c_suspend; /* which ports have 147
148 the change-suspend feature turned on */ 148 /* which ports are owned by the companion during a bus suspend */
149 unsigned long suspended_ports; /* which ports are 149 unsigned long owned_ports;
150 suspended */ 150
151 unsigned long resuming_ports; /* which ports have 151 /* which ports have the change-suspend feature turned on */
152 started to resume */ 152 unsigned long port_c_suspend;
153
154 /* which ports are suspended */
155 unsigned long suspended_ports;
156
157 /* which ports have started to resume */
158 unsigned long resuming_ports;
153 159
154 /* per-HC memory pools (could be per-bus, but ...) */ 160 /* per-HC memory pools (could be per-bus, but ...) */
155 struct dma_pool *qh_pool; /* qh per active urb */ 161 struct dma_pool *qh_pool; /* qh per active urb */
@@ -585,10 +591,10 @@ struct fotg210_fstn {
585/* Prepare the PORTSC wakeup flags during controller suspend/resume */ 591/* Prepare the PORTSC wakeup flags during controller suspend/resume */
586 592
587#define fotg210_prepare_ports_for_controller_suspend(fotg210, do_wakeup) \ 593#define fotg210_prepare_ports_for_controller_suspend(fotg210, do_wakeup) \
588 fotg210_adjust_port_wakeup_flags(fotg210, true, do_wakeup); 594 fotg210_adjust_port_wakeup_flags(fotg210, true, do_wakeup)
589 595
590#define fotg210_prepare_ports_for_controller_resume(fotg210) \ 596#define fotg210_prepare_ports_for_controller_resume(fotg210) \
591 fotg210_adjust_port_wakeup_flags(fotg210, false, false); 597 fotg210_adjust_port_wakeup_flags(fotg210, false, false)
592 598
593/*-------------------------------------------------------------------------*/ 599/*-------------------------------------------------------------------------*/
594 600